summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2020-05-06 08:00:00 +0000
committerDmitry V. Levin <ldv@altlinux.org>2020-05-21 16:51:52 +0000
commit611dac7a0b207311f2f7a3f14a4e729be8d4e5da (patch)
treed78de1da864fe8005314b9cd3855a519c8ece273 /modules
parent4e4a8215a559ccde75da34b1a674fc9b1f55ae87 (diff)
pam_debug: add a test for return values
* modules/pam_debug/tst-pam_debug-retval.c: New file. * modules/pam_debug/Makefile.am (TESTS): Add $(check_PROGRAMS). (check_PROGRAMS, tst_pam_debug_retval_LDADD): New variables.
Diffstat (limited to 'modules')
-rw-r--r--modules/pam_debug/Makefile.am7
-rw-r--r--modules/pam_debug/tst-pam_debug-retval.c65
2 files changed, 70 insertions, 2 deletions
diff --git a/modules/pam_debug/Makefile.am b/modules/pam_debug/Makefile.am
index 2b3d8613..8aa63056 100644
--- a/modules/pam_debug/Makefile.am
+++ b/modules/pam_debug/Makefile.am
@@ -12,14 +12,14 @@ dist_man_MANS = pam_debug.8
endif
XMLS = README.xml pam_debug.8.xml
dist_check_SCRIPTS = tst-pam_debug
-TESTS = $(dist_check_SCRIPTS)
+TESTS = $(dist_check_SCRIPTS) $(check_PROGRAMS)
securelibdir = $(SECUREDIR)
secureconfdir = $(SCONFIGDIR)
AM_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include \
$(WARN_CFLAGS)
-AM_LDFLAGS = -no-undefined -avoid-version -module
+AM_LDFLAGS = -no-undefined -avoid-version -module
if HAVE_VERSIONING
AM_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map
endif
@@ -27,6 +27,9 @@ endif
securelib_LTLIBRARIES = pam_debug.la
pam_debug_la_LIBADD = $(top_builddir)/libpam/libpam.la
+check_PROGRAMS = tst-pam_debug-retval
+tst_pam_debug_retval_LDADD = $(top_builddir)/libpam/libpam.la
+
if ENABLE_REGENERATE_MAN
dist_noinst_DATA = README
-include $(top_srcdir)/Make.xml.rules
diff --git a/modules/pam_debug/tst-pam_debug-retval.c b/modules/pam_debug/tst-pam_debug-retval.c
new file mode 100644
index 00000000..6d3edf8f
--- /dev/null
+++ b/modules/pam_debug/tst-pam_debug-retval.c
@@ -0,0 +1,65 @@
+/*
+ * Check pam_debug return values.
+ *
+ * Copyright (c) 2020 Dmitry V. Levin <ldv@altlinux.org>
+ */
+
+#include "test_assert.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <security/pam_appl.h>
+
+#define MODULE_NAME "pam_debug"
+#define TEST_NAME "tst-" MODULE_NAME "-retval"
+
+static const char service_file[] = TEST_NAME ".service";
+static const char user_name[] = "";
+static const char args[] = " auth=perm_denied"
+ " cred=cred_unavail"
+ " acct=acct_expired"
+ " prechauthtok=success"
+ " chauthtok=service_err"
+ " open_session=buf_err"
+ " close_session=system_err";
+static struct pam_conv conv;
+
+int
+main(void)
+{
+ pam_handle_t *pamh = NULL;
+ FILE *fp;
+ char cwd[PATH_MAX];
+
+ ASSERT_NE(NULL, getcwd(cwd, sizeof(cwd)));
+
+ ASSERT_NE(NULL, fp = fopen(service_file, "w"));
+ ASSERT_LT(0, fprintf(fp, "#%%PAM-1.0\n"
+ "auth required %s/.libs/%s.so %s\n"
+ "account required %s/.libs/%s.so %s\n"
+ "password required %s/.libs/%s.so %s\n"
+ "session required %s/.libs/%s.so %s\n",
+ cwd, MODULE_NAME, args,
+ cwd, MODULE_NAME, args,
+ cwd, MODULE_NAME, args,
+ cwd, MODULE_NAME, args));
+ ASSERT_EQ(0, fclose(fp));
+
+ ASSERT_EQ(PAM_SUCCESS,
+ pam_start_confdir(service_file, user_name, &conv, ".", &pamh));
+ ASSERT_NE(NULL, pamh);
+ ASSERT_EQ(PAM_PERM_DENIED, pam_authenticate(pamh, 0));
+ ASSERT_EQ(PAM_CRED_UNAVAIL, pam_setcred(pamh, 0));
+ ASSERT_EQ(PAM_ACCT_EXPIRED, pam_acct_mgmt(pamh, 0));
+ ASSERT_EQ(PAM_SERVICE_ERR, pam_chauthtok(pamh, 0));
+ ASSERT_EQ(PAM_BUF_ERR, pam_open_session(pamh, 0));
+ ASSERT_EQ(PAM_SYSTEM_ERR, pam_close_session(pamh, 0));
+ ASSERT_EQ(PAM_SUCCESS, pam_end(pamh, 0));
+ pamh = NULL;
+
+ ASSERT_EQ(0, unlink(service_file));
+
+ return 0;
+}