1 /* 2 ** The following test program tries the pathconf(2) routine. It should 3 ** be run in a non-NFS-mounted directory (e.g., /tmp) and on remote (NFS) 4 ** mounted directories running both NFS-v2 and NFS-v3 from systems that 5 ** both do and do not permit file giveaway. 6 */ 7 8 #include <sys/types.h> 9 #include <errno.h> 10 #include <fcntl.h> 11 #include <stdio.h> 12 #include <unistd.h> 13 #ifdef EX_OK 14 # undef EX_OK /* unistd.h may have another use for this */ 15 #endif /* EX_OK */ 16 #include <sysexits.h> 17 18 #ifndef lint 19 static char id[] = "@(#)$Id: t_pathconf.c,v 8.5 1999/08/28 00:25:28 gshapiro Exp $"; 20 #endif /* ! lint */ 21 22 int 23 main(argc, argv) 24 int argc; 25 char **argv; 26 { 27 int fd; 28 int i; 29 char tbuf[100]; 30 extern int errno; 31 32 if (geteuid() == 0) 33 { 34 printf("*** Run me as a non-root user! ***\n"); 35 exit(EX_USAGE); 36 } 37 38 strcpy(tbuf, "TXXXXXX"); 39 fd = mkstemp(tbuf); 40 if (fd < 0) 41 { 42 printf("*** Could not create test file %s\n", tbuf); 43 exit(EX_CANTCREAT); 44 } 45 errno = 0; 46 i = pathconf(".", _PC_CHOWN_RESTRICTED); 47 printf("pathconf(.) returns %2d, errno = %d\n", i, errno); 48 errno = 0; 49 i = pathconf(tbuf, _PC_CHOWN_RESTRICTED); 50 printf("pathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 51 errno = 0; 52 i = fpathconf(fd, _PC_CHOWN_RESTRICTED); 53 printf("fpathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 54 if (errno == 0 && i >= 0) 55 { 56 /* so it claims that it doesn't work -- try anyhow */ 57 printf(" fpathconf claims that chown is safe "); 58 if (fchown(fd, 1, 1) >= 0) 59 printf("*** but fchown works anyhow! ***\n"); 60 else 61 printf("and fchown agrees\n"); 62 } 63 else 64 { 65 /* well, let's see what really happens */ 66 printf(" fpathconf claims that chown is not safe "); 67 if (fchown(fd, 1, 1) >= 0) 68 printf("as indeed it is not\n"); 69 else 70 printf("*** but in fact it is safe ***\n"); 71 } 72 (void) unlink(tbuf); 73 exit(EX_OK); 74 } 75