From: Baptiste Daroussin Date: Mon, 24 Oct 2022 08:19:03 +0000 (+0200) Subject: mlmmj-send: validate argument for -l option X-Git-Tag: RELEASE_1_4_0a1~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fc15e152bbf337172d8af8b74cd189ee610d4e3;p=thirdparty%2Fmlmmj.git mlmmj-send: validate argument for -l option validate the argument for -l option, while here turn the "archive" into a boolean --- diff --git a/configure.ac b/configure.ac index 9e41a537..a94ad43b 100644 --- a/configure.ac +++ b/configure.ac @@ -56,4 +56,5 @@ AC_CONFIG_FILES([contrib/Makefile]) AC_CONFIG_FILES([contrib/receivestrip/Makefile]) AC_CONFIG_FILES([tests/Makefile]) AC_CONFIG_FILES([tests/Kyuafile]) +AC_CONFIG_FILES([tests/test_env.sh]) AC_OUTPUT diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index 2a4cc851..8db2385a 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -60,6 +60,7 @@ #include "wrappers.h" #include "statctrl.h" #include "ctrlvalue.h" +#include "stdbool.h" #include "getaddrsfromfd.h" static int addtohdr = 0; @@ -793,7 +794,8 @@ int main(int argc, char **argv) { size_t len = 0, hdrslen, bodylen; int sockfd = -1, mailfd = 0, opt, mindex = 0, subfd = 0, tmpfd, i; - int deletewhensent = 1, sendres = 0, archive = 1, digest = 0; + int deletewhensent = 1, sendres = 0, digest = 0; + bool archive = true; int ctrlarchive, res; char *listaddr = NULL, *listdelim = NULL; char *mailfilename = NULL, *subfilename = NULL, *omit = NULL; @@ -831,7 +833,7 @@ int main(int argc, char **argv) while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:o:")) != -1){ switch(opt) { case 'a': - archive = 0; + archive = false; break; case 'D': deletewhensent = 0; @@ -843,7 +845,12 @@ int main(int argc, char **argv) print_help(argv[0]); break; case 'l': + if (*optarg <= '0' || *optarg > '7') + errx(EXIT_FAILURE, "-l only accept the " + "following arguments: 1, 2, 3, 4, 5, 6 or" + " 7"); listctrl = optarg; + archive = false; break; case 'L': listdir = optarg; @@ -929,19 +936,6 @@ int main(int argc, char **argv) stl.strs = NULL; stl.count = 0; - switch(listctrl[0]) { - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - archive = 0; - default: - break; - } - if(listdir && listctrl[0] != '5') listaddr = getlistaddr(listdir); @@ -1031,7 +1025,7 @@ int main(int argc, char **argv) } break; case '6': - archive = 0; + archive = false; deletewhensent = 0; archivefilename = xstrdup(mailfilename); bounceaddr = bounce_from_adr(to_addr, listaddr, listdelim, diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in new file mode 100644 index 00000000..4d5c0e4c --- /dev/null +++ b/tests/Kyuafile.in @@ -0,0 +1,6 @@ +syntax(2) + +test_suite('mlmmj') + +atf_test_program{name='mlmmj'} +atf_test_program{name='mlmmj-send'} diff --git a/tests/Makefile.am b/tests/Makefile.am index 5e61cda7..770e78dc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,8 +7,15 @@ mlmmj_SOURCES = mlmmj.c AM_CFLAGS = -g -Wall -pedantic -Wsign-compare -DDEFAULTTEXTDIR='"@textlibdir@"' -I$(srcdir)/../include @ATF_CFLAGS@ mlmmj_LDADD = $(top_builddir)/src/libmlmmj.a @ATF_LIBS@ +test_scripts = mlmmj-send.sh +check_SCRIPTS= $(test_scripts:.sh=) +SUFFIXES= .sh + all: $(check_PROGRAMS) $(check_SCRIPTS) check: $(check_SCRIPTS) $(check_PROGRAMS) kyua --config=none test --kyuafile='$(builddir)/Kyuafile' \ --build-root='$(builddir)' + +.sh: + install -m 755 $< $@ diff --git a/tests/mlmmj-send.sh b/tests/mlmmj-send.sh new file mode 100644 index 00000000..026b3a71 --- /dev/null +++ b/tests/mlmmj-send.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh + +tests_init \ + basics + +basics_body() +{ + + mlmmjsend=$(command -v mlmmj-send) + helptxt="Usage: $mlmmjsend [-L /path/to/list -m /path/to/mail | -l listctrl] + [-a] [-D] [-F sender@example.org] [-h] [-o address@example.org] + [-r 127.0.0.1] [-R reply@example.org] [-s /path/to/subscribers] + [-T recipient@example.org] [-V] + -a: Don't archive the mail + -D: Don't delete the mail after it's sent + -F: What to use as MAIL FROM: + -h: This help + -l: List control variable: + '1' means 'send a single mail' + '2' means 'mail to moderators' + '3' means 'resend failed list mail' + '4' means 'send to file with recipients' + '5' means 'bounceprobe' + '6' means 'single listmail to single recipient' + '7' means 'digest' + -L: Full path to list directory + -m: Full path to mail file + -o: Address to omit from distribution (normal mail only) + -r: Relayhost IP address (defaults to 127.0.0.1) + -R: What to use as Reply-To: header + -s: Subscribers file name + -T: What to use as RCPT TO: + -V: Print version +" + init_ml ml + + atf_check -s exit:1 -e "inline:mlmmj-send: You have to specify -m and -L or -l\n$mlmmjsend -h for help\n" $mlmmjsend + atf_check -s exit:0 -o "inline:mlmmj-send version 1.3.0\n" $mlmmjsend -V + atf_check -s exit:0 -o "inline:$helptxt" $mlmmjsend -h + atf_check -s exit:1 -e "inline:mlmmj-send: -l only accept the following arguments: 1, 2, 3, 4, 5, 6 or 7\n" $mlmmjsend -l 8 + atf_check -s exit:1 -e "inline:mlmmj-send: -l only accept the following arguments: 1, 2, 3, 4, 5, 6 or 7\n" $mlmmjsend -l 0 +} diff --git a/tests/test_env.sh.in b/tests/test_env.sh.in new file mode 100644 index 00000000..4681fea3 --- /dev/null +++ b/tests/test_env.sh.in @@ -0,0 +1,37 @@ +srcdir="$(atf_get_srcdir)" +export PATH="$srcdir/../src:${PATH}" + +selfdir="@abs_top_srcdir@/tests" +LIBRARY_PATH_ENV="LIBRARY_PATH" +SYSROOT_DIR="${selfdir}" + +prefix="@prefix@" +exec_prefix="@exec_prefix@" +datarootdir="@datarootdir@" +pcpath="@PKG_DEFAULT_PATH@" + +tests_init() +{ + TESTS="$@" + export TESTS + for t ; do + atf_test_case $t + done +} + +atf_init_test_cases() { + for t in ${TESTS}; do + atf_add_test_case $t + done +} + +init_ml() +{ + local ml="$1" + mkdir "$ml" + for d in incoming queue queue/discarded archive text subconf unsubconf \ + bounce control moderation subscribers.d digesters.d requeue \ + nomailsubs.d; do + mkdir $ml/$d + done +}