06_add_compile_time_defaults.dpatch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-trunk/src/or/config.c /tmp/dpep.YE8t73/tor-trunk/src/or/config.c
  22. --- tor-trunk/src/or/config.c 2007-04-29 04:11:46.261474906 +0200
  23. +++ /tmp/dpep.YE8t73/tor-trunk/src/or/config.c 2007-04-29 04:12:24.827577276 +0200
  24. @@ -14,6 +14,7 @@
  25. #define CONFIG_PRIVATE
  26. #include "or.h"
  27. +#include <pwd.h>
  28. #ifdef MS_WINDOWS
  29. #include <shlobj.h>
  30. #endif
  31. @@ -595,6 +596,8 @@
  32. #if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD)
  33. static void check_libevent_version(const char *m, int server);
  34. #endif
  35. +static int debian_running_as_debiantor();
  36. +static int debian_config_fix_defaults();
  37. /** Magic value for or_options_t. */
  38. #define OR_OPTIONS_MAGIC 9090909
  39. @@ -2991,7 +2994,7 @@
  40. int
  41. options_init_from_torrc(int argc, char **argv)
  42. {
  43. - or_options_t *oldoptions, *newoptions;
  44. + or_options_t *oldoptions, *newoptions = NULL;
  45. config_line_t *cl;
  46. char *cf=NULL, *fname=NULL, *errmsg=NULL;
  47. int i, retval;
  48. @@ -3000,6 +3003,9 @@
  49. static char **backup_argv;
  50. static int backup_argc;
  51. + if (debian_config_fix_defaults() < 0)
  52. + goto err;
  53. +
  54. if (argv) { /* first time we're called. save commandline args */
  55. backup_argv = argv;
  56. backup_argc = argc;
  57. @@ -3135,7 +3141,8 @@
  58. err:
  59. tor_free(fname);
  60. torrc_fname = NULL;
  61. - config_free(&options_format, newoptions);
  62. + if (newoptions)
  63. + config_free(&options_format, newoptions);
  64. if (errmsg) {
  65. log(LOG_WARN,LD_CONFIG,"Failed to parse/validate config: %s", errmsg);
  66. tor_free(errmsg);
  67. @@ -4320,3 +4327,52 @@
  68. puts(routerparse_c_id);
  69. }
  70. +/* Checks whether we are running as the debian-tor user.
  71. + * Returns -1 on error, 1 if we are debian-tor, 0 if not */
  72. +static int
  73. +debian_running_as_debiantor()
  74. +{
  75. + struct passwd *pw = NULL;
  76. + int uid;
  77. +
  78. + uid = getuid();
  79. + pw = getpwuid(uid);
  80. + if (!pw) {
  81. + log(LOG_WARN, LD_GENERAL, "Could not get passwd information for uid %d.", uid);
  82. + return -1;
  83. + }
  84. + assert(pw->pw_name);
  85. + if (strcmp(pw->pw_name, "debian-tor") == 0)
  86. + return 1;
  87. + else
  88. + return 0;
  89. +}
  90. +
  91. +static int
  92. +debian_config_fix_defaults()
  93. +{
  94. + config_var_t *var;
  95. + static int fixed = 0;
  96. + int running_as_debian;
  97. +
  98. + if (fixed) return 0;
  99. + fixed = 1;
  100. +
  101. + running_as_debian = debian_running_as_debiantor();
  102. + if (running_as_debian < 0) return -1;
  103. + if (!running_as_debian) return 0;
  104. +
  105. + var = config_find_option(&options_format, "DataDirectory");
  106. + tor_assert(var);
  107. + var->initvalue = tor_strdup("/var/lib/tor");
  108. +
  109. + var = config_find_option(&options_format, "PidFile");
  110. + tor_assert(var);
  111. + var->initvalue = tor_strdup("/var/run/tor/tor.pid");
  112. +
  113. + var = config_find_option(&options_format, "RunAsDaemon");
  114. + tor_assert(var);
  115. + var->initvalue = tor_strdup("1");
  116. +
  117. + return 0;
  118. +}