1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-20 14:39:02 +00:00

Revert r32397, r32398, r32399 (tempnam to mkstemp).

I had intended the unlink to appy only to unix domain sockets, but it
was being called for every kind of local address.

http://seclists.org/nmap-dev/2013/q3/647
This commit is contained in:
david
2013-09-27 15:30:18 +00:00
parent db6f6ea069
commit d05d8acd93
5 changed files with 4 additions and 47 deletions

View File

@@ -560,8 +560,8 @@ int ncat_connect(void)
if (srcaddr.storage.ss_family != AF_UNIX) { if (srcaddr.storage.ss_family != AF_UNIX) {
char *tmp_name = NULL; char *tmp_name = NULL;
/* If no source socket was specified, we have to create temporary one. */ /* If no source socket was specified, we have to create temporary one. */
if ((tmp_name = tempfile(NULL, "ncat.")) == NULL) if ((tmp_name = tempnam(NULL, "ncat.")) == NULL)
bye("Failed to create name for temporary DGRAM source Unix domain socket (mkstemp)."); bye("Failed to create name for temporary DGRAM source Unix domain socket (tempnam).");
srcaddr.un.sun_family = AF_UNIX; srcaddr.un.sun_family = AF_UNIX;
strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path)); strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path));

View File

@@ -267,5 +267,3 @@ extern void set_lf_mode(void);
extern int setenv_portable(const char *name, const char *value); extern int setenv_portable(const char *name, const char *value);
extern void setup_environment(struct fdinfo *fdinfo); extern void setup_environment(struct fdinfo *fdinfo);
extern char *tempfile(const char *dir, const char *prefix);

View File

@@ -436,36 +436,3 @@ int setenv_portable(const char *name, const char *value)
{ {
return setenv(name, value, 1); return setenv(name, value, 1);
} }
/* Create a name temporary file. This function aims to emulate tempnam, with the
exception that it creates the file like mkstemp does.
The directories tried are, in order,
* $TMPDIR
* dir
* /tmp
*/
char *tempfile(const char *dir, const char *prefix)
{
const char *SUFFIX = "XXXXXXXXXX";
const char *tmpdir;
char *namebuf;
size_t namelen;
int n;
tmpdir = NULL;
if ((getuid() == geteuid()) && (getgid() == getegid()))
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = dir;
if (tmpdir == NULL)
tmpdir = "/tmp";
namelen = strlen(tmpdir) + 1 + strlen(prefix) + strlen(SUFFIX);
namebuf = malloc(namelen + 1);
n = Snprintf(namebuf, namelen + 1, "%s/%s%s", tmpdir, prefix, SUFFIX);
ncat_assert(n >= 0 && n <= namelen);
n = mkstemp(namebuf);
if (n == -1)
return NULL;
return namebuf;
}

View File

@@ -178,8 +178,3 @@ int ssl_load_default_ca_certs(SSL_CTX *ctx)
return rc == 1 ? 0 : -1; return rc == 1 ? 0 : -1;
} }
#endif #endif
char *tempfile(const char *dir, const char *prefix)
{
return tempnam(dir, prefix);
}

View File

@@ -67,7 +67,6 @@
static int mksock_bind_addr(mspool *ms, msiod *iod) { static int mksock_bind_addr(mspool *ms, msiod *iod) {
const char *path;
int rc; int rc;
int one = 1; int one = 1;
@@ -79,15 +78,13 @@ static int mksock_bind_addr(mspool *ms, msiod *iod) {
socket_strerror(err), err); socket_strerror(err), err);
} }
path = get_localaddr_string(iod); nsock_log_info(ms, "Binding to %s (IOD #%li)", get_localaddr_string(iod), iod->id);
unlink(path);
nsock_log_info(ms, "Binding to %s (IOD #%li)", path, iod->id);
rc = bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen); rc = bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen);
if (rc == -1) { if (rc == -1) {
int err = socket_errno(); int err = socket_errno();
nsock_log_error(ms, "Bind to %s failed (IOD #%li): %s (%d)", nsock_log_error(ms, "Bind to %s failed (IOD #%li): %s (%d)",
path, iod->id, get_localaddr_string(iod), iod->id,
socket_strerror(err), err); socket_strerror(err), err);
} }
return 0; return 0;