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
This commit is contained in:
Damien Miller 2018-07-20 14:53:42 +10:00
parent 6ad8648e83
commit c59aca8adb
5 changed files with 83 additions and 2 deletions

View File

@ -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) \

View File

@ -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

59
regress/mkdtemp.c Normal file
View File

@ -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;
}

View File

@ -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"

View File

@ -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
}