13
13
# See the Licence for the specific language governing permissions and
14
14
# limitations under the Licence.
15
15
16
- import pam
17
- import pwd
16
+ """Module containing the PAM auth provider for the Synapse Matrix server."""
18
17
18
+ import pwd
19
19
from collections import namedtuple
20
+
21
+ import pam
20
22
from twisted .internet import defer
21
23
24
+
22
25
class PAMAuthProvider :
26
+ """PAM auth provider for the Synapse Matrix server."""
27
+
23
28
def __init__ (self , config , account_handler ):
24
29
self .account_handler = account_handler
25
30
self .create_users = config .create_users
26
31
self .skip_user_check = config .skip_user_check
27
32
28
33
@defer .inlineCallbacks
29
34
def check_password (self , user_id , password ):
30
- """ Attempt to authenticate a user against PAM
31
- and register an account if none exists.
32
-
33
- Returns:
34
- True if authentication against PAM was successful
35
- """
35
+ """Check user/password against PAM, optionally creating the user."""
36
36
if not password :
37
37
defer .returnValue (False )
38
38
# user_id is of the form @foo:bar.com
@@ -46,7 +46,8 @@ def check_password(self, user_id, password):
46
46
defer .returnValue (False )
47
47
48
48
# Now check the password
49
- if not pam .pam ().authenticate (localpart , password , service = 'matrix-synapse' ):
49
+ if not pam .pam ().authenticate (localpart , password ,
50
+ service = 'matrix-synapse' ):
50
51
defer .returnValue (False )
51
52
52
53
# From here on, the user is authenticated
@@ -63,6 +64,7 @@ def check_password(self, user_id, password):
63
64
64
65
@staticmethod
65
66
def parse_config (config ):
67
+ """Parse the configuration for use in __init__."""
66
68
pam_config = namedtuple ('_Config' , 'create_users' )
67
69
pam_config .create_users = config .get ('create_users' , True )
68
70
pam_config .skip_user_check = config .get ('skip_user_check' , False )
0 commit comments