-const char jcc_rcs[] = "$Id: jcc.c,v 1.92.2.3 2003/02/28 12:53:06 oes Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.92.2.6 2003/03/11 11:55:00 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/Attic/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.92.2.6 2003/03/11 11:55:00 oes
+ * Clean-up and extension of improvements for forked mode:
+ * - Child's return code now consists of flags RC_FLAG_*
+ * - Reporting toggle to parent now properly #ifdef'ed
+ * - Children now report blocking to parent. This enables
+ * statistics in forked mode
+ *
+ * Revision 1.92.2.5 2003/03/10 23:45:32 oes
+ * Fixed bug #700381: Non-Threaded version now capable of being toggled.
+ * Children now report having been toggled through _exit(17), parents
+ * watch for that code and toggle themselves if found.
+ *
+ * Revision 1.92.2.4 2003/03/07 03:41:04 david__schmidt
+ * Wrapping all *_r functions (the non-_r versions of them) with mutex semaphores for OSX. Hopefully this will take care of all of those pesky crash reports.
+ *
* Revision 1.92.2.3 2003/02/28 12:53:06 oes
* Fixed two mostly harmless mem leaks
*
struct passwd *pw = NULL;
struct group *grp = NULL;
char *p;
+ int do_chroot = 0;
#endif
Argc = argc;
if (p != NULL) *--p = '\0';
}
+
+ else if (strcmp(argv[argc_pos], "--chroot" ) == 0)
+ {
+ do_chroot = 1;
+ }
#endif /* defined(unix) */
else
#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
{
log_error(LOG_LEVEL_FATAL, "Cannot setgid(): Insufficient permissions.");
}
+ if (do_chroot)
+ {
+ if (!pw->pw_dir)
+ {
+ log_error(LOG_LEVEL_FATAL, "Home directory for %s undefined", pw->pw_name);
+ }
+ if (chroot(pw->pw_dir) < 0)
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot chroot to %s", pw->pw_dir);
+ }
+ if (chdir ("/"))
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot chdir /");
+ }
+ }
if (setuid(pw->pw_uid))
{
log_error(LOG_LEVEL_FATAL, "Cannot setuid(): Insufficient permissions.");
}
+ if (do_chroot)
+ {
+ if (setenv ("HOME", "/", 1) < 0)
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot setenv(): HOME");
+ }
+ if (setenv ("USER", pw->pw_name, 1) < 0)
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot setenv(): USER");
+ }
+ }
+ }
+ else if (do_chroot)
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot chroot without --user argument.");
}
}
#endif /* defined unix */
}
#ifdef FEATURE_TOGGLE
- if (g_bToggleIJB)
+ if (global_toggle_state)
{
csp->flags |= CSP_FLAG_TOGGLED_ON;
}
#if defined(AMIGA) && !defined(SELECTED_ONE_OPTION)
#define SELECTED_ONE_OPTION
csp->cfd = ReleaseSocket(csp->cfd, -1);
+
if((child_id = (int)CreateNewProcTags(
NP_Entry, (ULONG)server_thread,
NP_Output, Output(),
*/
if (child_id == 0) /* child */
{
+ int rc = 0;
+#ifdef FEATURE_TOGGLE
+ int inherited_toggle_state = global_toggle_state;
+#endif /* def FEATURE_TOGGLE */
+
serve(csp);
- _exit(0);
+ /*
+ * If we've been toggled or we'be blocked the request, tell Mom
+ */
+
+#ifdef FEATURE_TOGGLE
+ if (inherited_toggle_state != global_toggle_state)
+ {
+ rc |= RC_FLAG_TOGGLED;
+ }
+#endif /* def FEATURE_TOGGLE */
+
+#ifdef FEATURE_STATISTICS
+ if (csp->flags & CSP_FLAG_REJECTED)
+ {
+ rc |= RC_FLAG_BLOCKED;
+ }
+#endif /* ndef FEATURE_STATISTICS */
+
+ _exit(rc);
}
else if (child_id > 0) /* parent */
{
* copy of the client socket and the CSP
* are not used.
*/
+ int child_status;
+#if !defined(_WIN32) && !defined(__CYGWIN__)
+
+ wait( &child_status );
+
+ /*
+ * Evaluate child's return code: If the child has
+ * - been toggled, toggle ourselves
+ * - blocked its request, bump up the stats counter
+ */
+
+#ifdef FEATURE_TOGGLE
+ if (WIFEXITED(child_status) && (WEXITSTATUS(child_status) & RC_FLAG_TOGGLED))
+ {
+ global_toggle_state = !global_toggle_state;
+ }
+#endif /* def FEATURE_TOGGLE */
+
+#ifdef FEATURE_STATISTICS
+ urls_read++;
+ if (WIFEXITED(child_status) && (WEXITSTATUS(child_status) & RC_FLAG_BLOCKED))
+ {
+ urls_rejected++;
+ }
+#endif /* def FEATURE_STATISTICS */
-#if !defined(_WIN32) && defined(__CYGWIN__)
- wait( NULL );
#endif /* !defined(_WIN32) && defined(__CYGWIN__) */
close_socket(csp->cfd);
csp->flags &= ~CSP_FLAG_ACTIVE;