1 /* Copyright (c) 2001 Matej Pfajfar. 2 * Copyright (c) 2001-2004, Roger Dingledine. 3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. 4 * Copyright (c) 2007-2021, The Tor Project, Inc. */ 5 /* See LICENSE for licensing information */ 6 7 /** 8 * \file control_cmd.h 9 * \brief Header file for control_cmd.c. 10 **/ 11 12 #ifndef TOR_CONTROL_CMD_H 13 #define TOR_CONTROL_CMD_H 14 15 #include "lib/malloc/malloc.h" 16 17 int handle_control_command(control_connection_t *conn, 18 uint32_t cmd_data_len, 19 char *args); 20 void control_cmd_free_all(void); 21 22 typedef struct control_cmd_args_t control_cmd_args_t; 23 void control_cmd_args_free_(control_cmd_args_t *args); 24 void control_cmd_args_wipe(control_cmd_args_t *args); 25 26 #define control_cmd_args_free(v) \ 27 FREE_AND_NULL(control_cmd_args_t, control_cmd_args_free_, (v)) 28 29 /** 30 * Definition for the syntax of a controller command, as parsed by 31 * control_cmd_parse_args. 32 * 33 * WORK IN PROGRESS: This structure is going to get more complex as this 34 * branch goes on. 35 **/ 36 typedef struct control_cmd_syntax_t { 37 /** 38 * Lowest number of positional arguments that this command accepts. 39 * 0 for "it's okay not to have positional arguments." 40 **/ 41 unsigned int min_args; 42 /** 43 * Highest number of positional arguments that this command accepts. 44 * UINT_MAX for no limit. 45 **/ 46 unsigned int max_args; 47 /** 48 * If true, we should parse options after the positional arguments 49 * as a set of unordered flags and key=value arguments. 50 * 51 * Requires that max_args is not UINT_MAX. 52 **/ 53 bool accept_keywords; 54 /** 55 * If accept_keywords is true, then only the keywords listed in this 56 * (NULL-terminated) array are valid keywords for this command. 57 **/ 58 const char **allowed_keywords; 59 /** 60 * If accept_keywords is true, this option is passed to kvline_parse() as 61 * its flags. 62 **/ 63 unsigned kvline_flags; 64 /** 65 * True iff this command wants to be followed by a multiline object. 66 **/ 67 bool want_cmddata; 68 /** 69 * True iff this command needs access to the raw body of the input. 70 * 71 * This should not be needed for pure commands; it is purely a legacy 72 * option. 73 **/ 74 bool store_raw_body; 75 } control_cmd_syntax_t; 76 77 #ifdef CONTROL_CMD_PRIVATE 78 #include "feature/hs/hs_service.h" 79 #include "lib/crypt_ops/crypto_ed25519.h" 80 81 /* ADD_ONION secret key to create an ephemeral service. The command supports 82 * multiple versions so this union stores the key and passes it to the HS 83 * subsystem depending on the requested version. */ 84 typedef union add_onion_secret_key_t { 85 /* Hidden service v3 secret key. */ 86 ed25519_secret_key_t *v3; 87 } add_onion_secret_key_t; 88 89 STATIC int add_onion_helper_keyarg(const char *arg, int discard_pk, 90 const char **key_new_alg_out, 91 char **key_new_blob_out, 92 add_onion_secret_key_t *decoded_key, 93 int *hs_version, 94 control_connection_t *conn); 95 96 STATIC hs_service_add_ephemeral_status_t add_onion_helper_add_service( 97 int hs_version, 98 add_onion_secret_key_t *pk, 99 smartlist_t *port_cfgs, int max_streams, 100 int max_streams_close_circuit, 101 smartlist_t *auth_clients_v3, char **address_out); 102 103 STATIC control_cmd_args_t *control_cmd_parse_args( 104 const char *command, 105 const control_cmd_syntax_t *syntax, 106 size_t body_len, 107 const char *body, 108 char **error_out); 109 110 #endif /* defined(CONTROL_CMD_PRIVATE) */ 111 112 #ifdef CONTROL_MODULE_PRIVATE 113 smartlist_t * get_detached_onion_services(void); 114 #endif /* defined(CONTROL_MODULE_PRIVATE) */ 115 116 #endif /* !defined(TOR_CONTROL_CMD_H) */ 117