--- parser3/src/main/pa_common.C 2003/02/24 12:26:48 1.145 +++ parser3/src/main/pa_common.C 2003/04/07 07:03:05 1.149 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_COMMON_C="$Date: 2003/02/24 12:26:48 $"; +static const char* IDENT_COMMON_C="$Date: 2003/04/07 07:03:05 $"; #include "pa_common.h" #include "pa_exception.h" @@ -186,14 +186,14 @@ static int http_request(String& response const char* host, int port, const char* request, int timeout, - bool fail_on_status_ne_200){ + bool fail_on_status_ne_200) { if(!host) throw Exception("http.host", origin_string, "zero hostname"); //never #ifdef PA_USE_ALARM - signal(SIGALRM, timeout_handler); + signal(SIGALRM, timeout_handler); #endif int sock=-1; #ifdef PA_USE_ALARM @@ -206,14 +206,15 @@ static int http_request(String& response throw Exception("http.timeout", origin_string, "timeout occured while retrieving document"); + return 0; // never } else { alarm(timeout); #endif - try { - int result; + try { + int result; struct sockaddr_in dest; - - if(!set_addr(&dest, host, port)) + + if(!set_addr(&dest, host, port)) throw Exception("http.host", origin_string, "can not resolve hostname \"%s\"", host); @@ -236,17 +237,19 @@ static int http_request(String& response closesocket(sock); #ifdef PA_USE_ALARM alarm(0); - } #endif - return result; - } catch(...) { - if(sock>=0) - closesocket(sock); + return result; + } catch(...) { #ifdef PA_USE_ALARM - alarm(0); + alarm(0); #endif - /*re*/throw; + if(sock>=0) + closesocket(sock); + /*re*/throw; + } +#ifdef PA_USE_ALARM } +#endif } #ifndef DOXYGEN @@ -449,6 +452,23 @@ bool file_read(Pool& pool, const String& return result; } +#ifdef PA_SAFE_MODE +void check_safe_mode(stat finfo, const String& file_spec, const char* fname) { + if(finfo.st_uid/*foreign?*/!=geteuid() + && finfo.st_gid/*foreign?*/!=getegid()) + throw Exception("parser.runtime", + &file_spec, + "parser is in safe mode: " + "reading files of foreign group and user disabled " + "[recompile parser with --disable-safe-mode configure option], " + "actual filename '%s', " + "fuid(%d)!=euid(%d) or fgid(%d)!=egid(%d)", + fname, + finfo.st_uid, geteuid(), + finfo.st_gid, getegid()); +} +#endif + bool file_read_action_under_lock(Pool& pool, const String& file_spec, const char* action_name, File_read_action action, void *context, bool as_text, @@ -481,12 +501,7 @@ bool file_read_action_under_lock(Pool& p strerror(errno), errno, fname); #ifdef PA_SAFE_MODE - if(finfo.st_uid/*foreign?*/!=geteuid() - && finfo.st_gid/*foreign?*/!=getegid()) - throw Exception("parser.runtime", - &file_spec, - "parser is in safe mode: reading files of foreign group and user disabled [recompile parser with --disable-safe-mode configure option], actual filename '%s'", - fname); + check_safe_mode(finfo, file_spec, fname); #endif action(pool, finfo, f, file_spec, fname, as_text, context);