]> git.armaanb.net Git - opendoas.git/blobdiff - doas.c
correct some unveil(2) violations due to "login.conf.db" access (the .db version...
[opendoas.git] / doas.c
diff --git a/doas.c b/doas.c
index 28954ecb6c7aee7a3db12ebf871a6e5e00782528..71f955a76afc65b7a328ff9b2963f6b8537eaf2f 100644 (file)
--- a/doas.c
+++ b/doas.c
@@ -249,6 +249,46 @@ good:
 }
 #endif
 
+#ifdef __OpenBSD__
+int
+unveilcommands(const char *ipath, const char *cmd)
+{
+       char *path = NULL, *p;
+       int unveils = 0;
+
+       if (strchr(cmd, '/') != NULL) {
+               if (unveil(cmd, "x") != -1)
+                       unveils++;
+               goto done;
+       }
+
+       if (!ipath) {
+               errno = ENOENT;
+               goto done;
+       }
+       path = strdup(ipath);
+       if (!path) {
+               errno = ENOENT;
+               goto done;
+       }
+       for (p = path; p && *p; ) {
+               char buf[PATH_MAX];
+               char *cp = strsep(&p, ":");
+
+               if (cp) {
+                       int r = snprintf(buf, sizeof buf, "%s/%s", cp, cmd);
+                       if (r >= 0 && r < sizeof buf) {
+                               if (unveil(buf, "x") != -1)
+                                       unveils++;
+                       }
+               }
+       }
+done:
+       free(path);
+       return (unveils);
+}
+#endif
+
 int
 main(int argc, char **argv)
 {
@@ -500,10 +540,13 @@ main(int argc, char **argv)
 
        envp = prepenv(rule, mypw, targpw);
 
+       /* setusercontext set path for the next process, so reset it for us */
        if (rule->cmd) {
-               /* do this again after setusercontext reset it */
                if (setenv("PATH", safepath, 1) == -1)
                        err(1, "failed to set PATH '%s'", safepath);
+       } else {
+               if (setenv("PATH", formerpath, 1) == -1)
+                       err(1, "failed to set PATH '%s'", formerpath);
        }
        execvpe(cmd, argv, envp);
        if (errno == ENOENT)