Switch pin checks from filesystem to dispense server
authorJohn Hodge <tpg@ucc.asn.au>
Sun, 23 Jun 2019 06:38:36 +0000 (14:38 +0800)
committerroot <root@ucc.gu.uwa.edu.au>
Sun, 23 Jun 2019 06:38:36 +0000 (14:38 +0800)
VendServer/OpenDispense.py

index 5e41363..79cec66 100644 (file)
@@ -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,))
 

UCC git Repository :: git.ucc.asn.au