Tor 0.4.9.1-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) |
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 2081 of file control_cmd.c.
#define CONTROL_CMD_PRIVATE |
Definition at line 11 of file control_cmd.c.
#define CONTROL_EVENTS_PRIVATE |
Definition at line 12 of file control_cmd.c.
#define CONTROL_MODULE_PRIVATE |
Definition at line 10 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 2099 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 2110 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 2087 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 2052 of file control_cmd.c.
|
static |
Compose the auth methods line of a PROTOCOLINFO reply.
Definition at line 1292 of file control_cmd.c.
STATIC hs_service_add_ephemeral_status_t add_onion_helper_add_service | ( | int | hs_version, |
add_onion_secret_key_t * | pk, | ||
smartlist_t * | port_cfgs, | ||
int | max_streams, | ||
int | max_streams_close_circuit, | ||
smartlist_t * | auth_clients_v3, | ||
char ** | address_out | ||
) |
Definition at line 1577 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 1865 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.
void control_cmd_free_all | ( | void | ) |
Definition at line 2231 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 1250 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 1611 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 1275 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 1628 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 937 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 1174 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 1133 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 2209 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 1960 of file control_cmd.c.
|
static |
Implementation for the DROPGUARDS command.
Definition at line 1384 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 1409 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 1442 of file control_cmd.c.
|
static |
Implementation for the HSPOST command.
Definition at line 1512 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 2038 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 1030 of file control_cmd.c.
|
static |
Called when we get a PROTOCOLINFO command: send back a reply.
Definition at line 1309 of file control_cmd.c.
|
static |
Called when we receive a REDIRECTSTREAM command. Try to change the target address of the named AP stream, and report success or failure.
Definition at line 1086 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 1204 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 892 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 1353 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 2168 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 1616 of file control_cmd.c.
|
static |
Definition at line 1619 of file control_cmd.c.
|
static |
Definition at line 925 of file control_cmd.c.
|
static |
Definition at line 928 of file control_cmd.c.
|
static |
Definition at line 1163 of file control_cmd.c.
|
static |
Definition at line 1124 of file control_cmd.c.
|
static |
An array defining all the recognized controller commands.
Definition at line 2121 of file control_cmd.c.
Referenced by handle_control_command().
|
static |
Definition at line 1953 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 1605 of file control_cmd.c.
Referenced by get_detached_onion_services().
|
static |
Definition at line 1378 of file control_cmd.c.
|
static |
Definition at line 511 of file control_cmd.c.
|
static |
Definition at line 1403 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 1431 of file control_cmd.c.
|
static |
Definition at line 1434 of file control_cmd.c.
|
static |
Definition at line 1500 of file control_cmd.c.
|
static |
Definition at line 1503 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 2161 of file control_cmd.c.
Referenced by handle_control_command().
|
static |
Definition at line 2029 of file control_cmd.c.
|
static |
Definition at line 1016 of file control_cmd.c.
|
static |
Definition at line 1020 of file control_cmd.c.
|
static |
Definition at line 1243 of file control_cmd.c.
|
static |
Definition at line 1078 of file control_cmd.c.
|
static |
Definition at line 262 of file control_cmd.c.
|
static |
Definition at line 1195 of file control_cmd.c.
|
static |
Definition at line 425 of file control_cmd.c.
|
static |
Definition at line 884 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 1346 of file control_cmd.c.