Update debian defaults in preparation for starting as root.

Previously the debian defaults were only loaded when we started Tor as
the debian-tor user.  Now they are also loaded when started as root.
In addition to logging, pidfile, datadir and runasdaemon we also change
the User and Group options from their NULL default to "debian-tor" so that
Tor correctly setuids/setgids to the role user the package created.

This will allow us to start the daemon as root.


svn:r13685
This commit is contained in:
Peter Palfrader 2008-02-23 12:59:52 +00:00
parent c3ac638971
commit c6a7ab729c
3 changed files with 32 additions and 15 deletions

12
debian/README.Debian vendored
View File

@ -1,14 +1,16 @@
This is the Debian package for Tor, The Onion Router.
Some changes have been made to the Tor source to integrate it better into
Debian. If Tor is started as the 'debian-tor' user, then:
Debian. If Tor is started as root or the 'debian-tor' user, then:
- RunAsDaemon is enabled by default.
- PidFile is set to /var/run/tor/tor.pid. No default upstream.
- default logging goes to /var/log/tor/log instead of stdout.
- DataDirectory is set to /var/lib/tor by default. Uses $HOME/.tor upstream.
- RunAsDaemon is enabled,
- PidFile is set to /var/run/tor/tor.pid (No default upstream),
- default logging goes to /var/log/tor/log (instead of stdout),
- DataDirectory is set to /var/lib/tor (uses $HOME/.tor upstream),
- User and Group are set to "debian-tor".
If Tor is started as any other user it behaves just like upstream's.
--
Peter Palfrader, Mon, 24 Jul 2006 05:20:30 +0200
Sat, 23 Feb 2008 13:44:40 +0100

5
debian/changelog vendored
View File

@ -10,8 +10,11 @@ tor (0.2.0.19-alpha+svn-1) unreleased; urgency=low
Big servers at the moment regularly use more than 10k FDs, so our old
default of 8k no longer is sufficient. On the other hand we don't want
lower end systems to run out of FDs on Tor's account.
* If we run as root also apply debian defaults.
* Add User=debian-tor and Group=debian-tor to debian defaults. That allows
us to start Tor as root and have it setuid/setgid to the target user.
-- Peter Palfrader <weasel@debian.org> Wed, 20 Feb 2008 23:38:45 +0100
-- Peter Palfrader <weasel@debian.org> Sat, 23 Feb 2008 13:44:56 +0100
tor (0.2.0.19-alpha-1) experimental; urgency=low

View File

@ -23,10 +23,10 @@ esac
exit 0
@DPATCH@
diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
--- tor-trunk/src/or/config.c 2007-04-29 04:11:46.261474906 +0200
+++ /tmp/dpep.YE8t73/tor-trunk/src/or/config.c 2007-04-29 04:12:24.827577276 +0200
@@ -14,6 +14,7 @@
diff -urNad trunk~/src/or/config.c trunk/src/or/config.c
--- trunk~/src/or/config.c 2008-02-23 11:08:40.000000000 +0100
+++ trunk/src/or/config.c 2008-02-23 13:43:05.000000000 +0100
@@ -15,6 +15,7 @@
#define CONFIG_PRIVATE
#include "or.h"
@ -34,7 +34,7 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
#ifdef MS_WINDOWS
#include <shlobj.h>
#endif
@@ -595,6 +596,8 @@
@@ -660,6 +661,8 @@
#if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD)
static void check_libevent_version(const char *m, int server);
#endif
@ -43,7 +43,7 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
/** Magic value for or_options_t. */
#define OR_OPTIONS_MAGIC 9090909
@@ -2991,7 +2994,7 @@
@@ -3522,7 +3525,7 @@
int
options_init_from_torrc(int argc, char **argv)
{
@ -52,7 +52,7 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
config_line_t *cl;
char *cf=NULL, *fname=NULL, *errmsg=NULL;
int i, retval;
@@ -3000,6 +3003,9 @@
@@ -3531,6 +3534,9 @@
static char **backup_argv;
static int backup_argc;
@ -62,7 +62,7 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
if (argv) { /* first time we're called. save commandline args */
backup_argv = argv;
backup_argc = argc;
@@ -3135,7 +3141,8 @@
@@ -3666,7 +3672,8 @@
err:
tor_free(fname);
torrc_fname = NULL;
@ -72,7 +72,7 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
if (errmsg) {
log(LOG_WARN,LD_CONFIG,"Failed to parse/validate config: %s", errmsg);
tor_free(errmsg);
@@ -4320,3 +4327,52 @@
@@ -5011,3 +5018,64 @@
puts(routerparse_c_id);
}
@ -85,6 +85,10 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
+ int uid;
+
+ uid = getuid();
+ /* If we run as root we also apply our debian defaults. */
+ if (uid == 0)
+ return 1;
+
+ pw = getpwuid(uid);
+ if (!pw) {
+ log(LOG_WARN, LD_GENERAL, "Could not get passwd information for uid %d.", uid);
@ -123,5 +127,13 @@ diff -urNad tor-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
+ tor_assert(var);
+ var->initvalue = tor_strdup("1");
+
+ var = config_find_option(&options_format, "User");
+ tor_assert(var);
+ var->initvalue = tor_strdup("debian-tor");
+
+ var = config_find_option(&options_format, "Group");
+ tor_assert(var);
+ var->initvalue = tor_strdup("debian-tor");
+
+ return 0;
+}