Skip to content

Commit 6302b9f

Browse files
committed
Release 2.4.10
2 parents 41218f1 + 9f3f5c2 commit 6302b9f

File tree

16 files changed

+246
-103
lines changed

16 files changed

+246
-103
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- uses: actions/setup-go@v4
2020
with:
21-
go-version: '1.20.4'
21+
go-version: '1.20.7'
2222

2323
- name: Ensure linux agent compiles
2424
run: |

agent/agent.go

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ type CmdOptions struct {
254254
func (a *Agent) NewCMDOpts() *CmdOptions {
255255
return &CmdOptions{
256256
Shell: "/bin/bash",
257-
Timeout: 30,
257+
Timeout: 60,
258258
}
259259
}
260260

@@ -322,38 +322,46 @@ func (a *Agent) CmdV2(c *CmdOptions) CmdStatus {
322322
}
323323
}()
324324

325+
statusChan := make(chan gocmd.Status, 1)
325326
// workaround for https://github.com/golang/go/issues/22315
326-
for i := 0; i < 5; i++ {
327-
<-envCmd.Start()
328-
329-
<-doneChan
330-
331-
status := envCmd.Status()
332-
333-
if errors.Is(status.Error, syscall.ETXTBSY) {
334-
a.Logger.Errorln("CmdV2 syscall.ETXTBSY, retrying...")
335-
time.Sleep(500 * time.Millisecond)
336-
} else {
337-
break
338-
}
339-
}
340-
341327
go func() {
342-
select {
343-
case <-doneChan:
328+
for i := 0; i < 5; i++ {
329+
finalStatus := <-envCmd.Start()
330+
if errors.Is(finalStatus.Error, syscall.ETXTBSY) {
331+
a.Logger.Errorln("CmdV2 syscall.ETXTBSY, retrying...")
332+
time.Sleep(500 * time.Millisecond)
333+
continue
334+
}
335+
statusChan <- finalStatus
344336
return
345-
case <-ctx.Done():
346-
a.Logger.Debugf("Command timed out after %d seconds\n", c.Timeout)
347-
pid := envCmd.Status().PID
348-
a.Logger.Debugln("Killing process with PID", pid)
349-
KillProc(int32(pid))
350337
}
351338
}()
352339

340+
var finalStatus gocmd.Status
341+
342+
select {
343+
case <-ctx.Done():
344+
a.Logger.Debugf("Command timed out after %d seconds\n", c.Timeout)
345+
pid := envCmd.Status().PID
346+
a.Logger.Debugln("Killing process with PID", pid)
347+
KillProc(int32(pid))
348+
finalStatus.Exit = 98
349+
ret := CmdStatus{
350+
Status: finalStatus,
351+
Stdout: CleanString(stdoutBuf.String()),
352+
Stderr: fmt.Sprintf("%s\nTimed out after %d seconds", CleanString(stderrBuf.String()), c.Timeout),
353+
}
354+
a.Logger.Debugf("%+v\n", ret)
355+
return ret
356+
case finalStatus = <-statusChan:
357+
// done
358+
}
359+
353360
// Wait for goroutine to print everything
354361
<-doneChan
362+
355363
ret := CmdStatus{
356-
Status: envCmd.Status(),
364+
Status: finalStatus,
357365
Stdout: CleanString(stdoutBuf.String()),
358366
Stderr: CleanString(stderrBuf.String()),
359367
}

agent/agent_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (a *Agent) AgentUpdate(url, inno, version string) error {
273273
se := a.NewCMDOpts()
274274
se.Command = fmt.Sprintf("restorecon -rv %s", self)
275275
out := a.CmdV2(se)
276-
a.Logger.Debugln("%+v\n", out)
276+
a.Logger.Debugf("%+v\n", out)
277277
}
278278

279279
opts := a.NewCMDOpts()

agent/agent_windows.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,10 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
161161
cmd := exec.Command(exe, cmdArgs...)
162162
if runasuser {
163163
token, err := wintoken.GetInteractiveToken(wintoken.TokenImpersonation)
164-
if err != nil {
165-
return "", err.Error(), 66, err
164+
if err == nil {
165+
defer token.Close()
166+
cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(token.Token()), HideWindow: true}
166167
}
167-
defer token.Close()
168-
cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(token.Token()), HideWindow: true}
169168
}
170169
cmd.Stdout = &outb
171170
cmd.Stderr = &errb

agent/embed_darwin.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
/*
5+
Copyright 2023 Amidaware Inc.
6+
7+
Licensed under the Tactical RMM License Version 1.0 (the “License”).
8+
You may only use the Licensed Software in accordance with the License.
9+
A copy of the License is available at:
10+
11+
https://license.tacticalrmm.com
12+
13+
*/
14+
15+
package agent
16+
17+
import _ "embed"
18+
19+
//go:embed scripts/macos_fix_mesh_install.sh
20+
var ventura_mesh_fix string
21+
22+
func (a *Agent) FixVenturaMesh() {
23+
a.RunScript(ventura_mesh_fix, "foo", []string{}, 45, false, []string{})
24+
}

agent/embed_stub.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//go:build !darwin
2+
// +build !darwin
3+
4+
/*
5+
Copyright 2023 Amidaware Inc.
6+
7+
Licensed under the Tactical RMM License Version 1.0 (the “License”).
8+
You may only use the Licensed Software in accordance with the License.
9+
A copy of the License is available at:
10+
11+
https://license.tacticalrmm.com
12+
13+
*/
14+
15+
package agent
16+
17+
func (a *Agent) FixVenturaMesh() {}

