pam-python 在执行脚本时不会向用户发送输出,仅在脚本完成时才向用户发送输出。下面的示例模拟了向用户发出的指令和一些 api 调用来完成该过程。没有用户交互。输出仅在脚本完成时发送给用户。
import sys
import time
def pam_sm_authenticate(pamh, flags, argv):
try:
# simulate sending instructions (10 lines) to the user, which needs to be displayed
for i in range(10):
msg = pamh.Message(pamh.PAM_TEXT_INFO, 'Some important information')
pamh.conversation(msg)
# simulate doing some api calls to conclude the authentication process
for i in range(5):
msg = pamh.Message(pamh.PAM_TEXT_INFO, 'Some important information')
pamh.conversation(msg)
time.sleep(1)
except Exception as e:
print(f"Exception occurred: {e}")
return 1
return 0
def pam_sm_setcred(pamh, flags, argv):
return 0
auth requisite /lib/x86_64-linux-gnu/security/pam_python3.so /lib/x86_64-linux-gnu/security/test.py
#
Ubuntu 24.04.1 LTS 上有趣的旁注,它向用户发送两次输出?!
我认为一些注释和示例可以帮助您。
login account requisite pam_python.so pam_accept.py
login auth requisite pam_python.so pam_accept.py
login password requisite pam_python.so pam_accept.py
login session requisite pam_python.so pam_accept.py