From: John Hodge Date: Sun, 23 Jun 2019 06:38:36 +0000 (+0800) Subject: Switch pin checks from filesystem to dispense server X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=commitdiff_plain;h=87633e7337e6bcf46a0be2fb057022ce8fb2eb7e Switch pin checks from filesystem to dispense server --- diff --git a/VendServer/OpenDispense.py b/VendServer/OpenDispense.py index 5e41363..79cec66 100644 --- a/VendServer/OpenDispense.py +++ b/VendServer/OpenDispense.py @@ -30,6 +30,41 @@ class OpenDispense(DispenseInterface): pass def authUserIdPin(self, userId, pin): + return self.authUserIdPin_db(userId, pin) + #return self.authUserIdPin_file(userId, pin) + + def authUserIdPin_db(self, userId, pin): + userId = int(userId) + + try: + # Get username (TODO: Store the user ID in the dispense database too) + info = pwd.getpwuid(userId) + except KeyError: + logging.info('getting pin for uid %d: user not in password file'%userId) + return False + + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) + sock.connect(DISPENSE_ENDPOINT) + logging.debug('connected to dispsrv') + sockf = sock.makefile() + sockf.write("AUTHIDENT\n"); sockf.flush() + rsp = sockf.readline() + assert "200" in rsp + logging.debug('authenticated') + sockf.write("PIN_CHECK %s %s\n" % (info.pw_name, pin)); sockf.flush() + rsp = sockf.readline() + if not "200" in rsp: + logging.info('checking pin for uid %d: Server said no - %r' % (userId, rsp)) + return False + #Login Successful + logging.info('accepted pin for uid %d \'%s\'' % (userId, info.pw_name)) + self._userid = userId + self._loggedIn = True + self._disabled = False + self._username = info.pw_name + return True + + def authUserIdPin_file(self, userId, pin): userId = int(userId) try: @@ -89,7 +124,7 @@ class OpenDispense(DispenseInterface): rsp = sockf.readline() if not "200" in rsp: logging.info("Rejected card base64:%s" % (card_base64,)) - return False + return False username = rsp.split('=')[1].strip() logging.info("Accepted card base64:%s for %s" % (card_base64,username,))