--- nocatauth-0.82+20040527nightly.orig/bin/gateway
+++ nocatauth-0.82+20040527nightly/bin/gateway
@@ -7,6 +7,7 @@
 use lib "$FindBin::Bin/../lib";
 use NoCat;
 use strict;
+use sigtrap qw(stack-trace untrapped error-signals);
 
 # Gracefully handle termination signals.
 $SIG{INT} = sub { exit };
@@ -58,7 +59,21 @@
     } elsif ( not defined $pid ) {
 	die "Can't fork: $!";
     }
-    setsid;
+
+    die "Cannot detach from controlling terminal"
+	unless setsid();
+
+    chdir '/' or die "Can't chdir('/'), $!\n";
+    umask 0;
+
+    # reopen stdin to /dev/null
+    open(STDIN,  "</dev/null");
+
+    # reopen stdout, stderr to /dev/null if not needed for logging
+    if ($server->{LogFacility} eq 'syslog') {
+	open(STDOUT, ">/dev/null");
+	open(STDERR, ">&STDOUT");
+    }
 }
 
 # Fork a child process and watch it, if we're in debug mode.
--- nocatauth-0.82+20040527nightly.orig/lib/NoCat/Gateway.pm
+++ nocatauth-0.82+20040527nightly/lib/NoCat/Gateway.pm
@@ -96,7 +96,8 @@
     return unless $self->bind_socket;
 
     local $SIG{PIPE} = "IGNORE"; 
-    local $SIG{CHLD} = sub { $kids++ };
+    local $SIG{CHLD} = 'IGNORE';    # the OS does the dirty job
+    #local $SIG{CHLD} = sub { $kids++ };
     local $SIG{HUP} = sub { $hup++ };
 
     # Reset history.
@@ -135,11 +136,13 @@
             $hup = 0;
         }
 
+	# changed by kg, let the OS do the dirty job
+	#
 	# See if any kids have expired, reap zombies
-	if ( $kids ) {
-	    1 until ( wait == -1 );
-	    $kids = 0;
-	}
+	#if ( $kids ) {
+	#    1 until ( wait == -1 );
+	#    $kids = 0;
+	#}
 
     } # loop forever
 }
--- nocatauth-0.82+20040527nightly.orig/lib/NoCat/AuthService.pm
+++ nocatauth-0.82+20040527nightly/lib/NoCat/AuthService.pm
@@ -289,9 +289,11 @@
     my $redirect = $vars{redirect} || $self->{HomePage};
 
     # Add a refresh time of five seconds... unless one is already set.
-    $vars{redirect} = $redirect = "5; URL=$redirect" unless $redirect =~ /^\d+;/o;
 
-    push @headers, -Refresh => $redirect;
+    $vars{http_redirect} = $redirect;
+    $vars{http_redirect} = "5; URL=$redirect" unless $redirect =~ /^\d+;/o;
+    push @headers, -Refresh => $vars{http_redirect};
+
     # push @headers, -Cookie => $self->{Cookie} if $self->{Cookie};
 
     # Hit the g/w with the ticket first if there is one, get a 304, 
--- nocatauth-0.82+20040527nightly.orig/lib/NoCat/Firewall.pm
+++ nocatauth-0.82+20040527nightly/lib/NoCat/Firewall.pm
@@ -21,6 +21,10 @@
     MembersOnly RouteOnly IgnoreMAC
 );
 
+# not in qw() in order to have independent patches
+# put these independent patches together in the next release -- charly
+push @Perform_Export, 'BinPath';
+
 # If /proc/net/arp is available, use it. Otherwise, fork /sbin/arp and read
 # its output to get ARP cache data. Turns out '/sbin/arp -an' gives the same
 # output on both Linux and *BSD. (Thank goodness.)
