summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore18
-rw-r--r--tests/Makefile.am18
-rw-r--r--tests/tst-dlopen.c40
-rw-r--r--tests/tst-pam_acct_mgmt.c54
-rw-r--r--tests/tst-pam_authenticate.c54
-rw-r--r--tests/tst-pam_chauthtok.c54
-rw-r--r--tests/tst-pam_close_session.c54
-rw-r--r--tests/tst-pam_end.c75
-rw-r--r--tests/tst-pam_fail_delay.c75
-rw-r--r--tests/tst-pam_get_item.c129
-rw-r--r--tests/tst-pam_getenvlist.c130
-rw-r--r--tests/tst-pam_open_session.c54
-rw-r--r--tests/tst-pam_set_item.c144
-rw-r--r--tests/tst-pam_setcred.c54
-rw-r--r--tests/tst-pam_start.c103
15 files changed, 1056 insertions, 0 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644
index 00000000..0ab179e8
--- /dev/null
+++ b/tests/.cvsignore
@@ -0,0 +1,18 @@
+Makefile
+Makefile.in
+.deps
+.libs
+*.o
+tst-dlopen
+tst-pam_acct_mgmt
+tst-pam_authenticate
+tst-pam_chauthtok
+tst-pam_close_session
+tst-pam_end
+tst-pam_fail_delay
+tst-pam_get_item
+tst-pam_getenvlist
+tst-pam_open_session
+tst-pam_set_item
+tst-pam_setcred
+tst-pam_start
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 00000000..035a9cec
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2006 Thorsten Kukuk <kukuk@suse.de>
+#
+
+AM_CFLAGS = -DLIBPAM_COMPILE -I$(top_srcdir)/libpam/include
+AM_LDFLAGS = -L$(top_builddir)/libpam -lpam
+
+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
+
+check_PROGRAMS = ${TESTS} tst-dlopen
+
+tst_dlopen_LDADD = -L$(top_builddir)/libpam -lpam -ldl
+
diff --git a/tests/tst-dlopen.c b/tests/tst-dlopen.c
new file mode 100644
index 00000000..9090367b
--- /dev/null
+++ b/tests/tst-dlopen.c
@@ -0,0 +1,40 @@
+/*
+ Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+/* Simple program to see if dlopen() would succeed. */
+int main(int argc, char **argv)
+{
+ int i;
+ struct stat st;
+ char buf[PATH_MAX];
+
+ for (i = 1; i < argc; i++) {
+ if (dlopen(argv[i], RTLD_NOW)) {
+ fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
+ argv[i]);
+ } else {
+ snprintf(buf, sizeof(buf), "./%s", argv[i]);
+ if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
+ fprintf(stdout, "dlopen() of \"./%s\" "
+ "succeeded.\n", argv[i]);
+ } else {
+ fprintf(stdout, "dlopen() of \"%s\" failed: "
+ "%s\n", argv[i], dlerror());
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
diff --git a/tests/tst-pam_acct_mgmt.c b/tests/tst-pam_acct_mgmt.c
new file mode 100644
index 00000000..8ae4c4d7
--- /dev/null
+++ b/tests/tst-pam_acct_mgmt.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_acct_mgmt (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_acct_mgmt (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_authenticate.c b/tests/tst-pam_authenticate.c
new file mode 100644
index 00000000..20e631aa
--- /dev/null
+++ b/tests/tst-pam_authenticate.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_authenticate (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "tst-pam_authenticate (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_chauthtok.c b/tests/tst-pam_chauthtok.c
new file mode 100644
index 00000000..abe83ed0
--- /dev/null
+++ b/tests/tst-pam_chauthtok.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_chauthtok (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "tst-pam_chauthtok (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_close_session.c b/tests/tst-pam_close_session.c
new file mode 100644
index 00000000..3e222088
--- /dev/null
+++ b/tests/tst-pam_close_session.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_close_session (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_close_session (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_end.c b/tests/tst-pam_end.c
new file mode 100644
index 00000000..edcd75a3
--- /dev/null
+++ b/tests/tst-pam_end.c
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval;
+
+ /* 1: close valid pam handle */
+ /* create valid 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;
+ }
+
+ retval = pam_end (pamh, 0);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_end (pamh, 0) returned %d\n", retval);
+ return 1;
+ }
+
+ /* 2: close NULL pam handle */
+ retval = pam_end (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_end (NULL, 0) returned %d\n", retval);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_fail_delay.c b/tests/tst-pam_fail_delay.c
new file mode 100644
index 00000000..f70e4c56
--- /dev/null
+++ b/tests/tst-pam_fail_delay.c
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval;
+
+ /* 1: set valid delay */
+ /* create valid 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;
+ }
+
+ retval = pam_fail_delay (pamh, 60);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_fail_delay (pamh, 60) returned %d\n", retval);
+ return 1;
+ }
+
+ /* 2: use NULL pam handle */
+ retval = pam_fail_delay (NULL, 60);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_fail_delay (NULL, 60) returned %d\n", retval);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_get_item.c b/tests/tst-pam_get_item.c
new file mode 100644
index 00000000..726aa2d0
--- /dev/null
+++ b/tests/tst-pam_get_item.c
@@ -0,0 +1,129 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+struct mapping {
+ int type;
+ const char *string;
+ int expected;
+};
+
+struct mapping items[] = {
+ {PAM_SERVICE, "PAM_SERVICE", PAM_SUCCESS},
+ {PAM_USER, "PAM_USER", 0},
+ {PAM_TTY, "PAM_TTY", 0},
+ {PAM_RHOST, "PAM_RHOST", 0},
+ {PAM_CONV, "PAM_CONV", 0},
+ {PAM_AUTHTOK, "PAM_AUTHTOK", PAM_BAD_ITEM},
+ {PAM_OLDAUTHTOK, "PAM_OLDAUTHTOK", PAM_BAD_ITEM},
+ {PAM_RUSER, "PAM_RUSER", 0},
+ {PAM_USER_PROMPT, "PAM_USER_PROMPT", 0},
+ {PAM_FAIL_DELAY, "PAM_FAIL_DELAY", 0}
+};
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval, num, i;
+ const void *value;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_get_item (NULL, PAM_SERVICE, &value);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_get_item (NULL, 0) 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: check for valid item types. Expected return value is
+ PAM_SUCCESS, except it has to fail. */
+ num = sizeof(items) / sizeof(struct mapping);
+
+ for (i = 0; i < num; i++)
+ {
+ retval = pam_get_item (pamh, items[i].type, &value);
+
+ if (retval != items[i].expected)
+ {
+ fprintf (stderr,
+ "pam_get_item failed to get value for %s. Returned %d\n",
+ items[i].string, retval);
+ return 1;
+ }
+ }
+
+ /* 3: check for bad item */
+ retval = pam_get_item (pamh, -1, &value);
+ if (retval != PAM_BAD_ITEM)
+ {
+ fprintf (stderr,
+ "pam_get_item returned %d when expecting PAM_BAD_ITEM\n",
+ retval);
+ return 1;
+ }
+
+ /* 4: check for valid item types, but NULL as value address. */
+ for (i = 0; i < num; i++)
+ {
+ retval = pam_get_item (pamh, items[i].type, NULL);
+
+ if (retval != PAM_PERM_DENIED)
+ {
+ fprintf (stderr,
+ "pam_get_item returned %d to get value for %s\n",
+ retval, items[i].string);
+ return 1;
+ }
+ }
+
+ pam_end (pamh, 0);
+
+ return 0;
+}
diff --git a/tests/tst-pam_getenvlist.c b/tests/tst-pam_getenvlist.c
new file mode 100644
index 00000000..52f2f185
--- /dev/null
+++ b/tests/tst-pam_getenvlist.c
@@ -0,0 +1,130 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <security/pam_appl.h>
+
+const char *envvals[] = {"VAL1=1", "VAL2=2", "VAL3=3"};
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval;
+ char **ptr;
+ char *temp;
+ int var, i;
+
+ /* 1: Call with NULL as pam handle */
+ ptr = pam_getenvlist (NULL);
+ if (ptr != NULL)
+ {
+ fprintf (stderr, "pam_getenvlist (NULL) does not return NULL\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 pam handle, but no environment set */
+ ptr = pam_getenvlist (pamh);
+ if (ptr == NULL || *ptr != NULL)
+ {
+ fprintf (stderr,
+ "pam_getenvlist (pamh) does not return pointer to NULL\n");
+ temp = *ptr;
+ var = 0;
+ while (temp)
+ {
+ printf ("%s\n", temp);
+ var++;
+ temp = *(ptr + var);
+ }
+ return 1;
+ }
+ free (ptr);
+
+ /* set environment variable */
+ for (i = 0; i < 3; i++)
+ {
+ retval = pam_putenv (pamh, envvals[i]);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_putenv (pamh, \"%s\") returned %d\n",
+ envvals[i], retval);
+ return 1;
+ }
+ }
+
+ /* 3: Call with pam handle and environment set */
+ ptr = pam_getenvlist (pamh);
+ if (ptr == NULL)
+ {
+ fprintf (stderr, "pam_getenvlist (pamh) returned NULL\n");
+ return 1;
+ }
+ else
+ {
+ temp = *ptr;
+ var = 0;
+ while (temp)
+ {
+ if (strcmp (temp, envvals[var]) != 0)
+ {
+ fprintf (stderr,
+ "pam_getenvlist returns wrong value:\n"
+ "expected: %s\n"
+ "got: %s\n", envvals[var], temp);
+ return 1;
+ }
+ free (temp);
+ var++;
+ temp = *(ptr + var);
+ }
+ free (ptr);
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_open_session.c b/tests/tst-pam_open_session.c
new file mode 100644
index 00000000..abbd3f39
--- /dev/null
+++ b/tests/tst-pam_open_session.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_open_session (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_open_session (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_set_item.c b/tests/tst-pam_set_item.c
new file mode 100644
index 00000000..ecc68e6c
--- /dev/null
+++ b/tests/tst-pam_set_item.c
@@ -0,0 +1,144 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+struct mapping {
+ int type;
+ const char *string;
+ int expected;
+ const char *new_value;
+};
+
+struct mapping items[] = {
+ {PAM_SERVICE, "PAM_SERVICE", PAM_SUCCESS, "logout"},
+ {PAM_USER, "PAM_USER", PAM_SUCCESS, "noroot"},
+ {PAM_TTY, "PAM_TTY", PAM_SUCCESS, "TTyX"},
+ {PAM_RHOST, "PAM_RHOST", PAM_SUCCESS, "remote"},
+ {PAM_AUTHTOK, "PAM_AUTHTOK", PAM_BAD_ITEM, "none"},
+ {PAM_OLDAUTHTOK, "PAM_OLDAUTHTOK", PAM_BAD_ITEM, "none"},
+ {PAM_RUSER, "PAM_RUSER", PAM_SUCCESS, "noroot"},
+ {PAM_USER_PROMPT, "PAM_USER_PROMPT", PAM_SUCCESS, "your name: "},
+ {PAM_FAIL_DELAY, "PAM_FAIL_DELAY", PAM_SUCCESS, "4000"}
+};
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval, num, i;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_set_item (NULL, PAM_SERVICE, "dummy");
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_set_item (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: check for bad item */
+ retval = pam_set_item (pamh, -1, "dummy");
+ if (retval != PAM_BAD_ITEM)
+ {
+ fprintf (stderr,
+ "pam_set_item returned %d when expecting PAM_BAD_ITEM\n",
+ retval);
+ return 1;
+ }
+
+ /* 3: try to set PAM_CONV to NULL */
+ retval = pam_set_item (pamh, PAM_CONV, NULL);
+ if (retval != PAM_PERM_DENIED)
+ {
+ fprintf (stderr,
+ "pam_set_item (pamh, PAM_CONV, NULL) returned %d\n",
+ retval);
+ return 1;
+ }
+
+ /* 4: try to replace all items */
+ num = sizeof(items) / sizeof(struct mapping);
+
+ for (i = 0; i < num; i++)
+ {
+ retval = pam_set_item (pamh, items[i].type, items[i].new_value);
+
+ if (retval != items[i].expected)
+ {
+ fprintf (stderr,
+ "pam_set_item failed to set value for %s. Returned %d\n",
+ items[i].string, retval);
+ return 1;
+ }
+ else if (items[i].expected == PAM_SUCCESS)
+ {
+ const void *value;
+
+ retval = pam_get_item (pamh, items[i].type, &value);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr,
+ "pam_get_item was not able to fetch changed value: %d\n",
+ retval);
+ return 1;
+ }
+ if (strcmp (items[i].new_value, value) != 0)
+ {
+ fprintf (stderr,
+ "pam_get_item got wrong value:\n"
+ "expected: %s\n"
+ "got: %s\n", items[i].new_value, value);
+ return 1;
+ }
+ }
+ }
+
+ pam_end (pamh, 0);
+
+ return 0;
+}
diff --git a/tests/tst-pam_setcred.c b/tests/tst-pam_setcred.c
new file mode 100644
index 00000000..c9e87c2a
--- /dev/null
+++ b/tests/tst-pam_setcred.c
@@ -0,0 +1,54 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ int retval;
+
+ /* 1: Call with NULL as pam handle */
+ retval = pam_setcred (NULL, 0);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_setcred (NULL, 0) returned PAM_SUCCESS\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/tests/tst-pam_start.c b/tests/tst-pam_start.c
new file mode 100644
index 00000000..f50d5e04
--- /dev/null
+++ b/tests/tst-pam_start.c
@@ -0,0 +1,103 @@
+/*
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <security/pam_appl.h>
+
+
+int
+main (void)
+{
+ const char *service = "dummy";
+ const char *user = "root";
+ struct pam_conv conv;
+ pam_handle_t *pamh;
+ int retval;
+
+ /* 1: check with valid arguments */
+ 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;
+ }
+ else if (pamh == NULL)
+ {
+ fprintf (stderr,
+ "pam_start (%s, %s, &conv, &pamh) returned NULL for pamh\n",
+ service, user);
+ return 1;
+ }
+
+ /* 2: check with NULL for service */
+ retval = pam_start (NULL, user, &conv, &pamh);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (NULL, %s, &conv, &pamh) returned %d\n",
+ user, retval);
+ return 1;
+ }
+
+ /* 3: check with NULL for user */
+ retval = pam_start (service, NULL, &conv, &pamh);
+ if (retval != PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (%s, NULL, &conv, &pamh) returned %d\n",
+ service, retval);
+ return 1;
+ }
+
+
+ /* 4: check with NULL for conv */
+ retval = pam_start (service, user, NULL, &pamh);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (%s, %s, NULL, &pamh) returned %d\n",
+ service, user, retval);
+ return 1;
+ }
+
+ /* 5: check with NULL for pamh */
+ retval = pam_start (service, user, &conv, NULL);
+ if (retval == PAM_SUCCESS)
+ {
+ fprintf (stderr, "pam_start (%s, %s, &conv, NULL) returned %d\n",
+ service, user, retval);
+ return 1;
+ }
+
+ return 0;
+}