--- parser3/src/main/pa_common.C 2003/02/24 12:26:48 1.145 +++ parser3/src/main/pa_common.C 2003/05/30 10:45:37 1.151 @@ -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/05/30 10:45:37 $"; #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(struct 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); @@ -960,6 +975,7 @@ int pa_sleep(unsigned long secs, unsigne // attributed meaning +/// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 static size_t date_attribute(const VDate& vdate, char *buf, size_t buf_size) { const char month_names[12][4]={ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; @@ -972,7 +988,7 @@ static size_t date_attribute(const VDate throw Exception(0, 0, "bad time in attribute value (seconds from epoch=%ld)", when); - return snprintf(buf, MAX_STRING, "%s, %.2d-%s-%.4d %.2d:%.2d:%.2d GMT", + return snprintf(buf, MAX_STRING, "%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT", days[tms->tm_wday], tms->tm_mday,month_names[tms->tm_mon],tms->tm_year+1900, tms->tm_hour,tms->tm_min,tms->tm_sec);