Discussion:
[tor-dev] Default parsing order of config files in Debain tor package
iry
2017-07-02 13:42:27 UTC
Permalink
Hello, Tor developers!

With the implementation of torrc.d, there will be at least two Tor
config files and one Tor config directory by default in Debian tor
package. However, I am not able to find the documents on what the
parsing order Tor follows.

My guess is that:
1. /usr/share/tor/tor-service-defaults-torrc is parsed first
2. /etc/torrc.d is parsed next (in lexical order)
3. /etc/torrc is parsed at last
4. and the lines in config files parsed later will overwrite similar
lines in config files that are parsed earlier

Could anyone familiar with the problem help me please? This will be
really helpful to my future work and I really appreciate your help!

Thank you very much!

Best,
iry
Daniel Pinto
2017-07-02 16:25:42 UTC
Permalink
Hello iry,

The precedence for tor options is the following (1 overrides 2, etc...):

1. Command line options.
2. Configuration file options (your /etc/torrc).
3. Defaults file options (your /usr/share/tor/tor-service-defaults-torrc).

In the same file, options that appear later override earlier options.

Currently, there is no torrc.d directory created when you install the
tor package. However, you can use a %include in the configuration file
or in the defaults file. When you insert a %include in a file, it works
as if all the options for the included file or folder were written on
the line of the %include. If you're including a folder, the files will
be processed in lexicographic order and files starting with a dot will
be ignored.

Here is an example:

tor-service-defaults-torrc:
SomeOption 0
%include /etc/tor/torrc.d/ # SomeOption is now 2
SomeOption 3 # SomeOption is now 3

/etc/tor/torrc.d/01_one:
SomeOption 1

/etc/tor/torrc.d/02_two:
SomeOption 2


With this configuration, the value for some option is 3.
But we can have a torrc with %include too:

/etc/torrc:
SomeOption 4 # SomeOption is now 4
%include /etc/tor/foo.torrc # SomeOption is now 5
SomeOption 6 # SomeOption is now 6

/etc/tor/foo.torrc:
SomeOption 5

With both these files, the value for SomeOption is 6.

There are also different types of options and some can take multiple
values. For more information see the section "Mid-level semantics" on
this file: https://gitweb.torproject.org/tor.git/tree/doc/torrc_format.txt

Best regards,
Daniel
Post by iry
Hello, Tor developers!
With the implementation of torrc.d, there will be at least two Tor
config files and one Tor config directory by default in Debian tor
package. However, I am not able to find the documents on what the
parsing order Tor follows.
1. /usr/share/tor/tor-service-defaults-torrc is parsed first
2. /etc/torrc.d is parsed next (in lexical order)
3. /etc/torrc is parsed at last
4. and the lines in config files parsed later will overwrite similar
lines in config files that are parsed earlier
Could anyone familiar with the problem help me please? This will be
really helpful to my future work and I really appreciate your help!
Thank you very much!
Best,
iry
_______________________________________________
tor-dev mailing list
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev
iry
2017-07-03 01:26:58 UTC
Permalink
Hi Daniel!

Thank you so much for your immediate, detailed and informative answer.
I really like the example you offered as it clearly illustrates the
parsing order.

Your answer is very helpful for me to decide where I should place the
%include line and Tor config files. I really appreciate your help.

Best,
iry
Post by Daniel Pinto
The precedence for tor options is the following (1 overrides 2,
1. Command line options. 2. Configuration file options (your
/etc/torrc). 3. Defaults file options (your
/usr/share/tor/tor-service-defaults-torrc).
In the same file, options that appear later override earlier
options.
Currently, there is no torrc.d directory created when you install
the tor package. However, you can use a %include in the
configuration file or in the defaults file. When you insert a
%include in a file, it works as if all the options for the included
file or folder were written on the line of the %include. If you're
including a folder, the files will be processed in lexicographic
order and files starting with a dot will be ignored.
tor-service-defaults-torrc: SomeOption 0 %include /etc/tor/torrc.d/
# SomeOption is now 2 SomeOption 3 # SomeOption is now 3
/etc/tor/torrc.d/01_one: SomeOption 1
/etc/tor/torrc.d/02_two: SomeOption 2
With this configuration, the value for some option is 3. But we can
/etc/torrc: SomeOption 4 # SomeOption is now 4 %include
/etc/tor/foo.torrc # SomeOption is now 5 SomeOption 6 # SomeOption
is now 6
/etc/tor/foo.torrc: SomeOption 5
With both these files, the value for SomeOption is 6.
There are also different types of options and some can take
multiple values. For more information see the section "Mid-level
https://gitweb.torproject.org/tor.git/tree/doc/torrc_format.txt
Best regards, Daniel
Loading...