138032Speter/* 2261363Sgshapiro * Copyright (c) 1999 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro * 990792Sgshapiro */ 1090792Sgshapiro 1190792Sgshapiro/* 1238032Speter** The following test program tries the pathconf(2) routine. It should 1338032Speter** be run in a non-NFS-mounted directory (e.g., /tmp) and on remote (NFS) 1438032Speter** mounted directories running both NFS-v2 and NFS-v3 from systems that 1538032Speter** both do and do not permit file giveaway. 1638032Speter*/ 1738032Speter 1864562Sgshapiro#include <sys/types.h> 1938032Speter#include <errno.h> 2038032Speter#include <fcntl.h> 2164562Sgshapiro#include <stdio.h> 2264562Sgshapiro#include <unistd.h> 2364562Sgshapiro#ifdef EX_OK 2464562Sgshapiro# undef EX_OK /* unistd.h may have another use for this */ 2564562Sgshapiro#endif /* EX_OK */ 2638032Speter#include <sysexits.h> 2738032Speter 2864562Sgshapiro#ifndef lint 29266692Sgshapirostatic char id[] = "@(#)$Id: t_pathconf.c,v 8.7 2013-11-22 20:52:01 ca Exp $"; 3064562Sgshapiro#endif /* ! lint */ 3164562Sgshapiro 3264562Sgshapiroint 3364562Sgshapiromain(argc, argv) 3464562Sgshapiro int argc; 3564562Sgshapiro char **argv; 3638032Speter{ 3738032Speter int fd; 3838032Speter int i; 3938032Speter char tbuf[100]; 4038032Speter extern int errno; 4138032Speter 4238032Speter if (geteuid() == 0) 4338032Speter { 4438032Speter printf("*** Run me as a non-root user! ***\n"); 4538032Speter exit(EX_USAGE); 4638032Speter } 4738032Speter 4838032Speter strcpy(tbuf, "TXXXXXX"); 4938032Speter fd = mkstemp(tbuf); 5038032Speter if (fd < 0) 5138032Speter { 5238032Speter printf("*** Could not create test file %s\n", tbuf); 5338032Speter exit(EX_CANTCREAT); 5438032Speter } 5538032Speter errno = 0; 5638032Speter i = pathconf(".", _PC_CHOWN_RESTRICTED); 5738032Speter printf("pathconf(.) returns %2d, errno = %d\n", i, errno); 5838032Speter errno = 0; 5938032Speter i = pathconf(tbuf, _PC_CHOWN_RESTRICTED); 6038032Speter printf("pathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 6138032Speter errno = 0; 6238032Speter i = fpathconf(fd, _PC_CHOWN_RESTRICTED); 6338032Speter printf("fpathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 6438032Speter if (errno == 0 && i >= 0) 6538032Speter { 6638032Speter /* so it claims that it doesn't work -- try anyhow */ 6738032Speter printf(" fpathconf claims that chown is safe "); 6838032Speter if (fchown(fd, 1, 1) >= 0) 6938032Speter printf("*** but fchown works anyhow! ***\n"); 7038032Speter else 7138032Speter printf("and fchown agrees\n"); 7238032Speter } 7338032Speter else 7438032Speter { 7538032Speter /* well, let's see what really happens */ 7638032Speter printf(" fpathconf claims that chown is not safe "); 7738032Speter if (fchown(fd, 1, 1) >= 0) 7838032Speter printf("as indeed it is not\n"); 7938032Speter else 8038032Speter printf("*** but in fact it is safe ***\n"); 8138032Speter } 8264562Sgshapiro (void) unlink(tbuf); 8338032Speter exit(EX_OK); 8438032Speter} 85