I'm new to UNIX programming.
I have a small program which simply ask the
user to enter a longinID and password, then, use pam_authenticate(...) to do the
authentication.
It executed fine with userID that do not have
a password, (i.e. the password is set to NULL in the passwd file).
However, with userID that has a none NULL value or
with a userID that does not exist in the system, it gave me a
coredump.
I compiled and ran the program on a Solaris 2.6
(SunOS 5.6 Generic_105181-05 ... , Ultra-5_10).
If any can give me tip as to how to fix this
or where can I get the answer, your help is much appreciated.
Thanks,
Here is the program:
#include <stdio.h>
#include <security/pam_appl.h> int authConv(int num_msg, struct pam_message **msg,
struct pam_response **res, void *pAppData);
struct pam_conv pamConv = {authConv, NULL}; int main()
{ char uid[15]; char passwd[20]; pam_handle_t* pHPam; int iPamError = 0; fprintf(stderr, "Login ID:
");
scanf("%s", uid); fprintf(stderr, "Password: "); scanf("%s", passwd); fprintf(stderr, "%s, %s\n", uid,
passwd);
if (pam_start("login", uid, &pamConv, &pHPam) != PAM_SUCCESS) { fprintf(stderr, "pam_start() failed.\n"); return 1; } fprintf(stderr, "pam
started.\n");
pam_set_item(pHPam, PAM_AUTHTOK, (void*) passwd); fprintf(stderr, "token is
set\n");
iPamError = pam_authenticate(pHPam, 0); if (PAM_SUCCESS ==
iPamError)
{ fprintf(stderr, "login succeeded!.\n"); } else { fprintf(stderr, "login failed: %s\n", pam_strerror(pHPam, iPamError)); } pam_end(pHPam, PAM_SUCCESS); return PAM_SUCCESS;
} int authConv(int num_msg, struct pam_message **msg,
struct pam_response **res, void *pAppData)
{ return PAM_SUCCESS; } -Hay
|