diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-02 19:05:59 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-02 19:05:59 +0000 |
commit | 43225228859332051b0497d6732b906e2c753f85 (patch) | |
tree | e1545792a305da6620c54b122c51c207dd70accd /gnu/usr.sbin/sendmail/test/t_pathconf.c | |
parent | 0b21c002091512c23501e805cd064cdc94f0a312 (diff) |
stock sendmail 8.10.0 with $Id -> $Sendmail
Diffstat (limited to 'gnu/usr.sbin/sendmail/test/t_pathconf.c')
-rw-r--r-- | gnu/usr.sbin/sendmail/test/t_pathconf.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/gnu/usr.sbin/sendmail/test/t_pathconf.c b/gnu/usr.sbin/sendmail/test/t_pathconf.c new file mode 100644 index 00000000000..dbe8f0a207a --- /dev/null +++ b/gnu/usr.sbin/sendmail/test/t_pathconf.c @@ -0,0 +1,74 @@ +/* +** 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[] = "@(#)$Sendmail: 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; + 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); +} |