From 13955e8f42c61f98e34d5f410e48f4ea93ae2193 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Sat, 26 Aug 1995 22:25:20 +0000 Subject: [PATCH] Add t_inetd.c to the source tree. This program simulates the starting of a daemon from inetd by binding to a socket and then execing the desired program with specified arguments. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6599 dc483132-0cff-0310-8789-dd5450dbe970 --- src/tests/dejagnu/.Sanitize | 1 + src/tests/dejagnu/ChangeLog | 12 ++++ src/tests/dejagnu/Makefile.in | 10 ++- src/tests/dejagnu/configure.in | 4 ++ src/tests/dejagnu/t_inetd.c | 128 +++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 src/tests/dejagnu/t_inetd.c diff --git a/src/tests/dejagnu/.Sanitize b/src/tests/dejagnu/.Sanitize index b3cf9bd2d..6a8238787 100644 --- a/src/tests/dejagnu/.Sanitize +++ b/src/tests/dejagnu/.Sanitize @@ -30,6 +30,7 @@ configure configure.in krb-root krb-standalone +t_inetd.c Makefile.in diff --git a/src/tests/dejagnu/ChangeLog b/src/tests/dejagnu/ChangeLog index 13a9ee487..6cb4fee7e 100644 --- a/src/tests/dejagnu/ChangeLog +++ b/src/tests/dejagnu/ChangeLog @@ -1,3 +1,15 @@ +Sat Aug 26 18:10:44 1995 Ezra Peisach (epeisach@kangaroo.mit.edu) + + * .Sanitize: Add t_inetd.c + + * t_inetd.c: Small program to simulate the use of inetd in running + tests. + + * configure.in: Add programming rules, shared libraries and + signal handling + + * Makefile.in: Build/clean t_inetd if dejagnu tests are run. + Thu Aug 24 18:48:01 1995 Theodore Y. Ts'o * .Sanitize: Update file list diff --git a/src/tests/dejagnu/Makefile.in b/src/tests/dejagnu/Makefile.in index 9ca7aa484..8d20ba0f1 100644 --- a/src/tests/dejagnu/Makefile.in +++ b/src/tests/dejagnu/Makefile.in @@ -8,5 +8,13 @@ check:: check-$(RUNTEST) check-:: @echo "Dejagnu is not installed on this system. No tests run." -check-runtest:: +check-runtest:: t_inetd $(RUNTEST) --tool krb --srcdir $(srcdir) $(RUNTESTFLAGS) + +CFLAGS = $(CCOPTS) $(DEFS) + +t_inetd:: t_inetd.o $(DEPLIBS) + $(LD) $(LDFLAGS) $(LDARGS) -o t_inetd t_inetd.o -lcom_err + +clean:: + $(RM) t_inetd t_inetd.o diff --git a/src/tests/dejagnu/configure.in b/src/tests/dejagnu/configure.in index 99da7d7d2..0a312b17e 100644 --- a/src/tests/dejagnu/configure.in +++ b/src/tests/dejagnu/configure.in @@ -2,4 +2,8 @@ AC_INIT(Makefile.in) CONFIG_RULES AC_PROG_INSTALL AC_CHECK_PROG(RUNTEST,runtest,runtest) +AC_RETSIGTYPE +CHECK_SIGNALS +KRB5_LIBRARIES +V5_USE_SHARED_LIB V5_AC_OUTPUT_MAKEFILE diff --git a/src/tests/dejagnu/t_inetd.c b/src/tests/dejagnu/t_inetd.c new file mode 100644 index 000000000..d5a01773a --- /dev/null +++ b/src/tests/dejagnu/t_inetd.c @@ -0,0 +1,128 @@ +/* + * tests/dejagnu/t_inetd.c + * + * Copyright 1991 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * A simple program to simulate starting a process from inetd. + * + * Unlike a proper inetd situation, environment variables are passed + * to the client. + * + * usage: t_inetd port program argv0 ... + * + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "com_err.h" + +extern int errno; + +char *progname; + +static void usage() +{ + fprintf(stderr, "%s: port program argv0 argv1 ...\n", progname); + exit(1); +} + +main(argc, argv) + int argc; + char **argv; +{ + unsigned short port; + char *path; + int sock, acc; + int one = 1; + struct sockaddr_in l_inaddr, f_inaddr; /* local, foreign address */ + int namelen = sizeof(f_inaddr); +#ifdef POSIX_SIGNALS + struct sigaction csig; +#endif + + progname = argv[0]; + + if(argc <= 3) usage(); + + if(atoi(argv[1]) == 0) usage(); + + port = htons(atoi(argv[1])); + path = argv[2]; + + if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { + com_err(progname, errno, "creating socket"); + exit(3); + } + + (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&one, + sizeof (one)); + + l_inaddr.sin_family = AF_INET; + l_inaddr.sin_addr.s_addr = 0; + l_inaddr.sin_port = port; + + if (bind(sock, (struct sockaddr *)&l_inaddr, sizeof(l_inaddr))) { + com_err(progname, errno, "binding socket"); + exit(3); + } + + if (listen(sock, 1) == -1) { + com_err(progname, errno, "listening"); + exit(3); + } + + if ((acc = accept(sock, (struct sockaddr *)&f_inaddr, + &namelen)) == -1) { + com_err(progname, errno, "accepting"); + exit(3); + } + + dup2(acc, 0); + dup2(acc, 1); + dup2(acc, 2); + close(sock); + sock = 0; + + /* Don't wait for a child signal... Otherwise dejagnu gets confused */ +#ifdef POSIX_SIGNALS + csig.sa_handler = (RETSIGTYPE (*)())0; + sigemptyset(&csig.sa_mask); + csig.sa_flags = 0; + sigaction(SIGCHLD, &csig, (struct sigaction *)0); +#else + signal(SIGCHLD, SIG_IGN); +#endif + + if(execv(path, &argv[3])) + fprintf(stderr, "t_inetd: Could not exec %s\n", path); + exit(1); +} + -- 2.26.2