summaryrefslogtreecommitdiff
path: root/xtests
diff options
context:
space:
mode:
authorThorsten Kukuk <kukuk@thkukuk.de>2007-06-20 13:54:08 +0000
committerThorsten Kukuk <kukuk@thkukuk.de>2007-06-20 13:54:08 +0000
commit2cffe6c172c372ac6ddf4c948c92373f69ed7def (patch)
tree387f17bfaa9ec2c11b2ae16595d4801e1257813c /xtests
parentb8df468e3ad7738ae5ed8bd69fac63fcef098329 (diff)
Relevant BUGIDs: 1688777
Purpose of commit: new features Commit summary: --------------- 2007-06-20 Thorsten Kukuk <kukuk@thkukuk.de> * modules/pam_cracklib/pam_cracklib.8.xml: Document new minclass option. * modules/pam_cracklib/pam_cracklib.c: Add support for minimum character classes [#1688777]. Based on patch from Keith Schincke. * xtests/tst-pam_cracklib2.c: New, test case for minclass option. * xtests/tst-pam_cracklib2.pamd: New, PAM config file for test case. * xtests/Makefile.am: Add new testcase. * xtests/pam_cracklib.c: Fix comment what this application tests. * configure.in: Use /lib64 on x86-64, ppc64, s390x, sparc64
Diffstat (limited to 'xtests')
-rw-r--r--xtests/.cvsignore1
-rw-r--r--xtests/Makefile.am8
-rw-r--r--xtests/tst-pam_cracklib1.c3
-rw-r--r--xtests/tst-pam_cracklib2.c140
-rw-r--r--xtests/tst-pam_cracklib2.pamd2
5 files changed, 148 insertions, 6 deletions
diff --git a/xtests/.cvsignore b/xtests/.cvsignore
index 4254282e..074250ca 100644
--- a/xtests/.cvsignore
+++ b/xtests/.cvsignore
@@ -7,6 +7,7 @@ tst-pam_dispatch2
tst-pam_dispatch3
tst-pam_dispatch4
tst-pam_cracklib1
+tst-pam_cracklib2
tst-pam_unix1
tst-pam_unix2
tst-pam_unix3
diff --git a/xtests/Makefile.am b/xtests/Makefile.am
index dd7ba801..2629a13f 100644
--- a/xtests/Makefile.am
+++ b/xtests/Makefile.am
@@ -11,13 +11,13 @@ CLEANFILES = *~
EXTRA_DIST = run-xtests.sh tst-pam_dispatch1.pamd tst-pam_dispatch2.pamd \
tst-pam_dispatch3.pamd tst-pam_dispatch4.pamd \
- tst-pam_cracklib1.pamd tst-pam_unix1.pamd tst-pam_unix2.pamd \
- tst-pam_unix3.pamd \
+ tst-pam_cracklib1.pamd tst-pam_cracklib2.pamd \
+ tst-pam_unix1.pamd tst-pam_unix2.pamd tst-pam_unix3.pamd \
tst-pam_unix1.sh tst-pam_unix2.sh tst-pam_unix3.sh
XTESTS = tst-pam_dispatch1 tst-pam_dispatch2 tst-pam_dispatch3 \
- tst-pam_dispatch4 tst-pam_cracklib1 tst-pam_unix1 tst-pam_unix2 \
- tst-pam_unix3
+ tst-pam_dispatch4 tst-pam_cracklib1 tst-pam_cracklib2 \
+ tst-pam_unix1 tst-pam_unix2 tst-pam_unix3
noinst_PROGRAMS = $(XTESTS)
diff --git a/xtests/tst-pam_cracklib1.c b/xtests/tst-pam_cracklib1.c
index 3aa3f15b..1600df97 100644
--- a/xtests/tst-pam_cracklib1.c
+++ b/xtests/tst-pam_cracklib1.c
@@ -83,8 +83,7 @@ static struct pam_conv conv = {
};
-/* Check that errors of optional modules are ignored and that
- required modules after a sufficient one are not executed. */
+/* Check that pam_cracklib does not seg.fault on empty passwords. */
int
main(int argc, char *argv[])
diff --git a/xtests/tst-pam_cracklib2.c b/xtests/tst-pam_cracklib2.c
new file mode 100644
index 00000000..49166a4e
--- /dev/null
+++ b/xtests/tst-pam_cracklib2.c
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+
+/* This test case checks
+ Patch 1688777: pam_cracklib support for minimum character classes */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <security/pam_appl.h>
+
+/* A conversation function which uses an internally-stored value for
+ the responses. */
+static int
+fake_conv (int num_msg, const struct pam_message **msgm UNUSED,
+ struct pam_response **response, void *appdata_ptr UNUSED)
+{
+ static int calls = 0;
+ struct pam_response *reply;
+ int count;
+
+ /* Sanity test. */
+ if (num_msg <= 0)
+ return PAM_CONV_ERR;
+
+ /* Allocate memory for the responses. */
+ reply = calloc (num_msg, sizeof (struct pam_response));
+ if (reply == NULL)
+ return PAM_CONV_ERR;
+
+ /* Each prompt elicits the same response. */
+ for (count = 0; count < num_msg; ++count)
+ {
+ reply[count].resp_retcode = 0;
+ /* first tow calls get a correct password, second a too
+ easy one. */
+ if (calls > 1)
+ reply[count].resp = strdup ("too easy");
+ else
+ {
+ ++calls;
+ reply[count].resp = strdup ("1a9C*8dK");
+ }
+ }
+
+ /* Set the pointers in the response structure and return. */
+ *response = reply;
+ return PAM_SUCCESS;
+}
+
+static struct pam_conv conv = {
+ fake_conv,
+ NULL
+};
+
+
+int
+main(int argc, char *argv[])
+{
+ pam_handle_t *pamh=NULL;
+ const char *user="root";
+ int retval;
+ int debug = 0;
+
+ /* Simulate passwd call by normal user */
+ setuid (65534);
+
+ if (argc > 1 && strcmp (argv[1], "-d") == 0)
+ debug = 1;
+
+ retval = pam_start("tst-pam_cracklib2", user, &conv, &pamh);
+ if (retval != PAM_SUCCESS)
+ {
+ if (debug)
+ fprintf (stderr, "cracklib2: pam_start returned %d\n", retval);
+ return 1;
+ }
+
+ /* Try one, first input is correct, second is NULL */
+ retval = pam_chauthtok (pamh, 0);
+ if (retval != PAM_SUCCESS)
+ {
+ if (debug)
+ fprintf (stderr, "cracklib2-1: pam_chauthtok returned %d\n", retval);
+ return 1;
+ }
+
+ /* Try two, second input is NULL */
+ retval = pam_chauthtok (pamh, 0);
+ if (retval != PAM_AUTHTOK_ERR)
+ {
+ if (debug)
+ fprintf (stderr, "cracklib2-2: pam_chauthtok returned %d\n", retval);
+ return 1;
+ }
+
+
+ retval = pam_end (pamh,retval);
+ if (retval != PAM_SUCCESS)
+ {
+ if (debug)
+ fprintf (stderr, "cracklib2: pam_end returned %d\n", retval);
+ return 1;
+ }
+ return 0;
+}
diff --git a/xtests/tst-pam_cracklib2.pamd b/xtests/tst-pam_cracklib2.pamd
new file mode 100644
index 00000000..5915aecd
--- /dev/null
+++ b/xtests/tst-pam_cracklib2.pamd
@@ -0,0 +1,2 @@
+#%PAM-1.0
+password required pam_cracklib.so minclass=4