Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Eugene Saun ( 15 years ago )
#include <security/pam_modules.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifdef PRINT
#undef PRINT
#endif
#ifdef DEBUG_PRINT_ENABLED
#include <stdio.h>
#define PRINT(x) printf x;
#else
#define PRINT(x)
#endif
#define MIN_X -20
#define MAX_X 20
#define MIN_A -10
#define MAX_A 10
PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, const char **argv) {
int retval;
const char *name;
int a, b, c, x1, x2;
retval = pam_get_user(pamh, &name;, NULL);
PRINT(("Obtained username: %s\n", name));
{
struct pam_message msg[2], *pmsg[2];
struct pam_response *resp;
const char *promptx[] = { "x1 = ", "x2 = " };
srand(time(NULL));
x1 = MIN_X + rand() % (MAX_X - MIN_X - 1);
x2 = MIN_X + rand() % (MAX_X - MIN_X - 1);
while (!(a = MIN_A + rand() % (MAX_A - MIN_A - 1)));
b = (-1) * (x1 + x2) * a;
c = x1 * x2 * a;
printf("%dx^2%+dx%+d=0\n", a, b, c);
pmsg[0] = &msg;[0];
msg[0].msg_style = PAM_PROMPT_ECHO_ON;
msg[0].msg = promptx[0];
pmsg[1] = &msg;[1];
msg[1].msg_style = PAM_PROMPT_ECHO_ON;
msg[1].msg = promptx[1];
{
struct pam_conv *conv;
int y1, y2;
pam_get_item(pamh, PAM_CONV, (const void **) &conv;);
conv->conv(2, (const struct pam_message **) pmsg, &resp;, conv->appdata_ptr);
y1 = atoi(resp[0].resp);
y2 = atoi(resp[1].resp);
if (x1 == y1 && x2 == y2 || x1 == y2 && x2 == y1)
return PAM_SUCCESS;
}
}
return PAM_AUTH_ERR;
}
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return PAM_SUCCESS;
}
#ifdef PAM_STATIC
struct pam_module _pam_quadec_modstruct = {
"pam_quadeq",
pam_sm_authenticate,
pam_sm_setcred,
NULL,
NULL,
NULL,
NULL,
};
#endif
Revise this Paste
Children: 39436