tag 550611 patch
thanks

Hi!

On Sun, 2009-10-11 at 15:12:02 +0000, Thorsten Glaser wrote:
> Package: netcat-openbsd
> Severity: wishlist
> 
> Please link against libbsd, now that it has been available in stable
> for quite a while, instead of glib.
> 
> Some day, libbsd may get upped to important (I hope), so that this
> can replace netcat-traditional and netcat6 at once. It’s also much
> more lightweight a dependency AND the “original source” of strlcpy
> and friends AND will probably require a much smaller patch only.

Here's a patch to switch to libbsd. I've added few functions needed by
netcat-openbsd on the last upstream release so this helps in reducing
the delta with upstream. If there's more stuff you need in the future
please request it and I'll consider its addition.

Here's a summary of the changes:

 * no-strtonum.patch: Remove, use strtonum from libbsd.
 * openbsd-compat.patch: Remove, use readpassphrase from libbsd.
 * quit-timer.patch: Change to use strtonum instead of strtoul.

 * gcc-warnings.patch: Refreshed to take into account no-strotonum
 patch removal.
 * getservbyname.patch: Likewise.

 * glib-strlcpy.patch: Remove hunks related to glib conversion
 (strlcpy and arc4random) as those are now from libbsd. Remaining
 changes are unrelated to glib, so rename to ...
 * disable-setsockopts.patch: ... this.

 * socks-b64-prototype.patch: Remove, not strictly libbsd related, but
 as I was at it, switch to use the function from <resolv.h> which
 requires to link against -lresolv on GNU systems, and avoids using
 the local embedded code.

 * bsd-compat.patch: New. This one should be obvious given the previous.

regards,
guillem
diff --git a/debian/control b/debian/control
index 193530c..91981d8 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: net
 Priority: optional
 Maintainer: Decklin Foster <deck...@red-bean.com>
 Standards-Version: 3.7.3
-Build-Depends: quilt, debhelper (>= 4.0.0), libglib2.0-dev
+Build-Depends: quilt, debhelper (>= 4.0.0), libbsd-dev (>= 0.2.0)
 
 Package: netcat-openbsd
 Architecture: any
