Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mike Perry
Tor
Commits
16528aa0
Commit
16528aa0
authored
Aug 10, 2005
by
Nick Mathewson
🎨
Browse files
Add a config-file GETINFO entry; fix a minor memory leak on some SAVECONF calls.
svn:r4761
parent
c031d146
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/control-spec.txt
View file @
16528aa0
...
...
@@ -294,6 +294,8 @@ $Id$
"version" -- The version of the server's software, including the name
of the software. (example: "Tor 0.0.9.4")
"config-file" -- The location of Tor's configuration file ("torrc").
"desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest server
descriptor for a given OR, NUL-terminated. If no such OR is known, the
corresponding value is an empty string.
...
...
src/or/config.c
View file @
16528aa0
...
...
@@ -322,7 +322,7 @@ static config_format_t state_format = {
/** Command-line and config-file options. */
static
or_options_t
*
global_options
=
NULL
;
/** Name of most recently read torrc file. */
static
char
*
config
_fname
=
NULL
;
static
char
*
torrc
_fname
=
NULL
;
/** Persistant serialized state. */
static
or_state_t
*
global_state
=
NULL
;
/** DOCDOC */
...
...
@@ -360,7 +360,7 @@ void
config_free_all
(
void
)
{
config_free
(
&
options_format
,
global_options
);
tor_free
(
config
_fname
);
tor_free
(
torrc
_fname
);
addr_policy_free
(
reachable_addr_policy
);
reachable_addr_policy
=
NULL
;
}
...
...
@@ -2026,16 +2026,16 @@ get_windows_conf_root(void)
#endif
/** Return the default location for our torrc file. */
static
char
*
static
const
char
*
get_default_conf_file
(
void
)
{
#ifdef MS_WINDOWS
char
*
path
=
tor_malloc
(
MAX_PATH
)
;
static
char
path
[
MAX_PATH
+
1
]
;
strlcpy
(
path
,
get_windows_conf_root
(),
MAX_PATH
);
strlcat
(
path
,
"
\\
torrc"
,
MAX_PATH
);
return
path
;
#else
return
tor_strdup
(
CONFDIR
"/torrc"
);
return
(
CONFDIR
"/torrc"
);
#endif
}
...
...
@@ -2131,22 +2131,21 @@ options_init_from_torrc(int argc, char **argv)
if
(
using_default_torrc
)
{
/* didn't find one, try CONFDIR */
c
har
*
fn
;
fn
=
get_default_conf_file
()
;
if
(
fn
&&
file_status
(
fn
)
==
FN_FILE
)
{
fname
=
fn
;
c
onst
char
*
dflt
=
get_default_conf_file
()
;
char
*
fn
=
NULL
;
if
(
dflt
&&
file_status
(
dflt
)
==
FN_FILE
)
{
fname
=
tor_strdup
(
dflt
)
;
}
else
{
tor_free
(
fn
);
#ifndef MS_WINDOWS
fn
=
expand_filename
(
"~/.torrc"
);
if
(
fn
&&
file_status
(
fn
)
==
FN_FILE
)
{
fname
=
fn
;
}
else
{
tor_free
(
fn
);
fname
=
get_default_conf_file
(
);
fname
=
tor_strdup
(
dflt
);
}
#else
fname
=
get_default_conf_file
(
);
fname
=
tor_strdup
(
dflt
);
#endif
}
}
...
...
@@ -2194,8 +2193,8 @@ options_init_from_torrc(int argc, char **argv)
log_fn
(
LOG_ERR
,
"Acting on config options left us in a broken state. Dying."
);
exit
(
1
);
}
tor_free
(
config
_fname
);
config
_fname
=
fname
;
tor_free
(
torrc
_fname
);
torrc
_fname
=
fname
;
return
0
;
err:
tor_free
(
fname
);
...
...
@@ -2203,6 +2202,18 @@ options_init_from_torrc(int argc, char **argv)
return
-
1
;
}
/** Return the location for our configuration file.
*/
const
char
*
get_torrc_fname
(
void
)
{
if
(
torrc_fname
)
return
torrc_fname
;
else
return
get_default_conf_file
();
}
/** Adjust the address map mased on the MapAddress elements in the
* configuration <b>options</b>
*/
...
...
@@ -2818,15 +2829,13 @@ write_configuration_file(const char *fname, or_options_t *options)
int
options_save_current
(
void
)
{
char
*
fn
;
if
(
config_fname
)
{
if
(
torrc_fname
)
{
/* XXX This fails if we can't write to our configuration file.
* Arguably, we should try falling back to datadirectory or something.
* But just as arguably, we shouldn't. */
return
write_configuration_file
(
config
_fname
,
get_options
());
return
write_configuration_file
(
torrc
_fname
,
get_options
());
}
fn
=
get_default_conf_file
();
return
write_configuration_file
(
fn
,
get_options
());
return
write_configuration_file
(
get_default_conf_file
(),
get_options
());
}
struct
unit_table_t
{
...
...
src/or/control.c
View file @
16528aa0
...
...
@@ -1150,6 +1150,8 @@ handle_getinfo_helper(const char *question, char **answer)
*
answer
=
NULL
;
/* unrecognized key by default */
if
(
!
strcmp
(
question
,
"version"
))
{
*
answer
=
tor_strdup
(
VERSION
);
}
else
if
(
!
strcmp
(
question
,
"config-file"
))
{
*
answer
=
tor_strdup
(
get_torrc_fname
());
}
else
if
(
!
strcmpstart
(
question
,
"accounting/"
))
{
return
accounting_getinfo_helper
(
question
,
answer
);
}
else
if
(
!
strcmpstart
(
question
,
"helper-nodes"
))
{
...
...
src/or/or.h
View file @
16528aa0
...
...
@@ -1376,6 +1376,7 @@ config_line_t *option_get_assignment(or_options_t *options,
const
char
*
key
);
char
*
options_dump
(
or_options_t
*
options
,
int
minimal
);
int
options_save_current
(
void
);
const
char
*
get_torrc_fname
(
void
);
or_state_t
*
get_or_state
(
void
);
int
or_state_load
(
void
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment