mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Better error message for GETINFO desc/(id|name) whenever microdescriptors are in use. Fixes #5847.
This commit is contained in:
parent
884c0ffe3b
commit
0a96d11539
5
changes/bug5847
Normal file
5
changes/bug5847
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
o Minor features (control port):
|
||||||
|
- Provide better error message for GETINFO desc/(id|name) when
|
||||||
|
microdescriptors are in use and router descriptors are not fetched.
|
||||||
|
Closes ticket 5847. Patch by Kevin Butler.
|
||||||
|
|
@ -60,6 +60,7 @@
|
|||||||
#include "hibernate.h"
|
#include "hibernate.h"
|
||||||
#include "hs_common.h"
|
#include "hs_common.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "microdesc.h"
|
||||||
#include "networkstatus.h"
|
#include "networkstatus.h"
|
||||||
#include "nodelist.h"
|
#include "nodelist.h"
|
||||||
#include "policies.h"
|
#include "policies.h"
|
||||||
@ -1892,6 +1893,12 @@ getinfo_helper_dir(control_connection_t *control_conn,
|
|||||||
const char *body = signed_descriptor_get_body(&ri->cache_info);
|
const char *body = signed_descriptor_get_body(&ri->cache_info);
|
||||||
if (body)
|
if (body)
|
||||||
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
|
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
|
||||||
|
} else if (! we_fetch_router_descriptors(get_options())) {
|
||||||
|
/* Descriptors won't be available, provide proper error */
|
||||||
|
*errmsg = "We fetch microdescriptors, not router "
|
||||||
|
"descriptors. You'll need to use md/id/* "
|
||||||
|
"instead of desc/id/*.";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (!strcmpstart(question, "desc/name/")) {
|
} else if (!strcmpstart(question, "desc/name/")) {
|
||||||
const routerinfo_t *ri = NULL;
|
const routerinfo_t *ri = NULL;
|
||||||
@ -1905,6 +1912,12 @@ getinfo_helper_dir(control_connection_t *control_conn,
|
|||||||
const char *body = signed_descriptor_get_body(&ri->cache_info);
|
const char *body = signed_descriptor_get_body(&ri->cache_info);
|
||||||
if (body)
|
if (body)
|
||||||
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
|
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
|
||||||
|
} else if (! we_fetch_router_descriptors(get_options())) {
|
||||||
|
/* Descriptors won't be available, provide proper error */
|
||||||
|
*errmsg = "We fetch microdescriptors, not router "
|
||||||
|
"descriptors. You'll need to use md/name/* "
|
||||||
|
"instead of desc/name/*.";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (!strcmp(question, "desc/all-recent")) {
|
} else if (!strcmp(question, "desc/all-recent")) {
|
||||||
routerlist_t *routerlist = router_get_routerlist();
|
routerlist_t *routerlist = router_get_routerlist();
|
||||||
@ -2907,7 +2920,8 @@ getinfo_helper_sr(control_connection_t *control_conn,
|
|||||||
* *<b>a</b>. If an internal error occurs, return -1 and optionally set
|
* *<b>a</b>. If an internal error occurs, return -1 and optionally set
|
||||||
* *<b>error_out</b> to point to an error message to be delivered to the
|
* *<b>error_out</b> to point to an error message to be delivered to the
|
||||||
* controller. On success, _or if the key is not recognized_, return 0. Do not
|
* controller. On success, _or if the key is not recognized_, return 0. Do not
|
||||||
* set <b>a</b> if the key is not recognized.
|
* set <b>a</b> if the key is not recognized but you may set <b>error_out</b>
|
||||||
|
* to improve the error message.
|
||||||
*/
|
*/
|
||||||
typedef int (*getinfo_helper_t)(control_connection_t *,
|
typedef int (*getinfo_helper_t)(control_connection_t *,
|
||||||
const char *q, char **a,
|
const char *q, char **a,
|
||||||
@ -3162,7 +3176,7 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
|
|||||||
smartlist_t *questions = smartlist_new();
|
smartlist_t *questions = smartlist_new();
|
||||||
smartlist_t *answers = smartlist_new();
|
smartlist_t *answers = smartlist_new();
|
||||||
smartlist_t *unrecognized = smartlist_new();
|
smartlist_t *unrecognized = smartlist_new();
|
||||||
char *msg = NULL, *ans = NULL;
|
char *ans = NULL;
|
||||||
int i;
|
int i;
|
||||||
(void) len; /* body is NUL-terminated, so it's safe to ignore the length. */
|
(void) len; /* body is NUL-terminated, so it's safe to ignore the length. */
|
||||||
|
|
||||||
@ -3177,20 +3191,26 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (!ans) {
|
if (!ans) {
|
||||||
smartlist_add(unrecognized, (char*)q);
|
if (errmsg) /* use provided error message */
|
||||||
|
smartlist_add_strdup(unrecognized, errmsg);
|
||||||
|
else /* use default error message */
|
||||||
|
smartlist_add_asprintf(unrecognized, "Unrecognized key \"%s\"", q);
|
||||||
} else {
|
} else {
|
||||||
smartlist_add_strdup(answers, q);
|
smartlist_add_strdup(answers, q);
|
||||||
smartlist_add(answers, ans);
|
smartlist_add(answers, ans);
|
||||||
}
|
}
|
||||||
} SMARTLIST_FOREACH_END(q);
|
} SMARTLIST_FOREACH_END(q);
|
||||||
|
|
||||||
if (smartlist_len(unrecognized)) {
|
if (smartlist_len(unrecognized)) {
|
||||||
|
/* control-spec section 2.3, mid-reply '-' or end of reply ' ' */
|
||||||
for (i=0; i < smartlist_len(unrecognized)-1; ++i)
|
for (i=0; i < smartlist_len(unrecognized)-1; ++i)
|
||||||
connection_printf_to_buf(conn,
|
connection_printf_to_buf(conn,
|
||||||
"552-Unrecognized key \"%s\"\r\n",
|
"552-%s\r\n",
|
||||||
(char*)smartlist_get(unrecognized, i));
|
(char *)smartlist_get(unrecognized, i));
|
||||||
|
|
||||||
connection_printf_to_buf(conn,
|
connection_printf_to_buf(conn,
|
||||||
"552 Unrecognized key \"%s\"\r\n",
|
"552 %s\r\n",
|
||||||
(char*)smartlist_get(unrecognized, i));
|
(char *)smartlist_get(unrecognized, i));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3217,8 +3237,8 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
|
|||||||
smartlist_free(answers);
|
smartlist_free(answers);
|
||||||
SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
|
||||||
smartlist_free(questions);
|
smartlist_free(questions);
|
||||||
|
SMARTLIST_FOREACH(unrecognized, char *, cp, tor_free(cp));
|
||||||
smartlist_free(unrecognized);
|
smartlist_free(unrecognized);
|
||||||
tor_free(msg);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user