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:
@@ -560,8 +560,8 @@ int ncat_connect(void)
|
||||
if (srcaddr.storage.ss_family != AF_UNIX) {
|
||||
char *tmp_name = NULL;
|
||||
/* If no source socket was specified, we have to create temporary one. */
|
||||
if ((tmp_name = tempfile(NULL, "ncat.")) == NULL)
|
||||
bye("Failed to create name for temporary DGRAM source Unix domain socket (mkstemp).");
|
||||
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));
|
||||
|
||||
@@ -267,5 +267,3 @@ extern void set_lf_mode(void);
|
||||
|
||||
extern int setenv_portable(const char *name, const char *value);
|
||||
extern void setup_environment(struct fdinfo *fdinfo);
|
||||
|
||||
extern char *tempfile(const char *dir, const char *prefix);
|
||||
|
||||
@@ -436,36 +436,3 @@ int setenv_portable(const char *name, const char *value)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,3 @@ int ssl_load_default_ca_certs(SSL_CTX *ctx)
|
||||
return rc == 1 ? 0 : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *tempfile(const char *dir, const char *prefix)
|
||||
{
|
||||
return tempnam(dir, prefix);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@
|
||||
|
||||
|
||||
static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
const char *path;
|
||||
int rc;
|
||||
int one = 1;
|
||||
|
||||
@@ -79,15 +78,13 @@ static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
socket_strerror(err), err);
|
||||
}
|
||||
|
||||
path = get_localaddr_string(iod);
|
||||
unlink(path);
|
||||
nsock_log_info(ms, "Binding to %s (IOD #%li)", path, iod->id);
|
||||
nsock_log_info(ms, "Binding to %s (IOD #%li)", get_localaddr_string(iod), iod->id);
|
||||
rc = bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen);
|
||||
if (rc == -1) {
|
||||
int err = socket_errno();
|
||||
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user