diff options
author | dm <dm@cvs.openbsd.org> | 1996-01-29 01:45:04 +0000 |
---|---|---|
committer | dm <dm@cvs.openbsd.org> | 1996-01-29 01:45:04 +0000 |
commit | a402471fd01805e5aa531735d5fd71e70f6741ab (patch) | |
tree | 5ed052e8fdc51125db5f335c59b0350ac4cce654 /usr.sbin/sendmail/test | |
parent | e3ba3bc873e356bbf1d0fd1c90c4b02cfdb74fad (diff) |
sendmail 8.9.1
Diffstat (limited to 'usr.sbin/sendmail/test')
-rw-r--r-- | usr.sbin/sendmail/test/t_seteuid.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/usr.sbin/sendmail/test/t_seteuid.c b/usr.sbin/sendmail/test/t_seteuid.c new file mode 100644 index 00000000000..4dfe3d63bf7 --- /dev/null +++ b/usr.sbin/sendmail/test/t_seteuid.c @@ -0,0 +1,120 @@ +/* +** This program checks to see if your version of seteuid works. +** Compile it, make it setuid 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 setuid, +** root and then execute it as a non-root user. +*/ + +#include <sys/types.h> +#include <unistd.h> +#include <stdio.h> + +#ifdef __hpux +#define seteuid(e) setresuid(-1, e, -1) +#endif + +main() +{ + 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 (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); + } + + 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()); +} |