Commit b04e2738 authored by Cornelius Kölbel's avatar Cornelius Kölbel

Add tokentype to PAM offline database

parent 8cba124e
...@@ -98,6 +98,8 @@ def pam_sm_authenticate(pamh, flags, argv): ...@@ -98,6 +98,8 @@ def pam_sm_authenticate(pamh, flags, argv):
auth_item = json_response.get("auth_items") auth_item = json_response.get("auth_items")
serial = json_response.get("detail", {}).get("serial", serial = json_response.get("detail", {}).get("serial",
"T%s" % time.time()) "T%s" % time.time())
tokentype = json_response.get("detail", {}).get("type",
"unknown")
if debug: if debug:
syslog.syslog(syslog.LOG_DEBUG, "%s: result: %s" % (__name__, syslog.syslog(syslog.LOG_DEBUG, "%s: result: %s" % (__name__,
result)) result))
...@@ -105,7 +107,7 @@ def pam_sm_authenticate(pamh, flags, argv): ...@@ -105,7 +107,7 @@ def pam_sm_authenticate(pamh, flags, argv):
if result.get("status"): if result.get("status"):
if result.get("value"): if result.get("value"):
rval = pamh.PAM_SUCCESS rval = pamh.PAM_SUCCESS
save_auth_item(sqlfile, user, serial, auth_item) save_auth_item(sqlfile, user, serial, tokentype, auth_item)
else: else:
rval = pamh.PAM_AUTH_ERR rval = pamh.PAM_AUTH_ERR
else: else:
...@@ -189,7 +191,7 @@ def check_offline_otp(user, otp, sqlfile, window=10): ...@@ -189,7 +191,7 @@ def check_offline_otp(user, otp, sqlfile, window=10):
return res return res
def save_auth_item(sqlfile, user, serial, authitem): def save_auth_item(sqlfile, user, serial, tokentype, authitem):
""" """
Save the given authitem to the sqlite file to be used later for offline Save the given authitem to the sqlite file to be used later for offline
authentication. authentication.
...@@ -202,6 +204,7 @@ def save_auth_item(sqlfile, user, serial, authitem): ...@@ -202,6 +204,7 @@ def save_auth_item(sqlfile, user, serial, authitem):
:type sqlfile: basestring :type sqlfile: basestring
:param user: The PAM user :param user: The PAM user
:param serial: The serial number of the token :param serial: The serial number of the token
:param tokentype: The type of the token
:param authitem: A dictionary with all authitem information being: :param authitem: A dictionary with all authitem information being:
username, count, and a response dict with counter and otphash. username, count, and a response dict with counter and otphash.
...@@ -241,6 +244,7 @@ def _create_table(c): ...@@ -241,6 +244,7 @@ def _create_table(c):
try: try:
c.execute("CREATE TABLE authitems " c.execute("CREATE TABLE authitems "
"(counter int, user text, serial text, tokenowner text," "(counter int, user text, serial text, tokenowner text,"
"otp text)") "otp text, tokentype text)")
except: except:
pass pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment