diff options
Diffstat (limited to 'contrib/sendmail/test')
-rw-r--r-- | contrib/sendmail/test/Results | 2 | ||||
-rw-r--r-- | contrib/sendmail/test/t_exclopen.c | 38 | ||||
-rw-r--r-- | contrib/sendmail/test/t_pathconf.c | 19 | ||||
-rw-r--r-- | contrib/sendmail/test/t_seteuid.c | 30 | ||||
-rw-r--r-- | contrib/sendmail/test/t_setreuid.c | 30 | ||||
-rw-r--r-- | contrib/sendmail/test/t_setuid.c | 101 | ||||
-rw-r--r-- | contrib/sendmail/test/t_snprintf.c | 24 |
7 files changed, 204 insertions, 40 deletions
diff --git a/contrib/sendmail/test/Results b/contrib/sendmail/test/Results index e31a68b..192f778 100644 --- a/contrib/sendmail/test/Results +++ b/contrib/sendmail/test/Results @@ -156,3 +156,5 @@ NCR MP-RAS 2 -1/0 NCR MP-RAS 3 -1/0 Linux 2.0.27 1/0 1/0 + +$Revision: 8.1 $, Last updated $Date: 1999/02/06 18:44:07 $ diff --git a/contrib/sendmail/test/t_exclopen.c b/contrib/sendmail/test/t_exclopen.c index a42baa9..22ef693 100644 --- a/contrib/sendmail/test/t_exclopen.c +++ b/contrib/sendmail/test/t_exclopen.c @@ -28,15 +28,30 @@ ** Ultrix 4.3 OK */ -#include <stdio.h> -#include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include <errno.h> #include <fcntl.h> +#include <stdio.h> +#include <unistd.h> -char Attacker[128]; -char Attackee[128]; +#ifndef lint +static char id[] = "@(#)$Id: t_exclopen.c,v 8.5 1999/08/28 00:25:28 gshapiro 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; @@ -61,16 +76,16 @@ main(argc, argv) } if (open(Attacker, O_WRONLY|O_CREAT|O_EXCL, 0644) < 0) { - int saveerr = errno; + int save_errno = errno; if (stat(Attackee, &st) >= 0) { printf("Weird. Open failed but %s was created anyhow (errno = %d)\n", - Attackee, saveerr); + Attackee, save_errno); bail(1); } printf("Good show! Exclusive open works properly with symbolic links (errno = %d).\n", - saveerr); + save_errno); bail(0); } if (stat(Attackee, &st) < 0) @@ -82,12 +97,7 @@ main(argc, argv) 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); -} -bail(stat) - int stat; -{ - (void) unlink(Attacker); - (void) unlink(Attackee); - exit(stat); + /* NOTREACHED */ + exit(0); } diff --git a/contrib/sendmail/test/t_pathconf.c b/contrib/sendmail/test/t_pathconf.c index a4b5038..5355fd6 100644 --- a/contrib/sendmail/test/t_pathconf.c +++ b/contrib/sendmail/test/t_pathconf.c @@ -5,13 +5,24 @@ ** both do and do not permit file giveaway. */ -#include <unistd.h> -#include <errno.h> #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> -main() +#ifndef lint +static char id[] = "@(#)$Id: t_pathconf.c,v 8.5 1999/08/28 00:25:28 gshapiro Exp $"; +#endif /* ! lint */ + +int +main(argc, argv) + int argc; + char **argv; { int fd; int i; @@ -58,6 +69,6 @@ main() else printf("*** but in fact it is safe ***\n"); } - unlink(tbuf); + (void) unlink(tbuf); exit(EX_OK); } diff --git a/contrib/sendmail/test/t_seteuid.c b/contrib/sendmail/test/t_seteuid.c index f3bd529..b912b60 100644 --- a/contrib/sendmail/test/t_seteuid.c +++ b/contrib/sendmail/test/t_seteuid.c @@ -15,11 +15,27 @@ #include <unistd.h> #include <stdio.h> +#ifndef lint +static char id[] = "@(#)$Id: t_seteuid.c,v 8.4 1999/08/28 00:25:28 gshapiro Exp $"; +#endif /* ! lint */ + #ifdef __hpux -#define seteuid(e) setresuid(-1, e, -1) -#endif +# define seteuid(e) setresuid(-1, e, -1) +#endif /* __hpux */ + +static void +printuids(str, r, e) + char *str; + int r, e; +{ + printf("%s (should be %d/%d): r/euid=%d/%d\n", str, r, e, + getuid(), geteuid()); +} -main() +int +main(argc, argv) + int argc; + char **argv; { int fail = 0; uid_t realuid = getuid(); @@ -111,11 +127,3 @@ main() printf("\nIt is safe to define USESETEUID on this system\n"); exit(0); } - -printuids(str, r, e) - char *str; - int r, e; -{ - printf("%s (should be %d/%d): r/euid=%d/%d\n", str, r, e, - getuid(), geteuid()); -} diff --git a/contrib/sendmail/test/t_setreuid.c b/contrib/sendmail/test/t_setreuid.c index 6622068..1b6eff6 100644 --- a/contrib/sendmail/test/t_setreuid.c +++ b/contrib/sendmail/test/t_setreuid.c @@ -12,11 +12,27 @@ #include <unistd.h> #include <stdio.h> +#ifndef lint +static char id[] = "@(#)$Id: t_setreuid.c,v 8.4 1999/08/28 00:25:28 gshapiro Exp $"; +#endif /* ! lint */ + #ifdef __hpux -#define setreuid(r, e) setresuid(r, e, -1) -#endif +# define setreuid(r, e) setresuid(r, e, -1) +#endif /* __hpux */ + +static void +printuids(str, r, e) + char *str; + int r, e; +{ + printf("%s (should be %d/%d): r/euid=%d/%d\n", str, r, e, + getuid(), geteuid()); +} -main() +int +main(argc, argv) + int argc; + char **argv; { int fail = 0; uid_t realuid = getuid(); @@ -123,11 +139,3 @@ main() printf("\nIt is safe to define HASSETREUID on this system\n"); exit(0); } - -printuids(str, r, e) - char *str; - int r, e; -{ - printf("%s (should be %d/%d): r/euid=%d/%d\n", str, r, e, - getuid(), geteuid()); -} diff --git a/contrib/sendmail/test/t_setuid.c b/contrib/sendmail/test/t_setuid.c new file mode 100644 index 0000000..7487579 --- /dev/null +++ b/contrib/sendmail/test/t_setuid.c @@ -0,0 +1,101 @@ +/* +** This program checks to see if your version of setuid works. +** Compile it, make it setuid 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 setuid, +** 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.2.2.1 2000/05/31 00:29:47 gshapiro Exp $"; +#endif /* ! lint */ + +static void +printuids(str, r, e) + char *str; + int r, e; +{ + printf("%s (should be %d/%d): r/euid=%d/%d\n", str, r, e, + getuid(), 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 setuid 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..4789f49 --- /dev/null +++ b/contrib/sendmail/test/t_snprintf.c @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <sysexits.h> + +#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') + { + 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); +} |