Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <security/pam_appl.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- static int pam_conv_handler(int num_msg, const struct pam_message ** msg,
- struct pam_response ** resp, void *appdata_ptr)
- {
- int i;
- struct pam_response *response;
- /* parameter sanity checking */
- if (!resp || !msg)
- return PAM_CONV_ERR;
- /* allocate memory to store response */
- response = malloc(num_msg * sizeof(struct pam_response));
- if (!response)
- return PAM_CONV_ERR;
- /* copy values */
- for (i = 0; i < num_msg; i++) {
- /* initialize to safe values */
- response[i].resp_retcode = 0;
- response[i].resp = 0;
- /* select response based on requested output style */
- switch (msg[i]->msg_style) {
- case PAM_PROMPT_ECHO_ON:
- /* on memory allocation failure, auth fails */
- response[i].resp = strdup("mylogin");
- break;
- case PAM_PROMPT_ECHO_OFF:
- response[i].resp = strdup("mypassword");
- break;
- default:
- if (response) {
- free(response);
- }
- return PAM_CONV_ERR;
- }
- }
- /* everything okay, set PAM response values */
- *resp = response;
- return PAM_SUCCESS;
- }
- int main(int argc, char **argv) {
- int rc;
- pam_handle_t *pamh = NULL;
- struct pam_conv conv_info;
- conv_info.conv = pam_conv_handler;
- if ((rc = pam_start("phpmyadmin", "mylogin", &conv_info, &pamh)) != PAM_SUCCESS) {
- fprintf(stderr, "Error: %s", pam_strerror(pamh, rc));
- return 1;
- }
- if ((rc = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) {
- fprintf(stderr, "Error: %s", pam_strerror(pamh, rc));
- return 1;
- }
- if ((rc = pam_acct_mgmt(pamh, PAM_DISALLOW_NULL_AUTHTOK)) != PAM_SUCCESS) {
- fprintf(stderr, "Error: %s", pam_strerror(pamh, rc));
- pam_end(pamh, PAM_SUCCESS);
- return 1;
- }
- pam_end(pamh, PAM_SUCCESS);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement