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