我正在尝试开发一个简单的PAM模块 . 我想要的是捕获用户尝试通过SSH访问系统提供的用户名和密码,并委托给模块来决定是否连接 . 粗略地说,我想要做的是将这样的规则添加到pam.d中的sshd文件中:

auth sufficient pam_exec.so <my script> <username> <password>

但据我所知,这不是我能做的事情 .

我也尝试编写一个通过C "system" 函数调用脚本的自定义PAM模块,但我不清楚如何访问那里的用户名和密码 . 我想我应该能够通过p am_get_user 获取用户名和密码通过 pam_authenticate (我认为这些可能会要求第二次提示,而不仅仅是使用用户提供给ssh的凭据,但这也可以正常工作),但是pam_get_item的参考页面说:

PAM_AUTHTOK

The authentication token (often a password). This token should be 
ignored by all module functions besides pam_sm_authenticate(3) and 
pam_sm_chauthtok(3). In the former function it is used to pass the 
most recent authentication token from one stacked module to another. 
In the latter function the token is used for another purpose. It 
contains the currently active authentication token.

这听起来像我不能(或者可能只是不应该?)尝试从我自己的代码访问身份验证令牌 .