diff options
author | dm <dm@cvs.openbsd.org> | 1996-01-29 01:45:07 +0000 |
---|---|---|
committer | dm <dm@cvs.openbsd.org> | 1996-01-29 01:45:07 +0000 |
commit | d4348a83d4e90a8f1a7a26c930bbbb9a30ebdd58 (patch) | |
tree | b8c6ba8362f38fb511f05eb04e0e221d7685c866 /usr.sbin/sendmail/test/t_setreuid.c | |
parent | a402471fd01805e5aa531735d5fd71e70f6741ab (diff) |
Sendmail 8.7.3 from NetBSD
Diffstat (limited to 'usr.sbin/sendmail/test/t_setreuid.c')
-rw-r--r-- | usr.sbin/sendmail/test/t_setreuid.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/usr.sbin/sendmail/test/t_setreuid.c b/usr.sbin/sendmail/test/t_setreuid.c index 2d087c3c36e..ca9a06f448b 100644 --- a/usr.sbin/sendmail/test/t_setreuid.c +++ b/usr.sbin/sendmail/test/t_setreuid.c @@ -4,7 +4,8 @@ ** 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". +** Compilation is trivial -- just "cc t_setreuid.c". Make it setuid, +** root and then execute it as a non-root user. */ #include <sys/types.h> @@ -17,58 +18,107 @@ main() { + int fail = 0; uid_t realuid = getuid(); printuids("initial uids", realuid, 0); if (geteuid() != 0) { - printf("re-run setuid root\n"); + 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 (setreuid(0, 1) < 0) + { + fail++; printf("setreuid(0, 1) failure\n"); + } printuids("after setreuid(0, 1)", 0, 1); 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", 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"); + } /* 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", 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); + } exit(0); } |