1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 PAM authentication classes.
18 """
19
20 import PAM as _PAM
21 from logging import getLogger
22
23 log = getLogger(__name__)
24
25
27
29 self.user = user
30 self.password = password
31
33 resp = []
34 for query, type in query_list:
35
36 if type == _PAM.PAM_PROMPT_ECHO_ON:
37 resp.append((self.user, 0))
38 continue
39
40 if type == _PAM.PAM_PROMPT_ECHO_OFF:
41 resp.append((self.password, 0))
42 continue
43 return resp
44
45
47 """
48 PAM object used for authentication.
49 @cvar SERVICE: The default service
50 @type SERVICE: str
51 """
52
53 SERVICE = 'passwd'
54
56 """
57 Authenticate the specified user.
58 @param user: A user name.
59 @type user: str
60 @param password: A password.
61 @type password: str
62 @param service: The optional PAM service.
63 @type service: str
64 @raise Exception: when authentication fails.
65 """
66 if not service:
67 service = self.SERVICE
68 q = Query(user, password)
69 auth = _PAM.pam()
70 auth.start(service, user, q)
71 auth.authenticate()
72 auth.acct_mgmt()
73