我正在尝试编译和构建以下非常简单直接的C程序:
#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_ *符号:
X@Y:~$ 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
对不起德国人,这意味着......&#34;缺少符号&#34;。这是我的问题:为什么它找不到符号?我需要包含哪些库?当我在libpam.a上做nm时,我可以找到所有的符号:
X@Y:~$ 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
kai@KTEC32:~$ nm /usr/lib/x86_64-linux-gnu/libpam.a | grep pam_authenticate
0000000000000000 T pam_authenticate
谁能看到这里出了什么问题?
感谢任何提示。
答案 0 :(得分:2)
您必须将源文件和目标文件放在库文件之前:
gcc -o checkpwd checkpwd.c -lpam -lpam_misc