Skip to content

Commit

Permalink
Appease python style gods
Browse files Browse the repository at this point in the history
  • Loading branch information
14mRh4X0r committed Sep 22, 2021
1 parent 9326aa4 commit 36d6676
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pam_auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
# See the Licence for the specific language governing permissions and
# limitations under the Licence.

import pam
import pwd
"""Module containing the PAM auth provider for the Synapse Matrix server."""

import pwd
from collections import namedtuple

import pam
from twisted.internet import defer


class PAMAuthProvider:
"""PAM auth provider for the Synapse Matrix server."""

def __init__(self, config, account_handler):
self.account_handler = account_handler
self.create_users = config.create_users
self.skip_user_check = config.skip_user_check

@defer.inlineCallbacks
def check_password(self, user_id, password):
""" Attempt to authenticate a user against PAM
and register an account if none exists.
Returns:
True if authentication against PAM was successful
"""
"""Check user/password against PAM, optionally creating the user."""
if not password:
defer.returnValue(False)
# user_id is of the form @foo:bar.com
Expand All @@ -46,7 +46,8 @@ def check_password(self, user_id, password):
defer.returnValue(False)

# Now check the password
if not pam.pam().authenticate(localpart, password, service='matrix-synapse'):
if not pam.pam().authenticate(localpart, password,
service='matrix-synapse'):
defer.returnValue(False)

# From here on, the user is authenticated
Expand All @@ -63,6 +64,7 @@ def check_password(self, user_id, password):

@staticmethod
def parse_config(config):
"""Parse the configuration for use in __init__."""
pam_config = namedtuple('_Config', 'create_users')
pam_config.create_users = config.get('create_users', True)
pam_config.skip_user_check = config.get('skip_user_check', False)
Expand Down

0 comments on commit 36d6676

Please sign in to comment.