[openssh-commits] [openssh] 01/01: Create control sockets in clean temp directories

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Jul 20 14:55:34 AEST 2018


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit c59aca8adbdf7f5597084ad360a19bedb3f80970
Author: Damien Miller <djm at mindrot.org>
Date:   Fri Jul 20 14:53:42 2018 +1000

    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
---
 Makefile.in           |  8 +++++++
 regress/forwarding.sh |  3 ++-
 regress/mkdtemp.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 regress/multiplex.sh  |  3 ++-
 regress/test-exec.sh  | 12 +++++++++++
 5 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index e09e2795..c3b67aa6 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 39fccba7..7d0fae11 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 00000000..8c7d2e21
--- /dev/null
+++ b/regress/mkdtemp.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2017 Colin Watson <cjwatson at 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 078a53a8..a6fad8eb 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 f09fe0ec..f0e3dabf 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
 }
 

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list