Loading src/common/compat.c +12 −11 Original line number Diff line number Diff line Loading @@ -177,6 +177,7 @@ tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen) #endif } #ifdef MS_WINDOWS /** Take a filename and return a pointer to its final element. This * function is called on __FILE__ to fix a MSVC nit where __FILE__ * contains the full path to the file. This is bad, because it Loading @@ -184,7 +185,7 @@ tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen) * compiled the binary in their warrning messages. */ const char * _tor_fix_source_file(const char *fname) tor_fix_source_file(const char *fname) { const char *cp1, *cp2, *r; cp1 = strrchr(fname, '/'); Loading @@ -200,6 +201,7 @@ _tor_fix_source_file(const char *fname) } return r; } #endif #ifndef UNALIGNED_INT_ACCESS_OK /** Loading Loading @@ -499,7 +501,7 @@ switch_id(char *user, char *group) if (user) { pw = getpwnam(user); if (pw == NULL) { err("User '%s' not found.", user); err(LD_CONFIG,"User '%s' not found.", user); return -1; } } Loading @@ -508,17 +510,17 @@ switch_id(char *user, char *group) if (group) { gr = getgrnam(group); if (gr == NULL) { err("Group '%s' not found.", group); err(LD_CONFIG,"Group '%s' not found.", group); return -1; } if (setgid(gr->gr_gid) != 0) { err("Error setting GID: %s", strerror(errno)); err(LD_GENERAL,"Error setting GID: %s", strerror(errno)); return -1; } } else if (user) { if (setgid(pw->pw_gid) != 0) { err("Error setting GID: %s", strerror(errno)); err(LD_GENERAL,"Error setting GID: %s", strerror(errno)); return -1; } } Loading @@ -527,7 +529,7 @@ switch_id(char *user, char *group) privileges */ if (user) { if (setuid(pw->pw_uid) != 0) { err("Error setting UID: %s", strerror(errno)); err(LD_GENERAL,"Error setting UID: %s", strerror(errno)); return -1; } } Loading @@ -535,8 +537,7 @@ switch_id(char *user, char *group) return 0; #endif err("User or group specified, but switching users is not supported."); err(LD_CONFIG,"User or group specified, but switching users is not supported."); return -1; } Loading @@ -550,7 +551,7 @@ get_user_homedir(const char *username) tor_assert(username); if (!(pw = getpwnam(username))) { err("User \"%s\" not found.", username); err(LD_CONFIG,"User \"%s\" not found.", username); return NULL; } return tor_strdup(pw->pw_dir); Loading Loading @@ -894,7 +895,7 @@ tor_gettimeofday(struct timeval *timeval) /* number of 100-nsec units since Jan 1, 1601 */ GetSystemTimeAsFileTime(&ft.ft_ft); if (ft.ft_64 < EPOCH_BIAS) { err("System time is before 1970; failing."); err(LD_GENERAL,"System time is before 1970; failing."); exit(1); } ft.ft_64 -= EPOCH_BIAS; Loading @@ -902,7 +903,7 @@ tor_gettimeofday(struct timeval *timeval) timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); #elif defined(HAVE_GETTIMEOFDAY) if (gettimeofday(timeval, NULL)) { err("gettimeofday failed."); err(LD_GENERAL,"gettimeofday failed."); /* If gettimeofday dies, we have either given a bad timezone (we didn't), or segfaulted.*/ exit(1); Loading src/common/compat.h +7 −2 Original line number Diff line number Diff line Loading @@ -100,8 +100,13 @@ const void *tor_memmem(const void *haystack, size_t hlen, const void *needle, #define TOR_ISDIGIT(c) isdigit((int)(unsigned char)(c)) #define TOR_ISPRINT(c) isprint((int)(unsigned char)(c)) #define _SHORT_FILE_ (_tor_fix_source_file(__FILE__)) const char *_tor_fix_source_file(const char *fname); #ifdef MS_WINDOWS #define _SHORT_FILE_ (tor_fix_source_file(__FILE__)) const char *tor_fix_source_file(const char *fname); #else #define _SHORT_FILE_ (__FILE__) #define tor_fix_source_file(s) (s) #endif /* ===== Time compatibility */ #if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_STRUCT_TIMEVAL_TV_SEC) Loading src/common/log.c +10 −10 Original line number Diff line number Diff line Loading @@ -184,7 +184,7 @@ format_msg(char *buf, size_t buf_len, * message. The actual message is derived as from tor_snprintf(format,ap). */ static void logv(int severity, int domain, const char *funcname, const char *format, logv(int severity, unsigned int domain, const char *funcname, const char *format, va_list ap) { char buf[10024]; Loading Loading @@ -234,7 +234,7 @@ logv(int severity, int domain, const char *funcname, const char *format, /** Output a message to the log. */ void _log(int severity, int domain, const char *format, ...) _log(int severity, unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -245,7 +245,7 @@ _log(int severity, int domain, const char *format, ...) /** Output a message to the log, prefixed with a function name <b>fn</b>. */ #ifdef __GNUC__ void _log_fn(int severity, int domain, const char *fn, const char *format, ...) _log_fn(int severity, unsigned int domain, const char *fn, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -255,7 +255,7 @@ _log_fn(int severity, int domain, const char *fn, const char *format, ...) #else const char *_log_fn_function_name=NULL; void _log_fn(int severity, int domain, const char *format, ...) _log_fn(int severity, unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -264,7 +264,7 @@ _log_fn(int severity, int domain, const char *format, ...) _log_fn_function_name = NULL; } void _debug(int domain, const char *format, ...) _debug(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -273,7 +273,7 @@ _debug(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _info(int domain, const char *format, ...) _info(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -282,7 +282,7 @@ _info(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _notice(int domain, const char *format, ...) _notice(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -291,7 +291,7 @@ _notice(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _warn(int domain, const char *format, ...) _warn(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -300,11 +300,11 @@ _warn(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _err(const char *format, ...) _err(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); logv(LOG_ERR, LD_GENERAL, _log_fn_function_name, format, ap); logv(LOG_ERR, domain, _log_fn_function_name, format, ap); va_end(ap); _log_fn_function_name = NULL; } Loading src/common/log.h +29 −27 Original line number Diff line number Diff line Loading @@ -53,39 +53,41 @@ /* Logging domains */ /** Catch-all for miscellaneous events and fatal errors */ #define LD_GENERAL 0 #define LD_GENERAL (1u<<0) /** The cryptography subsytem */ #define LD_CRYPTO 1 #define LD_CRYPTO (1u<<1) /** Networking */ #define LD_NET 2 #define LD_NET (1u<<2) /** Parsing and acting on our configuration */ #define LD_CONFIG 3 #define LD_CONFIG (1u<<3) /** Reading and writing from the filesystem */ #define LD_FS 4 #define LD_FS (1u<<4) /** Other servers' (non)compliance with the Tor protocol */ #define LD_PROTOCOL 5 #define LD_PROTOCOL (1u<<5) /** Memory management */ #define LD_MM 6 #define LD_MM (1u<<6) /** HTTP implementation */ #define LD_HTTP 7 #define LD_HTTP (1u<<7) /** Application (socks) requests */ #define LD_APP 8 #define LD_APP (1u<<8) /** Communication via the controller protocol */ #define LD_CONTROL 9 #define LD_CONTROL (1u<<9) /** Building, using, and managing circuits */ #define LD_CIRC 10 #define LD_CIRC (1u<<10) /** Hidden services */ #define LD_REND 11 #define LD_REND (1u<<11) /** Internal errors in this Tor process. */ #define LD_BUG 12 #define LD_BUG (1u<<12) /** Learning and using information about Tor servers. */ #define LD_DIR 13 #define LD_DIR (1u<<13) /** Learning and using information about Tor servers. */ #define LD_DIRSERV 14 #define LD_DIRSERV (1u<<14) /** Onion routing protocol. */ #define LD_OR 15 #define LD_OR (1u<<15) /** Connections leaving Tor, other exit stuff. */ #define LD_EXIT (1u<<16) typedef void (*log_callback)(int severity, int domain, const char *msg); typedef void (*log_callback)(int severity, unsigned int domain, const char *msg); int parse_log_level(const char *level); const char *log_level_to_string(int level); Loading @@ -108,10 +110,10 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax, log_callback cb); /* Outputs a message to stdout */ void _log(int severity, int domain, const char *format, ...) CHECK_PRINTF(3,4); void _log(int severity, unsigned int domain, const char *format, ...) CHECK_PRINTF(3,4); #ifdef __GNUC__ void _log_fn(int severity, int domain, void _log_fn(int severity, unsigned int domain, const char *funcname, const char *format, ...) CHECK_PRINTF(4,5); /** Log a message at level <b>severity</b>, using a pretty-printed version Loading @@ -134,16 +136,16 @@ void _log_fn(int severity, int domain, _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) #define warn(domain, args...) \ _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) #define err(args...) \ _log_fn(LOG_ERR, LD_GENERAL, __PRETTY_FUNCTION__, args) #define err(domain, args...) \ _log_fn(LOG_ERR, domain, __PRETTY_FUNCTION__, args) #else void _log_fn(int severity, int domain, const char *format, ...); void _debug(int domain, const char *format, ...); void _info(int domain, const char *format, ...); void _notice(int domain, const char *format, ...); void _warn(int domain, const char *format, ...); void _err(const char *format, ...); void _log_fn(int severity, unsigned int domain, const char *format, ...); void _debug(unsigned int domain, const char *format, ...); void _info(unsigned int domain, const char *format, ...); void _notice(unsigned int domain, const char *format, ...); void _warn(unsigned int domain, const char *format, ...); void _err(unsigned int domain, const char *format, ...); #define log _log /* hack it so we don't conflict with log() as much */ Loading src/common/tortls.c +2 −2 Original line number Diff line number Diff line Loading @@ -866,8 +866,8 @@ _check_no_tls_errors(const char *fname, int line) { if (ERR_peek_error() == 0) return; log_fn(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ", fname, line); log(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ", tor_fix_source_file(fname), line); tls_log_errors(LOG_WARN, NULL); } Loading
src/common/compat.c +12 −11 Original line number Diff line number Diff line Loading @@ -177,6 +177,7 @@ tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen) #endif } #ifdef MS_WINDOWS /** Take a filename and return a pointer to its final element. This * function is called on __FILE__ to fix a MSVC nit where __FILE__ * contains the full path to the file. This is bad, because it Loading @@ -184,7 +185,7 @@ tor_memmem(const void *_haystack, size_t hlen, const void *_needle, size_t nlen) * compiled the binary in their warrning messages. */ const char * _tor_fix_source_file(const char *fname) tor_fix_source_file(const char *fname) { const char *cp1, *cp2, *r; cp1 = strrchr(fname, '/'); Loading @@ -200,6 +201,7 @@ _tor_fix_source_file(const char *fname) } return r; } #endif #ifndef UNALIGNED_INT_ACCESS_OK /** Loading Loading @@ -499,7 +501,7 @@ switch_id(char *user, char *group) if (user) { pw = getpwnam(user); if (pw == NULL) { err("User '%s' not found.", user); err(LD_CONFIG,"User '%s' not found.", user); return -1; } } Loading @@ -508,17 +510,17 @@ switch_id(char *user, char *group) if (group) { gr = getgrnam(group); if (gr == NULL) { err("Group '%s' not found.", group); err(LD_CONFIG,"Group '%s' not found.", group); return -1; } if (setgid(gr->gr_gid) != 0) { err("Error setting GID: %s", strerror(errno)); err(LD_GENERAL,"Error setting GID: %s", strerror(errno)); return -1; } } else if (user) { if (setgid(pw->pw_gid) != 0) { err("Error setting GID: %s", strerror(errno)); err(LD_GENERAL,"Error setting GID: %s", strerror(errno)); return -1; } } Loading @@ -527,7 +529,7 @@ switch_id(char *user, char *group) privileges */ if (user) { if (setuid(pw->pw_uid) != 0) { err("Error setting UID: %s", strerror(errno)); err(LD_GENERAL,"Error setting UID: %s", strerror(errno)); return -1; } } Loading @@ -535,8 +537,7 @@ switch_id(char *user, char *group) return 0; #endif err("User or group specified, but switching users is not supported."); err(LD_CONFIG,"User or group specified, but switching users is not supported."); return -1; } Loading @@ -550,7 +551,7 @@ get_user_homedir(const char *username) tor_assert(username); if (!(pw = getpwnam(username))) { err("User \"%s\" not found.", username); err(LD_CONFIG,"User \"%s\" not found.", username); return NULL; } return tor_strdup(pw->pw_dir); Loading Loading @@ -894,7 +895,7 @@ tor_gettimeofday(struct timeval *timeval) /* number of 100-nsec units since Jan 1, 1601 */ GetSystemTimeAsFileTime(&ft.ft_ft); if (ft.ft_64 < EPOCH_BIAS) { err("System time is before 1970; failing."); err(LD_GENERAL,"System time is before 1970; failing."); exit(1); } ft.ft_64 -= EPOCH_BIAS; Loading @@ -902,7 +903,7 @@ tor_gettimeofday(struct timeval *timeval) timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); #elif defined(HAVE_GETTIMEOFDAY) if (gettimeofday(timeval, NULL)) { err("gettimeofday failed."); err(LD_GENERAL,"gettimeofday failed."); /* If gettimeofday dies, we have either given a bad timezone (we didn't), or segfaulted.*/ exit(1); Loading
src/common/compat.h +7 −2 Original line number Diff line number Diff line Loading @@ -100,8 +100,13 @@ const void *tor_memmem(const void *haystack, size_t hlen, const void *needle, #define TOR_ISDIGIT(c) isdigit((int)(unsigned char)(c)) #define TOR_ISPRINT(c) isprint((int)(unsigned char)(c)) #define _SHORT_FILE_ (_tor_fix_source_file(__FILE__)) const char *_tor_fix_source_file(const char *fname); #ifdef MS_WINDOWS #define _SHORT_FILE_ (tor_fix_source_file(__FILE__)) const char *tor_fix_source_file(const char *fname); #else #define _SHORT_FILE_ (__FILE__) #define tor_fix_source_file(s) (s) #endif /* ===== Time compatibility */ #if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_STRUCT_TIMEVAL_TV_SEC) Loading
src/common/log.c +10 −10 Original line number Diff line number Diff line Loading @@ -184,7 +184,7 @@ format_msg(char *buf, size_t buf_len, * message. The actual message is derived as from tor_snprintf(format,ap). */ static void logv(int severity, int domain, const char *funcname, const char *format, logv(int severity, unsigned int domain, const char *funcname, const char *format, va_list ap) { char buf[10024]; Loading Loading @@ -234,7 +234,7 @@ logv(int severity, int domain, const char *funcname, const char *format, /** Output a message to the log. */ void _log(int severity, int domain, const char *format, ...) _log(int severity, unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -245,7 +245,7 @@ _log(int severity, int domain, const char *format, ...) /** Output a message to the log, prefixed with a function name <b>fn</b>. */ #ifdef __GNUC__ void _log_fn(int severity, int domain, const char *fn, const char *format, ...) _log_fn(int severity, unsigned int domain, const char *fn, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -255,7 +255,7 @@ _log_fn(int severity, int domain, const char *fn, const char *format, ...) #else const char *_log_fn_function_name=NULL; void _log_fn(int severity, int domain, const char *format, ...) _log_fn(int severity, unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -264,7 +264,7 @@ _log_fn(int severity, int domain, const char *format, ...) _log_fn_function_name = NULL; } void _debug(int domain, const char *format, ...) _debug(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -273,7 +273,7 @@ _debug(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _info(int domain, const char *format, ...) _info(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -282,7 +282,7 @@ _info(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _notice(int domain, const char *format, ...) _notice(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -291,7 +291,7 @@ _notice(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _warn(int domain, const char *format, ...) _warn(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); Loading @@ -300,11 +300,11 @@ _warn(int domain, const char *format, ...) _log_fn_function_name = NULL; } void _err(const char *format, ...) _err(unsigned int domain, const char *format, ...) { va_list ap; va_start(ap,format); logv(LOG_ERR, LD_GENERAL, _log_fn_function_name, format, ap); logv(LOG_ERR, domain, _log_fn_function_name, format, ap); va_end(ap); _log_fn_function_name = NULL; } Loading
src/common/log.h +29 −27 Original line number Diff line number Diff line Loading @@ -53,39 +53,41 @@ /* Logging domains */ /** Catch-all for miscellaneous events and fatal errors */ #define LD_GENERAL 0 #define LD_GENERAL (1u<<0) /** The cryptography subsytem */ #define LD_CRYPTO 1 #define LD_CRYPTO (1u<<1) /** Networking */ #define LD_NET 2 #define LD_NET (1u<<2) /** Parsing and acting on our configuration */ #define LD_CONFIG 3 #define LD_CONFIG (1u<<3) /** Reading and writing from the filesystem */ #define LD_FS 4 #define LD_FS (1u<<4) /** Other servers' (non)compliance with the Tor protocol */ #define LD_PROTOCOL 5 #define LD_PROTOCOL (1u<<5) /** Memory management */ #define LD_MM 6 #define LD_MM (1u<<6) /** HTTP implementation */ #define LD_HTTP 7 #define LD_HTTP (1u<<7) /** Application (socks) requests */ #define LD_APP 8 #define LD_APP (1u<<8) /** Communication via the controller protocol */ #define LD_CONTROL 9 #define LD_CONTROL (1u<<9) /** Building, using, and managing circuits */ #define LD_CIRC 10 #define LD_CIRC (1u<<10) /** Hidden services */ #define LD_REND 11 #define LD_REND (1u<<11) /** Internal errors in this Tor process. */ #define LD_BUG 12 #define LD_BUG (1u<<12) /** Learning and using information about Tor servers. */ #define LD_DIR 13 #define LD_DIR (1u<<13) /** Learning and using information about Tor servers. */ #define LD_DIRSERV 14 #define LD_DIRSERV (1u<<14) /** Onion routing protocol. */ #define LD_OR 15 #define LD_OR (1u<<15) /** Connections leaving Tor, other exit stuff. */ #define LD_EXIT (1u<<16) typedef void (*log_callback)(int severity, int domain, const char *msg); typedef void (*log_callback)(int severity, unsigned int domain, const char *msg); int parse_log_level(const char *level); const char *log_level_to_string(int level); Loading @@ -108,10 +110,10 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax, log_callback cb); /* Outputs a message to stdout */ void _log(int severity, int domain, const char *format, ...) CHECK_PRINTF(3,4); void _log(int severity, unsigned int domain, const char *format, ...) CHECK_PRINTF(3,4); #ifdef __GNUC__ void _log_fn(int severity, int domain, void _log_fn(int severity, unsigned int domain, const char *funcname, const char *format, ...) CHECK_PRINTF(4,5); /** Log a message at level <b>severity</b>, using a pretty-printed version Loading @@ -134,16 +136,16 @@ void _log_fn(int severity, int domain, _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) #define warn(domain, args...) \ _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args) #define err(args...) \ _log_fn(LOG_ERR, LD_GENERAL, __PRETTY_FUNCTION__, args) #define err(domain, args...) \ _log_fn(LOG_ERR, domain, __PRETTY_FUNCTION__, args) #else void _log_fn(int severity, int domain, const char *format, ...); void _debug(int domain, const char *format, ...); void _info(int domain, const char *format, ...); void _notice(int domain, const char *format, ...); void _warn(int domain, const char *format, ...); void _err(const char *format, ...); void _log_fn(int severity, unsigned int domain, const char *format, ...); void _debug(unsigned int domain, const char *format, ...); void _info(unsigned int domain, const char *format, ...); void _notice(unsigned int domain, const char *format, ...); void _warn(unsigned int domain, const char *format, ...); void _err(unsigned int domain, const char *format, ...); #define log _log /* hack it so we don't conflict with log() as much */ Loading
src/common/tortls.c +2 −2 Original line number Diff line number Diff line Loading @@ -866,8 +866,8 @@ _check_no_tls_errors(const char *fname, int line) { if (ERR_peek_error() == 0) return; log_fn(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ", fname, line); log(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ", tor_fix_source_file(fname), line); tls_log_errors(LOG_WARN, NULL); }