s3:modules: make virusfilter_io_connect_path() more portable
authorStefan Metzmacher <metze@samba.org>
Wed, 21 Mar 2018 06:25:11 +0000 (07:25 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 3 Apr 2018 14:41:09 +0000 (16:41 +0200)
We have existing utility functions to prepare a socket.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13343

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Björn Jacke <bjacke@samba.org>
source3/modules/vfs_virusfilter_utils.c

index 90ae427023be53c2805439f08b3806c598b35e73..f56fc6ed5d8bc04d26d5752c55f6644e0feca923 100644 (file)
@@ -147,8 +147,9 @@ bool virusfilter_io_connect_path(
 {
        struct sockaddr_un addr;
        NTSTATUS status;
-       int socket, bes_result, flags, ret;
+       int socket, ret;
        size_t len;
+       bool ok;
 
        ZERO_STRUCT(addr);
        addr.sun_family = AF_UNIX;
@@ -168,23 +169,23 @@ bool virusfilter_io_connect_path(
        }
 
        /* We must not block */
-       flags = fcntl(socket, F_GETFL);
-       if (flags <= 0) {
-               /* Handle error by ignoring */;
-               flags = 0;
-               DBG_WARNING("Could not get flags on socket (%s).\n",
-                           strerror(errno));
-       }
-       flags |= SOCK_NONBLOCK;
-       ret = fcntl(socket, F_SETFL, flags);
+       ret = set_blocking(socket, false);
        if (ret == -1) {
-               /* Handle error by ignoring for now */
-               DBG_WARNING("Could not set flags on socket: %s.\n",
-                           strerror(errno));
+               close(socket);
+               io_h->stream = NULL;
+               return false;
        }
 
-       bes_result = tstream_bsd_existing_socket(io_h, socket, &io_h->stream);
-       if (bes_result < 0) {
+       ok = smb_set_close_on_exec(socket);
+       if (!ok) {
+               close(socket);
+               io_h->stream = NULL;
+               return false;
+       }
+
+       ret = tstream_bsd_existing_socket(io_h, socket, &io_h->stream);
+       if (ret == -1) {
+               close(socket);
                DBG_ERR("Could not convert socket to tstream: %s.\n",
                        strerror(errno));
                io_h->stream = NULL;