os_unix.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号