control_cmd.h 3.6 KB

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