Skip to content

Commit

Permalink
Release 2.4.10
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Aug 14, 2023
2 parents 41218f1 + 9f3f5c2 commit 6302b9f
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: '1.20.4'
go-version: '1.20.7'

- name: Ensure linux agent compiles
run: |
Expand Down
56 changes: 32 additions & 24 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ type CmdOptions struct {
func (a *Agent) NewCMDOpts() *CmdOptions {
return &CmdOptions{
Shell: "/bin/bash",
Timeout: 30,
Timeout: 60,
}
}

Expand Down Expand Up @@ -322,38 +322,46 @@ func (a *Agent) CmdV2(c *CmdOptions) CmdStatus {
}
}()

statusChan := make(chan gocmd.Status, 1)
// workaround for https://github.com/golang/go/issues/22315
for i := 0; i < 5; i++ {
<-envCmd.Start()

<-doneChan

status := envCmd.Status()

if errors.Is(status.Error, syscall.ETXTBSY) {
a.Logger.Errorln("CmdV2 syscall.ETXTBSY, retrying...")
time.Sleep(500 * time.Millisecond)
} else {
break
}
}

go func() {
select {
case <-doneChan:
for i := 0; i < 5; i++ {
finalStatus := <-envCmd.Start()
if errors.Is(finalStatus.Error, syscall.ETXTBSY) {
a.Logger.Errorln("CmdV2 syscall.ETXTBSY, retrying...")
time.Sleep(500 * time.Millisecond)
continue
}
statusChan <- finalStatus
return
case <-ctx.Done():
a.Logger.Debugf("Command timed out after %d seconds\n", c.Timeout)
pid := envCmd.Status().PID
a.Logger.Debugln("Killing process with PID", pid)
KillProc(int32(pid))
}
}()

var finalStatus gocmd.Status

select {
case <-ctx.Done():
a.Logger.Debugf("Command timed out after %d seconds\n", c.Timeout)
pid := envCmd.Status().PID
a.Logger.Debugln("Killing process with PID", pid)
KillProc(int32(pid))
finalStatus.Exit = 98
ret := CmdStatus{
Status: finalStatus,
Stdout: CleanString(stdoutBuf.String()),
Stderr: fmt.Sprintf("%s\nTimed out after %d seconds", CleanString(stderrBuf.String()), c.Timeout),
}
a.Logger.Debugf("%+v\n", ret)
return ret
case finalStatus = <-statusChan:
// done
}

// Wait for goroutine to print everything
<-doneChan

ret := CmdStatus{
Status: envCmd.Status(),
Status: finalStatus,
Stdout: CleanString(stdoutBuf.String()),
Stderr: CleanString(stderrBuf.String()),
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (a *Agent) AgentUpdate(url, inno, version string) error {
se := a.NewCMDOpts()
se.Command = fmt.Sprintf("restorecon -rv %s", self)
out := a.CmdV2(se)
a.Logger.Debugln("%+v\n", out)
a.Logger.Debugf("%+v\n", out)
}

opts := a.NewCMDOpts()
Expand Down
7 changes: 3 additions & 4 deletions agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
cmd := exec.Command(exe, cmdArgs...)
if runasuser {
token, err := wintoken.GetInteractiveToken(wintoken.TokenImpersonation)
if err != nil {
return "", err.Error(), 66, err
if err == nil {
defer token.Close()
cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(token.Token()), HideWindow: true}
}
defer token.Close()
cmd.SysProcAttr = &syscall.SysProcAttr{Token: syscall.Token(token.Token()), HideWindow: true}
}
cmd.Stdout = &outb
cmd.Stderr = &errb
Expand Down
24 changes: 24 additions & 0 deletions agent/embed_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build darwin
// +build darwin

/*
Copyright 2023 Amidaware Inc.
Licensed under the Tactical RMM License Version 1.0 (the “License”).
You may only use the Licensed Software in accordance with the License.
A copy of the License is available at:
https://license.tacticalrmm.com
*/

package agent

import _ "embed"

//go:embed scripts/macos_fix_mesh_install.sh
var ventura_mesh_fix string

func (a *Agent) FixVenturaMesh() {
a.RunScript(ventura_mesh_fix, "foo", []string{}, 45, false, []string{})
}
17 changes: 17 additions & 0 deletions agent/embed_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !darwin
// +build !darwin

/*
Copyright 2023 Amidaware Inc.
Licensed under the Tactical RMM License Version 1.0 (the “License”).
You may only use the Licensed Software in accordance with the License.
A copy of the License is available at:
https://license.tacticalrmm.com
*/

package agent

func (a *Agent) FixVenturaMesh() {}
1 change: 1 addition & 0 deletions agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (a *Agent) Install(i *Installer) {
} else {
opts := a.NewCMDOpts()
opts.Command = fmt.Sprintf("%s -install --installPath=%s", meshOutput, nixMeshDir)
opts.Timeout = i.Timeout
out := a.CmdV2(opts)
if out.Status.Exit != 0 {
a.Logger.Fatalln("Error installing mesh agent:", out.Stderr)
Expand Down
90 changes: 90 additions & 0 deletions agent/scripts/macos_fix_mesh_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash

# source: https://github.com/amidaware/community-scripts/blob/main/scripts_staging/macos_fix_mesh_install.sh
# author: https://github.com/NiceGuyIT

# This script fixes MeshAgent issue #161: MacOS Ventura - Not starting meshagent on boot (Maybe Solved)
# https://github.com/Ylianst/MeshAgent/issues/161
#
# The following actions are taken:
# 1) Add the eXecute bit for directory traversal for the installation directory. This allows regular users
# access to run the binary inside the directory, fixing the "meshagent" LaunchAgent integration with the
# user.
# 2) Rename the LaunchAgent "meshagent.plist" to prevent conflicts with the LaunchDaemon "meshagent.plist".
# This may not be needed but is done for good measure.
# 3) Rename the service Label inside the plist. Using "defaults" causes the plist to be rewritten in plist
# format, not ascii.
#
# Here's the original plist from my install.
# <?xml version="1.0" encoding="UTF-8"?>
# <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
# <plist version="1.0">
# <dict>
# <key>Label</key>
# <string>meshagent</string>
# <key>ProgramArguments</key>
# <array>
# <string>/opt/tacticalmesh/meshagent</string>
# <string>-kvm1</string>
# </array>
#
# <key>WorkingDirectory</key>
# <string>/opt/tacticalmesh</string>
#
# <key>RunAtLoad</key>
# <true/>
# <key>LimitLoadToSessionType</key>
# <array>
# <string>LoginWindow</string>
# </array>
# <key>KeepAlive</key>
# <dict>
# <key>Crashed</key>
# <true/>
# </dict>
# </dict>
# </plist>


mesh_install_dir="/opt/tacticalmesh/"
mesh_agent_plist_old="/Library/LaunchAgents/meshagent.plist"
mesh_agent_plist="/Library/LaunchAgents/meshagent-agent.plist"
mesh_daemon_plist="/Library/LaunchDaemons/meshagent.plist"

if [ ! -f "${mesh_daemon_plist}" ]
then
echo "meshagent LaunchDaemon does not exist to cause the duplicate service name issue. Exiting."
exit 0
fi

if /usr/bin/stat -f "%Sp" "${mesh_install_dir}" | grep -v 'x$' >/dev/null
then
echo "Fixing permissions on meshagent installation directory: ${mesh_install_dir}"
chmod o+X "${mesh_install_dir}"
else
echo "No action taken. Permissions on meshagent installation directory have already been fixed."
fi
echo

if [ -f "${mesh_agent_plist_old}" ]
then
echo "Renaming agent plist: ${mesh_agent_plist_old}"
mv "${mesh_agent_plist_old}" "${mesh_agent_plist}"
else
echo "No action taken. meshagent.plist was already renamed: ${mesh_agent_plist}"
fi
echo

# New file has to exist before renaming the label.
if [ -f "${mesh_agent_plist}" ]
then
label=$(defaults read "${mesh_agent_plist}" Label)
if [ "${label}" != "meshagent-agent" ]
then
echo "Renaming meshagent label in plist: ${mesh_agent_plist}"
echo "Warning: This will convert the plist from a text file to a binary plist file."
defaults write "${mesh_agent_plist}" Label "meshagent-agent"
else
echo "No action taken. meshagent label was already renamed: ${label}"
fi
fi
4 changes: 4 additions & 0 deletions agent/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (a *Agent) AgentSvc(nc *nats.Conn) {
a.SendSoftware()
}

if runtime.GOOS == "darwin" {
go a.FixVenturaMesh()
}

checkInHelloTicker := time.NewTicker(time.Duration(conf.Hello) * time.Second)
checkInAgentInfoTicker := time.NewTicker(time.Duration(conf.AgentInfo) * time.Second)
checkInWinSvcTicker := time.NewTicker(time.Duration(conf.WinSvc) * time.Second)
Expand Down
2 changes: 0 additions & 2 deletions agent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (a *Agent) PublicIP() string {

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

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

Expand Down
2 changes: 1 addition & 1 deletion build/rmm.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<assemblyIdentity
type="win32"
name="TacticalRMM"
version="2.4.9.0"
version="2.4.10.0"
processorArchitecture="*"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
Expand Down
2 changes: 1 addition & 1 deletion build/setup.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "Tactical RMM Agent"
#define MyAppVersion "2.4.9"
#define MyAppVersion "2.4.10"
#define MyAppPublisher "AmidaWare LLC"
#define MyAppURL "https://github.com/amidaware"
#define MyAppExeName "tacticalrmm.exe"
Expand Down
35 changes: 17 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ go 1.20

require (
github.com/StackExchange/wmi v1.2.1
github.com/elastic/go-sysinfo v1.10.2
github.com/elastic/go-sysinfo v1.11.0
github.com/go-ole/go-ole v1.2.6
github.com/go-ping/ping v1.1.0
github.com/go-resty/resty/v2 v2.7.0
github.com/gonutz/w32/v2 v2.4.0
github.com/iamacarpet/go-win64api v0.0.0-20220531131246-e84054eb584d
github.com/nats-io/nats-server/v2 v2.9.17 // indirect
github.com/nats-io/nats.go v1.26.0
github.com/iamacarpet/go-win64api v0.0.0-20230324134531-ef6dbdd6db97
github.com/nats-io/nats-server/v2 v2.9.20 // indirect
github.com/nats-io/nats.go v1.28.0
github.com/rickb777/date v1.19.1
github.com/shirou/gopsutil/v3 v3.23.4
github.com/sirupsen/logrus v1.9.0
github.com/shirou/gopsutil/v3 v3.23.6
github.com/sirupsen/logrus v1.9.3
github.com/ugorji/go/codec v1.2.11
github.com/wh1te909/go-win64api v0.0.0-20210906074314-ab23795a6ae5
github.com/wh1te909/go-win64api v0.0.0-20230802051600-21b24f62e846
github.com/wh1te909/trmm-shared v0.0.0-20220227075846-f9f757361139
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0
)

require (
github.com/amidaware/taskmaster v0.0.0-20220111015025-c9cd178bbbf2
github.com/go-cmd/cmd v1.4.1
github.com/go-cmd/cmd v1.4.2
)

require (
github.com/fourcorelabs/wintoken v1.0.0
github.com/jaypipes/ghw v0.10.0
github.com/jaypipes/ghw v0.12.0
github.com/kardianos/service v1.2.2
github.com/spf13/viper v1.15.0
github.com/spf13/viper v1.16.0
)

require (
Expand All @@ -52,23 +52,22 @@ require (
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rickb777/plural v1.4.1 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
Loading

0 comments on commit 6302b9f

Please sign in to comment.