]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ | |
6 | /* For copying and distribution information, please see the file */ | |
7 | /* <mit-copyright.h>. */ | |
8 | ||
9 | #ifndef lint | |
10 | static char *rcsid_exec_002_c = "$Header$"; | |
11 | #endif lint | |
12 | ||
13 | #include <mit-copyright.h> | |
14 | #include <stdio.h> | |
15 | #include <errno.h> | |
16 | #include <sys/types.h> | |
17 | #ifdef _AIX | |
18 | #undef _BSD | |
19 | #endif | |
20 | #include <sys/wait.h> | |
21 | #ifdef _AIX | |
22 | #define _BSD 44 | |
23 | #endif | |
24 | #include <signal.h> | |
25 | #include <gdb.h> | |
26 | #include <moira.h> | |
27 | #include "update.h" | |
28 | ||
29 | extern CONNECTION conn; | |
30 | extern int code, errno, uid; | |
31 | extern char *whoami; | |
32 | ||
33 | #if defined(vax) || defined(ibm032) | |
34 | #define WEXITSTATUS(waitb) ((waitb).w_retcode) | |
35 | #endif | |
36 | ||
37 | ||
38 | int | |
39 | exec_002(str) | |
40 | char *str; | |
41 | { | |
42 | #ifdef POSIX | |
43 | int waitb; | |
44 | sigset_t mask,oldmask; | |
45 | #else | |
46 | union wait waitb; | |
47 | int mask; | |
48 | #endif | |
49 | int n, pid; | |
50 | ||
51 | if (config_lookup("noexec")) { | |
52 | code = EPERM; | |
53 | code = send_object(conn, (char *)&code, INTEGER_T); | |
54 | com_err(whoami, code, "Not allowed to execute"); | |
55 | return(0); | |
56 | } | |
57 | str += 8; | |
58 | while (*str == ' ') | |
59 | str++; | |
60 | #ifdef POSIX | |
61 | sigemptyset(&mask); | |
62 | sigaddset(&mask,SIGCHLD); | |
63 | sigprocmask(SIG_BLOCK,&mask,&oldmask); | |
64 | #else | |
65 | mask = sigblock(sigmask(SIGCHLD)); | |
66 | #endif | |
67 | pid = fork(); | |
68 | switch (pid) { | |
69 | case -1: | |
70 | n = errno; | |
71 | #ifdef POSIX | |
72 | sigprocmask(SIG_UNBLOCK,&oldmask,&mask); | |
73 | #else | |
74 | sigsetmask(mask); | |
75 | #endif | |
76 | log_priority = log_ERROR; | |
77 | com_err(whoami, errno, ": can't fork to run install script"); | |
78 | code = send_object(conn, (char *)&n, INTEGER_T); | |
79 | if (code) | |
80 | exit(1); | |
81 | return(0); | |
82 | case 0: | |
83 | if (setuid(uid) < 0) { | |
84 | com_err(whoami, errno, "Unable to setuid to %d\n", uid); | |
85 | exit(1); | |
86 | } | |
87 | #ifdef POSIX | |
88 | sigprocmask(SIG_UNBLOCK,&oldmask,&mask); | |
89 | #else | |
90 | sigsetmask(mask); | |
91 | #endif | |
92 | execlp(str, str, (char *)NULL); | |
93 | n = errno; | |
94 | #ifdef POSIX | |
95 | sigprocmask(SIG_UNBLOCK,&oldmask,&mask); | |
96 | #else | |
97 | sigsetmask(mask); | |
98 | #endif | |
99 | log_priority = log_ERROR; | |
100 | com_err(whoami, n, ": %s", str); | |
101 | (void) send_object(conn, (char *)&n, INTEGER_T); | |
102 | exit(1); | |
103 | default: | |
104 | do { | |
105 | n = wait(&waitb); | |
106 | } while (n != -1 && n != pid); | |
107 | #ifdef POSIX | |
108 | sigprocmask(SIG_UNBLOCK,&oldmask,&mask); | |
109 | #else | |
110 | sigsetmask(mask); | |
111 | #endif | |
112 | #ifdef POSIX | |
113 | if (WIFEXITED(waitb)) { | |
114 | n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms; | |
115 | log_priority = log_ERROR; | |
116 | com_err(whoami, n, " child exited with status %d", | |
117 | WEXITSTATUS(waitb)); | |
118 | #else | |
119 | if (waitb.w_status) { | |
120 | n = waitb.w_retcode + ERROR_TABLE_BASE_sms; | |
121 | log_priority = log_ERROR; | |
122 | com_err(whoami, n, " child exited with status %d", | |
123 | waitb.w_retcode); | |
124 | #endif | |
125 | code = send_object(conn, (char *)&n, INTEGER_T); | |
126 | if (code) { | |
127 | exit(1); | |
128 | } | |
129 | } else { | |
130 | code = send_ok(); | |
131 | if (code) | |
132 | exit(1); | |
133 | } | |
134 | } | |
135 | } |