ports/65033: New port: net-mgmt/netmond network monitoring daemon
Viktor A. Fomichev
vfom at sicex.ru
Thu Apr 1 11:00:33 UTC 2004
>Number: 65033
>Category: ports
>Synopsis: New port: net-mgmt/netmond network monitoring daemon
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Apr 01 03:00:32 PST 2004
>Closed-Date:
>Last-Modified:
>Originator: Viktor Fomichev
>Release: FreeBSD 4.9-RELEASE i386
>Organization:
>Environment:
>Description:
NETwork MONitoring Dealer - IP network monitoring daemon.
Can check hosts availability (via ICMP ping), collect SNMP counters,
check simple TCP/UDP services (with internal chat), handle SNMP traps.
For a full documentation look at
WWW: http://soft.risp.ru/netmond/
(sorry, russian only)
>How-To-Repeat:
>Fix:
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# netmond
# netmond/files
# netmond/files/netmondctl
# netmond/files/netmond_watchdog
# netmond/files/README.port
# netmond/files/patch-AA
# netmond/files/netmond.sh
# netmond/Makefile
# netmond/distinfo
# netmond/pkg-descr
# netmond/pkg-install
# netmond/pkg-plist
# netmond/pkg-message
#
echo c - netmond
mkdir -p netmond > /dev/null 2>&1
echo c - netmond/files
mkdir -p netmond/files > /dev/null 2>&1
echo x - netmond/files/netmondctl
sed 's/^X//' >netmond/files/netmondctl << 'END-of-netmond/files/netmondctl'
X#!/bin/sh
X#
X# The exit codes returned are:
X# 0 - operation completed successfully
X# 1 - some error
X# 2 - usage error
X#
X#
X# the path to your NETMOND binary, including options if necessary
XNETMOND=/usr/local/sbin/netmond
XPIDFILE=/var/run/netmond.pid
X#
X# config file (default is "/usr/local/etc/netmon.conf")
X#
XTTT=X$2
Xif [ $TTT = "X" ]
Xthen
X CONFIG=""
Xelse
X CONFIG="-c $2"
X CFILE=$2
Xfi
X
X
XERROR=0
X
Xcase $1 in
Xstart)
X if [ -r $PIDFILE ] ; then
X PID=`cat $PIDFILE`
X if kill -0 $PID ;then
X echo "$0 $1: netmond (pid $PID) already running."
X exit 0;
X fi
X fi
X if $NETMOND -C $CONFIG >/dev/null 2>&1 ; then
X if $NETMOND $CONFIG ; then
X echo "$0 $1: netmond started"
X else
X echo "$0 $1: netmond could not be started"
X ERROR=1
X fi
X else
X echo "$0 $1: configuration broken, ignoring start"
X echo "$0 $1: (run 'netmond -C' for details)"
X ERROR=1
X fi
X ;;
Xstop)
X if [ ! -r $PIDFILE ] ; then
X exit 0
X fi
X PID=`cat $PIDFILE`
X if kill $PID ; then
X echo "$0 $1: netmond stopped"
X else
X echo "$0 $1: netmond could not be stopped"
X ERROR=1
X fi
X ;;
Xrestart)
X if [ ! -r $PIDFILE ] ; then
X echo "$0 $1: netmond not running, trying to start"
X if $NETMOND $CONFIG ; then
X echo "$0 $ARG: netmond started"
X else
X echo "$0 $ARG: netmond could not be started"
X ERROR=1
X fi
X else
X PID=`cat $PIDFILE`
X if $NETMOND -C $CONFIG >/dev/null 2>&1 ; then
X if kill -HUP $PID ; then
X echo "$0 $1: netmond restarted"
X else
X echo "$0 $1: netmond could not be restarted"
X ERROR=1
X fi
X else
X echo "$0 $1: configuration broken, ignoring restart"
X echo "$0 $1: (run 'netmond -C' for details)"
X ERROR=1
X fi
X fi
X ;;
X *)
X echo "usage: $0 start|stop|restart"
X cat <<EOF
X
Xstart - start netmond (or do nothing if running)
Xstop - stop netmond
Xrestart - restart netmond if running by sending a SIGHUP or start if
X not running
X
X
XEOF
X ERROR=
X ;;
Xesac
X
Xexit $ERROR
X
END-of-netmond/files/netmondctl
echo x - netmond/files/netmond_watchdog
sed 's/^X//' >netmond/files/netmond_watchdog << 'END-of-netmond/files/netmond_watchdog'
X#!/bin/sh
X#
Xprefix=/usr/local
Xexec_prefix=${prefix}
XPATH=/bin:/usr/bin
Xexport PATH
Xpidfile=/var/run/netmond.pid
X#config=/usr/home/netmon/netmon.conf
Xconfig=/usr/local/etc/netmon.conf
X
Xwhile : ; do
X if [ -r $pidfile ] && kill -0 `cat $pidfile` >/dev/null 2>&1 ; then
X # echo "Netmond Running"
X else
X # echo "Netmond failed"
X logger -p daemon.err -t nemond_watchdog "Netmond failed. Restarting..."
X rm -f ${pidfile}
X ${exec_prefix}/sbin/netmond -c ${config}
X fi
X sleep 10
Xdone
END-of-netmond/files/netmond_watchdog
echo x - netmond/files/README.port
sed 's/^X//' >netmond/files/README.port << 'END-of-netmond/files/README.port'
X
X netmond-2.2-b5-port
X
X÷ ÄÁÎÎÏÍ ÄÏËÕÍÅÎÔÅ ÏÐÉÓÁÎÙ ÉÚÍÅÎÅÎÉÑ É ÄÏÂÁ×ÌÅÎÉÑ ÏÔÎÏÓÉÔÅÌØÎÏ
XÏÒÉÇÉÎÁÌØÎÙÈ ÉÓÈÏÄÎÙÈ ÔÅËÓÔÒÏ× netmond-2.2-b5.
X
X##################################################################
X
XSrcAddress patch
X
X##################################################################
X ÷ ÎÅËÏÔÏÒÙÈ ÓÉÔÕÁÃÉÑÈ ÎÅÏÂÈÏÄÉÍÏ Ñ×ÎÏ ÚÁÄÁÔØ IP ÁÄÒÅÓ
XÉÓÔÏÞÎÉËÁ ÄÌÑ ÐÁËÅÔÏ×, ÏÔÐÒÁ×ÌÑÅÍÙÈ ÎÁ ÏÐÒÅÄÅÌÅÎÎÙÊ ÈÏÓÔ
X× ÓÌÕÞÁÅ, ÅÓÌÉ ÓÅÒ×ÅÒ ÉÍÅÅÔ ÎÅÓËÏÌØËÏ ÉÎÔÅÒÆÅÊÓÏ× É\ÉÌÉ
XÁÌÉÁÓÏ×.
X
XîÁÐÒÉÍÅÒ:
X
X- îÕÖÎÏ ÔÅÓÔÉÒÏ×ÁÔØ ÄÏÓÔÕÐÎÏÓÔØ ÈÏÓÔÁ ÐÏ ÏÐÒÅÄÅÌÎÎÏÍÕ ÍÁÒÛÒÕÔÕ,
X ÎÅ ÓÏ×ÐÁÄÁÀÝÅÍÕ Ó ÍÁÒÛÒÕÔÏÍ ÐÏ ÕÍÏÌÞÁÎÉÀ ÄÌÑ ÜÔÏÇÏ ÈÏÓÔÁ.
X
X- õÄÁÌÅÎÎÙÊ ÈÏÓÔ ÍÏÖÅÔ ÉÍÅÔØ "ÓÔÒÁÎÎÏ" ÓËÏÎÆÉÇÕÒÉÒÏ×ÁÎÎÙÊ
X ÐÁËÅÔÎÙÊ ÆÉÌØÔÒ, ÔÁË, ÞÔÏ ÒÅÁÇÉÒÕÅÔ ÎÁ ÐÁËÅÔÙ ÔÏÌØËÏ Ó
X ÏÐÒÅÄÅÌÅÎÎÙÈ IP ÁÄÒÅÓÏ×.
X
X- ðÏ ÍÁÒÛÒÕÔÕ ÄÏ ÕÄÁÌÅÎÎÏÇÏ ÈÏÓÔÁ ÓÕÝÅÓÔ×ÕÀÔ ÕÞÁÓÔËÉ, ÇÄÅ
X ÐÁËÅÔÙ Ó ÏÐÒÅÄÅÌÅÎÎÙÈ IP ÁÄÒÅÓÏ× ÉÍÅÀÔ ÐÒÉÏÒÉÔÅÔ, ÞÔÏ
X ÂÙ×ÁÅÔ ×ÁÖÎÏ ÐÒÉ ÞÁÓÔÏÊ ÐÅÒÅÇÒÕÚËÅ (ÜÔÉÈ) ËÁÎÁÌÏ×.
X
XäÏÂÁ×ÌÅÎÁ ÄÉÒÅËÔÉ×Á "SrcAddress"
X
X ÷ ÇÌÏÂÁÌØÎÏÍ ËÏÎÔÅËÓÔÅ ÜÔÁ ÄÉÒÅËÔÉ×Á ÚÁÄÁÅÔ IP ÁÄÒÅÓ ÉÓÔÏÞÎÉËÁ
XÄÌÑ ×ÓÅÈ ÏÂßÅËÔÏ×, ÄÌÑ ËÏÔÏÒÙÈ IP ÁÄÒÅÓ ÉÓÔÏÞÎÉËÁ Ñ×ÎÏ ÎÅ ÚÁÄÁÎ.
XåÓÌÉ ÄÉÒÅËÔÉ×Á ÎÅ ÕËÁÚÁÎÁ - ÜÔÏÔ ÁÄÒÅÓ = 0.0.0.0
X
X ÷ ËÏÎÔÅËÓÔÅ ÏÂßÅËÔÁ, ÜÔÁ ÄÉÒÅËÔÉ×Á ÚÁÄÁÅÔ IP ÁÄÒÅÓ ÉÓÔÏÞÎÉËÁ ÄÌÑ
XÐÏÓÙÌËÉ ÌÀÂÙÈ ÐÁËÅÔÏ× ÎÁ ÜÔÏÔ ÈÏÓÔ.
X
XåÓÌÉ ÄÉÒÅËÔÉ×Á îéçäå ÎÅ ÕËÁÚÁÎÁ - ÓÅÒ×ÅÒ ×ÅÄÅÔ ÓÅÂÑ ÔÁË, ËÁË ÄÏ
XÐÒÉÍÅÎÅÎÉÑ ÐÁÔÞÁ.
X
XðÒÉÍÅÒ:
X
X SrcAddress "192.168.2.1"
X
X Object "somehost" {
X Address "192.168.1.2"
X SrcAddress "192.168.1.1"
X ....................
X }
X
XîÅÄÏÓÔÁÔËÉ:
X
X îÅ ÒÅÁÌÉÚÏ×ÁÎÁ ÐÒÅÄ×ÁÒÉÔÅÌØÎÁÑ ÐÒÏ×ÅÒËÁ ×ÁÌÉÄÎÏÓÔÉ IP ÁÄÒÅÓÁ
XÉÓÔÏÞÎÉËÁ ÐÒÉ ÞÔÅÎÉÉ ÆÁÊÌÁ ËÏÎÆÉÇÕÒÁÃÉÉ. üÔÏ ÚÎÁÞÉÔ, ÞÔÏ ÄÏ
XÐÏÓÙÌËÉ ÐÅÒ×ÏÇÏ ÐÁËÅÔÁ ÎÁ ÈÏÓÔ ÷Ù ÎÅ ÕÚÎÁÅÔÅ, ÞÔÏ ÎÅÐÒÁ×ÉÌØÎÏ
XÕËÁÚÁÌÉ IP ÁÄÒÅÓ ÉÓÔÏÞÎÉËÁ.
X IP ÁÄÒÅÓ ÉÓÔÏÞÎÉËÁ ÎÅ×ÏÚÍÏÖÎÏ ÕÚÎÁÔØ Õ NetState ÓÅÒ×ÅÒÁ.
X
X##################################################################
X
XUID-GID-ChRoot Patch
X
X##################################################################
X
X åÓÌÉ ÕËÁÚÁÎ ÍÅÔÏÄ ÓÏÈÒÁÎÅÎÉÑ PIPE ÉÌÉ FILE, ÔÏ, × ÎÅËÏÔÏÒÙÈ
XÓÌÕÞÁÑÈ, ÚÁÐÕÓËÁÅÔÓÑ ÄÏÞÅÒÎÉÊ ÐÒÏÃÅÓÓ, ËÏÔÏÒÏÍÕ ÐÅÒÅÄÁÀÔÓÑ ÄÁÎÎÙÅ.
X ïÂÙÞÎÏ "Netmod" ÒÁÂÏÔÁÅÔ ÏÔ ÉÍÅÎÉ ÐÏÌØÚÏ×ÁÔÅÌÑ "root".
XóÌÅÄÏ×ÁÔÅÌØÎÏ ÄÏÞÅÒÎÉÅ ÐÒÏÃÅÓÓÙ ÔÁË-ÖÅ ÚÁÐÕÓËÁÀÔÓÑ ÏÔ ÉÍÅÎÉ
X"root". ÷ÏÏÂÝÅ ÇÏ×ÏÒÑ, ÜÔÏ îåâåúïðáóîï, ÔÅÍ ÂÏÌÅÅ, ÞÔÏ ÄÌÑ
XÉÓÐÏÌÎÅÎÉÑ ÜÔÉÈ ÐÒÏÇÒÁÍÍ ÏÂÙÞÎÏ ÐÒÁ×Á "root" ÎÅ ÎÕÖÎÙ.
X
X äÏÂÁ×ÌÅÎÙ ÇÌÏÂÁÌØÎÙÅ ÄÉÒÅËÔÉ×Ù "UserName" "GroupName" "ChrootDir"
XåÓÌÉ ÕËÁÚÁÎÙ ÜÔÉ ÄÉÒÅËÔÉ×Ù, ÔÏ ÐÅÒÅÄ ÚÁÐÕÓËÏÍ ÄÏÞÅÒÎÅÇÏ ÐÒÏÃÅÓÓÁ,
X( ÐÏÓÌÅ fork, ÎÏ ÒÁÎØÛÅ exec ) ÄÅÌÁÅÔÓÑ chroot × ÕËÁÚÁÎÎÙÊ ËÁÔÁÌÏÇ
X(ÅÓÌÉ ËÁÔÁÌÏÇ ÎÅ ÕËÁÚÁÎ - ÎÅ ÄÅÌÁÅÔÓÑ), É ÉÚÍÅÎÑÅÔÓÑ GID,UID ÐÒÏÃÅÓÓÁ.
X
XðÏ ÕÍÏÌÞÁÎÉÀ, chroot ÎÅ ÄÅÌÁÅÔÓÑ, UserName = netmon, GroupName= netmon.
X
XðÒÉÍÅÒ:
X UserName "nobody"
X GroupName "nogroup"
X ChRootDir "/var/netmon"
X
X÷ÐÒÏÞÅÍ, ÷Ù ÍÏÖÅÔÅ Ñ×ÎÏ ÕËÁÚÁÔØ, ÞÔÏ ÓËÒÉÐÔÙ ÎÕÖÎÏ ÚÁÐÕÓËÁÔØ ÏÔ "root".
X
X##################################################################
X
XNetState BindAddress Patch
X
X##################################################################
X
X éÎÏÇÄÁ ÂÙ×ÁÅÔ ÕÄÏÂÎÏ Ñ×ÎÏ ÚÁÄÁ×ÁÔØ IP ÁÄÒÅÓ, ÎÁ ËÏÔÏÒÏÍ NetState
XÓÅÒ×ÅÒ ÏÖÉÄÁÅÔ ×ÈÏÄÑÝÅÇÏ TCP ÓÏÅÄÉÎÅÎÉÑ.
X
XäÏÂÁ×ÌÅÎÁ ÄÉÒÅËÔÉ×Á "BindAddress" × ËÏÎÔÅËÓÔÅ "Port".
X
XðÒÉÍÅÒ:
X Port 3333 {
X BindAddress "192.168.1.1"
X ............
X }
XéÌÉ
X
XNetState {
X Port 3333
X BindAddress "192.168.1.1"
X}
X
X
XðÏ ÕÍÏÌÞÁÎÉÀ, ÖÄÅÍ ×ÈÏÄÑÝÅÇÏ TCP ÓÏÅÄÉÎÅÎÉÑ ÎÁ ×ÓÅÈ ÌÏËÁÌØÎÙÈ ÁÄÒÅÓÁÈ.
X
X##################################################################
X
XTrap Patch
X
X##################################################################
X
X éÎÏÇÄÁ ÂÙ×ÁÅÔ ÕÄÏÂÎÏ Ñ×ÎÏ ÚÁÄÁ×ÁÔØ IP ÁÄÒÅÓ, ÎÁ ËÏÔÏÒÏÍ
XÓÅÒ×ÅÒ ÏÖÉÄÁÅÔ ×ÈÏÄÑÝÉÊ SNMP Trap.
X
XäÏÂÁ×ÌÅÎÁ ÄÉÒÅËÔÉ×Á "TrapBindAddress" × ÇÌÏÂÁÌØÎÏÍ ËÏÎÔÅËÓÔÅ.
X
XðÒÉÍÅÒ:
X TrapBindAddress "192.168.1.1"
X
XðÏ ÕÍÏÌÞÁÎÉÀ, ÖÄÅÍ ×ÈÏÄÑÝÉÊ SNMP Trap ÎÁ ×ÓÅÈ ÌÏËÁÌØÎÙÈ ÁÄÒÅÓÁÈ.
X
X##################################################################
X
X
XPID-ÆÁÊÌ ×ÓÅÇÄÁ ÚÁÐÉÓÙ×ÁÅÔÓÑ × /var/run/netmond.pid
X
X
X##################################################################
X
XäÏÂÁ×ÌÅÎÁ ×ÏÚÍÏÖÎÏÓÔØ ÉÓÐÏÌØÚÏ×ÁÔØ × ÒÅÇÕÌÑÒÎÙÈ ×ÙÒÁÖÅÎÉÑÈ NetState
XÒÕÓÓËÉÅ ÂÕË×Ù.
X
X
X
X
X
END-of-netmond/files/README.port
echo x - netmond/files/patch-AA
sed 's/^X//' >netmond/files/patch-AA << 'END-of-netmond/files/patch-AA'
X--- dns.c.orig Mon Aug 25 18:19:04 2003
X+++ dns.c Tue Sep 16 23:43:05 2003
X@@ -149,6 +149,8 @@
X {
X SESSION *sd = method->sd;
X int reqid;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -161,6 +163,14 @@
X return;
X }
X
X+ /* bind socket to local source address */
X+
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "dns_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X /* turn on non-blocking I/O */
X if (set_socket_async(sd->sock, TRUE) < 0) {
X dns_reply(errno, sd, 0);
X@@ -288,7 +298,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("dns_init(%s/%s)\n", target->name, method->name));
X
X@@ -303,6 +313,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = dns_send;
X--- netmon.h.orig Tue Aug 26 10:00:38 2003
X+++ netmon.h Wed Sep 17 00:39:11 2003
X@@ -14,6 +14,9 @@
X #include <sys/socket.h>
X #include <sys/time.h>
X #include <netinet/in.h>
X+#include <pwd.h>
X+#include <grp.h>
X+#include <time.h>
X #ifdef DEBUG_MEMORY
X #include <assert.h>
X #endif
X@@ -77,7 +80,10 @@
X #endif
X
X #define NETMON "netmon"
X-#define DEFAULT_CONFIG "/etc/netmon.conf"
X+#define DEFAULT_CONFIG "/usr/local/etc/netmon.conf"
X+#define USERNAME "netmon"
X+#define GROUPNAME "netmon"
X+#define PIDFILE_PATH "/var/run"
X #define DEFAULT_WATCHDOG 600 /* 10 min */
X
X #define POLLING_MIN 30 /* 30 sec */
X@@ -385,6 +391,7 @@
X struct method_ent *method; /* session method */
X int sock; /* socket file descriptor */
X struct sockaddr peer; /* address of peer */
X+ struct sockaddr me; /* my source address */
X long timeout; /* number of microseconds until first timeout */
X int retries; /* number of retries before timeout */
X int (*connect) __P((struct session_ent *));
X@@ -530,7 +537,9 @@
X char *descr; /* object description */
X char *datadir; /* directory where store data */
X char *address; /* domain name or dotted IP address */
X+ char *srcaddress; /* domain name or dotted source IP address */
X struct in_addr ip_addr; /* ip address of peer */
X+ struct in_addr ip_srcaddr; /* source ip address */
X int polling; /* polling period in seconds */
X int saving; /* saving period in seconds */
X int sync; /* polling counter to synchronize saving */
X@@ -574,7 +583,14 @@
X
X typedef struct config_ent {
X char *rootdir; /* default work directory */
X+ char *chrootdir; /* chroot directory for EXEC children */
X+ char *username; /* username for EXEC children */
X+ uid_t uid; /* UID for EXEC children */
X+ char *groupname; /* groupname for EXEC children */
X+ gid_t gid; /* GID for EXEC children */
X char *timefmt; /* strftime format of currtime for logging */
X+ char *srcaddress; /* my default source domain name or dotted IP address */
X+ struct in_addr ip_srcaddr; /* my default sorce ip address */
X int polling; /* default polling interval in seconds */
X int saving; /* default saving interval in seconds */
X int timeout; /* default timeout in seconds */
X@@ -582,9 +598,13 @@
X
X int enable_traps; /* enable SNMP traps */
X int source_traps; /* match src-addr and agent-addr of traps */
X+ char *trap_address; /* Trap bind address */
X+ struct in_addr trap_ip_addr; /* */
X
X /* netstate server */
X int ns_port; /* server port number */
X+ char *ns_address; /* NetState bind address */
X+ struct in_addr ns_ip_addr; /* */
X int ns_timo; /* client timeout in seconds */
X GROUP_REF *ns_acl; /* netstate client access list */
X
X--- netmond.c.orig Fri Aug 22 15:49:23 2003
X+++ netmond.c Tue Sep 16 23:43:05 2003
X@@ -79,7 +79,6 @@
X static int reconfig_pending;
X static int watchdog_timeout;
X static int watchdog_pending;
X-
X static struct sighandler_ent {
X int sig;
X int flags;
X@@ -254,8 +253,7 @@
X /*
X * Make pid file.
X */
X- (void)strcpy(buf, program_name);
X- (void)strcat(buf, ".pid");
X+ snprintf(buf, sizeof(buf), "%s/%s.pid", PIDFILE_PATH, program_name);
X if ((fp = fopen(buf, "w")) != NULL) {
X fprintf(fp, "%d\n", (int)mypid);
X fclose(fp);
X@@ -831,6 +829,20 @@
X /* make session leader to be able killpg() latter */
X setsid();
X
X+ if ( cf->chrootdir) {
X+ if ( chroot( cf->chrootdir ) < 0 ) {
X+ report(LOG_ERR, "chroot %s: %s", cf->chrootdir,strerror(*(__error())) );
X+ _exit(127);
X+ }
X+ }
X+ if ( setgid(cf->gid) < 0 ) {
X+ report(LOG_ERR, "setgid %s[%d]: %s", cf->groupname, cf->gid, strerror(*(__error())) );
X+ _exit(127);
X+ }
X+ if ( (cf->uid != 0) & (setuid(cf->uid) < 0) ) {
X+ report(LOG_ERR, "setuid %s[%d]: %s", cf->username, cf->uid, strerror(*(__error())) );
X+ _exit(127);
X+ }
X execve(file, av, environ);
X report(LOG_ERR, "execve %s: %m", file);
X _exit(127);
X@@ -928,8 +940,7 @@
X #endif
X {
X char pidfile[100];
X- (void)strcpy(pidfile, program_name);
X- (void)strcat(pidfile, ".pid");
X+ snprintf(pidfile, sizeof(pidfile), "%s/%s.pid", PIDFILE_PATH, program_name);
X (void)unlink(pidfile);
X report(LOG_CRIT, "aborted by signal %d", sig);
X } else report(LOG_INFO, "interrupted by signal %d", sig);
X--- netstate.c.orig Tue Aug 26 10:54:09 2003
X+++ netstate.c Thu Sep 25 15:21:39 2003
X@@ -128,7 +128,7 @@
X memset(&sin, 0, sizeof(sin));
X sin.sin_family = AF_INET;
X sin.sin_port = htons(cf->ns_port);
X- sin.sin_addr.s_addr = INADDR_ANY;
X+ sin.sin_addr = cf->ns_ip_addr;
X if (bind(netstate_sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
X report(LOG_ERR, "bind port %d: %m", ntohs(sin.sin_port));
X close(netstate_sock);
X@@ -405,6 +405,14 @@
X _exit(1);
X }
X #endif
X+int
X+iskoi8(unsigned char ch)
X+{
X+ if ( ch == 163 ) return 1;
X+ if ( ch == 179 ) return 1;
X+ if ( ch >= 192 ) return 1;
X+ return 0;
X+}
X
X void *
X netstate_serve(arg)
X@@ -505,9 +513,9 @@
X set_timer(0, interrupt);
X #endif
X if (!cp) break;
X- while (isprint(*cp)) cp++;
X+ while ( iskoi8(*cp) || isprint(*cp) ) cp++;
X *cp = '\0';
X-
X+
X next = input;
X if ((cp = my_strsep(&next, " ")) == NULL) {
X bad_input++;
X--- parseconf.y.orig Tue Aug 26 10:53:30 2003
X+++ parseconf.y Wed Sep 17 00:22:40 2003
X@@ -197,11 +197,36 @@
X BGP_AS *bgp;
X ENV_MON *env;
X char *cp, buf[1024];
X+ struct passwd *pwentry;
X+ struct group *grentry;
X
X if (!config.rootdir) {
X report(LOG_ERR, "%s: rootdir unspecified", config_file);
X return NULL;
X }
X+ if (!config.srcaddress)
X+ bzero(&config.ip_srcaddr, sizeof(struct in_addr));
X+ if (!config.ns_address)
X+ bzero(&config.ns_ip_addr, sizeof(struct in_addr));
X+ if (!config.trap_address)
X+ bzero(&config.trap_ip_addr, sizeof(struct in_addr));
X+
X+ if(!config.username) {
X+ config.username = strdup(USERNAME);
X+ if ((pwentry = getpwnam(USERNAME)) == (struct passwd *) NULL) {
X+ report(LOG_ERR, "Bad default username: %s.",config.username);
X+ return NULL;
X+ }
X+ config.uid = pwentry->pw_uid;
X+ }
X+ if(!config.groupname) {
X+ config.groupname = strdup(GROUPNAME);
X+ if ((grentry = getgrnam(GROUPNAME)) == (struct group *) NULL) {
X+ report(LOG_ERR, "Bad default groupname: %s.",config.groupname);
X+ return NULL;
X+ }
X+ config.gid = (gid_t)grentry->gr_gid;
X+ }
X if (config.polling) {
X if (!config.timeout)
X config.timeout = TIMEOUT_DEFAULT;
X@@ -273,6 +298,7 @@
X
X for (service = target->service; service; service = service->next) {
X service->ip_addr = target->ip_addr;
X+ service->ip_srcaddr = target->ip_srcaddr;
X service->parent = target;
X
X (void)strcpy(cp, "/");
X@@ -1342,6 +1368,9 @@
X
X /* Lexical analyzer return values */
X %token TOKEN_ROOTDIR
X+%token TOKEN_CHROOTDIR
X+%token TOKEN_USERNAME
X+%token TOKEN_GROUPNAME
X %token TOKEN_TIMEFMT
X %token TOKEN_POLLING
X %token TOKEN_SAVING
X@@ -1354,6 +1383,7 @@
X
X %token TOKEN_NETSTATE
X %token TOKEN_PORT
X+%token TOKEN_BINDADDRESS
X
X %token TOKEN_SAVE
X %token TOKEN_FILE
X@@ -1365,6 +1395,7 @@
X
X %token TOKEN_OBJECT
X %token TOKEN_ADDRESS
X+%token TOKEN_SRCADDRESS
X %token TOKEN_DESCRIPTION
X %token TOKEN_SERVICE
X %token TOKEN_INTERFACE
X@@ -1398,6 +1429,7 @@
X %token TOKEN_V2
X
X %token TOKEN_TRAP
X+%token TOKEN_TRAPBINDADDRESS
X %token TOKEN_SOURCECHECK
X %token TOKEN_COMMUNITY
X %token TOKEN_ENTERPRISE
X@@ -1442,6 +1474,60 @@
X YYABORT;
X }
X }
X+ | TOKEN_CHROOTDIR quoted_string
X+ {
X+ if (config.chrootdir) {
X+ yyerror("ChRootDir statement duplicated");
X+ YYABORT;
X+ }
X+ config.chrootdir = $2;
X+ }
X+ | TOKEN_USERNAME quoted_string
X+ {
X+ struct passwd *pwentry;
X+
X+ if (config.username) {
X+ yyerror("UserName statement duplicated");
X+ YYABORT;
X+ }
X+ if ((pwentry = getpwnam($2)) == (struct passwd *)NULL) {
X+ yyerror("UserName %s unknown.", $2);
X+ YYABORT;
X+ }
X+ config.uid = pwentry->pw_uid;
X+ config.username = $2;
X+ }
X+
X+ | TOKEN_GROUPNAME quoted_string
X+ {
X+ struct group *grentry;
X+
X+ if (config.groupname) {
X+ yyerror("GroupName statement duplicated");
X+ YYABORT;
X+ }
X+ if ((grentry = getgrnam($2)) == (struct group *)NULL) {
X+ yyerror("GroupName %s unknown.", $2);
X+ YYABORT;
X+ }
X+ config.gid = grentry->gr_gid;
X+ config.groupname = $2;
X+ }
X+
X+ | TOKEN_SRCADDRESS quoted_string
X+ {
X+ struct in_addr ip_srcaddr;
X+
X+ if (config.srcaddress) {
X+ yyerror("config source address duplicated");
X+ YYABORT;
X+ }
X+ if (!gethostaddr(&ip_srcaddr, $2)) {
X+ YYABORT;
X+ }
X+ config.srcaddress = $2;
X+ memcpy(&config.ip_srcaddr, &ip_srcaddr, sizeof(struct in_addr));
X+ }
X | TOKEN_TIMEFMT quoted_string
X {
X if (config.timefmt) {
X@@ -1531,6 +1617,17 @@
X {
X config.source_traps = 1;
X }
X+ | TOKEN_TRAPBINDADDRESS quoted_string
X+ {
X+ if (config.trap_address) {
X+ yyerror("bindaddress duplicated");
X+ YYABORT;
X+ }
X+ if (!gethostaddr(&config.trap_ip_addr, $2)) {
X+ YYABORT;
X+ }
X+ config.trap_address = $2;
X+ }
X | TOKEN_TRAP legal_string '{' trap_config '}'
X {
X trap.name = $2;
X@@ -1556,6 +1653,13 @@
X yyerror("object address unspecified");
X YYABORT;
X }
X+ if (!object.srcaddress) {
X+ if (!config.srcaddress) {
X+ bzero(&object.ip_srcaddr, sizeof(struct in_addr));
X+ } else {
X+ memcpy(&object.ip_srcaddr, &config.ip_srcaddr, sizeof(struct in_addr));
X+ }
X+ }
X /* if ((object.interface || object.ifgroup ||
X object.bgp || object.env) &&
X !find_method(object.method_list, "ROUTER")) {
X@@ -1637,6 +1741,17 @@
X YYABORT;
X }
X }
X+ | TOKEN_BINDADDRESS quoted_string
X+ {
X+ if (config.ns_address) {
X+ yyerror("bindaddress duplicated");
X+ YYABORT;
X+ }
X+ if (!gethostaddr(&config.ns_ip_addr, $2)) {
X+ YYABORT;
X+ }
X+ config.ns_address = $2;
X+ }
X | TOKEN_PERMIT quoted_string
X {
X /* for backward compatibility */
X@@ -2095,6 +2210,18 @@
X }
X object.address = $2;
X }
X+ | TOKEN_SRCADDRESS quoted_string
X+ {
X+ if (object.srcaddress) {
X+ yyerror("object source address duplicated");
X+ YYABORT;
X+ }
X+ if (!gethostaddr(&object.ip_srcaddr, $2)) {
X+ YYABORT;
X+ }
X+ object.srcaddress = $2;
X+ }
X+
X | TOKEN_POLLING TOKEN_NUMBER
X {
X if (object.polling) {
X--- ping.c.orig Fri Aug 22 11:07:53 2003
X+++ ping.c Tue Sep 16 23:43:05 2003
X@@ -368,6 +368,7 @@
X u_char buf[MAX_PACKETSZ];
X struct ip *ip;
X struct icmp *icmp;
X+ struct sockaddr_in *from = (struct sockaddr_in *)&sd->me;
X struct sockaddr_in *to = (struct sockaddr_in *)&sd->peer;
X int header_len = sizeof(struct ip);
X int total_len = method->rport ? method->rport : MIN_PACKETSZ;
X@@ -400,7 +401,7 @@
X #endif
X ip->ip_ttl = IPDEFTTL;
X ip->ip_p = IPPROTO_ICMP;
X- /* ip->ip_src <-- filled by kernel (hopefulness) */
X+ ip->ip_src = from->sin_addr; /* replaced by kernel if=INADDR_ANY (hopefulness) */
X ip->ip_dst = to->sin_addr;
X
X if (rr_opt) { /* IP Option: Record Route */
X@@ -423,6 +424,7 @@
X memcpy(icmp->icmp_data, &sd->buf, sizeof(TIMEVAL *));
X
X icmp->icmp_cksum = in_cksum((u_short *)icmp, total_len - header_len);
X+
X #ifdef NO_ICMP_ERRORS
X total_len = send(sd->sock, (char *)buf, total_len, 0);
X #else
X@@ -600,6 +602,8 @@
X {
X SESSION *sd = method->sd;
X int tmpval;
X+ char ipaddr[20];
X+ struct sockaddr_in *from;
X
X /* sanity check */
X if (!sd) return;
X@@ -616,6 +620,13 @@
X echo_reply(errno, sd, 0);
X return;
X }
X+ /* bind RAW socket to local source address */
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "echo_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X #ifdef SO_BSDCOMPAT
X /* The following option is only necessary on Linux machines because
X * they have the unusual behavior of returning some ICMP errors to
X@@ -701,7 +712,12 @@
X if (sd->pkt_recv > 1) msec /= (double)sd->pkt_recv;
X sprintf(buf, "%g", msec);
X diag = buf;
X- } else diag = "0.000";
X+ if ( msec >= 10 ) {
X+ sprintf(buf, "%d", (int)msec);
X+ } else {
X+ sprintf(buf, "%g", msec);
X+ }
X+ } else diag = "0.0";
X } else {
X op = -1;
X diag = icmp_error(sd->data_int);
X@@ -740,8 +756,9 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X char varname[100];
X+ char ipaddr[20];
X
X dprintf(("echo_init(%s/%s)\n", target->name, method->name));
X
X@@ -758,6 +775,9 @@
X to = (struct sockaddr_in *)&template.peer;
X to->sin_family = AF_INET;
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = echo_send;
X--- radius.c.orig Mon Aug 25 18:20:03 2003
X+++ radius.c Tue Sep 16 23:43:05 2003
X@@ -208,6 +208,8 @@
X {
X SESSION *sd = method->sd;
X int reqid;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -220,6 +222,13 @@
X return;
X }
X
X+ /* bind socket to local source address */
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "radius_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X /* turn on non-blocking I/O */
X if (set_socket_async(sd->sock, TRUE) < 0) {
X radius_reply(errno, sd, 0);
X@@ -311,7 +320,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("radius_init(%s/%s)\n", target->name, method->name));
X
X@@ -326,6 +335,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = radius_send;
X--- reconfig.c.orig Tue Aug 26 10:54:37 2003
X+++ reconfig.c Wed Sep 17 00:26:06 2003
X@@ -395,7 +395,7 @@
X OBJECT *parent;
X OBJECT *old, *new;
X {
X- void *ip_addr;
X+ void *ip_addr, *ip_srcaddr;
X OBJECT *service;
X
X object_stop(old);
X@@ -403,9 +403,13 @@
X ptrswap(&old->descr, &new->descr);
X ptrswap(&old->datadir, &new->datadir);
X ptrswap(&old->address, &new->address);
X- if (parent)
X+ if (parent) {
X ip_addr = &parent->ip_addr;
X- else ip_addr = &new->ip_addr;
X+ ip_srcaddr = &parent->ip_srcaddr;
X+ } else {
X+ ip_addr = &new->ip_addr;
X+ ip_srcaddr = &new->ip_srcaddr;
X+ }
X old->parent = parent;
X
X if (memcmp(&old->ip_addr, ip_addr, sizeof(old->ip_addr))) {
X@@ -418,6 +422,8 @@
X memset(old->snmpdata, 0, sizeof(SNMP_DATA));
X }
X }
X+ if (memcmp(&old->ip_srcaddr, ip_srcaddr, sizeof(old->ip_srcaddr)))
X+ memcpy(&old->ip_srcaddr, ip_srcaddr, sizeof(old->ip_srcaddr));
X
X old->polling = new->polling;
X old->saving = new->saving;
X@@ -450,6 +456,7 @@
X service = splice_object_list(old, &old->service, &new->service);
X for (; service; service = service->next) {
X service->ip_addr = old->ip_addr;
X+ service->ip_srcaddr = old->ip_srcaddr;
X service->parent = old;
X object_init(service);
X }
X@@ -516,21 +523,41 @@
X }
X if (cf_new->rootdir) free(cf_new->rootdir);
X
X+ ptrswap(&cf->chrootdir, &cf_new->chrootdir);
X+ if (cf_new->chrootdir) free(cf_new->chrootdir);
X+
X+ ptrswap(&cf->username, &cf_new->username);
X+ if (cf_new->username) free(cf_new->username);
X+ cf->uid = cf_new->uid;
X+
X+ ptrswap(&cf->groupname, &cf_new->groupname);
X+ if (cf_new->groupname) free(cf_new->groupname);
X+ cf->gid = cf_new->gid;
X+
X ptrswap(&cf->timefmt, &cf_new->timefmt);
X if (cf_new->timefmt) free(cf_new->timefmt);
X
X+ ptrswap(&cf->srcaddress, &cf_new->srcaddress);
X+ if (cf_new->srcaddress) free(cf_new->srcaddress);
X+ memcpy( &cf->ip_srcaddr, &cf_new->ip_srcaddr, sizeof(struct in_addr));
X cf->polling = cf_new->polling;
X cf->saving = cf_new->saving;
X cf->timeout = cf_new->timeout;
X cf->retries = cf_new->retries;
X
X- if (cf->enable_traps != cf_new->enable_traps) {
X+ if ((cf->enable_traps != cf_new->enable_traps) || memcmp(&cf->trap_ip_addr, &cf_new->trap_ip_addr, sizeof(struct in_addr)) ) {
X+ ptrswap(&cf->trap_address, &cf_new->trap_address);
X+ if (cf_new->trap_address) free(cf_new->trap_address);
X+ memcpy( &cf->trap_ip_addr, &cf_new->trap_ip_addr, sizeof(struct in_addr));
X cf->enable_traps = cf_new->enable_traps;
X trap_init(cf->enable_traps > 0);
X }
X cf->source_traps = cf_new->source_traps;
X
X- if (cf->ns_port != cf_new->ns_port) {
X+ if ((cf->ns_port != cf_new->ns_port) || memcmp(&cf->ns_ip_addr, &cf_new->ns_ip_addr, sizeof(struct in_addr))) {
X+ ptrswap(&cf->ns_address, &cf_new->ns_address);
X+ if (cf_new->ns_address) free(cf_new->ns_address);
X+ memcpy( &cf->ns_ip_addr, &cf_new->ns_ip_addr, sizeof(struct in_addr));
X cf->ns_port = cf_new->ns_port;
X netstate_init(cf->ns_port);
X }
X@@ -576,6 +603,12 @@
X free_object_list(cf_cur->target);
X
X if (cf_cur->rootdir) free(cf_cur->rootdir);
X+ if (cf_cur->chrootdir) free(cf_cur->chrootdir);
X+ if (cf_cur->username) free(cf_cur->username);
X+ if (cf_cur->groupname) free(cf_cur->groupname);
X+ if (cf_cur->srcaddress) free(cf_cur->srcaddress);
X+ if (cf_cur->ns_address) free(cf_cur->ns_address);
X+ if (cf_cur->trap_address) free(cf_cur->trap_address);
X if (cf_cur->timefmt) free(cf_cur->timefmt);
X
X trap_init(cf_cur->enable_traps > 0);
X@@ -649,6 +682,7 @@
X if (obj->descr) free(obj->descr);
X if (obj->datadir) free(obj->datadir);
X if (obj->address) free(obj->address);
X+ if (obj->srcaddress) free(obj->srcaddress);
X free_trap_list(obj->trap_list);
X free_var_list(obj->var_list);
X free_save_list(obj->save_list);
X--- router.c.orig Mon Aug 25 16:07:07 2003
X+++ router.c Tue Sep 16 23:43:05 2003
X@@ -2214,6 +2214,8 @@
X METHOD *method;
X {
X SESSION *sd = method->sd;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) {
X@@ -2229,7 +2231,13 @@
X router_reply(errno, sd, 0);
X return;
X }
X-
X+ /* bind socket to local source address */
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "router_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X /* turn on non-blocking I/O */
X if (set_socket_async(sd->sock, TRUE) < 0) {
X router_reply(errno, sd, 0);
X@@ -2306,7 +2314,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("router_init(%s/%s)\n", target->name, method->name));
X
X@@ -2321,6 +2329,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof (struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = snmp_send;
X--- scanconf.l.orig Fri Aug 22 16:37:41 2003
X+++ scanconf.l Wed Sep 17 00:28:19 2003
X@@ -88,6 +88,9 @@
X
X /* token names */
X ROOTDIR [Rr]oot[Dd]ir
X+CHROOTDIR [Cc]h[Rr]oot[Dd]ir
X+USERNAME [Uu]ser[Nn]ame
X+GROUPNAME [Gg]roup[Nn]ame
X TIMEFMT [Tt]ime[Ff]mt
X POLLING [Pp]olling
X SAVING [Ss]aving
X@@ -111,6 +114,8 @@
X
X OBJECT [Oo]bject
X ADDRESS [Aa]ddress
X+SRCADDRESS [Ss]rc[Aa]ddress
X+BINDADDRESS [Bb]ind[Aa]ddress
X DESCRIPTION [Dd]escription|[Cc]omment
X SERVICE [Ss]ervice
X INTERFACE [Ii]nterface
X@@ -144,6 +149,7 @@
X V2 [Vv]2
X
X TRAP [Tt]rap
X+TRAPBINDADDRESS [Tt]rap[Bb]ind[Aa]ddress
X SOURCECHECK [Ss]ource[Cc]heck
X COMMUNITY [Cc]ommunity
X ENTERPRISE [Ee]nterprise
X@@ -186,6 +192,12 @@
X
X {ROOTDIR} { return TOKEN_ROOTDIR; }
X
X+{USERNAME} { return TOKEN_USERNAME; }
X+
X+{GROUPNAME} { return TOKEN_GROUPNAME; }
X+
X+{CHROOTDIR} { return TOKEN_CHROOTDIR; }
X+
X {TIMEFMT} { return TOKEN_TIMEFMT; }
X
X {POLLING} { return TOKEN_POLLING; }
X@@ -224,6 +236,10 @@
X
X {ADDRESS} { return TOKEN_ADDRESS; }
X
X+{SRCADDRESS} { return TOKEN_SRCADDRESS; }
X+
X+{BINDADDRESS} { return TOKEN_BINDADDRESS; }
X+
X {DESCRIPTION} { return TOKEN_DESCRIPTION; }
X
X {SERVICE} { return TOKEN_SERVICE; }
X@@ -285,6 +301,8 @@
X {V2} { return TOKEN_V2; }
X
X {TRAP} { return TOKEN_TRAP; }
X+
X+{TRAPBINDADDRESS} { return TOKEN_TRAPBINDADDRESS; }
X
X {SOURCECHECK} { return TOKEN_SOURCECHECK; }
X
X--- session.c.orig Sat Aug 2 11:26:38 2003
X+++ session.c Tue Sep 16 23:43:05 2003
X@@ -59,6 +59,7 @@
X curr_session->method = template->method;
X curr_session->sock = template->sock;
X curr_session->peer = template->peer;
X+ curr_session->me = template->me;
X curr_session->timeout = template->timeout;
X curr_session->retries = template->retries;
X curr_session->connect = template->connect;
X--- snmp.c.orig Tue Aug 26 10:52:39 2003
X+++ snmp.c Tue Sep 16 23:43:05 2003
X@@ -1198,6 +1198,8 @@
X {
X SESSION *sd = method->sd;
X int reqid;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -1209,7 +1211,13 @@
X snmp_reply(errno, sd, 0);
X return;
X }
X-
X+ /* bind datagram socket to local source address */
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "snmp_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X /* turn on non-blocking I/O */
X if (set_socket_async(sd->sock, TRUE) < 0) {
X snmp_reply(errno, sd, 0);
X@@ -1274,7 +1282,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("snmp_init(%s/%s)\n", target->name, method->name));
X
X@@ -1289,6 +1297,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in ));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = snmp_send;
X--- tacacs.c.orig Mon Aug 25 18:20:41 2003
X+++ tacacs.c Tue Sep 16 23:43:05 2003
X@@ -302,6 +302,8 @@
X {
X SESSION *sd = method->sd;
X int reqid;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -314,6 +316,13 @@
X return;
X }
X
X+ /* bind socket to local source address */
X+ from = (struct sockaddr_in *)&sd->me;
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "tacacs_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X /* turn on non-blocking I/O before connecting */
X if (set_socket_async(sd->sock, TRUE) < 0) {
X tacacs_reply(errno, sd, 0);
X@@ -415,7 +424,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("tacacs_init(%s/%s)\n", target->name, method->name));
X
X@@ -430,6 +439,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.connect = tacacs_connect;
X--- tcp.c.orig Thu Mar 20 16:16:38 2003
X+++ tcp.c Tue Sep 16 23:43:05 2003
X@@ -319,6 +319,8 @@
X {
X SESSION *sd = method->sd;
X int tmpval;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -330,17 +332,13 @@
X tcp_close(errno, sd, 0);
X return;
X }
X-
X+ from = (struct sockaddr_in *)&sd->me;
X /* allocate local port if required */
X if (method->lport_min) {
X- struct sockaddr_in sin;
X-
X- sin.sin_family = AF_INET;
X- sin.sin_addr.s_addr = htonl(INADDR_ANY);
X tmpval = method->lport_min;
X do {
X- sin.sin_port = htons((u_short)tmpval);
X- if (!bind(sd->sock, (struct sockaddr *)&sin, sizeof(sin))) {
X+ from->sin_port = htons((u_short)tmpval);
X+ if (!bind(sd->sock, &sd->me, sizeof(struct sockaddr))) {
X tmpval = 0;
X break;
X }
X@@ -354,6 +352,13 @@
X tcp_close(EAGAIN, sd, 0);
X return;
X }
X+ } else {
X+ /* bind socket to local source address */
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "tcp_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X }
X
X /* turn on non-blocking I/O before connecting */
X@@ -424,7 +429,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("tcp_init(%s/%s)\n", target->name, method->name));
X
X@@ -439,6 +444,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.connect = tcp_connect;
X--- trap.c.orig Wed Sep 17 00:00:56 2003
X+++ trap.c Wed Sep 17 00:35:21 2003
X@@ -40,9 +40,10 @@
X {
X static struct sockaddr_in sin;
X
X+ if (trap_sock != -1) /* already enabled */
X+ close(trap_sock);
X+
X if (enable) {
X- if (trap_sock != -1) /* already enabled */
X- return 0;
X
X if ((trap_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
X report(LOG_ERR, "socket: %m");
X@@ -51,17 +52,15 @@
X memset(&sin, 0, sizeof(sin));
X sin.sin_family = AF_INET;
X sin.sin_port = htons(SNMPTRAP_PORT);
X- sin.sin_addr.s_addr = INADDR_ANY;
X+ sin.sin_addr = cf->trap_ip_addr;
X if (bind(trap_sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
X report(LOG_ERR, "bind port %d: %m", ntohs(sin.sin_port));
X close(trap_sock);
X trap_sock = -1;
X return -1;
X }
X- } else if (trap_sock != -1) {
X- close(trap_sock);
X+ } else
X trap_sock = -1;
X- }
X return 0;
X }
X
X--- udp.c.orig Sat Aug 2 11:40:56 2003
X+++ udp.c Tue Sep 16 23:43:05 2003
X@@ -197,6 +197,8 @@
X {
X SESSION *sd = method->sd;
X int tmpval;
X+ struct sockaddr_in *from;
X+ char ipaddr[20];
X
X /* sanity check */
X if (!sd) return;
X@@ -208,17 +210,13 @@
X udp_close(errno, sd, 0);
X return;
X }
X-
X+ from = (struct sockaddr_in *)&sd->me;
X /* allocate local port if required */
X if (method->lport_min) {
X- struct sockaddr_in sin;
X-
X- sin.sin_family = AF_INET;
X- sin.sin_addr.s_addr = htonl(INADDR_ANY);
X tmpval = method->lport_min;
X do {
X- sin.sin_port = htons((u_short)tmpval);
X- if (!bind(sd->sock, (struct sockaddr *)&sin, sizeof(sin))) {
X+ from->sin_port = htons((u_short)tmpval);
X+ if (!bind(sd->sock, &sd->me, sizeof(struct sockaddr))) {
X tmpval = 0;
X break;
X }
X@@ -232,6 +230,13 @@
X udp_close(EAGAIN, sd, 0);
X return;
X }
X+ } else {
X+ /* bind socket to local source address */
X+ if ( from->sin_addr.s_addr != INADDR_ANY ) {
X+ if( bind(sd->sock, &sd->me, sizeof(struct sockaddr) ) == -1 )
X+ report(LOG_WARNING, "udp_start : bind failed for %s: %s",
X+ intoa(ipaddr,from->sin_addr), strerror(*(__error())) );
X+ }
X }
X
X /* turn on non-blocking I/O */
X@@ -298,7 +303,7 @@
X METHOD *method;
X {
X SESSION template;
X- struct sockaddr_in *to;
X+ struct sockaddr_in *to, *from;
X
X dprintf(("udp_init(%s/%s)\n", target->name, method->name));
X
X@@ -313,6 +318,10 @@
X to->sin_family = AF_INET;
X to->sin_port = htons(method->rport);
X to->sin_addr = method->address ? method->ip_addr : target->ip_addr;
X+ from = (struct sockaddr_in *)&template.me;
X+ bzero((char *)from, sizeof(struct sockaddr_in));
X+ from->sin_family = AF_INET;
X+ from->sin_addr = target->ip_srcaddr;
X template.timeout = method->timeout * 1000000L; /* make microseconds */
X template.retries = method->retries;
X template.send = udp_send;
X--- util.c.orig Tue Aug 26 10:53:17 2003
X+++ util.c Wed Sep 17 00:36:47 2003
X@@ -1415,16 +1415,27 @@
X printf("NetState %s\n", cf->ns_port ? "enabled" : "disabled");
X if (cf->ns_port) {
X printf("\tPort = %d\n", cf->ns_port);
X+ if (cf->ns_address)
X+ printf("\tBindAddress = \"%s\" [%s]\n", cf->ns_address, intoa(ipaddr, cf->ns_ip_addr));
X #ifndef HAVE_PTHREAD
X printf("\tTimeout = %d sec.\n", cf->ns_timo);
X #endif
X print_group_ref("\t", cf->ns_acl);
X }
X+ printf("SrcAddress = \"%s\" [%s]\n", (cf->srcaddress!=NULL ) ? cf->srcaddress : "default",
X+ intoa(ipaddr, cf->ip_srcaddr));
X
X+ printf("UserName = \"%s\" [%d]\n", cf->username, cf->uid);
X+ printf("GroupName = \"%s\" [%d]\n", cf->groupname, cf->gid);
X+
X+ if (cf->chrootdir)
X+ printf("ChRootDir = \"%s\"\n", cf->chrootdir );
X printf("Traps ");
X if (cf->enable_traps > 0) {
X printf("enabled");
X if (cf->source_traps > 0) printf(" (sourcecheck)");
X+ if (cf->trap_address)
X+ printf("\n\tTrapBindAddress = \"%s\" [%s]", cf->trap_address, intoa(ipaddr, cf->trap_ip_addr));
X } else printf("disabled");
X printf("\n");
X
X@@ -1434,6 +1445,8 @@
X printf("\tDescription = \"%s\"\n", target->descr);
X printf("\tAddress = \"%s\" [%s]\n", target->address,
X intoa(ipaddr, target->ip_addr));
X+ printf("\tSrcAddress = \"%s\" [%s]\n", (target->srcaddress!=NULL) ? target->srcaddress : "default",
X+ intoa(ipaddr, target->ip_srcaddr));
X if (target->polling > 0)
X printf("\tPolling = %d sec.\n", target->polling);
X else printf("\tPolling disabled\n");
X--- regex.h.orig Wed Sep 24 17:22:56 2003
X+++ regex.h Wed Sep 24 17:37:09 2003
X@@ -21,12 +21,12 @@
X */
X #define MAXDFA 1024
X #define MAXTAG 10
X-#define MAXCHR 128
X+#define MAXCHR 256
X #define CHRBIT 8
X #define BITBLK MAXCHR/CHRBIT
X #define BLKIND 0170
X #define BITIND 07
X-#define ASCIIB 0177
X+#define ASCIIB 0255
X
X typedef /*unsigned*/ char CHAR;
X
X--- regex.c.orig Wed Sep 24 17:09:07 2003
X+++ regex.c Thu Sep 25 15:26:47 2003
X@@ -554,12 +554,12 @@
X * the bitset form, since we may wish to extend it
X * in the future for other character classifications.
X *
X- * TRUE for 0-9 A-Z a-z _
X+ * TRUE for 0-9 A-Z a-z _ Á-Ñ á-ñ
X */
X static char chrtyp[MAXCHR] = {
X- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
X@@ -569,10 +569,23 @@
X 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
X 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
X- 1, 1, 1, 0, 0, 0, 0, 0
X+ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, // 120-129
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130-139
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 140-149
X+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // 160-169 163=£
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // 170-179 179=³
X+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 180-189
X+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, // 190-199
X+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 200-209
X+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 210-219
X+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 220-229
X+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 230-239
X+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 240-249
X+ 1, 1, 1, 1, 1, 1 // 250-255
X };
X
X-#define inascii(x) (0177&(x))
X+//#define inascii(x) (0177&(x))
X+#define inascii(x) (0255&(x))
X #define iswordc(x) chrtyp[inascii(x)]
X #define isinset(x, y) ((x)[((y)&BLKIND)>>3] & (1<<((y)&BITIND)))
X
END-of-netmond/files/patch-AA
echo x - netmond/files/netmond.sh
sed 's/^X//' >netmond/files/netmond.sh << 'END-of-netmond/files/netmond.sh'
X#!/bin/sh
X
Xif ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
X echo "$0: Cannot determine the PREFIX" >&2
X exit 1
Xfi
X
Xcase "$1" in
Xstart)
X [ -x ${PREFIX}/sbin/netmond ] && [ -r ${PREFIX}/etc/netmon.conf ] && ${PREFIX}/sbin/netmond && echo -n ' netmond'
X ;;
Xstop)
X killall netmond && echo -n ' netmond'
X ;;
X*)
X echo "Usage: `basename $0` {start|stop}" >&2
X ;;
Xesac
X
Xexit 0
END-of-netmond/files/netmond.sh
echo x - netmond/Makefile
sed 's/^X//' >netmond/Makefile << 'END-of-netmond/Makefile'
X# New ports collection makefile for: netmond
X# Date created: 2004 Mar 30
X# Whom: vfom at narod.ru
X#
X# $FreeBSD$
X#
X
XPORTNAME= netmond
XPORTVERSION= 2.2b5
XCATEGORIES= net-mgmt
XMASTER_SITES= ftp://ftp.risp.ru/pub/RinetSoftware/
XDISTNAME= netmond-2.2-b5
XEXTRACT_SUFX= .tgz
X
XMAINTAINER= vfom at narod.ru
XCOMMENT= Netmond - IP network monitoring daemon
X
XLIB_DEPENDS= gd.4:${PORTSDIR}/graphics/gd
X
XGNU_CONFIGURE= yes
XCONFIGURE_ARGS= --prefix=${PREFIX}
X
XNO_MTREE= yes
X
XBINOWN= root
XBINGRP= netmon
XBINMODE= 0550
X#
XPLIST_SUB= PORTNAME=${PORTNAME} PORTVERSION=${PORTVERSION}
X#
Xdo-install:
X @if pw user show netmon 2>/dev/null ; then \
X ${ECHO} "User 'netmon' exists." ; \
X else \
X pw useradd -n netmon -u 2002 -g wheel -c 'Network monitor account' -m ; \
X fi
X @if pw group show ${BINGRP} 2>/dev/null ; then \
X ${ECHO} "Group '${BINGRP}' exists." ; \
X else \
X pw groupadd ${BINGRP} -g 2002 -M root,netmon ; \
X fi
X ${INSTALL_PROGRAM} ${WRKSRC}/netmond ${PREFIX}/sbin/netmond
X ${INSTALL_PROGRAM} ${WRKSRC}/ifgraph ${PREFIX}/sbin/ifgraph
X ${INSTALL_SCRIPT} ${FILESDIR}/netmondctl ${PREFIX}/sbin/netmondctl
X ${INSTALL_SCRIPT} ${FILESDIR}/netmond_watchdog ${PREFIX}/sbin/netmond_watchdog
X ${INSTALL_SCRIPT} ${FILESDIR}/netmond.sh ${PREFIX}/etc/rc.d/netmond.sh
X ${INSTALL_DATA} ${WRKSRC}/netmon.conf.sample ${PREFIX}/etc
X ${CHMOD} u+s ${PREFIX}/sbin/netmond
X.if !defined(NOPORTDOCS)
X ${MKDIR} ${DOCSDIR}
X ${CHMOD} 555 ${DOCSDIR}
X ${INSTALL_DATA} ${WRKSRC}/README ${DOCSDIR}/
X ${INSTALL_DATA} ${WRKSRC}/CHANGES ${DOCSDIR}/
X ${INSTALL_DATA} ${FILESDIR}/README.port ${DOCSDIR}/
X.endif
X#
X.include <bsd.port.mk>
END-of-netmond/Makefile
echo x - netmond/distinfo
sed 's/^X//' >netmond/distinfo << 'END-of-netmond/distinfo'
XMD5 (netmond-2.2-b5.tgz) = cd624b7f275d949a239363c24c52f752
XSIZE (netmond-2.2-b5.tgz) = 263404
END-of-netmond/distinfo
echo x - netmond/pkg-descr
sed 's/^X//' >netmond/pkg-descr << 'END-of-netmond/pkg-descr'
XNETwork MONitoring Dealer - IP network monitoring daemon.
XCan check hosts availability (via ICMP ping), collect SNMP counters,
Xcheck simple TCP/UDP services (with internal chat), handle SNMP traps.
X
XFor a full documentation look at
XWWW: http://soft.risp.ru/netmond/
X(sorry, russian only)
X
XGUI frontends exist for netmond:
X - ftp://ftp.risp.ru/RinetSoft/netmond-spyboat-0.5.tgz ( with QT )
X - http://vfom.narod.ru/TkNetmon/ ( Tcl/Tk )
END-of-netmond/pkg-descr
echo x - netmond/pkg-install
sed 's/^X//' >netmond/pkg-install << 'END-of-netmond/pkg-install'
X#!/bin/sh
X#
XPKGNAME=$1
XDATADIR=/var/netmon
X#
Xcase $2 in
X PRE-INSTALL)
X if pw user show netmon 2>/dev/null ; then
X echo "User 'netmon' exists." ;
X else
X pw useradd -n netmon -u 2002 -g wheel -c 'Network monitor account' -m ;
X fi
X if pw group show netmon 2>/dev/null ; then
X echo "Group 'netmon' exists." ;
X else
X pw groupadd netmon -g 2002 -M root,netmon ;
X fi
X if [ ! -d ${DATADIR} ] ; then
X mkdir ${DATADIR}
X chown root:netmon ${DATADIR}
X chmod 750 ${DATADIR}
X fi
X ;;
X POST-INSTALL)
X ;;
X *)
X echo "Unexpected Argument $2!!!"
X exit 1
X ;;
Xesac
Xexit 0
END-of-netmond/pkg-install
echo x - netmond/pkg-plist
sed 's/^X//' >netmond/pkg-plist << 'END-of-netmond/pkg-plist'
Xsbin/netmond
Xsbin/ifgraph
Xsbin/netmondctl
Xsbin/netmond_watchdog
Xshare/doc/%%PORTNAME%%/README
Xshare/doc/%%PORTNAME%%/CHANGES
Xshare/doc/%%PORTNAME%%/README.port
Xetc/netmon.conf.sample
Xetc/rc.d/netmond.sh
X at dirrm share/doc/%%PORTNAME%%
END-of-netmond/pkg-plist
echo x - netmond/pkg-message
sed 's/^X//' >netmond/pkg-message << 'END-of-netmond/pkg-message'
X Attention!
X
X You need to create configuration file netmon.conf
X in directory ${PREFIX}/etc prior to launch netmond.
X
X Look at http://soft.risp.ru/netmond/ for the configuration guide
X or try to use TkNetmon to create configuration semiautomatically.
END-of-netmond/pkg-message
exit
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list