summaryrefslogtreecommitdiff
path: root/trunk/debian/patches/06_add_compile_time_defaults.dpatch
blob: 8b4e494246f504e334ce4b4df63cfef92f3cd14c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /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~/src/or/config.c tor/src/or/config.c
--- tor~/src/or/config.c	2006-07-23 19:31:29.000000000 +0200
+++ tor/src/or/config.c	2006-07-24 05:13:19.924871985 +0200
@@ -12,6 +12,7 @@
  **/
 
 #include "or.h"
+#include <pwd.h>
 #ifdef MS_WINDOWS
 #include <shlobj.h>
 #endif
@@ -396,6 +397,10 @@
 static void check_libevent_version(const char *m, const char *v, int server);
 #endif
 
+static int debian_running_as_debiantor();
+static int debian_config_fix_defaults();
+
+
 /*static*/ or_options_t *options_new(void);
 
 #define OR_OPTIONS_MAGIC 9090909
@@ -2663,7 +2668,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;
@@ -2671,6 +2676,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;
@@ -3948,3 +3956,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 %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;
+}