diff --git a/Win32Build/or/or.dsp b/Win32Build/or/or.dsp index 77bbf8916b..7378ac7d8a 100644 --- a/Win32Build/or/or.dsp +++ b/Win32Build/or/or.dsp @@ -74,7 +74,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib libeay32.lib ssleay32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"d:\openssl\lib\vc" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib libeay32.lib ssleay32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/tor.exe" /pdbtype:sept /libpath:"d:\openssl\lib\vc" !ENDIF @@ -111,19 +111,15 @@ SOURCE=..\..\src\or\connection.c # End Source File # Begin Source File -SOURCE=..\..\src\or\connection_ap.c -# End Source File -# Begin Source File - SOURCE=..\..\src\or\connection_edge.c # End Source File # Begin Source File -SOURCE=..\..\src\or\connection_exit.c +SOURCE=..\..\src\or\connection_or.c # End Source File # Begin Source File -SOURCE=..\..\src\or\connection_or.c +SOURCE=..\..\src\or\cpuworker.c # End Source File # Begin Source File @@ -135,6 +131,10 @@ SOURCE=..\..\src\or\directory.c # End Source File # Begin Source File +SOURCE=..\..\src\or\dirserv.c +# End Source File +# Begin Source File + SOURCE=..\..\src\or\dns.c # End Source File # Begin Source File @@ -155,7 +155,11 @@ SOURCE=..\..\src\or\onion.c # End Source File # Begin Source File -SOURCE=..\..\src\or\routers.c +SOURCE=..\..\src\or\router.c +# End Source File +# Begin Source File + +SOURCE=..\..\src\or\routerlist.c # End Source File # Begin Source File @@ -163,6 +167,10 @@ SOURCE=..\..\src\or\tor_main.c # End Source File # Begin Source File +SOURCE=..\..\src\common\tortls.c +# End Source File +# Begin Source File + SOURCE=..\..\src\common\util.c # End Source File # End Group @@ -203,6 +211,10 @@ SOURCE=..\..\src\common\torint.h # End Source File # Begin Source File +SOURCE=..\..\src\common\tortls.h +# End Source File +# Begin Source File + SOURCE=..\..\src\or\tree.h # End Source File # Begin Source File diff --git a/Win32Build/tor/tor.ncb b/Win32Build/tor/tor.ncb index 535305ac99..fadbcf1e50 100644 Binary files a/Win32Build/tor/tor.ncb and b/Win32Build/tor/tor.ncb differ diff --git a/Win32Build/tor/tor.opt b/Win32Build/tor/tor.opt index 8ae08d4288..0b4de68766 100644 Binary files a/Win32Build/tor/tor.opt and b/Win32Build/tor/tor.opt differ diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c index 4465b5101e..8b9242e050 100644 --- a/src/common/fakepoll.c +++ b/src/common/fakepoll.c @@ -32,7 +32,7 @@ int tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout) { - int idx, maxfd, fd; + unsigned int idx, maxfd, fd; int r; #ifdef MS_WINDOWS int any_fds_set = 0; diff --git a/src/common/log.c b/src/common/log.c index 947029079a..77e53449fe 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -3,6 +3,9 @@ /* $Id$ */ #include "../or/or.h" +#ifdef MS_WINDOWS +#define vsnprintf _vsnprintf +#endif struct logfile_t; typedef struct logfile_t { @@ -35,7 +38,7 @@ static INLINE void format_msg(char *buf, size_t buf_len, { time_t t; struct timeval now; - int n; + size_t n; buf_len -= 2; /* subtract 2 characters so we have room for \n\0 */ diff --git a/src/common/tortls.c b/src/common/tortls.c index 860fb10438..1531ea211e 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -493,7 +493,7 @@ tor_tls_get_peer_cert_nickname(tor_tls *tls, char *buf, int buflen) lenout = X509_NAME_get_text_by_NID(name, nid, buf, buflen); if (lenout == -1) goto error; - if (strspn(buf, LEGAL_NICKNAME_CHARACTERS) != lenout) { + if (((int)strspn(buf, LEGAL_NICKNAME_CHARACTERS)) < lenout) { log_fn(LOG_WARN, "Peer certificate nickname has illegal characters."); goto error; } diff --git a/src/common/util.c b/src/common/util.c index 7cbbca4778..3c62956132 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -283,7 +283,7 @@ time_t tor_timegm (struct tm *tm) { /* a wrapper for write(2) that makes sure to write all count bytes. * Only use if fd is a blocking fd. */ int write_all(int fd, const char *buf, size_t count) { - int written = 0; + size_t written = 0; int result; while(written != count) { @@ -298,7 +298,7 @@ int write_all(int fd, const char *buf, size_t count) { /* a wrapper for read(2) that makes sure to read all count bytes. * Only use if fd is a blocking fd. */ int read_all(int fd, char *buf, size_t count) { - int numread = 0; + size_t numread = 0; int result; while(numread != count) { @@ -507,6 +507,7 @@ file_status_t file_status(const char *fname) 0. Else returns -1. */ int check_private_dir(const char *dirname, int create) { + int r; struct stat st; if (stat(dirname, &st)) { if (errno != ENOENT) { @@ -519,7 +520,12 @@ int check_private_dir(const char *dirname, int create) return -1; } log(LOG_INFO, "Creating directory %s", dirname); - if (mkdir(dirname, 0700)) { +#ifdef MS_WINDOWS + r = mkdir(dirname); +#else + r = mkdir(dirname, 0700); +#endif + if (r) { log(LOG_WARN, "Error creating directory %s: %s", dirname, strerror(errno)); return -1; @@ -531,6 +537,7 @@ int check_private_dir(const char *dirname, int create) log(LOG_WARN, "%s is not a directory", dirname); return -1; } +#ifndef MS_WINDOWS if (st.st_uid != getuid()) { log(LOG_WARN, "%s is not owned by this UID (%d)", dirname, (int)getuid()); return -1; @@ -545,6 +552,7 @@ int check_private_dir(const char *dirname, int create) return 0; } } +#endif return 0; } @@ -787,7 +795,7 @@ void finish_daemon(void) } #else /* defined(MS_WINDOWS) */ -void start_daemon(void) {} +void start_daemon(char *cp) {} void finish_daemon(void) {} #endif @@ -855,3 +863,22 @@ int switch_id(char *user, char *group) { return -1; } +int tor_inet_aton(const char *c, struct in_addr* addr) +{ +#ifndef MS_WINDOWS + /* XXXX WWWW Should be HAVE_INET_ATON */ + return inet_aton(c, addr); +#else + uint32_t r; + assert(c && addr); + if (strcmp(c, "255.255.255.255") == 0) { + addr->s_addr = 0xFFFFFFFFu; + return 1; + } + r = inet_addr(c); + if (r == INADDR_NONE) + return 0; + addr->s_addr = r; + return 1; +#endif +} \ No newline at end of file diff --git a/src/common/util.h b/src/common/util.h index 850b9015ac..02cde56046 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -102,6 +102,9 @@ void finish_daemon(void); void write_pidfile(char *filename); int switch_id(char *user, char *group); +struct in_addr; +int tor_inet_aton(const char *cp, struct in_addr *addr); + /* For stupid historical reasons, windows sockets have an independent set of * errnos which they use as the fancy strikes them. */ diff --git a/src/or/buffers.c b/src/or/buffers.c index 55a4bced99..1ddf9d349d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -433,7 +433,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { log_fn(LOG_WARN,"socks5: offered methods don't include 'no auth'. Rejecting."); req->replylen = 2; /* 2 bytes of response */ req->reply[0] = 5; /* socks5 reply */ - req->reply[1] = 0xFF; /* reject all methods */ + req->reply[1] = '\xFF'; /* reject all methods */ return -1; } buf_remove_from_front(buf,2+nummethods);/* remove packet from buf */ diff --git a/src/or/circuit.c b/src/or/circuit.c index 3955505179..e0e7aa607c 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -6,7 +6,7 @@ extern or_options_t options; /* command-line and config-file options */ -static int relay_crypt(circuit_t *circ, cell_t *cell, char cell_direction, +static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, crypt_path_t **layer_hint, char *recognized); static connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell, int cell_direction); static void circuit_free_cpath_node(crypt_path_t *victim); @@ -488,7 +488,7 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, } /* wrap this into receive_relay_cell one day */ -static int relay_crypt(circuit_t *circ, cell_t *cell, char cell_direction, +static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, crypt_path_t **layer_hint, char *recognized) { crypt_path_t *thishop; relay_header_t rh; diff --git a/src/or/connection.c b/src/or/connection.c index 7dc177d4dc..1c7e3cf219 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -258,7 +258,7 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) { return -1; } - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one)); if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) { log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport,strerror(errno)); @@ -418,21 +418,24 @@ int retry_all_connections(void) { if(options.ORPort) { listener_close_if_present(CONN_TYPE_OR_LISTENER); - if(connection_create_listener(options.ORBindAddress, options.ORPort, + if(connection_create_listener(options.ORBindAddress, + (uint16_t) options.ORPort, CONN_TYPE_OR_LISTENER) < 0) return -1; } if(options.DirPort) { listener_close_if_present(CONN_TYPE_DIR_LISTENER); - if(connection_create_listener(options.DirBindAddress, options.DirPort, + if(connection_create_listener(options.DirBindAddress, + (uint16_t) options.DirPort, CONN_TYPE_DIR_LISTENER) < 0) return -1; } if(options.SocksPort) { listener_close_if_present(CONN_TYPE_AP_LISTENER); - if(connection_create_listener(options.SocksBindAddress, options.SocksPort, + if(connection_create_listener(options.SocksBindAddress, + (uint16_t) options.SocksPort, CONN_TYPE_AP_LISTENER) < 0) return -1; } diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index fb4b424278..aa861be847 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1003,7 +1003,7 @@ static uint32_t client_dns_lookup_entry(const char *address) assert(address); - if (inet_aton(address, &in)) { + if (tor_inet_aton(address, &in)) { log_fn(LOG_DEBUG, "Using static address %s (%08lX)", address, (unsigned long)ntohl(in.s_addr)); return ntohl(in.s_addr); @@ -1039,7 +1039,7 @@ static void client_dns_set_entry(const char *address, uint32_t val) assert(address); assert(val); - if (inet_aton(address, &in)) + if (tor_inet_aton(address, &in)) return; search.address = (char*) address; now = time(NULL); diff --git a/src/or/or.h b/src/or/or.h index 47a3474815..383fc97994 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -85,6 +85,7 @@ #ifdef MS_WINDOWS #include #include +#include #define WIN32_LEAN_AND_MEAN #include #define snprintf _snprintf @@ -349,7 +350,7 @@ struct connection_t { * This is always in the range 0..1<<15-1.*/ /* bandwidth and receiver_bucket only used by ORs in OPEN state: */ - uint32_t bandwidth; /* connection bandwidth. */ + int bandwidth; /* connection bandwidth. */ int receiver_bucket; /* when this hits 0, stop receiving. Every second we * add 'bandwidth' to this, capping it at 10*bandwidth. */ diff --git a/src/or/routerlist.c b/src/or/routerlist.c index f47d829582..4ade31c6f2 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -541,6 +541,36 @@ int router_exit_policy_rejects_all(routerinfo_t *router) { == ADDR_POLICY_REJECTED; } +static time_t parse_time(const char *cp) +{ + struct tm st_tm; + /* XXXX WWWW should be HAVE_STRPTIME */ +#ifndef MS_WINDOWS + if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) { + log_fn(LOG_WARN, "Published time was unparseable"); return 0; + } +#else + unsigned int year=0, month=0, day=0, hour=100, minute=100, second=100; + if (scanf("%u-%u-%u %u:%u:%u", cp, &year, &month, + &day, &hour, &minute, &second) < 6) { + log_fn(LOG_WARN, "Published time was unparseable"); return 0; + } + if (year < 2000 || month < 1 || month > 12 || day < 1 || day > 31 || + hour > 24 || minute > 61 || second > 62) { + log_fn(LOG_WARN, "Published time was nonsensical"); return 0; + } + st_tm.tm_year = year; + st_tm.tm_mon = month; + st_tm.tm_mday = day; + st_tm.tm_hour = hour; + st_tm.tm_min = minute; + st_tm.tm_sec = second; +#endif + return tor_timegm(&st_tm); + +} + + /* Helper function: parse a directory from 's' and, when done, store the * resulting routerlist in *dest, freeing the old value if necessary. * If pkey is provided, we check the directory signature with pkey. @@ -555,7 +585,6 @@ router_get_routerlist_from_directory_impl(const char *str, char signed_digest[128]; routerlist_t *new_dir = NULL; char *versions = NULL; - struct tm published; time_t published_on; char *good_nickname_lst[1024]; int n_good_nicknames = 0; @@ -604,10 +633,9 @@ router_get_routerlist_from_directory_impl(const char *str, } assert(tok->n_args == 1); - if (!strptime(tok->args[0], "%Y-%m-%d %H:%M:%S", &published)) { - log_fn(LOG_WARN, "Published time was unparseable"); goto err; + if (!(published_on = parse_time(tok->args[0]))) { + goto err; } - published_on = tor_timegm(&published); if (!(tok = find_first_by_keyword(tokens, K_RECOMMENDED_SOFTWARE))) { log_fn(LOG_WARN, "Missing recommended-software line from directory."); @@ -781,7 +809,6 @@ routerinfo_t *router_get_entry_from_string(const char *s, char digest[128]; smartlist_t *tokens = NULL, *exit_policy_tokens = NULL; directory_token_t *tok; - struct tm published; int t, i; int ports_set, bw_set; @@ -876,11 +903,8 @@ routerinfo_t *router_get_entry_from_string(const char *s, log_fn(LOG_WARN, "Missing published time"); goto err; } assert(tok->n_args == 1); - if (!strptime(tok->args[0], "%Y-%m-%d %H:%M:%S", &published)) { - log_fn(LOG_WARN, "Published time was unparseable"); goto err; - } - router->published_on = tor_timegm(&published); - + if (!(router->published_on = parse_time(tok->args[0]))) + goto err; if (!(tok = find_first_by_keyword(tokens, K_ONION_KEY))) { log_fn(LOG_WARN, "Missing onion key"); goto err; @@ -1056,7 +1080,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { if (strcmp(address, "*") == 0) { newe->addr = 0; - } else if (inet_aton(address, &in) != 0) { + } else if (tor_inet_aton(address, &in) != 0) { newe->addr = ntohl(in.s_addr); } else { log_fn(LOG_WARN, "Malformed IP %s in exit policy; rejecting.", @@ -1074,7 +1098,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { if (!*endptr) { /* strtol handled the whole mask. */ newe->msk = ~((1<<(32-bits))-1); - } else if (inet_aton(mask, &in) != 0) { + } else if (tor_inet_aton(mask, &in) != 0) { newe->msk = ntohl(in.s_addr); } else { log_fn(LOG_WARN, "Malformed mask %s on exit policy; rejecting.", @@ -1087,11 +1111,11 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { newe->prt_max = 65535; } else { endptr = NULL; - newe->prt_min = strtol(port, &endptr, 10); + newe->prt_min = (uint16_t) strtol(port, &endptr, 10); if (*endptr == '-') { port = endptr+1; endptr = NULL; - newe->prt_max = strtol(port, &endptr, 10); + newe->prt_max = (uint16_t) strtol(port, &endptr, 10); if (*endptr) { log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.", port); diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index 3170f9e3e5..29524513ba 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -145,3 +145,6 @@ /* Version number of package */ #define VERSION "0.0.2pre6" + +/* XXXX WWWW */ +#define CONFDIR "" \ No newline at end of file