config.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. /* Copyright 2001 Matej Pfajfar.
  2. * Copyright 2001-2004 Roger Dingledine.
  3. * Copyright 2004 Roger Dingledine, Nick Mathewson. */
  4. /* See LICENSE for licensing information */
  5. /* $Id$ */
  6. /**
  7. * /file config.c
  8. *
  9. * /brief Code to parse and interpret configuration files.
  10. *
  11. **/
  12. #include "or.h"
  13. #ifdef MS_WINDOWS
  14. #include <shlobj.h>
  15. #endif
  16. /** Enumeration of types which option values can take */
  17. typedef enum config_type_t {
  18. CONFIG_TYPE_STRING = 0, /**< An arbitrary string. */
  19. CONFIG_TYPE_UINT, /**< A non-negative integer less than MAX_INT */
  20. CONFIG_TYPE_DOUBLE, /**< A floating-point value */
  21. CONFIG_TYPE_BOOL, /**< A boolean value, expressed as 0 or 1. */
  22. CONFIG_TYPE_CSV, /**< A list of strings, separated by commas and optional
  23. * whitespace. */
  24. CONFIG_TYPE_LINELIST, /**< Uninterpreted config lines */
  25. CONFIG_TYPE_LINELIST_S, /**< Uninterpreted, context-sensitive config lines,
  26. * mixed with other keywords. */
  27. CONFIG_TYPE_LINELIST_V, /**< Catch-all "virtual" option to summarize
  28. * context-sensitive config lines when fetching.
  29. */
  30. CONFIG_TYPE_OBSOLETE, /**< Obsolete (ignored) option. */
  31. } config_type_t;
  32. /* An abbreviation for a configuration option allowed on the command line */
  33. typedef struct config_abbrev_t {
  34. const char *abbreviated;
  35. const char *full;
  36. int commandline_only;
  37. } config_abbrev_t;
  38. /* Handy macro for declaring "In the config file or on the command line,
  39. * you can abbreviate <b>tok</b>s as <b>tok</b>". */
  40. #define PLURAL(tok) { #tok, #tok "s", 0 }
  41. /* A list of command-line abbreviations. */
  42. static config_abbrev_t config_abbrevs[] = {
  43. PLURAL(ExitNode),
  44. PLURAL(EntryNodes),
  45. PLURAL(ExcludeNode),
  46. PLURAL(FirewallPort),
  47. PLURAL(HiddenServiceNode),
  48. PLURAL(HiddenServiceExcludeNode),
  49. PLURAL(RendNode),
  50. PLURAL(RendExcludeNode),
  51. { "l", "Log", 1},
  52. { "BandwidthRate", "BandwidthRateBytes", 1},
  53. { "BandwidthBurst", "BandwidthBurstBytes", 1},
  54. { NULL, NULL , 0},
  55. };
  56. #undef PLURAL
  57. /** A variable allowed in the configuration file or on the command line. */
  58. typedef struct config_var_t {
  59. const char *name; /**< The full keyword (case insensitive). */
  60. config_type_t type; /**< How to interpret the type and turn it into a value. */
  61. off_t var_offset; /**< Offset of the corresponding member of or_options_t. */
  62. const char *initvalue; /**< String (or null) describing initial value. */
  63. } config_var_t;
  64. /** Return the offset of <b>member</b> within the type <b>tp</b>, in bytes */
  65. #define STRUCT_OFFSET(tp, member) ((off_t) (((char*)&((tp*)0)->member)-(char*)0))
  66. /** An entry for config_vars: "The option <b>name</b> has type
  67. * CONFIG_TYPE_<b>conftype</b>, and corresponds to
  68. * or_options_t.<b>member</b>"
  69. */
  70. #define VAR(name,conftype,member,initvalue) \
  71. { name, CONFIG_TYPE_ ## conftype, STRUCT_OFFSET(or_options_t, member), initvalue }
  72. /** An entry for config_vars: "The option <b>name</b> is obsolete." */
  73. #define OBSOLETE(name) { name, CONFIG_TYPE_OBSOLETE, 0, NULL }
  74. /** Array of configuration options. Until we disallow nonstandard
  75. * abbreviations, order is significant, since the first matching option will
  76. * be chosen first.
  77. */
  78. static config_var_t config_vars[] = {
  79. VAR("Address", STRING, Address, NULL),
  80. VAR("AllowUnverifiedNodes",CSV, AllowUnverifiedNodes, "middle,rendezvous"),
  81. VAR("AuthoritativeDirectory",BOOL, AuthoritativeDir, "0"),
  82. VAR("BandwidthRateBytes", UINT, BandwidthRateBytes, "800000"),
  83. VAR("BandwidthBurstBytes", UINT, BandwidthBurstBytes, "50000000"),
  84. VAR("ClientOnly", BOOL, ClientOnly, "0"),
  85. VAR("ContactInfo", STRING, ContactInfo, NULL),
  86. VAR("ControlPort", UINT, ControlPort, "0"),
  87. VAR("DebugLogFile", STRING, DebugLogFile, NULL),
  88. VAR("DataDirectory", STRING, DataDirectory, NULL),
  89. VAR("DirPort", UINT, DirPort, "0"),
  90. VAR("DirBindAddress", LINELIST, DirBindAddress, NULL),
  91. VAR("DirFetchPostPeriod", UINT, DirFetchPostPeriod, "600"),
  92. VAR("DirPolicy", LINELIST, DirPolicy, NULL),
  93. VAR("DirServer", LINELIST, DirServers, NULL),
  94. VAR("ExitNodes", STRING, ExitNodes, NULL),
  95. VAR("EntryNodes", STRING, EntryNodes, NULL),
  96. VAR("StrictExitNodes", BOOL, StrictExitNodes, "0"),
  97. VAR("StrictEntryNodes", BOOL, StrictEntryNodes, "0"),
  98. VAR("ExitPolicy", LINELIST, ExitPolicy, NULL),
  99. VAR("ExcludeNodes", STRING, ExcludeNodes, NULL),
  100. VAR("FascistFirewall", BOOL, FascistFirewall, "0"),
  101. VAR("FirewallPorts", CSV, FirewallPorts, "80,443"),
  102. VAR("MyFamily", STRING, MyFamily, NULL),
  103. VAR("NodeFamily", LINELIST, NodeFamilies, NULL),
  104. VAR("Group", STRING, Group, NULL),
  105. VAR("HashedControlPassword",STRING, HashedControlPassword, NULL),
  106. VAR("HttpProxy", STRING, HttpProxy, NULL),
  107. VAR("HiddenServiceOptions",LINELIST_V, RendConfigLines, NULL),
  108. VAR("HiddenServiceDir", LINELIST_S, RendConfigLines, NULL),
  109. VAR("HiddenServicePort", LINELIST_S, RendConfigLines, NULL),
  110. VAR("HiddenServiceNodes", LINELIST_S, RendConfigLines, NULL),
  111. VAR("HiddenServiceExcludeNodes", LINELIST_S, RendConfigLines, NULL),
  112. VAR("IgnoreVersion", BOOL, IgnoreVersion, "0"),
  113. VAR("KeepalivePeriod", UINT, KeepalivePeriod, "300"),
  114. VAR("Log", LINELIST, Logs, NULL),
  115. VAR("LogLevel", LINELIST_S, OldLogOptions, NULL),
  116. VAR("LogFile", LINELIST_S, OldLogOptions, NULL),
  117. OBSOLETE("LinkPadding"),
  118. VAR("MaxConn", UINT, MaxConn, "1024"),
  119. VAR("MaxOnionsPending", UINT, MaxOnionsPending, "100"),
  120. VAR("MonthlyAccountingStart",UINT, AccountingStart, "0"),
  121. VAR("AccountingMaxKB", UINT, AccountingMaxKB, "0"),
  122. VAR("Nickname", STRING, Nickname, NULL),
  123. VAR("NewCircuitPeriod", UINT, NewCircuitPeriod, "30"),
  124. VAR("NumCpus", UINT, NumCpus, "1"),
  125. VAR("ORPort", UINT, ORPort, "0"),
  126. VAR("ORBindAddress", LINELIST, ORBindAddress, NULL),
  127. VAR("OutboundBindAddress", STRING, OutboundBindAddress, NULL),
  128. VAR("PidFile", STRING, PidFile, NULL),
  129. VAR("PathlenCoinWeight", DOUBLE, PathlenCoinWeight, "0.3"),
  130. VAR("RedirectExit", LINELIST, RedirectExit, NULL),
  131. OBSOLETE("RouterFile"),
  132. VAR("RunAsDaemon", BOOL, RunAsDaemon, "0"),
  133. VAR("RunTesting", BOOL, RunTesting, "0"),
  134. VAR("RecommendedVersions", LINELIST, RecommendedVersions, NULL),
  135. VAR("RendNodes", STRING, RendNodes, NULL),
  136. VAR("RendExcludeNodes", STRING, RendExcludeNodes, NULL),
  137. VAR("SocksPort", UINT, SocksPort, "9050"),
  138. VAR("SocksBindAddress", LINELIST, SocksBindAddress, NULL),
  139. VAR("SocksPolicy", LINELIST, SocksPolicy, NULL),
  140. VAR("SysLog", LINELIST_S, OldLogOptions, NULL),
  141. OBSOLETE("TrafficShaping"),
  142. VAR("User", STRING, User, NULL),
  143. { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
  144. };
  145. #undef VAR
  146. #undef OBSOLETE
  147. /** Largest allowed config line */
  148. #define CONFIG_LINE_T_MAXLEN 4096
  149. static void option_reset(or_options_t *options, config_var_t *var);
  150. static void options_free(or_options_t *options);
  151. static or_options_t *options_dup(or_options_t *old);
  152. static int options_validate(or_options_t *options);
  153. static int options_transition_allowed(or_options_t *old, or_options_t *new);
  154. static int check_nickname_list(const char *lst, const char *name);
  155. static int parse_dir_server_line(const char *line, int validate_only);
  156. static int parse_redirect_line(or_options_t *options,
  157. struct config_line_t *line);
  158. static int parse_log_severity_range(const char *range, int *min_out,
  159. int *max_out);
  160. static int convert_log_option(or_options_t *options,
  161. struct config_line_t *level_opt,
  162. struct config_line_t *file_opt, int isDaemon);
  163. static int add_single_log_option(or_options_t *options, int minSeverity,
  164. int maxSeverity,
  165. const char *type, const char *fname);
  166. static int normalize_log_options(or_options_t *options);
  167. /*
  168. * Functions to read and write the global options pointer.
  169. */
  170. /** Command-line and config-file options. */
  171. static or_options_t *global_options=NULL;
  172. /** Return the currently configured options. */
  173. or_options_t *
  174. get_options(void) {
  175. tor_assert(global_options);
  176. return global_options;
  177. }
  178. /** Change the current global options tocontain <b>new</b> instead of
  179. * their current value; free the old value as necessary. Where
  180. * <b>new</b> is different from the old value, update the process to
  181. * use the new value instead.
  182. *
  183. * Note 1: <b>new_val</b> must have previously been validated with
  184. * options_validate(), or Tor may freak out and exit.
  185. *
  186. * Note 2: We haven't moved all the "act on new configuration" logic
  187. * here yet. Some is still in do_hup() and other places.
  188. */
  189. void
  190. set_options(or_options_t *new_val) {
  191. struct config_line_t *cl;
  192. if (global_options)
  193. options_free(global_options);
  194. global_options = new_val;
  195. clear_trusted_dir_servers();
  196. for (cl = new_val->DirServers; cl; cl = cl->next) {
  197. if (parse_dir_server_line(cl->value, 0)<0) {
  198. log_fn(LOG_ERR,
  199. "Previously validated DirServer line could not be added!");
  200. tor_assert(0);
  201. }
  202. }
  203. if (rend_config_services(new_val, 0)<0) {
  204. log_fn(LOG_ERR,
  205. "Previously validated hidden services line could not be added!");
  206. tor_assert(0);
  207. }
  208. }
  209. /*
  210. * Functions to parse config options
  211. */
  212. /** If <b>option</b> is an official abbreviation for a longer option,
  213. * return the longer option. Otherwise return <b>option</b>.
  214. * If <b>command_line</b> is set, apply all abbreviations. Otherwise, only
  215. * apply abbreviations that work for the config file and the command line. */
  216. static const char *
  217. expand_abbrev(const char *option, int command_line)
  218. {
  219. int i;
  220. for (i=0; config_abbrevs[i].abbreviated; ++i) {
  221. /* Abbreviations aren't casei. */
  222. if (!strcmp(option,config_abbrevs[i].abbreviated) &&
  223. (command_line || !config_abbrevs[i].commandline_only)) {
  224. return config_abbrevs[i].full;
  225. }
  226. }
  227. return option;
  228. }
  229. /** Helper: Read a list of configuration options from the command line. */
  230. static struct config_line_t *
  231. config_get_commandlines(int argc, char **argv)
  232. {
  233. struct config_line_t *new;
  234. struct config_line_t *front = NULL;
  235. char *s;
  236. int i = 1;
  237. while (i < argc-1) {
  238. if (!strcmp(argv[i],"-f") ||
  239. !strcmp(argv[i],"--hash-password")) {
  240. i += 2; /* command-line option with argument. ignore them. */
  241. continue;
  242. } else if (!strcmp(argv[i],"--list-fingerprint")) {
  243. i += 1; /* command-line option. ignore it. */
  244. continue;
  245. }
  246. new = tor_malloc(sizeof(struct config_line_t));
  247. s = argv[i];
  248. while(*s == '-')
  249. s++;
  250. new->key = tor_strdup(expand_abbrev(s, 1));
  251. new->value = tor_strdup(argv[i+1]);
  252. log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
  253. new->key, new->value);
  254. new->next = front;
  255. front = new;
  256. i += 2;
  257. }
  258. return front;
  259. }
  260. /** Helper: allocate a new configuration option mapping 'key' to 'val',
  261. * prepend it to 'front', and return the newly allocated config_line_t */
  262. struct config_line_t *
  263. config_line_prepend(struct config_line_t *front,
  264. const char *key,
  265. const char *val)
  266. {
  267. struct config_line_t *newline;
  268. newline = tor_malloc(sizeof(struct config_line_t));
  269. newline->key = tor_strdup(key);
  270. newline->value = tor_strdup(val);
  271. newline->next = front;
  272. return newline;
  273. }
  274. /** Helper: parse the config string and strdup into key/value
  275. * strings. Set *result to the list, or NULL if parsing the string
  276. * failed. Return 0 on success, -1 on failure. Warn and ignore any
  277. * misformatted lines. */
  278. int
  279. config_get_lines(char *string, struct config_line_t **result)
  280. {
  281. struct config_line_t *list = NULL;
  282. char *k, *v;
  283. do {
  284. string = parse_line_from_str(string, &k, &v);
  285. if (!string) {
  286. config_free_lines(list);
  287. return -1;
  288. }
  289. if (k && v)
  290. list = config_line_prepend(list, k, v);
  291. } while (*string);
  292. *result = list;
  293. return 0;
  294. }
  295. /**
  296. * Free all the configuration lines on the linked list <b>front</b>.
  297. */
  298. void
  299. config_free_lines(struct config_line_t *front)
  300. {
  301. struct config_line_t *tmp;
  302. while (front) {
  303. tmp = front;
  304. front = tmp->next;
  305. tor_free(tmp->key);
  306. tor_free(tmp->value);
  307. tor_free(tmp);
  308. }
  309. }
  310. /** If <b>key</b> is a configuration option, return the corresponding
  311. * config_var_t. Otherwise, if <b>key</b> is a non-standard abbreviation,
  312. * warn, and return the corresponding config_var_t. Otherwise return NULL.
  313. */
  314. static config_var_t *config_find_option(const char *key)
  315. {
  316. int i;
  317. /* First, check for an exact (case-insensitive) match */
  318. for (i=0; config_vars[i].name; ++i) {
  319. if (!strcasecmp(key, config_vars[i].name))
  320. return &config_vars[i];
  321. }
  322. /* If none, check for an abbreviated match */
  323. for (i=0; config_vars[i].name; ++i) {
  324. if (!strncasecmp(key, config_vars[i].name, strlen(key))) {
  325. log_fn(LOG_WARN, "The abbreviation '%s' is deprecated. "
  326. "Tell Nick and Roger to make it official, or just use '%s' instead",
  327. key, config_vars[i].name);
  328. return &config_vars[i];
  329. }
  330. }
  331. /* Okay, unrecogized options */
  332. return NULL;
  333. }
  334. /** If <b>c</b> is a syntactically valid configuration line, update
  335. * <b>options</b> with its value and return 0. Otherwise return -1 for bad key,
  336. * -2 for bad value.
  337. *
  338. * If 'reset' is set, and we get a line containing no value, restore the
  339. * option to its default value.
  340. */
  341. static int
  342. config_assign_line(or_options_t *options, struct config_line_t *c, int reset)
  343. {
  344. int i, ok;
  345. config_var_t *var;
  346. void *lvalue;
  347. var = config_find_option(c->key);
  348. if (!var) {
  349. log_fn(LOG_WARN, "Unknown option '%s'. Failing.", c->key);
  350. return -1;
  351. }
  352. /* Put keyword into canonical case. */
  353. if (strcmp(var->name, c->key)) {
  354. tor_free(c->key);
  355. c->key = tor_strdup(var->name);
  356. }
  357. if (reset && !strlen(c->value)) {
  358. option_reset(options, var);
  359. return 0;
  360. }
  361. lvalue = ((char*)options) + var->var_offset;
  362. switch(var->type) {
  363. case CONFIG_TYPE_UINT:
  364. i = tor_parse_long(c->value, 10, 0, INT_MAX, &ok, NULL);
  365. if (!ok) {
  366. log(LOG_WARN, "Int keyword '%s %s' is malformed or out of bounds.",
  367. c->key,c->value);
  368. return -2;
  369. }
  370. *(int *)lvalue = i;
  371. break;
  372. case CONFIG_TYPE_BOOL:
  373. i = tor_parse_long(c->value, 10, 0, 1, &ok, NULL);
  374. if (!ok) {
  375. log(LOG_WARN, "Boolean keyword '%s' expects 0 or 1.", c->key);
  376. return -2;
  377. }
  378. *(int *)lvalue = i;
  379. break;
  380. case CONFIG_TYPE_STRING:
  381. tor_free(*(char **)lvalue);
  382. *(char **)lvalue = tor_strdup(c->value);
  383. break;
  384. case CONFIG_TYPE_DOUBLE:
  385. *(double *)lvalue = atof(c->value);
  386. break;
  387. case CONFIG_TYPE_CSV:
  388. if (*(smartlist_t**)lvalue == NULL)
  389. *(smartlist_t**)lvalue = smartlist_create();
  390. smartlist_split_string(*(smartlist_t**)lvalue, c->value, ",",
  391. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  392. break;
  393. case CONFIG_TYPE_LINELIST:
  394. case CONFIG_TYPE_LINELIST_S:
  395. /* Note: this reverses the order that the lines appear in. That's
  396. * just fine, since we build up the list of lines reversed in the
  397. * first place. */
  398. *(struct config_line_t**)lvalue =
  399. config_line_prepend(*(struct config_line_t**)lvalue, c->key, c->value);
  400. break;
  401. case CONFIG_TYPE_OBSOLETE:
  402. log_fn(LOG_WARN, "Skipping obsolete configuration option '%s'", c->key);
  403. break;
  404. case CONFIG_TYPE_LINELIST_V:
  405. log_fn(LOG_WARN, "Can't provide value for virtual option '%s'", c->key);
  406. return -2;
  407. default:
  408. tor_assert(0);
  409. break;
  410. }
  411. return 0;
  412. }
  413. /** restore the option named <b>key</b> in options to its default value. */
  414. static void
  415. config_reset_line(or_options_t *options, const char *key)
  416. {
  417. config_var_t *var;
  418. var = config_find_option(key);
  419. if (!var)
  420. return; /* give error on next pass. */
  421. option_reset(options, var);
  422. }
  423. /** Return a canonicalized list of the options assigned for key.
  424. */
  425. struct config_line_t *
  426. config_get_assigned_option(or_options_t *options, const char *key)
  427. {
  428. config_var_t *var;
  429. const void *value;
  430. char buf[32];
  431. struct config_line_t *result;
  432. var = config_find_option(key);
  433. if (!var) {
  434. log_fn(LOG_WARN, "Unknown option '%s'. Failing.", key);
  435. return NULL;
  436. } else if (var->type == CONFIG_TYPE_LINELIST_S) {
  437. log_fn(LOG_WARN, "Can't return context-sensitive '%s' on its own", key);
  438. return NULL;
  439. }
  440. value = ((char*)options) + var->var_offset;
  441. if (var->type == CONFIG_TYPE_LINELIST ||
  442. var->type == CONFIG_TYPE_LINELIST_V) {
  443. /* Linelist requires special handling: we just copy and return it. */
  444. const struct config_line_t *next_in = value;
  445. struct config_line_t **next_out = &result;
  446. while (next_in) {
  447. *next_out = tor_malloc(sizeof(struct config_line_t));
  448. (*next_out)->key = tor_strdup(next_in->key);
  449. (*next_out)->value = tor_strdup(next_in->value);
  450. next_in = next_in->next;
  451. next_out = &((*next_out)->next);
  452. }
  453. (*next_out) = NULL;
  454. return result;
  455. }
  456. result = tor_malloc_zero(sizeof(struct config_line_t));
  457. result->key = tor_strdup(var->name);
  458. switch(var->type)
  459. {
  460. case CONFIG_TYPE_STRING:
  461. result->value = tor_strdup(value ? (char*)value : "");
  462. break;
  463. case CONFIG_TYPE_UINT:
  464. /* XXX This means every or_options_t uint or bool element
  465. * needs to be an int. Not, say, a uint16_t or char. */
  466. tor_snprintf(buf, sizeof(buf), "%d", *(int*)value);
  467. result->value = tor_strdup(buf);
  468. break;
  469. case CONFIG_TYPE_DOUBLE:
  470. tor_snprintf(buf, sizeof(buf), "%f", *(double*)value);
  471. result->value = tor_strdup(buf);
  472. break;
  473. case CONFIG_TYPE_BOOL:
  474. result->value = tor_strdup(*(int*)value ? "1" : "0");
  475. break;
  476. case CONFIG_TYPE_CSV:
  477. if (value)
  478. result->value = smartlist_join_strings((smartlist_t*)value,",",0,NULL);
  479. else
  480. result->value = tor_strdup("");
  481. break;
  482. default:
  483. tor_free(result->key);
  484. tor_free(result);
  485. log_fn(LOG_WARN,"Bug: unknown type %d for known key %s", var->type, key);
  486. return NULL;
  487. }
  488. return result;
  489. }
  490. /** Iterate through the linked list of requested options <b>list</b>.
  491. * For each item, convert as appropriate and assign to <b>options</b>.
  492. * If an item is unrecognized, return -1 immediately,
  493. * else return 0 for success.
  494. *
  495. * If <b>reset</b>, then interpret empty lines as meaning "restore to
  496. * default value", and interpret LINELIST* options as replacing (not
  497. * extending) their previous values. Return 0 on success, -1 on bad key,
  498. * -2 on bad value.
  499. */
  500. static int
  501. config_assign(or_options_t *options, struct config_line_t *list, int reset)
  502. {
  503. struct config_line_t *p;
  504. /* pass 1: normalize keys */
  505. for (p = list; p; p = p->next) {
  506. const char *full = expand_abbrev(p->key, 0);
  507. if (strcmp(full,p->key)) {
  508. tor_free(p->key);
  509. p->key = tor_strdup(full);
  510. }
  511. }
  512. /* pass 2: if we're reading from a resetting source, clear all mentioned
  513. * linelists. */
  514. if (reset) {
  515. for (p = list; p; p = p->next)
  516. config_reset_line(options, p->key);
  517. }
  518. /* pass 3: assign. */
  519. while (list) {
  520. int r;
  521. if ((r=config_assign_line(options, list, reset)))
  522. return r;
  523. list = list->next;
  524. }
  525. return 0;
  526. }
  527. /** Try assigning <b>list</b> to <b>options</b>. You do this by duping
  528. * options, assigning list to the new one, then validating it. If it's
  529. * ok, then through out the old one and stick with the new one. Else,
  530. * revert to old and return failure. Return 0 on success, -1 on bad
  531. * keys, -2 on bad values, -3 on bad transition.
  532. */
  533. int
  534. config_trial_assign(or_options_t **options, struct config_line_t *list, int reset)
  535. {
  536. int r;
  537. or_options_t *trial_options = options_dup(*options);
  538. if ((r=config_assign(trial_options, list, reset)) < 0) {
  539. options_free(trial_options);
  540. return r;
  541. }
  542. if (options_validate(trial_options) < 0) {
  543. options_free(trial_options);
  544. return -2;
  545. }
  546. if (options_transition_allowed(*options, trial_options) < 0) {
  547. options_free(trial_options);
  548. return -3;
  549. }
  550. set_options(trial_options);
  551. return 0;
  552. }
  553. /** Replace the option indexed by <b>var</b> in <b>options</b> with its
  554. * default value. */
  555. static void
  556. option_reset(or_options_t *options, config_var_t *var)
  557. {
  558. struct config_line_t *c;
  559. void *lvalue;
  560. lvalue = ((char*)options) + var->var_offset;
  561. switch (var->type) {
  562. case CONFIG_TYPE_STRING:
  563. tor_free(*(char**)lvalue);
  564. break;
  565. case CONFIG_TYPE_DOUBLE:
  566. *(double*)lvalue = 0.0;
  567. break;
  568. case CONFIG_TYPE_UINT:
  569. case CONFIG_TYPE_BOOL:
  570. *(int*)lvalue = 0;
  571. break;
  572. case CONFIG_TYPE_CSV:
  573. if (*(smartlist_t**)lvalue) {
  574. SMARTLIST_FOREACH(*(smartlist_t **)lvalue, char *, cp, tor_free(cp));
  575. smartlist_free(*(smartlist_t **)lvalue);
  576. *(smartlist_t **)lvalue = NULL;
  577. }
  578. break;
  579. case CONFIG_TYPE_LINELIST:
  580. case CONFIG_TYPE_LINELIST_S:
  581. config_free_lines(*(struct config_line_t **)lvalue);
  582. *(struct config_line_t **)lvalue = NULL;
  583. break;
  584. case CONFIG_TYPE_LINELIST_V:
  585. /* handled by linelist_s. */
  586. break;
  587. case CONFIG_TYPE_OBSOLETE:
  588. break;
  589. }
  590. if (var->initvalue) {
  591. c = tor_malloc_zero(sizeof(struct config_line_t));
  592. c->key = tor_strdup(var->name);
  593. c->value = tor_strdup(var->initvalue);
  594. config_assign_line(options,c,0);
  595. config_free_lines(c);
  596. }
  597. }
  598. /** Set <b>options</b>-&gt;DirServers to contain the default directory
  599. * servers. */
  600. static void
  601. add_default_trusted_dirservers(or_options_t *options)
  602. {
  603. /* moria1 */
  604. options->DirServers = config_line_prepend(options->DirServers, "DirServer",
  605. "18.244.0.188:9031 FFCB 46DB 1339 DA84 674C 70D7 CB58 6434 C437 0441");
  606. /* moria2 */
  607. options->DirServers = config_line_prepend(options->DirServers, "DirServer",
  608. "18.244.0.114:80 719B E45D E224 B607 C537 07D0 E214 3E2D 423E 74CF");
  609. /* tor26 */
  610. options->DirServers = config_line_prepend(options->DirServers, "DirServer",
  611. "62.116.124.106:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
  612. }
  613. /** Print a usage message for tor. */
  614. static void
  615. print_usage(void)
  616. {
  617. printf("tor -f <torrc> [args]\n"
  618. "See man page for more options. This -h is obsolete.\n");
  619. #if 0
  620. "-b <bandwidth>\t\tbytes/second rate limiting\n"
  621. "-d <file>\t\tDebug file\n"
  622. "-l <level>\t\tLog level\n"
  623. "-r <file>\t\tList of known routers\n");
  624. printf("\nClient options:\n"
  625. "-e \"nick1 nick2 ...\"\t\tExit nodes\n"
  626. "-s <IP>\t\t\tPort to bind to for Socks\n");
  627. printf("\nServer options:\n"
  628. "-n <nick>\t\tNickname of router\n"
  629. "-o <port>\t\tOR port to bind to\n"
  630. "-p <file>\t\tPID file\n");
  631. #endif
  632. }
  633. /**
  634. * Based on <b>address</b>, guess our public IP address and put it
  635. * in <b>addr</b>.
  636. */
  637. int
  638. resolve_my_address(const char *address, uint32_t *addr)
  639. {
  640. struct in_addr in;
  641. struct hostent *rent;
  642. char hostname[256];
  643. int explicit_ip=1;
  644. tor_assert(addr);
  645. if (address) {
  646. strlcpy(hostname, address, sizeof(hostname));
  647. } else { /* then we need to guess our address */
  648. explicit_ip = 0; /* it's implicit */
  649. if (gethostname(hostname, sizeof(hostname)) < 0) {
  650. log_fn(LOG_WARN,"Error obtaining local hostname");
  651. return -1;
  652. }
  653. log_fn(LOG_DEBUG,"Guessed local host name as '%s'",hostname);
  654. }
  655. /* now we know hostname. resolve it and keep only the IP */
  656. if (tor_inet_aton(hostname, &in) == 0) {
  657. /* then we have to resolve it */
  658. explicit_ip = 0;
  659. rent = (struct hostent *)gethostbyname(hostname);
  660. if (!rent) {
  661. log_fn(LOG_WARN,"Could not resolve local Address %s. Failing.", hostname);
  662. return -1;
  663. }
  664. tor_assert(rent->h_length == 4);
  665. memcpy(&in.s_addr, rent->h_addr, rent->h_length);
  666. }
  667. if (!explicit_ip && is_internal_IP(htonl(in.s_addr))) {
  668. log_fn(LOG_WARN,"Address '%s' resolves to private IP '%s'. "
  669. "Please set the Address config option to be the IP you want to use.",
  670. hostname, inet_ntoa(in));
  671. return -1;
  672. }
  673. log_fn(LOG_DEBUG, "Resolved Address to %s.", inet_ntoa(in));
  674. *addr = ntohl(in.s_addr);
  675. return 0;
  676. }
  677. /** Called when we don't have a nickname set. Try to guess a good
  678. * nickname based on the hostname, and return it. */
  679. static char *
  680. get_default_nickname(void)
  681. {
  682. char localhostname[256];
  683. char *cp, *out, *outp;
  684. if (gethostname(localhostname, sizeof(localhostname)) < 0) {
  685. log_fn(LOG_WARN,"Error obtaining local hostname");
  686. return NULL;
  687. }
  688. /* Put it in lowercase; stop at the first dot. */
  689. for (cp = localhostname; *cp; ++cp) {
  690. if (*cp == '.') {
  691. *cp = '\0';
  692. break;
  693. }
  694. *cp = tolower(*cp);
  695. }
  696. /* Strip invalid characters. */
  697. cp = localhostname;
  698. out = outp = tor_malloc(strlen(localhostname) + 1);
  699. while (*cp) {
  700. if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp))
  701. *outp++ = *cp++;
  702. else
  703. cp++;
  704. }
  705. *outp = '\0';
  706. /* Enforce length. */
  707. if (strlen(out) > MAX_NICKNAME_LEN)
  708. out[MAX_NICKNAME_LEN]='\0';
  709. return out;
  710. }
  711. /** Release storage held by <b>options</b> */
  712. static void
  713. options_free(or_options_t *options)
  714. {
  715. int i;
  716. void *lvalue;
  717. for (i=0; config_vars[i].name; ++i) {
  718. lvalue = ((char*)options) + config_vars[i].var_offset;
  719. switch(config_vars[i].type) {
  720. case CONFIG_TYPE_UINT:
  721. case CONFIG_TYPE_BOOL:
  722. case CONFIG_TYPE_DOUBLE:
  723. case CONFIG_TYPE_OBSOLETE:
  724. break; /* nothing to free for these config types */
  725. case CONFIG_TYPE_STRING:
  726. tor_free(*(char **)lvalue);
  727. break;
  728. case CONFIG_TYPE_LINELIST:
  729. case CONFIG_TYPE_LINELIST_V:
  730. config_free_lines(*(struct config_line_t**)lvalue);
  731. *(struct config_line_t**)lvalue = NULL;
  732. break;
  733. case CONFIG_TYPE_CSV:
  734. if (*(smartlist_t**)lvalue) {
  735. SMARTLIST_FOREACH(*(smartlist_t**)lvalue, char *, cp, tor_free(cp));
  736. smartlist_free(*(smartlist_t**)lvalue);
  737. *(smartlist_t**)lvalue = NULL;
  738. }
  739. break;
  740. case CONFIG_TYPE_LINELIST_S:
  741. /* will be freed by corresponding LINELIST_V. */
  742. break;
  743. }
  744. }
  745. /* XXX this last part is an exception. can we make it not needed? */
  746. if (options->RedirectExitList) {
  747. SMARTLIST_FOREACH(options->RedirectExitList,
  748. exit_redirect_t *, p, tor_free(p));
  749. smartlist_free(options->RedirectExitList);
  750. options->RedirectExitList = NULL;
  751. }
  752. }
  753. /** Copy storage held by <b>old</b> into a new or_options_t and return it. */
  754. static or_options_t *
  755. options_dup(or_options_t *old)
  756. {
  757. or_options_t *new;
  758. int i;
  759. struct config_line_t *line;
  760. new = tor_malloc_zero(sizeof(or_options_t));
  761. for (i=0; config_vars[i].name; ++i) {
  762. line = config_get_assigned_option(old, config_vars[i].name);
  763. if (line) {
  764. if (config_assign(new, line, 0) < 0) {
  765. log_fn(LOG_WARN,"Bug: config_get_assigned_option() generated "
  766. "something we couldn't config_assign().");
  767. tor_assert(0);
  768. }
  769. }
  770. config_free_lines(line);
  771. }
  772. return new;
  773. }
  774. /** Set <b>options</b> to hold reasonable defaults for most options.
  775. * Each option defaults to zero. */
  776. void
  777. options_init(or_options_t *options)
  778. {
  779. int i;
  780. config_var_t *var;
  781. for (i=0; config_vars[i].name; ++i) {
  782. var = &config_vars[i];
  783. if(!var->initvalue)
  784. continue; /* defaults to NULL or 0 */
  785. option_reset(options, var);
  786. }
  787. }
  788. /** Return 0 if every setting in <b>options</b> is reasonable. Else
  789. * warn and return -1. Should have no side effects, except for
  790. * normalizing the contents of <b>options</b>. */
  791. static int
  792. options_validate(or_options_t *options)
  793. {
  794. int i;
  795. int result = 0;
  796. struct config_line_t *cl;
  797. if (options->ORPort < 0 || options->ORPort > 65535) {
  798. log(LOG_WARN, "ORPort option out of bounds.");
  799. result = -1;
  800. }
  801. if (options->Nickname == NULL) {
  802. if (server_mode(options)) {
  803. if (!(options->Nickname = get_default_nickname()))
  804. return -1;
  805. log_fn(LOG_NOTICE, "Choosing default nickname %s", options->Nickname);
  806. }
  807. } else {
  808. if (strspn(options->Nickname, LEGAL_NICKNAME_CHARACTERS) !=
  809. strlen(options->Nickname)) {
  810. log_fn(LOG_WARN, "Nickname '%s' contains illegal characters.", options->Nickname);
  811. result = -1;
  812. }
  813. if (strlen(options->Nickname) == 0) {
  814. log_fn(LOG_WARN, "Nickname must have at least one character");
  815. result = -1;
  816. }
  817. if (strlen(options->Nickname) > MAX_NICKNAME_LEN) {
  818. log_fn(LOG_WARN, "Nickname '%s' has more than %d characters.",
  819. options->Nickname, MAX_NICKNAME_LEN);
  820. result = -1;
  821. }
  822. }
  823. if (normalize_log_options(options))
  824. return -1;
  825. /* Special case if no options are given. */
  826. if (!options->Logs) {
  827. options->Logs = config_line_prepend(NULL, "Log", "notice-err stdout");
  828. }
  829. if (server_mode(options)) {
  830. /* confirm that our address isn't broken, so we can complain now */
  831. uint32_t tmp;
  832. if (resolve_my_address(options->Address, &tmp) < 0)
  833. result = -1;
  834. }
  835. if (options->SocksPort < 0 || options->SocksPort > 65535) {
  836. log(LOG_WARN, "SocksPort option out of bounds.");
  837. result = -1;
  838. }
  839. if (options->SocksPort == 0 && options->ORPort == 0) {
  840. log(LOG_WARN, "SocksPort and ORPort are both undefined? Quitting.");
  841. result = -1;
  842. }
  843. if (options->ControlPort < 0 || options->ControlPort > 65535) {
  844. log(LOG_WARN, "ControlPort option out of bounds.");
  845. result = -1;
  846. }
  847. if (options->DirPort < 0 || options->DirPort > 65535) {
  848. log(LOG_WARN, "DirPort option out of bounds.");
  849. result = -1;
  850. }
  851. if (options->StrictExitNodes &&
  852. (!options->ExitNodes || !strlen(options->ExitNodes))) {
  853. log(LOG_WARN, "StrictExitNodes set, but no ExitNodes listed.");
  854. }
  855. if (options->StrictEntryNodes &&
  856. (!options->EntryNodes || !strlen(options->EntryNodes))) {
  857. log(LOG_WARN, "StrictEntryNodes set, but no EntryNodes listed.");
  858. }
  859. if (options->AuthoritativeDir && options->RecommendedVersions == NULL) {
  860. log(LOG_WARN, "Directory servers must configure RecommendedVersions.");
  861. result = -1;
  862. }
  863. if (options->AuthoritativeDir && !options->DirPort) {
  864. log(LOG_WARN, "Running as authoritative directory, but no DirPort set.");
  865. result = -1;
  866. }
  867. if (options->AuthoritativeDir && !options->ORPort) {
  868. log(LOG_WARN, "Running as authoritative directory, but no ORPort set.");
  869. result = -1;
  870. }
  871. if (options->AuthoritativeDir && options->ClientOnly) {
  872. log(LOG_WARN, "Running as authoritative directory, but ClientOnly also set.");
  873. result = -1;
  874. }
  875. if (options->FirewallPorts) {
  876. SMARTLIST_FOREACH(options->FirewallPorts, const char *, cp,
  877. {
  878. i = atoi(cp);
  879. if (i < 1 || i > 65535) {
  880. log(LOG_WARN, "Port '%s' out of range in FirewallPorts", cp);
  881. result=-1;
  882. }
  883. });
  884. }
  885. options->_AllowUnverified = 0;
  886. if (options->AllowUnverifiedNodes) {
  887. SMARTLIST_FOREACH(options->AllowUnverifiedNodes, const char *, cp, {
  888. if (!strcasecmp(cp, "entry"))
  889. options->_AllowUnverified |= ALLOW_UNVERIFIED_ENTRY;
  890. else if (!strcasecmp(cp, "exit"))
  891. options->_AllowUnverified |= ALLOW_UNVERIFIED_EXIT;
  892. else if (!strcasecmp(cp, "middle"))
  893. options->_AllowUnverified |= ALLOW_UNVERIFIED_MIDDLE;
  894. else if (!strcasecmp(cp, "introduction"))
  895. options->_AllowUnverified |= ALLOW_UNVERIFIED_INTRODUCTION;
  896. else if (!strcasecmp(cp, "rendezvous"))
  897. options->_AllowUnverified |= ALLOW_UNVERIFIED_RENDEZVOUS;
  898. else {
  899. log(LOG_WARN, "Unrecognized value '%s' in AllowUnverifiedNodes",
  900. cp);
  901. result=-1;
  902. }
  903. });
  904. }
  905. if (options->SocksPort >= 1 &&
  906. (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0)) {
  907. log(LOG_WARN, "PathlenCoinWeight option must be >=0.0 and <1.0.");
  908. result = -1;
  909. }
  910. if (options->MaxConn < 1) {
  911. log(LOG_WARN, "MaxConn option must be a non-zero positive integer.");
  912. result = -1;
  913. }
  914. if (options->MaxConn >= MAXCONNECTIONS) {
  915. log(LOG_WARN, "MaxConn option must be less than %d.", MAXCONNECTIONS);
  916. result = -1;
  917. }
  918. #define MIN_DIRFETCHPOSTPERIOD 60
  919. if (options->DirFetchPostPeriod < MIN_DIRFETCHPOSTPERIOD) {
  920. log(LOG_WARN, "DirFetchPostPeriod option must be at least %d.", MIN_DIRFETCHPOSTPERIOD);
  921. result = -1;
  922. }
  923. if (options->DirFetchPostPeriod > MIN_ONION_KEY_LIFETIME / 2) {
  924. log(LOG_WARN, "DirFetchPostPeriod is too large; clipping.");
  925. options->DirFetchPostPeriod = MIN_ONION_KEY_LIFETIME / 2;
  926. }
  927. if (options->KeepalivePeriod < 1) {
  928. log(LOG_WARN,"KeepalivePeriod option must be positive.");
  929. result = -1;
  930. }
  931. if (options->AccountingStart < 0 || options->AccountingStart > 31) {
  932. log(LOG_WARN,"Monthly accounting must start on a day of the month, and no months have %d days.",
  933. options->AccountingStart);
  934. result = -1;
  935. } else if (options->AccountingStart > 28) {
  936. log(LOG_WARN,"Not every month has %d days.",options->AccountingStart);
  937. result = -1;
  938. }
  939. if (options->HttpProxy) { /* parse it now */
  940. if (parse_addr_port(options->HttpProxy, NULL,
  941. &options->HttpProxyAddr, &options->HttpProxyPort) < 0) {
  942. log(LOG_WARN,"HttpProxy failed to parse or resolve. Please fix.");
  943. result = -1;
  944. }
  945. if (options->HttpProxyPort == 0) { /* give it a default */
  946. options->HttpProxyPort = 80;
  947. }
  948. }
  949. if (check_nickname_list(options->ExitNodes, "ExitNodes"))
  950. result = -1;
  951. if (check_nickname_list(options->EntryNodes, "EntryNodes"))
  952. result = -1;
  953. if (check_nickname_list(options->ExcludeNodes, "ExcludeNodes"))
  954. result = -1;
  955. if (check_nickname_list(options->RendNodes, "RendNodes"))
  956. result = -1;
  957. if (check_nickname_list(options->RendNodes, "RendExcludeNodes"))
  958. result = -1;
  959. if (check_nickname_list(options->MyFamily, "MyFamily"))
  960. result = -1;
  961. for (cl = options->NodeFamilies; cl; cl = cl->next) {
  962. if (check_nickname_list(cl->value, "NodeFamily"))
  963. result = -1;
  964. }
  965. /* free options->RedirectExitList */
  966. if (options->RedirectExitList) {
  967. SMARTLIST_FOREACH(options->RedirectExitList,
  968. exit_redirect_t *, p, tor_free(p));
  969. smartlist_free(options->RedirectExitList);
  970. }
  971. options->RedirectExitList = smartlist_create();
  972. for (cl = options->RedirectExit; cl; cl = cl->next) {
  973. if (parse_redirect_line(options, cl)<0)
  974. result = -1;
  975. }
  976. if (!options->DirServers) {
  977. add_default_trusted_dirservers(options);
  978. } else {
  979. for (cl = options->DirServers; cl; cl = cl->next) {
  980. if (parse_dir_server_line(cl->value, 1)<0)
  981. result = -1;
  982. }
  983. }
  984. if (rend_config_services(options, 1) < 0)
  985. result = -1;
  986. return result;
  987. }
  988. /** Check if any of the previous options have changed but aren't allowed to. */
  989. static int
  990. options_transition_allowed(or_options_t *old, or_options_t *new) {
  991. if(!old)
  992. return 0;
  993. if (old->PidFile &&
  994. (!new->PidFile || strcmp(old->PidFile,new->PidFile))) {
  995. log_fn(LOG_WARN,"PidFile is not allowed to change. Failing.");
  996. return -1;
  997. }
  998. if (old->RunAsDaemon && !new->RunAsDaemon) {
  999. log_fn(LOG_WARN,"During reload, change from RunAsDaemon=1 to =0 not allowed. Failing.");
  1000. return -1;
  1001. }
  1002. if (old->ORPort != new->ORPort) {
  1003. log_fn(LOG_WARN,"During reload, changing ORPort is not allowed. Failing.");
  1004. return -1;
  1005. }
  1006. return 0;
  1007. }
  1008. #ifdef MS_WINDOWS
  1009. /** Return the directory on windows where we expect to find our application
  1010. * data. */
  1011. static char *get_windows_conf_root(void)
  1012. {
  1013. static int is_set = 0;
  1014. static char path[MAX_PATH+1];
  1015. LPITEMIDLIST idl;
  1016. IMalloc *m;
  1017. HRESULT result;
  1018. if (is_set)
  1019. return path;
  1020. /* Find X:\documents and settings\username\applicatation data\ .
  1021. * We would use SHGetSpecialFolder path, but that wasn't added until IE4.
  1022. */
  1023. if (!SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA,
  1024. &idl))) {
  1025. GetCurrentDirectory(MAX_PATH, path);
  1026. is_set = 1;
  1027. log_fn(LOG_WARN, "I couldn't find your application data folder: are you running an ancient version of Windows 95? Defaulting to '%s'", path);
  1028. return path;
  1029. }
  1030. /* Convert the path from an "ID List" (whatever that is!) to a path. */
  1031. result = SHGetPathFromIDList(idl, path);
  1032. /* Now we need to free the */
  1033. SHGetMalloc(&m);
  1034. if (m) {
  1035. m->lpVtbl->Free(m, idl);
  1036. m->lpVtbl->Release(m);
  1037. }
  1038. if (!SUCCEEDED(result)) {
  1039. return NULL;
  1040. }
  1041. strlcat(path,"\\tor",MAX_PATH);
  1042. is_set = 1;
  1043. return path;
  1044. }
  1045. #endif
  1046. /** Return the default location for our torrc file. */
  1047. static char *
  1048. get_default_conf_file(void)
  1049. {
  1050. #ifdef MS_WINDOWS
  1051. char *path = tor_malloc(MAX_PATH);
  1052. strlcpy(path, get_windows_conf_root(), MAX_PATH);
  1053. strlcat(path,"\\torrc",MAX_PATH);
  1054. return path;
  1055. #else
  1056. return tor_strdup(CONFDIR "/torrc");
  1057. #endif
  1058. }
  1059. /** Verify whether lst is a string containing valid-looking space-separated
  1060. * nicknames, or NULL. Return 0 on success. Warn and return -1 on failure.
  1061. */
  1062. static int check_nickname_list(const char *lst, const char *name)
  1063. {
  1064. int r = 0;
  1065. smartlist_t *sl;
  1066. if (!lst)
  1067. return 0;
  1068. sl = smartlist_create();
  1069. smartlist_split_string(sl, lst, ",", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  1070. SMARTLIST_FOREACH(sl, const char *, s,
  1071. {
  1072. if (!is_legal_nickname_or_hexdigest(s)) {
  1073. log_fn(LOG_WARN, "Invalid nickname '%s' in %s line", s, name);
  1074. r = -1;
  1075. }
  1076. });
  1077. SMARTLIST_FOREACH(sl, char *, s, tor_free(s));
  1078. smartlist_free(sl);
  1079. return r;
  1080. }
  1081. /** Read a configuration file into <b>options</b>, finding the configuration
  1082. * file location based on the command line. After loading the options,
  1083. * validate them for consistency. Return 0 if success, <0 if failure. */
  1084. int
  1085. getconfig(int argc, char **argv)
  1086. {
  1087. or_options_t *oldoptions, *newoptions;
  1088. struct config_line_t *cl;
  1089. char *cf=NULL, *fname=NULL;
  1090. int i, retval;
  1091. int using_default_torrc;
  1092. static char **backup_argv;
  1093. static int backup_argc;
  1094. /* we don't use get_options() here, since it's null on the first call */
  1095. oldoptions = global_options;
  1096. if (argv) { /* first time we're called. save commandline args */
  1097. backup_argv = argv;
  1098. backup_argc = argc;
  1099. } else { /* we're reloading. need to clean up old options first. */
  1100. argv = backup_argv;
  1101. argc = backup_argc;
  1102. }
  1103. if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
  1104. print_usage();
  1105. exit(0);
  1106. }
  1107. if (argc > 1 && (!strcmp(argv[1],"--version"))) {
  1108. printf("Tor version %s.\n",VERSION);
  1109. exit(0);
  1110. }
  1111. newoptions = tor_malloc_zero(sizeof(or_options_t));
  1112. options_init(newoptions);
  1113. /* learn config file name, get config lines, assign them */
  1114. fname = NULL;
  1115. using_default_torrc = 1;
  1116. newoptions->command = CMD_RUN_TOR;
  1117. for (i = 1; i < argc; ++i) {
  1118. if (i < argc-1 && !strcmp(argv[i],"-f")) {
  1119. if (fname) {
  1120. log(LOG_WARN, "Duplicate -f options on command line.");
  1121. tor_free(fname);
  1122. }
  1123. fname = tor_strdup(argv[i+1]);
  1124. using_default_torrc = 0;
  1125. ++i;
  1126. } else if (!strcmp(argv[i],"--list-fingerprint")) {
  1127. newoptions->command = CMD_LIST_FINGERPRINT;
  1128. } else if (!strcmp(argv[i],"--hash-password")) {
  1129. newoptions->command = CMD_HASH_PASSWORD;
  1130. newoptions->command_arg = tor_strdup( (i < argc-1) ? argv[i+1] : "");
  1131. ++i;
  1132. }
  1133. }
  1134. if (using_default_torrc) {
  1135. /* didn't find one, try CONFDIR */
  1136. char *fn;
  1137. fn = get_default_conf_file();
  1138. if (fn && file_status(fn) == FN_FILE) {
  1139. fname = fn;
  1140. } else {
  1141. tor_free(fn);
  1142. fn = expand_filename("~/.torrc");
  1143. if (fn && file_status(fn) == FN_FILE) {
  1144. fname = fn;
  1145. } else {
  1146. tor_free(fn);
  1147. fname = get_default_conf_file();
  1148. }
  1149. }
  1150. }
  1151. tor_assert(fname);
  1152. log(LOG_DEBUG, "Opening config file '%s'", fname);
  1153. cf = read_file_to_str(fname, 0);
  1154. if (!cf) {
  1155. if (using_default_torrc == 1) {
  1156. log(LOG_NOTICE, "Configuration file '%s' not present, "
  1157. "using reasonable defaults.", fname);
  1158. tor_free(fname);
  1159. } else {
  1160. log(LOG_WARN, "Unable to open configuration file '%s'.", fname);
  1161. tor_free(fname);
  1162. goto err;
  1163. }
  1164. } else { /* it opened successfully. use it. */
  1165. tor_free(fname);
  1166. retval = config_get_lines(cf, &cl);
  1167. tor_free(cf);
  1168. if (retval < 0)
  1169. goto err;
  1170. retval = config_assign(newoptions, cl, 0);
  1171. config_free_lines(cl);
  1172. if (retval < 0)
  1173. goto err;
  1174. }
  1175. /* go through command-line variables too */
  1176. cl = config_get_commandlines(argc,argv);
  1177. retval = config_assign(newoptions,cl,0);
  1178. config_free_lines(cl);
  1179. if (retval < 0)
  1180. goto err;
  1181. /* Validate newoptions */
  1182. if (options_validate(newoptions) < 0)
  1183. goto err;
  1184. if (options_transition_allowed(oldoptions, newoptions) < 0)
  1185. goto err;
  1186. set_options(newoptions);
  1187. return 0;
  1188. err:
  1189. options_free(newoptions);
  1190. return -1;
  1191. }
  1192. /** If <b>range</b> is of the form MIN-MAX, for MIN and MAX both
  1193. * recognized log severity levels, set *<b>min_out</b> to MIN and
  1194. * *<b>max_out</b> to MAX and return 0. Else, if <b>range<b> is of
  1195. * the form MIN, act as if MIN-err had been specified. Else, warn and
  1196. * return -1.
  1197. */
  1198. static int
  1199. parse_log_severity_range(const char *range, int *min_out, int *max_out)
  1200. {
  1201. int levelMin, levelMax;
  1202. const char *cp;
  1203. cp = strchr(range, '-');
  1204. if (cp) {
  1205. if (cp == range) {
  1206. levelMin = LOG_DEBUG;
  1207. } else {
  1208. char *tmp_sev = tor_strndup(range, cp - range);
  1209. levelMin = parse_log_level(tmp_sev);
  1210. if (levelMin < 0) {
  1211. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
  1212. "err|warn|notice|info|debug", tmp_sev);
  1213. tor_free(tmp_sev);
  1214. return -1;
  1215. }
  1216. tor_free(tmp_sev);
  1217. }
  1218. if (!*(cp+1)) {
  1219. levelMax = LOG_ERR;
  1220. } else {
  1221. levelMax = parse_log_level(cp+1);
  1222. if (levelMax < 0) {
  1223. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
  1224. "err|warn|notice|info|debug", cp+1);
  1225. return -1;
  1226. }
  1227. }
  1228. } else {
  1229. levelMin = parse_log_level(range);
  1230. if (levelMin < 0) {
  1231. log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
  1232. "err|warn|notice|info|debug", range);
  1233. return -1;
  1234. }
  1235. levelMax = LOG_ERR;
  1236. }
  1237. *min_out = levelMin;
  1238. *max_out = levelMax;
  1239. return 0;
  1240. }
  1241. /** Try to convert a pair of old-style logging options [LogLevel, and
  1242. * (LogFile/Syslog)] to a new-style option, and add the new option to
  1243. * options->Logs. */
  1244. static int
  1245. convert_log_option(or_options_t *options, struct config_line_t *level_opt,
  1246. struct config_line_t *file_opt, int isDaemon)
  1247. {
  1248. int levelMin = -1, levelMax = -1;
  1249. if (level_opt) {
  1250. if (parse_log_severity_range(level_opt->value, &levelMin, &levelMax))
  1251. return -1;
  1252. }
  1253. if (levelMin < 0 && levelMax < 0) {
  1254. levelMin = LOG_NOTICE;
  1255. levelMax = LOG_ERR;
  1256. } else if (levelMin < 0) {
  1257. levelMin = levelMax;
  1258. } else {
  1259. levelMax = LOG_ERR;
  1260. }
  1261. if (file_opt && !strcasecmp(file_opt->key, "LogFile")) {
  1262. if (add_single_log_option(options, levelMin, levelMax, "file", file_opt->value) < 0) {
  1263. log_fn(LOG_WARN, "Cannot write to LogFile '%s': %s.", file_opt->value,
  1264. strerror(errno));
  1265. return -1;
  1266. }
  1267. } else if (file_opt && !strcasecmp(file_opt->key, "SysLog")) {
  1268. if (add_single_log_option(options, levelMin, levelMax, "syslog", NULL) < 0)
  1269. return -1;
  1270. } else if (!isDaemon) {
  1271. add_single_log_option(options, levelMin, levelMax, "stdout", NULL);
  1272. }
  1273. return 0;
  1274. }
  1275. /**
  1276. * Initialize the logs based on the configuration file.
  1277. */
  1278. int
  1279. config_init_logs(or_options_t *options)
  1280. {
  1281. struct config_line_t *opt;
  1282. int ok;
  1283. smartlist_t *elts;
  1284. ok = 1;
  1285. elts = smartlist_create();
  1286. for (opt = options->Logs; opt; opt = opt->next) {
  1287. int levelMin=LOG_DEBUG, levelMax=LOG_ERR;
  1288. smartlist_split_string(elts, opt->value, " ",
  1289. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 3);
  1290. if (smartlist_len(elts) == 0) {
  1291. log_fn(LOG_WARN, "Bad syntax on Log option 'Log %s'", opt->value);
  1292. ok = 0; goto cleanup;
  1293. }
  1294. if (parse_log_severity_range(smartlist_get(elts,0), &levelMin, &levelMax)) {
  1295. ok = 0; goto cleanup;
  1296. }
  1297. if (smartlist_len(elts) < 2) { /* only loglevels were provided */
  1298. add_stream_log(levelMin, levelMax, "<stdout>", stdout);
  1299. goto cleanup;
  1300. }
  1301. if (!strcasecmp(smartlist_get(elts,1), "file")) {
  1302. if (smartlist_len(elts) != 3) {
  1303. log_fn(LOG_WARN, "Bad syntax on Log option 'Log %s'", opt->value);
  1304. ok = 0; goto cleanup;
  1305. }
  1306. add_file_log(levelMin, levelMax, smartlist_get(elts, 2));
  1307. goto cleanup;
  1308. }
  1309. if (smartlist_len(elts) != 2) {
  1310. log_fn(LOG_WARN, "Bad syntax on Log option 'Log %s'", opt->value);
  1311. ok = 0; goto cleanup;
  1312. }
  1313. if (!strcasecmp(smartlist_get(elts,1), "stdout")) {
  1314. add_stream_log(levelMin, levelMax, "<stdout>", stdout);
  1315. close_temp_logs();
  1316. } else if (!strcasecmp(smartlist_get(elts,1), "stderr")) {
  1317. add_stream_log(levelMin, levelMax, "<stderr>", stderr);
  1318. close_temp_logs();
  1319. } else if (!strcasecmp(smartlist_get(elts,1), "syslog")) {
  1320. #ifdef HAVE_SYSLOG_H
  1321. add_syslog_log(levelMin, levelMax);
  1322. #else
  1323. log_fn(LOG_WARN, "Syslog is not supported in this compilation.");
  1324. #endif
  1325. }
  1326. cleanup:
  1327. SMARTLIST_FOREACH(elts, char*, cp, tor_free(cp));
  1328. smartlist_clear(elts);
  1329. }
  1330. smartlist_free(elts);
  1331. close_temp_logs();
  1332. return ok?0:-1;
  1333. }
  1334. /** Add a single option of the form Log min-max <type> [fname] to options. */
  1335. static int
  1336. add_single_log_option(or_options_t *options, int minSeverity, int maxSeverity,
  1337. const char *type, const char *fname)
  1338. {
  1339. char buf[512];
  1340. int n;
  1341. n = tor_snprintf(buf, sizeof(buf), "%s-%s %s%s%s",
  1342. log_level_to_string(minSeverity),
  1343. log_level_to_string(maxSeverity),
  1344. type, fname?" ":"", fname?fname:"");
  1345. if (n<0) {
  1346. log_fn(LOG_WARN, "Normalized log option too long.");
  1347. return -1;
  1348. }
  1349. log_fn(LOG_WARN, "The old LogLevel/LogFile/DebugLogFile/SysLog options are deprecated, and will go away soon. New format: 'Log %s'", buf);
  1350. options->Logs = config_line_prepend(options->Logs, "Log", buf);
  1351. return 0;
  1352. }
  1353. /** Convert all old-style logging options to new-style Log options. Return 0
  1354. * on success, -1 on faulure. */
  1355. static int
  1356. normalize_log_options(or_options_t *options)
  1357. {
  1358. /* The order of options is: Level? (File Level?)+
  1359. */
  1360. struct config_line_t *opt = options->OldLogOptions;
  1361. /* Special case for if first option is LogLevel. */
  1362. if (opt && !strcasecmp(opt->key, "LogLevel")) {
  1363. if (opt->next && (!strcasecmp(opt->next->key, "LogFile") ||
  1364. !strcasecmp(opt->next->key, "SysLog"))) {
  1365. if (convert_log_option(options, opt, opt->next, options->RunAsDaemon) < 0)
  1366. return -1;
  1367. opt = opt->next->next;
  1368. } else if (!opt->next) {
  1369. if (convert_log_option(options, opt, NULL, options->RunAsDaemon) < 0)
  1370. return -1;
  1371. opt = opt->next;
  1372. } else {
  1373. ; /* give warning below */
  1374. }
  1375. }
  1376. while (opt) {
  1377. if (!strcasecmp(opt->key, "LogLevel")) {
  1378. log_fn(LOG_WARN, "Two LogLevel options in a row without intervening LogFile or SysLog");
  1379. opt = opt->next;
  1380. } else {
  1381. tor_assert(!strcasecmp(opt->key, "LogFile") ||
  1382. !strcasecmp(opt->key, "SysLog"));
  1383. if (opt->next && !strcasecmp(opt->next->key, "LogLevel")) {
  1384. /* LogFile/SysLog followed by LogLevel */
  1385. if (convert_log_option(options,opt->next,opt, options->RunAsDaemon) < 0)
  1386. return -1;
  1387. opt = opt->next->next;
  1388. } else {
  1389. /* LogFile/SysLog followed by LogFile/SysLog or end of list. */
  1390. if (convert_log_option(options,NULL, opt, options->RunAsDaemon) < 0)
  1391. return -1;
  1392. opt = opt->next;
  1393. }
  1394. }
  1395. }
  1396. if (options->DebugLogFile) {
  1397. if (add_single_log_option(options, LOG_DEBUG, LOG_ERR, "file", options->DebugLogFile) < 0)
  1398. return -1;
  1399. }
  1400. tor_free(options->DebugLogFile);
  1401. config_free_lines(options->OldLogOptions);
  1402. options->OldLogOptions = NULL;
  1403. return 0;
  1404. }
  1405. /**
  1406. * Given a linked list of config lines containing "allow" and "deny" tokens,
  1407. * parse them and place the result in <b>dest</b>. Skip malformed lines.
  1408. */
  1409. void
  1410. config_parse_exit_policy(struct config_line_t *cfg,
  1411. struct exit_policy_t **dest)
  1412. {
  1413. struct exit_policy_t **nextp;
  1414. smartlist_t *entries;
  1415. if (!cfg)
  1416. return;
  1417. nextp = dest;
  1418. while (*nextp)
  1419. nextp = &((*nextp)->next);
  1420. entries = smartlist_create();
  1421. for (; cfg; cfg = cfg->next) {
  1422. smartlist_split_string(entries, cfg->value, ",", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  1423. SMARTLIST_FOREACH(entries, const char *, ent,
  1424. {
  1425. log_fn(LOG_DEBUG,"Adding new entry '%s'",ent);
  1426. *nextp = router_parse_exit_policy_from_string(ent);
  1427. if (*nextp) {
  1428. nextp = &((*nextp)->next);
  1429. } else {
  1430. log_fn(LOG_WARN,"Malformed exit policy %s; skipping.", ent);
  1431. }
  1432. });
  1433. SMARTLIST_FOREACH(entries, char *, ent, tor_free(ent));
  1434. smartlist_clear(entries);
  1435. }
  1436. smartlist_free(entries);
  1437. }
  1438. /** Release all storage held by <b>p</b> */
  1439. void
  1440. exit_policy_free(struct exit_policy_t *p) {
  1441. struct exit_policy_t *e;
  1442. while (p) {
  1443. e = p;
  1444. p = p->next;
  1445. tor_free(e->string);
  1446. tor_free(e);
  1447. }
  1448. }
  1449. /** Parse a single RedirectExit line's contents from <b>line</b>. If they are
  1450. * valid, add an element to <b>options</b>-&gt;RedirectExitList and return 0.
  1451. * Else return -1. */
  1452. static int
  1453. parse_redirect_line(or_options_t *options, struct config_line_t *line)
  1454. {
  1455. smartlist_t *elements = NULL;
  1456. exit_redirect_t *r;
  1457. tor_assert(options);
  1458. tor_assert(options->RedirectExitList);
  1459. tor_assert(line);
  1460. r = tor_malloc_zero(sizeof(exit_redirect_t));
  1461. elements = smartlist_create();
  1462. smartlist_split_string(elements, line->value, " ",
  1463. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  1464. if (smartlist_len(elements) != 2) {
  1465. log_fn(LOG_WARN, "Wrong number of elements in RedirectExit line");
  1466. goto err;
  1467. }
  1468. if (parse_addr_and_port_range(smartlist_get(elements,0),&r->addr,&r->mask,
  1469. &r->port_min,&r->port_max)) {
  1470. log_fn(LOG_WARN, "Error parsing source address in RedirectExit line");
  1471. goto err;
  1472. }
  1473. if (0==strcasecmp(smartlist_get(elements,1), "pass")) {
  1474. r->is_redirect = 0;
  1475. } else {
  1476. if (parse_addr_port(smartlist_get(elements,1),NULL,&r->addr_dest,
  1477. &r->port_dest)) {
  1478. log_fn(LOG_WARN, "Error parsing dest address in RedirectExit line");
  1479. goto err;
  1480. }
  1481. r->is_redirect = 1;
  1482. }
  1483. goto done;
  1484. err:
  1485. tor_free(r);
  1486. done:
  1487. SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
  1488. smartlist_free(elements);
  1489. if (r) {
  1490. smartlist_add(options->RedirectExitList, r);
  1491. return 0;
  1492. } else {
  1493. return -1;
  1494. }
  1495. }
  1496. /** Read the contents of a DirServer line from <b>line</b>. Return 0
  1497. * if the line is well-formed, and 0 if it isn't. If
  1498. * <b>validate_only</b> is 0, and the line is well-formed, then add
  1499. * the dirserver desribed in the line as a valid server. */
  1500. static int
  1501. parse_dir_server_line(const char *line, int validate_only)
  1502. {
  1503. smartlist_t *items = NULL;
  1504. int r;
  1505. char *addrport, *address=NULL;
  1506. uint16_t port;
  1507. char digest[DIGEST_LEN];
  1508. items = smartlist_create();
  1509. smartlist_split_string(items, line, " ",
  1510. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
  1511. if (smartlist_len(items) < 2) {
  1512. log_fn(LOG_WARN, "Too few arguments to DirServer line.");
  1513. goto err;
  1514. }
  1515. addrport = smartlist_get(items, 0);
  1516. if (parse_addr_port(addrport, &address, NULL, &port)<0) {
  1517. log_fn(LOG_WARN, "Error parsing DirServer address '%s'", addrport);
  1518. goto err;
  1519. }
  1520. if (!port) {
  1521. log_fn(LOG_WARN, "Missing port in DirServe address '%s'",addrport);
  1522. goto err;
  1523. }
  1524. tor_strstrip(smartlist_get(items, 1), " ");
  1525. if (strlen(smartlist_get(items, 1)) != HEX_DIGEST_LEN) {
  1526. log_fn(LOG_WARN, "Key digest for DirServer is wrong length.");
  1527. goto err;
  1528. }
  1529. if (base16_decode(digest, DIGEST_LEN,
  1530. smartlist_get(items,1), HEX_DIGEST_LEN)<0) {
  1531. log_fn(LOG_WARN, "Unable to decode DirServer key digest.");
  1532. goto err;
  1533. }
  1534. if (!validate_only) {
  1535. log_fn(LOG_DEBUG, "Trusted dirserver at %s:%d (%s)", address, (int)port,
  1536. (char*)smartlist_get(items,1));
  1537. add_trusted_dir_server(address, port, digest);
  1538. }
  1539. r = 0;
  1540. goto done;
  1541. err:
  1542. r = -1;
  1543. done:
  1544. SMARTLIST_FOREACH(items, char*, s, tor_free(s));
  1545. smartlist_free(items);
  1546. tor_free(address);
  1547. return r;
  1548. }
  1549. /** Return the place where we are currently configured to store and read all
  1550. * of our persistant data. */
  1551. const char *
  1552. get_data_directory(void)
  1553. {
  1554. const char *d;
  1555. or_options_t *options = get_options();
  1556. if (options->DataDirectory) {
  1557. d = options->DataDirectory;
  1558. } else {
  1559. #ifdef MS_WINDOWS
  1560. char *p;
  1561. p = tor_malloc(MAX_PATH);
  1562. strlcpy(p,get_windows_conf_root(),MAX_PATH);
  1563. options->DataDirectory = p;
  1564. return p;
  1565. #else
  1566. d = "~/.tor";
  1567. #endif
  1568. }
  1569. if (d && strncmp(d,"~/",2) == 0) {
  1570. char *fn = expand_filename(d);
  1571. if (!fn) {
  1572. log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.", d);
  1573. exit(1);
  1574. }
  1575. tor_free(options->DataDirectory);
  1576. options->DataDirectory = fn;
  1577. }
  1578. return options->DataDirectory;
  1579. }
  1580. /*
  1581. Local Variables:
  1582. mode:c
  1583. indent-tabs-mode:nil
  1584. c-basic-offset:2
  1585. End:
  1586. */