X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/de56407f0fd27d5366a936b872972630f1683f0f..8b3ba58ebf0a18a240e178ea05986f646e4cbe8d:/update/exec_002.c diff --git a/update/exec_002.c b/update/exec_002.c index 4f4d06c4..887c4b13 100644 --- a/update/exec_002.c +++ b/update/exec_002.c @@ -2,36 +2,51 @@ * $Source$ * $Header$ */ +/* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ +/* For copying and distribution information, please see the file */ +/* . */ #ifndef lint static char *rcsid_exec_002_c = "$Header$"; #endif lint +#include #include +#include +#include #include -#include "gdb.h" +#include +#include +#include #include "update.h" -#include "sms_update_int.h" -#include "kludge.h" -#include "smsu_int.h" extern CONNECTION conn; -extern int code, errno; +extern int code, errno, uid; +extern char *whoami; + int exec_002(str) char *str; { union wait waitb; - int n, pid; + int n, pid, mask; + if (config_lookup("noexec")) { + code = EPERM; + code = send_object(conn, (char *)&code, INTEGER_T); + com_err(whoami, code, "Not allowed to execute"); + return; + } str += 8; while (*str == ' ') str++; + mask = sigblock(sigmask(SIGCHLD)); pid = fork(); switch (pid) { case -1: n = errno; + sigsetmask(mask); log_priority = log_ERROR; com_err(whoami, errno, ": can't fork to run install script"); code = send_object(conn, (char *)&n, INTEGER_T); @@ -39,8 +54,14 @@ exec_002(str) exit(1); return; case 0: + if (setuid(uid) < 0) { + com_err(whoami, errno, "Unable to setuid to %d\n", uid); + exit(1); + } + sigsetmask(mask); execlp(str, str, (char *)NULL); n = errno; + sigsetmask(mask); log_priority = log_ERROR; com_err(whoami, n, ": %s", str); (void) send_object(conn, (char *)&n, INTEGER_T); @@ -49,17 +70,19 @@ exec_002(str) do { n = wait(&waitb); } while (n != -1 && n != pid); + sigsetmask(mask); if (waitb.w_status) { + n = waitb.w_retcode + ERROR_TABLE_BASE_sms; log_priority = log_ERROR; - com_err(whoami, 0, "child exited with status %d", waitb.w_status); + com_err(whoami, n, " child exited with status %d", waitb.w_retcode); code = send_object(conn, (char *)&n, INTEGER_T); - if (code) + if (code) { exit(1); - } - else { + } + } else { code = send_ok(); if (code) - exit(1); + exit(1); } } }