vfs: add and use vfs_fake_fd()
authorRalph Boehme <slow@samba.org>
Thu, 23 Jul 2020 05:32:11 +0000 (07:32 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 2 Oct 2020 19:39:43 +0000 (19:39 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_fruit.c
source3/modules/vfs_streams_xattr.c
source3/smbd/proto.h
source3/smbd/vfs.c

index 51251b7b86beae25b87be6ddc4fc0d8113e2838d..451b07d686b0d6fb15cb00593e3ad89f82a6486f 100644 (file)
@@ -1312,27 +1312,6 @@ static int fruit_connect(vfs_handle_struct *handle,
        return rc;
 }
 
-static int fruit_fake_fd(void)
-{
-       int pipe_fds[2];
-       int fd;
-       int ret;
-
-       /*
-        * Return a valid fd, but ensure any attempt to use it returns
-        * an error (EPIPE). Once we get a write on the handle, we open
-        * the real fd.
-        */
-       ret = pipe(pipe_fds);
-       if (ret != 0) {
-               return -1;
-       }
-       fd = pipe_fds[0];
-       close(pipe_fds[1]);
-
-       return fd;
-}
-
 static int fruit_open_meta_stream(vfs_handle_struct *handle,
                                  const struct files_struct *dirfsp,
                                  const struct smb_filename *smb_fname,
@@ -1369,7 +1348,7 @@ static int fruit_open_meta_stream(vfs_handle_struct *handle,
                return -1;
        }
 
-       fd = fruit_fake_fd();
+       fd = vfs_fake_fd();
        if (fd == -1) {
                VFS_REMOVE_FSP_EXTENSION(handle, fsp);
                return -1;
@@ -1409,7 +1388,7 @@ static int fruit_open_meta_netatalk(vfs_handle_struct *handle,
                return -1;
        }
 
-       fd = fruit_fake_fd();
+       fd = vfs_fake_fd();
        if (fd == -1) {
                return -1;
        }
index 2e4105fec496ee76d79e8135f694fb20f28b6f08..13ea46b080663fda952544b292606331bde7f1e7 100644 (file)
@@ -371,7 +371,6 @@ static int streams_xattr_openat(struct vfs_handle_struct *handle,
        struct stream_io *sio = NULL;
        struct ea_struct ea;
        char *xattr_name = NULL;
-       int pipe_fds[2];
        int fakefd = -1;
        bool set_empty_xattr = false;
        int ret;
@@ -456,18 +455,7 @@ static int streams_xattr_openat(struct vfs_handle_struct *handle,
                }
        }
 
-       /*
-        * Return a valid fd, but ensure any attempt to use it returns an error
-        * (EPIPE).
-        */
-       ret = pipe(pipe_fds);
-       if (ret != 0) {
-               goto fail;
-       }
-
-       close(pipe_fds[1]);
-       pipe_fds[1] = -1;
-       fakefd = pipe_fds[0];
+       fakefd = vfs_fake_fd();
 
         sio = VFS_ADD_FSP_EXTENSION(handle, fsp, struct stream_io, NULL);
         if (sio == NULL) {
index 72ee8e82fe57f59510659a83ecf75b84fd670a45..a001c4834f47298bf39074142acdfd7b31fb6124 100644 (file)
@@ -1304,6 +1304,7 @@ NTSTATUS vfs_streaminfo(connection_struct *conn,
                        unsigned int *num_streams,
                        struct stream_struct **streams);
 void init_smb_file_time(struct smb_file_time *ft);
+int vfs_fake_fd(void);
 
 /* The following definitions come from smbd/avahi_register.c */
 
index 2194e09ab1656d4c4b9dd70458ebc9c18baba369..9ba104903f8c4849b65b392a66f0d50a47a8cfc5 100644 (file)
@@ -1571,6 +1571,24 @@ NTSTATUS vfs_streaminfo(connection_struct *conn,
                        streams);
 }
 
+int vfs_fake_fd(void)
+{
+       int pipe_fds[2];
+       int ret;
+
+       /*
+        * Return a valid fd, but ensure any attempt to use
+        * it returns an error (EPIPE).
+        */
+       ret = pipe(pipe_fds);
+       if (ret != 0) {
+               return -1;
+       }
+
+       close(pipe_fds[1]);
+       return pipe_fds[0];
+}
+
 /*
   generate a file_id from a stat structure
  */