spwd module
在Python中提供了对Unix 影子密码数据库。数据库中存储的条目是类似元组的对象,其属性类似于元组的成员结构式定义于<shadow.h>头文件.
以下是类元组对象的属性,它表示存储在 Unix 影子密码数据库中的条目:
index | 属性 | 意义 |
---|---|---|
0 | sp_namp | 登录名 |
1 | sp_pwdp | 加密密码 |
2 | sp_lstchg | 最后更改日期 |
3 | sp_min | 更改之间的最短天数 |
4 | sp_max | 更改之间的最大天数 |
5 | sp_warn | 密码过期前警告用户的天数 |
6 | sp_inact | 密码过期后到帐户被禁用的天数 |
7 | sp_expire | 自 1970-01-01 帐户到期以来的天数 |
8 | sp_flag | Reserved |
Python中的spwd module
定义了以下两个方法:
spwd.getspnam() method
spwd.getspall() method
注意: spwd
模块是 UNIX 特定的服务。因此,该模块的所有方法仅在 UNIX 版本上可用。
spwd.getspnam()方法-
spwd.getspnam()
Python 中的方法用于获取存储在 Unix 影子密码数据库中的指定用户名的条目。
此方法要求用户有足够的权限来访问影子密码数据库。PermissionError如果用户没有足够的权限,则会引发异常。
用法: spwd.getspnam(name)
参数:
name:表示需要影子密码数据库条目的用户名的字符串值。
返回类型:此方法返回“spwd.struct_spwd”类的类似元组的对象,它表示与指定用户名关联的影子密码数据库条目。
代码:用于 spwd.getspnam()
方法
# Python program to explain spwd.getspnam() method
# importing spwd module
import spwd
# User name
name = "ihritik"
# Get the shadow password
# database entry for the
# specified user name
# using spwd.getspnam() method
entry = spwd.getspnam(name)
# Print the retrieved entry
print("Shadow password database entry for the user name '%s':" %name)
print(entry)
# User name
name = "root"
# Get the shadow password
# database entry for the
# specified user name
# using spwd.getspnam() method
entry = spwd.getspnam(name)
# Print the retrieved entry
print("\nShadow password database entry for the user name '%s':" %name)
print(entry)
输出:
spwd.getspall()方法-
Python 中的 spwd.getspall()
方法用于获取影子密码数据库中存储的所有可用条目。此方法还要求用户有足够的权限来访问影子密码数据库。
用法: spwd.getspall()
参数:不需要参数。
返回类型:此方法返回“spwd.struct_spwd”类的类元组对象列表,其元素表示影子密码数据库条目。
代码:用于spwd.getspall()
方法
# Python program to explain spwd.getspall() method
# importing spwd module
import spwd
# Get the all available
# shadow password database entries
# using spwd.getspall() method
entries = spwd.getspall()
# Print the retrieved entries
print("Shadow password database entries:")
for row in entries:
print(row)
Shadow password database entries:
spwd.struct_spwd(sp_namp=’root’, sp_pwdp=’!’, sp_lstchg=17677, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’daemon’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’bin’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’sys’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’sync’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’games’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’man’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’lp’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’mail’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’news’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’uucp’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’proxy’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’www-data’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’backup’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’list’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’irc’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’gnats’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’nobody’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’systemd-timesync’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’systemd-network’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’systemd-resolve’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’systemd-bus-proxy’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’syslog’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’messagebus’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’_apt’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’uuidd’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’rtkit’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’avahi-autoipd’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’usbmux’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’dnsmasq’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’whoopsie’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’kernoops’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’speech-dispatcher’, sp_pwdp=’!’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’avahi’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’saned’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’pulse’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’colord’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’hplip’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’geoclue’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’gdm’, sp_pwdp=’*’, sp_lstchg=17536, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’ihritik’, sp_pwdp=’$6$xOnnKlQr$yiKkE4XS1zT9mUj9NARHUTLZ8ibWurTx4pjQYOC58YHGGGBWTI3GIFKU4RUWC99JmPZIsfSlSvtm1GAyJL1G41′, sp_lstchg=17677, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’sshd’, sp_pwdp=’*’, sp_lstchg=17692, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
spwd.struct_spwd(sp_namp=’master’, sp_pwdp=’$6$oMUtyit0$zCrJ3K5XEWEhqclJW.rsL9SP3zWHkLhT8rQ75fhJ4P6zZlhF3aOfymQT8A/VRqkJrutWCuWXvaekMUP/IIgFG1′, sp_lstchg=17972, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
相关用法
- Python splitfields()用法及代码示例
- Python spongemock用法及代码示例
- Python staticmethod()用法及代码示例
- Python set()用法及代码示例
- Python setattr()用法及代码示例
- Python slice()用法及代码示例
- Python sorted()用法及代码示例
- Python str()用法及代码示例
- Python sum()用法及代码示例
- Python super()用法及代码示例
- Python strip()用法及代码示例
- Python sympy.gammasimp()用法及代码示例
- Python shutil.chown()用法及代码示例
- Python shutil.copy()用法及代码示例
- Python shutil.copy2()用法及代码示例
- Python shutil.copyfile()用法及代码示例
- Python shutil.copyfileobj()用法及代码示例
- Python shutil.copymode()用法及代码示例
- Python shutil.copystat()用法及代码示例
- Python shutil.copytree()用法及代码示例
- Python shutil.disk_usage()用法及代码示例
- Python shutil.get_archive_formats()用法及代码示例
- Python shutil.get_unpack_formats()用法及代码示例
- Python shutil.move()用法及代码示例
- Python shutil.unpack_archive()用法及代码示例
注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 spwd module in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。