Skip to content

Instantly share code, notes, and snippets.

@nikmartin
Created September 10, 2012 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikmartin/3688099 to your computer and use it in GitHub Desktop.
Save nikmartin/3688099 to your computer and use it in GitHub Desktop.
PAM Auth App
#include <security/pam_appl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pam_response *reply;
int null_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
*resp = reply;
return PAM_SUCCESS;
}
static struct pam_conv conv = { null_conv, NULL };
int main(int argc, char *argv[]) {
int retval;
char *service, *user, *pass;
service = argv[1];
user = argv[2];
pass = strdup(argv[3]);
}
return authenticate(service, user, pass);
}
int authenticate(char *service, char *user, char *pass) {
pam_handle_t *pamh = NULL;
int retval = pam_start(service, user, &conv, &pamh);
if (retval == PAM_SUCCESS) {
reply = (struct pam_response *)malloc(sizeof(struct pam_response));
reply[0].resp = pass;
reply[0].resp_retcode = 0;
retval = pam_authenticate(pamh, 0);
pam_end(pamh, PAM_SUCCESS);
return ( retval == PAM_SUCCESS ? 0:1 );
}
return ( retval == PAM_SUCCESS ? 0:1 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment