Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ It can take the following parameters:
This is the SQLite file that is used to store the offline authentication
information.
The default file is /etc/privacyidea/pam.sqlite

**no_authtok**

Do not set pam authtok to user input from OTP prompt.
Useful if you want pam_unix to ask for user password after OTP authentication.
13 changes: 9 additions & 4 deletions privacyidea_pam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2020-03-12 Julian Golderer <julian.golderer@fhv.at>
# Add parameter "no_authtok": do not set pam authtok
# 2016-08-31 Cornelius Kölbel <cornelius.koelgel@netknights.it>
# Add header user-agent to request
# 2015-03-04 Cornelius Kölbel <cornelius.koelbel@netknights.it>
Expand Down Expand Up @@ -311,6 +313,7 @@ def pam_sm_authenticate(pamh, flags, argv):
debug = config.get("debug")
try_first_pass = config.get("try_first_pass")
prompt = config.get("prompt", "Your OTP")
no_authtok = config.get("no_authtok")
if prompt[-1] != ":":
prompt += ":"
rval = pamh.PAM_AUTH_ERR
Expand All @@ -321,22 +324,24 @@ def pam_sm_authenticate(pamh, flags, argv):
if pamh.authtok is None or not try_first_pass:
message = pamh.Message(pamh.PAM_PROMPT_ECHO_OFF, "%s " % prompt)
response = pamh.conversation(message)
pamh.authtok = response.resp
if not no_authtok:
pamh.authtok = response.resp

if debug and try_first_pass:
syslog.syslog(syslog.LOG_DEBUG, "%s: running try_first_pass" %
__name__)
rval = Auth.authenticate(pamh.authtok)
rval = Auth.authenticate(response.resp)

# If the first authentication did not succeed but we have
# try_first_pass, we ask again for a password:
if rval != pamh.PAM_SUCCESS and try_first_pass:
# Now we give it a second try:
message = pamh.Message(pamh.PAM_PROMPT_ECHO_OFF, "%s " % prompt)
response = pamh.conversation(message)
pamh.authtok = response.resp
if not no_authtok:
pamh.authtok = response.resp

rval = Auth.authenticate(pamh.authtok)
rval = Auth.authenticate(response.resp)

except Exception as exx:
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
Expand Down