def load_passwd(dirpath):
# check if we need to reload cache
passwd_file = os.path.join(dirpath, "etc/passwd")
passwd_stamp = os.stat(passwd_file).st_mtime
if passwd_stamp <= users_lastupdate.get(dirpath, -1):
return
users[dirpath] = user = {}
uids[dirpath] = uid = {}
f = open(passwd_file)
for line in f:
arr = line.rstrip().split(":")
if len(arr) != 7:
# Skip any line we can't make sense of.
continue
try:
arr[2] = int(arr[2])
arr[3] = int(arr[3])
except ValueError:
# Skip any line we can't make sense of.
continue
pw_entry = pwd.struct_passwd(arr)
user[pw_entry.pw_name] = pw_entry
# Traditional systems allow multiple users to have the same
# user id, so only the first one should be mapped to the
# current pw_entry.
uid.setdefault(pw_entry.pw_uid, pw_entry)
users_lastupdate[dirpath] = passwd_stamp
f.close()
评论列表
文章目录