Tor
0.4.7.0-alpha-dev
|
Implement various commands for Tor's control-socket interface. More...
#include "core/or/or.h"
#include "app/config/config.h"
#include "lib/confmgt/confmgt.h"
#include "app/main/main.h"
#include "core/mainloop/connection.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/connection_edge.h"
#include "core/or/circuitstats.h"
#include "core/or/extendinfo.h"
#include "feature/client/addressmap.h"
#include "feature/client/dnsserv.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/control/control_auth.h"
#include "feature/control/control_cmd.h"
#include "feature/control/control_hs.h"
#include "feature/control/control_events.h"
#include "feature/control/control_getinfo.h"
#include "feature/control/control_proto.h"
#include "feature/hs/hs_control.h"
#include "feature/hs/hs_service.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/rend/rendcommon.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "lib/encoding/kvline.h"
#include "core/or/cpath_build_state_st.h"
#include "core/or/entry_connection_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/socks_request_st.h"
#include "feature/control/control_cmd_args_st.h"
#include "feature/control/control_connection_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "app/config/statefile.h"
Go to the source code of this file.
Data Structures | |
struct | control_cmd_def_t |
Macros | |
#define | CONTROL_MODULE_PRIVATE |
#define | CONTROL_CMD_PRIVATE |
#define | CONTROL_EVENTS_PRIVATE |
#define | STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN) |
#define | SEND_ERRMSG(code, msg) |
#define | SEND_ERRMSG(code, msg) control_printf_endreply(conn, code, msg ": %s", errstring); |
#define | CMD_FL_WIPE (1u<<0) |
#define | ONE_LINE(name, flags) |
#define | MULTLINE(name, flags) |
#define | OBSOLETE(name) |
Typedefs | |
typedef int(* | handler_fn_t) (control_connection_t *conn, const control_cmd_args_t *args) |
Variables | |
static const control_cmd_syntax_t | setconf_syntax |
static const control_cmd_syntax_t | resetconf_syntax |
static const control_cmd_syntax_t | getconf_syntax |
static const control_cmd_syntax_t | loadconf_syntax |
static const control_cmd_syntax_t | setevents_syntax |
static const control_cmd_syntax_t | saveconf_syntax |
static const control_cmd_syntax_t | signal_syntax |
static const control_cmd_syntax_t | takeownership_syntax |
static const control_cmd_syntax_t | dropownership_syntax |
static const control_cmd_syntax_t | mapaddress_syntax |
static const control_cmd_syntax_t | extendcircuit_syntax |
static const control_cmd_syntax_t | setcircuitpurpose_syntax |
static const char * | attachstream_keywords [] |
static const control_cmd_syntax_t | attachstream_syntax |
static const char * | postdescriptor_keywords [] |
static const control_cmd_syntax_t | postdescriptor_syntax |
static const control_cmd_syntax_t | redirectstream_syntax |
static const control_cmd_syntax_t | closestream_syntax |
static const control_cmd_syntax_t | closecircuit_syntax |
static const control_cmd_syntax_t | resolve_syntax |
static const control_cmd_syntax_t | protocolinfo_syntax |
static const control_cmd_syntax_t | usefeature_syntax |
static const control_cmd_syntax_t | dropguards_syntax |
static const control_cmd_syntax_t | droptimeouts_syntax |
static const char * | hsfetch_keywords [] |
static const control_cmd_syntax_t | hsfetch_syntax |
static const char * | hspost_keywords [] |
static const control_cmd_syntax_t | hspost_syntax |
static smartlist_t * | detached_onion_services = NULL |
static const char * | add_onion_keywords [] |
static const control_cmd_syntax_t | add_onion_syntax |
static const control_cmd_syntax_t | del_onion_syntax |
static const control_cmd_syntax_t | obsolete_syntax |
static const control_cmd_def_t | CONTROL_COMMANDS [] |
static const size_t | N_CONTROL_COMMANDS = ARRAY_LENGTH(CONTROL_COMMANDS) |
Implement various commands for Tor's control-socket interface.
Definition in file control_cmd.c.
#define CMD_FL_WIPE (1u<<0) |
Indicates that the command's arguments are sensitive, and should be memwiped after use.
Definition at line 2076 of file control_cmd.c.
#define MULTLINE | ( | name, | |
flags | |||
) |
Macro: declare a command with a multi-line argument and a given set of flags.
Definition at line 2094 of file control_cmd.c.
#define OBSOLETE | ( | name | ) |
Macro: declare an obsolete command. (Obsolete commands give a different error than non-existent ones.)
Definition at line 2105 of file control_cmd.c.
#define ONE_LINE | ( | name, | |
flags | |||
) |
Macro: declare a command with a one-line argument, a given set of flags, and a syntax definition.
Definition at line 2082 of file control_cmd.c.
#define SEND_ERRMSG | ( | code, | |
msg | |||
) |
#define STATE_IS_OPEN | ( | s | ) | ((s) == CONTROL_CONN_STATE_OPEN) |
Yield true iff s is the state of a control_connection_t that has finished authentication and is accepting commands.
Definition at line 63 of file control_cmd.c.
typedef int(* handler_fn_t) (control_connection_t *conn, const control_cmd_args_t *args) |
Function pointer to a handler function for a controller command.
Definition at line 2047 of file control_cmd.c.
|
static |
Compose the auth methods line of a PROTOCOLINFO reply.
Definition at line 1287 of file control_cmd.c.
STATIC int add_onion_helper_keyarg | ( | const char * | arg, |
int | discard_pk, | ||
const char ** | key_new_alg_out, | ||
char ** | key_new_blob_out, | ||
add_onion_secret_key_t * | decoded_key, | ||
int * | hs_version, | ||
control_connection_t * | conn | ||
) |
Helper function to handle parsing the KeyType:KeyBlob argument to the ADD_ONION command. Return a new crypto_pk_t and if a new key was generated and the private key not discarded, the algorithm and serialized private key, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned key_new_blob.
Note: The error messages returned are deliberately vague to avoid echoing key material.
Note: conn is only used for writing control replies. For testing purposes, it can be NULL if control_write_reply() is appropriately mocked.
Definition at line 1860 of file control_cmd.c.
|
static |
Return true iff addr is unusable as a mapaddress target because of containing funny characters.
Definition at line 616 of file control_cmd.c.
Referenced by handle_control_mapaddress().
|
static |
Given a string, convert it to a circuit purpose.
Definition at line 702 of file control_cmd.c.
|
static |
Return true iff lines contains flags as a no-value (keyword-only) entry.
Definition at line 240 of file control_cmd.c.
Referenced by handle_control_saveconf().
void control_cmd_args_free_ | ( | control_cmd_args_t * | args | ) |
Release all storage held in args
Definition at line 69 of file control_cmd.c.
void control_cmd_args_wipe | ( | control_cmd_args_t * | args | ) |
Erase all memory held in args.
Definition at line 86 of file control_cmd.c.
STATIC control_cmd_args_t* control_cmd_parse_args | ( | const char * | command, |
const control_cmd_syntax_t * | syntax, | ||
size_t | body_len, | ||
const char * | body, | ||
char ** | error_out | ||
) |
Helper: parse the arguments to a command according to syntax. On success, set *error_out to NULL and return a newly allocated control_cmd_args_t. On failure, set *error_out to newly allocated error string, and return NULL.
Definition at line 158 of file control_cmd.c.
Referenced by handle_single_control_command().
|
static |
Helper for setconf and resetconf. Acts like setconf, except it passes use_defaults on to options_trial_assign(). Modifies the contents of body.
Definition at line 567 of file control_cmd.c.
Referenced by handle_control_resetconf(), and handle_control_setconf().
|
static |
Return a comma-separated list of authentication methods for handle_control_protocolinfo(). Caller must free this string.
Definition at line 1245 of file control_cmd.c.
Referenced by add_authmethods().
|
static |
Given a text circuit id, return the corresponding circuit.
Definition at line 536 of file control_cmd.c.
smartlist_t* get_detached_onion_services | ( | void | ) |
Return a list of detached onion services, or NULL if none exist.
Definition at line 1606 of file control_cmd.c.
Referenced by getinfo_helper_onions().
|
static |
Return escaped cookie filename. Caller must free this string. Return NULL if cookie authentication is disabled.
Definition at line 1270 of file control_cmd.c.
Referenced by add_authmethods().
|
static |
Given a text stream id, return the corresponding AP connection.
Definition at line 548 of file control_cmd.c.
Referenced by handle_control_redirectstream().
|
static |
Called when we get a ADD_ONION command; parse the body, and set up the new ephemeral Onion Service.
Definition at line 1623 of file control_cmd.c.
|
static |
Called when we get an ATTACHSTREAM message. Try to attach the requested stream, and report success or failure.
Definition at line 932 of file control_cmd.c.
|
static |
Called when we get a CLOSECIRCUIT command; try to close the named circuit and report success or failure.
Definition at line 1169 of file control_cmd.c.
|
static |
Called when we get a CLOSESTREAM command; try to close the named stream and report success or failure.
Definition at line 1128 of file control_cmd.c.
int handle_control_command | ( | control_connection_t * | conn, |
uint32_t | cmd_data_len, | ||
char * | args | ||
) |
Run a given controller command, as selected by the current_cmd field of conn.
Definition at line 2204 of file control_cmd.c.
|
static |
Called when we get a DEL_ONION command; parse the body, and remove the existing ephemeral Onion Service.
Definition at line 1955 of file control_cmd.c.
|
static |
Implementation for the DROPGUARDS command.
Definition at line 1379 of file control_cmd.c.
|
static |
Called when we get a DROPOWNERSHIP command. Mark this connection as a non-owning connection, so that we will not exit if the connection closes.
Definition at line 519 of file control_cmd.c.
|
static |
Implementation for the DROPTIMEOUTS command.
Definition at line 1404 of file control_cmd.c.
|
static |
Called when we get an EXTENDCIRCUIT message. Try to extend the listed circuit, and report success or failure.
Definition at line 725 of file control_cmd.c.
|
static |
Called when we receive a GETCONF message. Parse the request, and reply with a CONFVALUE or an ERROR message
Definition at line 285 of file control_cmd.c.
|
static |
Implementation for the HSFETCH command.
Definition at line 1437 of file control_cmd.c.
|
static |
Implementation for the HSPOST command.
Definition at line 1507 of file control_cmd.c.
|
static |
Called when we get a +LOADCONF message.
Definition at line 336 of file control_cmd.c.
|
static |
Called when we get a MAPADDRESS command; try to bind all listed addresses, and report success or failure.
Definition at line 634 of file control_cmd.c.
|
static |
Called when we get an obsolete command: tell the controller that it is obsolete.
Definition at line 2033 of file control_cmd.c.
|
static |
Called when we get a POSTDESCRIPTOR message. Try to learn the provided descriptor, and report success or failure.
Definition at line 1025 of file control_cmd.c.
|
static |
Called when we get a PROTOCOLINFO command: send back a reply.
Definition at line 1304 of file control_cmd.c.
|
static |
Called when we receive a REDIRECTSTERAM command. Try to change the target address of the named AP stream, and report success or failure.
Definition at line 1081 of file control_cmd.c.
|
static |
Called when we receive a RESETCONF message: parse the body and try to update our configuration. Reply with a DONE or ERROR message. Modifies the contents of body.
Definition at line 272 of file control_cmd.c.
|
static |
Called when we get a RESOLVE command: start trying to resolve the listed addresses.
Definition at line 1199 of file control_cmd.c.
|
static |
Called when we get a SAVECONF command. Try to flush the current options to disk, and report success or failure.
Definition at line 434 of file control_cmd.c.
|
static |
Called when we get a SETCIRCUITPURPOSE message. If we can find the circuit and it's a valid purpose, change it.
Definition at line 887 of file control_cmd.c.
|
static |
Called when we receive a SETCONF message: parse the body and try to update our configuration. Reply with a DONE or ERROR message. Modifies the contents of body.
Definition at line 256 of file control_cmd.c.
|
static |
Called when we get a SETEVENTS message: update conn->event_mask, and reply with DONE or ERROR.
Definition at line 384 of file control_cmd.c.
|
static |
Called when we get a SIGNAL command. React to the provided signal, and report success or failure. (If the signal results in a shutdown, success may not be reported.)
Definition at line 457 of file control_cmd.c.
|
static |
Called when we get a TAKEOWNERSHIP command. Mark this connection as an owning connection, so that we will exit if the connection closes.
Definition at line 496 of file control_cmd.c.
|
static |
Called when we get a USEFEATURE command: parse the feature list, and set up the control_connection's options properly.
Definition at line 1348 of file control_cmd.c.
|
static |
Run a single control command, as defined by a control_cmd_def_t, with a given set of arguments.
Definition at line 2163 of file control_cmd.c.
Referenced by handle_control_command().
|
static |
Helper for argument parsing: check whether the keyword arguments just parsed in result were well-formed according to syntax.
On success, return 0. On failure, return -1 and set *error_out to a newly allocated error string.
Definition at line 123 of file control_cmd.c.
|
static |
Return true iff any element of the NULL-terminated array matches kwd. Case-insensitive.
Definition at line 107 of file control_cmd.c.
Referenced by kvline_check_keyword_args().
|
static |
Definition at line 1611 of file control_cmd.c.
|
static |
Definition at line 1614 of file control_cmd.c.
|
static |
Definition at line 920 of file control_cmd.c.
|
static |
Definition at line 923 of file control_cmd.c.
|
static |
Definition at line 1158 of file control_cmd.c.
|
static |
Definition at line 1119 of file control_cmd.c.
|
static |
An array defining all the recognized controller commands.
Definition at line 2116 of file control_cmd.c.
Referenced by handle_control_command().
|
static |
Definition at line 1948 of file control_cmd.c.
|
static |
The list of onion services that have been added via ADD_ONION that do not belong to any particular control connection.
Definition at line 1600 of file control_cmd.c.
Referenced by get_detached_onion_services().
|
static |
Definition at line 1373 of file control_cmd.c.
|
static |
Definition at line 511 of file control_cmd.c.
|
static |
Definition at line 1398 of file control_cmd.c.
|
static |
Definition at line 715 of file control_cmd.c.
|
static |
Definition at line 278 of file control_cmd.c.
|
static |
Definition at line 1426 of file control_cmd.c.
|
static |
Definition at line 1429 of file control_cmd.c.
|
static |
Definition at line 1495 of file control_cmd.c.
|
static |
Definition at line 1498 of file control_cmd.c.
|
static |
Definition at line 330 of file control_cmd.c.
|
static |
Definition at line 624 of file control_cmd.c.
|
static |
The number of entries in CONTROL_COMMANDS.
Definition at line 2156 of file control_cmd.c.
Referenced by handle_control_command().
|
static |
Definition at line 2024 of file control_cmd.c.
|
static |
Definition at line 1011 of file control_cmd.c.
|
static |
Definition at line 1015 of file control_cmd.c.
|
static |
Definition at line 1238 of file control_cmd.c.
|
static |
Definition at line 1073 of file control_cmd.c.
|
static |
Definition at line 262 of file control_cmd.c.
|
static |
Definition at line 1190 of file control_cmd.c.
|
static |
Definition at line 425 of file control_cmd.c.
|
static |
Definition at line 879 of file control_cmd.c.
|
static |
Definition at line 246 of file control_cmd.c.
|
static |
Definition at line 377 of file control_cmd.c.
|
static |
Definition at line 448 of file control_cmd.c.
|
static |
Definition at line 488 of file control_cmd.c.
|
static |
Definition at line 1341 of file control_cmd.c.