config.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. /**
  5. * /file config.c
  6. *
  7. * /brief Code to parse and interpret configuration files.
  8. *
  9. **/
  10. #include "or.h"
  11. /** Enumeration of types which option values can take */
  12. typedef enum config_type_t {
  13. CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
  14. CONFIG_TYPE_INT, /**< An integer */
  15. CONFIG_TYPE_DOUBLE, /**< A floating-point value */
  16. CONFIG_TYPE_BOOL, /**< A boolean value, expressed as 0 or 1. */
  17. CONFIG_TYPE_CSV, /**< A list of strings, separated by commas and optional
  18. * whitespace. */
  19. CONFIG_TYPE_LINELIST, /**< Uninterpreted config lines */
  20. } config_type_t;
  21. /** Largest allowed config line */
  22. #define CONFIG_LINE_T_MAXLEN 4096
  23. static FILE *config_open(const unsigned char *filename);
  24. static int config_close(FILE *f);
  25. static struct config_line_t *config_get_commandlines(int argc, char **argv);
  26. static struct config_line_t *config_get_lines(FILE *f);
  27. static void config_free_lines(struct config_line_t *front);
  28. static int config_compare(struct config_line_t *c, const char *key, config_type_t type, void *arg);
  29. static int config_assign(or_options_t *options, struct config_line_t *list);
  30. /** Open a configuration file for reading */
  31. static FILE *config_open(const unsigned char *filename) {
  32. tor_assert(filename);
  33. if (strspn(filename,CONFIG_LEGAL_FILENAME_CHARACTERS) != strlen(filename)) {
  34. /* filename has illegal letters */
  35. return NULL;
  36. }
  37. return fopen(filename, "r");
  38. }
  39. /** Close the configuration file */
  40. static int config_close(FILE *f) {
  41. tor_assert(f);
  42. return fclose(f);
  43. }
  44. /** Helper: Read a list of configuration options from the command line. */
  45. static struct config_line_t *config_get_commandlines(int argc, char **argv) {
  46. struct config_line_t *new;
  47. struct config_line_t *front = NULL;
  48. char *s;
  49. int i = 1;
  50. while(i < argc-1) {
  51. if(!strcmp(argv[i],"-f")) {
  52. // log(LOG_DEBUG,"Commandline: skipping over -f.");
  53. i+=2; /* this is the config file option. ignore it. */
  54. continue;
  55. }
  56. new = tor_malloc(sizeof(struct config_line_t));
  57. s = argv[i];
  58. while(*s == '-')
  59. s++;
  60. new->key = tor_strdup(s);
  61. new->value = tor_strdup(argv[i+1]);
  62. log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
  63. new->key, new->value);
  64. new->next = front;
  65. front = new;
  66. i += 2;
  67. }
  68. return front;
  69. }
  70. /** Helper: allocate a new configuration option mapping 'key' to 'val',
  71. * prepend it to 'front', and return the newly allocated config_line_t */
  72. static struct config_line_t *
  73. config_line_prepend(struct config_line_t *front,
  74. const char *key,
  75. const char *val)
  76. {
  77. struct config_line_t *newline;
  78. newline = tor_malloc(sizeof(struct config_line_t));
  79. newline->key = tor_strdup(key);
  80. newline->value = tor_strdup(val);
  81. newline->next = front;
  82. return newline;
  83. }
  84. /** Helper: parse the config file and strdup into key/value
  85. * strings. Return list, or NULL if parsing the file failed. Warn and
  86. * ignore any misformatted lines. */
  87. static struct config_line_t *config_get_lines(FILE *f) {
  88. struct config_line_t *front = NULL;
  89. char line[CONFIG_LINE_T_MAXLEN];
  90. int result;
  91. char *key, *value;
  92. while( (result=parse_line_from_file(line,sizeof(line),f,&key,&value)) > 0) {
  93. front = config_line_prepend(front, key, value);
  94. }
  95. if(result < 0)
  96. return NULL;
  97. return front;
  98. }
  99. /**
  100. * Free all the configuration lines on the linked list <b>front</b>.
  101. */
  102. static void config_free_lines(struct config_line_t *front) {
  103. struct config_line_t *tmp;
  104. while(front) {
  105. tmp = front;
  106. front = tmp->next;
  107. free(tmp->key);
  108. free(tmp->value);
  109. free(tmp);
  110. }
  111. }
  112. /**
  113. * Given a list of comma-separated entries, each surrounded by optional
  114. * whitespace, insert copies of the entries (in order) into lst, without
  115. * their surrounding whitespace.
  116. */
  117. static void parse_csv_into_smartlist(smartlist_t *lst, const char *val)
  118. {
  119. const char *cp, *start, *end;
  120. cp = val;
  121. while (1) {
  122. while (isspace(*cp))
  123. ++cp;
  124. start = cp;
  125. end = strchr(cp, ',');
  126. if (!end)
  127. end = strchr(cp, '\0');
  128. for (cp=end-1; cp>=start && isspace(*cp); --cp)
  129. ;
  130. /* Now start points to the first nonspace character of an entry,
  131. * end points to the terminator of that entry,
  132. * and cp points to the last nonspace character of an entry. */
  133. tor_assert(start <= cp);
  134. tor_assert(cp <= end);
  135. tor_assert(*end == '\0' || *end == ',');
  136. tor_assert((!isspace(*start) && !isspace(*cp)) || start==cp);
  137. smartlist_add(lst, tor_strndup(start, cp-start));
  138. if (!*end)
  139. break;
  140. cp = end+1;
  141. }
  142. }
  143. /** Search the linked list <b>c</b> for any option whose key is <b>key</b>.
  144. * If such an option is found, interpret it as of type <b>type</b>, and store
  145. * the result in <b>arg</b>. If the option is misformatted, log a warning and
  146. * skip it.
  147. */
  148. static int config_compare(struct config_line_t *c, const char *key, config_type_t type, void *arg) {
  149. int i;
  150. if(strncasecmp(c->key,key,strlen(c->key)))
  151. return 0;
  152. if(strcasecmp(c->key,key)) {
  153. tor_free(c->key);
  154. c->key = tor_strdup(key);
  155. }
  156. /* it's a match. cast and assign. */
  157. log_fn(LOG_DEBUG,"Recognized keyword '%s' as %s, using value '%s'.",c->key,key,c->value);
  158. switch(type) {
  159. case CONFIG_TYPE_INT:
  160. *(int *)arg = atoi(c->value);
  161. break;
  162. case CONFIG_TYPE_BOOL:
  163. i = atoi(c->value);
  164. if (i != 0 && i != 1) {
  165. log(LOG_WARN, "Boolean keyword '%s' expects 0 or 1", c->key);
  166. return 0;
  167. }
  168. *(int *)arg = i;
  169. break;
  170. case CONFIG_TYPE_STRING:
  171. tor_free(*(char **)arg);
  172. *(char **)arg = tor_strdup(c->value);
  173. break;
  174. case CONFIG_TYPE_DOUBLE:
  175. *(double *)arg = atof(c->value);
  176. break;
  177. case CONFIG_TYPE_CSV:
  178. if(*(smartlist_t**)arg == NULL)
  179. *(smartlist_t**)arg = smartlist_create();
  180. parse_csv_into_smartlist(*(smartlist_t**)arg, c->value);
  181. break;
  182. case CONFIG_TYPE_LINELIST:
  183. /* Note: this reverses the order that the lines appear in. That's
  184. * just fine, since we build up the list of lines reversed in the
  185. * first place. */
  186. *(struct config_line_t**)arg =
  187. config_line_prepend(*(struct config_line_t**)arg, c->key, c->value);
  188. break;
  189. }
  190. return 1;
  191. }
  192. /** Iterate through the linked list of options <b>list</b>.
  193. * For each item, convert as appropriate and assign to <b>options</b>.
  194. * If an item is unrecognized, return -1 immediately,
  195. * else return 0 for success. */
  196. static int config_assign(or_options_t *options, struct config_line_t *list) {
  197. while(list) {
  198. if(
  199. /* order matters here! abbreviated arguments use the first match. */
  200. /* string options */
  201. config_compare(list, "Address", CONFIG_TYPE_STRING, &options->Address) ||
  202. config_compare(list, "AllowUnverifiedNodes", CONFIG_TYPE_CSV, &options->AllowUnverifiedNodes) ||
  203. config_compare(list, "AuthoritativeDirectory",CONFIG_TYPE_BOOL, &options->AuthoritativeDir) ||
  204. config_compare(list, "BandwidthRate", CONFIG_TYPE_INT, &options->BandwidthRate) ||
  205. config_compare(list, "BandwidthBurst", CONFIG_TYPE_INT, &options->BandwidthBurst) ||
  206. config_compare(list, "ClientOnly", CONFIG_TYPE_BOOL, &options->ClientOnly) ||
  207. config_compare(list, "ContactInfo", CONFIG_TYPE_STRING, &options->ContactInfo) ||
  208. config_compare(list, "DebugLogFile", CONFIG_TYPE_STRING, &options->DebugLogFile) ||
  209. config_compare(list, "DataDirectory", CONFIG_TYPE_STRING, &options->DataDirectory) ||
  210. config_compare(list, "DirPort", CONFIG_TYPE_INT, &options->DirPort) ||
  211. config_compare(list, "DirBindAddress", CONFIG_TYPE_LINELIST, &options->DirBindAddress) ||
  212. config_compare(list, "DirFetchPostPeriod",CONFIG_TYPE_INT, &options->DirFetchPostPeriod) ||
  213. config_compare(list, "ExitNodes", CONFIG_TYPE_STRING, &options->ExitNodes) ||
  214. config_compare(list, "EntryNodes", CONFIG_TYPE_STRING, &options->EntryNodes) ||
  215. config_compare(list, "StrictExitNodes", CONFIG_TYPE_BOOL, &options->StrictExitNodes) ||
  216. config_compare(list, "StrictEntryNodes", CONFIG_TYPE_BOOL, &options->StrictEntryNodes) ||
  217. config_compare(list, "ExitPolicy", CONFIG_TYPE_LINELIST, &options->ExitPolicy) ||
  218. config_compare(list, "ExcludeNodes", CONFIG_TYPE_STRING, &options->ExcludeNodes) ||
  219. config_compare(list, "FascistFirewall",CONFIG_TYPE_BOOL, &options->FascistFirewall) ||
  220. config_compare(list, "FirewallPorts",CONFIG_TYPE_CSV, &options->FirewallPorts) ||
  221. config_compare(list, "Group", CONFIG_TYPE_STRING, &options->Group) ||
  222. config_compare(list, "HiddenServiceDir", CONFIG_TYPE_LINELIST, &options->RendConfigLines)||
  223. config_compare(list, "HiddenServicePort", CONFIG_TYPE_LINELIST, &options->RendConfigLines)||
  224. config_compare(list, "HiddenServiceNodes", CONFIG_TYPE_LINELIST, &options->RendConfigLines)||
  225. config_compare(list, "HiddenServiceExcludeNodes", CONFIG_TYPE_LINELIST, &options->RendConfigLines)||
  226. config_compare(list, "IgnoreVersion", CONFIG_TYPE_BOOL, &options->IgnoreVersion) ||
  227. config_compare(list, "KeepalivePeriod",CONFIG_TYPE_INT, &options->KeepalivePeriod) ||
  228. config_compare(list, "LogLevel", CONFIG_TYPE_LINELIST, &options->LogOptions) ||
  229. config_compare(list, "LogFile", CONFIG_TYPE_LINELIST, &options->LogOptions) ||
  230. config_compare(list, "LinkPadding", CONFIG_TYPE_BOOL, &options->LinkPadding) ||
  231. config_compare(list, "MaxConn", CONFIG_TYPE_INT, &options->MaxConn) ||
  232. config_compare(list, "MaxOnionsPending",CONFIG_TYPE_INT, &options->MaxOnionsPending) ||
  233. config_compare(list, "Nickname", CONFIG_TYPE_STRING, &options->Nickname) ||
  234. config_compare(list, "NewCircuitPeriod",CONFIG_TYPE_INT, &options->NewCircuitPeriod) ||
  235. config_compare(list, "NumCpus", CONFIG_TYPE_INT, &options->NumCpus) ||
  236. config_compare(list, "ORPort", CONFIG_TYPE_INT, &options->ORPort) ||
  237. config_compare(list, "ORBindAddress", CONFIG_TYPE_LINELIST, &options->ORBindAddress) ||
  238. config_compare(list, "OutboundBindAddress",CONFIG_TYPE_STRING, &options->OutboundBindAddress) ||
  239. config_compare(list, "PidFile", CONFIG_TYPE_STRING, &options->PidFile) ||
  240. config_compare(list, "PathlenCoinWeight",CONFIG_TYPE_DOUBLE, &options->PathlenCoinWeight) ||
  241. config_compare(list, "RouterFile", CONFIG_TYPE_STRING, &options->RouterFile) ||
  242. config_compare(list, "RunAsDaemon", CONFIG_TYPE_BOOL, &options->RunAsDaemon) ||
  243. config_compare(list, "RunTesting", CONFIG_TYPE_BOOL, &options->RunTesting) ||
  244. config_compare(list, "RecommendedVersions",CONFIG_TYPE_STRING, &options->RecommendedVersions) ||
  245. config_compare(list, "RendNodes", CONFIG_TYPE_STRING, &options->RendNodes) ||
  246. config_compare(list, "RendExcludeNodes",CONFIG_TYPE_STRING, &options->RendExcludeNodes) ||
  247. config_compare(list, "SocksPort", CONFIG_TYPE_INT, &options->SocksPort) ||
  248. config_compare(list, "SocksBindAddress",CONFIG_TYPE_LINELIST,&options->SocksBindAddress) ||
  249. config_compare(list, "SocksPolicy", CONFIG_TYPE_LINELIST,&options->SocksPolicy) ||
  250. config_compare(list, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
  251. config_compare(list, "User", CONFIG_TYPE_STRING, &options->User)
  252. ) {
  253. /* then we're ok. it matched something. */
  254. } else {
  255. log_fn(LOG_WARN,"Unknown keyword '%s'. Failing.",list->key);
  256. return -1;
  257. }
  258. list = list->next;
  259. }
  260. return 0;
  261. }
  262. const char default_dirservers_string[] =
  263. "router moria1 18.244.0.188 9001 9021 9031\n"
  264. "platform Tor 0.0.6rc1 on Linux moria.mit.edu i686\n"
  265. "published 2004-04-25 21:54:28\n"
  266. "bandwidth 800000 10000000\n"
  267. "onion-key\n"
  268. "-----BEGIN RSA PUBLIC KEY-----\n"
  269. "MIGJAoGBANoIvHieyHUTzIacbnWOnyTyzGrLOdXqbcjz2GGMxyHEd5K1bO1ZBNHP\n"
  270. "9i5qLQpN5viFk2K2rEGuG8tFgDEzSWZEtBqv3NVfUdiumdERWMBwlaQ0MVK4C+jf\n"
  271. "y5gZ8KI3o9ZictgPS1AQF+Kk932/vIHTuRIUKb4ILTnQilNvID0NAgMBAAE=\n"
  272. "-----END RSA PUBLIC KEY-----\n"
  273. "signing-key\n"
  274. "-----BEGIN RSA PUBLIC KEY-----\n"
  275. "MIGJAoGBAMHa0ZC/jo2Q2DrwKYF/6ZbmZ27PFYG91u4gUzzmZ/VXLpZ8wNzEV3oW\n"
  276. "nt+I61048fBiC1frT1/DZ351n2bLSk9zJbB6jyGZJn0380FPRX3+cXyXS0Gq8Ril\n"
  277. "xkhMQf5XuNFUb8UmYPSOH4WErjvYjKvU+gfjbK/82Jo9SuHpYz+BAgMBAAE=\n"
  278. "-----END RSA PUBLIC KEY-----\n"
  279. "reject 0.0.0.0/255.0.0.0:*\n"
  280. "reject 169.254.0.0/255.255.0.0:*\n"
  281. "reject 127.0.0.0/255.0.0.0:*\n"
  282. "reject 192.168.0.0/255.255.0.0:*\n"
  283. "reject 10.0.0.0/255.0.0.0:*\n"
  284. "reject 172.16.0.0/255.240.0.0:*\n"
  285. "accept *:20-22\n"
  286. "accept *:53\n"
  287. "accept *:79-80\n"
  288. "accept *:110\n"
  289. "accept *:143\n"
  290. "accept *:443\n"
  291. "accept *:873\n"
  292. "accept *:993\n"
  293. "accept *:995\n"
  294. "accept *:1024-65535\n"
  295. "reject *:*\n"
  296. "router-signature\n"
  297. "-----BEGIN SIGNATURE-----\n"
  298. "o1eAoRHDAEAXsnh5wN++vIwrupd+DbAJ2p3wxHDrmqxTpygzxxCnyQyhMfX03ua2\n"
  299. "4iplyNlwyFwzWcw0sk31otlO2HBYXT1V9G0YxGtKMOeOBMHjfGbUjGvEALHzWi4z\n"
  300. "8DXGJp13zgnUyP4ZA6xaGROwcT6oB5e7UlztvvpGxTg=\n"
  301. "-----END SIGNATURE-----\n"
  302. "\n"
  303. "router moria2 18.244.0.188 9002 9022 9032\n"
  304. "platform Tor 0.0.6rc1 on Linux moria.mit.edu i686\n"
  305. "published 2004-04-25 21:54:30\n"
  306. "bandwidth 800000 10000000\n"
  307. "onion-key\n"
  308. "-----BEGIN RSA PUBLIC KEY-----\n"
  309. "MIGJAoGBAM4Cc/npgYC54XrYLC+grVxJp7PDmNO2DRRJOxKttBBtvLpnR1UaueTi\n"
  310. "kyknT5kmlx+ihgZF/jmye//2dDUp2+kK/kSkpRV4xnDLXZmed+sNSQxqmm9TtZQ9\n"
  311. "/hjpxhp5J9HmUTYhntBs+4E4CUKokmrI6oRLoln4SA39AX9QLPcnAgMBAAE=\n"
  312. "-----END RSA PUBLIC KEY-----\n"
  313. "signing-key\n"
  314. "-----BEGIN RSA PUBLIC KEY-----\n"
  315. "MIGJAoGBAOcrht/y5rkaahfX7sMe2qnpqoPibsjTSJaDvsUtaNP/Bq0MgNDGOR48\n"
  316. "rtwfqTRff275Edkp/UYw3G3vSgKCJr76/bqOHCmkiZrnPV1zxNfrK18gNw2Cxre0\n"
  317. "nTA+fD8JQqpPtb8b0SnG9kwy75eS//sRu7TErie2PzGMxrf9LH0LAgMBAAE=\n"
  318. "-----END RSA PUBLIC KEY-----\n"
  319. "reject 0.0.0.0/255.0.0.0:*\n"
  320. "reject 169.254.0.0/255.255.0.0:*\n"
  321. "reject 127.0.0.0/255.0.0.0:*\n"
  322. "reject 192.168.0.0/255.255.0.0:*\n"
  323. "reject 10.0.0.0/255.0.0.0:*\n"
  324. "reject 172.16.0.0/255.240.0.0:*\n"
  325. "accept *:20-22\n"
  326. "accept *:53\n"
  327. "accept *:79-80\n"
  328. "accept *:110\n"
  329. "accept *:143\n"
  330. "accept *:443\n"
  331. "accept *:873\n"
  332. "accept *:993\n"
  333. "accept *:995\n"
  334. "accept *:1024-65535\n"
  335. "reject *:*\n"
  336. "router-signature\n"
  337. "-----BEGIN SIGNATURE-----\n"
  338. "RKROLwP1ExjTZeg6wuN0pzYqed9IJUd5lAe9hp4ritbnmJAgS6qfww6jgx61CfUR\n"
  339. "6SElhOLE7Q77jAdoL45Ji5pn/Y+Q+E+5lJm1E/ed9ha+YsOPaOc7z6GQ7E4mihCL\n"
  340. "gI1vsw92+P1Ty4RHj6fyD9DhbV19nh2Qs+pvGJOS2FY=\n"
  341. "-----END SIGNATURE-----\n"
  342. "\n"
  343. "router tor26 62.116.124.106 9001 9050 9030\n"
  344. "platform Tor 0.0.6 on Linux seppia i686\n"
  345. "published 2004-05-06 21:33:23\n"
  346. "bandwidth 500000 10000000\n"
  347. "onion-key\n"
  348. "-----BEGIN RSA PUBLIC KEY-----\n"
  349. "MIGJAoGBAMEHdDnpj3ik1AF1xe/VqjoguH2DbANifYqXXfempu0fS+tU9FGo6dU/\n"
  350. "fnVHAZwL9Ek9k2rMzumShi1RduK9p035R/Gk+PBBcLfvwYJ/Nat+ZO/L8jn/3bZe\n"
  351. "ieQd9CKj2LjNGKpRNry37vkwMGIOIlegwK+2us8aXJ7sIvlNts0TAgMBAAE=\n"
  352. "-----END RSA PUBLIC KEY-----\n"
  353. "signing-key\n"
  354. "-----BEGIN RSA PUBLIC KEY-----\n"
  355. "MIGJAoGBAMQgV2gXLbXgesWgeAsj8P1Uvm/zibrFXqwDq27lLKNgWGYGX2ax3LyT\n"
  356. "3nzI1Y5oLs4kPKTsMM5ft9aokwf417lKoCRlZc9ptfRbgxDx90c9GtWVmkrmDvCK\n"
  357. "ae59TMoXIiGfZiwWT6KKq5Zm9/Fu2Il3B2vHGkKJYKixmiBJRKp/AgMBAAE=\n"
  358. "-----END RSA PUBLIC KEY-----\n"
  359. "accept 62.245.184.24:25\n"
  360. "accept 62.116.124.106:6666-6670\n"
  361. "accept *:48099\n"
  362. "reject *:*\n"
  363. "router-signature\n"
  364. "-----BEGIN SIGNATURE-----\n"
  365. "qh/xRoqfLNFzPaB8VdpbdMAwRyuk5qjx4LeLVQ2pDwTZ55PqmG99+VKUNte2WTTD\n"
  366. "7dZEA7um2rueohGe4nYmvbhJWr20/I0ZxmWDRDvFy0b5nwzDMGvLvDw95Zu/XJQ2\n"
  367. "md32NE3y9VZCfbCN+GlvETX3fdR3Svzcm8Kzesg2/s4=\n"
  368. "-----END SIGNATURE-----\n"
  369. ;
  370. int config_assign_default_dirservers(void) {
  371. if(router_load_routerlist_from_string(default_dirservers_string, 1) < 0) {
  372. log_fn(LOG_WARN,"Bug: the default dirservers internal string is corrupt.");
  373. return -1;
  374. }
  375. return 0;
  376. }
  377. /** Set <b>options</b> to a reasonable default.
  378. *
  379. * Call this function when we can't find any torrc config file.
  380. */
  381. static int config_assign_defaults(or_options_t *options) {
  382. /* set them up as a client only */
  383. options->SocksPort = 9050;
  384. options->AllowUnverifiedNodes = smartlist_create();
  385. smartlist_add(options->AllowUnverifiedNodes, "middle");
  386. smartlist_add(options->AllowUnverifiedNodes, "rendezvous");
  387. config_free_lines(options->ExitPolicy);
  388. options->ExitPolicy = config_line_prepend(NULL, "ExitPolicy", "reject *:*");
  389. /* plus give them a dirservers file */
  390. if(config_assign_default_dirservers() < 0)
  391. return -1;
  392. return 0;
  393. }
  394. /** Print a usage message for tor. */
  395. static void print_usage(void) {
  396. printf("tor -f <torrc> [args]\n"
  397. "See man page for more options. This -h is probably obsolete.\n\n"
  398. "-b <bandwidth>\t\tbytes/second rate limiting\n"
  399. "-d <file>\t\tDebug file\n"
  400. // "-m <max>\t\tMax number of connections\n"
  401. "-l <level>\t\tLog level\n"
  402. "-r <file>\t\tList of known routers\n");
  403. printf("\nClient options:\n"
  404. "-e \"nick1 nick2 ...\"\t\tExit nodes\n"
  405. "-s <IP>\t\t\tPort to bind to for Socks\n"
  406. );
  407. printf("\nServer options:\n"
  408. "-n <nick>\t\tNickname of router\n"
  409. "-o <port>\t\tOR port to bind to\n"
  410. "-p <file>\t\tPID file\n"
  411. );
  412. }
  413. /**
  414. * Adjust <b>options</b> to contain a reasonable value for Address.
  415. */
  416. int resolve_my_address(const char *address, uint32_t *addr) {
  417. struct in_addr in;
  418. struct hostent *rent;
  419. char hostname[256];
  420. int explicit_ip=1;
  421. tor_assert(addr);
  422. if(address) {
  423. strlcpy(hostname,address,sizeof(hostname));
  424. } else { /* then we need to guess our address */
  425. explicit_ip = 0; /* it's implicit */
  426. if(gethostname(hostname,sizeof(hostname)) < 0) {
  427. log_fn(LOG_WARN,"Error obtaining local hostname");
  428. return -1;
  429. }
  430. log_fn(LOG_DEBUG,"Guessed local host name as '%s'",hostname);
  431. }
  432. /* now we know hostname. resolve it and keep only the IP */
  433. if(tor_inet_aton(hostname, &in) == 0) {
  434. /* then we have to resolve it */
  435. explicit_ip = 0;
  436. rent = (struct hostent *)gethostbyname(hostname);
  437. if (!rent) {
  438. log_fn(LOG_WARN,"Could not resolve local Address %s. Failing.", hostname);
  439. return -1;
  440. }
  441. tor_assert(rent->h_length == 4);
  442. memcpy(&in.s_addr, rent->h_addr,rent->h_length);
  443. }
  444. if(!explicit_ip && is_internal_IP(htonl(in.s_addr))) {
  445. log_fn(LOG_WARN,"Address '%s' resolves to private IP '%s'. "
  446. "Please set the Address config option to be the IP you want to use.",
  447. hostname, inet_ntoa(in));
  448. return -1;
  449. }
  450. log_fn(LOG_DEBUG,"Resolved Address to %s.", inet_ntoa(in));
  451. *addr = ntohl(in.s_addr);
  452. return 0;
  453. }
  454. static char *get_default_nickname(void)
  455. {
  456. char localhostname[256];
  457. char *cp, *out, *outp;
  458. if(gethostname(localhostname,sizeof(localhostname)) < 0) {
  459. log_fn(LOG_WARN,"Error obtaining local hostname");
  460. return NULL;
  461. }
  462. /* Put it in lowercase; stop at the first dot. */
  463. for(cp = localhostname; *cp; ++cp) {
  464. if (*cp == '.') {
  465. *cp = '\0';
  466. break;
  467. }
  468. *cp = tolower(*cp);
  469. }
  470. /* Strip invalid characters. */
  471. cp = localhostname;
  472. out = outp = tor_malloc(strlen(localhostname)+1);
  473. while (*cp) {
  474. if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp))
  475. *outp++ = *cp++;
  476. else
  477. cp++;
  478. }
  479. *outp = '\0';
  480. /* Enforce length. */
  481. if (strlen(out) > MAX_NICKNAME_LEN)
  482. out[MAX_NICKNAME_LEN]='\0';
  483. return out;
  484. }
  485. /** Release storage held by <b>options</b> */
  486. static void free_options(or_options_t *options) {
  487. config_free_lines(options->LogOptions);
  488. tor_free(options->ContactInfo);
  489. tor_free(options->DebugLogFile);
  490. tor_free(options->DataDirectory);
  491. tor_free(options->RouterFile);
  492. tor_free(options->Nickname);
  493. tor_free(options->Address);
  494. tor_free(options->PidFile);
  495. tor_free(options->ExitNodes);
  496. tor_free(options->EntryNodes);
  497. tor_free(options->ExcludeNodes);
  498. tor_free(options->RendNodes);
  499. tor_free(options->RendExcludeNodes);
  500. tor_free(options->OutboundBindAddress);
  501. tor_free(options->RecommendedVersions);
  502. tor_free(options->User);
  503. tor_free(options->Group);
  504. config_free_lines(options->RendConfigLines);
  505. config_free_lines(options->SocksBindAddress);
  506. config_free_lines(options->ORBindAddress);
  507. config_free_lines(options->DirBindAddress);
  508. config_free_lines(options->ExitPolicy);
  509. config_free_lines(options->SocksPolicy);
  510. SMARTLIST_FOREACH(options->FirewallPorts, char *, cp, tor_free(cp));
  511. smartlist_free(options->FirewallPorts);
  512. }
  513. /** Set <b>options</b> to hold reasonable defaults for most options. */
  514. static void init_options(or_options_t *options) {
  515. /* give reasonable values for each option. Defaults to zero. */
  516. memset(options,0,sizeof(or_options_t));
  517. options->LogOptions = NULL;
  518. options->ExitNodes = tor_strdup("");
  519. options->EntryNodes = tor_strdup("");
  520. options->StrictEntryNodes = options->StrictExitNodes = 0;
  521. options->ExcludeNodes = tor_strdup("");
  522. options->RendNodes = tor_strdup("");
  523. options->RendExcludeNodes = tor_strdup("");
  524. options->ExitPolicy = NULL;
  525. options->SocksPolicy = NULL;
  526. options->SocksBindAddress = NULL;
  527. options->ORBindAddress = NULL;
  528. options->DirBindAddress = NULL;
  529. options->OutboundBindAddress = NULL;
  530. options->RecommendedVersions = NULL;
  531. options->PidFile = NULL; // tor_strdup("tor.pid");
  532. options->DataDirectory = NULL;
  533. options->PathlenCoinWeight = 0.3;
  534. options->MaxConn = 900;
  535. options->DirFetchPostPeriod = 600;
  536. options->KeepalivePeriod = 300;
  537. options->MaxOnionsPending = 100;
  538. options->NewCircuitPeriod = 30; /* twice a minute */
  539. options->BandwidthRate = 800000; /* at most 800kB/s total sustained incoming */
  540. options->BandwidthBurst = 10000000; /* max burst on the token bucket */
  541. options->NumCpus = 1;
  542. options->RendConfigLines = NULL;
  543. options->FirewallPorts = NULL;
  544. }
  545. /** Read a configuration file into <b>options</b>, finding the configuration
  546. * file location based on the command line. After loading the options,
  547. * validate them for consistency. Return 0 if success, <0 if failure. */
  548. int getconfig(int argc, char **argv, or_options_t *options) {
  549. struct config_line_t *cl;
  550. FILE *cf;
  551. char *fname;
  552. int i;
  553. int result = 0;
  554. static int first_load = 1;
  555. static char **backup_argv;
  556. static int backup_argc;
  557. char *previous_pidfile = NULL;
  558. int previous_runasdaemon = 0;
  559. int previous_orport = -1;
  560. int using_default_torrc;
  561. if(first_load) { /* first time we're called. save commandline args */
  562. backup_argv = argv;
  563. backup_argc = argc;
  564. first_load = 0;
  565. } else { /* we're reloading. need to clean up old ones first. */
  566. argv = backup_argv;
  567. argc = backup_argc;
  568. /* record some previous values, so we can fail if they change */
  569. if(options->PidFile)
  570. previous_pidfile = tor_strdup(options->PidFile);
  571. previous_runasdaemon = options->RunAsDaemon;
  572. previous_orport = options->ORPort;
  573. free_options(options);
  574. }
  575. init_options(options);
  576. if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
  577. print_usage();
  578. exit(0);
  579. }
  580. if(argc > 1 && (!strcmp(argv[1],"--version"))) {
  581. printf("Tor version %s.\n",VERSION);
  582. exit(0);
  583. }
  584. /* learn config file name, get config lines, assign them */
  585. i = 1;
  586. while(i < argc-1 && strcmp(argv[i],"-f")) {
  587. i++;
  588. }
  589. if(i < argc-1) { /* we found one */
  590. fname = tor_strdup(argv[i+1]);
  591. using_default_torrc = 0;
  592. } else if (file_status(CONFDIR "/torrc")==FN_FILE) {
  593. /* didn't find one, try CONFDIR */
  594. fname = tor_strdup(CONFDIR "/torrc");
  595. using_default_torrc = 1;
  596. } else {
  597. char *fn = expand_filename("~/.torrc");
  598. if (fn && file_status(fn)==FN_FILE) {
  599. fname = fn;
  600. } else {
  601. tor_free(fn);
  602. fname = tor_strdup(CONFDIR "/torrc");
  603. }
  604. using_default_torrc = 1;
  605. }
  606. log(LOG_DEBUG,"Opening config file '%s'",fname);
  607. cf = config_open(fname);
  608. if(!cf) {
  609. if(using_default_torrc == 1) {
  610. log(LOG_NOTICE, "Configuration file '%s' not present, using reasonable defaults.",fname);
  611. tor_free(fname);
  612. if(config_assign_defaults(options) < 0) {
  613. return -1;
  614. }
  615. } else {
  616. log(LOG_WARN, "Unable to open configuration file '%s'.",fname);
  617. tor_free(fname);
  618. return -1;
  619. }
  620. } else { /* it opened successfully. use it. */
  621. tor_free(fname);
  622. cl = config_get_lines(cf);
  623. if(!cl) return -1;
  624. if(config_assign(options,cl) < 0)
  625. return -1;
  626. config_free_lines(cl);
  627. config_close(cf);
  628. }
  629. /* go through command-line variables too */
  630. cl = config_get_commandlines(argc,argv);
  631. if(config_assign(options,cl) < 0)
  632. return -1;
  633. config_free_lines(cl);
  634. /* Validate options */
  635. /* first check if any of the previous options have changed but aren't allowed to */
  636. if(previous_pidfile && strcmp(previous_pidfile,options->PidFile)) {
  637. log_fn(LOG_WARN,"During reload, PidFile changed from %s to %s. Failing.",
  638. previous_pidfile, options->PidFile);
  639. return -1;
  640. }
  641. tor_free(previous_pidfile);
  642. if(previous_runasdaemon && !options->RunAsDaemon) {
  643. log_fn(LOG_WARN,"During reload, change from RunAsDaemon=1 to =0 not allowed. Failing.");
  644. return -1;
  645. }
  646. if(previous_orport == 0 && options->ORPort > 0) {
  647. log_fn(LOG_WARN,"During reload, change from ORPort=0 to >0 not allowed. Failing.");
  648. return -1;
  649. }
  650. if(options->ORPort < 0) {
  651. log(LOG_WARN,"ORPort option can't be negative.");
  652. result = -1;
  653. }
  654. if (options->Nickname == NULL) {
  655. if(server_mode()) {
  656. if (!(options->Nickname = get_default_nickname()))
  657. return -1;
  658. log_fn(LOG_NOTICE, "Choosing default nickname %s", options->Nickname);
  659. }
  660. } else {
  661. if (strspn(options->Nickname, LEGAL_NICKNAME_CHARACTERS) !=
  662. strlen(options->Nickname)) {
  663. log_fn(LOG_WARN, "Nickname '%s' contains illegal characters.", options->Nickname);
  664. result = -1;
  665. }
  666. if (strlen(options->Nickname) > MAX_NICKNAME_LEN) {
  667. log_fn(LOG_WARN, "Nickname '%s' has more than %d characters.",
  668. options->Nickname, MAX_NICKNAME_LEN);
  669. result = -1;
  670. }
  671. }
  672. if(server_mode()) {
  673. /* confirm that our address isn't broken, so we can complain now */
  674. uint32_t tmp;
  675. if(resolve_my_address(options->Address, &tmp) < 0)
  676. result = -1;
  677. }
  678. if(options->SocksPort < 0) {
  679. log(LOG_WARN,"SocksPort option can't be negative.");
  680. result = -1;
  681. }
  682. if(options->SocksPort == 0 && options->ORPort == 0) {
  683. log(LOG_WARN,"SocksPort and ORPort are both undefined? Quitting.");
  684. result = -1;
  685. }
  686. if(options->DirPort < 0) {
  687. log(LOG_WARN,"DirPort option can't be negative.");
  688. result = -1;
  689. }
  690. if(options->StrictExitNodes && !strlen(options->ExitNodes)) {
  691. log(LOG_WARN,"StrictExitNodes set, but no ExitNodes listed.");
  692. }
  693. if(options->StrictEntryNodes && !strlen(options->EntryNodes)) {
  694. log(LOG_WARN,"StrictEntryNodes set, but no EntryNodes listed.");
  695. }
  696. if(options->AuthoritativeDir && options->RecommendedVersions == NULL) {
  697. log(LOG_WARN,"Directory servers must configure RecommendedVersions.");
  698. result = -1;
  699. }
  700. if(options->AuthoritativeDir && !options->DirPort) {
  701. log(LOG_WARN,"Running as authoritative directory, but no DirPort set.");
  702. result = -1;
  703. }
  704. if(options->AuthoritativeDir && !options->ORPort) {
  705. log(LOG_WARN,"Running as authoritative directory, but no ORPort set.");
  706. result = -1;
  707. }
  708. if(options->AuthoritativeDir && options->ClientOnly) {
  709. log(LOG_WARN,"Running as authoritative directory, but ClientOnly also set.");
  710. result = -1;
  711. }
  712. if(options->FascistFirewall && !options->FirewallPorts) {
  713. options->FirewallPorts = smartlist_create();
  714. smartlist_add(options->FirewallPorts, "80");
  715. smartlist_add(options->FirewallPorts, "443");
  716. }
  717. if(options->FirewallPorts) {
  718. SMARTLIST_FOREACH(options->FirewallPorts, const char *, cp,
  719. { i = atoi(cp);
  720. if (i < 1 || i > 65535) {
  721. log(LOG_WARN, "Port '%s' out of range in FirewallPorts", cp);
  722. result=-1;
  723. }
  724. });
  725. }
  726. options->_AllowUnverified = 0;
  727. if(options->AllowUnverifiedNodes) {
  728. SMARTLIST_FOREACH(options->AllowUnverifiedNodes, const char *, cp,
  729. { if (!strcasecmp(cp, "entry"))
  730. options->_AllowUnverified |= ALLOW_UNVERIFIED_ENTRY;
  731. else if (!strcasecmp(cp, "exit"))
  732. options->_AllowUnverified |= ALLOW_UNVERIFIED_EXIT;
  733. else if (!strcasecmp(cp, "middle"))
  734. options->_AllowUnverified |= ALLOW_UNVERIFIED_MIDDLE;
  735. else if (!strcasecmp(cp, "introduction"))
  736. options->_AllowUnverified |= ALLOW_UNVERIFIED_INTRODUCTION;
  737. else if (!strcasecmp(cp, "rendezvous"))
  738. options->_AllowUnverified |= ALLOW_UNVERIFIED_RENDEZVOUS;
  739. else {
  740. log(LOG_WARN, "Unrecognized value '%s' in AllowUnverifiedNodes",
  741. cp);
  742. result=-1;
  743. }
  744. });
  745. }
  746. if(options->SocksPort >= 1 &&
  747. (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0)) {
  748. log(LOG_WARN,"PathlenCoinWeight option must be >=0.0 and <1.0.");
  749. result = -1;
  750. }
  751. if(options->MaxConn < 1) {
  752. log(LOG_WARN,"MaxConn option must be a non-zero positive integer.");
  753. result = -1;
  754. }
  755. if(options->MaxConn >= MAXCONNECTIONS) {
  756. log(LOG_WARN,"MaxConn option must be less than %d.", MAXCONNECTIONS);
  757. result = -1;
  758. }
  759. if(options->DirFetchPostPeriod < 1) {
  760. log(LOG_WARN,"DirFetchPostPeriod option must be positive.");
  761. result = -1;
  762. }
  763. if(options->DirFetchPostPeriod > MIN_ONION_KEY_LIFETIME/2) {
  764. log(LOG_WARN,"DirFetchPostPeriod is too large; clipping.");
  765. options->DirFetchPostPeriod = MIN_ONION_KEY_LIFETIME/2;
  766. }
  767. if(options->KeepalivePeriod < 1) {
  768. log(LOG_WARN,"KeepalivePeriod option must be positive.");
  769. result = -1;
  770. }
  771. /* XXX look at the various nicknamelists and make sure they're
  772. * valid and don't have hostnames that are too long.
  773. */
  774. if (rend_config_services(options) < 0) {
  775. result = -1;
  776. }
  777. return result;
  778. }
  779. static int add_single_log(struct config_line_t *level_opt,
  780. struct config_line_t *file_opt,
  781. int isDaemon)
  782. {
  783. int levelMin=-1, levelMax=-1;
  784. char *cp, *tmp_sev;
  785. if (level_opt) {
  786. cp = strchr(level_opt->value, '-');
  787. if (cp) {
  788. tmp_sev = tor_strndup(level_opt->value, cp - level_opt->value);
  789. levelMin = parse_log_level(tmp_sev);
  790. if (levelMin<0) {
  791. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", tmp_sev);
  792. return -1;
  793. }
  794. tor_free(tmp_sev);
  795. levelMax = parse_log_level(cp+1);
  796. if (levelMax<0) {
  797. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", cp+1);
  798. return -1;
  799. }
  800. } else {
  801. levelMin = parse_log_level(level_opt->value);
  802. if (levelMin<0) {
  803. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", level_opt->value);
  804. return -1;
  805. }
  806. }
  807. }
  808. if (levelMin < 0 && levelMax < 0) {
  809. levelMin = LOG_NOTICE;
  810. levelMax = LOG_ERR;
  811. } else if (levelMin < 0) {
  812. levelMin = levelMax;
  813. } else {
  814. levelMax = LOG_ERR;
  815. }
  816. if (file_opt) {
  817. if (add_file_log(levelMin, levelMax, file_opt->value) < 0) {
  818. log_fn(LOG_WARN, "Cannot write to LogFile '%s': %s.", file_opt->value,
  819. strerror(errno));
  820. return -1;
  821. }
  822. log_fn(LOG_NOTICE, "Successfully opened LogFile '%s', redirecting output.",
  823. file_opt->value);
  824. } else if (!isDaemon) {
  825. add_stream_log(levelMin, levelMax, "<stdout>", stdout);
  826. close_temp_logs();
  827. }
  828. return 0;
  829. }
  830. /**
  831. * Initialize the logs based on the configuration file.
  832. */
  833. int config_init_logs(or_options_t *options)
  834. {
  835. /* The order of options is: Level? (File Level?)+
  836. */
  837. struct config_line_t *opt = options->LogOptions;
  838. /* Special case if no options are given. */
  839. if (!opt) {
  840. add_stream_log(LOG_NOTICE, LOG_ERR, "<stdout>", stdout);
  841. close_temp_logs();
  842. /* don't return yet, in case we want to do a debuglogfile below */
  843. }
  844. /* Special case for if first option is LogLevel. */
  845. if (opt && !strcasecmp(opt->key, "LogLevel")) {
  846. if (opt->next && !strcasecmp(opt->next->key, "LogFile")) {
  847. if (add_single_log(opt, opt->next, options->RunAsDaemon)<0)
  848. return -1;
  849. opt = opt->next->next;
  850. } else if (!opt->next) {
  851. if (add_single_log(opt, NULL, options->RunAsDaemon)<0)
  852. return -1;
  853. opt = opt->next;
  854. } else {
  855. ; /* give warning below */
  856. }
  857. }
  858. while (opt) {
  859. if (!strcasecmp(opt->key, "LogLevel")) {
  860. log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile");
  861. opt = opt->next;
  862. } else {
  863. tor_assert(!strcasecmp(opt->key, "LogFile"));
  864. if (opt->next && !strcasecmp(opt->next->key, "LogLevel")) {
  865. /* LogFile followed by LogLevel */
  866. if (add_single_log(opt->next, opt, options->RunAsDaemon)<0)
  867. return -1;
  868. opt = opt->next->next;
  869. } else {
  870. /* LogFile followed by LogFile or end of list. */
  871. if (add_single_log(NULL, opt, options->RunAsDaemon)<0)
  872. return -1;
  873. opt = opt->next;
  874. }
  875. }
  876. }
  877. if (options->DebugLogFile) {
  878. log_fn(LOG_WARN, "DebugLogFile is deprecated; use LogFile and LogLevel instead");
  879. if (add_file_log(LOG_DEBUG, LOG_ERR, options->DebugLogFile)<0)
  880. return -1;
  881. }
  882. return 0;
  883. }
  884. /** XXX008 DOCDOC */
  885. void
  886. config_parse_exit_policy(struct config_line_t *cfg,
  887. struct exit_policy_t **dest)
  888. {
  889. struct exit_policy_t **nextp;
  890. char *e, *s;
  891. int last=0;
  892. char line[1024];
  893. if (!cfg)
  894. return;
  895. nextp = dest;
  896. while (*nextp)
  897. nextp = &((*nextp)->next);
  898. for (; cfg; cfg = cfg->next) {
  899. s = cfg->value;
  900. for (;;) {
  901. e = strchr(s,',');
  902. if(!e) {
  903. last = 1;
  904. strncpy(line,s,1023);
  905. } else {
  906. memcpy(line,s, ((e-s)<1023)?(e-s):1023);
  907. line[e-s] = 0;
  908. }
  909. line[1023]=0;
  910. log_fn(LOG_DEBUG,"Adding new entry '%s'",line);
  911. *nextp = router_parse_exit_policy_from_string(line);
  912. if(*nextp) {
  913. nextp = &((*nextp)->next);
  914. } else {
  915. log_fn(LOG_WARN,"Malformed exit policy %s; skipping.", line);
  916. }
  917. if (last)
  918. break;
  919. s = e+1;
  920. }
  921. }
  922. }
  923. void exit_policy_free(struct exit_policy_t *p) {
  924. struct exit_policy_t *e;
  925. while (p) {
  926. e = p;
  927. p = p->next;
  928. tor_free(e->string);
  929. tor_free(e);
  930. }
  931. }
  932. const char *get_data_directory(or_options_t *options) {
  933. const char *d;
  934. if (options->DataDirectory)
  935. d = options->DataDirectory;
  936. else if (server_mode())
  937. d = "~/.tor";
  938. else
  939. d = NULL; /* XXX008 don't create datadir until we have something
  940. we'll be putting in it */
  941. if (d && strncmp(d,"~/",2)==0) {
  942. char *fn = expand_filename(d);
  943. tor_free(options->DataDirectory);
  944. options->DataDirectory = fn;
  945. }
  946. return options->DataDirectory;
  947. }
  948. /*
  949. Local Variables:
  950. mode:c
  951. indent-tabs-mode:nil
  952. c-basic-offset:2
  953. End:
  954. */