[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] On windows, default datadir is APPDATA/tor, and default con...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] On windows, default datadir is APPDATA/tor, and default con...
- From: nickm@seul.org (Nick Mathewson)
- Date: Tue, 17 Aug 2004 23:42:58 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Tue, 17 Aug 2004 23:43:24 -0400
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv11518/src/or
Modified Files:
config.c
Log Message:
On windows, default datadir is APPDATA/tor, and default config file is APPDATA/tor/torrc. (APPDATA is usually somedrive:/Documents and Settings/.../Application Data/)
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- config.c 17 Aug 2004 21:06:36 -0000 1.143
+++ config.c 18 Aug 2004 03:42:55 -0000 1.144
@@ -9,7 +9,10 @@
*
**/
-#include "or.h"
+#include "or.h"
+#ifdef MS_WINDOWS
+#include <shlobj.h>
+#endif
/** Enumeration of types which option values can take */
typedef enum config_type_t {
@@ -578,6 +581,21 @@
options->RendConfigLines = NULL;
options->FirewallPorts = NULL;
}
+
+static char *get_default_conf_file(void)
+{
+#ifdef MS_WINDOWS
+ char *path = tor_malloc(MAX_PATH);
+ if (!SUCCEEDED(SHGetSpecialFolderPath(NULL, path, CSIDL_APPDATA, 1))) {
+ tor_free(path);
+ return NULL;
+ }
+ strlcat(path,"\\tor\\torrc",MAX_PATH);
+ return path;
+#else
+ return tor_strdup(CONF_DIR "/torrc");
+#endif
+}
/** Read a configuration file into <b>options</b>, finding the configuration
* file location based on the command line. After loading the options,
@@ -631,19 +649,23 @@
if(i < argc-1) { /* we found one */
fname = tor_strdup(argv[i+1]);
using_default_torrc = 0;
- } else if (file_status(CONFDIR "/torrc")==FN_FILE) {
- /* didn't find one, try CONFDIR */
- fname = tor_strdup(CONFDIR "/torrc");
- using_default_torrc = 1;
- } else {
- char *fn = expand_filename("~/.torrc");
- if (fn && file_status(fn)==FN_FILE) {
- fname = fn;
- } else {
- tor_free(fn);
- fname = tor_strdup(CONFDIR "/torrc");
- }
- using_default_torrc = 1;
+ } else {
+ /* didn't find one, try CONFDIR */
+ char *fn;
+ using_default_torrc = 1;
+ fn = get_default_conf_file();
+ if (fn && file_status(fn)==FN_FILE) {
+ fname = fn;
+ } else {
+ tor_free(fn);
+ fn = expand_filename("~/.torrc");
+ if (fn && file_status(fn)==FN_FILE) {
+ fname = fn;
+ } else {
+ tor_free(fn);
+ fname = get_default_conf_file();
+ }
+ }
}
log(LOG_DEBUG,"Opening config file '%s'",fname);
@@ -1015,9 +1037,20 @@
const char *d;
if (options->DataDirectory)
d = options->DataDirectory;
- else if (server_mode())
- d = "~/.tor";
- else
+ else if (server_mode()) {
+#ifdef MS_WINDOWS
+ char *p;
+ p = tor_malloc(MAX_PATH);
+ if (!SUCCEEDED(SHGetSpecialFolderPath(NULL, p, CSIDL_APPDATA, 1))) {
+ strlcpy(p,CONFDIR, MAX_PATH);
+ }
+ strlcat(p,"\\tor",MAX_PATH);
+ options->DataDirectory = p;
+ return p;
+#else
+ d = "~/.tor";
+#endif
+ } else
d = NULL; /* XXX008 don't create datadir until we have something
we'll be putting in it */