aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-10-30 19:18:37 +0000
committerNick Mathewson <nickm@torproject.org>2004-10-30 19:18:37 +0000
commit9510d9a79286d4baf3f3bd8ee69ae5ff422f9735 (patch)
tree4ae1e51c64b5612bd8c340b78817fa1ab6259f35 /src
parent80f43a8c6e2c297de165333c2cfe6ec9c5213fe2 (diff)
downloadtor-9510d9a79286d4baf3f3bd8ee69ae5ff422f9735.tar.gz
tor-9510d9a79286d4baf3f3bd8ee69ae5ff422f9735.zip
tor --list-fingerprint to print fingerprint and exit
svn:r2627
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c28
-rw-r--r--src/or/main.c39
-rw-r--r--src/or/or.h4
3 files changed, 60 insertions, 11 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 7b366f5593..7dd83aa8dc 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -184,6 +184,8 @@ config_get_commandlines(int argc, char **argv)
// log(LOG_DEBUG,"Commandline: skipping over -f.");
i += 2; /* this is the config file option. ignore it. */
continue;
+ } else if (!strcmp(argv[i],"--list-fingerprint")) {
+ i += 1; /* command-line option. ignore it. */
}
new = tor_malloc(sizeof(struct config_line_t));
@@ -726,19 +728,27 @@ getconfig(int argc, char **argv, or_options_t *options)
exit(0);
}
-/* learn config file name, get config lines, assign them */
- i = 1;
- while (i < argc-1 && strcmp(argv[i],"-f")) {
- i++;
+ /* learn config file name, get config lines, assign them */
+ fname = NULL;
+ using_default_torrc = 1;
+ options->command = CMD_RUN_TOR;
+ for (i = 1; i < argc; ++i) {
+ if (i < argc-1 && !strcmp(argv[i],"-f")) {
+ if (fname) {
+ log(LOG_WARN, "Duplicate -f options on command line.");
+ tor_free(fname);
+ }
+ fname = tor_strdup(argv[i+1]);
+ using_default_torrc = 0;
+ ++i;
+ } else if (!strcmp(argv[i],"--list-fingerprint")) {
+ options->command = CMD_LIST_FINGERPRINT;
+ }
}
- if (i < argc-1) { /* we found one */
- fname = tor_strdup(argv[i+1]);
- using_default_torrc = 0;
- } else {
+ if (using_default_torrc) {
/* didn't find one, try CONFDIR */
char *fn;
- using_default_torrc = 1;
fn = get_default_conf_file();
if (fn && file_status(fn) == FN_FILE) {
fname = fn;
diff --git a/src/or/main.c b/src/or/main.c
index a85ab53afb..b0b9792f56 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -706,6 +706,11 @@ static int init_from_config(int argc, char **argv) {
return -1;
}
+ /* Bail out at this point if we're not going to be a server: we want
+ * to not fork, and to log stuff to stderr. */
+ if (options.command != CMD_RUN_TOR)
+ return 0;
+
/* Configure the log(s) */
if (config_init_logs(&options)<0)
return -1;
@@ -1095,11 +1100,31 @@ static int tor_init(int argc, char *argv[]) {
void tor_cleanup(void) {
/* Remove our pid file. We don't care if there was an error when we
* unlink, nothing we could do about it anyways. */
- if(options.PidFile)
+ if(options.PidFile && options.command == CMD_RUN_TOR)
unlink(options.PidFile);
crypto_global_cleanup();
}
+/** Read/create keys as needed, and echo our fingerprint to stdout. */
+void do_list_fingerprint(void)
+{
+ char buf[FINGERPRINT_LEN+1];
+ crypto_pk_env_t *k;
+ if (init_keys() < 0) {
+ log_fn(LOG_ERR,"Error initializing keys; exiting");
+ return;
+ }
+ if (!(k = get_identity_key())) {
+ log_fn(LOG_ERR,"Error: missing identity key.");
+ return;
+ }
+ if (crypto_pk_get_fingerprint(k, buf, 1)<0) {
+ log_fn(LOG_ERR, "Error computing fingerprint");
+ return;
+ }
+ printf("%s %s\n", options.Nickname, buf);
+}
+
#ifdef MS_WINDOWS_SERVICE
void nt_service_control(DWORD request)
{
@@ -1169,7 +1194,17 @@ int tor_main(int argc, char *argv[]) {
#else
if (tor_init(argc, argv)<0)
return -1;
- do_main_loop();
+ switch (options.command) {
+ case CMD_RUN_TOR:
+ do_main_loop();
+ break;
+ case CMD_LIST_FINGERPRINT:
+ do_list_fingerprint();
+ break;
+ default:
+ log_fn(LOG_ERR, "Illegal command number %d: internal error.",
+ options.command);
+ }
tor_cleanup();
return -1;
#endif
diff --git a/src/or/or.h b/src/or/or.h
index 4f2aee9c40..6a36516f66 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -832,6 +832,10 @@ typedef struct exit_redirect_t {
/** Configuration options for a Tor process */
typedef struct {
+ /** What should the tor process actually do? */
+ enum {
+ CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT
+ } command;
struct config_line_t *LogOptions; /**< List of configuration lines
* for logfiles */