本文整理汇总了Python中spwd.getspnam方法的典型用法代码示例。如果您正苦于以下问题:Python spwd.getspnam方法的具体用法?Python spwd.getspnam怎么用?Python spwd.getspnam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spwd
的用法示例。
在下文中一共展示了spwd.getspnam方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_authentication
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def validate_authentication(self, username, password, handler):
"""Authenticates against shadow password db; raises
AuthenticationFailed in case of failed authentication.
"""
if username == "anonymous":
if self.anonymous_user is None:
raise AuthenticationFailed(self.msg_anon_not_allowed)
else:
try:
pw1 = spwd.getspnam(username).sp_pwd
pw2 = crypt.crypt(password, pw1)
except KeyError: # no such username
raise AuthenticationFailed(self.msg_no_such_user)
else:
if pw1 != pw2:
raise AuthenticationFailed(self.msg_wrong_password)
示例2: setUp
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def setUp(self):
self.admin = credentials.UsernamePassword('admin', 'asdf')
self.alice = credentials.UsernamePassword('alice', 'foo')
self.badPass = credentials.UsernamePassword('alice', 'foobar')
self.badUser = credentials.UsernamePassword('x', 'yz')
self.checker = strcred.makeChecker('unix')
# Hack around the pwd and spwd modules, since we can't really
# go about reading your /etc/passwd or /etc/shadow files
if pwd:
database = UserDatabase()
for username, password in self.users.items():
database.addUser(
username, crypt.crypt(password, 'F/'),
1000, 1000, username, '/home/' + username, '/bin/sh')
self.patch(pwd, 'getpwnam', database.getpwnam)
if spwd:
self._spwd_getspnam = spwd.getspnam
spwd.getspnam = self._spwd
示例3: tearDown
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def tearDown(self):
if spwd:
spwd.getspnam = self._spwd_getspnam
示例4: _shadowGetByName
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def _shadowGetByName(username):
"""
Look up a user in the /etc/shadow database using the spwd module. If it is
not available, return L{None}.
@param username: the username of the user to return the shadow database
information for.
@type username: L{str}
"""
if spwd is not None:
f = spwd.getspnam
else:
return None
return runAsEffectiveUser(0, 0, f, username)
示例5: checkSpwd
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def checkSpwd(self, spwd, username, password):
try:
cryptedPass = spwd.getspnam(username)[1]
except KeyError:
return defer.fail(UnauthorizedLogin())
else:
if verifyCryptedPassword(cryptedPass, password):
return defer.succeed(username)
示例6: checkSpwd
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def checkSpwd(self, spwd, username, password):
"""
Obtain the encrypted password for C{username} from the
Unix shadow password database using L{spwd.getspnam},
and see if it it matches it matches C{password}.
@param spwd: Module which provides functions which
access to the Unix shadow password database.
@type pwd: C{module}
@param username: The user to look up in the Unix password database.
@type username: L{unicode}/L{str} or L{bytes}
@param password: The password to compare.
@type username: L{unicode}/L{str} or L{bytes}
"""
try:
if not isinstance(username, StringType):
username = username.decode('utf-8')
if getattr(spwd.struct_spwd, "sp_pwdp", None):
# Python 3
cryptedPass = spwd.getspnam(username).sp_pwdp
else:
# Python 2
cryptedPass = spwd.getspnam(username).sp_pwd
except KeyError:
return defer.fail(UnauthorizedLogin())
else:
if verifyCryptedPassword(cryptedPass, password):
return defer.succeed(username)
示例7: get_password_hash
# 需要导入模块: import spwd [as 别名]
# 或者: from spwd import getspnam [as 别名]
def get_password_hash(username):
"""
Fetch a user's password hash.
"""
try:
h = spwd.getspnam(username)
except KeyError:
return None
# mitogen.core.Secret() is a Unicode subclass with a repr() that hides the
# secret data. This keeps secret stuff out of logs. Like blobs, secrets can
# also be serialized.
return mitogen.core.Secret(h)