unix-socket: create socket directory if possible

Create the socket directory in the default case.

Since we're doing stat+mkdir indicate to Coverity not to worry about
the toctou case.
pull/2445/head
Victor Julien 10 years ago
parent 3f741e450b
commit c5e550b10d

@ -143,18 +143,27 @@ int UnixNew(UnixCommand * this)
struct stat stat_buf; struct stat stat_buf;
/* coverity[toctou] */ /* coverity[toctou] */
if (stat(SOCKET_PATH, &stat_buf) != 0) { if (stat(SOCKET_PATH, &stat_buf) != 0) {
SCLogWarning(SC_ERR_INITIALIZATION, int ret;
"Unix socket: problem with requested directory in %s: %s", /* coverity[toctou] */
SOCKET_TARGET, strerror(errno)); ret = mkdir(SOCKET_PATH, S_IRWXU|S_IXGRP|S_IRGRP);
return 0; if (ret != 0) {
int err = errno;
if (err != EEXIST) {
SCLogError(SC_ERR_INITIALIZATION,
"Cannot create socket directory %s: %s",
SOCKET_PATH, strerror(err));
return 0;
}
} else {
SCLogInfo("Created socket directory %s",
SOCKET_PATH);
}
} }
sockettarget = SCStrdup(SOCKET_TARGET); sockettarget = SCStrdup(SOCKET_TARGET);
if (unlikely(sockettarget == NULL)) { if (unlikely(sockettarget == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name"); SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name");
return 0; return 0;
} }
} }
/* Remove socket file */ /* Remove socket file */

Loading…
Cancel
Save