]> git.armaanb.net Git - opendoas.git/blobdiff - doas.c
Add insult option to doas.conf
[opendoas.git] / doas.c
diff --git a/doas.c b/doas.c
index 5a969a0834737800f9bb01d312ae37ab08085b5b..a99b964105e3465adb2c947bc974a0610cb87f70 100644 (file)
--- a/doas.c
+++ b/doas.c
@@ -35,8 +35,9 @@
 #include <syslog.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <time.h>
 
-#include "includes.h"
+#include "openbsd.h"
 #include "doas.h"
 
 static void __dead
@@ -139,7 +140,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++) {
@@ -235,6 +236,18 @@ mygetpwuid_r(uid_t uid, struct passwd *pwd, struct passwd **result)
        return rv;
 }
 
+void
+authfail(int opt)
+{
+
+#ifdef DOAS_INSULTS
+       if (opt)
+               printf("%s\n", getinsult());
+#endif
+
+       errx(1, "Authentication failed");
+}
+
 int
 main(int argc, char **argv)
 {
@@ -352,15 +365,17 @@ 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);
+               int ret = shadowauth(mypw->pw_name, rule->options & PERSIST);
+               if (ret == 5)
+                       authfail(rule->options & INSULT);
        }
 #elif !defined(USE_PAM)
        /* 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)
@@ -386,6 +401,7 @@ main(int argc, char **argv)
 
 #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");
@@ -396,6 +412,8 @@ main(int argc, char **argv)
                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)