From 381f9696ebfe1e1665c982d7f9344c1d044bf36a Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 8 Aug 2022 23:07:34 +0000 Subject: [PATCH] fix agent update when selinux is enforcing fixes amidaware/tacticalrmm#1239 --- agent/agent_unix.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/agent/agent_unix.go b/agent/agent_unix.go index 993b446..9d23590 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -209,6 +209,13 @@ func SetDetached() *syscall.SysProcAttr { return &syscall.SysProcAttr{Setpgid: true} } +func (a *Agent) seEnforcing() bool { + opts := a.NewCMDOpts() + opts.Command = "getenforce" + out := a.CmdV2(opts) + return out.Status.Exit == 0 && strings.Contains(out.Stdout, "Enforcing") +} + func (a *Agent) AgentUpdate(url, inno, version string) { self, err := os.Executable() @@ -276,6 +283,13 @@ func (a *Agent) AgentUpdate(url, inno, version string) { } } + if a.seEnforcing() { + se := a.NewCMDOpts() + se.Command = fmt.Sprintf("restorecon -rv %s", self) + out := a.CmdV2(se) + a.Logger.Debugln("%+v\n", out) + } + opts := a.NewCMDOpts() opts.Detached = true opts.Command = "systemctl restart tacticalagent.service"