From fe328d192e76324ab788436318000ed1f20f8786 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sun, 25 Jan 2015 16:42:42 +0200 Subject: [PATCH 1/3] Allow reading torrc from stdin. --- src/or/config.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/or/config.c b/src/or/config.c index 568baec703..3ff60e5fc5 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4204,6 +4204,17 @@ find_torrc_filename(config_line_t *cmd_arg, return fname; } +/** Read the torrc from standard input and return it as a string. + * Upon failure, return NULL. + */ +static char * +load_torrc_from_stdin(config_line_t *cmd_arg) +{ + size_t sz_out; + + return read_file_to_str_until_eof(STDIN_FILENO,SIZE_MAX,&sz_out); +} + /** Load a configuration file from disk, setting torrc_fname or * torrc_defaults_fname if successful. * @@ -4344,7 +4355,19 @@ options_init_from_torrc(int argc, char **argv) cf = tor_strdup(""); } else { cf_defaults = load_torrc_from_disk(cmdline_only_options, 1); - cf = load_torrc_from_disk(cmdline_only_options, 0); + + const config_line_t *f_line = config_line_find(cmdline_only_options, + "-f"); + + const int read_torrc_from_stdin = + (f_line != NULL && strcmp(f_line->value, "-") == 0); + + if (read_torrc_from_stdin) { + cf = load_torrc_from_stdin(cmdline_only_options); + } else { + cf = load_torrc_from_disk(cmdline_only_options, 0); + } + if (!cf) { if (config_line_find(cmdline_only_options, "--allow-missing-torrc")) { cf = tor_strdup(""); From 313e2a7dabbe9cc32c9db231cf5c97dee77cdea9 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 26 Jan 2015 21:23:42 +0200 Subject: [PATCH 2/3] Changes file for 13865. --- changes/feature13865 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/feature13865 diff --git a/changes/feature13865 b/changes/feature13865 new file mode 100644 index 0000000000..48291b4248 --- /dev/null +++ b/changes/feature13865 @@ -0,0 +1,5 @@ + o Minor features: + - Implement '-f -' CLI suboption to allow torrc to be read + from standard input, thus not requiring to store torrc in file + system. Implements feature 13865. + From 1ebed7cc7758fdfc3786ef9c1edfa4388f43e8e2 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 26 Jan 2015 21:33:19 +0200 Subject: [PATCH 3/3] Updating manpage for 13865. --- doc/tor.1.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/tor.1.txt b/doc/tor.1.txt index 5302b33bd1..4d7069ee23 100644 --- a/doc/tor.1.txt +++ b/doc/tor.1.txt @@ -42,7 +42,8 @@ COMMAND-LINE OPTIONS [[opt-f]] **-f** __FILE__:: Specify a new configuration file to contain further Tor configuration - options. (Default: @CONFDIR@/torrc, or $HOME/.torrc if that file is not + options OR pass *-* to make Tor read its configuration from standard + input. (Default: @CONFDIR@/torrc, or $HOME/.torrc if that file is not found) [[opt-allow-missing-torrc]] **--allow-missing-torrc**::