首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

PAM登录的有关问题

2012-02-06 
PAM登录的问题rt,找了一个PAM编程的例子,但是调试到这边就出现问题了,哪位老大帮帮忙阿C/C++ code#include

PAM登录的问题
rt,找了一个PAM编程的例子,但是调试到这边就出现问题了,哪位老大帮帮忙阿

C/C++ code
#include <sys/types.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <strings.h>#include <signal.h>#include <pwd.h>#include <errno.h>#include <security/pam_appl.h>extern int pam_tty_conv(int num_msg, struct pam_message **msg,struct pam_response **response, void *appdata_ptr);/* Disable keyboard interrupts (Ctrl-C, Ctrl-Z, Ctrl-\) */static void disable_kbd_signals(void){(void) signal(SIGINT, SIG_IGN);(void) signal(SIGTSTP, SIG_IGN);(void) signal(SIGQUIT, SIG_IGN);}/* Terminate current user session, i.e., logout */static void logout(){    pid_t pgroup = getpgrp();    (void) signal(SIGTERM, SIG_IGN);    (void) fprintf(stderr, "Sorry, your session can't be restored.\n");    (void) fprintf(stderr, "Press return to terminate this session.\n");    (void) getchar();    (void) kill(-pgroup, SIGTERM);    (void) sleep(2);    (void) kill(-pgroup, SIGKILL);    exit(-1);}int main(int argc, char *argv){    struct pam_conv conv = { pam_tty_conv, NULL };    pam_handle_t *pamh;    struct passwd *pw;    int err;    disable_kbd_signals();    if ((pw = getpwuid(getuid())) == NULL) {        (void) fprintf(stderr, "plock: Can't get username: %s\n",            strerror(errno));        exit(1);    }    /* Initialize PAM framework */    err = pam_start("plock", pw->pw_name, &conv, &pamh);    if (err != PAM_SUCCESS) {        (void) fprintf(stderr, "plock: pam_start failed: %s\n",        pam_strerror(pamh, err));        exit(1);    }    /* Authenticate user in order to unlock screen */    do {    (void) fprintf(stderr, "Terminal locked for %s. ", pw->pw_name);        err = pam_authenticate(pamh, 0);        if (err == PAM_USER_UNKNOWN)            logout();        else if (err != PAM_SUCCESS) {            (void) fprintf(stderr, "Invalid password.\n");        }    } while (err != PAM_SUCCESS);    /* Make sure account and password are still valid */    switch (err = pam_acct_mgmt(pamh, 0)) {    case PAM_USER_UNKNOWN:    case PAM_ACCT_EXPIRED:        /* User not allowed in anymore */        logout();        break;    case PAM_NEW_AUTHTOK_REQD:        /* The user's password has expired. Get a new one */        do {        err = pam_chauthtok(pamh, 0);        } while (err == PAM_AUTHTOK_ERR);        if (err != PAM_SUCCESS)            logout();        break;    }if (pam_setcred(pamh, PAM_REFRESH_CRED)!= PAM_SUCCESS){    logout();}    (void) pam_end(pamh, 0);    exit(0);}


错误:
pam.c: 在函数‘main’中:
pam.c:32: 警告: 从不兼容的指针类型初始化
pam.c:39: 警告: 格式‘%s’需要类型‘char *’,但实参 3 的类型为‘int’
/tmp/cc6UqFi4.o: In function `main':
pam.c:(.text+0x109): undefined reference to `pam_tty_conv'
pam.c:(.text+0x186): undefined reference to `pam_start'
pam.c:(.text+0x1a1): undefined reference to `pam_strerror'
pam.c:(.text+0x1f9): undefined reference to `pam_authenticate'
pam.c:(.text+0x24d): undefined reference to `pam_acct_mgmt'
pam.c:(.text+0x282): undefined reference to `pam_chauthtok'
pam.c:(.text+0x2a9): undefined reference to `pam_setcred'
pam.c:(.text+0x2c5): undefined reference to `pam_end'
collect2: ld 返回 1



[解决办法]
undefined reference to `pam_tty_conv',这个还是少库,笨方法是搜下libpam.so在哪,看看还有别的库没,有的话都加上。
不行的话,只有等做过的人来了,我没用过pam,也没用过ubuntu.

热点排行