setuid-allowed.c revision 296853
1247280Sdteske/*
2247280Sdteske * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
3247280Sdteske *
4252980Sdteske * Permission to use, copy, modify, and distribute this software for any
5247280Sdteske * purpose with or without fee is hereby granted, provided that the above
6247280Sdteske * copyright notice and this permission notice appear in all copies.
7247280Sdteske *
8247280Sdteske * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9247280Sdteske * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10247280Sdteske * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11247280Sdteske * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12247280Sdteske * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13247280Sdteske * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14247280Sdteske * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15247280Sdteske */
16252987Sdteske
17247280Sdteske/* $OpenBSD$ */
18247280Sdteske
19247280Sdteske#include "includes.h"
20252987Sdteske
21247280Sdteske#include <sys/types.h>
22247280Sdteske#ifdef HAVE_SYS_STATVFS_H
23247280Sdteske# include <sys/statvfs.h>
24247280Sdteske#endif
25247280Sdteske#include <stdio.h>
26247280Sdteske#include <string.h>
27247280Sdteske#include <errno.h>
28247280Sdteske
29247280Sdteskestatic void
30247280Sdteskeusage(void)
31247280Sdteske{
32247280Sdteske	fprintf(stderr, "check-setuid [path]\n");
33247280Sdteske	exit(1);
34247280Sdteske}
35247280Sdteske
36259054Sdteskeint
37252077Sdteskemain(int argc, char **argv)
38247280Sdteske{
39247280Sdteske	const char *path = ".";
40247280Sdteske	struct statvfs sb;
41247280Sdteske
42247280Sdteske	if (argc > 2)
43247280Sdteske		usage();
44247280Sdteske	else if (argc == 2)
45247280Sdteske		path = argv[1];
46247280Sdteske
47247280Sdteske	if (statvfs(path, &sb) != 0) {
48247280Sdteske		/* Don't return an error if the host doesn't support statvfs */
49247280Sdteske		if (errno == ENOSYS)
50247280Sdteske			return 0;
51247280Sdteske		fprintf(stderr, "statvfs for \"%s\" failed: %s\n",
52247280Sdteske		     path, strerror(errno));
53247280Sdteske	}
54247280Sdteske	return (sb.f_flag & ST_NOSUID) ? 1 : 0;
55247280Sdteske}
56247280Sdteske
57247280Sdteske
58247280Sdteske