]> git.armaanb.net Git - opendoas.git/blobdiff - doas.c
Replace build/installation instructions with discouragements
[opendoas.git] / doas.c
diff --git a/doas.c b/doas.c
index 8275fe180b70ed80e99a8ee05affcca54b610e38..ac3a42a3a171cd96680ed34446278f3dc1f8d473 100644 (file)
--- a/doas.c
+++ b/doas.c
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "config.h"
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 
 #include <limits.h>
+#ifdef HAVE_LOGIN_CAP_H
+#include <login_cap.h>
+#endif
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,7 +36,7 @@
 #include <errno.h>
 #include <fcntl.h>
 
-#include "includes.h"
+#include "openbsd.h"
 #include "doas.h"
 
 static void __dead
@@ -134,7 +139,7 @@ static int
 permit(uid_t uid, gid_t *groups, int ngroups, const struct rule **lastr,
     uid_t target, const char *cmd, const char **cmdargs)
 {
-       int i;
+       size_t i;
 
        *lastr = NULL;
        for (i = 0; i < nrules; i++) {
@@ -347,7 +352,7 @@ main(int argc, char **argv)
 #if defined(USE_SHADOW)
        if (!(rule->options & NOPASS)) {
                if (nflag)
-                       errx(1, "Authorization required");
+                       errx(1, "Authentication required");
 
                shadowauth(mypw->pw_name, rule->options & PERSIST);
        }
@@ -355,7 +360,7 @@ main(int argc, char **argv)
        /* no authentication provider, only allow NOPASS rules */
        (void) nflag;
        if (!(rule->options & NOPASS))
-               errx(1, "Authorization required");
+               errx(1, "Authentication required");
 #endif
 
        if ((p = getenv("PATH")) != NULL)
@@ -379,20 +384,33 @@ main(int argc, char **argv)
            rule->options & PERSIST);
 #endif
 
+#ifdef HAVE_LOGIN_CAP_H
+       if (setusercontext(NULL, targpw, target, LOGIN_SETGROUP |
+           LOGIN_SETPATH |
+           LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
+           LOGIN_SETUSER) != 0)
+               errx(1, "failed to set user context for target");
+#else
        if (setresgid(targpw->pw_gid, targpw->pw_gid, targpw->pw_gid) != 0)
                err(1, "setresgid");
        if (initgroups(targpw->pw_name, targpw->pw_gid) != 0)
                err(1, "initgroups");
        if (setresuid(target, target, target) != 0)
                err(1, "setresuid");
+       if (setenv("PATH", safepath, 1) == -1)
+               err(1, "failed to set PATH '%s'", safepath);
+#endif
 
        if (getcwd(cwdpath, sizeof(cwdpath)) == NULL)
                cwd = "(failed)";
        else
                cwd = cwdpath;
 
-       syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
-           mypw->pw_name, cmdline, targpw->pw_name, cwd);
+       if (!(rule->options & NOLOG)) {
+               syslog(LOG_AUTHPRIV | LOG_INFO,
+                   "%s ran command %s as %s from %s",
+                   mypw->pw_name, cmdline, targpw->pw_name, cwd);
+       }
 
        envp = prepenv(rule, mypw, targpw);