s3: Fix the clustering build
[mat/samba.git] / source4 / lib / socket / socket_unix.c
index 3feb1bf234f6e331fb100c98a52dbb3b3ae470f2..2909ecca8fde32ba8095d284ba3ead62fda151b1 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -26,6 +25,7 @@
 #include "system/network.h"
 #include "system/filesys.h"
 
+_PUBLIC_ const struct socket_ops *socket_unixdom_ops(enum socket_type type);
 
 
 /*
@@ -33,7 +33,7 @@
 */
 static NTSTATUS unixdom_error(int ernum)
 {
-       return map_nt_error_from_unix(ernum);
+       return map_nt_error_from_unix_common(ernum);
 }
 
 static NTSTATUS unixdom_init(struct socket_context *sock)
@@ -53,12 +53,14 @@ static NTSTATUS unixdom_init(struct socket_context *sock)
 
        sock->fd = socket(PF_UNIX, type, 0);
        if (sock->fd == -1) {
-               return map_nt_error_from_unix(errno);
+               return map_nt_error_from_unix_common(errno);
        }
        sock->private_data = NULL;
 
        sock->backend_name = "unix";
 
+       smb_set_close_on_exec(sock->fd);
+
        return NT_STATUS_OK;
 }
 
@@ -76,16 +78,16 @@ static NTSTATUS unixdom_connect_complete(struct socket_context *sock, uint32_t f
           for non-blocking connect */
        ret = getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &error, &len);
        if (ret == -1) {
-               return map_nt_error_from_unix(errno);
+               return map_nt_error_from_unix_common(errno);
        }
        if (error != 0) {
-               return map_nt_error_from_unix(error);
+               return map_nt_error_from_unix_common(error);
        }
 
        if (!(flags & SOCKET_FLAG_BLOCK)) {
-               ret = set_blocking(sock->fd, False);
+               ret = set_blocking(sock->fd, false);
                if (ret == -1) {
-                       return map_nt_error_from_unix(errno);
+                       return map_nt_error_from_unix_common(errno);
                }
        }
 
@@ -162,7 +164,7 @@ static NTSTATUS unixdom_listen(struct socket_context *sock,
        }
 
        if (!(flags & SOCKET_FLAG_BLOCK)) {
-               ret = set_blocking(sock->fd, False);
+               ret = set_blocking(sock->fd, false);
                if (ret == -1) {
                        return unixdom_error(errno);
                }
@@ -191,13 +193,15 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
        }
 
        if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
-               int ret = set_blocking(new_fd, False);
+               int ret = set_blocking(new_fd, false);
                if (ret == -1) {
                        close(new_fd);
-                       return map_nt_error_from_unix(errno);
+                       return map_nt_error_from_unix_common(errno);
                }
        }
 
+       smb_set_close_on_exec(new_fd);
+
        (*new_sock) = talloc(NULL, struct socket_context);
        if (!(*new_sock)) {
                close(new_fd);
@@ -219,23 +223,13 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
 }
 
 static NTSTATUS unixdom_recv(struct socket_context *sock, void *buf, 
-                            size_t wantlen, size_t *nread, uint32_t flags)
+                            size_t wantlen, size_t *nread)
 {
        ssize_t gotlen;
-       int flgs = 0;
-
-       /* TODO: we need to map all flags here */
-       if (flags & SOCKET_FLAG_PEEK) {
-               flgs |= MSG_PEEK;
-       }
-
-       if (flags & SOCKET_FLAG_BLOCK) {
-               flgs |= MSG_WAITALL;
-       }
 
        *nread = 0;
 
-       gotlen = recv(sock->fd, buf, wantlen, flgs);
+       gotlen = recv(sock->fd, buf, wantlen, 0);
        if (gotlen == 0) {
                return NT_STATUS_END_OF_FILE;
        } else if (gotlen == -1) {
@@ -248,14 +242,13 @@ static NTSTATUS unixdom_recv(struct socket_context *sock, void *buf,
 }
 
 static NTSTATUS unixdom_send(struct socket_context *sock,
-                            const DATA_BLOB *blob, size_t *sendlen, uint32_t flags)
+                            const DATA_BLOB *blob, size_t *sendlen)
 {
        ssize_t len;
-       int flgs = 0;
 
        *sendlen = 0;
 
-       len = send(sock->fd, blob->data, blob->length, flgs);
+       len = send(sock->fd, blob->data, blob->length, 0);
        if (len == -1) {
                return unixdom_error(errno);
        }       
@@ -267,15 +260,14 @@ static NTSTATUS unixdom_send(struct socket_context *sock,
 
 
 static NTSTATUS unixdom_sendto(struct socket_context *sock, 
-                              const DATA_BLOB *blob, size_t *sendlen, uint32_t flags,
+                              const DATA_BLOB *blob, size_t *sendlen, 
                               const struct socket_address *dest)
 {
        ssize_t len;
-       int flgs = 0;
        *sendlen = 0;
                
        if (dest->sockaddr) {
-               len = sendto(sock->fd, blob->data, blob->length, flgs
+               len = sendto(sock->fd, blob->data, blob->length, 0
                             dest->sockaddr, dest->sockaddrlen);
        } else {
                struct sockaddr_un srv_addr;
@@ -288,11 +280,11 @@ static NTSTATUS unixdom_sendto(struct socket_context *sock,
                srv_addr.sun_family = AF_UNIX;
                strncpy(srv_addr.sun_path, dest->addr, sizeof(srv_addr.sun_path));
                
-               len = sendto(sock->fd, blob->data, blob->length, flgs
+               len = sendto(sock->fd, blob->data, blob->length, 0
                             (struct sockaddr *)&srv_addr, sizeof(srv_addr));
        }
        if (len == -1) {
-               return map_nt_error_from_unix(errno);
+               return map_nt_error_from_unix_common(errno);
        }       
 
        *sendlen = len;
@@ -402,7 +394,7 @@ static NTSTATUS unixdom_pending(struct socket_context *sock, size_t *npending)
                *npending = value;
                return NT_STATUS_OK;
        }
-       return map_nt_error_from_unix(errno);
+       return map_nt_error_from_unix_common(errno);
 }
 
 static const struct socket_ops unixdom_ops = {
@@ -427,7 +419,7 @@ static const struct socket_ops unixdom_ops = {
        .fn_get_fd              = unixdom_get_fd
 };
 
-const struct socket_ops *socket_unixdom_ops(enum socket_type type)
+_PUBLIC_ const struct socket_ops *socket_unixdom_ops(enum socket_type type)
 {
        return &unixdom_ops;
 }