You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

213 lines
5.7 KiB

Index: Makefile
--- Makefile.orig 2003-05-23 20:10:13 +0200
+++ Makefile 2004-07-05 09:59:10 +0200
@@ -115,90 +115,90 @@
SYSTYPE=bsd
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
openbsd:
SYSTYPE=openbsd
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
freebsd:
SYSTYPE=freebsd
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
osx:
SYSTYPE=osx
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
netbsd:
SYSTYPE=netbsd
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
bsdi:
SYSTYPE=bsdi
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DBSD44 -o ./portsentry ./portsentry.c \
- ./portsentry_io.c ./portsentry_util.c
+ ./portsentry_io.c ./portsentry_util.c $(LIBS)
generic:
SYSTYPE=generic
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
hpux:
SYSTYPE=hpux
@echo "Making $(SYSTYPE)"
$(CC) -Ae -DHPUX -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
hpux-gcc:
SYSTYPE=hpux-gcc
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -DHPUX -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
solaris:
SYSTYPE=solaris
@echo "Making $(SYSTYPE)"
$(CC) -lnsl -lsocket -lresolv -lc -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
aix:
SYSTYPE=aix
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
osf:
SYSTYPE=osf
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -taso -ldb -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
irix:
SYSTYPE=irix
@echo "Making $(SYSTYPE)"
$(CC) $(CFLAGS) -O -n32 -mips3 -o ./portsentry ./portsentry.c ./portsentry_io.c \
- ./portsentry_util.c
+ ./portsentry_util.c $(LIBS)
# NeXTSTEP Users. NeXT used to work, but we changed the log function and
Index: portsentry.c
--- portsentry.c.orig 2003-05-23 20:10:13 +0200
+++ portsentry.c 2004-07-05 09:59:34 +0200
@@ -41,7 +41,7 @@
int
main (int argc, char *argv[])
{
- if (argc != 2)
+ if (argc != 2 && argc != 3)
{
Usage ();
Exit (ERROR);
@@ -91,7 +91,7 @@
Exit (ERROR);
}
#ifndef NODAEMON
- else if (DaemonSeed () == ERROR)
+ else if (DaemonSeed (argc > 2 ? argv[2] : NULL) == ERROR)
{
Log ("adminalert: ERROR: could not go into daemon mode. Shutting down.\n");
printf ("ERROR: could not go into daemon mode. Shutting down.\n");
@@ -1581,15 +1581,14 @@
Usage (void)
{
printf ("PortSentry - Port Scan Detector.\n");
- printf ("Copyright 1997-2003 Craig H. Rowland <craigrowland at users dot
-sourceforget dot net>\n");
+ printf ("Copyright 1997-2003 Craig H. Rowland <craigrowland at users dot sourceforget dot net>\n");
printf ("Licensing restrictions apply. Please see documentation\n");
printf ("Version: %s\n\n", VERSION);
#ifdef SUPPORT_STEALTH
- printf ("usage: portsentry [-tcp -udp -stcp -atcp -sudp -audp]\n\n");
+ printf ("usage: portsentry [-tcp -udp -stcp -atcp -sudp -audp] [pidfile]\n\n");
#else
printf ("Stealth scan detection not supported on this platform\n");
- printf ("usage: portsentry [-tcp -udp]\n\n");
+ printf ("usage: portsentry [-tcp -udp] [pidfile]\n\n");
#endif
printf ("*** PLEASE READ THE DOCS BEFORE USING *** \n\n");
}
Index: portsentry_io.c
--- portsentry_io.c.orig 2003-05-23 20:10:13 +0200
+++ portsentry_io.c 2004-07-05 09:59:10 +0200
@@ -21,6 +21,8 @@
#include "portsentry_io.h"
#include "portsentry_util.h"
+static char *rmpidfile;
+
/* Main logging function to surrogate syslog */
void
Log (char *logentry, ...)
@@ -45,6 +47,13 @@
{
Log ("securityalert: PortSentry is shutting down\n");
Log ("adminalert: PortSentry is shutting down\n");
+
+ if (rmpidfile) {
+ Log ("adminalert: PortSentry removes '%s'\n", rmpidfile);
+ if (unlink(rmpidfile))
+ Log ("adminalert: PortSentry cannot remove pidfile (%s)\n", strerror(errno));
+ }
+
exit (status);
}
@@ -63,9 +72,10 @@
/* The daemonizing code copied from Advanced Programming */
/* in the UNIX Environment by W. Richard Stevens with minor changes */
int
-DaemonSeed (void)
+DaemonSeed (char *pidfile)
{
int childpid;
+ FILE *f;
signal (SIGALRM, SIG_IGN);
signal (SIGHUP, SIG_IGN);
@@ -80,6 +90,15 @@
else if (childpid > 0)
exit (0);
+ if (pidfile != NULL) {
+ f = fopen(pidfile,"w");
+ if (f != NULL) {
+ fprintf(f,"%d",getpid());
+ fclose(f);
+ rmpidfile = pidfile;
+ }
+ }
+
setsid ();
chdir ("/");
umask (077);
Index: portsentry_io.h
--- portsentry_io.h.orig 2003-05-23 20:10:13 +0200
+++ portsentry_io.h 2004-07-05 09:59:10 +0200
@@ -22,7 +22,7 @@
void Log (char *,...);
void Exit (int);
void Start (void);
-int DaemonSeed (void);
+int DaemonSeed (char *pidfile);
int NeverBlock (char *, char *);
int CheckConfig (void);
int OpenTCPSocket (void);