From 337fdb7eb6b78f78449d496f1b5ab6a4eb67cd1e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 5 Feb 2007 20:45:02 +0000 Subject: [PATCH] r11643@catbus: nickm | 2007-02-05 15:44:59 -0500 Fix bug 254, sort of: make the default NT service user NetworkService rather than NULL (system). Also, add a --user argument to --service install so that admins can override this default: this latter point should take care of most of my objections to NetworkService. I have no idea whether this even compiles. svn:r9486 --- ChangeLog | 6 ++++++ src/or/main.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b29904635..cbcc482140 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,12 @@ Changes in version 0.1.2.7-alpha - 2007-??-?? writing to them, so we avoid queueing 4+ megabytes of data before trying to flush. + o Major bugfixes (NT services): + - Install as NT_AUTHORITY\NetworkService rather than as SYSTEM; add a + command-line flag so that admins can override the default by saying + "tor --service install --user "SomeUser"". This will not effect + existing installed services. + o Major bugfixes (other): - Fix a crash bug in the presence of DNS hijacking (reported by Andrew Del Vecchio). diff --git a/src/or/main.c b/src/or/main.c index bd7de8ea2d..61f49c5693 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -77,6 +77,7 @@ int has_completed_circuit=0; #define GENSRV_DISPLAYNAME TEXT("Tor Win32 Service") #define GENSRV_DESCRIPTION \ TEXT("Provides an anonymous Internet communication system") +#define GENSRV_USERACCT TEXT("NT AUTHORITY\\NetworkService") // Cheating: using the pre-defined error codes, tricks Windows into displaying // a semi-related human-readable error message if startup fails as @@ -2128,7 +2129,7 @@ nt_service_command_line(void) * started if installation succeeds. Returns 0 on success, or -1 on * failure. */ int -nt_service_install(void) +nt_service_install(int argc, char **argv) { /* Notes about developing NT services: * @@ -2143,7 +2144,8 @@ nt_service_install(void) SERVICE_DESCRIPTION sdBuff; char *command; char *errmsg; - int len = 0; + const char *user_acct = GENSRV_USERACCT; + int i; if (nt_service_loadlibrary()<0) return -1; @@ -2157,6 +2159,12 @@ nt_service_install(void) service_fns.CloseServiceHandle_fn(hSCManager); return -1; } + for (i=1; i < argc, ++i) { + if (!strcmp(i, "--user") && i+1= 2) { if (nt_service_loadlibrary() < 0) { printf("Unable to load library support for NT services.\n"); return -1; } - if (!strcmp(argv[1], "-install") || !strcmp(argv[1], "--install")) - return nt_service_install(); - if (!strcmp(argv[1], "-remove") || !strcmp(argv[1], "--remove")) - return nt_service_remove(); if (!strcmp(argv[1], "-nt-service") || !strcmp(argv[1], "--nt-service")) { nt_service_main(); return 0; } + // These values have been deprecated since 0.1.1.2-alpha; we've warned + // about them since 0.1.2.7-alpha. + if (!strcmp(argv[1], "-install") || !strcmp(argv[1], "--install")) { + fprintf(stderr, + "The %s option is deprecated; use \"--service install\" instead.", + argv[1]); + return nt_service_install(); + } + if (!strcmp(argv[1], "-remove") || !strcmp(argv[1], "--remove")) { + fprintf(stderr, + "The %s option is deprecated; use \"--service remove\" instead.", + argv[1]); + return nt_service_remove(); + } } #endif if (tor_init(argc, argv)<0)