[or-cvs] r13948: Implement LOADCONF control command The LOADCONF control comm (tor/trunk/src/or)

weasel at seul.org weasel at seul.org
Mon Mar 10 12:41:53 UTC 2008


Author: weasel
Date: 2008-03-10 08:41:52 -0400 (Mon, 10 Mar 2008)
New Revision: 13948

Modified:
   tor/trunk/src/or/control.c
Log:
Implement LOADCONF control command

The LOADCONF control command allows posting a config file to Tor
over the control interface.  This config file is then loaded as if
it had been read from disk.  Sending a HUP signal to Tor will make
it try to load its old config from disk again, thereby forgetting
the config loaded with this command.


Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2008-03-10 12:41:49 UTC (rev 13947)
+++ tor/trunk/src/or/control.c	2008-03-10 12:41:52 UTC (rev 13948)
@@ -100,6 +100,8 @@
                                     char *body);
 static int handle_control_getconf(control_connection_t *conn, uint32_t len,
                                   const char *body);
+static int handle_control_loadconf(control_connection_t *conn, uint32_t len,
+                                  const char *body);
 static int handle_control_setevents(control_connection_t *conn, uint32_t len,
                                     const char *body);
 static int handle_control_authenticate(control_connection_t *conn,
@@ -862,6 +864,49 @@
   return 0;
 }
 
+
+/** Called when we get a +LOADCONF message. */
+static int
+handle_control_loadconf(control_connection_t *conn, uint32_t len,
+                         const char *body)
+{
+  int retval;
+  char *errstring = NULL;
+  char *msg = NULL;
+
+  retval = options_init_from_string(body, CMD_RUN_TOR, NULL, &errstring);
+
+  if (retval < 0) {
+    log_warn(LD_CONTROL,
+             "Controller gave us config file that didn't validate: %s",
+             errstring);
+    switch (retval) {
+      case -2:
+        msg = "552 Invalid config file";
+        break;
+      case -3:
+        msg = "553 Transition not allowed";
+        break;
+      case -4:
+        msg = "553 Unable to set option";
+        break;
+      case -1:
+      default:
+        msg = "550 Unable to load config";
+        break;
+    }
+    if (*errstring)
+      connection_printf_to_buf(conn, "%s: %s\r\n", msg, errstring);
+    else
+      connection_printf_to_buf(conn, "%s\r\n", msg);
+    tor_free(errstring);
+    return 0;
+  }
+  send_control_done(conn);
+  return 0;
+}
+
+
 /** Called when we get a SETEVENTS message: update conn->event_mask,
  * and reply with DONE or ERROR. */
 static int
@@ -2801,6 +2846,9 @@
   } else if (!strcasecmp(conn->incoming_cmd, "GETCONF")) {
     if (handle_control_getconf(conn, cmd_data_len, args))
       return -1;
+  } else if (!strcasecmp(conn->incoming_cmd, "+LOADCONF")) {
+    if (handle_control_loadconf(conn, cmd_data_len, args))
+      return -1;
   } else if (!strcasecmp(conn->incoming_cmd, "SETEVENTS")) {
     if (handle_control_setevents(conn, cmd_data_len, args))
       return -1;



More information about the tor-commits mailing list