1 const char jcc_rcs[] = "$Id: jcc.c,v 1.4 2001/05/21 19:34:01 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
6 * Purpose : Main file. Contains main() method, main loop, and
7 * the main connection-handling function.
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 * Revision 1.4 2001/05/21 19:34:01 jongfoster
37 * Made failure to bind() a fatal error.
39 * Revision 1.3 2001/05/20 01:21:20 jongfoster
40 * Version 2.9.4 checkin.
41 * - Merged popupfile and cookiefile, and added control over PCRS
42 * filtering, in new "permissionsfile".
43 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
44 * file error you now get a message box (in the Win32 GUI) rather
45 * than the program exiting with no explanation.
46 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
48 * - Removed tabs from "config"
49 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
50 * - Bumped up version number.
52 * Revision 1.2 2001/05/17 22:34:44 oes
53 * - Added hint on GIF char array generation to jcc.c
54 * - Cleaned CRLF's from the sources and related files
55 * - Repaired logging for REF and FRC
57 * Revision 1.1.1.1 2001/05/15 13:58:56 oes
58 * Initial import of version 2.9.3 source tree
61 *********************************************************************/
67 #include <sys/types.h>
76 # include <sys/timeb.h>
82 # endif /* def TOGGLE */
87 # endif /* ndef _WIN_CONSOLE */
89 #else /* ifndef _WIN32 */
92 # include <sys/time.h>
93 # include <sys/wait.h>
94 # include <sys/stat.h>
98 # include <socket.h> /* BeOS has select() for sockets only. */
99 # include <OS.h> /* declarations for threads and stuff. */
112 #include "showargs.h"
114 #include "killpopup.h"
115 #include "miscutil.h"
117 #include "jbsockets.h"
120 const char jcc_h_rcs[] = JCC_H_VERSION;
121 const char project_h_rcs[] = PROJECT_H_VERSION;
123 const char DEFAULT_USER_AGENT[] ="User-Agent: Mozilla (X11; I; Linux 2.0.32 i586)";
125 struct client_state clients[1];
126 struct file_list files[1];
129 int urls_read = 0; /* total nr of urls read inc rejected */
130 int urls_rejected = 0; /* total nr of urls rejected */
131 #endif /* def STATISTICS */
134 static void listen_loop(void);
135 static void chat(struct client_state *csp);
136 static void serve(struct client_state *csp);
138 static int32 server_thread(void *data);
139 #endif /* def __BEOS__ */
142 #define sleep(N) Sleep(((N) * 1000))
146 /*********************************************************************
150 * Description : Once a connection to the client has been accepted,
151 * this function is called (via serve()) to handle the
152 * main business of the communication. When this
153 * function returns, the caller must close the client
157 * 1 : csp = Current client state (buffers, headers, etc...)
159 * Returns : On success, the number of bytes written are returned (zero
160 * indicates nothing was written). On error, -1 is returned,
161 * and errno is set appropriately. If count is zero and the
162 * file descriptor refers to a regular file, 0 will be
163 * returned without causing any other effect. For a special
164 * file, the results are not portable.
166 *********************************************************************/
167 static void chat(struct client_state *csp)
169 /* This next line is a little ugly, but it simplifies the if statement below. */
170 /* Basically if TOGGLE, then we want the if to test "csp->toggled_on", else we don't */
172 # define IS_TOGGLED_ON csp->toggled_on &&
173 #else /* ifndef TOGGLE */
174 # define IS_TOGGLED_ON
175 #endif /* ndef TOGGLE */
177 /* This next line is a little ugly, but it simplifies the if statement below. */
178 /* Basically if TRUST_FILES, then we want the if to call "trust_url", else we don't */
180 # define IS_TRUSTED_URL (p = trust_url(http, csp)) ||
181 #else /* ifndef TRUST_FILES */
182 # define IS_TRUSTED_URL
183 #endif /* ndef TRUST_FILES */
185 char buf[BUFSIZ], *hdr, *p, *req;
189 int n, maxfd, server_body, ms_iis5_hack = 0;
190 const struct gateway *gw;
191 struct http_request *http;
193 int block_popups; /* bool, 1==will block popups */
194 int block_popups_now = 0; /* bool, 1==currently blocking popups */
195 #endif /* def KILLPOPUPS */
197 int pcrs_filter; /* bool, 1==will filter through pcrs */
198 int filtering = 0; /* bool, 1==currently filtering through pcrs */
199 #endif /* def PCRS */
204 * Read the client's request. Note that since we're not using select() we
205 * could get blocked here if a client connected, then didn't say anything!
210 n = read_socket(csp->cfd, buf, sizeof(buf));
212 if (n <= 0) break; /* error! */
214 add_to_iob(csp, buf, n);
216 req = get_header(csp);
220 break; /* no HTTP request! */
225 continue; /* more to come! */
229 /* If this request contains the FORCE_PREFIX,
230 * better get rid of it now and set the force flag --oes
233 if(strstr(req, FORCE_PREFIX))
235 strclean(req, FORCE_PREFIX);
236 log_error(LOG_LEVEL_FORCE, "Enforcing request \"%s\".\n", req);
243 #endif /* def FORCE_LOAD */
245 parse_http_request(req, http, csp);
250 if (http->cmd == NULL)
252 strcpy(buf, CHEADER);
253 write_socket(csp->cfd, buf, strlen(buf));
257 /* decide how to route the HTTP request */
259 if ((gw = forward_url(http, csp)) == NULL)
261 log_error(LOG_LEVEL_FATAL, "gateway spec is NULL!?!? This can't happen!");
262 /* Never get here - LOG_LEVEL_FATAL causes program exit */
265 /* build the http request to send to the server
266 * we have to do one of the following:
268 * create = use the original HTTP request to create a new
269 * HTTP request that has only the path component
270 * without the http://domainspec
271 * pass = pass the original HTTP request unchanged
273 * drop = drop the HTTP request
278 * +--------+--------+
280 * 0 | create | drop |
282 * Forwarding +--------+--------+
286 * +--------+--------+
290 if (gw->forward_host)
292 /* if forwarding, just pass the request as is */
293 enlist(csp->headers, http->cmd);
299 /* otherwise elide the host information from the url */
301 p = strsav(p, http->gpc);
303 p = strsav(p, http->path);
305 p = strsav(p, http->ver);
306 enlist(csp->headers, p);
311 /* decide what we're to do with cookies */
314 if (!csp->toggled_on)
316 /* Most compatible set of permissions */
317 csp->permissions = PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | PERMIT_POPUPS;
321 csp->permissions = url_permissions(http, csp);
323 #else /* ifndef TOGGLE */
324 csp->permissions = url_permissions(http, csp);
325 #endif /* ndef TOGGLE */
328 block_popups = ((csp->permissions & PERMIT_POPUPS) == 0);
329 #endif /* def KILLPOPUPS */
331 pcrs_filter = (csp->rlist != NULL) && /* There are expressions to be used */
332 ((csp->permissions & PERMIT_RE_FILTER) != 0);
333 #endif /* def PCRS */
336 /* grab the rest of the client's headers */
340 if ( ( p = get_header(csp) ) && ( *p == '\0' ) )
342 n = read_socket(csp->cfd, buf, sizeof(buf));
345 log_error(LOG_LEVEL_ERROR, "read from client failed: %E");
348 add_to_iob(csp, buf, n);
352 if (p == NULL) break;
354 enlist(csp->headers, p);
358 /* filter it as required */
360 hdr = sed(client_patterns, add_client_headers, csp);
362 destroy_list(csp->headers);
364 /* Check the request against all rules, unless
365 * we're toggled off or in force mode.
371 #endif /* def FORCE_LOAD */
372 ( (p = intercept_url(http, csp)) ||
374 (p = block_url(http, csp))
375 #ifdef FAST_REDIRECTS
376 || (fast_redirects && (p = redirect_url(http, csp)))
377 #endif /* def FAST_REDIRECTS */
382 #endif /* def STATISTICS */
384 log_error(LOG_LEVEL_GPC, "%s%s crunch!", http->hostport, http->path);
386 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
387 /* Block as image? */
388 if ( (tinygif > 0) && block_imageurl(http, csp) )
390 /* Send "blocked" image */
391 log_error(LOG_LEVEL_GPC, "%s%s image crunch!",
392 http->hostport, http->path);
394 if ((tinygif == 2) || strstr(http->path, "ijb-send-banner"))
396 write_socket(csp->cfd, JBGIF, sizeof(JBGIF)-1);
400 write_socket(csp->cfd, BLANKGIF, sizeof(BLANKGIF)-1);
402 else if ((tinygif == 3) && (tinygifurl))
404 p = (char *)malloc(strlen(HTTP_REDIRECT_TEMPLATE) + strlen(tinygifurl));
405 sprintf(p, HTTP_REDIRECT_TEMPLATE, tinygifurl);
406 write_socket(csp->cfd, p, strlen(p));
410 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
413 /* Send HTML "blocked" message, interception, or redirection result */
414 write_socket(csp->cfd, p, strlen(p));
417 log_error(LOG_LEVEL_LOG, "%s", p);
424 log_error(LOG_LEVEL_GPC, "%s%s", http->hostport, http->path);
426 if (gw->forward_host)
428 log_error(LOG_LEVEL_CONNECT, "via %s:%d to: %s",
429 gw->forward_host, gw->forward_port, http->hostport);
433 log_error(LOG_LEVEL_CONNECT, "to %s", http->hostport);
436 /* here we connect to the server, gateway, or the forwarder */
438 csp->sfd = (gw->conn)(gw, http, csp);
442 log_error(LOG_LEVEL_CONNECT, "connect to: %s failed: %E",
447 err = zalloc(strlen(CNXDOM) + strlen(http->host));
448 sprintf(err, CNXDOM, http->host);
452 eno = safe_strerror(errno);
453 err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno));
454 sprintf(err, CFAIL, http->hostport, eno);
457 write_socket(csp->cfd, err, strlen(err));
459 log_error(LOG_LEVEL_LOG, err);
466 log_error(LOG_LEVEL_CONNECT, "OK");
468 if (gw->forward_host || (http->ssl == 0))
470 /* write the client's (modified) header to the server
471 * (along with anything else that may be in the buffer)
476 if ((write_socket(csp->sfd, hdr, n) != n)
477 || (flush_socket(csp->sfd, csp ) < 0))
479 log_error(LOG_LEVEL_CONNECT, "write header to: %s failed: %E",
482 eno = safe_strerror(errno);
483 err = zalloc(strlen(CFAIL) + strlen(http->hostport) + strlen(eno));
484 sprintf(err, CFAIL, http->hostport, eno);
485 write_socket(csp->cfd, err, strlen(err));
495 * We're running an SSL tunnel and we're not forwarding,
496 * so just send the "connect succeeded" message to the
497 * client, flush the rest, and get out of the way.
499 if (write_socket(csp->cfd, CSUCCEED, sizeof(CSUCCEED)-1) < 0)
507 /* we're finished with the client's header */
510 maxfd = ( csp->cfd > csp->sfd ) ? csp->cfd : csp->sfd;
512 /* pass data between the client and server
513 * until one or the other shuts down the connection.
522 FD_SET(csp->cfd, &rfds);
523 FD_SET(csp->sfd, &rfds);
525 n = select(maxfd+1, &rfds, NULL, NULL, NULL);
529 log_error(LOG_LEVEL_ERROR, "select() failed!: %E");
533 /* this is the body of the browser's request
534 * just read it and write it.
537 if (FD_ISSET(csp->cfd, &rfds))
539 n = read_socket(csp->cfd, buf, sizeof(buf));
541 if (n <= 0) break; /* "game over, man" */
543 if (write_socket(csp->sfd, buf, n) != n)
545 log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host);
552 * The server wants to talk. It could be the header or the body.
553 * If `hdr' is null, then it's the header otherwise it's the body.
554 * FIXME: Does `hdr' really mean `host'?
558 if (FD_ISSET(csp->sfd, &rfds))
561 n = read_socket(csp->sfd, buf, sizeof(buf) - 1);
565 log_error(LOG_LEVEL_ERROR, "read from: %s failed: %E", http->host);
567 eno = safe_strerror(errno);
568 sprintf(buf, CFAIL, http->hostport, eno);
570 write_socket(csp->cfd, buf, strlen(buf));
574 /* Add a trailing zero. This lets filter_popups
575 * use string operations.
580 /* Filter the popups on this read. */
581 if (block_popups_now)
583 filter_popups(buf, n);
585 #endif /* def KILLPOPUPS */
587 /* Normally, this would indicate that we've read
588 * as much as the server has sent us and we can
589 * close the client connection. However, Microsoft
590 * in its wisdom has released IIS/5 with a bug that
591 * prevents it from sending the trailing \r\n in
592 * a 302 redirect header (and possibly other headers).
593 * To work around this if we've haven't parsed
594 * a full header we'll append a trailing \r\n
595 * and see if this now generates a valid one.
597 * This hack shouldn't have any impacts. If we've
598 * already transmitted the header or if this is a
599 * SSL connection, then we won't bother with this
600 * hack. So we only work on partially received
601 * headers. If we append a \r\n and this still
602 * doesn't generate a valid header, then we won't
603 * transmit anything to the client.
607 /* This hack must only be enforced for headers. */
608 if (server_body || http->ssl)
613 re_process_buffer(csp);
615 #endif /* def PCRS */
616 break; /* "game over, man" */
619 /* Let's pretend the server just sent us a blank line. */
620 n = sprintf(buf, "\r\n");
623 * Now, let the normal header parsing algorithm below do its
624 * job. If it fails, we'll exit instead of continuing.
631 * If this is an SSL connection or we're in the body
632 * of the server document, just write it to the client.
635 if (server_body || http->ssl)
640 add_to_iob(csp, buf, n); /* Buffer the body for filtering */
643 #endif /* def PCRS */
646 if (write_socket(csp->cfd, buf, n) != n)
648 log_error(LOG_LEVEL_ERROR, "write to client failed: %E");
656 /* we're still looking for the end of the
657 * server's header ... (does that make header
658 * parsing an "out of body experience" ?
661 /* buffer up the data we just read */
662 add_to_iob(csp, buf, n);
664 /* get header lines from the iob */
666 while ((p = get_header(csp)))
670 /* see following note */
673 enlist(csp->headers, p);
677 /* NOTE: there are no "empty" headers so
678 * if the pointer `p' is not NULL we must
679 * assume that we reached the end of the
680 * buffer before we hit the end of the header.
687 /* Well, we tried our MS IIS/5
688 * hack and it didn't work.
689 * The header is incomplete
690 * and there isn't anything
691 * we can do about it.
697 /* Since we have to wait for
698 * more from the server before
699 * we can parse the headers
700 * we just continue here.
706 /* we have now received the entire header.
707 * filter it and send the result to the client
710 hdr = sed(server_patterns, add_server_headers, csp);
713 /* write the server's (modified) header to
714 * the client (along with anything else that
715 * may be in the buffer)
719 /* Start blocking popups if appropriate. */
721 if (csp->is_text && /* It's a text / * MIME-Type */
722 !http->ssl && /* We talk plaintext */
725 block_popups_now = 1;
728 #endif /* def KILLPOPUPS */
731 /* Start re_filtering this if appropriate. */
733 if (csp->is_text && /* It's a text / * MIME-Type */
734 !http->ssl && /* We talk plaintext */
735 pcrs_filter) /* Policy allows */
740 /* This next line is a little ugly, but it simplifies the if statement below. */
741 /* Basically if using PCRS, we want the OR condition to require "!filtering" */
742 #define NOT_FILTERING_AND !filtering &&
744 #else /* not def PCRS */
746 #define NOT_FILTERING_AND
748 #endif /* def PCRS */
751 if ((write_socket(csp->cfd, hdr, n) != n)
752 || (NOT_FILTERING_AND (flush_socket(csp->cfd, csp) < 0)))
754 log_error(LOG_LEVEL_CONNECT, "write header to client failed: %E");
756 /* the write failed, so don't bother
757 * mentioning it to the client...
758 * it probably can't hear us anyway.
764 /* we're finished with the server's header */
769 /* If this was a MS IIS/5 hack then it means
770 * the server has already closed the
771 * connection. Nothing more to read. Time
782 return; /* huh? we should never get here */
789 /*********************************************************************
793 * Description : This is little more than chat. We only "serve" to
794 * to close any socket that chat may have opened.
797 * 1 : csp = Current client state (buffers, headers, etc...)
801 *********************************************************************/
802 static void serve(struct client_state *csp)
805 close_socket(csp->cfd);
809 close_socket(csp->sfd);
819 /*********************************************************************
821 * Function : server_thread
823 * Description : We only exist to call `serve' in a threaded environment.
826 * 1 : data = Current client state (buffers, headers, etc...)
828 * Returns : Always 0.
830 *********************************************************************/
831 static int32 server_thread(void *data)
833 serve((struct client_state *) data);
841 /*********************************************************************
845 * Description : Load the config file and start the listen loop.
846 * This function is a lot more *sane* with the `load_config'
847 * and `listen_loop' functions; although it stills does
848 * a *little* too much for my taste.
851 * 1 : argc = Number of parameters (including $0).
852 * 2 : argv = Array of (char *)'s to the parameters.
854 * Returns : 1 if : can't open config file, unrecognized directive,
855 * stats requested in multi-thread mode, can't open the
856 * log file, can't open the jar file, listen port is invalid,
857 * any load fails, and can't bind port.
859 * Else main never returns, the process must be signaled
860 * to terminate execution. Or, on Windows, use the
861 * "File", "Exit" menu option.
863 *********************************************************************/
865 int _main(int argc, const char *argv[])
867 int main(int argc, const char *argv[])
878 #if !defined(_WIN32) || defined(_WIN_CONSOLE)
879 if ((argc >= 2) && (strcmp(argv[1], "--help")==0))
881 printf("JunkBuster proxy version " VERSION ".\n\n"
882 "Usage: %s [configfile]\n\n"
883 "See " HOME_PAGE_URL " for details.\n"
884 "This program is distributed under the GNU GPL, version 2 or later.\n",
888 if ((argc >= 2) && (strcmp(argv[1], "--version")==0))
890 printf(VERSION "\n");
893 #endif /* !defined(_WIN32) || defined(_WIN_CONSOLE) */
900 configfile = argv[1];
903 remove_all_loaders();
904 memset( proxy_args, 0, sizeof( proxy_args ) );
910 * Since load_config acts as a signal handler too, it returns
911 * its status in configret. Check it for an error in loading.
913 if ( 0 != configret )
915 /* load config failed! Exit with error. */
925 signal(SIGPIPE, SIG_IGN);
926 signal(SIGCHLD, SIG_IGN);
927 signal(SIGHUP, load_config);
929 #else /* ifdef _WIN32 */
932 * We *are* in a windows console app.
933 * Print a verbose messages about FAQ's and such
936 # endif /* def _WIN_CONSOLE */
937 #endif /* def _WIN32 */
948 /*********************************************************************
950 * Function : listen_loop
952 * Description : bind the listen port and enter a "FOREVER" listening loop.
958 *********************************************************************/
959 static void listen_loop(void)
961 struct client_state *csp = NULL;
964 log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)",
965 haddr ? haddr : "INADDR_ANY", hport);
967 bfd = bind_port(haddr, hport);
972 log_error(LOG_LEVEL_FATAL, "can't bind %s:%d: %E "
973 "- There may be another junkbuster or some other "
974 "proxy running on port %d",
975 (NULL != haddr) ? haddr : "INADDR_ANY", hport, hport
977 /* shouldn't get here */
984 #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA)
985 while (waitpid(-1, NULL, WNOHANG) > 0)
987 /* zombie children */
989 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */
992 if ( NULL == (csp = (struct client_state *) malloc(sizeof(*csp))) )
994 log_error(LOG_LEVEL_ERROR, "malloc(%d) for csp failed: %E", sizeof(*csp));
998 memset(csp, '\0', sizeof(*csp));
1003 if ( config_changed )
1006 * Since we were listening to the "old port", we will not see
1007 * a "listen" param change until the next IJB request. So, at
1008 * least 1 more request must be made for us to find the new
1009 * setting. I am simply closing the old socket and binding the
1012 * Which-ever is correct, we will serve 1 more page via the
1013 * old settings. This should probably be a "show-proxy-args"
1014 * request. This should not be a so common of an operation
1015 * that this will hurt people's feelings.
1019 log_error(LOG_LEVEL_CONNECT, "bind (%s, %d)",
1020 haddr ? haddr : "INADDR_ANY", hport);
1021 bfd = bind_port(haddr, hport);
1026 log_error(LOG_LEVEL_CONNECT, "accept connection ... ");
1028 if (!accept_connection(csp, bfd))
1030 log_error(LOG_LEVEL_CONNECT, "accept failed: %E");
1042 log_error(LOG_LEVEL_CONNECT, "OK");
1046 /* by haroon - most of credit to srt19170 */
1047 csp->toggled_on = g_bToggleIJB;
1050 /* add it to the list of clients */
1051 csp->next = clients->next;
1052 clients->next = csp;
1054 if (run_loader(csp))
1056 log_error(LOG_LEVEL_FATAL, "a loader failed - must exit");
1057 /* Never get here - LOG_LEVEL_FATAL causes program exit */
1064 /* this is a switch () statment in the C preprocessor - ugh */
1065 #undef SELECTED_ONE_OPTION
1067 #if defined(_WIN32) && !defined(_CYGWIN) && !defined(SELECTED_ONE_OPTION)
1068 #define SELECTED_ONE_OPTION
1069 child_id = _beginthread(
1075 #if defined(__BEOS__) && !defined(SELECTED_ONE_OPTION)
1076 #define SELECTED_ONE_OPTION
1078 thread_id tid = spawn_thread
1079 (server_thread, "server", B_NORMAL_PRIORITY, csp);
1081 if ((tid >= 0) && (resume_thread(tid) == B_OK))
1083 child_id = (int) tid;
1092 #if defined(AMIGA) && !defined(SELECTED_ONE_OPTION)
1093 #define SELECTED_ONE_OPTION
1094 csp->cfd = ReleaseSocket(csp->cfd, -1);
1095 if((child_id = (int)CreateNewProcTags(
1096 NP_Entry, (ULONG)server_thread,
1097 NP_Output, Output(),
1098 NP_CloseOutput, FALSE,
1099 NP_Name, (ULONG)"junkbuster child",
1100 NP_StackSize, 20*1024,
1104 ((struct Task *)child_id)->tc_UserData = csp;
1105 Signal((struct Task *)child_id, SIGF_SINGLE);
1110 #if !defined(SELECTED_ONE_OPTION)
1114 #undef SELECTED_ONE_OPTION
1115 /* end of cpp switch () */
1117 if (child_id < 0) /* failed */
1121 log_error(LOG_LEVEL_ERROR, "can't fork: %E");
1123 sprintf(buf , "JunkBuster: can't fork: errno = %d", errno);
1125 write_socket(csp->cfd, buf, strlen(buf));
1126 close_socket(csp->cfd);
1132 #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA)
1133 /* This block is only needed when using fork().
1134 * When using threads, the server thread was
1135 * created and run by the call to _beginthread().
1137 if (child_id == 0) /* child */
1145 /* in a fork()'d environment, the parent's
1146 * copy of the client socket and the CSP
1150 #if !defined(_WIN32) && defined(__CYGWIN__)
1152 #endif /* !defined(_WIN32) && defined(__CYGWIN__) */
1153 close_socket(csp->cfd);
1156 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */