summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/test
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/sendmail/test')
-rw-r--r--contrib/sendmail/test/Makefile19
-rw-r--r--contrib/sendmail/test/Makefile.m419
-rw-r--r--contrib/sendmail/test/README27
-rw-r--r--contrib/sendmail/test/Results198
-rw-r--r--contrib/sendmail/test/t_dropgid.c154
-rw-r--r--contrib/sendmail/test/t_exclopen.c113
-rw-r--r--contrib/sendmail/test/t_pathconf.c84
-rw-r--r--contrib/sendmail/test/t_seteuid.c139
-rw-r--r--contrib/sendmail/test/t_setgid.c119
-rw-r--r--contrib/sendmail/test/t_setreuid.c163
-rw-r--r--contrib/sendmail/test/t_setuid.c111
-rw-r--r--contrib/sendmail/test/t_snprintf.c39
12 files changed, 1185 insertions, 0 deletions
diff --git a/contrib/sendmail/test/Makefile b/contrib/sendmail/test/Makefile
new file mode 100644
index 0000000..d0a8842
--- /dev/null
+++ b/contrib/sendmail/test/Makefile
@@ -0,0 +1,19 @@
+# $Id: Makefile,v 1.2 2006/05/30 18:50:26 ca Exp $
+
+SHELL= /bin/sh
+BUILD= ./Build
+OPTIONS= $(CONFIG) $(FLAGS)
+
+all: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) $@
+clean: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) $@
+check: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) $@
+install: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) $@
+
+fresh: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) -c
+
+FRC:
diff --git a/contrib/sendmail/test/Makefile.m4 b/contrib/sendmail/test/Makefile.m4
new file mode 100644
index 0000000..1d38d62
--- /dev/null
+++ b/contrib/sendmail/test/Makefile.m4
@@ -0,0 +1,19 @@
+dnl $Id: Makefile.m4,v 1.4 2002/06/21 22:01:54 ca Exp $
+include(confBUILDTOOLSDIR`/M4/switch.m4')
+
+bldPRODUCT_START(`executable', `test')
+define(`bldSOURCES', `t_dropgid.c ')
+bldPRODUCT_END
+
+include(confBUILDTOOLSDIR`/M4/'bldM4_TYPE_DIR`/sm-test.m4')
+dnl smtest(`getipnode')
+smtest(`t_dropgid')
+smtest(`t_exclopen')
+smtest(`t_pathconf')
+smtest(`t_seteuid')
+smtest(`t_setgid')
+smtest(`t_setreuid')
+smtest(`t_setuid')
+dnl smtest(`t_snprintf')
+
+bldFINISH
diff --git a/contrib/sendmail/test/README b/contrib/sendmail/test/README
new file mode 100644
index 0000000..d715bbb
--- /dev/null
+++ b/contrib/sendmail/test/README
@@ -0,0 +1,27 @@
+# Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+# All rights reserved.
+#
+# By using this file, you agree to the terms and conditions set
+# forth in the LICENSE file which can be found at the top level of
+# the sendmail distribution.
+#
+# $Id: README,v 1.2 2001/09/28 16:36:28 ca Exp $
+#
+
+This directory contains several programs to test various OS calls.
+If your OS is not listed in the Results file, you should run those
+test programs. Most of them have instructions at the begin of source
+code, at least those which are important.
+
+Notice: most of these programs require set-user-ID or set-group-ID
+installation. Hence they are not tested automatically.
+
+t_dropgid.c test how to drop saved-gid for a set-group-ID program
+t_exclopen.c test for security-defeating semantics that an open with
+ O_CREAT|O_EXCL set will successfully open a file named
+ by a symbolic link that to a non-existent file
+t_seteuid.c test whether seteuid works
+t_setgid.c test whether setgid works
+t_setreuid.c test whether setreuid works
+t_setuid.c test whether setuid works
+
diff --git a/contrib/sendmail/test/Results b/contrib/sendmail/test/Results
new file mode 100644
index 0000000..934f9a1
--- /dev/null
+++ b/contrib/sendmail/test/Results
@@ -0,0 +1,198 @@
++------------+
+| t_setreuid |
++------------+
+
+The following are results of running t_setreuid on various architectures.
+
+OPSYS VERSION STATUS DATE TESTER/NOTES
+===== ======= ====== ==== ============
+
+SunOS 4.1 OK 93.07.19 eric
+SunOS 4.1.2 OK 93.07.19 eric
+SunOS 4.1.3 OK 93.09.25 Robert Elz
+
+BSD 4.4 OK 93.07.19 eric (wierd results, but functional)
+BSD 4.3Utah OK 93.07.19 eric
+
+FreeBSD 2.1-sta OK 96.04.14 Jaye Mathisen <mrcpu@cdsnet.net>
+
+Ultrix 4.2A OK 93.07.19 eric
+Ultrix 4.3A OK 93.07.19 Allan Johannesen
+Ultrix 4.5 OK 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+HP-UX 8.07 OK 93.07.19 eric (on 7xx series)
+HP-UX 8.02 OK 93.07.19 Michael Corrigan (on 8xx series)
+HP-UX 8.00 OK 93.07.21 Michael Corrigan (on 3xx/4xx series)
+HP-UX 9.01 OK 93.11.19 Cassidy (on 7xx series)
+
+Solaris 2.1
+Solaris 2.2 FAIL 93.07.19 Bill Wisner
+Solaris 2.3 FAIL 95.11.22 Scott J. Kramer <sjk@lux.com>
+Solaris 2.5 OK 96.02.29 Carson Gaspar <carson@lehman.com>
+Solaris 2.5.1 OK 96.11.29 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+OSF/1 T1.3-4 OK 93.07.19 eric (on DEC Alpha)
+OSF/1 1.3 OK 94.12.10 Jeff A. Earickson (on Intel Paragon)
+OSF/1 3.2D OK 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+OSF/1 4.0 OK 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+CxOS 11.5 OK 96.07.08 Eric Schnoebelen <eric@cirr.com>
+CxOS 11.0 OK 93.01.21 Eric Schnoebelen (CxOS 11.0 beta 1)
+CxOS 10.x OK 93.01.21 Eric Schnoebelen
+
+AIX 3.1.5 FAIL 93.08.07 David J. N. Begley
+AIX 3.2.3e FAIL 93.07.26 Steve Bauer <sbauer@silver.sdsmt.edu>
+AIX 3.2.4 FAIL 93.10.07 David J. N. Begley
+AIX 3.2.5 FAIL 94.05.17 Steve Bauer <sbauer@hpcmmib.hpc.sdsmt.edu>
+AIX 4.1 FAIL 96.10.21 Hakan Lindholm <hakan@af.lu.se>
+AIX 4.2 OK 96.10.16 Steve Bauer <sbauer@krypton.hpc.sdsmt.edu>
+
+IRIX 4.0.4 OK 93.09.25 Robert Elz
+IRIX 5.2 OK 94.12.06 Mark Andrews <mandrews@alias.com>
+IRIX 5.3 OK 94.12.06 Mark Andrews <mandrews@alias.com>
+IRIX 6.2 OK 96.09.16 Kari E. Hurtta <Kari.Hurtta@ozone.FMI.FI>
+IRIX 6.3 OK 97.02.10 Mark Andrews <mandrews@aw.sgi.com>
+
+SCO 3.2v4.0 OK 93.10.02 Peter Wemm (with -lsocket from 3.2v4 devsys)
+
+NeXT 2.1 OK 93.07.28 eric
+NeXT 3.0 OK 34.05.05 Kevin John Wang <kwang@lore.acs.calpoly.edu>
+
+Linux 0.99p10 OK 93.08.08 Karl London
+Linux 0.99p13 OK 93.09.27 Christian Kuhtz
+Linux 0.99p14 OK 93.11.30 Christian Kuhtz <chk@data-hh.Hanse.DE>
+Linux 1.0 OK 94.03.19 Shayne Smith <snsmith@rastus.brisnet.org.au>
+Linux 1.2.13 OK 95.11.02 Sven Neuhaus <sven@ping.de>
+Linux 2.0.17 OK 96.09.03 Horst von Brand <vonbrand@sleipnir.valparaiso.cl>
+Linux 2.1.109 OK 98.07.21 John Kennedy <jk@csuchico.edu>
+
+BSD/386 1.0 OK 93.11.13 Tony Sanders
+
+DELL 2.2 OK 93.11.15 Peter Wemm (using -DSETEUID)
+
+Pyramid 5.0d OK 95.01.14 David Miller <davem@nadzieja.rutgers.edu>
+
+
++-----------+
+| t_seteuid |
++-----------+
+
+The following are results of running t_seteuid on various architectures.
+
+OPSYS VERSION STATUS DATE TESTER/NOTES
+===== ======= ====== ==== ============
+
+Solaris 2.3 OK 95.11.22 Scott J. Kramer <sjk@lux.com>
+Solaris 2.4 OK 95.09.22 Thomas 'Mike' Michlmayr <mike@cosy.sbg.ac.at>
+Solaris 2.5 OK 96.02.29 Carson Gaspar <carson@lehman.com>
+Solaris 2.5.1 OK 96.11.29 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+Linux 1.2.13 FAIL 95.11.02 Sven Neuhaus <sven@ping.de>
+Linux 2.0.17 FAIL 96.09.03 Horst von Brand <vonbrand@sleipnir.valparaiso.cl>
+Linux 2.1.109 FAIL 98.07.21 John Kennedy <jk@csuchico.edu>
+
+AIX 4.1 OK 96.10.21 Hakan Lindholm <hakan@af.lu.se>
+
+IRIX 5.2 OK 95.12.01 Mark Andrews <mandrews@aw.sgi.com>
+IRIX 5.3 OK 95.12.01 Mark Andrews <mandrews@aw.sgi.com>
+IRIX 6.2 OK 96.09.16 Kari E. Hurtta <Kari.Hurtta@ozone.FMI.FI>
+IRIX 6.3 OK 97.02.10 Mark Andrews <mandrews@aw.sgi.com>
+
+FreeBSD 2.1-sta OK 96.04.14 Jaye Mathisen <mrcpu@cdsnet.net>
+
+Ultrix 4.5 FAIL 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+OSF/1 3.2D OK 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+OSF/1 4.0 OK 96.09.18 Gregory Neil Shapiro <gshapiro@wpi.edu>
+
+CxOS 11.5 FAIL 96.07.08 Eric Schnoebelen <eric@cirr.com>
+
+
++------------+
+| t_pathconf |
++------------+
+
+The following are the results of running t_pathconf.c. Safe means that
+the underlying filesystem (in NFS, the filesystem on the server) does not
+permit regular (non-root) users to chown their files to another user.
+Unsafe means that they can. Typically, BSD-based systems do not permit
+giveaway and System V-based systems do. However, some systems (e.g.,
+Solaris) can set this on a per-system or per-filesystem basis. Entries
+are the return value of pathconf, the errno value, and a * if chown
+disagreed with the result of the pathconf call, and a ? if the test has
+not been run. A mark of [R] means that the local filesystem has
+chown set to be restricted, [U] means that it is set to be unrestricted.
+
+ Safe Filesystem Unsafe Filesystem
+SYSTEM LOCAL NFS-V2 NFS-V3 NFS-V2 NFS-V3
+
+SunOS 4.1.3_U1 1/0 -1/EINVAL* n/a -1/EINVAL? n/a
+SunOS 4.1.4 1/0 -1/EINVAL* n/a -1/EINVAL n/a
+
+AIX 3.2 0/0 0/0
+
+Solaris 2.4 1/0 -1/EINVAL*
+Solaris 2.5 1/0 -1/EINVAL* 1/0 0/0?
+Solaris 2.5.1 1/0 -1/EINVAL* 0/0
+
+DEC OSF1 3.0 0/0 0/0
+DEC OSF1 3.2D-2 0/0 0/0 0/0
+DEC OSF1 4.0A 0/0 0/0 0/0
+DEC OSF 4.0B 0/0 0/0 0/0
+
+Ultrix 4.3 0/0 0/0 n/a n/a
+Ultrix 4.5 1/0 1/0
+
+HP-UX 9.05 -1/0 -1/EOPNOTSUPP* -1/EOPNOTSUPP
+HP-UX 9.05[R] 1/0 -1/EOPNOTSUPP* -1/EOPNOTSUPP*
+HP-UX 10.10 -1/0 -1/EOPNOTSUPP* -1/EOPNOTSUPP
+HP-UX 10.20 -1/EOPNOTSUPP? -1/EOPNOTSUPP?
+HP-UX 10.30 -1/0 -1/EOPNOTSUPP -1/EOPNOTSUPP
+
+BSD/OS 2.1 1/0
+
+FreeBSD 2.1.7 1/0 -1/EINVAL* -1/EINVAL
+
+Irix 5.3 -1/0* -1/0
+Irix 6.2 1/0 -1/0 0/0*
+Irix 6.2 -1/0 -1/0
+Irix 6.3 R10000 -1/0 -1/0 0/0*
+
+A/UX 3.1.1 1/0
+
+DomainOS [R] -1/0*
+DomainOS [U] -1/0
+
+NCR MP-RAS 2 -1/0
+NCR MP-RAS 3 -1/0
+
+Linux 2.0.27 1/0 1/0
+
+
++-----------+
+| t_dropgid |
++-----------+
+
+The following are results of running t_dropgid on various architectures.
+
+OPSYS VERSION STATUS DATE TESTER/NOTES
+===== ======= ====== ==== ============
+AIX 4.3.3 FAILS 2001-09-22 Valdis Kletnieks
+BSD/OS 4.2 OK 2001-09-22 Vernon Schryver
+FreeBSD 3.2 OK 2001-09-22 ca
+FreeBSD 4.4 OK 2001-09-29 ca
+HP-UX 11.00 HASSETRESGID 2001-09-22 ca
+IRIX 6.5 FAILS 2001-09-22 Mark D. Roth
+Linux 2.0.35 HASSETREGID 2001-09-22 Neil W Rickert
+Linux 2.2.12 HASSETREGID 2001-09-22 ca
+Linux 2.2.16 HASSETREGID 2001-09-22 Neil W Rickert
+Linux 2.4.9 HASSETREGID 2001-09-22 Derek Balling
+NetBSD 1.5 OK 2001-09-22 Kimmo Suominen
+OpenBSD 2.8 HASSETEGID 2001-09-22 ca
+SCO 5.0.5 FAILS 2001-09-22 Phillip Porch
+SunOS 5.7 HASSETREGID 2001-09-22 Neil W Rickert
+SunOS 5.8 HASSETREGID 2001-09-22 ca
+SunOS 5.9 HASSETREGID 2001-09-22 Neil W Rickert
+
+
+$Revision: 8.3 $, Last updated $Date: 2001/09/30 01:32:33 $
diff --git a/contrib/sendmail/test/t_dropgid.c b/contrib/sendmail/test/t_dropgid.c
new file mode 100644
index 0000000..cb166d0
--- /dev/null
+++ b/contrib/sendmail/test/t_dropgid.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program checks to see if your version of setgid works.
+** Compile it, make it set-group-ID guest, and run it as yourself (NOT as
+** root and not as member of the group guest).
+**
+** Compilation is trivial -- just "cc t_dropgid.c". Make it set-group-ID
+** guest and then execute it as a non-root user.
+*/
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_dropgid.c,v 1.6 2001/09/28 16:36:28 ca Exp $";
+#endif /* ! lint */
+
+static void
+printgids(str, r, e)
+ char *str;
+ gid_t r, e;
+{
+ printf("%s (should be %d/%d): r/egid=%d/%d\n", str, (int) r, (int) e,
+ (int) getgid(), (int) getegid());
+}
+
+/* define only one of these */
+#if HASSETEGID
+# define SETGIDCALL "setegid"
+#endif /* HASSETEGID */
+#if HASSETREGID
+# define SETGIDCALL "setregid"
+#endif /* HASSETREGID */
+#if HASSETRESGID
+# define SETGIDCALL "setresgid"
+#endif /* HASSETRESGID */
+
+#ifndef SETGIDCALL
+# define SETGIDCALL "setgid"
+#endif /* ! SETGIDCALL */
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fail = 0;
+ int res;
+ gid_t realgid = getgid();
+ gid_t effgid = getegid();
+ char *prg = argv[0];
+
+ printgids("initial gids", realgid, effgid);
+
+ if (effgid == realgid)
+ {
+ printf("SETUP ERROR: re-run set-group-ID guest\n");
+ printf("Use chgrp(1) and chmod(1)\n");
+ printf("For example, do this as root ");
+ printf("(nobody is the name of a group in this example):\n");
+ printf("# chgrp nobody %s\n", prg);
+ printf("# chmod g+s nobody %s\n", prg);
+ exit(1);
+ }
+
+#if HASSETREGID
+ res = setregid(realgid, realgid);
+ printf("setregid(%d)=%d %s\n", (int) realgid, res,
+ res < 0 ? "failure" : "ok");
+ printgids("after setregid()", realgid, realgid);
+#endif /* HASSETREGID */
+#if HASSETRESGID
+ res = setresgid(realgid, realgid, realgid);
+ printf("setresgid(%d)=%d %s\n", (int) realgid, res,
+ res < 0 ? "failure" : "ok");
+ printgids("after setresgid()", realgid, realgid);
+#endif /* HASSETRESGID */
+#if HASSETEGID
+ res = setegid(realgid);
+ printf("setegid(%d)=%d %s\n", (int) realgid, res,
+ res < 0 ? "failure" : "ok");
+ printgids("after setegid()", realgid, realgid);
+#endif /* HASSETEGID */
+ res = setgid(realgid);
+ printf("setgid(%d)=%d %s\n", (int) realgid, res,
+ res < 0 ? "failure" : "ok");
+ printgids("after setgid()", realgid, realgid);
+
+ if (getegid() != realgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective gid\n");
+ }
+
+ if (getgid() != realgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real gid\n");
+ }
+
+ /* do activity here */
+ if (setgid(effgid) == 0)
+ {
+ fail++;
+ printf("MAYDAY! setgid(%d) succeeded (should have failed)\n",
+ effgid);
+ }
+ else
+ {
+ printf("setgid(%d) failed (this is correct)\n", effgid);
+ }
+ printgids("after setgid() to egid", realgid, realgid);
+
+ if (getegid() != realgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective gid\n");
+ }
+ if (getgid() != realgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real gid\n");
+ }
+ printf("\n");
+
+ if (fail > 0)
+ {
+ printf("\nThis system cannot use %s to give up set-group-ID rights\n",
+ SETGIDCALL);
+#if !HASSETEGID
+ printf("Maybe compile with -DHASSETEGID and try again\n");
+#endif /* !HASSETEGID */
+#if !HASSETREGID
+ printf("Maybe compile with -DHASSETREGID and try again\n");
+#endif /* !HASSETREGID */
+#if !HASSETRESGID
+ printf("Maybe compile with -DHASSETRESGID and try again\n");
+#endif /* !HASSETRESGID */
+ exit(1);
+ }
+
+ printf("\nIt is possible to use %s on this system\n", SETGIDCALL);
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_exclopen.c b/contrib/sendmail/test/t_exclopen.c
new file mode 100644
index 0000000..f1bde72
--- /dev/null
+++ b/contrib/sendmail/test/t_exclopen.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 1999 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program tests your system to see if you have the lovely
+** security-defeating semantics that an open with O_CREAT|O_EXCL
+** set will successfully open a file named by a symbolic link that
+** points to a non-existent file. Sadly, Posix is mute on what
+** should happen in this situation.
+**
+** Results to date:
+** AIX 3.2 OK
+** BSD family OK
+** BSD/OS 2.1 OK
+** FreeBSD 2.1 OK
+** DEC OSF/1 3.0 OK
+** HP-UX 9.04 FAIL
+** HP-UX 9.05 FAIL
+** HP-UX 9.07 OK
+** HP-UX 10.01 OK
+** HP-UX 10.10 OK
+** HP-UX 10.20 OK
+** Irix 5.3 OK
+** Irix 6.2 OK
+** Irix 6.3 OK
+** Irix 6.4 OK
+** Linux OK
+** NeXT 2.1 OK
+** Solaris 2.x OK
+** SunOS 4.x OK
+** Ultrix 4.3 OK
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_exclopen.c,v 8.6 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+static char Attacker[128];
+static char Attackee[128];
+
+static void
+bail(status)
+ int status;
+{
+ (void) unlink(Attacker);
+ (void) unlink(Attackee);
+ exit(status);
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct stat st;
+
+ sprintf(Attacker, "/tmp/attacker.%d.%ld", getpid(), time(NULL));
+ sprintf(Attackee, "/tmp/attackee.%d.%ld", getpid(), time(NULL));
+
+ if (symlink(Attackee, Attacker) < 0)
+ {
+ printf("Could not create %s->%s symlink: %d\n",
+ Attacker, Attackee, errno);
+ bail(1);
+ }
+ (void) unlink(Attackee);
+ if (stat(Attackee, &st) >= 0)
+ {
+ printf("%s already exists -- remove and try again.\n",
+ Attackee);
+ bail(1);
+ }
+ if (open(Attacker, O_WRONLY|O_CREAT|O_EXCL, 0644) < 0)
+ {
+ int save_errno = errno;
+
+ if (stat(Attackee, &st) >= 0)
+ {
+ printf("Weird. Open failed but %s was created anyhow (errno = %d)\n",
+ Attackee, save_errno);
+ bail(1);
+ }
+ printf("Good show! Exclusive open works properly with symbolic links (errno = %d).\n",
+ save_errno);
+ bail(0);
+ }
+ if (stat(Attackee, &st) < 0)
+ {
+ printf("Weird. Open succeeded but %s was not created\n",
+ Attackee);
+ bail(2);
+ }
+ printf("Bad news: you can do an exclusive open through a symbolic link\n");
+ printf("\tBe sure you #define BOGUS_O_EXCL in conf.h\n");
+ bail(1);
+
+ /* NOTREACHED */
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_pathconf.c b/contrib/sendmail/test/t_pathconf.c
new file mode 100644
index 0000000..2baaaa6
--- /dev/null
+++ b/contrib/sendmail/test/t_pathconf.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 1999 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** The following test program tries the pathconf(2) routine. It should
+** be run in a non-NFS-mounted directory (e.g., /tmp) and on remote (NFS)
+** mounted directories running both NFS-v2 and NFS-v3 from systems that
+** both do and do not permit file giveaway.
+*/
+
+#include <sys/types.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#ifdef EX_OK
+# undef EX_OK /* unistd.h may have another use for this */
+#endif /* EX_OK */
+#include <sysexits.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_pathconf.c,v 8.6 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fd;
+ int i;
+ char tbuf[100];
+ extern int errno;
+
+ if (geteuid() == 0)
+ {
+ printf("*** Run me as a non-root user! ***\n");
+ exit(EX_USAGE);
+ }
+
+ strcpy(tbuf, "TXXXXXX");
+ fd = mkstemp(tbuf);
+ if (fd < 0)
+ {
+ printf("*** Could not create test file %s\n", tbuf);
+ exit(EX_CANTCREAT);
+ }
+ errno = 0;
+ i = pathconf(".", _PC_CHOWN_RESTRICTED);
+ printf("pathconf(.) returns %2d, errno = %d\n", i, errno);
+ errno = 0;
+ i = pathconf(tbuf, _PC_CHOWN_RESTRICTED);
+ printf("pathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno);
+ errno = 0;
+ i = fpathconf(fd, _PC_CHOWN_RESTRICTED);
+ printf("fpathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno);
+ if (errno == 0 && i >= 0)
+ {
+ /* so it claims that it doesn't work -- try anyhow */
+ printf(" fpathconf claims that chown is safe ");
+ if (fchown(fd, 1, 1) >= 0)
+ printf("*** but fchown works anyhow! ***\n");
+ else
+ printf("and fchown agrees\n");
+ }
+ else
+ {
+ /* well, let's see what really happens */
+ printf(" fpathconf claims that chown is not safe ");
+ if (fchown(fd, 1, 1) >= 0)
+ printf("as indeed it is not\n");
+ else
+ printf("*** but in fact it is safe ***\n");
+ }
+ (void) unlink(tbuf);
+ exit(EX_OK);
+}
diff --git a/contrib/sendmail/test/t_seteuid.c b/contrib/sendmail/test/t_seteuid.c
new file mode 100644
index 0000000..9fab898
--- /dev/null
+++ b/contrib/sendmail/test/t_seteuid.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program checks to see if your version of seteuid works.
+** Compile it, make it set-user-ID root, and run it as yourself (NOT as
+** root). If it won't compile or outputs any MAYDAY messages, don't
+** define USESETEUID in conf.h.
+**
+** NOTE: It is not sufficient to have seteuid in your library.
+** You must also have saved uids that function properly.
+**
+** Compilation is trivial -- just "cc t_seteuid.c". Make it set-user-ID
+** root and then execute it as a non-root user.
+*/
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_seteuid.c,v 8.8 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+#ifdef __hpux
+# define seteuid(e) setresuid(-1, e, -1)
+#endif /* __hpux */
+
+static void
+printuids(str, r, e)
+ char *str;
+ uid_t r, e;
+{
+ printf("%s (should be %d/%d): r/euid=%d/%d\n", str, (int) r, (int) e,
+ (int) getuid(), (int) geteuid());
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fail = 0;
+ uid_t realuid = getuid();
+
+ printuids("initial uids", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ printf("SETUP ERROR: re-run set-user-ID root\n");
+ exit(1);
+ }
+
+ if (getuid() == 0)
+ {
+ printf("SETUP ERROR: must be run by a non-root user\n");
+ exit(1);
+ }
+
+ if (seteuid(1) < 0)
+ printf("seteuid(1) failure\n");
+ printuids("after seteuid(1)", realuid, 1);
+
+ if (geteuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+
+ /* do activity here */
+
+ if (seteuid(0) < 0)
+ {
+ fail++;
+ printf("seteuid(0) failure\n");
+ }
+ printuids("after seteuid(0)", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+ if (getuid() != realuid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+ printf("\n");
+
+ if (seteuid(2) < 0)
+ {
+ fail++;
+ printf("seteuid(2) failure\n");
+ }
+ printuids("after seteuid(2)", realuid, 2);
+
+ if (geteuid() != 2)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+
+ /* do activity here */
+
+ if (seteuid(0) < 0)
+ {
+ fail++;
+ printf("seteuid(0) failure\n");
+ }
+ printuids("after seteuid(0)", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+ if (getuid() != realuid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+
+ if (fail)
+ {
+ printf("\nThis system cannot use seteuid\n");
+ exit(1);
+ }
+
+ printf("\nIt is safe to define USESETEUID on this system\n");
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_setgid.c b/contrib/sendmail/test/t_setgid.c
new file mode 100644
index 0000000..dfe1805
--- /dev/null
+++ b/contrib/sendmail/test/t_setgid.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program checks to see if your version of setgid works.
+** Compile it, make it set-group-ID guest, and run it as yourself (NOT as
+** root and not as member of the group guest).
+**
+** Compilation is trivial -- just "cc t_setgid.c". Make it set-group-ID,
+** guest and then execute it as a non-root user.
+*/
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_setgid.c,v 1.6 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+static void
+printgids(str, r, e)
+ char *str;
+ gid_t r, e;
+{
+ printf("%s (should be %d/%d): r/egid=%d/%d\n", str, (int) r, (int) e,
+ (int) getgid(), (int) getegid());
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fail = 0;
+ int res;
+ gid_t realgid = getgid();
+ gid_t effgid = getegid();
+
+ printgids("initial gids", realgid, effgid);
+
+ if (effgid == realgid)
+ {
+ printf("SETUP ERROR: re-run set-group-ID guest\n");
+ exit(1);
+ }
+
+#if SM_CONF_SETREGID
+ res = setregid(effgid, effgid);
+#else /* SM_CONF_SETREGID */
+ res = setgid(effgid);
+#endif /* SM_CONF_SETREGID */
+
+ printf("setgid(%d)=%d %s\n", (int) effgid, res,
+ res < 0 ? "failure" : "ok");
+#if SM_CONF_SETREGID
+ printgids("after setregid()", effgid, effgid);
+#else /* SM_CONF_SETREGID */
+ printgids("after setgid()", effgid, effgid);
+#endif /* SM_CONF_SETREGID */
+
+ if (getegid() != effgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective gid\n");
+ }
+
+ if (getgid() != effgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real gid\n");
+ }
+
+ /* do activity here */
+ if (setgid(0) == 0)
+ {
+ fail++;
+ printf("MAYDAY! setgid(0) succeeded (should have failed)\n");
+ }
+ else
+ {
+ printf("setgid(0) failed (this is correct)\n");
+ }
+ printgids("after setgid(0)", effgid, effgid);
+
+ if (getegid() != effgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective gid\n");
+ }
+ if (getgid() != effgid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real gid\n");
+ }
+ printf("\n");
+
+ if (fail > 0)
+ {
+ printf("\nThis system cannot use %s to set the real gid to the effective gid\nand clear the saved gid.\n",
+#if SM_CONF_SETREGID
+ "setregid"
+#else /* SM_CONF_SETREGID */
+ "setgid"
+#endif /* SM_CONF_SETREGID */
+ );
+ exit(1);
+ }
+
+ printf("\nIt is possible to use setgid on this system\n");
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_setreuid.c b/contrib/sendmail/test/t_setreuid.c
new file mode 100644
index 0000000..b307b08
--- /dev/null
+++ b/contrib/sendmail/test/t_setreuid.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program checks to see if your version of setreuid works.
+** Compile it, make it set-user-ID root, and run it as yourself (NOT as
+** root). If it won't compile or outputs any MAYDAY messages, don't
+** define HASSETREUID in conf.h.
+**
+** Compilation is trivial -- just "cc t_setreuid.c". Make it set-user-ID,
+** root and then execute it as a non-root user.
+*/
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_setreuid.c,v 8.9 2001/10/12 03:04:46 gshapiro Exp $";
+#endif /* ! lint */
+
+#ifdef __hpux
+# define setreuid(r, e) setresuid(r, e, -1)
+#endif /* __hpux */
+
+static void
+printuids(str, r, e)
+ char *str;
+ uid_t r, e;
+{
+ printf("%s (should be %d/%d): r/euid=%d/%d\n", str, (int) r, (int) e,
+ (int) getuid(), (int) geteuid());
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fail = 0;
+ uid_t realuid = getuid();
+
+ printuids("initial uids", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ printf("SETUP ERROR: re-run set-user-ID root\n");
+ exit(1);
+ }
+
+ if (getuid() == 0)
+ {
+ printf("SETUP ERROR: must be run by a non-root user\n");
+ exit(1);
+ }
+
+ if (setreuid(0, 1) < 0)
+ {
+ fail++;
+ printf("setreuid(0, 1) failure\n");
+ }
+ printuids("after setreuid(0, 1)", 0, 1);
+
+ if (getuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+
+ if (geteuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+
+ /* do activity here */
+
+ if (setreuid(-1, 0) < 0)
+ {
+ fail++;
+ printf("setreuid(-1, 0) failure\n");
+ }
+ printuids("after setreuid(-1, 0)", 0, 0);
+ if (setreuid(realuid, 0) < 0)
+ {
+ fail++;
+ printf("setreuid(%d, 0) failure\n", (int) realuid);
+ }
+ printuids("after setreuid(realuid, 0)", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+ if (getuid() != realuid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+ printf("\n");
+
+ if (setreuid(0, 2) < 0)
+ {
+ fail++;
+ printf("setreuid(0, 2) failure\n");
+ }
+ printuids("after setreuid(0, 2)", 0, 2);
+
+ if (geteuid() != 2)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+
+ if (getuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+
+ /* do activity here */
+
+ if (setreuid(-1, 0) < 0)
+ {
+ fail++;
+ printf("setreuid(-1, 0) failure\n");
+ }
+ printuids("after setreuid(-1, 0)", 0, 0);
+ if (setreuid(realuid, 0) < 0)
+ {
+ fail++;
+ printf("setreuid(%d, 0) failure\n", (int) realuid);
+ }
+ printuids("after setreuid(realuid, 0)", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+ if (getuid() != realuid)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+
+ if (fail)
+ {
+ printf("\nThis system cannot use setreuid\n");
+ exit(1);
+ }
+
+ printf("\nIt is safe to define HASSETREUID on this system\n");
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_setuid.c b/contrib/sendmail/test/t_setuid.c
new file mode 100644
index 0000000..6533339
--- /dev/null
+++ b/contrib/sendmail/test/t_setuid.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+/*
+** This program checks to see if your version of setuid works.
+** Compile it, make it set-user-ID root, and run it as yourself (NOT as
+** root).
+**
+** NOTE: This should work everywhere, but Linux has the ability
+** to use the undocumented setcap() call to make this break.
+**
+** Compilation is trivial -- just "cc t_setuid.c". Make it set-user-ID,
+** root and then execute it as a non-root user.
+*/
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_setuid.c,v 8.7 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+static void
+printuids(str, r, e)
+ char *str;
+ uid_t r, e;
+{
+ printf("%s (should be %d/%d): r/euid=%d/%d\n", str, (int) r, (int) e,
+ (int) getuid(), (int) geteuid());
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int fail = 0;
+ uid_t realuid = getuid();
+
+ printuids("initial uids", realuid, 0);
+
+ if (geteuid() != 0)
+ {
+ printf("SETUP ERROR: re-run set-user-ID root\n");
+ exit(1);
+ }
+
+ if (getuid() == 0)
+ {
+ printf("SETUP ERROR: must be run by a non-root user\n");
+ exit(1);
+ }
+
+ if (setuid(1) < 0)
+ printf("setuid(1) failure\n");
+ printuids("after setuid(1)", 1, 1);
+
+ if (geteuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+
+ if (getuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+
+
+ /* do activity here */
+ if (setuid(0) == 0)
+ {
+ fail++;
+ printf("MAYDAY! setuid(0) succeeded (should have failed)\n");
+ }
+ else
+ {
+ printf("setuid(0) failed (this is correct)\n");
+ }
+ printuids("after setuid(0)", 1, 1);
+
+ if (geteuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong effective uid\n");
+ }
+ if (getuid() != 1)
+ {
+ fail++;
+ printf("MAYDAY! Wrong real uid\n");
+ }
+ printf("\n");
+
+ if (fail)
+ {
+ printf("\nThis system cannot use setuid (maybe use setreuid)\n");
+ exit(1);
+ }
+
+ printf("\nIt is safe to use setuid on this system\n");
+ exit(0);
+}
diff --git a/contrib/sendmail/test/t_snprintf.c b/contrib/sendmail/test/t_snprintf.c
new file mode 100644
index 0000000..8a0378f
--- /dev/null
+++ b/contrib/sendmail/test/t_snprintf.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+#include <stdio.h>
+#include <sysexits.h>
+
+#ifndef lint
+static char id[] = "@(#)$Id: t_snprintf.c,v 8.4 2001/09/23 03:35:41 ca Exp $";
+#endif /* ! lint */
+
+#define TEST_STRING "1234567890"
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int r;
+ char buf[5];
+
+ r = snprintf(buf, sizeof buf, "%s", TEST_STRING);
+
+ if (buf[sizeof buf - 1] != '\0' ||
+ r != strlen(TEST_STRING))
+ {
+ fprintf(stderr, "Add the following to devtools/Site/site.config.m4:\n\n");
+ fprintf(stderr, "APPENDDEF(`confENVDEF', `-DSNPRINTF_IS_BROKEN=1')\n\n");
+ exit(EX_OSERR);
+ }
+ fprintf(stderr, "snprintf() appears to work properly\n");
+ exit(EX_OK);
+}
OpenPOWER on IntegriCloud