unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob be771b01771a1d24ab693d6b770b0ecd6d4d796c 3649 bytes (raw)
name: gnu/packages/patches/netcat-openbsd-misc-failures-and-features.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
From: Aron Xu <aron@debian.org>
Date: Mon, 13 Feb 2012 19:06:52 +0800
Subject: misc failures and features

---
 Makefile |    3 ++-
 nc.1     |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 netcat.c |   14 ++++++++++++--
 3 files changed, 65 insertions(+), 3 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,8 @@
 PROG=	nc
 SRCS=	netcat.c atomicio.c socks.c
 
-LIBS=  `pkg-config --libs libbsd` -lresolv
+PKG_CONFIG ?= pkg-config
+LIBS=  `$(PKG_CONFIG) --libs libbsd` -lresolv
 OBJS=  $(SRCS:.c=.o)
 CFLAGS=  -g -O2
 LDFLAGS=  -Wl,--no-add-needed
--- a/nc.1
+++ b/nc.1
@@ -365,6 +365,54 @@ and which side is being used as a
 The connection may be terminated using an
 .Dv EOF
 .Pq Sq ^D .
+.Pp
+There is no
+.Fl c
+or
+.Fl e
+option in this netcat, but you still can execute a command after connection
+being established by redirecting file descriptors. Be cautious here because
+opening a port and let anyone connected execute arbitrary command on your
+site is DANGEROUS. If you really need to do this, here is an example:
+.Pp
+On
+.Sq server
+side:
+.Pp
+.Dl $ rm -f /tmp/f; mkfifo /tmp/f
+.Dl $ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f
+.Pp
+On
+.Sq client
+side:
+.Pp
+.Dl $ nc host.example.com 1234
+.Dl $ (shell prompt from host.example.com)
+.Pp
+By doing this, you create a fifo at /tmp/f and make nc listen at port 1234
+of address 127.0.0.1 on
+.Sq server
+side, when a
+.Sq client
+establishes a connection successfully to that port, /bin/sh gets executed
+on
+.Sq server
+side and the shell prompt is given to
+.Sq client
+side.
+.Pp
+When connection is terminated,
+.Nm
+quits as well. Use
+.Fl k
+if you want it keep listening, but if the command quits this option won't
+restart it or keep
+.Nm
+running. Also don't forget to remove the file descriptor once you don't need
+it anymore:
+.Pp
+.Dl $ rm -f /tmp/f
+.Pp
 .Sh DATA TRANSFER
 The example in the previous section can be expanded to build a
 basic data transfer model.
@@ -517,6 +565,9 @@ Original implementation by
 .br
 Rewritten with IPv6 support by
 .An Eric Jackson Aq Mt ericj@monkey.org .
+.br
+Modified for Debian port by Aron Xu
+.Aq aron@debian.org .
 .Sh CAVEATS
 UDP port scans using the
 .Fl uz
--- a/netcat.c
+++ b/netcat.c
@@ -98,6 +98,7 @@
 #include <netdb.h>
 #include <poll.h>
 #include <signal.h>
+#include <stddef.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -246,7 +247,10 @@ main(int argc, char *argv[])
 	struct addrinfo hints;
 	struct servent *sv;
 	socklen_t len;
-	struct sockaddr_storage cliaddr;
+	union {
+		struct sockaddr_storage storage;
+		struct sockaddr_un forunix;
+	} cliaddr;
 	char *proxy = NULL, *proxyport = NULL;
 	const char *errstr;
 	struct addrinfo proxyhints;
@@ -945,6 +949,8 @@ unix_bind(char *path, int flags)
 	    0)) < 0)
 		return -1;
 
+	unlink(path);
+
 	memset(&s_un, 0, sizeof(struct sockaddr_un));
 	s_un.sun_family = AF_UNIX;
 
@@ -1070,8 +1076,10 @@ unix_connect(char *path)
 		if ((s = unix_bind(unix_dg_tmp_socket, SOCK_CLOEXEC)) < 0)
 			return -1;
 	} else {
-		if ((s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0)
+		if ((s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0) {
+			errx(1, "create unix socket failed");
 			return -1;
+		}
 	}
 
 	memset(&s_un, 0, sizeof(struct sockaddr_un));
@@ -1081,10 +1089,12 @@ unix_connect(char *path)
 	    sizeof(s_un.sun_path)) {
 		close(s);
 		errno = ENAMETOOLONG;
+		warn("unix connect abandoned");
 		return -1;
 	}
 	if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) {
 		save_errno = errno;
+		warn("unix connect failed");
 		close(s);
 		errno = save_errno;
 		return -1;

debug log:

solving be771b0177 ...
found be771b0177 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-misc-failures-and-features.patch b/gnu/packages/patches/netcat-openbsd-misc-failures-and-features.patch
new file mode 100644
index 0000000000..be771b0177

1:22: trailing whitespace.
 
1:107: space before tab in indent.
 	struct addrinfo hints;
1:108: space before tab in indent.
 	struct servent *sv;
1:109: space before tab in indent.
 	socklen_t len;
1:115: space before tab in indent.
 	char *proxy = NULL, *proxyport = NULL;
Checking patch gnu/packages/patches/netcat-openbsd-misc-failures-and-features.patch...
Applied patch gnu/packages/patches/netcat-openbsd-misc-failures-and-features.patch cleanly.
warning: squelched 25 whitespace errors
warning: 30 lines add whitespace errors.

index at:
100644 be771b01771a1d24ab693d6b770b0ecd6d4d796c	gnu/packages/patches/netcat-openbsd-misc-failures-and-features.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).