1261287Sdes/*
2261287Sdes * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
3261287Sdes *
4261287Sdes * Permission to use, copy, modify, and distribute this software for any
5261287Sdes * purpose with or without fee is hereby granted, provided that the above
6261287Sdes * copyright notice and this permission notice appear in all copies.
7261287Sdes *
8261287Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9261287Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10261287Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11261287Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12261287Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13261287Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14261287Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15261287Sdes */
16261287Sdes
17261287Sdes/* $OpenBSD$ */
18261287Sdes
19261287Sdes#include "includes.h"
20261287Sdes
21261287Sdes#include <sys/types.h>
22261287Sdes#ifdef HAVE_SYS_STATVFS_H
23261287Sdes# include <sys/statvfs.h>
24261287Sdes#endif
25261287Sdes#include <stdio.h>
26264377Sdes#include <string.h>
27261287Sdes#include <errno.h>
28261287Sdes
29261287Sdesvoid
30261287Sdesusage(void)
31261287Sdes{
32261287Sdes	fprintf(stderr, "check-setuid [path]\n");
33261287Sdes	exit(1);
34261287Sdes}
35261287Sdes
36261287Sdesint
37261287Sdesmain(int argc, char **argv)
38261287Sdes{
39261287Sdes	const char *path = ".";
40261287Sdes	struct statvfs sb;
41261287Sdes
42261287Sdes	if (argc > 2)
43261287Sdes		usage();
44261287Sdes	else if (argc == 2)
45261287Sdes		path = argv[1];
46261287Sdes
47261287Sdes	if (statvfs(path, &sb) != 0) {
48261287Sdes		/* Don't return an error if the host doesn't support statvfs */
49261287Sdes		if (errno == ENOSYS)
50261287Sdes			return 0;
51261287Sdes		fprintf(stderr, "statvfs for \"%s\" failed: %s\n",
52261287Sdes		     path, strerror(errno));
53261287Sdes	}
54261287Sdes	return (sb.f_flag & ST_NOSUID) ? 1 : 0;
55261287Sdes}
56261287Sdes
57261287Sdes
58