diff options
Diffstat (limited to 't')
| -rw-r--r-- | t/Makefile.am | 23 | ||||
| -rw-r--r-- | t/Makefile.in | 118 | ||||
| -rw-r--r-- | t/t_file.c | 160 | ||||
| -rw-r--r-- | t/t_main.c | 127 | ||||
| -rw-r--r-- | t/t_openpam_ctype.c | 47 | ||||
| -rw-r--r-- | t/t_openpam_dispatch.c | 220 | ||||
| -rw-r--r-- | t/t_openpam_readlinev.c | 134 | ||||
| -rw-r--r-- | t/t_openpam_readword.c | 306 | ||||
| -rw-r--r-- | t/t_pam_conv.c | 134 | ||||
| -rw-r--r-- | t/t_pam_conv.h (renamed from t/t.h) | 60 | 
10 files changed, 812 insertions, 517 deletions
diff --git a/t/Makefile.am b/t/Makefile.am index bf3801b5417b..9c538a4dd959 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -1,19 +1,32 @@ -# $Id: Makefile.am 763 2014-02-26 16:29:16Z des $ +# $Id: Makefile.am 922 2017-02-19 19:28:30Z des $ + +if WITH_TEST  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libpam -noinst_HEADERS = t.h +AM_TESTS_ENVIRONMENT = \ +	PAM_RETURN_SO=$(abs_top_builddir)/modules/pam_return/.libs/pam_return.so + +noinst_HEADERS = t_pam_conv.h  # tests  TESTS =  TESTS += t_openpam_ctype +TESTS += t_openpam_dispatch  TESTS += t_openpam_readword  TESTS += t_openpam_readlinev  check_PROGRAMS = $(TESTS)  # libt - common support code  check_LIBRARIES = libt.a -libt_a_SOURCES = t_main.c t_file.c +libt_a_SOURCES = t_pam_conv.c + +# link with libpam and test framework +LDADD = $(CRYB_TEST_LIBS) libt.a +if WITH_SYSTEM_LIBPAM +LDADD += $(SYSTEM_LIBPAM) +else +LDADD += $(top_builddir)/lib/libpam/libpam.la +endif -# link with libpam and libt -LDADD = libt.a $(top_builddir)/lib/libpam/libpam.la +endif diff --git a/t/Makefile.in b/t/Makefile.in index 756951eced11..119d686e9c00 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.14 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am.  # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc.  # This Makefile.in is free software; the Free Software Foundation  # gives unlimited permission to copy and/or distribute it, @@ -14,10 +14,20 @@  @SET_MAKE@ -# $Id: Makefile.am 763 2014-02-26 16:29:16Z des $ +# $Id: Makefile.am 922 2017-02-19 19:28:30Z des $  VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ +  if test -z '$(MAKELEVEL)'; then \ +    false; \ +  elif test -n '$(MAKE_HOST)'; then \ +    true; \ +  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ +    true; \ +  else \ +    false; \ +  fi; \ +}  am__make_running_with_option = \    case $${target_option-} in \        ?) ;; \ @@ -80,17 +90,23 @@ PRE_UNINSTALL = :  POST_UNINSTALL = :  build_triplet = @build@  host_triplet = @host@ -TESTS = t_openpam_ctype$(EXEEXT) t_openpam_readword$(EXEEXT) \ -	t_openpam_readlinev$(EXEEXT) -check_PROGRAMS = $(am__EXEEXT_1) +@WITH_TEST_TRUE@TESTS = t_openpam_ctype$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_dispatch$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_readword$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_readlinev$(EXEEXT) +@WITH_TEST_TRUE@check_PROGRAMS = $(am__EXEEXT_1) +@WITH_SYSTEM_LIBPAM_TRUE@@WITH_TEST_TRUE@am__append_1 = $(SYSTEM_LIBPAM) +@WITH_SYSTEM_LIBPAM_FALSE@@WITH_TEST_TRUE@am__append_2 = $(top_builddir)/lib/libpam/libpam.la  subdir = t -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ -	$(top_srcdir)/depcomp $(noinst_HEADERS) \ -	$(top_srcdir)/test-driver  ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ +	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ +	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ +	$(top_srcdir)/configure.ac  am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \  	$(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__noinst_HEADERS_DIST) \ +	$(am__DIST_COMMON)  mkinstalldirs = $(install_sh) -d  CONFIG_HEADER = $(top_builddir)/config.h  CONFIG_CLEAN_FILES = @@ -102,29 +118,42 @@ am__v_AR_0 = @echo "  AR      " $@;  am__v_AR_1 =   libt_a_AR = $(AR) $(ARFLAGS)  libt_a_LIBADD = -am_libt_a_OBJECTS = t_main.$(OBJEXT) t_file.$(OBJEXT) +am__libt_a_SOURCES_DIST = t_pam_conv.c +@WITH_TEST_TRUE@am_libt_a_OBJECTS = t_pam_conv.$(OBJEXT)  libt_a_OBJECTS = $(am_libt_a_OBJECTS) -am__EXEEXT_1 = t_openpam_ctype$(EXEEXT) t_openpam_readword$(EXEEXT) \ -	t_openpam_readlinev$(EXEEXT) +@WITH_TEST_TRUE@am__EXEEXT_1 = t_openpam_ctype$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_dispatch$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_readword$(EXEEXT) \ +@WITH_TEST_TRUE@	t_openpam_readlinev$(EXEEXT)  t_openpam_ctype_SOURCES = t_openpam_ctype.c  t_openpam_ctype_OBJECTS = t_openpam_ctype.$(OBJEXT)  t_openpam_ctype_LDADD = $(LDADD) -t_openpam_ctype_DEPENDENCIES = libt.a \ -	$(top_builddir)/lib/libpam/libpam.la +am__DEPENDENCIES_1 = +@WITH_SYSTEM_LIBPAM_TRUE@@WITH_TEST_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) +@WITH_TEST_TRUE@t_openpam_ctype_DEPENDENCIES = $(am__DEPENDENCIES_1) \ +@WITH_TEST_TRUE@	libt.a $(am__DEPENDENCIES_2) $(am__append_2)  AM_V_lt = $(am__v_lt_@AM_V@)  am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)  am__v_lt_0 = --silent  am__v_lt_1 =  +t_openpam_dispatch_SOURCES = t_openpam_dispatch.c +t_openpam_dispatch_OBJECTS = t_openpam_dispatch.$(OBJEXT) +t_openpam_dispatch_LDADD = $(LDADD) +@WITH_TEST_TRUE@t_openpam_dispatch_DEPENDENCIES =  \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_1) libt.a \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_2) $(am__append_2)  t_openpam_readlinev_SOURCES = t_openpam_readlinev.c  t_openpam_readlinev_OBJECTS = t_openpam_readlinev.$(OBJEXT)  t_openpam_readlinev_LDADD = $(LDADD) -t_openpam_readlinev_DEPENDENCIES = libt.a \ -	$(top_builddir)/lib/libpam/libpam.la +@WITH_TEST_TRUE@t_openpam_readlinev_DEPENDENCIES =  \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_1) libt.a \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_2) $(am__append_2)  t_openpam_readword_SOURCES = t_openpam_readword.c  t_openpam_readword_OBJECTS = t_openpam_readword.$(OBJEXT)  t_openpam_readword_LDADD = $(LDADD) -t_openpam_readword_DEPENDENCIES = libt.a \ -	$(top_builddir)/lib/libpam/libpam.la +@WITH_TEST_TRUE@t_openpam_readword_DEPENDENCIES =  \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_1) libt.a \ +@WITH_TEST_TRUE@	$(am__DEPENDENCIES_2) $(am__append_2)  AM_V_P = $(am__v_P_@AM_V@)  am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)  am__v_P_0 = false @@ -159,15 +188,17 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)  am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)  am__v_CCLD_0 = @echo "  CCLD    " $@;  am__v_CCLD_1 =  -SOURCES = $(libt_a_SOURCES) t_openpam_ctype.c t_openpam_readlinev.c \ -	t_openpam_readword.c -DIST_SOURCES = $(libt_a_SOURCES) t_openpam_ctype.c \ +SOURCES = $(libt_a_SOURCES) t_openpam_ctype.c t_openpam_dispatch.c \  	t_openpam_readlinev.c t_openpam_readword.c +DIST_SOURCES = $(am__libt_a_SOURCES_DIST) t_openpam_ctype.c \ +	t_openpam_dispatch.c t_openpam_readlinev.c \ +	t_openpam_readword.c  am__can_run_installinfo = \    case $$AM_UPDATE_INFO_DIR in \      n|no|NO) false;; \      *) (install-info --version) >/dev/null 2>&1;; \    esac +am__noinst_HEADERS_DIST = t_pam_conv.h  HEADERS = $(noinst_HEADERS)  am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)  # Read a list of newline-separated strings from the standard input, @@ -392,6 +423,8 @@ TEST_LOGS = $(am__test_logs2:.test.log=.log)  TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver  TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \  	$(TEST_LOG_FLAGS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ +	$(top_srcdir)/test-driver  DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)  ACLOCAL = @ACLOCAL@  AMTAR = @AMTAR@ @@ -406,6 +439,7 @@ CCDEPMODE = @CCDEPMODE@  CFLAGS = @CFLAGS@  CPP = @CPP@  CPPFLAGS = @CPPFLAGS@ +CRYB_TEST_LIBS = @CRYB_TEST_LIBS@  CRYPTO_LIBS = @CRYPTO_LIBS@  CRYPT_LIBS = @CRYPT_LIBS@  CYGPATH_W = @CYGPATH_W@ @@ -436,6 +470,7 @@ LIB_MAJ = @LIB_MAJ@  LIPO = @LIPO@  LN_S = @LN_S@  LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@  MAKEINFO = @MAKEINFO@  MANIFEST_TOOL = @MANIFEST_TOOL@  MKDIR_P = @MKDIR_P@ @@ -459,6 +494,7 @@ SED = @SED@  SET_MAKE = @SET_MAKE@  SHELL = @SHELL@  STRIP = @STRIP@ +SYSTEM_LIBPAM = @SYSTEM_LIBPAM@  VERSION = @VERSION@  abs_builddir = @abs_builddir@  abs_srcdir = @abs_srcdir@ @@ -512,15 +548,19 @@ target_alias = @target_alias@  top_build_prefix = @top_build_prefix@  top_builddir = @top_builddir@  top_srcdir = @top_srcdir@ -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libpam -noinst_HEADERS = t.h +@WITH_TEST_TRUE@AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libpam +@WITH_TEST_TRUE@AM_TESTS_ENVIRONMENT = \ +@WITH_TEST_TRUE@	PAM_RETURN_SO=$(abs_top_builddir)/modules/pam_return/.libs/pam_return.so + +@WITH_TEST_TRUE@noinst_HEADERS = t_pam_conv.h  # libt - common support code -check_LIBRARIES = libt.a -libt_a_SOURCES = t_main.c t_file.c +@WITH_TEST_TRUE@check_LIBRARIES = libt.a +@WITH_TEST_TRUE@libt_a_SOURCES = t_pam_conv.c -# link with libpam and libt -LDADD = libt.a $(top_builddir)/lib/libpam/libpam.la +# link with libpam and test framework +@WITH_TEST_TRUE@LDADD = $(CRYB_TEST_LIBS) libt.a $(am__append_1) \ +@WITH_TEST_TRUE@	$(am__append_2)  all: all-am  .SUFFIXES: @@ -537,7 +577,6 @@ $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)  	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign t/Makefile'; \  	$(am__cd) $(top_srcdir) && \  	  $(AUTOMAKE) --foreign t/Makefile -.PRECIOUS: Makefile  Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status  	@case '$?' in \  	  *config.status*) \ @@ -577,6 +616,10 @@ t_openpam_ctype$(EXEEXT): $(t_openpam_ctype_OBJECTS) $(t_openpam_ctype_DEPENDENC  	@rm -f t_openpam_ctype$(EXEEXT)  	$(AM_V_CCLD)$(LINK) $(t_openpam_ctype_OBJECTS) $(t_openpam_ctype_LDADD) $(LIBS) +t_openpam_dispatch$(EXEEXT): $(t_openpam_dispatch_OBJECTS) $(t_openpam_dispatch_DEPENDENCIES) $(EXTRA_t_openpam_dispatch_DEPENDENCIES)  +	@rm -f t_openpam_dispatch$(EXEEXT) +	$(AM_V_CCLD)$(LINK) $(t_openpam_dispatch_OBJECTS) $(t_openpam_dispatch_LDADD) $(LIBS) +  t_openpam_readlinev$(EXEEXT): $(t_openpam_readlinev_OBJECTS) $(t_openpam_readlinev_DEPENDENCIES) $(EXTRA_t_openpam_readlinev_DEPENDENCIES)   	@rm -f t_openpam_readlinev$(EXEEXT)  	$(AM_V_CCLD)$(LINK) $(t_openpam_readlinev_OBJECTS) $(t_openpam_readlinev_LDADD) $(LIBS) @@ -591,11 +634,11 @@ mostlyclean-compile:  distclean-compile:  	-rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_file.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_main.Po@am__quote@  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_openpam_ctype.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_openpam_dispatch.Po@am__quote@  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_openpam_readlinev.Po@am__quote@  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_openpam_readword.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_pam_conv.Po@am__quote@  .c.o:  @am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -706,7 +749,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS)  	if test -n "$$am__remaking_logs"; then \  	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \  	       "recursion detected" >&2; \ -	else \ +	elif test -n "$$redo_logs"; then \  	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \  	fi; \  	if $(am__make_dryrun); then :; else \ @@ -824,6 +867,13 @@ t_openpam_ctype.log: t_openpam_ctype$(EXEEXT)  	--log-file $$b.log --trs-file $$b.trs \  	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \  	"$$tst" $(AM_TESTS_FD_REDIRECT) +t_openpam_dispatch.log: t_openpam_dispatch$(EXEEXT) +	@p='t_openpam_dispatch$(EXEEXT)'; \ +	b='t_openpam_dispatch'; \ +	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ +	--log-file $$b.log --trs-file $$b.trs \ +	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ +	"$$tst" $(AM_TESTS_FD_REDIRECT)  t_openpam_readword.log: t_openpam_readword$(EXEEXT)  	@p='t_openpam_readword$(EXEEXT)'; \  	b='t_openpam_readword'; \ @@ -1010,6 +1060,8 @@ uninstall-am:  	pdf pdf-am ps ps-am recheck tags tags-am uninstall \  	uninstall-am +.PRECIOUS: Makefile +  # Tell versions [3.59,3.63) of GNU make to not export all variables.  # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/t/t_file.c b/t/t_file.c deleted file mode 100644 index 8de4f9786c0d..000000000000 --- a/t/t_file.c +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * Copyright (c) 2012 Dag-Erling Smørgrav - * All rights reserved. - * - * 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, this list of conditions and the following disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. - * - * $Id: t_file.c 648 2013-03-05 17:54:27Z des $ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "openpam_asprintf.h" - -#include "t.h" - -static struct t_file *tflist; - -/* - * Open a temp file. - */ -struct t_file * -t_fopen(const char *filename) -{ -	struct t_file *tf; -	int fd; - -	if ((tf = calloc(sizeof *tf, 1)) == NULL) -		err(1, "%s(): calloc()", __func__); -	if (filename) { -		if ((tf->name = strdup(filename)) == NULL) -			err(1, "%s(): strdup()", __func__); -	} else { -		asprintf(&tf->name, "%s.%lu.%p.tmp", -		    t_progname, (unsigned long)getpid(), (void *)tf); -		if (tf->name == NULL) -			err(1, "%s(): asprintf()", __func__); -	} -	if ((fd = open(tf->name, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0) -		err(1, "%s(): %s", __func__, tf->name); -	if ((tf->file = fdopen(fd, "r+")) == NULL) -		err(1, "%s(): fdopen()", __func__); -	if ((tf->next = tflist) != NULL) -		tf->next->prev = tf; -	tflist = tf; -	return (tf); -} - -/* - * Write text to the temp file. - */ -int -t_fprintf(struct t_file *tf, const char *fmt, ...) -{ -	va_list ap; -	int len; - -	va_start(ap, fmt); -	len = vfprintf(tf->file, fmt, ap); -	va_end(ap); -	if (ferror(tf->file)) -		err(1, "%s(): vfprintf()", __func__); -	return (len); -} - -/* - * Rewind the temp file. - */ -void -t_frewind(struct t_file *tf) -{ - -	errno = 0; -	rewind(tf->file); -	if (errno != 0) -		err(1, "%s(): rewind()", __func__); -} - -/* - * Return non-zero if an error occurred. - */ -int -t_ferror(struct t_file *tf) -{ - -	return (ferror(tf->file)); -} - -/* - * Return non-zero if the end of the file was reached. - */ -int -t_feof(struct t_file *tf) -{ - -	return (feof(tf->file)); -} - -/* - * Close a temp file. - */ -void -t_fclose(struct t_file *tf) -{ - -	if (tf == tflist) -		tflist = tf->next; -	if (tf->prev) -		tf->prev->next = tf->next; -	if (tf->next) -		tf->next->prev = tf->prev; -	fclose(tf->file); -	if (unlink(tf->name) < 0) -		warn("%s(): unlink()", __func__); -	free(tf->name); -	free(tf); -} - -/* - * atexit() function to close all remaining files. - */ -void -t_fcloseall(void) -{ - -	while (tflist) -		t_fclose(tflist); -} diff --git a/t/t_main.c b/t/t_main.c deleted file mode 100644 index a0bbdda5713c..000000000000 --- a/t/t_main.c +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * Copyright (c) 2012 Dag-Erling Smørgrav - * All rights reserved. - * - * 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, this list of conditions and the following disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. - * - * $Id: t_main.c 651 2013-03-05 18:11:59Z des $ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <err.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> - -#include "t.h" - -const char *t_progname; - -static int verbose; - -void -t_verbose(const char *fmt, ...) -{ -	va_list ap; - -	if (verbose) { -		va_start(ap, fmt); -		vfprintf(stderr, fmt, ap); -		va_end(ap); -	} -} - -static void -usage(void) -{ - -	fprintf(stderr, "usage: %s [-v]\n", t_progname); -	exit(1); -} - -int -main(int argc, char *argv[]) -{ -	const struct t_test **t_plan; -	const char *desc; -	int n, pass, fail; -	int opt; - -#ifdef HAVE_SETLOGMASK -	/* suppress openpam_log() */ -	setlogmask(LOG_UPTO(0)); -#endif - -	/* clean up temp files in case of premature exit */ -	atexit(t_fcloseall); - -	if ((t_progname = strrchr(argv[0], '/')) != NULL) -		t_progname++; /* one past the slash */ -	else -		t_progname = argv[0]; - -	while ((opt = getopt(argc, argv, "v")) != -1) -		switch (opt) { -		case 'v': -			verbose = 1; -			break; -		default: -			usage(); -		} - -	argc -= optind; -	argv += optind; - -	/* prepare the test plan */ -	if ((t_plan = t_prepare(argc, argv)) == NULL) -		errx(1, "no plan\n"); - -	/* count the tests */ -	for (n = 0; t_plan[n] != NULL; ++n) -		/* nothing */; -	printf("1..%d\n", n); - -	/* run the tests */ -	for (n = pass = fail = 0; t_plan[n] != NULL; ++n) { -		desc = t_plan[n]->desc ? t_plan[n]->desc : "no description"; -		if ((*t_plan[n]->func)(t_plan[n]->arg)) { -			printf("ok %d - %s\n", n + 1, desc); -			++pass; -		} else { -			printf("not ok %d - %s\n", n + 1, desc); -			++fail; -		} -	} - -	/* clean up and exit */ -	t_cleanup(); -	exit(fail > 0 ? 1 : 0); -} diff --git a/t/t_openpam_ctype.c b/t/t_openpam_ctype.c index 7e56f95a4153..3fd617d4c7af 100644 --- a/t/t_openpam_ctype.c +++ b/t/t_openpam_ctype.c @@ -1,5 +1,5 @@  /*- - * Copyright (c) 2014 Dag-Erling Smørgrav + * Copyright (c) 2014-2015 Dag-Erling Smørgrav   * All rights reserved.   *   * Redistribution and use in source and binary forms, with or without @@ -26,19 +26,20 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id$ + * $Id: t_openpam_ctype.c 922 2017-02-19 19:28:30Z des $   */  #ifdef HAVE_CONFIG_H  # include "config.h"  #endif +#include <stdint.h>  #include <stdio.h>  #include <string.h> -#include "openpam_ctype.h" +#include <cryb/test.h> -#include "t.h" +#include "openpam_ctype.h"  #define OC_DIGIT	"0123456789"  #define OC_XDIGIT	OC_DIGIT "ABCDEFabcdef" @@ -61,11 +62,14 @@ static const char oc_p[] = OC_P;  static const char oc_pfcs[] = OC_PFCS;  #define T_OC(set)							\ -	T_FUNC(t_oc_##set, "is_" #set)					\ +	static int							\ +	t_oc_##set(char **desc, void *arg)				\  	{								\  		char crib[256];						\  		unsigned int i, ret;					\  									\ +		(void)desc;						\ +		(void)arg;						\  		memset(crib, 0, sizeof crib);				\  		for (i = 0; oc_##set[i]; ++i)				\  			crib[(int)oc_##set[i]] = 1;			\ @@ -78,6 +82,7 @@ static const char oc_pfcs[] = OC_PFCS;  		}							\  		return (ret == 0);					\  	} +#define T_OC_ADD(set) t_add_test(&t_oc_##set, NULL, "is_"#set)  T_OC(digit)  T_OC(xdigit) @@ -94,29 +99,27 @@ T_OC(pfcs)   * Boilerplate   */ -const struct t_test *t_plan[] = { -	T(t_oc_digit), -	T(t_oc_xdigit), -	T(t_oc_upper), -	T(t_oc_lower), -	T(t_oc_letter), -	T(t_oc_lws), -	T(t_oc_ws), -	T(t_oc_p), -	T(t_oc_pfcs), -	NULL -}; - -const struct t_test ** +static int  t_prepare(int argc, char *argv[])  {  	(void)argc;  	(void)argv; -	return (t_plan); +	T_OC_ADD(digit); +	T_OC_ADD(xdigit); +	T_OC_ADD(upper); +	T_OC_ADD(lower); +	T_OC_ADD(letter); +	T_OC_ADD(lws); +	T_OC_ADD(ws); +	T_OC_ADD(p); +	T_OC_ADD(pfcs); +	return (0);  } -void -t_cleanup(void) +int +main(int argc, char *argv[])  { + +	t_main(t_prepare, NULL, argc, argv);  } diff --git a/t/t_openpam_dispatch.c b/t/t_openpam_dispatch.c new file mode 100644 index 000000000000..f198a994e63e --- /dev/null +++ b/t/t_openpam_dispatch.c @@ -0,0 +1,220 @@ +/*- + * Copyright (c) 2015 Dag-Erling Smørgrav + * All rights reserved. + * + * 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, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $Id: t_openpam_dispatch.c 922 2017-02-19 19:28:30Z des $ + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <err.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <cryb/test.h> + +#include <security/pam_appl.h> +#include <security/openpam.h> + +#include "openpam_impl.h" +#include "t_pam_conv.h" + +#define T_FUNC(n, d)							\ +	static const char *t_ ## n ## _desc = d;			\ +	static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc),	\ +	    OPENPAM_UNUSED(void *arg)) + +#define T(n)								\ +	t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc) + +const char *pam_return_so; + +T_FUNC(empty_policy, "empty policy") +{ +	struct t_pam_conv_script script; +	struct pam_conv pamc; +	struct t_file *tf; +	pam_handle_t *pamh; +	int pam_err, ret; + +	memset(&script, 0, sizeof script); +	pamc.conv = &t_pam_conv; +	pamc.appdata_ptr = &script; +	tf = t_fopen(NULL); +	t_fprintf(tf, "# empty policy\n"); +	pam_err = pam_start(tf->name, "test", &pamc, &pamh); +	if (pam_err != PAM_SUCCESS) { +		t_verbose("pam_start() returned %d\n", pam_err); +		return (0); +	} +	/* +	 * Note: openpam_dispatch() currently returns PAM_SYSTEM_ERR when +	 * the chain is empty, it should possibly return PAM_SERVICE_ERR +	 * instead. +	 */ +	pam_err = pam_authenticate(pamh, 0); +	t_verbose("pam_authenticate() returned %d\n", pam_err); +	ret = (pam_err == PAM_SYSTEM_ERR); +	pam_err = pam_setcred(pamh, 0); +	t_verbose("pam_setcred() returned %d\n", pam_err); +	ret &= (pam_err == PAM_SYSTEM_ERR); +	pam_err = pam_acct_mgmt(pamh, 0); +	t_verbose("pam_acct_mgmt() returned %d\n", pam_err); +	ret &= (pam_err == PAM_SYSTEM_ERR); +	pam_err = pam_chauthtok(pamh, 0); +	t_verbose("pam_chauthtok() returned %d\n", pam_err); +	ret &= (pam_err == PAM_SYSTEM_ERR); +	pam_err = pam_open_session(pamh, 0); +	t_verbose("pam_open_session() returned %d\n", pam_err); +	ret &= (pam_err == PAM_SYSTEM_ERR); +	pam_err = pam_close_session(pamh, 0); +	t_verbose("pam_close_session() returned %d\n", pam_err); +	ret &= (pam_err == PAM_SYSTEM_ERR); +	pam_end(pamh, pam_err); +	t_fclose(tf); +	return (ret); +} + +static struct t_pam_return_case { +	int		 facility; +	int		 primitive; +	int		 flags; +	struct { +		int		 ctlflag; +		int		 modret; +	} mod[2]; +	int		 result; +} t_pam_return_cases[] = { +	{ +		PAM_AUTH, PAM_SM_AUTHENTICATE, 0, +		{ +			{ PAM_REQUIRED, PAM_SUCCESS }, +			{ PAM_REQUIRED, PAM_SUCCESS }, +		}, +		PAM_SUCCESS, +	}, +}; + +T_FUNC(mod_return, "module return value") +{ +	struct t_pam_return_case *tc; +	struct t_pam_conv_script script; +	struct pam_conv pamc; +	struct t_file *tf; +	pam_handle_t *pamh; +	unsigned int i, j, n; +	int pam_err; + +	memset(&script, 0, sizeof script); +	pamc.conv = &t_pam_conv; +	pamc.appdata_ptr = &script; +	n = sizeof t_pam_return_cases / sizeof t_pam_return_cases[0]; +	for (i = 0; i < n; ++i) { +		tc = &t_pam_return_cases[i]; +		tf = t_fopen(NULL); +		for (j = 0; j < 2; ++j) { +			t_fprintf(tf, "%s %s %s error=%s\n", +			    pam_facility_name[tc->facility], +			    pam_control_flag_name[tc->mod[j].ctlflag], +			    pam_return_so, +			    pam_err_name[tc->mod[j].modret]); +		} +		pam_err = pam_start(tf->name, "test", &pamc, &pamh); +		if (pam_err != PAM_SUCCESS) { +			t_verbose("pam_start() returned %d\n", pam_err); +			t_fclose(tf); +			continue; +		} +		switch (tc->primitive) { +		case PAM_SM_AUTHENTICATE: +			pam_err = pam_authenticate(pamh, tc->flags); +			break; +		case PAM_SM_SETCRED: +			pam_err = pam_setcred(pamh, tc->flags); +			break; +		case PAM_SM_ACCT_MGMT: +			pam_err = pam_acct_mgmt(pamh, tc->flags); +			break; +		case PAM_SM_OPEN_SESSION: +			pam_err = pam_open_session(pamh, tc->flags); +			break; +		case PAM_SM_CLOSE_SESSION: +			pam_err = pam_close_session(pamh, tc->flags); +			break; +		case PAM_SM_CHAUTHTOK: +			pam_err = pam_chauthtok(pamh, tc->flags); +			break; +		} +		t_verbose("%s returned %d\n", +		    pam_func_name[tc->primitive], pam_err); +		pam_end(pamh, pam_err); +		t_verbose("here\n"); +		t_fclose(tf); +	} +	return (1); +} + + +/*************************************************************************** + * Boilerplate + */ + +static int +t_prepare(int argc, char *argv[]) +{ + +	(void)argc; +	(void)argv; + +	if ((pam_return_so = getenv("PAM_RETURN_SO")) == NULL) { +		t_verbose("define PAM_RETURN_SO before running these tests\n"); +		return (0); +	} + +	openpam_set_feature(OPENPAM_RESTRICT_MODULE_NAME, 0); +	openpam_set_feature(OPENPAM_VERIFY_MODULE_FILE, 0); +	openpam_set_feature(OPENPAM_RESTRICT_SERVICE_NAME, 0); +	openpam_set_feature(OPENPAM_VERIFY_POLICY_FILE, 0); +	openpam_set_feature(OPENPAM_FALLBACK_TO_OTHER, 0); + +	T(empty_policy); +	T(mod_return); + +	return (0); +} + +int +main(int argc, char *argv[]) +{ + +	t_main(t_prepare, NULL, argc, argv); +} diff --git a/t/t_openpam_readlinev.c b/t/t_openpam_readlinev.c index 59f2b1071532..abc29e26cd55 100644 --- a/t/t_openpam_readlinev.c +++ b/t/t_openpam_readlinev.c @@ -1,5 +1,5 @@  /*- - * Copyright (c) 2012 Dag-Erling Smørgrav + * Copyright (c) 2012-2015 Dag-Erling Smørgrav   * All rights reserved.   *   * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: t_openpam_readlinev.c 648 2013-03-05 17:54:27Z des $ + * $Id: t_openpam_readlinev.c 922 2017-02-19 19:28:30Z des $   */  #ifdef HAVE_CONFIG_H @@ -34,15 +34,25 @@  #endif  #include <err.h> +#include <stdint.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include <cryb/test.h> +  #include <security/pam_appl.h>  #include <security/openpam.h>  #include "openpam_impl.h" -#include "t.h" + +#define T_FUNC(n, d)							\ +	static const char *t_ ## n ## _desc = d;			\ +	static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc),	\ +	    OPENPAM_UNUSED(void *arg)) + +#define T(n)								\ +	t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc)  /*   * Read a line from the temp file and verify that the result matches our @@ -55,7 +65,9 @@ orlv_expect(struct t_file *tf, const char **expectedv, int lines, int eof)  {  	int expectedc, gotc, i, lineno = 0;  	char **gotv; +	int ret; +	ret = 1;  	expectedc = 0;  	if (expectedv != NULL)  		while (expectedv[expectedc] != NULL) @@ -65,44 +77,38 @@ orlv_expect(struct t_file *tf, const char **expectedv, int lines, int eof)  		err(1, "%s(): %s", __func__, tf->name);  	if (expectedv != NULL && gotv == NULL) {  		t_verbose("expected %d words, got nothing\n", expectedc); -		return (0); -	} -	if (expectedv == NULL && gotv != NULL) { +		ret = 0; +	} else if (expectedv == NULL && gotv != NULL) {  		t_verbose("expected nothing, got %d words\n", gotc); -		FREEV(gotc, gotv); -		return (0); -	} -	if (expectedv != NULL && gotv != NULL) { +		ret = 0; +	} else if (expectedv != NULL && gotv != NULL) {  		if (expectedc != gotc) {  			t_verbose("expected %d words, got %d\n",  			    expectedc, gotc); -			FREEV(gotc, gotv); -			return (0); +			ret = 0;  		}  		for (i = 0; i < gotc; ++i) {  			if (strcmp(expectedv[i], gotv[i]) != 0) {  				t_verbose("word %d: expected <<%s>>, "  				    "got <<%s>>\n", i, expectedv[i], gotv[i]); -				FREEV(gotc, gotv); -				return (0); +				ret = 0;  			}  		} -		FREEV(gotc, gotv);  	} +	FREEV(gotc, gotv);  	if (lineno != lines) {  		t_verbose("expected to advance %d lines, advanced %d lines\n",  		    lines, lineno); -		return (0); +		ret = 0;  	}  	if (eof && !t_feof(tf)) {  		t_verbose("expected EOF, but didn't get it\n"); -		return (0); -	} -	if (!eof && t_feof(tf)) { +		ret = 0; +	} else if (!eof && t_feof(tf)) {  		t_verbose("didn't expect EOF, but got it anyway\n"); -		return (0); +		ret = 0;  	} -	return (1); +	return (ret);  } @@ -125,6 +131,23 @@ static const char *hello_world[] = {  	NULL  }; +static const char *numbers[] = { +	"zero", "one", "two", "three", "four", "five", "six", "seven", +	"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", +	"fifteen", "sixteen", "seventeen", "nineteen", "twenty", +	"twenty-one", "twenty-two", "twenty-three", "twenty-four", +	"twenty-five", "twenty-six", "twenty-seven", "twenty-eight", +	"twenty-nine", "thirty", "thirty-one", "thirty-two", "thirty-three", +	"thirty-four", "thirty-five", "thirty-six", "thirty-seven", +	"thirty-eight", "thirty-nine", "fourty", "fourty-one", "fourty-two", +	"fourty-three", "fourty-four", "fourty-five", "fourty-six", +	"fourty-seven", "fourty-eight", "fourty-nine", "fifty", "fifty-one", +	"fifty-two", "fifty-three", "fifty-four", "fifty-five", "fifty-six", +	"fifty-seven", "fifty-eight", "fifty-nine", "sixty", "sixty-one", +	"sixty-two", "sixty-three", +	NULL +}; +  /***************************************************************************   * Lines without words @@ -206,6 +229,20 @@ T_FUNC(whitespace_before_comment, "whitespace before comment")  	return (ret);  } +T_FUNC(line_continuation_within_whitespace, "line continuation within whitespace") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "%s \\\n %s\n", hello_world[0], hello_world[1]); +	t_frewind(tf); +	ret = orlv_expect(tf, hello_world, 2 /*lines*/, 0 /*eof*/) && +	    orlv_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/); +	t_fclose(tf); +	return (ret); +} +  /***************************************************************************   * Simple words @@ -237,6 +274,22 @@ T_FUNC(two_words, "two words")  	return (ret);  } +T_FUNC(many_words, "many words") +{ +	struct t_file *tf; +	const char **word; +	int ret; + +	tf = t_fopen(NULL); +	for (word = numbers; *word; ++word) +		t_fprintf(tf, " %s", *word); +	t_fprintf(tf, "\n"); +	t_frewind(tf); +	ret = orlv_expect(tf, numbers, 1 /*lines*/, 0 /*eof*/); +	t_fclose(tf); +	return (ret); +} +  T_FUNC(unterminated_line, "unterminated line")  {  	struct t_file *tf; @@ -255,31 +308,32 @@ T_FUNC(unterminated_line, "unterminated line")   * Boilerplate   */ -const struct t_test *t_plan[] = { -	T(empty_input), -	T(empty_line), -	T(unterminated_empty_line), -	T(whitespace), -	T(comment), -	T(whitespace_before_comment), - -	T(one_word), -	T(two_words), -	T(unterminated_line), - -	NULL -}; - -const struct t_test ** +static int  t_prepare(int argc, char *argv[])  {  	(void)argc;  	(void)argv; -	return (t_plan); + +	T(empty_input); +	T(empty_line); +	T(unterminated_empty_line); +	T(whitespace); +	T(comment); +	T(whitespace_before_comment); +	T(line_continuation_within_whitespace); + +	T(one_word); +	T(two_words); +	T(many_words); +	T(unterminated_line); + +	return (0);  } -void -t_cleanup(void) +int +main(int argc, char *argv[])  { + +	t_main(t_prepare, NULL, argc, argv);  } diff --git a/t/t_openpam_readword.c b/t/t_openpam_readword.c index d2d6bd5ffd28..767696e52a55 100644 --- a/t/t_openpam_readword.c +++ b/t/t_openpam_readword.c @@ -1,5 +1,5 @@  /*- - * Copyright (c) 2012 Dag-Erling Smørgrav + * Copyright (c) 2012-2015 Dag-Erling Smørgrav   * All rights reserved.   *   * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: t_openpam_readword.c 648 2013-03-05 17:54:27Z des $ + * $Id: t_openpam_readword.c 922 2017-02-19 19:28:30Z des $   */  #ifdef HAVE_CONFIG_H @@ -39,10 +39,18 @@  #include <string.h>  #include <unistd.h> +#include <cryb/test.h> +  #include <security/pam_appl.h>  #include <security/openpam.h> -#include "t.h" +#define T_FUNC(n, d)							\ +	static const char *t_ ## n ## _desc = d;			\ +	static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc),	\ +	    OPENPAM_UNUSED(void *arg)) + +#define T(n)								\ +	t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc)  /*   * Read a word from the temp file and verify that the result matches our @@ -56,49 +64,49 @@ orw_expect(struct t_file *tf, const char *expected, int lines, int eof, int eol)  	int ch, lineno = 0;  	char *got;  	size_t len; +	int ret;  	got = openpam_readword(tf->file, &lineno, &len); +	ret = 1;  	if (t_ferror(tf))  		err(1, "%s(): %s", __func__, tf->name);  	if (expected != NULL && got == NULL) {  		t_verbose("expected <<%s>>, got nothing\n", expected); -		return (0); -	} -	if (expected == NULL && got != NULL) { +		ret = 0; +	} else if (expected == NULL && got != NULL) {  		t_verbose("expected nothing, got <<%s>>\n", got); -		return (0); -	} -	if (expected != NULL && got != NULL && strcmp(expected, got) != 0) { +		ret = 0; +	} else if (expected != NULL && got != NULL && strcmp(expected, got) != 0) {  		t_verbose("expected <<%s>>, got <<%s>>\n", expected, got); -		return (0); +		ret = 0;  	} +	free(got);  	if (lineno != lines) {  		t_verbose("expected to advance %d lines, advanced %d lines\n",  		    lines, lineno); -		return (0); +		ret = 0;  	}  	if (eof && !t_feof(tf)) {  		t_verbose("expected EOF, but didn't get it\n"); -		return (0); +		ret = 0;  	}  	if (!eof && t_feof(tf)) {  		t_verbose("didn't expect EOF, but got it anyway\n"); -		return (0); +		ret = 0;  	}  	ch = fgetc(tf->file);  	if (t_ferror(tf))  		err(1, "%s(): %s", __func__, tf->name);  	if (eol && ch != '\n') {  		t_verbose("expected EOL, but didn't get it\n"); -		return (0); -	} -	if (!eol && ch == '\n') { +		ret = 0; +	} else if (!eol && ch == '\n') {  		t_verbose("didn't expect EOL, but got it anyway\n"); -		return (0); +		ret = 0;  	}  	if (ch != EOF)  		ungetc(ch, tf->file); -	return (1); +	return (ret);  } @@ -195,6 +203,45 @@ T_FUNC(whitespace_before_comment, "whitespace before comment")  	return (ret);  } +T_FUNC(single_quoted_comment, "single-quoted comment") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, " '# comment'\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "# comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(double_quoted_comment, "double-quoted comment") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, " \"# comment\"\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "# comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(comment_at_eof, "comment at end of file") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "# comment"); +	t_frewind(tf); +	ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); +	t_fclose(tf); +	return (ret); +} +  /***************************************************************************   * Simple cases - no quotes or escapes @@ -414,6 +461,33 @@ T_FUNC(escaped_letter, "escaped letter")  	return (ret);  } +T_FUNC(escaped_comment, "escaped comment") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, " \\# comment\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "#", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && +	    orw_expect(tf, "comment", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(escape_at_eof, "escape at end of file") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "z\\"); +	t_frewind(tf); +	ret = orw_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); +	t_fclose(tf); +	return (ret); +} +  /***************************************************************************   * Quotes @@ -820,78 +894,148 @@ T_FUNC(escaped_double_quote_within_double_quotes,  /*************************************************************************** + * Line continuation + */ + +T_FUNC(line_continuation_within_whitespace, "line continuation within whitespace") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "hello \\\n world\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "hello", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && +	    orw_expect(tf, "world", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(line_continuation_before_whitespace, "line continuation before whitespace") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "hello\\\n world\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/) && +	    orw_expect(tf, "world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(line_continuation_after_whitespace, "line continuation after whitespace") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "hello \\\nworld\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "hello", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && +	    orw_expect(tf, "world", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + +T_FUNC(line_continuation_within_word, "line continuation within word") +{ +	struct t_file *tf; +	int ret; + +	tf = t_fopen(NULL); +	t_fprintf(tf, "hello\\\nworld\n"); +	t_frewind(tf); +	ret = orw_expect(tf, "helloworld", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); +	t_fclose(tf); +	return (ret); +} + + +/***************************************************************************   * Boilerplate   */ -const struct t_test *t_plan[] = { -	T(empty_input), -	T(empty_line), -	T(single_whitespace), -	T(multiple_whitespace), -	T(comment), -	T(whitespace_before_comment), - -	T(single_word), -	T(single_whitespace_before_word), -	T(double_whitespace_before_word), -	T(single_whitespace_after_word), -	T(double_whitespace_after_word), -	T(comment_after_word), -	T(word_containing_hash), -	T(two_words), - -	T(naked_escape), -	T(escaped_escape), -	T(escaped_whitespace), -	T(escaped_newline_before_word), -	T(escaped_newline_within_word), -	T(escaped_newline_after_word), -	T(escaped_letter), - -	T(naked_single_quote), -	T(naked_double_quote), -	T(empty_single_quotes), -	T(empty_double_quotes), -	T(single_quotes_within_double_quotes), -	T(double_quotes_within_single_quotes), -	T(single_quoted_whitespace), -	T(double_quoted_whitespace), -	T(single_quoted_words), -	T(double_quoted_words), - -	T(single_quote_before_word), -	T(double_quote_before_word), -	T(single_quote_within_word), -	T(double_quote_within_word), -	T(single_quote_after_word), -	T(double_quote_after_word), - -	T(escaped_single_quote), -	T(escaped_double_quote), -	T(escaped_whitespace_within_single_quotes), -	T(escaped_whitespace_within_double_quotes), -	T(escaped_letter_within_single_quotes), -	T(escaped_letter_within_double_quotes), -	T(escaped_escape_within_single_quotes), -	T(escaped_escape_within_double_quotes), -	T(escaped_single_quote_within_single_quotes), -	T(escaped_double_quote_within_single_quotes), -	T(escaped_single_quote_within_double_quotes), -	T(escaped_double_quote_within_double_quotes), - -	NULL -}; - -const struct t_test ** +static int  t_prepare(int argc, char *argv[])  {  	(void)argc;  	(void)argv; -	return (t_plan); + +	T(empty_input); +	T(empty_line); +	T(unterminated_line); +	T(single_whitespace); +	T(multiple_whitespace); +	T(comment); +	T(whitespace_before_comment); +	T(single_quoted_comment); +	T(double_quoted_comment); +	T(comment_at_eof); + +	T(single_word); +	T(single_whitespace_before_word); +	T(double_whitespace_before_word); +	T(single_whitespace_after_word); +	T(double_whitespace_after_word); +	T(comment_after_word); +	T(word_containing_hash); +	T(two_words); + +	T(naked_escape); +	T(escaped_escape); +	T(escaped_whitespace); +	T(escaped_newline_before_word); +	T(escaped_newline_within_word); +	T(escaped_newline_after_word); +	T(escaped_letter); +	T(escaped_comment); +	T(escape_at_eof); + +	T(naked_single_quote); +	T(naked_double_quote); +	T(empty_single_quotes); +	T(empty_double_quotes); +	T(single_quotes_within_double_quotes); +	T(double_quotes_within_single_quotes); +	T(single_quoted_whitespace); +	T(double_quoted_whitespace); +	T(single_quoted_words); +	T(double_quoted_words); + +	T(single_quote_before_word); +	T(double_quote_before_word); +	T(single_quote_within_word); +	T(double_quote_within_word); +	T(single_quote_after_word); +	T(double_quote_after_word); + +	T(escaped_single_quote); +	T(escaped_double_quote); +	T(escaped_whitespace_within_single_quotes); +	T(escaped_whitespace_within_double_quotes); +	T(escaped_letter_within_single_quotes); +	T(escaped_letter_within_double_quotes); +	T(escaped_escape_within_single_quotes); +	T(escaped_escape_within_double_quotes); +	T(escaped_single_quote_within_single_quotes); +	T(escaped_double_quote_within_single_quotes); +	T(escaped_single_quote_within_double_quotes); +	T(escaped_double_quote_within_double_quotes); + +	T(line_continuation_within_whitespace); +	T(line_continuation_before_whitespace); +	T(line_continuation_after_whitespace); +	T(line_continuation_within_word); + +	return (0);  } -void -t_cleanup(void) +int +main(int argc, char *argv[])  { + +	t_main(t_prepare, NULL, argc, argv);  } diff --git a/t/t_pam_conv.c b/t/t_pam_conv.c new file mode 100644 index 000000000000..58e5c086c1b5 --- /dev/null +++ b/t/t_pam_conv.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2015 Dag-Erling Smørgrav + * All rights reserved. + * + * 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, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $Id: t_pam_conv.c 922 2017-02-19 19:28:30Z des $ + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <err.h> +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <cryb/test.h> + +#include <security/pam_appl.h> +#include <security/openpam.h> + +#include "openpam_impl.h" +#include "openpam_asprintf.h" + +#include "t_pam_conv.h" + +/* + * Conversation function + * + * The appdata argument points to a struct t_pam_conv_script which + * contains both the expected messages and the desired responses.  If + * script.responses is NULL, t_pam_conv() will return PAM_CONV_ERR.  If an + * error occurs (incorrect number of messages, messages don't match script + * etc.), script.comment will be set to point to a malloc()ed string + * describing the error.  Otherwise, t_pam_conv() will return to its + * caller a malloc()ed copy of script.responses. + */ +int +t_pam_conv(int nm, const struct pam_message **msgs, +    struct pam_response **respsp, void *ad) +{ +	struct t_pam_conv_script *s = ad; +	struct pam_response *resps; +	int i; + +	/* check message count */ +	if (nm != s->nmsg) { +		asprintf(&s->comment, "expected %d messages, got %d", +		    s->nmsg, nm); +		return (PAM_CONV_ERR); +	} +	if (nm <= 0 || nm > PAM_MAX_NUM_MSG) { +		/* since the previous test passed, this is intentional! */ +		s->comment = NULL; +		return (PAM_CONV_ERR); +	} + +	/* check each message and provide the sed answer */ +	if ((resps = calloc(nm, sizeof *resps)) == NULL) +		goto enomem; +	for (i = 0; i < nm; ++i) { +		if (msgs[i]->msg_style != s->msgs[i].msg_style) { +			asprintf(&s->comment, +			    "message %d expected style %d got %d", i, +			    s->msgs[i].msg_style, msgs[i]->msg_style); +			goto fail; +		} +		if (strcmp(msgs[i]->msg, s->msgs[i].msg) != 0) { +			asprintf(&s->comment, +			    "message %d expected \"%s\" got \"%s\"", i, +			    s->msgs[i].msg, msgs[i]->msg); +			goto fail; +		} +		switch (msgs[i]->msg_style) { +		case PAM_PROMPT_ECHO_OFF: +			t_verbose("[PAM_PROMPT_ECHO_OFF] %s\n", msgs[i]->msg); +			break; +		case PAM_PROMPT_ECHO_ON: +			t_verbose("[PAM_PROMPT_ECHO_ON] %s\n", msgs[i]->msg); +			break; +		case PAM_ERROR_MSG: +			t_verbose("[PAM_ERROR_MSG] %s\n", msgs[i]->msg); +			break; +		case PAM_TEXT_INFO: +			t_verbose("[PAM_TEXT_INFO] %s\n", msgs[i]->msg); +			break; +		default: +			asprintf(&s->comment, "invalid message style %d", +			    msgs[i]->msg_style); +			goto fail; +		} +		/* copy the response, if there is one */ +		if (s->resps[i].resp != NULL && +		    (resps[i].resp = strdup(s->resps[i].resp)) == NULL) +			goto enomem; +		resps[i].resp_retcode = s->resps[i].resp_retcode; +	} +	s->comment = NULL; +	*respsp = resps; +	return (PAM_SUCCESS); +enomem: +	asprintf(&s->comment, "%s", strerror(ENOMEM)); +fail: +	for (i = 0; i < nm; ++i) +		free(resps[i].resp); +	free(resps); +	return (PAM_CONV_ERR); +} diff --git a/t/t.h b/t/t_pam_conv.h index 1e156bd03e76..ab0749744594 100644 --- a/t/t.h +++ b/t/t_pam_conv.h @@ -1,5 +1,5 @@  /*- - * Copyright (c) 2012 Dag-Erling Smørgrav + * Copyright (c) 2015 Dag-Erling Smørgrav   * All rights reserved.   *   * Redistribution and use in source and binary forms, with or without @@ -26,58 +26,20 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: t.h 657 2013-03-06 22:59:05Z des $ + * $Id: t_pam_conv.h 863 2015-07-30 23:44:31Z des $   */ -#ifndef T_H_INCLUDED -#define T_H_INCLUDED +#ifndef T_PAM_CONV_H_INCLUDED +#define T_PAM_CONV_H_INCLUDED -#include <security/openpam_attr.h> - -struct t_test { -	int (*func)(void *); -	const char *desc; -	void *arg; -}; - -#define T_FUNC(n, d)				\ -	static int t_ ## n ## _func(void *);	\ -	static const struct t_test t_ ## n =	\ -	    { t_ ## n ## _func, d, NULL };	\ -	static int t_ ## n ## _func(OPENPAM_UNUSED(void *arg)) - -#define T_FUNC_ARG(n, d, a)			\ -	static int t_ ## n ## _func(void *);	\ -	static const struct t_test t_ ## n =	\ -	    { t_ ## n ## _func, d, a };		\ -	static int t_ ## n ## _func(void *arg) - -#define T(n)					\ -	&t_ ## n - -extern const char *t_progname; - -const struct t_test **t_prepare(int, char **); -void t_cleanup(void); - -void t_verbose(const char *, ...) -	OPENPAM_FORMAT((__printf__, 1, 2)); - -/* - * Convenience functions for temp files - */ -struct t_file { -	char *name; -	FILE *file; -	struct t_file *prev, *next; +struct t_pam_conv_script { +	int			 nmsg; +	struct pam_message	*msgs; +	struct pam_response	*resps; +	char			*comment;  }; -struct t_file *t_fopen(const char *); -int t_fprintf(struct t_file *, const char *, ...); -int t_ferror(struct t_file *); -int t_feof(struct t_file *); -void t_frewind(struct t_file *); -void t_fclose(struct t_file *); -void t_fcloseall(void); +int t_pam_conv(int, const struct pam_message **, struct pam_response **, +	void *);  #endif  | 
