我正在尝试使用 PAM 和 pam_timestamp 模块来减少需要输入的密码数量。
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <pwd.h>
#include <sys/types.h>
#include <stdio.h>
#define MY_CONFIG "myconfig"
static struct pam_conv conv = { misc_conv, NULL };
main( )
{
pam_handle_t *pamh;
int result;
struct passwd *pw;
if ((pw = getpwuid(getuid( ))) == NULL)
perror("getpwuid");
else if ((result = pam_start(MY_CONFIG, pw->pw_name, &conv, &pamh)) != PAM_SUCCESS)
fprintf(stderr, "start failed: %d\n", result);
else if ((result = pam_authenticate(pamh, 0)) != PAM_SUCCESS)
fprintf(stderr, "authenticate failed: %d\n", result);
else if ((result = pam_acct_mgmt(pamh, 0)) != PAM_SUCCESS)
fprintf(stderr, "acct_mgmt failed: %d\n", result);
else if ((result = pam_end(pamh, result)) != PAM_SUCCESS)
fprintf(stderr, "end failed: %d\n", result);
else
fprintf(stderr, "SUCCESS!\n");
}
测试 pam 配置/etc/pam.d/myconfig
- 这是直接来自手册页
auth sufficient pam_timestamp.so verbose
auth required pam_unix.so
session required pam_unix.so
session optional pam_timestamp.so
但是,当我运行测试程序时,它总是要求输入密码,我本来期望它在创建时间戳文件后不会询问。
nfultz@neal-slg2:/tmp/pamapp$ ./a.out
Password:
SUCCESS!
nfultz@neal-slg2:/tmp/pamapp$ ./a.out
Password:
authenticate failed: 7
如果重要的话,这是在 Ubuntu 23.04 上。