diff --git a/debian/patches/bsd-compat.patch b/debian/patches/bsd-compat.patch
new file mode 100644
index 0000000..8507b55
--- /dev/null
+++ b/debian/patches/bsd-compat.patch
@@ -0,0 +1,36 @@
+---
+ Makefile |    9 ++++-----
+ socks.c  |    2 +-
+ 2 files changed, 5 insertions(+), 6 deletions(-)
+
+--- a/socks.c
++++ b/socks.c
+@@ -38,7 +38,7 @@
+ #include <string.h>
+ #include <unistd.h>
+ #include <resolv.h>
+-#include <readpassphrase.h>
++#include <bsd/readpassphrase.h>
+ #include "atomicio.h"
+ 
+ #define SOCKS_PORT	"1080"
+--- a/Makefile
++++ b/Makefile
+@@ -1,13 +1,12 @@
+ #	$OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $
+ 
+ PROG=	nc
+-SRCS=	netcat.c atomicio.c socks.c \
+-        openbsd-compat/base64.c openbsd-compat/readpassphrase.c
++SRCS=	netcat.c atomicio.c socks.c
+ 
+ CC = gcc
+-override CFLAGS += `pkg-config --cflags glib-2.0`
+-INC = -Iopenbsd-compat
+-LIBS = `pkg-config --libs glib-2.0`
++override CFLAGS += `pkg-config --cflags libbsd`
++INC = -include bsd/bsd.h
++LIBS = `pkg-config --libs libbsd` -lresolv
+ OBJS = $(SRCS:.c=.o)
+ 
+ all: nc
diff --git a/debian/patches/disable-setsockopts.patch b/debian/patches/disable-setsockopts.patch
new file mode 100644
index 0000000..d55db1a
--- /dev/null
+++ b/debian/patches/disable-setsockopts.patch
@@ -0,0 +1,59 @@
+Index: netcat-openbsd-1.89/netcat.c
+===================================================================
+--- netcat-openbsd-1.89.orig/netcat.c	2007-02-20 09:11:17.000000000 -0500
++++ netcat-openbsd-1.89/netcat.c	2008-01-21 18:48:23.000000000 -0500
+@@ -549,11 +551,11 @@
+ 		if ((s = socket(res0->ai_family, res0->ai_socktype,
+ 		    res0->ai_protocol)) < 0)
+ 			continue;
+-
++		#ifdef SO_REUSEPORT
+ 		ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
+ 		if (ret == -1)
+ 			err(1, NULL);
+-
++		#endif
+ 		set_common_sockopts(s);
+ 
+ 		if (bind(s, (struct sockaddr *)res0->ai_addr,
+@@ -761,21 +764,25 @@
+ {
+ 	int x = 1;
+ 
++#ifdef TCP_MD5SIG
+ 	if (Sflag) {
+ 		if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
+ 			&x, sizeof(x)) == -1)
+ 			err(1, NULL);
+ 	}
++#endif
+ 	if (Dflag) {
+ 		if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
+ 			&x, sizeof(x)) == -1)
+ 			err(1, NULL);
+ 	}
++#ifdef SO_JUMBO
+ 	if (jflag) {
+ 		if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
+ 			&x, sizeof(x)) == -1)
+ 			err(1, NULL);
+ 	}
++#endif
+ 	if (Tflag != -1) {
+ 		if (setsockopt(s, IPPROTO_IP, IP_TOS,
+ 		    &Tflag, sizeof(Tflag)) == -1)
+@@ -816,9 +823,11 @@
+ 	\t-n		Suppress name/port resolutions\n\
+ 	\t-P proxyuser\tUsername for proxy authentication\n\
+ 	\t-p port\t	Specify local port for remote connects\n\
+-	\t-r		Randomize remote ports\n\
+-	\t-S		Enable the TCP MD5 signature option\n\
+-	\t-s addr\t	Local source address\n\
++	\t-r		Randomize remote ports\n "
++#ifdef TCP_MD5SIG
++"	\t-S		Enable the TCP MD5 signature option\n"
++#endif
++"	\t-s addr\t	Local source address\n\
+ 	\t-T ToS\t	Set IP Type of Service\n\
+ 	\t-t		Answer TELNET negotiation\n\
+ 	\t-U		Use UNIX domain socket\n\
diff --git a/debian/patches/gcc-warnings.patch b/debian/patches/gcc-warnings.patch
index b83b618..59f3a97 100644
--- a/debian/patches/gcc-warnings.patch
+++ b/debian/patches/gcc-warnings.patch
@@ -2,16 +2,16 @@ Index: netcat-openbsd-1.89/netcat.c
 ===================================================================
 --- netcat-openbsd-1.89.orig/netcat.c	2008-01-22 20:39:46.000000000 -0500
 +++ netcat-openbsd-1.89/netcat.c	2008-01-22 20:42:35.000000000 -0500
-@@ -127,7 +127,7 @@
+@@ -125,7 +125,7 @@
  	struct servent *sv;
  	socklen_t len;
  	struct sockaddr_storage cliaddr;
 -	char *proxy;
 +	char *proxy = NULL;
- 	const char *proxyhost = "", *proxyport = NULL;
+ 	const char *errstr, *proxyhost = "", *proxyport = NULL;
  	struct addrinfo proxyhints;
  
-@@ -800,14 +800,12 @@
+@@ -795,14 +795,12 @@
  			obuf[1] = DONT;
  		if ((*p == DO) || (*p == DONT))
  			obuf[1] = WONT;
@@ -36,7 +36,7 @@ Index: netcat-openbsd-1.89/socks.c
 ===================================================================
 --- netcat-openbsd-1.89.orig/socks.c	2008-01-22 20:36:26.000000000 -0500
 +++ netcat-openbsd-1.89/socks.c	2008-01-22 20:39:46.000000000 -0500
-@@ -169,11 +169,11 @@
+@@ -167,11 +167,11 @@
  		buf[2] = SOCKS_NOAUTH;
  		cnt = atomicio(vwrite, proxyfd, buf, 3);
  		if (cnt != 3)
@@ -50,7 +50,7 @@ Index: netcat-openbsd-1.89/socks.c
  
  		if (buf[1] == SOCKS_NOMETHOD)
  			errx(1, "authentication method negotiation failed");
-@@ -222,11 +222,11 @@
+@@ -220,11 +220,11 @@
  
  		cnt = atomicio(vwrite, proxyfd, buf, wlen);
  		if (cnt != wlen)
@@ -64,7 +64,7 @@ Index: netcat-openbsd-1.89/socks.c
  		if (buf[1] != 0)
  			errx(1, "connection failed, SOCKS error %d", buf[1]);
  	} else if (socksv == 4) {
-@@ -244,11 +244,11 @@
+@@ -242,11 +242,11 @@
  
  		cnt = atomicio(vwrite, proxyfd, buf, wlen);
  		if (cnt != wlen)
@@ -78,7 +78,7 @@ Index: netcat-openbsd-1.89/socks.c
  		if (buf[1] != 90)
  			errx(1, "connection failed, SOCKS error %d", buf[1]);
  	} else if (socksv == -1) {
-@@ -260,39 +260,39 @@
+@@ -258,39 +258,39 @@
  
  		/* Try to be sane about numeric IPv6 addresses */
  		if (strchr(host, ':') != NULL) {
@@ -127,7 +127,7 @@ Index: netcat-openbsd-1.89/socks.c
  		}
  
  		/* Terminate headers */
-@@ -300,22 +300,22 @@
+@@ -298,22 +298,22 @@
  			err(1, "write failed (2/%d)", r);
  
  		/* Read status reply */
diff --git a/debian/patches/getservbyname.patch b/debian/patches/getservbyname.patch
index 783536c..e391c48 100644
--- a/debian/patches/getservbyname.patch
+++ b/debian/patches/getservbyname.patch
@@ -2,12 +2,13 @@ Index: netcat-openbsd-1.89/netcat.c
 ===================================================================
 --- netcat-openbsd-1.89.orig/netcat.c	2008-01-22 20:39:46.000000000 -0500
 +++ netcat-openbsd-1.89/netcat.c	2008-01-22 20:43:36.000000000 -0500
-@@ -819,11 +819,18 @@
+@@ -814,12 +814,19 @@
  void
  build_ports(char *p)
  {
 +	struct servent *sv;
- 	char *n, *endp;
+ 	const char *errstr;
+ 	char *n;
  	int hi, lo, cp;
  	int x = 0;
  
diff --git a/debian/patches/glib-strlcpy.patch b/debian/patches/glib-strlcpy.patch
deleted file mode 100644
index d3d0d41..0000000
--- a/debian/patches/glib-strlcpy.patch
+++ /dev/null
@@ -1,96 +0,0 @@
-Index: netcat-openbsd-1.89/netcat.c
-===================================================================
---- netcat-openbsd-1.89.orig/netcat.c	2007-02-20 09:11:17.000000000 -0500
-+++ netcat-openbsd-1.89/netcat.c	2008-01-21 18:48:23.000000000 -0500
-@@ -55,6 +55,8 @@
- #include <limits.h>
- #include "atomicio.h"
- 
-+#include <glib.h>
-+
- #ifndef SUN_LEN
- #define SUN_LEN(su) \
- 	(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
-@@ -414,7 +416,7 @@
- 	memset(&sun, 0, sizeof(struct sockaddr_un));
- 	sun.sun_family = AF_UNIX;
- 
--	if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
-+	if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
- 	    sizeof(sun.sun_path)) {
- 		close(s);
- 		errno = ENAMETOOLONG;
-@@ -445,7 +447,7 @@
- 	memset(&sun, 0, sizeof(struct sockaddr_un));
- 	sun.sun_family = AF_UNIX;
- 
--	if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
-+	if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
- 	    sizeof(sun.sun_path)) {
- 		close(s);
- 		errno = ENAMETOOLONG;
-@@ -549,11 +551,11 @@
- 		if ((s = socket(res0->ai_family, res0->ai_socktype,
- 		    res0->ai_protocol)) < 0)
- 			continue;
--
-+		#ifdef SO_REUSEPORT
- 		ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
- 		if (ret == -1)
- 			err(1, NULL);
--
-+		#endif
- 		set_common_sockopts(s);
- 
- 		if (bind(s, (struct sockaddr *)res0->ai_addr,
-@@ -719,7 +721,8 @@
- 			char *c;
- 
- 			for (x = 0; x <= (hi - lo); x++) {
--				y = (arc4random() & 0xFFFF) % (hi - lo);
-+				/* use random instead of arc4random */
-+				y = (random() & 0xFFFF) % (hi - lo);
- 				c = portlist[x];
- 				portlist[x] = portlist[y];
- 				portlist[y] = c;
-@@ -761,21 +764,25 @@
- {
- 	int x = 1;
- 
-+#ifdef TCP_MD5SIG
- 	if (Sflag) {
- 		if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
- 			&x, sizeof(x)) == -1)
- 			err(1, NULL);
- 	}
-+#endif
- 	if (Dflag) {
- 		if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
- 			&x, sizeof(x)) == -1)
- 			err(1, NULL);
- 	}
-+#ifdef SO_JUMBO
- 	if (jflag) {
- 		if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
- 			&x, sizeof(x)) == -1)
- 			err(1, NULL);
- 	}
-+#endif
- 	if (Tflag != -1) {
- 		if (setsockopt(s, IPPROTO_IP, IP_TOS,
- 		    &Tflag, sizeof(Tflag)) == -1)
-@@ -816,9 +823,11 @@
- 	\t-n		Suppress name/port resolutions\n\
- 	\t-P proxyuser\tUsername for proxy authentication\n\
- 	\t-p port\t	Specify local port for remote connects\n\
--	\t-r		Randomize remote ports\n\
--	\t-S		Enable the TCP MD5 signature option\n\
--	\t-s addr\t	Local source address\n\
-+	\t-r		Randomize remote ports\n "
-+#ifdef TCP_MD5SIG
-+"	\t-S		Enable the TCP MD5 signature option\n"
-+#endif
-+"	\t-s addr\t	Local source address\n\
- 	\t-T ToS\t	Set IP Type of Service\n\
- 	\t-t		Answer TELNET negotiation\n\
- 	\t-U		Use UNIX domain socket\n\
diff --git a/debian/patches/no-strtonum.patch b/debian/patches/no-strtonum.patch
deleted file mode 100644
index 6370afe..0000000
--- a/debian/patches/no-strtonum.patch
+++ /dev/null
@@ -1,107 +0,0 @@
-Index: netcat-openbsd-1.89/netcat.c
-===================================================================
---- netcat-openbsd-1.89.orig/netcat.c	2008-01-22 16:17:17.000000000 -0500
-+++ netcat-openbsd-1.89/netcat.c	2008-01-22 16:17:18.000000000 -0500
-@@ -67,7 +67,7 @@
- 
- /* Command Line Options */
- int	dflag;					/* detached, no stdin */
--unsigned int iflag;				/* Interval Flag */
-+int	iflag;					/* Interval Flag */
- int	jflag;					/* use jumbo frames if we can */
- int	kflag;					/* More than one connect */
- int	lflag;					/* Bind to local port */
-@@ -108,13 +108,13 @@
- main(int argc, char *argv[])
- {
- 	int ch, s, ret, socksv;
--	char *host, *uport;
-+	char *host, *uport, *endp;
- 	struct addrinfo hints;
- 	struct servent *sv;
- 	socklen_t len;
- 	struct sockaddr_storage cliaddr;
- 	char *proxy;
--	const char *errstr, *proxyhost = "", *proxyport = NULL;
-+	const char *proxyhost = "", *proxyport = NULL;
- 	struct addrinfo proxyhints;
- 
- 	ret = 1;
-@@ -122,6 +122,7 @@
- 	socksv = 5;
- 	host = NULL;
- 	uport = NULL;
-+	endp = NULL;
- 	sv = NULL;
- 
- 	while ((ch = getopt(argc, argv,
-@@ -153,9 +154,9 @@
- 			help();
- 			break;
- 		case 'i':
--			iflag = strtonum(optarg, 0, UINT_MAX, &errstr);
--			if (errstr)
--				errx(1, "interval %s: %s", errstr, optarg);
-+			iflag = (int)strtoul(optarg, &endp, 10);
-+			if (iflag < 0 || *endp != '\0')
-+				errx(1, "interval cannot be negative");
- 			break;
- 		case 'j':
- 			jflag = 1;
-@@ -191,9 +192,11 @@
- 			vflag = 1;
- 			break;
- 		case 'w':
--			timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
--			if (errstr)
--				errx(1, "timeout %s: %s", errstr, optarg);
-+			timeout = (int)strtoul(optarg, &endp, 10);
-+			if (timeout < 0 || *endp != '\0')
-+				errx(1, "timeout cannot be negative");
-+			if (timeout >= (INT_MAX / 1000))
-+				errx(1, "timeout too large");
- 			timeout *= 1000;
- 			break;
- 		case 'x':
-@@ -680,8 +683,7 @@
- void
- build_ports(char *p)
- {
--	const char *errstr;
--	char *n;
-+	char *n, *endp;
- 	int hi, lo, cp;
- 	int x = 0;
- 
-@@ -693,12 +695,12 @@
- 		n++;
- 
- 		/* Make sure the ports are in order: lowest->highest. */
--		hi = strtonum(n, 1, PORT_MAX, &errstr);
--		if (errstr)
--			errx(1, "port number %s: %s", errstr, n);
--		lo = strtonum(p, 1, PORT_MAX, &errstr);
--		if (errstr)
--			errx(1, "port number %s: %s", errstr, p);
-+		hi = (int)strtoul(n, &endp, 10);
-+		if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
-+			errx(1, "port range not valid");
-+		lo = (int)strtoul(p, &endp, 10);
-+		if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
-+			errx(1, "port range not valid");
- 
- 		if (lo > hi) {
- 			cp = hi;
-@@ -729,9 +731,9 @@
- 			}
- 		}
- 	} else {
--		hi = strtonum(p, 1, PORT_MAX, &errstr);
--		if (errstr)
--			errx(1, "port number %s: %s", errstr, p);
-+		hi = (int)strtoul(p, &endp, 10);
-+		if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
-+			errx(1, "port range not valid");
- 		portlist[0] = calloc(1, PORT_MAX_LEN);
- 		if (portlist[0] == NULL)
- 			err(1, NULL);
diff --git a/debian/patches/openbsd-compat.patch b/debian/patches/openbsd-compat.patch
deleted file mode 100644
index 0e9466e..0000000
--- a/debian/patches/openbsd-compat.patch
+++ /dev/null
@@ -1,54 +0,0 @@
-Index: netcat-openbsd-1.89/openbsd-compat/readpassphrase.c
-===================================================================
---- netcat-openbsd-1.89.orig/openbsd-compat/readpassphrase.c	2008-01-22 18:21:56.000000000 -0500
-+++ netcat-openbsd-1.89/openbsd-compat/readpassphrase.c	2008-01-22 18:22:58.000000000 -0500
-@@ -31,6 +31,12 @@
- #include <unistd.h>
- #include <readpassphrase.h>
- 
-+#ifdef TCSASOFT
-+# define _T_FLUSH      (TCSAFLUSH|TCSASOFT)
-+#else
-+# define _T_FLUSH      (TCSAFLUSH)
-+#endif
-+
- static volatile sig_atomic_t signo;
- 
- static void handler(int);
-@@ -92,9 +98,11 @@
- 		memcpy(&term, &oterm, sizeof(term));
- 		if (!(flags & RPP_ECHO_ON))
- 			term.c_lflag &= ~(ECHO | ECHONL);
-+#ifdef VSTATUS
- 		if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
- 			term.c_cc[VSTATUS] = _POSIX_VDISABLE;
--		(void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
-+#endif
-+		(void)tcsetattr(input, _T_FLUSH, &term);
- 	} else {
- 		memset(&term, 0, sizeof(term));
- 		term.c_lflag |= ECHO;
-@@ -129,7 +137,7 @@
- 
- 	/* Restore old terminal settings and signals. */
- 	if (memcmp(&term, &oterm, sizeof(term)) != 0) {
--		while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
-+		while (tcsetattr(input, _T_FLUSH, &oterm) == -1 &&
- 		    errno == EINTR)
- 			continue;
- 	}
-@@ -164,14 +172,6 @@
- 	return(nr == -1 ? NULL : buf);
- }
- 
--char *
--getpass(const char *prompt)
--{
--	static char buf[_PASSWORD_LEN + 1];
--
--	return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
--}
--
- static void handler(int s)
- {
- 
diff --git a/debian/patches/quit-timer.patch b/debian/patches/quit-timer.patch
index 4d3d059..3dac00e 100644
--- a/debian/patches/quit-timer.patch
+++ b/debian/patches/quit-timer.patch
@@ -35,12 +35,14 @@ Index: netcat-openbsd-1.89/netcat.c
  		switch (ch) {
  		case '4':
  			family = AF_INET;
-@@ -187,6 +190,9 @@
+@@ -187,6 +190,11 @@
  		case 'p':
  			pflag = optarg;
  			break;
 +		case 'q':
-+			qflag = (int)strtoul(optarg, &endp, 10);
++			qflag = strtonum(optarg, INT_MIN, INT_MAX, &errstr);
++			if (errstr)
++				errx(1, "interval %s: %s", errstr, optarg);
 +			break;
  		case 'r':
  			rflag = 1;
diff --git a/debian/patches/series b/debian/patches/series
index 3f64b58..b97402f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,8 +1,6 @@
-openbsd-compat.patch
-socks-b64-prototype.patch
+bsd-compat.patch
 silence-z.patch
-glib-strlcpy.patch
-no-strtonum.patch
+disable-setsockopts.patch
 pollhup.patch
 reuseaddr.patch
 connect-timeout.patch
diff --git a/debian/patches/socks-b64-prototype.patch b/debian/patches/socks-b64-prototype.patch
deleted file mode 100644
index f040039..0000000
--- a/debian/patches/socks-b64-prototype.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-Index: netcat-openbsd-1.89/socks.c
-===================================================================
---- netcat-openbsd-1.89.orig/socks.c	2008-06-19 16:30:45.000000000 -0400
-+++ netcat-openbsd-1.89/socks.c	2008-06-19 16:30:36.000000000 -0400
-@@ -53,6 +53,8 @@
- #define SOCKS_DOMAIN	3
- #define SOCKS_IPV6	4
- 
-+extern int b64_ntop(unsigned char const *, size_t, char *, size_t);
-+
- int	remote_connect(const char *, const char *, struct addrinfo);
- int	socks_connect(const char *, const char *, struct addrinfo,
- 	    const char *, const char *, struct addrinfo, int,

Reply via email to