aboutsummaryrefslogtreecommitdiff
path: root/tests/mock_pam.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mock_pam.c')
-rw-r--r--tests/mock_pam.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/tests/mock_pam.c b/tests/mock_pam.c
index ce57973..f32d95f 100644
--- a/tests/mock_pam.c
+++ b/tests/mock_pam.c
@@ -19,37 +19,44 @@ struct pam_handle {
/* note: the other fields have been omitted */
};
-int fake_conv (int num_msg, const struct pam_message **msg,
- struct pam_response **resp, void *appdata_ptr)
+int fake_conv (int __attribute__((unused)) num_msg,
+ const struct pam_message **msg,
+ struct pam_response **resp,
+ void __attribute__((unused)) *appdata_ptr)
{
struct pam_response *response = NULL;
response = malloc (sizeof (struct pam_response));
- if (response == NULL)
+ if (response == NULL) {
return PAM_BUF_ERR;
+ }
response->resp_retcode = 0;
- if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0)
+ if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) {
response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) {
response->resp = strdup ("ruser");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) {
response->resp = strdup ("protocol://rhost/dummy");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) {
response->resp = strdup ("password");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) {
response->resp = strdup ("domain");
- else
+ } else {
+ free(response);
return PAM_SYMBOL_ERR; /* leaks... */
+ }
*resp = response;
return PAM_SUCCESS;
}
-int fake_conv_empty_password (int num_msg, const struct pam_message **msg,
- struct pam_response **resp, void *appdata_ptr)
+int fake_conv_empty_password (int __attribute__((unused)) num_msg,
+ const struct pam_message **msg,
+ struct pam_response **resp,
+ void __attribute__((unused)) *appdata_ptr)
{
struct pam_response *response = NULL;
response = malloc (sizeof (struct pam_response));
@@ -59,18 +66,20 @@ int fake_conv_empty_password (int num_msg, const struct pam_message **msg,
response->resp_retcode = 0;
- if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0)
+ if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) {
response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) {
response->resp = strdup ("ruser");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) {
response->resp = strdup ("protocol://rhost/dummy");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) {
response->resp = strdup ("");
- else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0)
+ } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) {
response->resp = strdup ("domain");
- else
+ } else {
+ free(response);
return PAM_SYMBOL_ERR; /* leaks... */
+ }
*resp = response;
@@ -109,20 +118,22 @@ int PAM_NONNULL((1)) pam_get_item (const pam_handle_t *pamh, int type, const voi
if (pamh == NULL)
return PAM_SYSTEM_ERR;
- if (type == PAM_CONV)
+ if (type == PAM_CONV) {
*value = pamh->conv;
- else if (pamh->item[type] != NULL)
+ } else if (pamh->item[type] != NULL) {
*value = pamh->item[type];
- else
+ } else {
*value = NULL; /* will result in a prompt conversation */
+ }
return PAM_SUCCESS;
}
int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *value)
{
- if (pamh == NULL)
+ if (pamh == NULL) {
return PAM_SYSTEM_ERR;
+ }
void **slot, *tmp;
size_t nsize, osize;
@@ -130,10 +141,12 @@ int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *val
slot = &pamh->item[type];
osize = nsize = 0;
- if (*slot != NULL)
+ if (*slot != NULL) {
osize = strlen((const char *)*slot) + 1;
- if (value != NULL)
+ }
+ if (value != NULL) {
nsize = strlen((const char *)value) + 1;
+ }
if (*slot != NULL) {
memset(*slot, 0xd0, osize);
@@ -141,8 +154,9 @@ int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *val
}
if (value != NULL) {
- if ((tmp = malloc(nsize)) == NULL)
+ if ((tmp = malloc(nsize)) == NULL) {
return PAM_BUF_ERR;
+ }
memcpy(tmp, value, nsize);
} else {
tmp = NULL;