123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #! /bin/sh -e
- ## 06_add_compile_time_defaults.dpatch by <weasel@debian.org>
- ##
- ## All lines beginning with `## DP:' are a description of the patch.
- ## DP: No description.
- if [ $# -lt 1 ]; then
- echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
- exit 1
- fi
- [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
- patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
- case "$1" in
- -patch) patch -p1 ${patch_opts} < $0;;
- -unpatch) patch -R -p1 ${patch_opts} < $0;;
- *)
- echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
- exit 1;;
- esac
- exit 0
- @DPATCH@
- diff -urNad tor-debian~/src/or/config.c tor-debian/src/or/config.c
- --- tor-debian~/src/or/config.c 2007-03-06 21:52:33.000000000 +0100
- +++ tor-debian/src/or/config.c 2007-04-27 13:05:42.420147495 +0200
- @@ -12,6 +12,7 @@
- **/
-
- #include "or.h"
- +#include <pwd.h>
- #ifdef MS_WINDOWS
- #include <shlobj.h>
- #endif
- @@ -592,6 +593,10 @@
- static void check_libevent_version(const char *m, int server);
- #endif
-
- +static int debian_running_as_debiantor();
- +static int debian_config_fix_defaults();
- +
- +
- /*static*/ or_options_t *options_new(void);
-
- /** Magic value for or_options_t. */
- @@ -2982,7 +2987,7 @@
- int
- options_init_from_torrc(int argc, char **argv)
- {
- - or_options_t *oldoptions, *newoptions;
- + or_options_t *oldoptions, *newoptions = NULL;
- config_line_t *cl;
- char *cf=NULL, *fname=NULL, *errmsg=NULL;
- int i, retval;
- @@ -2991,6 +2996,9 @@
- static char **backup_argv;
- static int backup_argc;
-
- + if (debian_config_fix_defaults() < 0)
- + goto err;
- +
- if (argv) { /* first time we're called. save commandline args */
- backup_argv = argv;
- backup_argc = argc;
- @@ -3120,7 +3128,8 @@
- err:
- tor_free(fname);
- torrc_fname = NULL;
- - config_free(&options_format, newoptions);
- + if (newoptions)
- + config_free(&options_format, newoptions);
- if (errmsg) {
- log(LOG_WARN,LD_CONFIG,"Failed to parse/validate config: %s", errmsg);
- tor_free(errmsg);
- @@ -4306,3 +4315,52 @@
- puts(routerparse_c_id);
- }
-
- +/* Checks whether we are running as the debian-tor user.
- + * Returns -1 on error, 1 if we are debian-tor, 0 if not */
- +static int
- +debian_running_as_debiantor()
- +{
- + struct passwd *pw = NULL;
- + int uid;
- +
- + uid = getuid();
- + pw = getpwuid(uid);
- + if (!pw) {
- + log(LOG_WARN, LD_GENERAL, "Could not get passwd information for uid %d.", uid);
- + return -1;
- + }
- + assert(pw->pw_name);
- + if (strcmp(pw->pw_name, "debian-tor") == 0)
- + return 1;
- + else
- + return 0;
- +}
- +
- +static int
- +debian_config_fix_defaults()
- +{
- + config_var_t *var;
- + static int fixed = 0;
- + int running_as_debian;
- +
- + if (fixed) return 0;
- + fixed = 1;
- +
- + running_as_debian = debian_running_as_debiantor();
- + if (running_as_debian < 0) return -1;
- + if (!running_as_debian) return 0;
- +
- + var = config_find_option(&options_format, "DataDirectory");
- + tor_assert(var);
- + var->initvalue = tor_strdup("/var/lib/tor");
- +
- + var = config_find_option(&options_format, "PidFile");
- + tor_assert(var);
- + var->initvalue = tor_strdup("/var/run/tor/tor.pid");
- +
- + var = config_find_option(&options_format, "RunAsDaemon");
- + tor_assert(var);
- + var->initvalue = tor_strdup("1");
- +
- + return 0;
- +}
|