// Copyright (c) 1998 Red Hat Software, Inc. // Authors: Michael K. Johnson // Jacques Gelinas #include #include #include #include extern "C" { #include } /* Static variables used to communicate between the conversation function * and the server_login function */ static const char *PAM_password; /* hackish PAM conversation function * Here we assume that echo off means password. */ static int hack_conv ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void *) { #define COPY_STRING(s) (s) ? strdup(s) : (char*)NULL struct pam_response *reply = (struct pam_response*)malloc(sizeof(struct pam_response) * num_msg); if (!reply) return PAM_CONV_ERR; for (int replies = 0; replies < num_msg; replies++) { switch (msg[replies]->msg_style) { case PAM_PROMPT_ECHO_OFF: reply[replies].resp_retcode = PAM_SUCCESS; reply[replies].resp = COPY_STRING(PAM_password); /* PAM frees resp */ break; case PAM_TEXT_INFO: /* fall through */ case PAM_ERROR_MSG: /* ignore it, but pam still wants a NULL response... */ reply[replies].resp_retcode = PAM_SUCCESS; reply[replies].resp = NULL; break; case PAM_PROMPT_ECHO_ON: /* fall through */ default: /* Must be an error of some sort... */ free (reply); return PAM_CONV_ERR; } } *resp = reply; return PAM_SUCCESS; } static struct pam_conv hack_conversation = { &hack_conv, NULL }; int pam_check_pair( const char *user, const char *pass) { int retval; pam_handle_t *pamh = NULL; PAM_password = pass; retval = pam_start ("livraison", user, &hack_conversation, &pamh); if (retval == PAM_SUCCESS) { retval = pam_authenticate(pamh, 0); //fprintf (stderr,"apres authenticate %d %d\n",retval,retval==PAM_SUCCESS); if (retval == PAM_SUCCESS){ retval = pam_acct_mgmt(pamh, 0); //fprintf (stderr,"apres acct %d %d\n",retval,retval==PAM_SUCCESS); } } if (pamh != NULL) pam_end(pamh, PAM_SUCCESS); if (retval != PAM_SUCCESS) return 0; else return 1; }