diff options
author | Damien Miller <djm@mindrot.org> | 2018-07-20 06:53:42 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-07-20 06:55:29 +0200 |
commit | c59aca8adbdf7f5597084ad360a19bedb3f80970 (patch) | |
tree | 79912187691e15a3d34db3fff61f6dfdacb03def | |
parent | upstream: remove unused zlib.h (diff) | |
download | openssh-c59aca8adbdf7f5597084ad360a19bedb3f80970.tar.xz openssh-c59aca8adbdf7f5597084ad360a19bedb3f80970.zip |
Create control sockets in clean temp directories
Adds a regress/mkdtemp tool and uses it to create empty temp
directories for tests needing control sockets.
Patch from Colin Watson via bz#2660; ok dtucker
-rw-r--r-- | Makefile.in | 8 | ||||
-rw-r--r-- | regress/forwarding.sh | 3 | ||||
-rw-r--r-- | regress/mkdtemp.c | 59 | ||||
-rw-r--r-- | regress/multiplex.sh | 3 | ||||
-rw-r--r-- | regress/test-exec.sh | 12 |
5 files changed, 83 insertions, 2 deletions
diff --git a/Makefile.in b/Makefile.in index e09e27954..c3b67aa61 100644 --- a/Makefile.in +++ b/Makefile.in @@ -230,6 +230,7 @@ clean: regressclean rm -f *.o *.a $(TARGETS) logintest config.cache config.log rm -f *.out core survey rm -f regress/check-perm$(EXEEXT) + rm -f regress/mkdtemp$(EXEEXT) rm -f regress/unittests/test_helper/*.a rm -f regress/unittests/test_helper/*.o rm -f regress/unittests/sshbuf/*.o @@ -258,6 +259,8 @@ distclean: regressclean rm -f Makefile buildpkg.sh config.h config.status rm -f survey.sh openbsd-compat/regress/Makefile *~ rm -rf autom4te.cache + rm -f regress/check-perm + rm -f regress/mkdtemp rm -f regress/unittests/test_helper/*.a rm -f regress/unittests/test_helper/*.o rm -f regress/unittests/sshbuf/*.o @@ -460,6 +463,10 @@ regress/check-perm$(EXEEXT): $(srcdir)/regress/check-perm.c $(REGRESSLIBS) $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(srcdir)/regress/check-perm.c \ $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS) +regress/mkdtemp$(EXEEXT): $(srcdir)/regress/mkdtemp.c $(REGRESSLIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(srcdir)/regress/mkdtemp.c \ + $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS) + UNITTESTS_TEST_HELPER_OBJS=\ regress/unittests/test_helper/test_helper.o \ regress/unittests/test_helper/fuzz.o @@ -568,6 +575,7 @@ regress-binaries: regress/modpipe$(EXEEXT) \ regress/setuid-allowed$(EXEEXT) \ regress/netcat$(EXEEXT) \ regress/check-perm$(EXEEXT) \ + regress/mkdtemp$(EXEEXT) \ regress/unittests/sshbuf/test_sshbuf$(EXEEXT) \ regress/unittests/sshkey/test_sshkey$(EXEEXT) \ regress/unittests/bitmap/test_bitmap$(EXEEXT) \ diff --git a/regress/forwarding.sh b/regress/forwarding.sh index 39fccba73..7d0fae114 100644 --- a/regress/forwarding.sh +++ b/regress/forwarding.sh @@ -10,7 +10,8 @@ start_sshd base=33 last=$PORT fwd="" -CTL=/tmp/openssh.regress.ctl-sock.$$ +make_tmpdir +CTL=${SSH_REGRESS_TMP}/ctl-sock for j in 0 1 2; do for i in 0 1 2; do diff --git a/regress/mkdtemp.c b/regress/mkdtemp.c new file mode 100644 index 000000000..8c7d2e219 --- /dev/null +++ b/regress/mkdtemp.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 Colin Watson <cjwatson@debian.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* Roughly equivalent to "mktemp -d -t TEMPLATE", but portable. */ + +#include "includes.h" + +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +#include "log.h" + +static void +usage(void) +{ + fprintf(stderr, "mkdtemp template\n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + const char *base; + const char *tmpdir; + char template[PATH_MAX]; + int r; + char *dir; + + if (argc != 2) + usage(); + base = argv[1]; + + if ((tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = "/tmp"; + r = snprintf(template, sizeof(template), "%s/%s", tmpdir, base); + if (r < 0 || (size_t)r >= sizeof(template)) + fatal("template string too long"); + dir = mkdtemp(template); + if (dir == NULL) { + perror("mkdtemp"); + exit(1); + } + puts(dir); + return 0; +} diff --git a/regress/multiplex.sh b/regress/multiplex.sh index 078a53a88..a6fad8eb8 100644 --- a/regress/multiplex.sh +++ b/regress/multiplex.sh @@ -1,7 +1,8 @@ # $OpenBSD: multiplex.sh,v 1.28 2017/04/30 23:34:55 djm Exp $ # Placed in the Public Domain. -CTL=/tmp/openssh.regress.ctl-sock.$$ +make_tmpdir +CTL=${SSH_REGRESS_TMP}/ctl-sock tid="connection multiplexing" diff --git a/regress/test-exec.sh b/regress/test-exec.sh index f09fe0ec4..f0e3dabfe 100644 --- a/regress/test-exec.sh +++ b/regress/test-exec.sh @@ -76,6 +76,9 @@ SFTP=sftp SFTPSERVER=/usr/libexec/openssh/sftp-server SCP=scp +# Set by make_tmpdir() on demand (below). +SSH_REGRESS_TMP= + # Interop testing PLINK=plink PUTTYGEN=puttygen @@ -322,6 +325,12 @@ stop_sshd () fi } +make_tmpdir () +{ + SSH_REGRESS_TMP="$($OBJ/mkdtemp openssh-regress-XXXXXXXXXXXX)" || \ + fatal "failed to create temporary directory" +} + # helper cleanup () { @@ -332,6 +341,9 @@ cleanup () kill $SSH_PID fi fi + if [ "x$SSH_REGRESS_TMP" != "x" ]; then + rm -rf "$SSH_REGRESS_TMP" + fi stop_sshd } |