Python中的spwd模块
Python中的spwd module
提供对Unix 影子密码数据库的访问。存储在数据库中的条目是类似元组的对象,其属性类似于
以下是元组对象的属性,它表示存储在Unix 影子密码数据库中的条目:
Index | Attributes | Meaning |
---|---|---|
0 | sp_namp | Login name |
1 | sp_pwdp | Encrypted password |
2 | sp_lstchg | Date of last change |
3 | sp_min | Minimal number of days between changes |
4 | sp_max | Maximum number of days between changes |
5 | sp_warn | Number of days before password expires to warn user about it |
6 | sp_inact | Number of days after password expires until account is disabled |
7 | sp_expire | Number of days since 1970-01-01 when account expires |
8 | sp_flag | Reserved |
Python中的spwd module
定义了以下两种方法:
-
spwd.getspnam() method
-
spwd.getspall() method
注意: spwd
模块是 UNIX 特定的服务。因此,该模块的所有方法仅在 UNIX 版本上可用。
spwd.getspnam() 方法 -
Python中的spwd.getspnam()
方法用于获取存储在 Unix 影子密码数据库中的指定用户名的条目。
此方法要求用户有足够的权限来访问影子密码数据库。如果用户没有足够的权限,将引发PermissionError异常。
Syntax: spwd.getspnam(name)
Parameter:
name: A string value representing the user name for which shadow password database entry is required.
Return type: This method returns a tuple-like object of class ‘spwd.struct_spwd’ which represents the shadow password database entry associated with the specified user name.
代码: 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()
方法用于获取存储在影子密码数据库中的所有可用条目。此方法还要求用户具有足够的权限来访问影子密码数据库。
Syntax: spwd.getspall()
Parameter: No parameter is required.
Return type: This method returns a list of tuple-like object of class ‘spwd.struct_spwd’ whose elements represent the shadow password database entries.
代码: 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)