1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-04 05:39:01 +00:00

Disable automatic generation of datagram Unix domain source socket.

This code was not always properly cleaning up automatically generated
sockets; for example in the case of "Connection refused". It would
delete sockets even if you gave one manually with --source; it's not
clear that's the right behavior.
This commit is contained in:
david
2012-11-12 20:44:45 +00:00
parent e017de82bb
commit cc4eb9f381
3 changed files with 6 additions and 40 deletions

View File

@@ -767,11 +767,8 @@
Both stream and datagram domain sockets are supported. Use
<option>-U</option> on its own for stream sockets, or
combine it with <option>--udp</option> for datagram sockets.
Datagram sockets require a source socket to connect from. By
default, a source socket with a random filename will be created as
needed, and deleted when the program ends. Use the
<option>--source</option> with a path to use a source socket with a
specific name.
Datagram sockets require the use of the <option>--source</option>
option to specify a source socket to connect from.
</para>
</refsect1>

View File

@@ -538,23 +538,11 @@ int ncat_connect(void)
/* For DGRAM UNIX socket we have to use source socket */
if (o.af == AF_UNIX && o.udp)
{
if (srcaddr.storage.ss_family == AF_UNIX) {
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
} else {
char *tmp_name = NULL;
/* If no source socket was specified, we have to create temporary one. */
if ((tmp_name = tempnam(NULL, "ncat.")) == NULL)
bye("Failed to create name for temporary DGRAM source Unix domain socket (tempnam).");
srcaddr.un.sun_family = AF_UNIX;
strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path));
free (tmp_name);
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
if (srcaddr.storage.ss_family != AF_UNIX) {
bye("A source socket filename (--source) is required when using\n"
"Unix domain sockets in --udp mode.");
}
if (o.verbose)
loguser("[%s] used as source DGRAM Unix domain socket.\n", srcaddr.un.sun_path);
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
}
else
#endif
@@ -707,11 +695,6 @@ int ncat_connect(void)
nsi_get_read_count(cs.sock_nsi), time);
}
#if HAVE_SYS_UN_H
if (o.af == AF_UNIX && o.udp)
unlink(srcaddr.un.sun_path);
#endif
nsp_delete(mypool);
return rc == NSOCK_LOOP_ERROR ? 1 : 0;

View File

@@ -548,20 +548,6 @@ sub {
kill_children;
unlink($UNIXSOCK);
($s_pid, $s_out, $s_in) = ncat("-l", "-U", "--udp", $UNIXSOCK);
test "Server UNIX socket listen on $UNIXSOCK --udp (DGRAM)",
sub {
my $resp;
unlink($UNIXSOCK);
my ($c_pid, $c_out, $c_in) = ncat("-U", "--udp", $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 {