From 788858a758cb0db992247299c4b430ba603196e2 Mon Sep 17 00:00:00 2001 From: Iftikhar Ahmad Date: Tue, 19 Mar 2013 12:25:39 +0500 Subject: unit test for empty password bug --- tests/mock_pam.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/mock_pam.c') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index 6368b84..2a1dcc7 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -47,7 +47,37 @@ int fake_conv (int num_msg, const struct pam_message **msg, return PAM_SUCCESS; } +int fake_conv_empty_password (int num_msg, const struct pam_message **msg, + struct pam_response **resp, void *appdata_ptr) +{ + struct pam_response *response = NULL; + response = malloc (sizeof (struct pam_response)); + + if (response == NULL) + return PAM_BUF_ERR; + + response->resp_retcode = 0; + + if (strcmp((*msg)->msg, "login:") == 0) + response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */ + else if (strcmp((*msg)->msg, "remote login:") == 0) + response->resp = strdup ("ruser"); + else if (strcmp((*msg)->msg, "remote host:") == 0) + response->resp = strdup ("protocol://rhost/dummy"); + else if (strcmp((*msg)->msg, "password:") == 0) + response->resp = strdup (""); + else if (strcmp((*msg)->msg, "domain:") == 0) + response->resp = strdup ("domain"); + else + return PAM_SYMBOL_ERR; /* leaks... */ + + *resp = response; + + return PAM_SUCCESS; +} + struct pam_conv static_conv = { &fake_conv, (void *)NULL }; +struct pam_conv static_conv_empty_pswd = { &fake_conv_empty_password, (void *)NULL }; pam_handle_t *pam_handle_new (void) { @@ -61,6 +91,18 @@ pam_handle_t *pam_handle_new (void) return newh; } +pam_handle_t *pam_handle_empty_pswd_new (void) +{ + pam_handle_t *newh = malloc (sizeof (pam_handle_t)); + + if (newh != NULL) { + newh->conv = &static_conv_empty_pswd; + memset(newh->item, 0, sizeof(void *) * PAM_NUM_ITEMS); + } + + return newh; +} + int pam_get_item (const pam_handle_t *pamh, int type, const void **value) { if (pamh == NULL) -- cgit v1.2.3