为什么我的程序 link pam_* 不能调用
Why can't my program link pam_* calls
我正在尝试编译和构建以下非常简单直接的 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;
}
我在 google 的某处找到了它。问题是它没有找到主要的 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
对不起德国人,它的意思是 "missing symbol"。这就是我的问题:为什么找不到符号?我需要包含哪些库?当我在 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
谁能看出这里出了什么问题?
感谢任何提示。
您必须将源文件和目标文件放在库文件之前:
gcc -o checkpwd checkpwd.c -lpam -lpam_misc
参见:Why does the order of '-l' option in gcc matter?
我正在尝试编译和构建以下非常简单直接的 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;
}
我在 google 的某处找到了它。问题是它没有找到主要的 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
对不起德国人,它的意思是 "missing symbol"。这就是我的问题:为什么找不到符号?我需要包含哪些库?当我在 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
谁能看出这里出了什么问题?
感谢任何提示。
您必须将源文件和目标文件放在库文件之前:
gcc -o checkpwd checkpwd.c -lpam -lpam_misc
参见:Why does the order of '-l' option in gcc matter?