简介
pwd可以访问Unix shadow密码数据库。 2.5新增。通常需要为root用户。
密码数据库项由结构体spwd(类似元组)表示,参见shadow.h:
序号 | 属性 | 含义 |
---|---|---|
0 | sp_nam | Login name |
1 | sp_pwd | 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 blocked |
7 | sp_expire | Number of days since 1970-01-01 until account is disabled |
8 | sp_flag | Reserved |
sp_nam和sp_pwd为字符串,其他为整型。
spwd方法
-
spwd.getspnam(name)
Return the shadow password database entry for the given user name.
-
spwd.getspall()
Return a list of all available shadow password database entries, in arbitrary order.
"""
Name: spwd_demo.py
Tesed in python3.5/2.7/2.6
"""
import os
import spwd
print(spwd.getspnam('root'))
print("------ All Passwords ------")
for item in spwd.getspall():
print(item)
执行结果:
# python3 spwd_demo.py
spwd.struct_spwd(sp_namp='root', sp_pwdp='$6$lI1PEE0n$aM1p4k/rycTFYmS44mKPulvtPTxpVmZ7BH.bIuqoOI2ZDJUgQqTgSBEAEPdhLgVhFygwlZkOInP0RMxIk0dQE1', sp_lstchg=16916, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
------ All Passwords ------
spwd.struct_spwd(sp_namp='root', sp_pwdp='$6$lI1PEE0n$aM1p4k/rycTFYmS44mKPulvtPTxpVmZ7BH.bIuqoOI2ZDJUgQqTgSBEAEPdhLgVhFygwlZkOInP0RMxIk0dQE1', sp_lstchg=16916, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1)
...
$ python spwd_demo.py
Traceback (most recent call last):
File "spwd_demo.py", line 12, in <module>
print(spwd.getspnam('root'))
KeyError: 'getspnam(): name not found'
可见用普通用户执行会报异常KeyError。
参考资料
- python测试等IT技术支持qq群: 144081101(后期会录制视频存在该群群文件) 591302926 567351477
- 道家技术-手相手诊看相中医等钉钉群21734177 qq群:391441566 184175668 338228106 看手相、面相、舌相、抽签、体质识别。服务费50元每人次起。请联系钉钉或者微信pythontesting
- 本文最新版本地址
- 本文涉及的python测试开发库 谢谢点赞!
- 本文相关海量书籍下载
- 接口自动化性能测试线上培训大纲
- python官方文档:https://docs.python.org/3/library/spwd.html
- pymotw文档:https://pymotw.com/3/enum/index.html