diff options
Diffstat (limited to 'src/feature/rend/rendservice.c')
-rw-r--r-- | src/feature/rend/rendservice.c | 138 |
1 files changed, 3 insertions, 135 deletions
diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c index 2be68eadbe..a744f6f93a 100644 --- a/src/feature/rend/rendservice.c +++ b/src/feature/rend/rendservice.c @@ -237,8 +237,8 @@ rend_service_free_(rend_service_t *service) tor_free(service->directory); if (service->ports) { - SMARTLIST_FOREACH(service->ports, rend_service_port_config_t*, p, - rend_service_port_config_free(p)); + SMARTLIST_FOREACH(service->ports, hs_port_config_t*, p, + hs_port_config_free(p)); smartlist_free(service->ports); } if (service->private_key) @@ -355,7 +355,7 @@ static int rend_add_service(smartlist_t *service_list, rend_service_t *service) { int i; - rend_service_port_config_t *p; + hs_port_config_t *p; tor_assert(service); @@ -408,138 +408,6 @@ rend_add_service(smartlist_t *service_list, rend_service_t *service) return 0; } -/** Return a new rend_service_port_config_t with its path set to - * <b>socket_path</b> or empty if <b>socket_path</b> is NULL */ -static rend_service_port_config_t * -rend_service_port_config_new(const char *socket_path) -{ - if (!socket_path) - return tor_malloc_zero(sizeof(rend_service_port_config_t) + 1); - - const size_t pathlen = strlen(socket_path) + 1; - rend_service_port_config_t *conf = - tor_malloc_zero(sizeof(rend_service_port_config_t) + pathlen); - memcpy(conf->unix_addr, socket_path, pathlen); - conf->is_unix_addr = 1; - return conf; -} - -/** Parses a virtual-port to real-port/socket mapping separated by - * the provided separator and returns a new rend_service_port_config_t, - * or NULL and an optional error string on failure. - * - * The format is: VirtualPort SEP (IP|RealPort|IP:RealPort|'socket':path)? - * - * IP defaults to 127.0.0.1; RealPort defaults to VirtualPort. - */ -rend_service_port_config_t * -rend_service_parse_port_config(const char *string, const char *sep, - char **err_msg_out) -{ - smartlist_t *sl; - int virtport; - int realport = 0; - uint16_t p; - tor_addr_t addr; - rend_service_port_config_t *result = NULL; - unsigned int is_unix_addr = 0; - const char *socket_path = NULL; - char *err_msg = NULL; - char *addrport = NULL; - - sl = smartlist_new(); - smartlist_split_string(sl, string, sep, - SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2); - if (smartlist_len(sl) < 1 || BUG(smartlist_len(sl) > 2)) { - err_msg = tor_strdup("Bad syntax in hidden service port configuration."); - goto err; - } - virtport = (int)tor_parse_long(smartlist_get(sl,0), 10, 1, 65535, NULL,NULL); - if (!virtport) { - tor_asprintf(&err_msg, "Missing or invalid port %s in hidden service " - "port configuration", escaped(smartlist_get(sl,0))); - - goto err; - } - if (smartlist_len(sl) == 1) { - /* No addr:port part; use default. */ - realport = virtport; - tor_addr_from_ipv4h(&addr, 0x7F000001u); /* 127.0.0.1 */ - } else { - int ret; - - const char *addrport_element = smartlist_get(sl,1); - const char *rest = NULL; - int is_unix; - ret = port_cfg_line_extract_addrport(addrport_element, &addrport, - &is_unix, &rest); - - if (ret < 0) { - tor_asprintf(&err_msg, "Couldn't process address <%s> from hidden " - "service configuration", addrport_element); - goto err; - } - - if (rest && strlen(rest)) { - err_msg = tor_strdup("HiddenServicePort parse error: invalid port " - "mapping"); - goto err; - } - - if (is_unix) { - socket_path = addrport; - is_unix_addr = 1; - } else if (strchr(addrport, ':') || strchr(addrport, '.')) { - /* else try it as an IP:port pair if it has a : or . in it */ - if (tor_addr_port_lookup(addrport, &addr, &p)<0) { - err_msg = tor_strdup("Unparseable address in hidden service port " - "configuration."); - goto err; - } - realport = p?p:virtport; - } else { - /* No addr:port, no addr -- must be port. */ - realport = (int)tor_parse_long(addrport, 10, 1, 65535, NULL, NULL); - if (!realport) { - tor_asprintf(&err_msg, "Unparseable or out-of-range port %s in " - "hidden service port configuration.", - escaped(addrport)); - goto err; - } - tor_addr_from_ipv4h(&addr, 0x7F000001u); /* Default to 127.0.0.1 */ - } - } - - /* Allow room for unix_addr */ - result = rend_service_port_config_new(socket_path); - result->virtual_port = virtport; - result->is_unix_addr = is_unix_addr; - if (!is_unix_addr) { - result->real_port = realport; - tor_addr_copy(&result->real_addr, &addr); - result->unix_addr[0] = '\0'; - } - - err: - tor_free(addrport); - if (err_msg_out != NULL) { - *err_msg_out = err_msg; - } else { - tor_free(err_msg); - } - SMARTLIST_FOREACH(sl, char *, c, tor_free(c)); - smartlist_free(sl); - - return result; -} - -/** Release all storage held in a rend_service_port_config_t. */ -void -rend_service_port_config_free_(rend_service_port_config_t *p) -{ - tor_free(p); -} - /* Copy relevant data from service src to dst while pruning the service lists. * This should only be called during the pruning process which takes existing * services and copy their data to the newly configured services. The src |