use cwd for everything

This commit is contained in:
wh1te909 2023-03-29 17:41:24 +00:00
parent 407f2a8072
commit 56cbf8a9d7
5 changed files with 27 additions and 79 deletions

View File

@ -1,16 +0,0 @@
/*
Copyright 2022 AmidaWare LLC.
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 tmpNoExec() bool {
return false
}

View File

@ -1,30 +0,0 @@
/*
Copyright 2022 AmidaWare LLC.
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 (
"os"
"syscall"
)
func tmpNoExec() bool {
var stat syscall.Statfs_t
var noexec bool
tmpdir := os.TempDir()
if err := syscall.Statfs(tmpdir, &stat); err == nil {
if stat.Flags&syscall.MS_NOEXEC != 0 {
noexec = true
}
}
return noexec
}

View File

@ -230,11 +230,9 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
cwd := filepath.Dir(self)
// create a tmpfile in same location as current binary
// avoids issues with /tmp dir and other fs mount issues
tmpfile := filepath.Join(cwd, GenerateAgentID())
f, err := os.Create(tmpfile)
f, err := os.CreateTemp(cwd, "trmm")
if err != nil {
a.Logger.Errorln("AgentUpdate() os.Create(tmpfile)", err)
a.Logger.Errorln("AgentUpdate() os.CreateTemp:", err)
return
}
defer os.Remove(f.Name())
@ -477,26 +475,6 @@ func (a *Agent) GetWMIInfo() map[string]interface{} {
return wmiInfo
}
func createNixTmpFile() (*os.File, error) {
var f *os.File
noexec := tmpNoExec()
f, err := os.CreateTemp("", "trmm")
if err != nil || noexec {
if noexec {
os.Remove(f.Name())
}
cwd, err := os.Getwd()
if err != nil {
return f, err
}
f, err = os.CreateTemp(cwd, "trmm")
if err != nil {
return f, err
}
}
return f, nil
}
// windows only below TODO add into stub file
func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig {
return ret

View File

@ -906,12 +906,3 @@ func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig
func (a *Agent) NixMeshNodeID() string {
return "not implemented"
}
func tmpNoExec() bool {
return false
}
func createNixTmpFile() (*os.File, error) {
var f *os.File
return f, nil
}

View File

@ -340,3 +340,28 @@ func getCMDExe() string {
}
return cmdExe
}
// more accurate than os.Getwd()
func getCwd() (string, error) {
self, err := os.Executable()
if err != nil {
return "", err
}
return filepath.Dir(self), nil
}
func createNixTmpFile() (*os.File, error) {
var f *os.File
cwd, err := getCwd()
if err != nil {
return f, err
}
f, err = os.CreateTemp(cwd, "trmm")
if err != nil {
return f, err
}
return f, nil
}