]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
2 | * | |
3 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. | |
4 | * For copying and distribution information, please see the file | |
5 | * <mit-copyright.h>. | |
de56407f | 6 | */ |
de56407f | 7 | |
546bc43b | 8 | #include <mit-copyright.h> |
7ac48069 | 9 | #include <moira.h> |
10 | #include "update_server.h" | |
11 | #include "update.h" | |
12 | ||
de56407f | 13 | #include <sys/wait.h> |
7ac48069 | 14 | |
15 | #include <errno.h> | |
6143ee87 | 16 | #include <signal.h> |
7ac48069 | 17 | #include <stdio.h> |
18 | #include <unistd.h> | |
19 | ||
7ac48069 | 20 | RCSID("$Header$"); |
de56407f | 21 | |
85330553 | 22 | void exec_002(int conn, char *str) |
de56407f | 23 | { |
85330553 | 24 | int waitb, n; |
5eaef520 | 25 | sigset_t mask, oldmask; |
85330553 | 26 | pid_t pid; |
27 | long code; | |
de56407f | 28 | |
5eaef520 | 29 | if (!have_authorization) |
30 | { | |
85330553 | 31 | send_int(conn, MR_PERM); |
32 | return; | |
994657b2 | 33 | } |
5eaef520 | 34 | if (config_lookup("noexec")) |
35 | { | |
85330553 | 36 | send_int(conn, EPERM); |
37 | com_err(whoami, EPERM, "Not allowed to execute"); | |
38 | return; | |
8b3ba58e | 39 | } |
85330553 | 40 | |
5eaef520 | 41 | str += 8; |
42 | while (*str == ' ') | |
43 | str++; | |
44 | sigemptyset(&mask); | |
45 | sigaddset(&mask, SIGCHLD); | |
46 | sigprocmask(SIG_BLOCK, &mask, &oldmask); | |
47 | pid = fork(); | |
48 | switch (pid) | |
49 | { | |
de56407f | 50 | case -1: |
5eaef520 | 51 | n = errno; |
52 | sigprocmask(SIG_UNBLOCK, &oldmask, &mask); | |
85330553 | 53 | com_err(whoami, n, ": can't fork to run install script"); |
54 | code = send_int(conn, n); | |
5eaef520 | 55 | if (code) |
56 | exit(1); | |
85330553 | 57 | return; |
58 | ||
de56407f | 59 | case 0: |
5eaef520 | 60 | if (setuid(uid) < 0) |
61 | { | |
62 | com_err(whoami, errno, "Unable to setuid to %d\n", uid); | |
63 | exit(1); | |
8b3ba58e | 64 | } |
5eaef520 | 65 | sigprocmask(SIG_UNBLOCK, &oldmask, &mask); |
66 | execlp(str, str, NULL); | |
67 | n = errno; | |
68 | sigprocmask(SIG_UNBLOCK, &oldmask, &mask); | |
5eaef520 | 69 | com_err(whoami, n, ": %s", str); |
85330553 | 70 | send_int(conn, n); |
5eaef520 | 71 | exit(1); |
85330553 | 72 | |
de56407f | 73 | default: |
5eaef520 | 74 | do |
75 | n = wait(&waitb); | |
76 | while (n != -1 && n != pid); | |
85330553 | 77 | |
5eaef520 | 78 | sigprocmask(SIG_UNBLOCK, &oldmask, &mask); |
79 | if ((WIFEXITED(waitb) && (WEXITSTATUS(waitb) != 0)) || | |
80 | WIFSIGNALED(waitb)) | |
81 | { | |
5eaef520 | 82 | if (WIFSIGNALED(waitb)) |
83 | { | |
84 | n = MR_COREDUMP; | |
85 | com_err(whoami, n, " child exited on signal %d", | |
86 | WTERMSIG(waitb)); | |
585b298c | 87 | } |
5eaef520 | 88 | else |
89 | { | |
90 | n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms; | |
91 | com_err(whoami, n, " child exited with status %d", | |
92 | WEXITSTATUS(waitb)); | |
c8dc853f | 93 | } |
85330553 | 94 | code = send_int(conn, n); |
5eaef520 | 95 | if (code) |
96 | exit(1); | |
97 | } | |
98 | else | |
99 | { | |
85330553 | 100 | code = send_ok(conn); |
5eaef520 | 101 | if (code) |
102 | exit(1); | |
de56407f | 103 | } |
104 | } | |
85330553 | 105 | return; |
de56407f | 106 | } |