-/* $OpenBSD: doas.c,v 1.23 2015/07/26 19:08:17 zhuk Exp $ */
+/* $OpenBSD: doas.c,v 1.28 2015/07/27 15:38:11 espie Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
static void __dead
usage(void)
{
- fprintf(stderr, "usage: doas [-s] [-C config] [-u user] command [args]\n");
+ fprintf(stderr, "usage: doas [-ns] [-C config] [-u user] command [args]\n");
exit(1);
}
size_t j;
for (j = 0; j < nextras; j++) {
if (strcmp(extra[j], safeset[i]) == 0) {
- extra[j--] = extra[nextras--];
+ nextras--;
+ extra[j] = extra[nextras];
extra[nextras] = NULL;
+ j--;
}
}
}
exit(1);
}
-static int
+static void __dead
checkconfig(const char *confpath, int argc, char **argv,
uid_t uid, gid_t *groups, int ngroups, uid_t target)
{
int ngroups;
int i, ch;
int sflag = 0;
+ int nflag = 0;
- while ((ch = getopt(argc, argv, "C:su:")) != -1) {
+ uid = getuid();
+ while ((ch = getopt(argc, argv, "C:nsu:")) != -1) {
switch (ch) {
case 'C':
confpath = optarg;
if (parseuid(optarg, &target) != 0)
errx(1, "unknown user");
break;
+ case 'n':
+ nflag = 1;
+ break;
case 's':
sflag = 1;
break;
parseconfig("/etc/doas.conf", 1);
/* cmdline is used only for logging, no need to abort on truncate */
- (void) strlcpy(cmdline, argv[0], sizeof(cmdline)) < sizeof(cmdline);
- if (strlcpy(cmdline, argv[0], sizeof(cmdline)) >= sizeof(cmdline))
- errx(1, "command line too long");
+ (void) strlcpy(cmdline, argv[0], sizeof(cmdline));
for (i = 1; i < argc; i++) {
if (strlcat(cmdline, " ", sizeof(cmdline)) >= sizeof(cmdline))
break;
}
if (!(rule->options & NOPASS)) {
+ if (nflag)
+ errx(1, "Authorization required");
if (!auth_userokay(myname, NULL, NULL, NULL)) {
syslog(LOG_AUTHPRIV | LOG_NOTICE,
"failed password for %s", myname);