diff options
author | Iftikhar Ahmad <iftikhar.ahmad@gmail.com> | 2013-03-19 12:29:06 +0500 |
---|---|---|
committer | Iftikhar Ahmad <iftikhar.ahmad@gmail.com> | 2013-03-19 12:29:06 +0500 |
commit | 5cf1567bf526dd292e084e1a289f72609ea92c2d (patch) | |
tree | 7e6acd2284d724a46079c2fb0018cde44d6151a7 | |
parent | ffb3ffe818c5444c3407ec79565a99db53397a2d (diff) | |
parent | 788858a758cb0db992247299c4b430ba603196e2 (diff) | |
download | libpam-freerdp2-5cf1567bf526dd292e084e1a289f72609ea92c2d.tar.gz libpam-freerdp2-5cf1567bf526dd292e084e1a289f72609ea92c2d.tar.bz2 libpam-freerdp2-5cf1567bf526dd292e084e1a289f72609ea92c2d.zip |
Empty password fix and added related unit test Bug#1092428
-rw-r--r-- | tests/mock_pam.c | 42 | ||||
-rw-r--r-- | tests/mock_pam.h | 1 | ||||
-rw-r--r-- | tests/test-freerdp-wrapper.cc | 10 |
3 files changed, 53 insertions, 0 deletions
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) diff --git a/tests/mock_pam.h b/tests/mock_pam.h index eb88a2e..c9c4f36 100644 --- a/tests/mock_pam.h +++ b/tests/mock_pam.h @@ -17,6 +17,7 @@ typedef struct pam_handle pam_handle_t; pam_handle_t *pam_handle_new (void); +pam_handle_t *pam_handle_empty_pswd_new (void); int pam_get_item (const pam_handle_t *pamh, int type, const void **value); int pam_set_item (pam_handle_t *pamh, int type, const void *value); diff --git a/tests/test-freerdp-wrapper.cc b/tests/test-freerdp-wrapper.cc index 147682d..6ba670f 100644 --- a/tests/test-freerdp-wrapper.cc +++ b/tests/test-freerdp-wrapper.cc @@ -58,6 +58,16 @@ namespace { // that I got all of the wrapper and pam to link there } + TEST_F(FreerdpclientWrapperTest, canHandleEmptyPassword) { + const char *argv[] = { NULL }; + + pam_handle_t *pamh = pam_handle_empty_pswd_new (); + + EXPECT_EQ (PAM_AUTH_ERR, + pam_sm_authenticate (pamh, 0, 0, argv)); + + } + TEST_F(FreerdpclientWrapperTest, canCallPamOpenSession) { const char *argv[] = { NULL }; |