pam-python 在身份验证过程中不会将输出发送回用户

问题描述 投票:0回答:1

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 上有趣的旁注,它向用户发送两次输出?!

authentication pam pam-python
1个回答
0
投票

我认为一些注释和示例可以帮助您。

  1. “返回 0”- 这是错误! Pam 使用她自己的变量。下一个代码示例https://github.com/Ralnoc/pam-python/blob/master/examples/pam_deny.py
  2. 发送消息。显示示例 https://pam-python.sourceforge.net/examples/pam_nologin.py
  3. 选择验证阶段。您是否正确选择了“auth Requirement”验证阶段? 我们的操作可以分 4 个阶段执行:帐户、身份验证、密码、会话
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
© www.soinside.com 2019 - 2024. All rights reserved.