Move superuser check to common.c

This commit is contained in:
Erik Ekman 2009-01-24 15:50:54 +00:00 committed by Erik Ekman
parent 03f4fb11d2
commit 352d75131f
4 changed files with 14 additions and 9 deletions

View File

@ -82,6 +82,17 @@ int setgroups(int count, int *groups)
}
#endif
void
check_superuser(void (*usage_fn)(void))
{
if (geteuid() != 0) {
warnx("Run as root and you'll be happy.\n");
usage_fn();
/* NOTREACHED */
}
}
int
open_dns(int localport, in_addr_t listen_ip)
{

View File

@ -58,6 +58,7 @@ struct query {
int fromlen;
};
void check_superuser(void (*usage_fn)(void));
int open_dns(int, in_addr_t);
void close_dns(int);

View File

@ -945,11 +945,7 @@ main(int argc, char **argv)
}
}
if (geteuid() != 0) {
warnx("Run as root and you'll be happy.\n");
usage();
/* NOTREACHED */
}
check_superuser(usage);
argc -= optind;
argv += optind;

View File

@ -1002,10 +1002,7 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
if (geteuid() != 0) {
warnx("Run as root and you'll be happy.\n");
usage();
}
check_superuser(usage);
if (argc != 2)
usage();