module pam working with password from http basic auth.

groups brokens.
This commit is contained in:
2018-07-03 15:55:13 -04:00
parent e5916f2e29
commit 5d05c63644
+88 -7
View File
@@ -93,7 +93,76 @@ static int check_autorization(request_rec *r)
/* ToDo prompt user for input */
//};
//struct pam_conv conv = { function_conversation, 0 };
struct pam_conv conv = { misc_conv, 0 };
struct pam_response *reply;
int converse(int n, const struct pam_message **msg,
struct pam_response **resp, void *data)
{
*resp = reply;
return PAM_SUCCESS;
struct pam_response *aresp;
char buf[PAM_MAX_RESP_SIZE];
int i;
data = data;
if (n <= 0 || n > PAM_MAX_NUM_MSG)
return (PAM_CONV_ERR);
if ((aresp = calloc(n, sizeof *aresp)) == NULL)
return (PAM_BUF_ERR);
for (i = 0; i < n; ++i) {
aresp[i].resp_retcode = 0;
aresp[i].resp = NULL;
switch (msg[i]->msg_style) {
case PAM_PROMPT_ECHO_OFF:
aresp[i].resp = strdup("jlcyrpass01!");
//aresp[i].resp = strdup(getpass(msg[i]->msg));
if (aresp[i].resp == NULL)
goto fail;
break;
case PAM_PROMPT_ECHO_ON:
fputs(msg[i]->msg, stderr);
//if (fgets(buf, sizeof buf, stdin) == NULL)
// goto fail;
//aresp[i].resp = strdup(buf);
aresp[i].resp = strdup("jlcyrpass01!");
if (aresp[i].resp == NULL)
goto fail;
break;
case PAM_ERROR_MSG:
fputs(msg[i]->msg, stderr);
if (strlen(msg[i]->msg) > 0 &&
msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n')
fputc('\n', stderr);
break;
case PAM_TEXT_INFO:
fputs(msg[i]->msg, stdout);
if (strlen(msg[i]->msg) > 0 &&
msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n')
fputc('\n', stdout);
break;
default:
goto fail;
}
}
*resp = aresp;
return (PAM_SUCCESS);
fail:
for (i = 0; i < n; ++i) {
if (aresp[i].resp != NULL) {
memset(aresp[i].resp, 0, strlen(aresp[i].resp));
free(aresp[i].resp);
}
}
memset(aresp, 0, n * sizeof *aresp);
*resp = NULL;
return (PAM_CONV_ERR);
}
struct pam_conv conv = { converse, 0 };
////////////////////////////////////////////////////////////////
/* Main routine */
@@ -253,22 +322,30 @@ static int absec_handler_first(request_rec *r)
printf("Pam start failed\n");
exit(0);
}
if((rret = pam_set_item( pamh, PAM_AUTHTOK, &pass)) == PAM_BUF_ERR) {
/* if((rret = pam_set_item( pamh, PAM_AUTHTOK, &pass)) == PAM_BUF_ERR) {
return HTTP_BAD_REQUEST;
}
*/
reply = (struct pam_response *)malloc(sizeof(struct pam_response));
// *** Get the password by any method, or maybe it was passed into this function.
reply[0].resp = strdup(pass);
reply[0].resp_retcode = 0;
if((rret = pam_authenticate(pamh, 0)) != PAM_SUCCESS) {
return HTTP_UNAUTHORIZED;
printf("User auth failed\n"); exit(0);
printf("User auth failed\n");
exit(0);
}
if(pam_end(pamh, rret) != PAM_SUCCESS) {
//perror("pam_end");
pamh = NULL;
return HTTP_INTERNAL_SERVER_ERROR;exit(1);
return HTTP_INTERNAL_SERVER_ERROR;
exit(1);
}
return HTTP_OK;
////////
/* Encrypt and compare shadow password */
@@ -303,6 +380,10 @@ return HTTP_OK;
ap_rprintf(r, "Fichier groupe<br/>\r\n");
return (DECLINED);
}
return HTTP_OK;
////////
/* Check supplemental groups */