+ if card_base64 in CARD_BLACKLIST:
+ logging.info("Blacklisted card base64:%s" % (card_base64,))
+ 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("AUTHCARD %s\n" % (card_base64,)); sockf.flush()
+ rsp = sockf.readline()
+ if not "200" in rsp:
+ logging.info("Rejected card base64:%s" % (card_base64,))
+ return False
+ username = rsp.split('=')[1].strip()
+ logging.info("Accepted card base64:%s for %s" % (card_base64,username,))
+
+ ## Check for thier username
+ #try:
+ # # Get info from the system (by username)
+ # info = pwd.getpwnam(username)
+ #except KeyError:
+ # logging.info('getting info for user \'%s\': user not in password file' % (username,))
+ # return False
+ #self._userid = info.pw_uid
+ self._userid = None
+ self._username = username
+ else:
+ # Get the users ID
+ self._userid = get_uid(cardId)
+
+ # Check for thier username
+ try:
+ # Get info from the system (by UID)
+ info = pwd.getpwuid(self._userid)
+ except KeyError:
+ logging.info('getting info for uid %d: user not in password file' % (self._userid,))
+ return False
+ self._username = info.pw_name