* prefork-interp [<option> ..] <interpreter> [<script> [<args> ...]]
* prefork-interp [<option>,..],<interpreter> <script> [<args> ...]
* prefork-interp '[<option> ..] <interpreter>' <script> [<args> ...]
+ *
+ * Options must specify argument laundering mode.
+ * Currently the only mode supported is:
+ * -U unlaundered: setup and executor both get all arguments and env vars
+ * ident covers only env vars specified with -E
+ * ident covers only arguments interpreter and (if present) script
*/
/*
* Process structure:
* (implicitly releases lock)
*
* setup (pre-exec) fd0: null,
- * fd[12: fd2-from-outer
+ * fd[12]: fd2-from-outer
* env fds: listener, call(server-end)(fake)
- * env fds: orig-fd[01]
* close fd: lockfile
+ * possibly clean env, argv
*
* setup (script) runs initialisation parts of the script
* at prefork establishment point:
* forks for server
* [2] exits
*
- # server (pm) [1] [fd0: null],
- * [fd[12: fd2-from-outer]
- * right away, forks one fa-monitor
+ * server (pm) [1] [fd0: null],
+ * [fd[12]: fd2-from-outer]
+ * right away, forks init monitor
* [2] closes outer caller fds and call(fake)
* [server (pm)] fd[012]: null
* other fds: listener, syslog
* runs in loop accepting and forking,
- * reaping and limiting children (incl fa-monitor)
+ * reaping and limiting children (incl init monitor)
* reports failures of monitors to syslog
*
- * f-a monitor forks executor
- * closes fd: listener
- * [fd[12: fd2-from-outer]
- * [other fds: call(server-end)(fake), syslog]
- * runs as monitor, below
- *
- *
* [client (C wrapper)] if client connect succeeds:
* now fd: call(client-end)
* sends message with: cmdline, env
* sends fds
*
- * [server (script)] accepts, forks monitor
+ * [server (script)] accepts, forks subseq monitor
*
- * monitor [1] [fd[012]: null]
- * other fds: syslog, call(server-end)
+ * monitor [1] [fd0: null]
+ * (init [fd[12]: init: fd2-from-outer; subseq: null]
+ * or errors: init: fd2; subseq: syslog
+ * subseq) other fds: syslog, call(server-end)
* sends ack byte
* receives args, env, fds
* forks executor
* exits normally
*
* [monitor] [fd[012]: null]
- * [other fds: call(server-end), syslog]
+ * [fd[12]: init: fd2-from-outer; subseq: null]
+ * [errors: init: fd2; subseq: syslog]
* reaps executor
* reports status via socket
*
fprintf(f, "usage: #!/usr/bin/prefork-interp [<options>]\n");
}
+static int laundering;
+
const struct cmdinfo cmdinfos[]= {
PREFORK_CMDINFOS
+ { 0, 'U', 0, .iassignto= &laundering, .arg= 'U' },
{ 0 }
};
+void ident_addinit(void) {
+ char ident_magic[1] = { 0 };
+ sha256_update(&identsc, sizeof(ident_magic), ident_magic);
+}
+
static void propagate_exit_status(int status, const char *what) {
int r;
return feof(call_sock) || errno==ECONNRESET;
}
+// Does protocol exchange. Returns 0 if OK, -1 if peer was garbage.
+static int protocol_exchange(FILE *call_sock) {
+ char ack;
+ size_t sr = fread(&ack, sizeof(ack), 1, call_sock);
+ if (sr != 1) {
+ if (was_eof(call_sock)) return -1;
+ diee("read() ack byte");
+ }
+ if (ack != '\n') die("got ack byte 0x%02x, not '\n'", ack);
+
+ // We're committed now, send the request (or bail out)
+ send_request(call_sock);
+
+ return 0;
+}
+
// Returns: call(client-end), or 0 to mean "is garbage"
// find_socket_path must have been called
static FILE *connect_existing(void) {
call_sock = call_sock_from_fd(fd);
fd = -1;
- char ack;
- size_t sr = fread(&ack, sizeof(ack), 1, call_sock);
- if (sr != 1) {
- if (was_eof(call_sock)) goto x_garbage;
- diee("read() ack byte");
- }
- if (ack != '\n') die("got ack byte 0x%02x, not '\n'", ack);
-
- // We're committed now, send the request (or bail out)
- send_request(call_sock);
+ if (protocol_exchange(call_sock) < 0)
+ goto x_garbage;
return call_sock;
}
static void make_executor_argv(const char *const *argv) {
+ switch (laundering) {
+ case 'U': break;
+ default: die("need -U (specifying unlaundered argument handling)");
+ }
+
const char *arg;
#define EACH_NEW_ARG(EACH) { \
arg = interp; { EACH } \