feat: clone from: https://github.com/anowell/pam-rs
This commit is contained in:
52
pam-http/test.c
Normal file
52
pam-http/test.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_misc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const struct pam_conv conv = {
|
||||
misc_conv,
|
||||
NULL
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
pam_handle_t* pamh = NULL;
|
||||
int retval;
|
||||
const char* user = "nobody";
|
||||
|
||||
if(argc != 2) {
|
||||
printf("Usage: app [username]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
user = argv[1];
|
||||
|
||||
retval = pam_start("http-auth", user, &conv, &pamh);
|
||||
|
||||
// Are the credentials correct?
|
||||
if (retval == PAM_SUCCESS) {
|
||||
printf("Credentials accepted.\n");
|
||||
retval = pam_authenticate(pamh, 0);
|
||||
}
|
||||
|
||||
// Can the accound be used at this time?
|
||||
if (retval == PAM_SUCCESS) {
|
||||
printf("Account is valid.\n");
|
||||
retval = pam_acct_mgmt(pamh, 0);
|
||||
}
|
||||
|
||||
// Did everything work?
|
||||
if (retval == PAM_SUCCESS) {
|
||||
printf("Authenticated\n");
|
||||
} else {
|
||||
printf("Not Authenticated\n");
|
||||
}
|
||||
|
||||
// close PAM (end session)
|
||||
if (pam_end(pamh, retval) != PAM_SUCCESS) {
|
||||
pamh = NULL;
|
||||
printf("check_user: failed to release authenticator\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return retval == PAM_SUCCESS ? 0 : 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user