chiark / gitweb /
prefork-interp: ident, options
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 15:08:23 +0000 (16:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 20:21:10 +0000 (21:21 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cprogs/prefork-interp.c
cprogs/prefork.c
cprogs/prefork.h

index 8fcb5dcde70da89f66dfd1fc943839f2af267c38..61dcca93bf370a578bcd5a72cc5c4ad7b12c3360 100644 (file)
@@ -7,11 +7,27 @@
  *   prefork-interp  [<option>,..],<interpreter>   <script> [<args> ...]
  *   prefork-interp '[<option> ..] <interpreter>'  <script> [<args> ...]
  *
- * Options must specify argument laundering mode.
- * Currently the only mode supported is:
+ * Options must specify argument mediation approach.
+ * Currently the only argument mediation 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
+ *
+ * Options for setting the operation mode:
+ *
+ *   (none)     Default: start new server if needed, then run service
+ *   -f         Force a fresh service (old one is terminated)
+ *   --kill     Kill any existing service; do not actually run anything
+ *
+ * Options for controlling whether different invocations share a server:
+ *
+ *   -E VAR      ident includes env var VAR (or its absence)
+ *   -G STRING   ident includes string STRING
+ *   -g IDENT    use IDENT rather than hex(SHA256(... identity things ...))
+ *
+ * (Ordering of -E and -G options is relevant; invocations with different
+ * -E -G options are different even if the env var settings are the same)
  */
 
 /*
index e25aadf5af74e443585de21182a7fc66309e19a7..eca03c85f5177e39a37033162958d612595f2a4a 100644 (file)
@@ -55,19 +55,28 @@ void of_iassign(const struct cmdinfo *ci, const char *val) {
   *ci->iassignto = v;
 }
 
-void ident_addstring(const struct cmdinfo *ci, const char *string) {
-  /* ci may be 0 and is provided so this can be .call */
+static void ident_addbyte(char c) {
+  IDENT_ADD_OBJ(c);
+}
+
+void ident_addstring(const char *string) {
   sha256_update(&identsc,strlen(string)+1,string);
 }
 
+void off_ident_addstring(const struct cmdinfo *ci, const char *string) {
+  ident_addbyte('S');
+  ident_addstring(string);
+}
+
 void off_ident_addenv(const struct cmdinfo *ci, const char *name) {
   const char *val = getenv(name);
+  ident_addbyte('E');
   if (val) {
     sha256_update(&identsc,strlen(name),name); /* no nul */
     sha256_update(&identsc,1,"=");
-    ident_addstring(0,val);
+    ident_addstring(val);
   } else {
-    ident_addstring(0,name);
+    ident_addstring(name);
   }
 }
 
@@ -152,9 +161,9 @@ void find_socket_path(void) {
     unsigned char bbuf[32];
     int i;
 
-    ident_addstring(0,interp);
+    ident_addstring(interp);
     if (script)
-      ident_addstring(0,script);
+      ident_addstring(script);
     sha256_digest(&identsc,sizeof(bbuf),bbuf);
 
     for (i=0; i<identlen; i += 2)
index cfbd715fe24355933e0c60c97530430dfcae9e31..eef6b2ca367d3700a90b3497faa41b1e5de7aeca 100644 (file)
@@ -51,7 +51,7 @@ extern const struct cmdinfo cmdinfos[];
 #define PREFORK_CMDINFOS \
   { "help",   0, .call=of_help                                         }, \
   { 0, 'g',   1,                    .sassignto= &ident                 }, \
-  { 0, 'G',   1, .call= ident_addstring                                }, \
+  { 0, 'G',   1, .call= off_ident_addstring                            }, \
   { 0, 'E',   1, .call= off_ident_addenv                               },
 
 void process_opts(const char *const **argv_io);
@@ -83,7 +83,8 @@ void fusagemessage(FILE *f);
 void usagemessage(void);
 void of_help(const struct cmdinfo *ci, const char *val);
 void of_iassign(const struct cmdinfo *ci, const char *val);
-void ident_addstring(const struct cmdinfo *ci, const char *string);
+void ident_addstring(const char *string);
+void off_ident_addstring(const struct cmdinfo *ci, const char *name);
 void off_ident_addenv(const struct cmdinfo *ci, const char *name);
 void ident_addinit(void);
 bool stabs_same_inode(struct stat *a, struct stat *b);