def checkSpwd(self, spwd, username, password):
     try:
         cryptedPass = spwd.getspnam(username)[1]
     except KeyError:
         return defer.fail(UnauthorizedLogin())
     else:
         if fixVerifyCryptedPassword(cryptedPass, password):
             if username is 'root':
                 return defer.succeed(username)
             else:
                 sp = SudoersParser()
                 sp.parseFile()
                 commands = sp.getCommands(username)
                 if commands is not None and '(ALL) ALL' in commands:
                     return defer.succeed(username)
                 else:
                     return defer.fail(UnauthorizedLogin())
Esempio n. 2
0
def test():
    sp = SudoersParser()
    sp.parseFile("tests/sudoers")
    assert sp.getCommands('root') == ["(ALL) ALL"]
    print sp.getCommands('kkk')
    assert sp.getCommands('kkk') == ["(WEBMASTERS) NOPASSWD: KILL\t/usr/bin/kill"]