Subject: pkg/15157: SUBMISSION: net/sdig - Switch Digger finds port assignments for a client on a switched Ethernet.
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 01/06/2002 19:03:13
>Number:         15157
>Category:       pkg
>Synopsis:       SUBMISSION: net/sdig - Switch Digger finds port assignments for a client on a switched Ethernet.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 06 16:04:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Greg A. Woods
>Release:        pkgsrc 2002/01/05
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD
>Description:

	Enclosed is a pkgsrc module for net/sdig, aka Switch Digger, a
	program which finds router/switch port assignments for a client
	on a switched Ethernet.

	Note the changes I made in the sdig.c patch to optionally
	support ucd-snmp-4.1.2 are not likely to be accepted by the
	author who is only claiming support of the latest version of
	net-snmp (4.2.x, presumably).

>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:
#
#	DESCR
#	Makefile
#	MESSAGE
#	PLIST
#	distinfo
#	patches
#	patches/patch-aa
#	patches/patch-ab
#	patches/patch-ac
#
echo x - DESCR
sed 's/^X//' >DESCR << 'END-of-DESCR'
XThe Switch Digger works on the premise that today's routers and switches
Xare chock-full of information that very few people use.  It puts that data
Xto good use and cross-references what the network knows with what it knows
Xto arrive at the closest possible location.
X
XThis program is designed to track down computers to the finest level of
Xinformation available at the moment.  Sometimes this can mean an exact
Xdescription of a port in a building anywhere in an enterprise.  Other
Xtimes this may just be a vague notion of a faraway network.  The results
Xare only as good as the data you feed to it.
END-of-DESCR
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X# $NetBSD$
X
XDISTNAME=	sdig-0.11
XCATEGORIES=	net
XMASTER_SITES=	http://www.exploits.org/sdig/
X
XDISTFILES=	${DISTNAME}${EXTRACT_SUFX} mactable.gz
XEXTRACT_ONLY=	${DISTNAME}${EXTRACT_SUFX}
X
XMAINTAINER=	packages@netbsd.org
XHOMEPAGE=	http://www.exploits.org/sdig/
XCOMMENT=	Switch Digger finds port assignment for a client on a switched Ethernet.
X
XDEPENDS=	ucd-snmp>=4.1.2:../../net/ucd-snmp
X
X.include "../../mk/bsd.prefs.mk"
X
Xpost-extract:
X	${GZCAT} < ${DISTDIR}/mactable.gz > ${WRKDIR}/mactable
X
Xpost-build: my-post-build
X
Xpost-install:
X	${INSTALL_DATA} ${WRKDIR}/sdig.conf ${PREFIX}/share/examples/
X	${INSTALL_DATA} ${WRKDIR}/mactable ${PREFIX}/share/misc/
X
X.include "../../mk/bsd.pkg.mk"
X
X# Note:  this depends on having a MESSAGE file, which we do.
X#
Xmy-post-build:
X	${SED} ${MESSAGE_SUBST_SED} < ${WRKSRC}/sdig.conf > ${WRKDIR}/sdig.conf
END-of-Makefile
echo x - MESSAGE
sed 's/^X//' >MESSAGE << 'END-of-MESSAGE'
XNote: a sample config file can be found here:
X
X	 ${PREFIX}/share/examples/sdig.conf
X
XCopy it to ${PREFIX}/etc/sdig.conf and edit to suit your needs.
END-of-MESSAGE
echo x - PLIST
sed 's/^X//' >PLIST << 'END-of-PLIST'
X@comment $NetBSD$
Xbin/sdig
Xbin/nbname
Xshare/doc/sdig.README
Xshare/examples/sdig.conf
Xshare/misc/mactable
END-of-PLIST
echo x - distinfo
sed 's/^X//' >distinfo << 'END-of-distinfo'
X$NetBSD$
X
XSHA1 (sdig-0.11.tar.gz) = 5e21c28a22c8ce4106b38b4490a6b10e870d06e2
XSize (sdig-0.11.tar.gz) = 21546 bytes
XSHA1 (mactable.gz) = afe9c24c45c5472c9e78d2a8d72fcdc18d43563d
XSize (mactable.gz) = 36490 bytes
XSHA1 (patch-aa) = c5a66e535440a81a7fa8b5735c5a38fbd1b33475
XSHA1 (patch-ab) = 3e08390a2b66a068ce9901e1ffe6d9d42a32cea9
XSHA1 (patch-ac) = f9c6f28d65a540b326644cc7d96cf0ed5cf0cf60
END-of-distinfo
echo c - patches
mkdir -p patches > /dev/null 2>&1
echo x - patches/patch-aa
sed 's/^X//' >patches/patch-aa << 'END-of-patches/patch-aa'
X+++ Makefile	Sun Jan  6 18:34:14 2002
X@@ -1,22 +1,19 @@
X-CC	= gcc
X-CFLAGS	= -O2 -Wall # -g -static
X-BINDIR	= /usr/sbin
X-PROGS   = sdig nbname swc
X+PREFIX ?= /usr/local
X+CFLAGS	= -g -O2 -Wall -DPREFIX="\"${PREFIX}\""
X+PROGS   = sdig nbname # swc
X 
X all: $(PROGS)
X 
X+sdig: sdig.o common.o
X+	$(CC) $(LDFLAGS) -o $@ $@.o common.o
X+
X+#swc: swc.o common.o
X+#	$(CC) $(LDFLAGS) -o $@ $@.o common.o
X 
X clean:
X 	rm $(PROGS) *.o
X 
X install: all
X-	cp sdig /usr/local/bin
X-	cp nbname /usr/local/bin
X-	@if ( test -f /etc/sdig.conf ) \
X-	then \
X-	else \
X-		cp sdig.conf /etc; \
X-	fi
X+	${BSD_INSTALL_PROGRAM} sdig ${PREFIX}/bin
X+	${BSD_INSTALL_PROGRAM} nbname ${PREFIX}/bin
X+	${BSD_INSTALL_DATA} README ${PREFIX}/share/doc/sdig.README
END-of-patches/patch-aa
echo x - patches/patch-ab
sed 's/^X//' >patches/patch-ab << 'END-of-patches/patch-ab'
X+++ sdig.c	Sun Jan  6 18:45:02 2002
X@@ -25,15 +25,19 @@
X #include <stdlib.h> 
X #include <string.h> 
X #include <unistd.h> 
X-#include <arpa/inet.h> 
X-#include <netinet/in.h> 
X+#include <sys/types.h>
X #include <sys/socket.h>
X+#include <netinet/in.h> 
X+#include <arpa/inet.h> 
X+#include <netdb.h> 
X+#include <arpa/nameser.h> 
X+#include <resolv.h> 
X 
X #include "common.h"
X #include "version.h"
X 
X #define PPS 32		/* 32 ports per switch */
X-#define CONFIGFILE "/etc/sdig.conf"
X+#define CONFIGFILE PREFIX "/etc/sdig.conf"
X 
X 	char	*wins = NULL, *nbname = NULL, *nmblookup = NULL, 
X 		*snmpget = NULL, *mactable = NULL;
X@@ -115,6 +119,7 @@
X char *findport (char *mac, char *swip, char *swpw)
X {
X 	char	needle[64], oid[64], exec[256], *ptr, *ptr2, buf[256], *sp;
X+	char	sep = ':';
X 	char	*tmp;
X 	FILE	*out;
X 	int	i;
X@@ -125,13 +130,22 @@
X 		exit (1);
X 	}
X 
X-	snprintf (needle, sizeof(needle), "17.4.3.1.2");
X+	snprintf (needle, sizeof(needle), ".1.3.6.1.2.1.17.4.3.1.2");
X 
X-	ptr = strdup(mac);
X+	if (strncmp(mac, " Hex: ", 6) == 0) {
X+		sep = ' ';
X+		ptr = strdup(mac + 6);
X+		debug("MAC ptr with sep = ' ' is [%s]\n", ptr);
X+	} else {
X+		ptr = strdup(mac);
X+		debug("MAC ptr with sep = ':' is [%s]\n", ptr);
X+	}
X 	for (i = 0; i < 6; i++) {
X+		sp = strchr (ptr, sep);
X 		if (sp)
X 			*sp = '\0';
X+		else
X+			break;
X 
X 		val = strtoul (ptr, NULL, 16);
X 		if (i == 5)
X@@ -145,7 +159,7 @@
X 
X 	debug("needle is [%s]\n", needle);
X 
X-	snprintf (exec, sizeof(exec), "%s %s %s %s 2>/dev/null", snmpget, swip, swpw, needle);
X+	snprintf (exec, sizeof(exec), "%s -On %s %s %s 2>/dev/null", snmpget, swip, swpw, needle);
X 
X 	debug("popen: %s\n", exec);
X 	out = popen (exec, "r");
X@@ -472,6 +486,7 @@
X {
X 	FILE	*macdb;
X 	char	buf[256], *mac, *tmp, *ptr, *cp, macfind[16];
X+	char	sep = ':';
X 	int	i, num[3];
X 
X 	macdb = fopen (mactable, "r");
X@@ -482,9 +497,16 @@
X 
X 	num[0] = num[1] = num[2] = 0;
X 
X-	ptr = mac = strdup(inmac);
X+	if (strncmp(inmac, " Hex: ", 6) == 0) {
X+		sep = ' ';
X+		ptr = mac = strdup(inmac + 6);
X+		debug("inMAC ptr with sep = ' ' is [%s]\n", ptr);
X+	} else {
X+		ptr = mac = strdup(inmac);
X+		debug("inMAC ptr with sep = ':' is [%s]\n", ptr);
X+	}
X 	for (i = 0; i < 3; i++) {
X+		cp = strchr (ptr, sep);
X 
X 		if (!cp)
X 			continue;
X@@ -498,6 +520,7 @@
X 	snprintf(macfind, sizeof(macfind), "%02x %02x %02x", 
X 		num[0], num[1], num[2]);
X 
X+	debug("looking for MAC prefix [%s] in %s\n", macfind, mactable);
X 	while (fgets(buf, sizeof(buf), macdb)) {
X 		buf[strlen(buf) - 1] = '\0';
X 
END-of-patches/patch-ab
echo x - patches/patch-ac
sed 's/^X//' >patches/patch-ac << 'END-of-patches/patch-ac'
X+++ sdig.conf	Sun Jan  6 18:33:55 2002
X@@ -49,12 +49,10 @@
X #
X # Enter the pathname to the Samba nmblookup program.
X #
X-# This setting also must exist to query hostnames.  IP addresses can
X+# This setting also must exist to query WINS hostnames.  IP addresses can
X # still be used without it.
X-#
X-# Usual path is /usr/local/samba/bin
X 
X-NMBLOOKUP /usr/local/samba/bin/nmblookup
X+NMBLOOKUP ${PREFIX}/bin/nmblookup
X 
X # ---------------------------------------------------------------------------
X # NBNAME <path to nbname binary>
X@@ -65,10 +63,8 @@
X # servers will sanely answer queries from any source port.
X #
X # This is strictly to add extra information, and is optional.
X-#
X-# Installed by default into /usr/local/bin
X 
X-NBNAME /usr/local/bin/nbname
X+NBNAME ${PREFIX}/bin/nbname
X 
X # ---------------------------------------------------------------------------
X # SNMPGET <path to snmpget program>
X@@ -76,10 +72,8 @@
X # Enter the pathname to the Net-SNMP snmpget program.
X #
X # This does all the dirty work for us, and therefore is required.
X-#
X-# It usually installs to /usr/local/bin, so this default is generally OK.
X 
X-SNMPGET /usr/local/bin/snmpget
X+SNMPGET ${PREFIX}/bin/snmpget
X 
X # ---------------------------------------------------------------------------
X # MACTABLE <path to MAC table file>
X@@ -92,4 +86,4 @@
X # rarely changes.  If you want to use this feature, get it from the
X # main web site: http://www.exploits.org/sdig/
X 
X-MACTABLE /etc/mactable
X+MACTABLE ${PREFIX}/share/misc/mactable
END-of-patches/patch-ac
exit

>Release-Note:
>Audit-Trail:
>Unformatted: