File: t_pathconf.c

package info (click to toggle)
sendmail 8.9.3-3slink1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,744 kB
  • ctags: 2,997
  • sloc: ansic: 40,418; perl: 2,044; sh: 1,466; makefile: 319
file content (63 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
**  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 <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sysexits.h>

main()
{
	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");
	}
	unlink(tbuf);
	exit(EX_OK);
}