diff options
-rw-r--r-- | ChangeLog | 79 | ||||
-rw-r--r-- | NEWS | 11 | ||||
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | lib/cli++/main.cc | 29 | ||||
-rw-r--r-- | nullmailer-1.11.spec (renamed from nullmailer-1.10.spec) | 2 | ||||
-rw-r--r-- | protocols/protocol.cc | 2 | ||||
-rw-r--r-- | protocols/protocol.h | 1 | ||||
-rw-r--r-- | protocols/tls_gnutls.cc | 7 | ||||
-rw-r--r-- | src/sendmail.cc | 15 | ||||
-rw-r--r-- | test/Makefile.am | 13 | ||||
-rw-r--r-- | test/Makefile.in | 60 | ||||
-rw-r--r-- | test/clitest.cc | 45 | ||||
-rw-r--r-- | test/clitest.sh | 81 |
15 files changed, 314 insertions, 39 deletions
@@ -1,3 +1,82 @@ +commit ef77697eafa9033063fe9e3c546f2f1e451da005 +Author: Bruce Guenter <bruce@untroubled.org> +Date: Thu Jun 14 09:44:38 2012 -0600 + + Tagged the README with today's date + + README | 4 ++-- + 1 files changed, 2 insertions(+), 2 deletions(-) + +commit d5a7ce0be1d08d3a3636af471241346e219306a4 +Author: Bruce Guenter <bruce@untroubled.org> +Date: Tue Jun 12 14:52:50 2012 -0600 + + protocols: Add support for client certificate files. + + NEWS | 2 ++ + protocols/protocol.cc | 2 ++ + protocols/protocol.h | 1 + + protocols/tls_gnutls.cc | 4 ++++ + 4 files changed, 9 insertions(+), 0 deletions(-) + +commit 16674b30624c3240aad4b4ad1b9e85e6c08f7e8e +Author: Bruce Guenter <bruce@untroubled.org> +Date: Tue Jun 12 14:47:15 2012 -0600 + + sendmail: Ignore all sendmail options + + NEWS | 2 +- + src/sendmail.cc | 21 +-------------------- + 2 files changed, 2 insertions(+), 21 deletions(-) + +commit 2704d1305f3d7c474520b3c5cb0063d36b180698 +Author: Bruce Guenter <bruce@untroubled.org> +Date: Tue Jun 12 14:21:44 2012 -0600 + + lib/cli++: Fix handling of single-char options with values + + Invoking 'sendmail -FNAME' fails without this patch. + + This change also introduces a set of self-tests. + + NEWS | 2 + + lib/cli++/main.cc | 29 ++++++++++++------- + test/Makefile.am | 13 +++++++- + test/clitest.cc | 45 +++++++++++++++++++++++++++++ + test/clitest.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 5 files changed, 157 insertions(+), 13 deletions(-) + create mode 100644 test/clitest.cc + create mode 100644 test/clitest.sh + +commit dd9bb3ece55d2ce2b940b67e069d4ce800f54b5e +Author: Bruce Guenter <bruce@untroubled.org> +Date: Tue Jun 12 08:31:13 2012 -0600 + + sendmail: Add -odd -odi and -odq options for compatibility + + NEWS | 2 ++ + src/sendmail.cc | 6 ++++++ + 2 files changed, 8 insertions(+), 0 deletions(-) + +commit f6f6a935463211a4e2fccb12448824bf82fd2362 +Author: Bruce Guenter <bruce@untroubled.org> +Date: Tue Jun 12 08:30:43 2012 -0600 + + Bump version to 1.11 + + NEWS | 5 +++++ + configure.in | 2 +- + 2 files changed, 6 insertions(+), 1 deletions(-) + +commit e6bc62f9ba314c024c8cb96574b9e9897d1624c2 +Author: Bruce Guenter <bruce@untroubled.org> +Date: Thu May 24 15:49:00 2012 -0600 + + protocols: Remove unneeded (?) gnutls/abstract.h include + + protocols/tls_gnutls.cc | 3 --- + 1 files changed, 0 insertions(+), 3 deletions(-) + commit 221121d4d568e6e3922654641645dbace6f1cc43 Author: Bruce Guenter <bruce@untroubled.org> Date: Tue Apr 24 09:41:44 2012 -0600 @@ -1,5 +1,16 @@ This file lists all the major user-visible changes to nullmailer. ------------------------------------------------------------------------------- +Changes in version 1.11 + +- Simplify (and expand) handling of ignored sendmail options. + +- Fixed command-line interpretation of short options with values. + +- Added support for SSL/TLS client certificates. + +Development of this version has been sponsored by FutureQuest, Inc. +ossi@FutureQuest.net http://www.FutureQuest.net/ +------------------------------------------------------------------------------- Changes in version 1.10 - Added support for SMTPS (SMTP over SSL/TLS) and STARTTLS. @@ -1,8 +1,8 @@ nullmailer Simple relay-only mail transport agent Bruce Guenter <bruce@untroubled.org> -Version 1.10 -2012-04-24 +Version 1.11 +2012-06-14 This is nullmailer, a sendmail/qmail/etc replacement MTA for hosts which relay to a fixed set of smart relays. It is designed to be simple to @@ -2660,7 +2660,7 @@ fi # Define the identity of the package. PACKAGE=nullmailer - VERSION=1.10 + VERSION=1.11 cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index 1e9da2f..88521a7 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ AC_INIT AC_LANG([C++]) AC_CONFIG_SRCDIR([lib/defines.h]) -AM_INIT_AUTOMAKE(nullmailer, 1.10) +AM_INIT_AUTOMAKE(nullmailer, 1.11) AM_CONFIG_HEADER(config.h) AC_PROG_MAKE_SET diff --git a/lib/cli++/main.cc b/lib/cli++/main.cc index f0eb014..406e990 100644 --- a/lib/cli++/main.cc +++ b/lib/cli++/main.cc @@ -36,6 +36,7 @@ static cli_option help_option = { 'h', "help", cli_option::flag, static cli_option** options; static unsigned optionc; +static const char* short_options; static void build_options() { @@ -47,6 +48,13 @@ static void build_options() for(unsigned i = 0; i < optionc-1; i++) options[i] = &cli_options[i]; options[optionc-1] = &help_option; + + char* so; + short_options = so = new char[optionc+1]; + for (unsigned i = 0; i < optionc; i++) + if (options[i]->ch != 0) + *so++ = options[i]->ch; + *so = 0; } static inline int max(int a, int b) @@ -275,14 +283,6 @@ static int parse_long(int, char* argv[]) ++arg; for(unsigned j = 0; j < optionc; j++) { cli_option* o = options[j]; - if (cli_only_long && o->ch) { - if (arg[0] == o->ch) { - if (arg[1] == '\0') - return o->parse_long_noeq(argv[1], true); - else if (arg[1] == '=') - return o->parse_long_eq(arg+2, true); - } - } if(o->name) { size_t len = strlen(o->name); if(!memcmp(arg, o->name, len)) { @@ -297,6 +297,13 @@ static int parse_long(int, char* argv[]) return -1; } +static int parse_either(int argc, char* argv[]) +{ + return (strchr(short_options, argv[0][1]) != 0) + ? parse_short(argc, argv) + : parse_long(argc, argv); +} + static int parse_args(int argc, char* argv[]) { build_options(); @@ -312,9 +319,9 @@ static int parse_args(int argc, char* argv[]) i++; break; } - int j = (!cli_only_long && arg[1] != '-') - ? parse_short(argc-i, argv+i) - : parse_long(argc-i, argv+i); + int j = (arg[1] == '-') ? parse_long(argc-i, argv+i) + : cli_only_long ? parse_either(argc-i, argv+i) + : parse_short(argc-i, argv+i); if(j < 0) usage(1); else diff --git a/nullmailer-1.10.spec b/nullmailer-1.11.spec index 0c53b32..c104742 100644 --- a/nullmailer-1.10.spec +++ b/nullmailer-1.11.spec @@ -1,6 +1,6 @@ Name: nullmailer Summary: Simple relay-only mail transport agent -Version: 1.10 +Version: 1.11 Release: 1 License: GPL Group: Networking/Daemons diff --git a/protocols/protocol.cc b/protocols/protocol.cc index 6fc6263..9b0b834 100644 --- a/protocols/protocol.cc +++ b/protocols/protocol.cc @@ -51,6 +51,8 @@ cli_option cli_options[] = { "Connect using SSL (on an alternate port by default)", 0 }, { 0, "starttls", cli_option::flag, 1, &use_starttls, "Use STARTTLS command", 0 }, + { 0, "x509certfile", cli_option::string, 0, &tls_x509certfile, + "Client certificate file", 0 }, { 0, "x509cafile", cli_option::string, 0, &tls_x509cafile, "Certificate authority trust file", DEFAULT_CA_FILE }, { 0, "x509crlfile", cli_option::string, 0, &tls_x509crlfile, diff --git a/protocols/protocol.h b/protocols/protocol.h index 0910ada..c335b04 100644 --- a/protocols/protocol.h +++ b/protocols/protocol.h @@ -26,6 +26,7 @@ extern void protocol_send(fdibuf& in, fdibuf& netin, fdobuf& netout); extern void protocol_starttls(fdibuf& netin, fdobuf& netout); extern int tls_insecure; +extern const char* tls_x509certfile; extern const char* tls_x509cafile; extern const char* tls_x509crlfile; extern int tls_x509derfmt; diff --git a/protocols/tls_gnutls.cc b/protocols/tls_gnutls.cc index fca8437..2941c0b 100644 --- a/protocols/tls_gnutls.cc +++ b/protocols/tls_gnutls.cc @@ -25,14 +25,12 @@ #include "mystring/mystring.h" #include "protocol.h" #include <gnutls/gnutls.h> -#ifdef HAVE_GNUTLS_SET_VERIFY_FUNCTION -#include <gnutls/abstract.h> -#endif #include <gnutls/x509.h> #include "fdbuf/tlsibuf.h" #include "fdbuf/tlsobuf.h" int tls_insecure = false; +const char* tls_x509certfile = NULL; const char* tls_x509cafile = NULL; const char* tls_x509crlfile = NULL; int tls_x509derfmt = false; @@ -99,6 +97,9 @@ void tls_init(const char* remote) gnutls_certificate_set_verify_flags(creds, 0); gnutls_x509_crt_fmt_t x509fmt = tls_x509derfmt ? GNUTLS_X509_FMT_DER : GNUTLS_X509_FMT_PEM; + if (tls_x509certfile != NULL) + gnutls_wrap(gnutls_certificate_set_x509_key_file(creds, tls_x509certfile, tls_x509certfile, x509fmt), + "Error setting SSL/TLS X.509 client certificate"); if (tls_x509cafile == NULL && access(DEFAULT_CA_FILE, R_OK) == 0) tls_x509cafile = DEFAULT_CA_FILE; if (tls_x509cafile != NULL) diff --git a/src/sendmail.cc b/src/sendmail.cc index f245226..7713d3f 100644 --- a/src/sendmail.cc +++ b/src/sendmail.cc @@ -66,26 +66,13 @@ cli_option cli_options[] = { { 'N', 0, cli_option::string, 0, &o_dummys, "Ignored", 0 }, { 'n', 0, cli_option::flag, 0, &o_dummyi, "Ignored", 0 }, { 'O', 0, cli_option::string, 0, &o_dummys, "Ignored", 0 }, - { 0, "odb", cli_option::flag, 0, &o_dummyi, - "Deliver in background (always true)", 0 }, - { 0, "odf", cli_option::flag, 0, &o_dummyi, - "Deliver in foreground (ignored)", 0 }, - { 0, "oem", cli_option::flag, 0, &o_dummyi, - "Ignored", 0 }, + { 'o', 0, cli_option::string, 0, &o_dummys, "Set sendmail option, ignored", 0 }, { 0, "em", cli_option::flag, 0, &o_dummyi, "Ignored", 0 }, - { 0, "oep", cli_option::flag, 0, &o_dummyi, - "Ignored", 0 }, { 0, "ep", cli_option::flag, 0, &o_dummyi, "Ignored", 0 }, - { 0, "oeq", cli_option::flag, 0, &o_dummyi, - "Ignored", 0 }, { 0, "eq", cli_option::flag, 0, &o_dummyi, "Ignored", 0 }, - { 0, "oi", cli_option::flag, 0, &o_dummyi, - "Ignored", 0 }, - { 0, "om", cli_option::flag, 0, &o_dummyi, - "Ignored", 0 }, { 'p', 0, cli_option::string, 0, &o_dummys, "Ignored", 0 }, { 'q', 0, cli_option::string, 0, &o_dummys, "Ignored", 0 }, { 'R', 0, cli_option::string, 0, &o_dummys, "Ignored", 0 }, diff --git a/test/Makefile.am b/test/Makefile.am index 2c1d7dd..8f7934c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,19 @@ -noinst_PROGRAMS = address-test -EXTRA_DIST = address-trace.cc +noinst_PROGRAMS = address-test clitest0 clitest1 +EXTRA_DIST = address-trace.cc clitest.cc clitest.sh INCLUDES = -I../lib address_test_SOURCES = address-test.cc # address-trace.cc address_test_LDADD = ../lib/libnullmailer.a +clitest0_CPPFLAGS = -DCLI_ONLY_LONG=false +clitest0_SOURCES = clitest.cc +clitest0_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a + +clitest1_CPPFLAGS = -DCLI_ONLY_LONG=true +clitest1_SOURCES = clitest.cc +clitest1_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a + # The following makes sure that we can't produce a package without the # tests executing properly dist-hook: test @@ -13,6 +21,7 @@ dist-hook: test test: all ./address-test + sh clitest.sh @failed=0; \ for test in `find tests -type f -not -name '.*.swp'`; do \ echo Running test $$test...; \ diff --git a/test/Makefile.in b/test/Makefile.in index ab2ea26..dfcad89 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -31,7 +31,8 @@ POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -noinst_PROGRAMS = address-test$(EXEEXT) +noinst_PROGRAMS = address-test$(EXEEXT) clitest0$(EXEEXT) \ + clitest1$(EXEEXT) subdir = test DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -46,6 +47,12 @@ PROGRAMS = $(noinst_PROGRAMS) am_address_test_OBJECTS = address-test.$(OBJEXT) address_test_OBJECTS = $(am_address_test_OBJECTS) address_test_DEPENDENCIES = ../lib/libnullmailer.a +am_clitest0_OBJECTS = clitest0-clitest.$(OBJEXT) +clitest0_OBJECTS = $(am_clitest0_OBJECTS) +clitest0_DEPENDENCIES = ../lib/libnullmailer.a ../lib/cli++/libcli++.a +am_clitest1_OBJECTS = clitest1-clitest.$(OBJEXT) +clitest1_OBJECTS = $(am_clitest1_OBJECTS) +clitest1_DEPENDENCIES = ../lib/libnullmailer.a ../lib/cli++/libcli++.a DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -54,8 +61,10 @@ CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ CXXLD = $(CXX) CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $@ -SOURCES = $(address_test_SOURCES) -DIST_SOURCES = $(address_test_SOURCES) +SOURCES = $(address_test_SOURCES) $(clitest0_SOURCES) \ + $(clitest1_SOURCES) +DIST_SOURCES = $(address_test_SOURCES) $(clitest0_SOURCES) \ + $(clitest1_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -152,10 +161,16 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -EXTRA_DIST = address-trace.cc +EXTRA_DIST = address-trace.cc clitest.cc clitest.sh INCLUDES = -I../lib address_test_SOURCES = address-test.cc # address-trace.cc address_test_LDADD = ../lib/libnullmailer.a +clitest0_CPPFLAGS = -DCLI_ONLY_LONG=false +clitest0_SOURCES = clitest.cc +clitest0_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a +clitest1_CPPFLAGS = -DCLI_ONLY_LONG=true +clitest1_SOURCES = clitest.cc +clitest1_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a all: all-am .SUFFIXES: @@ -195,6 +210,12 @@ clean-noinstPROGRAMS: address-test$(EXEEXT): $(address_test_OBJECTS) $(address_test_DEPENDENCIES) @rm -f address-test$(EXEEXT) $(CXXLINK) $(address_test_OBJECTS) $(address_test_LDADD) $(LIBS) +clitest0$(EXEEXT): $(clitest0_OBJECTS) $(clitest0_DEPENDENCIES) + @rm -f clitest0$(EXEEXT) + $(CXXLINK) $(clitest0_OBJECTS) $(clitest0_LDADD) $(LIBS) +clitest1$(EXEEXT): $(clitest1_OBJECTS) $(clitest1_DEPENDENCIES) + @rm -f clitest1$(EXEEXT) + $(CXXLINK) $(clitest1_OBJECTS) $(clitest1_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -203,6 +224,8 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/address-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clitest0-clitest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clitest1-clitest.Po@am__quote@ .cc.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -218,6 +241,34 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` +clitest0-clitest.o: clitest.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest0_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT clitest0-clitest.o -MD -MP -MF $(DEPDIR)/clitest0-clitest.Tpo -c -o clitest0-clitest.o `test -f 'clitest.cc' || echo '$(srcdir)/'`clitest.cc +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/clitest0-clitest.Tpo $(DEPDIR)/clitest0-clitest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='clitest.cc' object='clitest0-clitest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest0_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o clitest0-clitest.o `test -f 'clitest.cc' || echo '$(srcdir)/'`clitest.cc + +clitest0-clitest.obj: clitest.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest0_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT clitest0-clitest.obj -MD -MP -MF $(DEPDIR)/clitest0-clitest.Tpo -c -o clitest0-clitest.obj `if test -f 'clitest.cc'; then $(CYGPATH_W) 'clitest.cc'; else $(CYGPATH_W) '$(srcdir)/clitest.cc'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/clitest0-clitest.Tpo $(DEPDIR)/clitest0-clitest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='clitest.cc' object='clitest0-clitest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest0_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o clitest0-clitest.obj `if test -f 'clitest.cc'; then $(CYGPATH_W) 'clitest.cc'; else $(CYGPATH_W) '$(srcdir)/clitest.cc'; fi` + +clitest1-clitest.o: clitest.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest1_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT clitest1-clitest.o -MD -MP -MF $(DEPDIR)/clitest1-clitest.Tpo -c -o clitest1-clitest.o `test -f 'clitest.cc' || echo '$(srcdir)/'`clitest.cc +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/clitest1-clitest.Tpo $(DEPDIR)/clitest1-clitest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='clitest.cc' object='clitest1-clitest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest1_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o clitest1-clitest.o `test -f 'clitest.cc' || echo '$(srcdir)/'`clitest.cc + +clitest1-clitest.obj: clitest.cc +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest1_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT clitest1-clitest.obj -MD -MP -MF $(DEPDIR)/clitest1-clitest.Tpo -c -o clitest1-clitest.obj `if test -f 'clitest.cc'; then $(CYGPATH_W) 'clitest.cc'; else $(CYGPATH_W) '$(srcdir)/clitest.cc'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/clitest1-clitest.Tpo $(DEPDIR)/clitest1-clitest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='clitest.cc' object='clitest1-clitest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(clitest1_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o clitest1-clitest.obj `if test -f 'clitest.cc'; then $(CYGPATH_W) 'clitest.cc'; else $(CYGPATH_W) '$(srcdir)/clitest.cc'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ @@ -414,6 +465,7 @@ dist-hook: test test: all ./address-test + sh clitest.sh @failed=0; \ for test in `find tests -type f -not -name '.*.swp'`; do \ echo Running test $$test...; \ diff --git a/test/clitest.cc b/test/clitest.cc new file mode 100644 index 0000000..c819972 --- /dev/null +++ b/test/clitest.cc @@ -0,0 +1,45 @@ +#include "cli++/cli++.h" +#include "fdbuf/fdbuf.h" + +const char* cli_program = "clitest"; +const char* cli_help_prefix = "Nullmailer CLI test harness\n"; +const char* cli_help_suffix = 0; +const char* cli_args_usage = "[args]"; +const int cli_args_min = 0; +const int cli_args_max = -1; +const bool cli_only_long = CLI_ONLY_LONG; + +static int a = 0; +static int b = 0; +static const char* c = 0; +static const char* d = 0; + +cli_option cli_options[] = { + { 'a', 0, cli_option::flag, 1, &a, "Test flag", 0 }, + { 0, "bb", cli_option::flag, 1, &b, "Test flag", 0 }, + { 'c', 0, cli_option::string, 1, &c, "Test string", 0 }, + { 0, "dd", cli_option::string, 1, &d, "Test string", 0 }, + CLI_OPTION_END +}; + +static void showcstr(const char* name, const char* value) +{ + fout << ' ' << name; + if (value == NULL) + fout << "=NULL"; + else + fout << "=\"" << value << "\""; +} + +int cli_main(int argc, char* argv[]) +{ + fout << "argc=" << argc + << " a=" << a + << " b=" << b; + showcstr("c", c); + showcstr("d", d); + fout << endl; + for (int i = 0; i < argc; i++) + fout << "argv[" << i << "]=\"" << argv[i] << "\"" << endl; + return 0; +} diff --git a/test/clitest.sh b/test/clitest.sh new file mode 100644 index 0000000..a60133b --- /dev/null +++ b/test/clitest.sh @@ -0,0 +1,81 @@ +tmp=$PWD/clitest.tmp +trap 'rm -f ${tmp}*' EXIT + +testit() { + test "x$1" = 'x!' && isfailed='-eq 0' || isfailed='-ne 0' + "$@" >$tmp.out 2>/dev/null + if [ $? $isfailed ] + then + echo "Test \"$*\" failed!" + exit 1 + fi + if [ "x$1" != 'x!' ] + then + cat >$tmp.exp + if ! diff -u $tmp.exp $tmp.out + then + echo "Test \"$*\" failed!" + exit 1 + fi + fi +} + +testit ./clitest0 <<EOF +argc=0 a=0 b=0 c=NULL d=NULL +EOF +testit ./clitest1 <<EOF +argc=0 a=0 b=0 c=NULL d=NULL +EOF + +testit ! ./clitest0 -abb +testit ! ./clitest1 -abb + +testit ! ./clitest0 -a -bb +testit ./clitest1 -a -bb <<EOF +argc=0 a=1 b=1 c=NULL d=NULL +EOF + +testit ./clitest0 -a --bb <<EOF +argc=0 a=1 b=1 c=NULL d=NULL +EOF +testit ./clitest1 -a --bb <<EOF +argc=0 a=1 b=1 c=NULL d=NULL +EOF + +testit ./clitest0 -ctest <<EOF +argc=0 a=0 b=0 c="test" d=NULL +EOF +testit ./clitest1 -ctest <<EOF +argc=0 a=0 b=0 c="test" d=NULL +EOF + +testit ! ./clitest0 -ddtest +testit ! ./clitest1 -ddtest +testit ! ./clitest0 --ddtest +testit ! ./clitest1 --ddtest + +testit ! ./clitest0 -dd test +testit ./clitest1 -dd test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF + +testit ./clitest0 --dd test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF +testit ./clitest1 --dd test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF + +testit ! ./clitest0 -dd=test +testit ./clitest1 -dd=test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF + +testit ./clitest0 --dd=test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF +testit ./clitest1 --dd=test <<EOF +argc=0 a=0 b=0 c=NULL d="test" +EOF + +echo "All tests passed." |