control_cmd.h 3.7 KB

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