MCPcopy Create free account
hub / github.com/saltstack/salt / verify_env

Function verify_env

salt/utils/verify.py:233–330  ·  view source on GitHub ↗

Verify that the named directories are in place and that the environment can shake the salt

(
    dirs, user, permissive=False, pki_dir="", skip_extra=False, root_dir=ROOT_DIR
)

Source from the content-addressed store, hash-verified

231
232
233def verify_env(
234 dirs, user, permissive=False, pki_dir="", skip_extra=False, root_dir=ROOT_DIR
235):
236 """
237 Verify that the named directories are in place and that the environment
238 can shake the salt
239 """
240 if salt.utils.platform.is_windows():
241 return win_verify_env(
242 root_dir, dirs, permissive=permissive, skip_extra=skip_extra
243 )
244
245 # after confirming not running Windows
246 pwnam = _get_pwnam(user)
247 uid = pwnam[2]
248 gid = pwnam[3]
249 groups = salt.utils.user.get_gid_list(user, include_default=False)
250
251 for dir_ in dirs:
252 if not dir_:
253 continue
254 if not os.path.isdir(dir_):
255 try:
256 with salt.utils.files.set_umask(0o022):
257 os.makedirs(dir_)
258 # If starting the process as root, chown the new dirs
259 if os.getuid() == 0:
260 os.chown(dir_, uid, gid)
261 except OSError as err:
262 msg = 'Failed to create directory path "{0}" - {1}\n'
263 sys.stderr.write(msg.format(dir_, err))
264 sys.exit(err.errno)
265
266 mode = os.stat(dir_)
267 # If starting the process as root, chown the new dirs
268 if os.getuid() == 0:
269 fmode = os.stat(dir_)
270 if fmode.st_uid != uid or fmode.st_gid != gid:
271 if permissive and fmode.st_gid in groups:
272 # Allow the directory to be owned by any group root
273 # belongs to if we say it's ok to be permissive
274 pass
275 else:
276 # chown the file for the new user
277 os.chown(dir_, uid, gid)
278 for subdir in [a for a in os.listdir(dir_) if "jobs" not in a]:
279 fsubdir = os.path.join(dir_, subdir)
280 if f"{os.path.sep}jobs" in fsubdir:
281 continue
282 for root, dirs, files in salt.utils.path.os_walk(fsubdir):
283 for name in itertools.chain(files, dirs):
284 if name.startswith("."):
285 continue
286 path = os.path.join(root, name)
287 try:
288 fmode = os.stat(path)
289 if fmode.st_uid != uid or fmode.st_gid != gid:
290 if permissive and fmode.st_gid in groups:

Callers 8

runMethod · 0.90
verify_environmentMethod · 0.90
prepareMethod · 0.90
prepareMethod · 0.90
prepareMethod · 0.90
runMethod · 0.90
get_temp_configMethod · 0.90
get_temp_configMethod · 0.90

Calls 6

win_verify_envFunction · 0.85
_get_pwnamFunction · 0.85
zmq_versionFunction · 0.85
formatMethod · 0.80
exitMethod · 0.80
writeMethod · 0.45

Tested by 1

get_temp_configMethod · 0.72