summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThorsten Kukuk <kukuk@thkukuk.de>2006-03-12 10:26:29 +0000
committerThorsten Kukuk <kukuk@thkukuk.de>2006-03-12 10:26:29 +0000
commitd1623a3eec7265ad6be1b13292d19718d7816478 (patch)
tree1acbe1be4282038d84ae9611d34fb255d5d3e2b8 /tests
parent993d5e30fa9085a05cc8231c49750e8bcc03170e (diff)
Relevant BUGIDs:
Purpose of commit: bugfix/new feature Commit summary: --------------- 2006-03-12 Thorsten Kukuk <kukuk@thkukuk.de> * libpam/pam_item.c (pam_get_user): Check for valid pamh before using it. * tests/tst-pam_get_user.c: New.
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/tst-pam_get_user.c172
-rw-r--r--tests/tst-pam_set_item.c3
4 files changed, 176 insertions, 2 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
index 0ab179e8..9833ca68 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -11,6 +11,7 @@ tst-pam_close_session
tst-pam_end
tst-pam_fail_delay
tst-pam_get_item
+tst-pam_get_user
tst-pam_getenvlist
tst-pam_open_session
tst-pam_set_item
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 035a9cec..4f0d6a56 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,7 @@ CLEANFILES = *~
TESTS = tst-pam_start tst-pam_end tst-pam_fail_delay tst-pam_open_session \
tst-pam_close_session tst-pam_acct_mgmt tst-pam_authenticate \
tst-pam_chauthtok tst-pam_setcred tst-pam_get_item tst-pam_set_item \
- tst-pam_getenvlist
+ tst-pam_getenvlist tst-pam_get_user
check_PROGRAMS = ${TESTS} tst-dlopen
diff --git a/tests/tst-pam_get_user.c b/tests/tst-pam_get_user.c
new file mode 100644
index 00000000..916c6cc6
--- /dev/null
+++ b/tests/tst-pam_get_user.c
@@ -0,0 +1,172 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * ALTERNATIVELY, this product may be distributed under the terms of
+ * the GNU Public License, in which case the provisions of the GPL are
+ * required INSTEAD OF the above restrictions. (This clause is
+ * necessary due to a potential bad interaction between the GPL and
+ * the restrictions contained in a BSD-style copyright.)
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <security/pam_appl.h>
+#include <security/pam_modules.h>
+
+static const char *prompt = "myprompt:";
+static const char *user = "itsme";
+
+static int
+login_conv (int num_msg, const struct pam_message **mesg,
+ struct pam_response **resp, void *appdata_ptr UNUSED)
+{
+ struct pam_response *reply;
+ int count;
+
+ reply = calloc(num_msg, sizeof (struct pam_response));
+
+ if (reply == NULL)
+ return PAM_BUF_ERR;
+
+ for (count = 0; count < num_msg; count++)
+ {
+ reply[count].resp_retcode = 0;
+ reply[count].resp = NULL;
+
+ switch (mesg[count]->msg_style)
+ {
+ case PAM_PROMPT_ECHO_ON:
+ if (strcmp (mesg[count]->msg, prompt) != 0)
+ {
+ fprintf (stderr, "conv function called with wrong prompt: %s\n",
+ mesg[count]->msg);
+ exit (1);
+ }
+ reply[count].resp = strdup (user);
+ break;
+
+ default:
+ fprintf (stderr,
+ "pam_get_user calls conv function with unexpected msg style");
+ exit (1);
+ }
+ }
+
+ *resp = reply;
+ return PAM_SUCCESS;
+}
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *value;
+ struct pam_conv conv = { &login_conv, NULL};
+ pam_handle_t *pamh;
+ int retval;
+
+ /* 1: Call with NULL for every argument */
+ retval = pam_get_user (NULL, NULL, NULL);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (NULL, NULL, NULL) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ /* setup pam handle */
+ retval = pam_start (service, user, &conv, &pamh);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (%s, %s, &conv, &pamh) returned %d\n",
+ service, user, retval);
+ return 1;
+ }
+
+ /* 2: Call with valid pamh handle but NULL for user */
+ retval = pam_get_user (pamh, NULL, NULL);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (pamh, NULL, NULL) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ /* 3: Call with valid pamh handle and valid user ptr */
+ retval = pam_get_user (pamh, &value, NULL);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (pamh, &value, NULL) returned %d\n",
+ retval);
+ return 1;
+ }
+ if (strcmp (user, value) != 0)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (pamh, &value, NULL) mismatch:\n"
+ "expected: %s\n"
+ "got: %s\n", user, value);
+ return 1;
+ }
+
+ pam_end (pamh, 0);
+
+ /* setup pam handle without user */
+ retval = pam_start (service, NULL, &conv, &pamh);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (%s, %s, &conv, &pamh) returned %d\n",
+ service, user, retval);
+ return 1;
+ }
+
+ /* 4: Call with valid pamh handle and valid user ptr */
+ retval = pam_get_user (pamh, &value, prompt);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (pamh, &value, prompt) returned %d\n",
+ retval);
+ return 1;
+ }
+ if (strcmp (user, value) != 0)
+ {
+ fprintf (stderr,
+ "tst-pam_get_user (pamh, &value, prompt) mismatch:\n"
+ "expected: %s\n"
+ "got: %s\n", user, value);
+ return 1;
+ }
+
+ pam_end (pamh, 0);
+
+ return 0;
+}
diff --git a/tests/tst-pam_set_item.c b/tests/tst-pam_set_item.c
index ecc68e6c..29944bdc 100644
--- a/tests/tst-pam_set_item.c
+++ b/tests/tst-pam_set_item.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include <security/pam_appl.h>
@@ -132,7 +133,7 @@ main (void)
fprintf (stderr,
"pam_get_item got wrong value:\n"
"expected: %s\n"
- "got: %s\n", items[i].new_value, value);
+ "got: %s\n", items[i].new_value, (const char *)value);
return 1;
}
}