]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-socket: create socket directory if possible 2445/head
authorVictor Julien <victor@inliniac.net>
Thu, 1 Dec 2016 14:19:35 +0000 (15:19 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Dec 2016 14:19:35 +0000 (15:19 +0100)
Create the socket directory in the default case.

Since we're doing stat+mkdir indicate to Coverity not to worry about
the toctou case.

src/unix-manager.c

index 07f99268c072f3495cb90c5cac71a16df21c3fe9..cc7af7eb6c4c01a3a7b557fc59f52077fcc7ae4c 100644 (file)
@@ -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 */