X-Git-Url: http://www.privoxy.org/gitweb/general.html?a=blobdiff_plain;f=jcc.c;h=d0d535eae91568001cca4d26450e1c27f733d2f7;hb=bfe28519e62da559f3d37481e8dd82a85e170fea;hp=ea4ae6447d7444932227108ab01ae6de52b1045a;hpb=4e2c6db9354f8f98c67de8a5940c6e4a6bccbe46;p=privoxy.git diff --git a/jcc.c b/jcc.c index ea4ae644..d0d535ea 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.219 2009/01/31 16:08:21 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.226 2009/03/01 18:28:24 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -6,7 +6,7 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.219 2009/01/31 16:08:21 fabiankeil Exp $" * Purpose : Main file. Contains main() method, main loop, and * the main connection-handling function. * - * Copyright : Written by and Copyright (C) 2001-2008 the SourceForge + * Copyright : Written by and Copyright (C) 2001-2009 the SourceForge * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -33,6 +33,36 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.219 2009/01/31 16:08:21 fabiankeil Exp $" * * Revisions : * $Log: jcc.c,v $ + * Revision 1.226 2009/03/01 18:28:24 fabiankeil + * Help clang understand that we aren't dereferencing + * NULL pointers here. + * + * Revision 1.225 2009/02/19 18:09:32 fabiankeil + * Unbreak build without FEATURE_CONNECTION_KEEP_ALIVE. + * Noticed by David. + * + * Revision 1.224 2009/02/14 15:32:04 fabiankeil + * Add the request URL to the timeout message in chat(). + * Suggested by Lee. + * + * Revision 1.223 2009/02/09 21:21:16 fabiankeil + * Now that init_log_module() is called earlier, call show_version() + * later on from main() directly so it doesn't get called for --help + * or --version. + * + * Revision 1.222 2009/02/08 12:56:51 fabiankeil + * Call initialize_mutexes() before init_log_module() again. + * Broken since r220, might be the cause of Lee's #2579448. + * + * Revision 1.221 2009/02/06 18:02:58 fabiankeil + * When dropping privileges, also give up membership in supplementary + * groups. Thanks to Matthias Drochner for reporting the problem, + * providing the initial patch and testing the final version. + * + * Revision 1.220 2009/02/04 18:29:07 fabiankeil + * Initialize the log module before parsing arguments. + * Thanks to Matthias Drochner for the report. + * * Revision 1.219 2009/01/31 16:08:21 fabiankeil * Remove redundant error check in receive_client_request(). * @@ -2087,7 +2117,7 @@ static jb_err change_request_destination(struct client_state *csp) log_error(LOG_LEVEL_INFO, "Rewrite detected: %s", csp->headers->first->str); free_http_request(http); - err = parse_http_request(csp->headers->first->str, http, csp); + err = parse_http_request(csp->headers->first->str, http); if (JB_ERR_OK != err) { log_error(LOG_LEVEL_ERROR, "Couldn't parse rewritten request: %s.", @@ -2150,8 +2180,38 @@ static int server_response_is_complete(struct client_state *csp, size_t content_ return (content_length_known && ((0 == csp->expected_content_length) || (csp->expected_content_length <= content_length))); } + + +/********************************************************************* + * + * Function : wait_for_alive_connections + * + * Description : Waits for alive connections to timeout. + * + * Parameters : N/A + * + * Returns : N/A + * + *********************************************************************/ +static void wait_for_alive_connections() +{ + int connections_alive = close_unusable_connections(); + + while (0 < connections_alive) + { + log_error(LOG_LEVEL_CONNECT, + "Waiting for %d connections to timeout.", + connections_alive); + sleep(60); + connections_alive = close_unusable_connections(); + } + + log_error(LOG_LEVEL_CONNECT, "No connections to wait for left."); + +} #endif /* FEATURE_CONNECTION_KEEP_ALIVE */ + /********************************************************************* * * Function : mark_server_socket_tainted @@ -2295,7 +2355,7 @@ static jb_err receive_client_request(struct client_state *csp) } #endif /* def FEATURE_FORCE_LOAD */ - err = parse_http_request(req, http, csp); + err = parse_http_request(req, http); freez(req); if (JB_ERR_OK != err) { @@ -2539,6 +2599,7 @@ static void chat(struct client_state *csp) { log_error(LOG_LEVEL_FATAL, "gateway spec is NULL!?!? This can't happen!"); /* Never get here - LOG_LEVEL_FATAL causes program exit */ + return; } /* @@ -2765,7 +2826,8 @@ static void chat(struct client_state *csp) if (n == 0) { - log_error(LOG_LEVEL_ERROR, "Didn't receive data in time."); + log_error(LOG_LEVEL_ERROR, + "Didn't receive data in time: %s", http->url); if ((byte_count == 0) && (http->ssl == 0)) { write_socket(csp->cfd, CONNECTION_TIMEOUT_RESPONSE, @@ -3222,6 +3284,7 @@ static void chat(struct client_state *csp) csp->content_length = byte_count; } +#ifdef FEATURE_CONNECTION_KEEP_ALIVE if ((csp->flags & CSP_FLAG_CONTENT_LENGTH_SET) && (csp->expected_content_length != byte_count)) { @@ -3230,40 +3293,13 @@ static void chat(struct client_state *csp) byte_count, csp->expected_content_length); mark_server_socket_tainted(csp); } +#endif log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 200 %d", csp->ip_addr_str, http->ocmd, csp->content_length); } -/********************************************************************* - * - * Function : wait_for_alive_connections - * - * Description : Waits for alive connections to timeout. - * - * Parameters : N/A - * - * Returns : N/A - * - *********************************************************************/ -static void wait_for_alive_connections() -{ - int connections_alive = close_unusable_connections(); - - while (0 < connections_alive) - { - log_error(LOG_LEVEL_CONNECT, - "Waiting for %d connections to timeout.", - connections_alive); - sleep(60); - connections_alive = close_unusable_connections(); - } - - log_error(LOG_LEVEL_CONNECT, "No connections to wait for left."); - -} - /********************************************************************* * * Function : serve @@ -3567,8 +3603,11 @@ int main(int argc, const char *argv[]) #endif ; + /* Prepare mutexes if supported and necessary. */ + initialize_mutexes(); + /* Enable logging until further notice. */ - init_log_module(Argv[0]); + init_log_module(); /* * Parse the command line arguments @@ -3681,6 +3720,8 @@ int main(int argc, const char *argv[]) } /* -END- while (more arguments) */ + show_version(Argv[0]); + #if defined(unix) if ( *configfile != '/' ) { @@ -3723,9 +3764,6 @@ int main(int argc, const char *argv[]) InitWin32(); #endif - /* Prepare mutexes if supported and necessary. */ - initialize_mutexes(); - random_seed = (unsigned int)time(NULL); #ifdef HAVE_RANDOM srandom(random_seed); @@ -3859,6 +3897,17 @@ int main(int argc, const char *argv[]) { log_error(LOG_LEVEL_FATAL, "Cannot setgid(): Insufficient permissions."); } + if (NULL != grp) + { + if (setgroups(1, &grp->gr_gid)) + { + log_error(LOG_LEVEL_FATAL, "setgroups() failed: %E"); + } + } + else if (initgroups(pw->pw_name, pw->pw_gid)) + { + log_error(LOG_LEVEL_FATAL, "initgroups() failed: %E"); + } if (do_chroot) { if (!pw->pw_dir)