unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob b2e8c72ee3c87cb5adb70ef667526c78083f7a81 2973 bytes (raw)
name: gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
 
From: Thomas Habets <habets@google.com>
Date: Sat, 18 Feb 2017 21:07:22 +0000
Subject: Set TCP MD5SIG correctly for client connections

---
 netcat.c |   31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

--- a/netcat.c
+++ b/netcat.c
@@ -46,6 +46,9 @@
 #ifdef __linux__
 # include <linux/in6.h>
 #endif
+#if defined(TCP_MD5SIG) && defined(TCP_MD5SIG_MAXKEYLEN)
+# include <bsd/readpassphrase.h>
+#endif
 
 #ifndef IPTOS_LOWDELAY
 # define IPTOS_LOWDELAY 0x10
@@ -175,6 +178,9 @@ FILE	*Zflag;					/* file to save peer ce
 int	Cflag = 0;			/* CRLF line-ending */
 # endif
 
+# if defined(TCP_MD5SIG) && defined(TCP_MD5SIG_MAXKEYLEN)
+char Sflag_password[TCP_MD5SIG_MAXKEYLEN];
+# endif
 int recvcount, recvlimit;
 int timeout = -1;
 int family = AF_UNSPEC;
@@ -205,7 +211,7 @@ int	udptest(int);
 int	unix_bind(char *, int);
 int	unix_connect(char *);
 int	unix_listen(char *);
-void	set_common_sockopts(int, int);
+void	set_common_sockopts(int, const struct sockaddr *);
 int	process_tos_opt(char *, int *);
 # if defined(TLS)
 int	process_tls_opt(char *, int *);
@@ -458,7 +464,10 @@ main(int argc, char *argv[])
 			break;
 # endif
 		case 'S':
-# if defined(TCP_MD5SIG)
+# if defined(TCP_MD5SIG) && defined(TCP_MD5SIG_MAXKEYLEN)
+			if (readpassphrase("TCP MD5SIG password: ",
+			                   Sflag_password, TCP_MD5SIG_MAXKEYLEN, RPP_REQUIRE_TTY) == NULL)
+				errx(1, "Unable to read TCP MD5SIG password");
 			Sflag = 1;
 # else
 			errx(1, "no TCP MD5 signature support available");
@@ -1169,7 +1178,7 @@ remote_connect(const char *host, const c
 			freeaddrinfo(ares);
 		}
 
-		set_common_sockopts(s, res->ai_family);
+		set_common_sockopts(s, res->ai_addr);
 		char *proto = proto_name(uflag, dccpflag);
 
 		if ((error = connect_with_timeout(s, res->ai_addr, res->ai_addrlen, timeout)) == CONNECTION_SUCCESS)
@@ -1323,7 +1332,7 @@ local_listen(const char *host, const cha
 			err(1, NULL);
 # endif
 
-		set_common_sockopts(s, res->ai_family);
+		set_common_sockopts(s, res->ai_addr);
 
 		if (bind(s, (struct sockaddr *)res->ai_addr,
 		    res->ai_addrlen) == 0)
@@ -1855,9 +1864,10 @@ udptest(int s)
 }
 
 void
-set_common_sockopts(int s, int af)
+set_common_sockopts(int s, const struct sockaddr* sa)
 {
 	int x = 1;
+	int af = sa->sa_family;
 
 # if defined(SO_BROADCAST)
 	if (bflag) {
@@ -1868,10 +1878,17 @@ set_common_sockopts(int s, int af)
 			err(1, NULL);
 	}
 # endif
-# if defined(TCP_MD5SIG)
+# if defined(TCP_MD5SIG) && defined(TCP_MD5SIG_MAXKEYLEN)
 	if (Sflag) {
+		struct tcp_md5sig sig;
+		memset(&sig, 0, sizeof(sig));
+		memcpy(&sig.tcpm_addr, sa, sizeof(struct sockaddr_storage));
+		sig.tcpm_keylen = TCP_MD5SIG_MAXKEYLEN < strlen(Sflag_password)
+			? TCP_MD5SIG_MAXKEYLEN
+			: strlen(Sflag_password);
+		strlcpy(sig.tcpm_key, Sflag_password, sig.tcpm_keylen);
 		if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
-			&x, sizeof(x)) == -1)
+			&sig, sizeof(sig)) == -1)
 			err(1, NULL);
 	}
 # endif

debug log:

solving b2e8c72ee3 ...
found b2e8c72ee3 in https://yhetil.org/guix-patches/3dfac477-b081-49f4-86b3-2c142bb39f6b@www.fastmail.com/

applying [1/1] https://yhetil.org/guix-patches/3dfac477-b081-49f4-86b3-2c142bb39f6b@www.fastmail.com/
diff --git a/gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch b/gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch
new file mode 100644
index 0000000000..b2e8c72ee3

1:24: trailing whitespace.
 
1:30: trailing whitespace.
 
1:47: space before tab in indent.
 			break;
1:49: space before tab in indent.
 		case 'S':
1:55: space before tab in indent.
 			Sflag = 1;
Checking patch gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch...
Applied patch gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch cleanly.
warning: squelched 22 whitespace errors
warning: 27 lines add whitespace errors.

index at:
100644 b2e8c72ee3c87cb5adb70ef667526c78083f7a81	gnu/packages/patches/netcat-openbsd-set-TCP-MD5SIG-correctly-for-client-connections.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).