From: Victor Julien Date: Thu, 1 Dec 2016 14:19:35 +0000 (+0100) Subject: unix-socket: create socket directory if possible X-Git-Tag: suricata-3.2.1~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2445%2Fhead;p=thirdparty%2Fsuricata.git 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. --- diff --git a/src/unix-manager.c b/src/unix-manager.c index 07f99268c0..cc7af7eb6c 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -143,18 +143,27 @@ int UnixNew(UnixCommand * this) struct stat stat_buf; /* coverity[toctou] */ if (stat(SOCKET_PATH, &stat_buf) != 0) { - SCLogWarning(SC_ERR_INITIALIZATION, - "Unix socket: problem with requested directory in %s: %s", - SOCKET_TARGET, strerror(errno)); - return 0; + int ret; + /* coverity[toctou] */ + ret = mkdir(SOCKET_PATH, S_IRWXU|S_IXGRP|S_IRGRP); + 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); if (unlikely(sockettarget == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name"); return 0; } - - } /* Remove socket file */