2016-03-25 92 views
2

我試圖編譯和構建以下非常簡單和直接的C程序:爲什麼不能我的節目鏈接爲pam_ *調用

#include <security/pam_appl.h> 
#include <security/pam_misc.h> 
#include <stdio.h> 
#include <string.h> 

// Define custom PAM conversation function 
int custom_conversation(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr) 
{ 
    // Provide password for the PAM conversation response that was passed into appdata_ptr 
    struct pam_response* reply = (struct pam_response*)malloc(sizeof(struct pam_response)); 
    reply[0].resp = (char*)appdata_ptr; 
    reply[0].resp_retcode = 0; 

    *resp = reply; 

    return PAM_SUCCESS; 
} 

int main (int argc, char* argv[]) 
{ 
    if (argc > 2) 
    { 
     // Set up a custom PAM conversation passing in authentication password 
     char* password = (char*)malloc(strlen(argv[2]) + 1); 
     strcpy(password, argv[2]);   
     struct pam_conv pamc = { custom_conversation, password }; 
     pam_handle_t* pamh; 
     int retval; 

     // Start PAM - just associate with something simple like the "whoami" command 
     if ((retval = pam_start("whoami", argv[1], &pamc, &pamh)) == PAM_SUCCESS) 
     { 
      // Authenticate the user 
      if ((retval = pam_authenticate(pamh, 0)) == PAM_SUCCESS) 
       fprintf(stdout, "OK\n"); 
      else 
       fprintf(stderr, "FAIL: pam_authentication failed.\n"); 

      // All done 
      pam_end(pamh, 0); 
      return retval; 
     } 
     else 
     { 
      fprintf(stderr, "FAIL: pam_start failed.\n"); 
      return retval; 
     } 
    } 

    fprintf(stderr, "FAIL: expected two arguments for user name and password.\n"); 
    return 1; 
} 

我發現它在谷歌的地方。問題是,它沒有找到主要爲pam_ *符號:

[email protected]:~$ gcc -o checkpwd -lpam -lpam_misc checkpwd.c 
/tmp/ccjIBywU.o: In Funktion `main': 
checkpwd.c:(.text+0xcf): Nicht definierter Verweis auf `pam_start' 
checkpwd.c:(.text+0xe9): Nicht definierter Verweis auf `pam_authenticate' 
checkpwd.c:(.text+0x141): Nicht definierter Verweis auf `pam_end' 
collect2: error: ld returned 1 exit status 

很抱歉的德國,這意味着某事像「失蹤符號」。這就是我的問題:爲什麼沒有找到符號?我需要包括哪些庫?當我在libpam.a上執行nm時,可以找到所有符號:

[email protected]:~$ nm /usr/lib/x86_64-linux-gnu/libpam.a | grep pam_start 
      U _pam_start_timer 
    0000000000000010 T _pam_start_timer 
    0000000000001930 T _pam_start_handlers 
      U _pam_start_timer 
pam_start.o: 
    0000000000000000 T pam_start 
      U _pam_start_handlers 
[email protected]:~$ nm /usr/lib/x86_64-linux-gnu/libpam.a | grep pam_authenticate 
    0000000000000000 T pam_authenticate 

任何人都可以看到這裏出了什麼問題嗎?

感謝您的任何提示。

回答

相關問題