agent/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func (a *Agent) Install(i *Installer) {
186186
} else {
187187
opts := a.NewCMDOpts()
188188
opts.Command = fmt.Sprintf("%s -install --installPath=%s", meshOutput, nixMeshDir)
189+
opts.Timeout = i.Timeout
189190
out := a.CmdV2(opts)
190191
if out.Status.Exit != 0 {
191192
a.Logger.Fatalln("Error installing mesh agent:", out.Stderr)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
3+
# source: https://github.com/amidaware/community-scripts/blob/main/scripts_staging/macos_fix_mesh_install.sh
4+
# author: https://github.com/NiceGuyIT
5+
6+
# This script fixes MeshAgent issue #161: MacOS Ventura - Not starting meshagent on boot (Maybe Solved)
7+
# https://github.com/Ylianst/MeshAgent/issues/161
8+
#
9+
# The following actions are taken:
10+
# 1) Add the eXecute bit for directory traversal for the installation directory. This allows regular users
11+
# access to run the binary inside the directory, fixing the "meshagent" LaunchAgent integration with the
12+
# user.
13+
# 2) Rename the LaunchAgent "meshagent.plist" to prevent conflicts with the LaunchDaemon "meshagent.plist".
14+
# This may not be needed but is done for good measure.
15+
# 3) Rename the service Label inside the plist. Using "defaults" causes the plist to be rewritten in plist
16+
# format, not ascii.
17+
#
18+
# Here's the original plist from my install.
19+
# <?xml version="1.0" encoding="UTF-8"?>
20+
# <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
21+
# <plist version="1.0">
22+
# <dict>
23+
# <key>Label</key>
24+
# <string>meshagent</string>
25+
# <key>ProgramArguments</key>
26+
# <array>
27+
# <string>/opt/tacticalmesh/meshagent</string>
28+
# <string>-kvm1</string>
29+
# </array>
30+
#
31+
# <key>WorkingDirectory</key>
32+
# <string>/opt/tacticalmesh</string>
33+
#
34+
# <key>RunAtLoad</key>
35+
# <true/>
36+
# <key>LimitLoadToSessionType</key>
37+
# <array>
38+
# <string>LoginWindow</string>
39+
# </array>
40+
# <key>KeepAlive</key>
41+
# <dict>
42+
# <key>Crashed</key>
43+
# <true/>
44+
# </dict>
45+
# </dict>
46+
# </plist>
47+
48+
49+
mesh_install_dir="/opt/tacticalmesh/"
50+
mesh_agent_plist_old="/Library/LaunchAgents/meshagent.plist"
51+
mesh_agent_plist="/Library/LaunchAgents/meshagent-agent.plist"
52+
mesh_daemon_plist="/Library/LaunchDaemons/meshagent.plist"
53+
54+
if [ ! -f "${mesh_daemon_plist}" ]
55+
then
56+
echo "meshagent LaunchDaemon does not exist to cause the duplicate service name issue. Exiting."
57+
exit 0
58+
fi
59+
60+
if /usr/bin/stat -f "%Sp" "${mesh_install_dir}" | grep -v 'x$' >/dev/null
61+
then
62+
echo "Fixing permissions on meshagent installation directory: ${mesh_install_dir}"
63+
chmod o+X "${mesh_install_dir}"
64+
else
65+
echo "No action taken. Permissions on meshagent installation directory have already been fixed."
66+
fi
67+
echo
68+
69+
if [ -f "${mesh_agent_plist_old}" ]
70+
then
71+
echo "Renaming agent plist: ${mesh_agent_plist_old}"
72+
mv "${mesh_agent_plist_old}" "${mesh_agent_plist}"
73+
else
74+
echo "No action taken. meshagent.plist was already renamed: ${mesh_agent_plist}"
75+
fi
76+
echo
77+
78+
# New file has to exist before renaming the label.
79+
if [ -f "${mesh_agent_plist}" ]
80+
then
81+
label=$(defaults read "${mesh_agent_plist}" Label)
82+
if [ "${label}" != "meshagent-agent" ]
83+
then
84+
echo "Renaming meshagent label in plist: ${mesh_agent_plist}"
85+
echo "Warning: This will convert the plist from a text file to a binary plist file."
86+
defaults write "${mesh_agent_plist}" Label "meshagent-agent"
87+
else
88+
echo "No action taken. meshagent label was already renamed: ${label}"
89+
fi
90+
fi

agent/svc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (a *Agent) AgentSvc(nc *nats.Conn) {
8080
a.SendSoftware()
8181
}
8282

83+
if runtime.GOOS == "darwin" {
84+
go a.FixVenturaMesh()
85+
}
86+
8387
checkInHelloTicker := time.NewTicker(time.Duration(conf.Hello) * time.Second)
8488
checkInAgentInfoTicker := time.NewTicker(time.Duration(conf.AgentInfo) * time.Second)
8589
checkInWinSvcTicker := time.NewTicker(time.Duration(conf.WinSvc) * time.Second)

agent/utils.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func (a *Agent) PublicIP() string {
128128

129129
// GenerateAgentID creates and returns a unique agent id
130130
func GenerateAgentID() string {
131-
rand.Seed(time.Now().UnixNano())
132131
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
133132
b := make([]rune, 40)
134133
for i := range b {
@@ -297,7 +296,6 @@ func ByteCountSI(b uint64) string {
297296
}
298297

299298
func randRange(min, max int) int {
300-
rand.Seed(time.Now().UnixNano())
301299
return rand.Intn(max-min) + min
302300
}
303301

0 commit comments

Comments
 (0)