--- nocatauth-0.82+20040527nightly.orig/lib/NoCat/Message.pm
+++ nocatauth-0.82+20040527nightly/lib/NoCat/Message.pm
@@ -48,7 +48,7 @@
 
     } elsif ( $self->{GpgPath} and $self->{PGPKeyPath} and $Cmd_Map{$cmd} ) {
 	$cmd = "$self->{GpgPath} $Cmd_Map{$cmd} --homedir=$self->{PGPKeyPath} " .
-	    "--keyring trustedkeys.gpg --no-tty -o-";
+	    "--keyring trustedkeys.gpg --no-tty --no-secmem-warning -o-";
 	$cmd .= " 2>/dev/null" if $self->{Verbosity} < 7;
 
     } else {
--- nocatauth-0.82+20040527nightly.orig/lib/NoCat.pm
+++ nocatauth-0.82+20040527nightly/lib/NoCat.pm
@@ -54,6 +54,9 @@
     ### Where to look for form templates?
     DocumentRoot    => "$FindBin::Bin/../htdocs",
 
+    ### Where to look for executables
+    BinPath         => "$FindBin::Bin",
+
     ### Default log level.
     Verbosity	    => 5,
     LogFacility     => "internal",
--- nocatauth-0.82+20040527nightly.orig/libexec/iptables/initialize.fw
+++ nocatauth-0.82+20040527nightly/libexec/iptables/initialize.fw
@@ -235,7 +235,7 @@
 #
 # chmod +x throttle.fw
 #
-[ -x throttle.fw ] && throttle.fw
+[ -x $BinPath/throttle.fw ] && $BinPath/throttle.fw
 
 ##
 # Add any other local firewall rules below.
--- nocatauth-0.82+20040527nightly.orig/htdocs/renew_pasv.html
+++ nocatauth-0.82+20040527nightly/htdocs/renew_pasv.html
@@ -1,7 +1,7 @@
 <html>
 <head>
     <title>NoCat login agent</title>
-    <meta http-equiv="Refresh" content="$redirect" />
+    <meta http-equiv="Refresh" content="$http_redirect" />
 </head>
 <script language="JavaScript">
     setTimeout( "document.RenewalForm.submit()", $timeout * 1000 );
--- nocatauth-0.82+20040527nightly.orig/htdocs/login_ok.html
+++ nocatauth-0.82+20040527nightly/htdocs/login_ok.html
@@ -1,7 +1,7 @@
 <html>
 <head>
     <title>Welcome, $user!</title>
-    <meta http-equiv="Refresh" content="$redirect" />
+    <meta http-equiv="Refresh" content="$http_redirect" />
 </head>
 <script language="JavaScript">
     window.open( "$popup", "NoCat_Login_Renewal", "width=250,height=180,scrollbars=no" );	
--- nocatauth-0.82+20040527nightly.orig/htdocs/renew.html
+++ nocatauth-0.82+20040527nightly/htdocs/renew.html
@@ -1,7 +1,7 @@
 <html>
 <head>
     <title>NoCat login agent</title>
-    <meta http-equiv="Refresh" content="$redirect" />
+    <meta http-equiv="Refresh" content="$http_redirect" />
 </head>
 <body bgcolor="#FFFFFF">
 <p><a href="http://nocat.net" target="_blank"><img src="/images/auth_logo.gif" width="112" height="35" border="0"></a> </p>
--- nocatauth-0.82+20040527nightly.orig/htdocs/register_ok.html
+++ nocatauth-0.82+20040527nightly/htdocs/register_ok.html
@@ -1,7 +1,7 @@
 <html>
 <head>
     <title>Welcome, $name!</title>
-    <meta http-equiv="Refresh" content="$redirect" />
+    <meta http-equiv="Refresh" content="$http_redirect" />
 </head>
 <body bgcolor="#FFFFFF">
 <h1><a href="http://nocat.net"><img src="/images/auth_logo.gif" width="112" height="35" border="0"></a></h1>
--- nocatauth-0.82+20040527nightly.orig/cgi-bin/login
+++ nocatauth-0.82+20040527nightly/cgi-bin/login
@@ -33,7 +33,7 @@
 ));
 
 $authserv->log( 7, sprintf( "User %s from %s requests %s", 
-    $params->{user} || "UNKNOWN", $cgi->remote_host, 
+    $params->{user} || ANONYMOUS, $cgi->remote_host, 
     lc( $params->{mode} ) || "form" ) 
 );
 
--- nocatauth-0.82+20040527nightly.orig/cgi-bin/admlogin
+++ nocatauth-0.82+20040527nightly/cgi-bin/admlogin
@@ -13,7 +13,7 @@
 ###
 
 use lib '../lib/';
-use NoCat;
+use NoCat qw( ANONYMOUS );
 use strict;
 
 my $authserv	= NoCat->auth_service( ConfigFile => $ENV{NOCAT} );
