| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "makeint.h" |
| 22 |
#include "filedef.h" |
| 23 |
#include "commands.h" |
| 24 |
#include "job.h" |
| 25 |
#include "debug.h" |
| 26 |
|
| 27 |
#include <sys/time.h> |
| 28 |
#include <netdb.h> |
| 29 |
|
| 30 |
#include "customs.h" |
| 31 |
|
| 32 |
char *remote_description = "Customs"; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#define EXPORT_COMMAND "/usr/local/bin/export" |
| 37 |
|
| 38 |
|
| 39 |
static ExportPermit permit; |
| 40 |
|
| 41 |
|
| 42 |
static char *normalized_cwd; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
void |
| 47 |
remote_setup (void) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void |
| 54 |
remote_cleanup (void) |
| 55 |
{ |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
int |
| 61 |
start_remote_job_p (int first_p) |
| 62 |
{ |
| 63 |
static int inited = 0; |
| 64 |
int status; |
| 65 |
int njobs; |
| 66 |
|
| 67 |
if (!inited) |
| 68 |
{ |
| 69 |
|
| 70 |
|
| 71 |
if (getenv ("GNU_MAKE_NO_CUSTOMS") != 0) |
| 72 |
{ |
| 73 |
inited = -1; |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
make_access (); |
| 80 |
|
| 81 |
if (ISDB (DB_JOBS)) |
| 82 |
Rpc_Debug (1); |
| 83 |
|
| 84 |
|
| 85 |
inited = Customs_Ping () == RPC_SUCCESS ? 1 : -1; |
| 86 |
|
| 87 |
|
| 88 |
user_access (); |
| 89 |
|
| 90 |
if (starting_directory == 0) |
| 91 |
|
| 92 |
inited = -1; |
| 93 |
else |
| 94 |
{ |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
normalized_cwd = xmalloc (GET_PATH_MAX); |
| 99 |
strcpy (normalized_cwd, starting_directory); |
| 100 |
if (Customs_NormPath (normalized_cwd, GET_PATH_MAX) < 0) |
| 101 |
|
| 102 |
|
| 103 |
inited = -1; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
if (inited < 0) |
| 108 |
return 0; |
| 109 |
|
| 110 |
njobs = job_slots_used; |
| 111 |
if (!first_p) |
| 112 |
njobs -= 1; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
if (max_load_average < 0 && njobs == 0 || njobs < max_load_average) |
| 117 |
return 0; |
| 118 |
|
| 119 |
status = Customs_Host (EXPORT_SAME, &permit); |
| 120 |
if (status != RPC_SUCCESS) |
| 121 |
{ |
| 122 |
DB (DB_JOBS, (_("Customs won't export: %s\n"), |
| 123 |
Rpc_ErrorMessage (status))); |
| 124 |
return 0; |
| 125 |
} |
| 126 |
|
| 127 |
return !CUSTOMS_FAIL (&permit.addr); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
int |
| 138 |
start_remote_job (char **argv, char **envp, int stdin_fd, |
| 139 |
int *is_remote, pid_t *id_ptr, int *used_stdin) |
| 140 |
{ |
| 141 |
char waybill[MAX_DATA_SIZE], msg[128]; |
| 142 |
struct hostent *host; |
| 143 |
struct timeval timeout; |
| 144 |
struct sockaddr_in sin; |
| 145 |
int len; |
| 146 |
int retsock, retport, sock; |
| 147 |
Rpc_Stat status; |
| 148 |
pid_t pid; |
| 149 |
|
| 150 |
|
| 151 |
retsock = Rpc_UdpCreate (True, 0); |
| 152 |
if (retsock < 0) |
| 153 |
{ |
| 154 |
O (error, NILF, "exporting: Couldn't create return socket."); |
| 155 |
return 1; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
len = sizeof (sin); |
| 160 |
if (getsockname (retsock, (struct sockaddr *) &sin, &len) < 0) |
| 161 |
{ |
| 162 |
(void) close (retsock); |
| 163 |
perror_with_name ("exporting: ", "getsockname"); |
| 164 |
return 1; |
| 165 |
} |
| 166 |
retport = sin.sin_port; |
| 167 |
|
| 168 |
|
| 169 |
sock = Rpc_TcpCreate (False, 0); |
| 170 |
|
| 171 |
|
| 172 |
len = Customs_MakeWayBill (&permit, normalized_cwd, argv[0], argv, |
| 173 |
envp, retport, waybill); |
| 174 |
|
| 175 |
|
| 176 |
{ |
| 177 |
WayBill *wb = (WayBill *) waybill; |
| 178 |
wb->ruid = wb->euid; |
| 179 |
wb->rgid = wb->egid; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
timeout.tv_usec = 0; |
| 184 |
timeout.tv_sec = 20; |
| 185 |
sin.sin_family = AF_INET; |
| 186 |
sin.sin_port = htons (Customs_Port ()); |
| 187 |
sin.sin_addr = permit.addr; |
| 188 |
status = Rpc_Call (sock, &sin, (Rpc_Proc) CUSTOMS_IMPORT, |
| 189 |
len, (Rpc_Opaque) waybill, |
| 190 |
sizeof (msg), (Rpc_Opaque) msg, |
| 191 |
1, &timeout); |
| 192 |
|
| 193 |
host = gethostbyaddr ((char *)&permit.addr, sizeof(permit.addr), AF_INET); |
| 194 |
|
| 195 |
{ |
| 196 |
const char *hnm = host ? host->h_name : inet_ntoa (permit.addr); |
| 197 |
size_t hlen = strlen (hnm); |
| 198 |
|
| 199 |
if (status != RPC_SUCCESS) |
| 200 |
{ |
| 201 |
const char *err = Rpc_ErrorMessage (status); |
| 202 |
(void) close (retsock); |
| 203 |
(void) close (sock); |
| 204 |
error (NILF, hlen + strlen (err), |
| 205 |
"exporting to %s: %s", hnm, err); |
| 206 |
return 1; |
| 207 |
} |
| 208 |
else if (msg[0] != 'O' || msg[1] != 'k' || msg[2] != '\0') |
| 209 |
{ |
| 210 |
(void) close (retsock); |
| 211 |
(void) close (sock); |
| 212 |
error (NILF, hlen + strlen (msg), "exporting to %s: %s", hnm, msg); |
| 213 |
return 1; |
| 214 |
} |
| 215 |
else |
| 216 |
{ |
| 217 |
error (NILF, hlen + INTSTR_LENGTH, |
| 218 |
"*** exported to %s (id %u)", hnm, permit.id); |
| 219 |
} |
| 220 |
|
| 221 |
fflush (stdout); |
| 222 |
fflush (stderr); |
| 223 |
} |
| 224 |
|
| 225 |
pid = vfork (); |
| 226 |
if (pid < 0) |
| 227 |
{ |
| 228 |
|
| 229 |
perror_with_name ("fork", ""); |
| 230 |
return 1; |
| 231 |
} |
| 232 |
else if (pid == 0) |
| 233 |
{ |
| 234 |
|
| 235 |
static char sock_buf[20], retsock_buf[20], id_buf[20]; |
| 236 |
static char *new_argv[6] = |
| 237 |
{ EXPORT_COMMAND, "-id", sock_buf, retsock_buf, id_buf, 0 }; |
| 238 |
|
| 239 |
|
| 240 |
(void) sprintf (sock_buf, "%d", sock); |
| 241 |
(void) sprintf (retsock_buf, "%d", retsock); |
| 242 |
(void) sprintf (id_buf, "%x", permit.id); |
| 243 |
|
| 244 |
|
| 245 |
if (stdin_fd != 0) |
| 246 |
(void) dup2 (stdin_fd, 0); |
| 247 |
|
| 248 |
|
| 249 |
unblock_all_sigs (); |
| 250 |
|
| 251 |
|
| 252 |
exec_command (new_argv, envp); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
(void) close (retsock); |
| 257 |
(void) close (sock); |
| 258 |
*is_remote = 0; |
| 259 |
*id_ptr = pid; |
| 260 |
*used_stdin = 1; |
| 261 |
return 0; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
int |
| 271 |
remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr, |
| 272 |
int block) |
| 273 |
{ |
| 274 |
return -1; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
void |
| 281 |
block_remote_children (void) |
| 282 |
{ |
| 283 |
return; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
void |
| 290 |
unblock_remote_children (void) |
| 291 |
{ |
| 292 |
return; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
int |
| 297 |
remote_kill (pid_t id, int sig) |
| 298 |
{ |
| 299 |
return -1; |
| 300 |
} |