MCPcopy
hub / github.com/slimtoolkit/slim / homeDirs

Function homeDirs

pkg/app/sensor/artifact/artifact.go:1114–1161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1112}
1113
1114func homeDirs() []string {
1115 dirMap := map[string]struct{}{}
1116 var done bool
1117 if fsutil.Exists(sysidentity.PasswdFilePath) {
1118 info, err := sysidentity.ReadPasswdFile(sysidentity.PasswdFilePath)
1119 if err != nil {
1120 log.Debugf("sensor.store.homeDirs: error processing passwd: %v", err)
1121 } else {
1122 for _, pr := range info.Records {
1123 if pr.NoLoginShell || pr.Home == "" {
1124 continue
1125 }
1126
1127 dirMap[pr.Home] = struct{}{}
1128 }
1129
1130 done = true
1131 }
1132 }
1133
1134 if !done {
1135 // hacky way to get the home directories for users...
1136 rootDir := "/root"
1137 if !fsutil.DirExists(rootDir) {
1138 dirMap[rootDir] = struct{}{}
1139 }
1140
1141 homeBaseDir := "/home"
1142 hdFiles, err := os.ReadDir(homeBaseDir)
1143 if err == nil {
1144 for _, file := range hdFiles {
1145 fullPath := filepath.Join(homeBaseDir, file.Name())
1146 if fsutil.IsDir(fullPath) {
1147 dirMap[fullPath] = struct{}{}
1148 }
1149 }
1150 } else {
1151 log.Debugf("sensor.store.homeDirs: error enumerating %s: %v", homeBaseDir, err)
1152 }
1153 }
1154
1155 var dirList []string
1156 for dp := range dirMap {
1157 dirList = append(dirList, dp)
1158 }
1159
1160 return dirList
1161}
1162
1163func (ref *store) saveSSHClient() {
1164 if !ref.cmd.IncludeSSHClient {

Callers 1

saveSSHClientMethod · 0.85

Calls 5

ExistsFunction · 0.92
ReadPasswdFileFunction · 0.92
DirExistsFunction · 0.92
IsDirFunction · 0.92
NameMethod · 0.65

Tested by

no test coverage detected