call shutdown also in listen mode
This commit is contained in:
parent
35db512439
commit
71ee2cb26d
43
nmap-6.01-shutdown.patch
Normal file
43
nmap-6.01-shutdown.patch
Normal file
@ -0,0 +1,43 @@
|
||||
diff -up nmap-6.01/ncat/ncat_core.c.shutdown nmap-6.01/ncat/ncat_core.c
|
||||
diff -up nmap-6.01/ncat/ncat_core.h.shutdown nmap-6.01/ncat/ncat_core.h
|
||||
diff -up nmap-6.01/ncat/ncat_listen.c.shutdown nmap-6.01/ncat/ncat_listen.c
|
||||
--- nmap-6.01/ncat/ncat_listen.c.shutdown 2012-03-01 07:53:35.000000000 +0100
|
||||
+++ nmap-6.01/ncat/ncat_listen.c 2012-11-22 18:14:05.991381724 +0100
|
||||
@@ -317,10 +317,13 @@ static int ncat_listen_stream(int proto)
|
||||
}else {
|
||||
/* Read from stdin and write to all clients. */
|
||||
rc = read_stdin();
|
||||
- if (rc == 0 && o.sendonly)
|
||||
- /* There will be nothing more to send. If we're not
|
||||
- receiving anything, we can quit here. */
|
||||
- return 0;
|
||||
+ if (rc == 0) {
|
||||
+ if (o.sendonly)
|
||||
+ /* There will be nothing more to send. If we're not
|
||||
+ receiving anything, we can quit here. */
|
||||
+ return 0;
|
||||
+ shutdown_sockets(SHUT_WR);
|
||||
+ }
|
||||
if (rc < 0)
|
||||
return 1;
|
||||
}
|
||||
@@ -495,6 +498,19 @@ int read_stdin(void)
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
+void shutdown_sockets(int how)
|
||||
+{
|
||||
+ struct fdinfo *fdn;
|
||||
+ int i;
|
||||
+ for (i = 0; i <= broadcast_fdlist.fdmax; i++) {
|
||||
+ if (!FD_ISSET(i, &master_broadcastfds))
|
||||
+ continue;
|
||||
+
|
||||
+ fdn = get_fdinfo(&broadcast_fdlist, i);
|
||||
+ shutdown(fdn->fd, how);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* Read from a client socket and write to stdout. Return the number of bytes
|
||||
read from the socket, or -1 on error. */
|
||||
int read_socket(int recv_fd)
|
145
nmap-6.01-shutdown_test.patch
Normal file
145
nmap-6.01-shutdown_test.patch
Normal file
@ -0,0 +1,145 @@
|
||||
diff -up nmap-6.01/ncat/test/ncat-test.pl.shutdown_test nmap-6.01/ncat/test/ncat-test.pl
|
||||
--- nmap-6.01/ncat/test/ncat-test.pl.shutdown_test 2011-12-19 20:12:48.000000000 +0100
|
||||
+++ nmap-6.01/ncat/test/ncat-test.pl 2012-11-27 14:18:16.000000000 +0100
|
||||
@@ -21,6 +21,8 @@ my $HOST = "localhost";
|
||||
my $IPV6_ADDR = "::1";
|
||||
my $PORT = 40000;
|
||||
my $PROXY_PORT = 40001;
|
||||
+my $UNIXSOCK = "ncat.unixsock";
|
||||
+my $UNIXSOCK_TMP = "ncat.unixsock_tmp";
|
||||
|
||||
my $BUFSIZ = 1024;
|
||||
|
||||
@@ -531,6 +533,22 @@ sub {
|
||||
};
|
||||
kill_children;
|
||||
|
||||
+# Test UNIX domain sockets listening
|
||||
+($s_pid, $s_out, $s_in) = ncat("-l", "-U", $UNIXSOCK);
|
||||
+test "Server UNIX socket listen on $UNIXSOCK (STREAM)",
|
||||
+sub {
|
||||
+ my $resp;
|
||||
+
|
||||
+ unlink($UNIXSOCK);
|
||||
+ my ($c_pid, $c_out, $c_in) = ncat("-U", $UNIXSOCK);
|
||||
+ syswrite($c_in, "abc\n");
|
||||
+ $resp = timeout_read($s_out);
|
||||
+ $resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\" from client";
|
||||
+};
|
||||
+kill_children;
|
||||
+unlink($UNIXSOCK);
|
||||
+
|
||||
+
|
||||
server_client_test "Connect success exit code",
|
||||
[], ["--send-only"], sub {
|
||||
my ($pid, $code);
|
||||
@@ -655,16 +673,37 @@ sub {
|
||||
};
|
||||
kill_children;
|
||||
|
||||
+server_client_test_all "Messages are logged to output file",
|
||||
+["--output", "server.log"], ["--output", "client.log"], sub {
|
||||
+
|
||||
+ syswrite($c_in, "abc\n");
|
||||
+ sleep 1;
|
||||
+ syswrite($s_in, "def\n");
|
||||
+ sleep 1;
|
||||
+ close($c_in);
|
||||
+ open(FH, "server.log");
|
||||
+ my $contents = join("", <FH>);
|
||||
+ close(FH);
|
||||
+ $contents eq "abc\ndef\n" or die "Server logged " . d($contents);
|
||||
+ open(FH, "client.log");
|
||||
+ $contents = join("", <FH>);
|
||||
+ close(FH);
|
||||
+ $contents eq "abc\ndef\n" or die "Client logged " . d($contents);
|
||||
+};
|
||||
+unlink "server.log";
|
||||
+unlink "client.log";
|
||||
+kill_children;
|
||||
+
|
||||
server_client_test_tcp_sctp_ssl "Debug messages go to stderr",
|
||||
["-vvv"], ["-vvv"], sub {
|
||||
my $resp;
|
||||
|
||||
syswrite($c_in, "abc\n");
|
||||
- close($c_in);
|
||||
$resp = timeout_read($s_out) or die "Read timeout";
|
||||
$resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
||||
syswrite($s_in, "abc\n");
|
||||
close($s_in);
|
||||
+ close($c_in);
|
||||
$resp = timeout_read($c_out) or die "Read timeout";
|
||||
$resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
||||
};
|
||||
@@ -690,6 +729,36 @@ server_client_test_tcp_sctp_ssl "Server
|
||||
};
|
||||
kill_children;
|
||||
|
||||
+server_client_test "Client shutdown()s connection when reading EOF",
|
||||
+[], [], sub {
|
||||
+ my $resp;
|
||||
+
|
||||
+ syswrite($c_in, "abc\n");
|
||||
+ $resp = timeout_read($s_out) or die "Read timeout";
|
||||
+ $resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
||||
+
|
||||
+ close($c_in);
|
||||
+
|
||||
+ $resp = timeout_read($s_out);
|
||||
+ !defined($resp) or die "Server didn't get EOF (got \"$resp\")";
|
||||
+};
|
||||
+kill_children;
|
||||
+
|
||||
+server_client_test "Server shutdown()s connection when reading EOF",
|
||||
+[], [], sub {
|
||||
+ my $resp;
|
||||
+
|
||||
+ syswrite($s_in, "abc\n");
|
||||
+ $resp = timeout_read($c_out) or die "Read timeout";
|
||||
+ $resp eq "abc\n" or die "Client got \"$resp\", not \"abc\\n\"";
|
||||
+
|
||||
+ close($s_in);
|
||||
+
|
||||
+ $resp = timeout_read($c_out);
|
||||
+ !defined($resp) or die "Client didn't get EOF (got \"$resp\")";
|
||||
+};
|
||||
+kill_children;
|
||||
+
|
||||
# Tests to check that server defaults to non-persistent without --keep-open.
|
||||
|
||||
# Server immediately quits after the first connection closed without --keep-open
|
||||
@@ -1195,6 +1264,33 @@ sub {
|
||||
};
|
||||
kill_children;
|
||||
|
||||
+# Test connecting to UNIX datagram socket with -s
|
||||
+test "Connect to UNIX datagram socket with -s",
|
||||
+sub {
|
||||
+ my ($pid, $code);
|
||||
+ local $SIG{CHLD} = sub { };
|
||||
+ local *SOCK;
|
||||
+ my $buff;
|
||||
+
|
||||
+ unlink($UNIXSOCK);
|
||||
+ unlink($UNIXSOCK_TMP);
|
||||
+
|
||||
+ socket(SOCK, AF_UNIX, SOCK_DGRAM, 0) or die;
|
||||
+ bind(SOCK, sockaddr_un($UNIXSOCK)) or die;
|
||||
+
|
||||
+ my ($c_pid, $c_out, $c_in) = ncat("-U", "--udp", "-s", $UNIXSOCK_TMP, $UNIXSOCK);
|
||||
+ syswrite($c_in, "abc\n");
|
||||
+ close($c_in);
|
||||
+
|
||||
+ my $peeraddr = recv(SOCK, $buff, 4, 0) or die;
|
||||
+ my ($path) = sockaddr_un($peeraddr);
|
||||
+ $path eq $UNIXSOCK_TMP or die "Client connected to prosy with source socket path $path, not $UNIXSOCK_TMP";
|
||||
+};
|
||||
+kill_children;
|
||||
+unlink($UNIXSOCK);
|
||||
+unlink($UNIXSOCK_TMP);
|
||||
+
|
||||
+
|
||||
# HTTP proxy tests.
|
||||
|
||||
sub http_request {
|
@ -4,7 +4,7 @@ Name: nmap
|
||||
Epoch: 2
|
||||
Version: 6.01
|
||||
#global prerelease TEST5
|
||||
Release: 7%{?dist}
|
||||
Release: 8%{?dist}
|
||||
# nmap is GPLv2
|
||||
# zenmap is GPLv2 and LGPLv2+ (zenmap/higwidgets) and GPLv2+ (zenmap/radialnet)
|
||||
# libdnet-stripped is BSD (advertising clause rescinded by the Univ. of California in 1999) with some parts as Public Domain (crc32)
|
||||
@ -36,6 +36,8 @@ Patch5: ncat_reg_stdin.diff
|
||||
|
||||
# shutdown socket on EOF, sent upstream
|
||||
Patch6: nmap-6.01-r29743.patch
|
||||
Patch7: nmap-6.01-shutdown.patch
|
||||
Patch8: nmap-6.01-shutdown_test.patch
|
||||
|
||||
URL: http://nmap.org/
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
@ -89,6 +91,8 @@ uses.
|
||||
%patch4 -p1 -b .bz637403
|
||||
%patch5 -p1 -b .ncat_reg_stdin
|
||||
%patch6 -p1 -b .r29743
|
||||
%patch7 -p1 -b .shutdown
|
||||
%patch8 -p1 -b .shutdown_test
|
||||
|
||||
#be sure we're not using tarballed copies of some libraries
|
||||
rm -rf liblua libpcap libpcre macosx mswin32
|
||||
@ -216,6 +220,9 @@ rm -rf $RPM_BUILD_ROOT
|
||||
%{_mandir}/man1/xnmap.1.gz
|
||||
|
||||
%changelog
|
||||
* Thu Nov 29 2012 Michal Hlavinka <mhlavink@redhat.com> - 2:6.01-8
|
||||
- call shutdown also in listen mode
|
||||
|
||||
* Tue Oct 02 2012 Petr Šabata <contyk@redhat.com> - 2:6.01-7
|
||||
- Move the socat dependency to the ncat subpackage (#858733)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user