tor  0.4.2.1-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
control_cmd.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "lib/confmgt/confparse.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 "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_events.h"
#include "feature/control/control_getinfo.h"
#include "feature/control/control_proto.h"
#include "feature/hs/hs_control.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendparse.h"
#include "feature/rend/rendservice.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 "feature/rend/rend_authorized_client_st.h"
#include "feature/rend/rend_encoded_v2_service_descriptor_st.h"
#include "feature/rend/rend_service_descriptor_st.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)
 
typedef struct control_cmd_def_t control_cmd_def_t
 

Functions

static int control_setconf_helper (control_connection_t *conn, const control_cmd_args_t *args, int use_defaults)
 
void control_cmd_args_free_ (control_cmd_args_t *args)
 
void control_cmd_args_wipe (control_cmd_args_t *args)
 
static bool string_array_contains_keyword (const char **array, const char *kwd)
 
static int kvline_check_keyword_args (const control_cmd_args_t *result, const control_cmd_syntax_t *syntax, char **error_out)
 
STATIC control_cmd_args_tcontrol_cmd_parse_args (const char *command, const control_cmd_syntax_t *syntax, size_t body_len, const char *body, char **error_out)
 
static bool config_lines_contain_flag (const config_line_t *lines, const char *flag)
 
static int handle_control_setconf (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_resetconf (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_getconf (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_loadconf (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_setevents (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_saveconf (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_signal (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_takeownership (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_dropownership (control_connection_t *conn, const control_cmd_args_t *args)
 
static origin_circuit_tget_circ (const char *id)
 
static entry_connection_tget_stream (const char *id)
 
static int address_is_invalid_mapaddress_target (const char *addr)
 
static int handle_control_mapaddress (control_connection_t *conn, const control_cmd_args_t *args)
 
static uint8_t circuit_purpose_from_string (const char *string)
 
static int handle_control_extendcircuit (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_setcircuitpurpose (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_attachstream (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_postdescriptor (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_redirectstream (control_connection_t *conn, const control_cmd_args_t *cmd_args)
 
static int handle_control_closestream (control_connection_t *conn, const control_cmd_args_t *cmd_args)
 
static int handle_control_closecircuit (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_resolve (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_protocolinfo (control_connection_t *conn, const control_cmd_args_t *cmd_args)
 
static int handle_control_usefeature (control_connection_t *conn, const control_cmd_args_t *cmd_args)
 
static int handle_control_dropguards (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_hsfetch (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_control_hspost (control_connection_t *conn, const control_cmd_args_t *args)
 
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, int auth_type, smartlist_t *auth_clients, char **address_out)
 
smartlist_tget_detached_onion_services (void)
 
static int handle_control_add_onion (control_connection_t *conn, const control_cmd_args_t *args)
 
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)
 
STATIC rend_authorized_client_tadd_onion_helper_clientauth (const char *arg, int *created, control_connection_t *conn)
 
static int handle_control_del_onion (control_connection_t *conn, const control_cmd_args_t *cmd_args)
 
static int handle_control_obsolete (control_connection_t *conn, const control_cmd_args_t *args)
 
static int handle_single_control_command (const control_cmd_def_t *def, control_connection_t *conn, uint32_t cmd_data_len, char *args)
 
int handle_control_command (control_connection_t *conn, uint32_t cmd_data_len, char *args)
 
void control_cmd_free_all (void)
 

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 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_tdetached_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)
 

Detailed Description

Implement various commands for Tor's control-socket interface.

Definition in file control_cmd.c.

Macro Definition Documentation

◆ CMD_FL_WIPE

#define CMD_FL_WIPE   (1u<<0)

Indicates that the command's arguments are sensitive, and should be memwiped after use.

Definition at line 2246 of file control_cmd.c.

◆ MULTLINE

#define MULTLINE (   name,
  flags 
)
Value:
{ "+"#name, \
handle_control_ ##name, \
flags, \
&name##_syntax \
}

Macro: declare a command with a multi-line argument and a given set of flags.

Definition at line 2263 of file control_cmd.c.

◆ OBSOLETE

#define OBSOLETE (   name)
Value:
{ #name, \
handle_control_obsolete, \
0, \
&obsolete_syntax, \
}

Macro: declare an obsolete command. (Obsolete commands give a different error than non-existent ones.)

Definition at line 2274 of file control_cmd.c.

◆ ONE_LINE

#define ONE_LINE (   name,
  flags 
)
Value:
{ \
#name, \
handle_control_ ##name, \
flags, \
&name##_syntax, \
}

Macro: declare a command with a one-line argument, a given set of flags, and a syntax definition.

Definition at line 2251 of file control_cmd.c.

◆ SEND_ERRMSG

#define SEND_ERRMSG (   code,
  msg 
)
Value:
control_printf_endreply(conn, code, msg "%s%s", \
errstring ? ": " : "", \
errstring ? errstring : "")
void control_printf_endreply(control_connection_t *conn, int code, const char *fmt,...)

◆ STATE_IS_OPEN

#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 Documentation

◆ control_cmd_def_t

Definition for a controller command.

◆ handler_fn_t

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 2217 of file control_cmd.c.

Function Documentation

◆ add_onion_helper_clientauth()

STATIC rend_authorized_client_t* add_onion_helper_clientauth ( const char *  arg,
int *  created,
control_connection_t conn 
)

Helper function to handle parsing a ClientAuth argument to the ADD_ONION command. Return a new rend_authorized_client_t, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned auth_client.

If 'created' is specified, it will be set to 1 when a new cookie has been generated.

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 2064 of file control_cmd.c.

References tor_assert().

◆ add_onion_helper_keyarg()

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 1930 of file control_cmd.c.

References smartlist_split_string().

◆ address_is_invalid_mapaddress_target()

static int address_is_invalid_mapaddress_target ( const char *  addr)
static

Return true iff addr is unusable as a mapaddress target because of containing funny characters.

Definition at line 633 of file control_cmd.c.

References address_is_invalid_destination(), and strcmpstart().

Referenced by handle_control_mapaddress().

◆ circuit_purpose_from_string()

static uint8_t circuit_purpose_from_string ( const char *  string)
static

Given a string, convert it to a circuit purpose.

Definition at line 717 of file control_cmd.c.

References CIRCUIT_PURPOSE_C_GENERAL, CIRCUIT_PURPOSE_CONTROLLER, CIRCUIT_PURPOSE_UNKNOWN, and strcasecmpstart().

◆ config_lines_contain_flag()

static bool config_lines_contain_flag ( const config_line_t lines,
const char *  flag 
)
static

Return true iff lines contains flags as a no-value (keyword-only) entry.

Definition at line 240 of file control_cmd.c.

References config_line_find_case().

Referenced by handle_control_saveconf().

◆ control_cmd_args_free_()

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.

References control_cmd_args_t::args, SMARTLIST_FOREACH, and tor_free.

◆ control_cmd_args_wipe()

void control_cmd_args_wipe ( control_cmd_args_t args)

◆ control_cmd_parse_args()

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().

◆ control_setconf_helper()

static int control_setconf_helper ( control_connection_t conn,
const control_cmd_args_t args,
int  use_defaults 
)
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 584 of file control_cmd.c.

References CAL_CLEAR_FIRST, CAL_USE_DEFAULTS, config_lines_dup(), control_cmd_args_t::kwargs, and options_trial_assign().

Referenced by handle_control_resetconf(), and handle_control_setconf().

◆ get_circ()

static origin_circuit_t* get_circ ( const char *  id)
static

Given a text circuit id, return the corresponding circuit.

Definition at line 553 of file control_cmd.c.

References circuit_get_by_global_id(), and tor_parse_ulong().

◆ get_detached_onion_services()

smartlist_t* get_detached_onion_services ( void  )

Return a list of detached onion services, or NULL if none exist.

Definition at line 1640 of file control_cmd.c.

References detached_onion_services.

Referenced by getinfo_helper_onions().

◆ get_stream()

static entry_connection_t* get_stream ( const char *  id)
static

Given a text stream id, return the corresponding AP connection.

Definition at line 565 of file control_cmd.c.

References CONN_TYPE_AP, connection_get_by_global_id(), connection_t::marked_for_close, tor_parse_uint64(), and connection_t::type.

Referenced by handle_control_redirectstream().

◆ handle_control_add_onion()

static int handle_control_add_onion ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a ADD_ONION command; parse the body, and set up the new ephemeral Onion Service.

Definition at line 1657 of file control_cmd.c.

◆ handle_control_attachstream()

static int handle_control_attachstream ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get an ATTACHSTREAM message. Try to attach the requested stream, and report success or failure.

Definition at line 946 of file control_cmd.c.

◆ handle_control_closecircuit()

static int handle_control_closecircuit ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a CLOSECIRCUIT command; try to close the named circuit and report success or failure.

Definition at line 1184 of file control_cmd.c.

◆ handle_control_closestream()

static int handle_control_closestream ( control_connection_t conn,
const control_cmd_args_t cmd_args 
)
static

Called when we get a CLOSESTREAM command; try to close the named stream and report success or failure.

Definition at line 1143 of file control_cmd.c.

References control_cmd_args_t::args, and tor_assert().

◆ handle_control_command()

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 2368 of file control_cmd.c.

References CONTROL_COMMANDS, control_printf_endreply(), control_connection_t::current_cmd, handle_single_control_command(), N_CONTROL_COMMANDS, control_cmd_def_t::name, and tor_assert().

◆ handle_control_del_onion()

static int handle_control_del_onion ( control_connection_t conn,
const control_cmd_args_t cmd_args 
)
static

Called when we get a DEL_ONION command; parse the body, and remove the existing ephemeral Onion Service.

Definition at line 2120 of file control_cmd.c.

References control_cmd_args_t::args, and tor_assert().

◆ handle_control_dropguards()

static int handle_control_dropguards ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Implementation for the DROPGUARDS command.

Definition at line 1361 of file control_cmd.c.

◆ handle_control_dropownership()

static int handle_control_dropownership ( control_connection_t conn,
const control_cmd_args_t args 
)
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 536 of file control_cmd.c.

References control_connection_t::is_owning_control_connection.

◆ handle_control_extendcircuit()

static int handle_control_extendcircuit ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get an EXTENDCIRCUIT message. Try to extend the listed circuit, and report success or failure.

Definition at line 740 of file control_cmd.c.

References CIRCUIT_PURPOSE_C_GENERAL, and control_cmd_args_t::kwargs.

◆ handle_control_getconf()

static int handle_control_getconf ( control_connection_t conn,
const control_cmd_args_t args 
)
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.

References control_cmd_args_t::args, option_get_assignment(), option_is_recognized(), smartlist_add(), and SMARTLIST_FOREACH_BEGIN.

◆ handle_control_hsfetch()

static int handle_control_hsfetch ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Implementation for the HSFETCH command.

Definition at line 1391 of file control_cmd.c.

References DIGEST_LEN.

◆ handle_control_hspost()

static int handle_control_hspost ( control_connection_t conn,
const control_cmd_args_t args 
)
static

◆ handle_control_loadconf()

static int handle_control_loadconf ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a +LOADCONF message.

Definition at line 353 of file control_cmd.c.

References control_cmd_args_t::cmddata, and options_init_from_string().

◆ handle_control_mapaddress()

static int handle_control_mapaddress ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a MAPADDRESS command; try to bind all listed addresses, and report success or failure.

Definition at line 649 of file control_cmd.c.

References address_is_invalid_mapaddress_target(), control_cmd_args_t::kwargs, and smartlist_add_asprintf().

◆ handle_control_obsolete()

static int handle_control_obsolete ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get an obsolete command: tell the controller that it is obsolete.

Definition at line 2203 of file control_cmd.c.

◆ handle_control_postdescriptor()

static int handle_control_postdescriptor ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a POSTDESCRIPTOR message. Try to learn the provided descriptor, and report success or failure.

Definition at line 1040 of file control_cmd.c.

References control_cmd_args_t::cmddata, config_line_find_case(), control_printf_endreply(), control_write_endreply(), control_cmd_args_t::kwargs, router_load_single_router(), router_purpose_from_string(), and send_control_done().

◆ handle_control_protocolinfo()

static int handle_control_protocolinfo ( control_connection_t conn,
const control_cmd_args_t cmd_args 
)
static

Called when we get a PROTOCOLINFO command: send back a reply.

Definition at line 1259 of file control_cmd.c.

References control_cmd_args_t::args, control_printf_endreply(), escaped(), control_connection_t::have_sent_protocolinfo, SMARTLIST_FOREACH, STATE_IS_OPEN, TO_CONN, and tor_parse_long().

◆ handle_control_redirectstream()

static int handle_control_redirectstream ( control_connection_t conn,
const control_cmd_args_t cmd_args 
)
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 1096 of file control_cmd.c.

References control_cmd_args_t::args, and get_stream().

◆ handle_control_resetconf()

static int handle_control_resetconf ( control_connection_t conn,
const control_cmd_args_t args 
)
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.

References control_setconf_helper().

◆ handle_control_resolve()

static int handle_control_resolve ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a RESOLVE command: start trying to resolve the listed addresses.

Definition at line 1214 of file control_cmd.c.

References control_connection_t::event_mask.

◆ handle_control_saveconf()

static int handle_control_saveconf ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a SAVECONF command. Try to flush the current options to disk, and report success or failure.

Definition at line 451 of file control_cmd.c.

References config_lines_contain_flag(), control_write_endreply(), or_options_t::IncludeUsed, control_cmd_args_t::kwargs, options_save_current(), and send_control_done().

◆ handle_control_setcircuitpurpose()

static int handle_control_setcircuitpurpose ( control_connection_t conn,
const control_cmd_args_t args 
)
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 901 of file control_cmd.c.

◆ handle_control_setconf()

static int handle_control_setconf ( control_connection_t conn,
const control_cmd_args_t args 
)
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.

References control_setconf_helper().

◆ handle_control_setevents()

static int handle_control_setevents ( control_connection_t conn,
const control_cmd_args_t args 
)
static

Called when we get a SETEVENTS message: update conn->event_mask, and reply with DONE or ERROR.

Definition at line 401 of file control_cmd.c.

References control_cmd_args_t::args, and SMARTLIST_FOREACH_BEGIN.

◆ handle_control_signal()

static int handle_control_signal ( control_connection_t conn,
const control_cmd_args_t args 
)
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 474 of file control_cmd.c.

References tor_assert().

◆ handle_control_takeownership()

static int handle_control_takeownership ( control_connection_t conn,
const control_cmd_args_t args 
)
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 513 of file control_cmd.c.

References control_connection_t::is_owning_control_connection.

◆ handle_control_usefeature()

static int handle_control_usefeature ( control_connection_t conn,
const control_cmd_args_t cmd_args 
)
static

Called when we get a USEFEATURE command: parse the feature list, and set up the control_connection's options properly.

Definition at line 1330 of file control_cmd.c.

References control_cmd_args_t::args, control_printf_endreply(), and SMARTLIST_FOREACH_BEGIN.

◆ handle_single_control_command()

static int handle_single_control_command ( const control_cmd_def_t def,
control_connection_t conn,
uint32_t  cmd_data_len,
char *  args 
)
static

Run a single control command, as defined by a control_cmd_def_t, with a given set of arguments.

Definition at line 2327 of file control_cmd.c.

References control_cmd_parse_args(), control_printf_endreply(), control_connection_t::current_cmd, control_cmd_def_t::syntax, tor_assert(), and tor_free.

Referenced by handle_control_command().

◆ kvline_check_keyword_args()

static int kvline_check_keyword_args ( const control_cmd_args_t result,
const control_cmd_syntax_t syntax,
char **  error_out 
)
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.

References control_cmd_syntax_t::allowed_keywords, escaped(), control_cmd_args_t::kwargs, string_array_contains_keyword(), and tor_asprintf().

◆ string_array_contains_keyword()

static bool string_array_contains_keyword ( const char **  array,
const char *  kwd 
)
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().

Variable Documentation

◆ add_onion_keywords

const char* add_onion_keywords[]
static
Initial value:
= {
"Port", "Flags", "MaxStreams", "ClientAuth", NULL
}

Definition at line 1645 of file control_cmd.c.

◆ add_onion_syntax

const control_cmd_syntax_t add_onion_syntax
static
Initial value:
= {
.min_args = 1, .max_args = 1,
.accept_keywords = true,
.allowed_keywords = add_onion_keywords
}

Definition at line 1648 of file control_cmd.c.

◆ attachstream_keywords

const char* attachstream_keywords[]
static
Initial value:
= {
"HOP", NULL
}

Definition at line 934 of file control_cmd.c.

◆ attachstream_syntax

const control_cmd_syntax_t attachstream_syntax
static
Initial value:
= {
.min_args=2, .max_args=2,
.accept_keywords=true,
.allowed_keywords=attachstream_keywords
}

Definition at line 937 of file control_cmd.c.

◆ closecircuit_syntax

const control_cmd_syntax_t closecircuit_syntax
static
Initial value:
= {
.min_args=1, .max_args=1,
.accept_keywords=true,
.kvline_flags=KV_OMIT_VALS,
}

Definition at line 1173 of file control_cmd.c.

◆ closestream_syntax

const control_cmd_syntax_t closestream_syntax
static
Initial value:
= {
.min_args = 2,
.max_args = UINT_MAX,
}

Definition at line 1134 of file control_cmd.c.

◆ CONTROL_COMMANDS

const control_cmd_def_t CONTROL_COMMANDS[]
static

An array defining all the recognized controller commands.

Definition at line 2284 of file control_cmd.c.

Referenced by handle_control_command().

◆ del_onion_syntax

const control_cmd_syntax_t del_onion_syntax
static
Initial value:
= {
.min_args = 1, .max_args = 1,
}

Definition at line 2113 of file control_cmd.c.

◆ detached_onion_services

smartlist_t* detached_onion_services = NULL
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 1634 of file control_cmd.c.

Referenced by get_detached_onion_services().

◆ dropguards_syntax

const control_cmd_syntax_t dropguards_syntax
static
Initial value:
= {
.max_args = 0,
}

Definition at line 1355 of file control_cmd.c.

◆ dropownership_syntax

const control_cmd_syntax_t dropownership_syntax
static
Initial value:
= {
.max_args = UINT_MAX,
}

Definition at line 528 of file control_cmd.c.

◆ extendcircuit_syntax

const control_cmd_syntax_t extendcircuit_syntax
static
Initial value:
= {
.min_args=1,
.max_args=1,
.accept_keywords=true,
.kvline_flags=KV_OMIT_VALS
}

Definition at line 730 of file control_cmd.c.

◆ getconf_syntax

const control_cmd_syntax_t getconf_syntax
static
Initial value:
= {
.max_args=UINT_MAX
}

Definition at line 278 of file control_cmd.c.

◆ hsfetch_keywords

const char* hsfetch_keywords[]
static
Initial value:
= {
"SERVER", NULL,
}

Definition at line 1380 of file control_cmd.c.

◆ hsfetch_syntax

const control_cmd_syntax_t hsfetch_syntax
static
Initial value:
= {
.min_args = 1, .max_args = 1,
.accept_keywords = true,
.allowed_keywords = hsfetch_keywords,
}

Definition at line 1383 of file control_cmd.c.

◆ hspost_keywords

const char* hspost_keywords[]
static
Initial value:
= {
"SERVER", "HSADDRESS", NULL
}

Definition at line 1485 of file control_cmd.c.

◆ hspost_syntax

const control_cmd_syntax_t hspost_syntax
static
Initial value:
= {
.min_args = 0, .max_args = 0,
.accept_keywords = true,
.want_cmddata = true,
.allowed_keywords = hspost_keywords
}

Definition at line 1488 of file control_cmd.c.

◆ loadconf_syntax

const control_cmd_syntax_t loadconf_syntax
static
Initial value:
= {
.want_cmddata = true
}

Definition at line 347 of file control_cmd.c.

◆ mapaddress_syntax

const control_cmd_syntax_t mapaddress_syntax
static
Initial value:
= {
.max_args=1,
.accept_keywords=true,
}

Definition at line 641 of file control_cmd.c.

◆ N_CONTROL_COMMANDS

const size_t N_CONTROL_COMMANDS = ARRAY_LENGTH(CONTROL_COMMANDS)
static

The number of entries in CONTROL_COMMANDS.

Definition at line 2320 of file control_cmd.c.

Referenced by handle_control_command().

◆ obsolete_syntax

const control_cmd_syntax_t obsolete_syntax
static
Initial value:
= {
.max_args = UINT_MAX
}

Definition at line 2194 of file control_cmd.c.

◆ postdescriptor_keywords

const char* postdescriptor_keywords[]
static
Initial value:
= {
"cache", "purpose", NULL,
}

Definition at line 1026 of file control_cmd.c.

◆ postdescriptor_syntax

const control_cmd_syntax_t postdescriptor_syntax
static
Initial value:
= {
.max_args = 0,
.accept_keywords = true,
.allowed_keywords = postdescriptor_keywords,
.want_cmddata = true,
}

Definition at line 1030 of file control_cmd.c.

◆ protocolinfo_syntax

const control_cmd_syntax_t protocolinfo_syntax
static
Initial value:
= {
.max_args = UINT_MAX
}

Definition at line 1253 of file control_cmd.c.

◆ redirectstream_syntax

const control_cmd_syntax_t redirectstream_syntax
static
Initial value:
= {
.min_args = 2,
.max_args = UINT_MAX,
}

Definition at line 1088 of file control_cmd.c.

◆ resetconf_syntax

const control_cmd_syntax_t resetconf_syntax
static
Initial value:
= {
.max_args=0,
.accept_keywords=true,
.kvline_flags=KV_OMIT_VALS|KV_QUOTED,
}

Definition at line 262 of file control_cmd.c.

◆ resolve_syntax

const control_cmd_syntax_t resolve_syntax
static
Initial value:
= {
.max_args=0,
.accept_keywords=true,
.kvline_flags=KV_OMIT_VALS,
}

Definition at line 1205 of file control_cmd.c.

◆ saveconf_syntax

const control_cmd_syntax_t saveconf_syntax
static
Initial value:
= {
.max_args = 0,
.accept_keywords = true,
.kvline_flags=KV_OMIT_VALS,
}

Definition at line 442 of file control_cmd.c.

◆ setcircuitpurpose_syntax

const control_cmd_syntax_t setcircuitpurpose_syntax
static
Initial value:
= {
.max_args=1,
.accept_keywords=true,
}

Definition at line 893 of file control_cmd.c.

◆ setconf_syntax

const control_cmd_syntax_t setconf_syntax
static
Initial value:
= {
.max_args=0,
.accept_keywords=true,
.kvline_flags=KV_OMIT_VALS|KV_QUOTED,
}

Definition at line 246 of file control_cmd.c.

◆ setevents_syntax

const control_cmd_syntax_t setevents_syntax
static
Initial value:
= {
.max_args = UINT_MAX
}

Definition at line 394 of file control_cmd.c.

◆ signal_syntax

const control_cmd_syntax_t signal_syntax
static
Initial value:
= {
.min_args = 1,
.max_args = 1,
}

Definition at line 465 of file control_cmd.c.

◆ takeownership_syntax

const control_cmd_syntax_t takeownership_syntax
static
Initial value:
= {
.max_args = UINT_MAX,
}

Definition at line 505 of file control_cmd.c.

◆ usefeature_syntax

const control_cmd_syntax_t usefeature_syntax
static
Initial value:
= {
.max_args = UINT_MAX
}

Definition at line 1323 of file control_cmd.c.