06_add_compile_time_defaults.dpatch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #! /bin/sh -e
  2. ## 06_add_compile_time_defaults.dpatch by <weasel@debian.org>
  3. ##
  4. ## All lines beginning with `## DP:' are a description of the patch.
  5. ## DP: No description.
  6. if [ $# -lt 1 ]; then
  7. echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
  8. exit 1
  9. fi
  10. [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
  11. patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
  12. case "$1" in
  13. -patch) patch -p1 ${patch_opts} < $0;;
  14. -unpatch) patch -R -p1 ${patch_opts} < $0;;
  15. *)
  16. echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
  17. exit 1;;
  18. esac
  19. exit 0
  20. @DPATCH@
  21. diff -urNad tor~/src/or/config.c tor/src/or/config.c
  22. --- tor~/src/or/config.c 2006-07-23 19:31:29.000000000 +0200
  23. +++ tor/src/or/config.c 2006-07-24 05:13:19.924871985 +0200
  24. @@ -12,6 +12,7 @@
  25. **/
  26. #include "or.h"
  27. +#include <pwd.h>
  28. #ifdef MS_WINDOWS
  29. #include <shlobj.h>
  30. #endif
  31. @@ -396,6 +397,10 @@
  32. static void check_libevent_version(const char *m, const char *v, int server);
  33. #endif
  34. +static int debian_running_as_debiantor();
  35. +static int debian_config_fix_defaults();
  36. +
  37. +
  38. /*static*/ or_options_t *options_new(void);
  39. #define OR_OPTIONS_MAGIC 9090909
  40. @@ -2663,7 +2668,7 @@
  41. int
  42. options_init_from_torrc(int argc, char **argv)
  43. {
  44. - or_options_t *oldoptions, *newoptions;
  45. + or_options_t *oldoptions, *newoptions = NULL;
  46. config_line_t *cl;
  47. char *cf=NULL, *fname=NULL, *errmsg=NULL;
  48. int i, retval;
  49. @@ -2671,6 +2676,9 @@
  50. static char **backup_argv;
  51. static int backup_argc;
  52. + if (debian_config_fix_defaults() < 0)
  53. + goto err;
  54. +
  55. if (argv) { /* first time we're called. save commandline args */
  56. backup_argv = argv;
  57. backup_argc = argc;
  58. @@ -3948,3 +3956,52 @@
  59. puts(routerparse_c_id);
  60. }
  61. +/* Checks whether we are running as the debian-tor user.
  62. + * Returns -1 on error, 1 if we are debian-tor, 0 if not */
  63. +static int
  64. +debian_running_as_debiantor()
  65. +{
  66. + struct passwd *pw = NULL;
  67. + int uid;
  68. +
  69. + uid = getuid();
  70. + pw = getpwuid(uid);
  71. + if (!pw) {
  72. + log(LOG_WARN, LD_GENERAL, "Could not get passwd information for %d.", uid);
  73. + return -1;
  74. + }
  75. + assert(pw->pw_name);
  76. + if (strcmp(pw->pw_name, "debian-tor") == 0)
  77. + return 1;
  78. + else
  79. + return 0;
  80. +}
  81. +
  82. +static int
  83. +debian_config_fix_defaults()
  84. +{
  85. + config_var_t *var;
  86. + static int fixed = 0;
  87. + int running_as_debian;
  88. +
  89. + if (fixed) return 0;
  90. + fixed = 1;
  91. +
  92. + running_as_debian = debian_running_as_debiantor();
  93. + if (running_as_debian < 0) return -1;
  94. + if (!running_as_debian) return 0;
  95. +
  96. + var = config_find_option(&options_format, "DataDirectory");
  97. + tor_assert(var);
  98. + var->initvalue = tor_strdup("/var/lib/tor");
  99. +
  100. + var = config_find_option(&options_format, "PidFile");
  101. + tor_assert(var);
  102. + var->initvalue = tor_strdup("/var/run/tor/tor.pid");
  103. +
  104. + var = config_find_option(&options_format, "RunAsDaemon");
  105. + tor_assert(var);
  106. + var->initvalue = tor_strdup("1");
  107. +
  108. + return 0;
  109. +}