note 13910 deleted from features.http-auth by irc-html
| From: | irc-html@php.net | Date: | Sat, 19 Jan 2002 20:29:25 +0000 |
| Subject: | note 13910 deleted from features.http-auth by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25319@lists.php.net to get a copy of this message | ||
If you want to check user/password against real UNIX system accounts, you can use this C program -
"checkuser user password". Don't forget to add the two lines into
/etc/pam.d/check_user as mentioned in the begining of the code.</p>
/*
This program was contributed by Shane Watts
[modifications by AGM and Abraxis]
You need to create /etc/pam.d/check_user file with this two lines:
check_user auth required /usr/lib/security/pam_unix_auth.so
check_user account required /usr/lib/security/pam_unix_acct.so
*/
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <stdio.h>
#include <string.h>
#define PAM_MSG_MEMBER(msg, n, member) ((*(msg))[(n)].member)
static char *pampasswd = NULL;
char *
xstrdup(const char *str)
{
size_t len = strlen(str) + 1;
char *cp;
cp = (char *)malloc(len);
strcpy(cp, str);
return cp;
}
static int arg_conv(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr) {
struct pam_response *reply;
int count;
if((reply = malloc(num_msg * sizeof(reply))) == NULL)
return PAM_CONV_ERR;
for(count=0; count<num_msg; count++) {
switch(PAM_MSG_MEMBER(msg, count, msg_style)) {
case PAM_PROMPT_ECHO_ON:
case PAM_PROMPT_ECHO_OFF:
reply[count].resp = xstrdup(pampasswd);
reply[count].resp_retcode = PAM_SUCCESS;
break;
case PAM_ERROR_MSG:
case PAM_TEXT_INFO:
reply[count].resp = xstrdup("");
reply[count].resp_retcode = PAM_SUCCESS;
break;
default:
free(reply);
return PAM_CONV_ERR;
}
}
*resp = reply;
return PAM_SUCCESS;
}
static struct pam_conv conv = {
arg_conv,
NULL
};
int main(int argc, char *argv[])
{
pam_handle_t *pamh=NULL;
int retval;
const char *user="nobody";
user = argv[1];
pampasswd = argv[2];
retval = pam_start("check_user", user, &conv, &pamh);
if (retval == PAM_SUCCESS)
retval = pam_authenticate(pamh, 0); /* is user really user? */
if (retval == PAM_SUCCESS)
retval = pam_acct_mgmt(pamh, 0); /* permitted access? */
/* This is where we have been authorized or not. */
if (retval == PAM_SUCCESS) {
fprintf(stdout, "Authenticated\n");
} else {
fprintf(stdout, "Not Authenticated\n");
}
if (pam_end(pamh,retval) != PAM_SUCCESS) { /* close Linux-PAM */
pamh = NULL;
fprintf(stderr, "check_user: failed to release authenticator\n");
exit(1);
}
return ( retval == PAM_SUCCESS ? 0:1 ); /* indicate success */
}