X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=doas.c;h=a184650ba38ea9b4f8c781fd791a869efee32dc1;hb=b82ffa68a6436ce3f4c4b480bc9c12ac284b0d99;hp=008132b3a6e0d8c485f040049a973f54cec18040;hpb=84ccfe0b9ac591199d0464ede10a4130c8a3482d;p=opendoas.git diff --git a/doas.c b/doas.c index 008132b..a184650 100644 --- a/doas.c +++ b/doas.c @@ -15,11 +15,16 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" + #include #include #include #include +#ifdef HAVE_LOGIN_CAP_H +#include +#endif #include #include #include @@ -31,7 +36,7 @@ #include #include -#include "includes.h" +#include "openbsd.h" #include "doas.h" static void __dead @@ -340,7 +345,7 @@ main(int argc, char **argv) if (!permit(uid, groups, ngroups, &rule, target, cmd, (const char **)argv + 1)) { syslog(LOG_AUTHPRIV | LOG_NOTICE, - "failed command for %s: %s", mypw->pw_name, cmdline); + "command not permitted for %s: %s", mypw->pw_name, cmdline); errc(1, EPERM, NULL); } @@ -379,20 +384,30 @@ main(int argc, char **argv) rule->options & PERSIST); #endif +#ifdef HAVE_LOGIN_CAP_H + if (setusercontext(NULL, targpw, target, LOGIN_SETGROUP | + 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"); +#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);