@@ -27,7 +27,7 @@
 ));
 
 $authserv->log( 7, sprintf( "User %s from %s requests %s", 
-    $params->{user} || "UNKNOWN", $cgi->remote_host, lc( $params->{mode} ) || "form" ) );
+    $params->{user} || ANONYMOUS, $cgi->remote_host, lc( $params->{mode} ) || "form" ) );
 
 # Figure out which image button was clicked (since they don't have value="" attributes).
 if (my ($button) = grep $params->{"mode_$_.x"}, qw( login skip logout )) {
--- nocatauth-0.82+20040527nightly.orig/debian/changelog
+++ nocatauth-0.82+20040527nightly/debian/changelog
@@ -0,0 +1,83 @@
+nocatauth (0.82+20040527nightly-0.1) unstable; urgency=high
+
+  * daemonize-04.patch
+  * anonymous-01.patch
+  * gpg-secmem-01.patch
+  * http_redirect_header-01.patch
+
+ -- Punky Tse <punkytse@yahoo.com>  Tue, 23 May 2004 22:59:13 +0800
+
+nocatauth (0.82+20031109nightly-0.1) unstable; urgency=high
+
+  * New nightly build.
+  * Still include stable-01.patch; it has not yet been integrated upstream.
+  * Changed the nocatauth-gateway init.d script to use --name $NAME
+    instead of --exec $DAEMON when stopping.
+  * Removed PERL5LIB environment variable from nocatauth-gateway init.d
+    script; it was completely unnecessary and potentially confusing.
+
+ -- Keegan Quinn <ice@thebasement.org>  Sun, 09 Nov 2003 12:59:13 -0800
+
+nocatauth (0.82+20031108nightly-0.1) unstable; urgency=high
+
+  * New nightly build.
+  * Added stable-01.patch.
+
+ -- Keegan Quinn <ice@thebasement.org>  Sat, 08 Nov 2003 13:28:04 -0800
+
+nocatauth (0.82+20031105nightly-0.1) unstable; urgency=high
+
+  * New maintainer.
+  * New nightly build.
+  * Change of version numbering.  No epoch is necessary since the older
+    packages were never uploaded to the pool.
+  * Removed unused debian/README.Debian.
+  * Split into two binary packages: nocatauth-gateway and nocatauth-authserv.
+  * Updated descriptions.
+  * Trimmed debian/copyright, fixed URL and added reference to
+    /usr/share/common-licenses/GPL.
+  * Removed LICENSE from debian/docs; Debian systems include a system-wide
+    copy of the GPL.
+  * Removed debconf-related files and dependancies.  These need to be
+    modified to not lose administrator changes even when "managing with
+    debconf," and extended to include authserv.
+  * Updated Standards-Version; this package should be compliant to policy
+    version 3.6.1.
+  * Switched to CDBS; added Build-Depends on cdbs.
+  * Reorganized files to use /usr/share/nocatauth for the program and
+    /etc/nocatauth for configurable things.
+  * Now records build environment information into packages with
+    dh-buildinfo.
+
+ -- Keegan Quinn <ice@thebasement.org>  Wed, 05 Nov 2003 16:46:24 -0800
+
+nocatauth (20030325-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Brian Beattie <beattie@coyote.pdx.beattie-home.net>  Tue, 25 Mar 2003 19:14:48 -0800
+
+nocatauth (0.81-4) unstable; urgency=low
+
+  * fix bug in postinst
+
+ -- Brian Beattie <beattie@beattie-home.net>  Tue, 18 Feb 2003 01:39:40 -0800
+
+nocatauth (0.81-3) unstable; urgency=high
+
+  * update template and postinst to select throttle script
+
+ -- Brian Beattie <beattie@beattie-home.net>  Mon, 17 Feb 2003 17:14:08 -0800
+
+nocatauth (0.81-2) unstable; urgency=low
+
+  * fix postinst script to link in the correct firewall scripts
+
+ -- Brian Beattie <beattie@beattie-home.net>  Mon, 17 Feb 2003 16:57:19 -0800
+
+nocatauth (0.81-1) unstable; urgency=low
+
+  * Initial Release.
+
+ -- Brian Beattie <beattie@beattie-home.net>  Fri, 14 Feb 2003 16:16:09 -0800
+
--- nocatauth-0.82+20040527nightly.orig/debian/compat
+++ nocatauth-0.82+20040527nightly/debian/compat
@@ -0,0 +1 @@
+4
--- nocatauth-0.82+20040527nightly.orig/debian/control
+++ nocatauth-0.82+20040527nightly/debian/control
@@ -0,0 +1,39 @@
+Source: nocatauth
+Section: net
+Priority: optional
+Maintainer: Keegan Quinn <ice@thebasement.org>
+Build-Depends: cdbs, debhelper (>> 4.1.0), dh-buildinfo, gnupg, iptables
+Standards-Version: 3.6.1
+
+Package: nocatauth-gateway
+Architecture: all
+Depends: perl-modules, iptables
+Recommends: gnupg
+Description: gateway daemon for the NoCatAuth captive portal
+ NoCatAuth is a system to control access to networks.  It operates
+ as a captive portal, also called an "open" or "active" portal.
+ When run on a gateway or router on a network, NoCatAuth's gateway
+ causes all web requests to be redirected to a "splash page," where
+ users must log in or (for example) agree to a usage policy.
+ .
+ The gateway daemon uses ipchains or iptables to set firewall rules to
+ control the flow of traffic, based on IP and MAC addresses.  NoCatAuth
+ supports advanced authentication features, handled by the authserv
+ daemon, which is included in the nocatauth-authserv package.
+
+Package: nocatauth-authserv
+Architecture: all
+Depends: perl-modules, gnupg
+Description: authentication server for the NoCatAuth captive portal
+ NoCatAuth is a system to control access to networks.  It operates
+ as a captive portal, also called an "open" or "active" portal.
+ When run on a gateway or router on a network, NoCatAuth's gateway
+ causes all web requests to be redirected to a "splash page," where
+ users must log in or (for example) agree to a usage policy.
+ .
+ The authentication server (authserv) handles authentication requests
+ from NoCatAuth gateway daemons.  It can use authentication data from
+ various data sources, including MySQL databases, RADIUS servers, and
+ plain text files.  The gateway daemon is included in the
+ nocatauth-gateway package.
+
--- nocatauth-0.82+20040527nightly.orig/debian/copyright
+++ nocatauth-0.82+20040527nightly/debian/copyright
@@ -0,0 +1,14 @@
+This package was debianized by Brian Beattie <beattie@beattie-home.net> on
+Fri, 14 Feb 2003 14:02:41 -0800.
+
+It was downloaded from http://nocat.net
+
+Upstream Authors: Schuyler Erle and Robert Flickenger
+
+Copyright (c) 2001, 2002 Schuyler Erle & Robert Flickenger.
+
+This software is covered by the GNU General Public License, Version 2.
+
+On Debian systems, the complete text of the GNU General Public License
+can be found in `/usr/share/common-licenses/GPL'.
+
--- nocatauth-0.82+20040527nightly.orig/debian/nocatauth-gateway.default
+++ nocatauth-0.82+20040527nightly/debian/nocatauth-gateway.default
@@ -0,0 +1,14 @@
+# Defaults for nocatauth-gateway initscript
+# sourced by /etc/init.d/nocatauth-gateway
+# installed at /etc/default/nocatauth-gateway by the maintainer scripts
+
+#
+# This is a POSIX shell fragment
+#
+
+# Full path to the gateway configuration file
+CONFIGFILE="/etc/nocatauth/gateway/nocat.conf"
+
+# Change this to true to enable the init.d script
+ENABLE=false
+
--- nocatauth-0.82+20040527nightly.orig/debian/nocatauth-gateway.init
+++ nocatauth-0.82+20040527nightly/debian/nocatauth-gateway.init
@@ -0,0 +1,56 @@
+#! /bin/sh
+#
+# nocatauth-gateway
+#
+#		Based on scripts from an unknown Red Hat package source
+#		and on Miquel van Smoorenburg and Ian Murdock's excellent
+#		work on Debian's standard init.d scripts.
+#
+
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+DAEMON=/usr/share/nocatauth/gateway/bin/gateway
+NAME=gateway
+DESC="NoCatAuth gateway"
+
+test -x $DAEMON || exit 0
+
+# Defaults
+CONFIGFILE="/etc/nocatauth/gateway/nocat.conf"
+CONFIGDEFAULTFILE="/etc/default/nocatauth-gateway"
+ENABLE="false"
+
+# Read config file (will override defaults above)
+[ -r "$CONFIGDEFAULTFILE" ] && . $CONFIGDEFAULTFILE
+
+if [ "$ENABLE" != "true" ]; then
+	echo "$NAME daemon disabled - read $CONFIGDEFAULTFILE."
+	exit 0
+fi
+
+set -e
+
+case "$1" in
+  start)
+        echo -n "Starting $DESC: "
+	start-stop-daemon --start --quiet --exec $DAEMON -- -f $CONFIGFILE
+	echo "$NAME."
+        ;;
+  stop)
+        echo "Stopping $DESC: "
+	start-stop-daemon --stop --oknodo --quiet --name $NAME
+	echo "$NAME."
+        ;;
+  reload|force-reload|restart)
+  	echo -n "Restarting $DESC: "
+	start-stop-daemon --stop --oknodo --quiet --name $NAME
+	sleep 1
+	start-stop-daemon --start --quiet --exec $DAEMON -- -f $CONFIGFILE
+	echo "$NAME."
+        ;;
+  *)
+        echo "Usage: $0 {start|stop|restart|reload|force-reload}"
+        exit 1
+	;;
+esac
+
+exit 0
--- nocatauth-0.82+20040527nightly.orig/debian/rules
+++ nocatauth-0.82+20040527nightly/debian/rules
@@ -0,0 +1,64 @@
+#!/usr/bin/make -f
+include /usr/share/cdbs/1/rules/debhelper.mk
+include /usr/share/cdbs/1/class/makefile.mk
+
+binary-install/nocatauth-gateway::
+	$(MAKE) DESTDIR=$(CURDIR)/debian/nocatauth-gateway \
+		PREFIX=/usr/share/nocatauth/gateway gateway
+
+binary-post-install/nocatauth-gateway::
+	# Move configuration file to proper location
+	mkdir -p $(CURDIR)/debian/nocatauth-gateway/etc/nocatauth/gateway
+	mv $(CURDIR)/debian/nocatauth-gateway/usr/share/nocatauth/gateway/nocat.conf \
+		$(CURDIR)/debian/nocatauth-gateway/etc/nocatauth/gateway/
+
+	# Move HTML templates to /etc and replace with a symlink
+	for file in `cd $(CURDIR)/debian/nocatauth-gateway/usr/share/nocatauth/gateway && find htdocs -type f -name *.html -o -name *.gif`; do \
+		mkdir -p $(CURDIR)/debian/nocatauth-gateway/etc/nocatauth/gateway/`dirname $$file`; \
+		mv $(CURDIR)/debian/nocatauth-gateway/usr/share/nocatauth/gateway/$$file $(CURDIR)/debian/nocatauth-gateway/etc/nocatauth/gateway/$$file; \
+	done
+	rm -rf $(CURDIR)/debian/nocatauth-gateway/usr/share/nocatauth/gateway/htdocs
+	ln -s /etc/nocatauth/gateway/htdocs \
+		$(CURDIR)/debian/nocatauth-gateway/usr/share/nocatauth/gateway/htdocs
+
+	# Store build information
+	dh_buildinfo
+
+binary-install/nocatauth-authserv::
+	$(MAKE) DESTDIR=$(CURDIR)/debian/nocatauth-authserv \
+		PREFIX=/usr/share/nocatauth/authserv authserv
+
+binary-post-install/nocatauth-authserv::
+	# These are not used by the authentication server...
+	# TODO patch upstream
+	rm -f $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/iptables \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/access.fw \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/clear.fw \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/dump.fw \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/initialize.fw \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/reset.fw \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/bin/throttle.fw
+
+	# This seems to be only for example purposes
+	rm -rf $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/etc
+
+	# Move configuration files to the proper location
+	mkdir -p $(CURDIR)/debian/nocatauth-authserv/etc/nocatauth/authserv
+	mv $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/nocat.conf \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/httpd.conf \
+		$(CURDIR)/debian/nocatauth-authserv/etc/nocatauth/authserv/
+
+	# Move HTML templates to /etc and replace with a symlink
+	for file in `cd $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv && find htdocs -type f -name *.html -o -name *.gif`; do \
+		mkdir -p $(CURDIR)/debian/nocatauth-authserv/etc/nocatauth/authserv/`dirname $$file`; \
+		mv $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/$$file $(CURDIR)/debian/nocatauth-authserv/etc/nocatauth/authserv/$$file; \
+	done
+	rm -rf $(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/htdocs
+	ln -s /etc/nocatauth/authserv/htdocs \
+		$(CURDIR)/debian/nocatauth-authserv/usr/share/nocatauth/authserv/htdocs
+
+clean::
+	# Upstream forgot to clean these, it seems...  TODO submit patch
+	rm -f bin/iptables bin/access.fw bin/clear.fw bin/dump.fw \
+		bin/initialize.fw bin/reset.fw bin/throttle.fw
+
