2002-02-17 21:56:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 Sendmail, Inc. and its suppliers.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* By using this file, you agree to the terms and conditions set
|
|
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
|
|
* the sendmail distribution.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-06-27 14:53:01 +00:00
|
|
|
/*
|
|
|
|
** 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>
|
2000-08-12 21:55:49 +00:00
|
|
|
#include <errno.h>
|
1997-06-27 14:53:01 +00:00
|
|
|
#include <fcntl.h>
|
2000-08-12 21:55:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef EX_OK
|
|
|
|
# undef EX_OK /* unistd.h may have another use for this */
|
|
|
|
#endif /* EX_OK */
|
1997-06-27 14:53:01 +00:00
|
|
|
#include <sysexits.h>
|
|
|
|
|
2000-08-12 21:55:49 +00:00
|
|
|
#ifndef lint
|
2002-02-17 21:56:45 +00:00
|
|
|
static char id[] = "@(#)$Id: t_pathconf.c,v 8.6 2001/09/23 03:35:41 ca Exp $";
|
2000-08-12 21:55:49 +00:00
|
|
|
#endif /* ! lint */
|
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
1997-06-27 14:53:01 +00:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
2000-08-12 21:55:49 +00:00
|
|
|
(void) unlink(tbuf);
|
1997-06-27 14:53:01 +00:00
|
|
|
exit(EX_OK);
|
|
|
|
}
|