audit_logging: Remove debug log header and JSON Authentication: prefix
[amitay/samba.git] / source3 / modules / vfs_streams_xattr.c
index 5355dd8ca443af87375d7046dc3972ab6f5343ad..9f4bc13b034772289d03e0e891f1e0cc88ed9574 100644 (file)
@@ -190,16 +190,21 @@ static bool streams_xattr_recheck(struct stream_io *sio)
        TALLOC_FREE(sio->base);
        sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
                                        xattr_name);
-        sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
-                                  sio->fsp->fsp_name->base_name);
-       sio->fsp_name_ptr = sio->fsp->fsp_name;
-
+       if (sio->xattr_name == NULL) {
+               DBG_DEBUG("sio->xattr_name==NULL\n");
+               return false;
+       }
        TALLOC_FREE(xattr_name);
 
-       if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
+       sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
+                                 sio->fsp->fsp_name->base_name);
+       if (sio->base == NULL) {
+               DBG_DEBUG("sio->base==NULL\n");
                return false;
        }
 
+       sio->fsp_name_ptr = sio->fsp->fsp_name;
+
        return true;
 }
 
@@ -407,6 +412,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,
        char *xattr_name = NULL;
        int pipe_fds[2];
        int fakefd = -1;
+       bool set_empty_xattr = false;
        int ret;
 
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
@@ -440,39 +446,37 @@ static int streams_xattr_open(vfs_handle_struct *handle,
                goto fail;
        }
 
-       /*
-        * 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];
-
        status = get_ea_value(talloc_tos(), handle->conn, NULL,
                              smb_fname, xattr_name, &ea);
 
        DEBUG(10, ("get_ea_value returned %s\n", nt_errstr(status)));
 
-       if (!NT_STATUS_IS_OK(status)
-           && !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-               /*
-                * The base file is not there. This is an error even if we got
-                * O_CREAT, the higher levels should have created the base
-                * file for us.
-                */
-               DEBUG(10, ("streams_xattr_open: base file %s not around, "
-                          "returning ENOENT\n", smb_fname->base_name));
-               errno = ENOENT;
-               goto fail;
+       if (!NT_STATUS_IS_OK(status)) {
+               if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+                       /*
+                        * The base file is not there. This is an error even if
+                        * we got O_CREAT, the higher levels should have created
+                        * the base file for us.
+                        */
+                       DBG_DEBUG("streams_xattr_open: base file %s not around, "
+                                 "returning ENOENT\n", smb_fname->base_name);
+                       errno = ENOENT;
+                       goto fail;
+               }
+
+               if (!(flags & O_CREAT)) {
+                       errno = ENOATTR;
+                       goto fail;
+               }
+
+               set_empty_xattr = true;
        }
 
-       if ((!NT_STATUS_IS_OK(status) && (flags & O_CREAT)) ||
-           (flags & O_TRUNC)) {
+       if (flags & O_TRUNC) {
+               set_empty_xattr = true;
+       }
+
+       if (set_empty_xattr) {
                /*
                 * The attribute does not exist or needs to be truncated
                 */
@@ -495,6 +499,19 @@ static int streams_xattr_open(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];
+
         sio = VFS_ADD_FSP_EXTENSION(handle, fsp, struct stream_io, NULL);
         if (sio == NULL) {
                 errno = ENOMEM;
@@ -503,6 +520,11 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 
         sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
                                        xattr_name);
+       if (sio->xattr_name == NULL) {
+               errno = ENOMEM;
+               goto fail;
+       }
+
        /*
         * so->base needs to be a copy of fsp->fsp_name->base_name,
         * making it identical to streams_xattr_recheck(). If the
@@ -512,15 +534,15 @@ static int streams_xattr_open(vfs_handle_struct *handle,
         */
         sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
                                  fsp->fsp_name->base_name);
-       sio->fsp_name_ptr = fsp->fsp_name;
-       sio->handle = handle;
-       sio->fsp = fsp;
-
-       if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
+       if (sio->base == NULL) {
                errno = ENOMEM;
                goto fail;
        }
 
+       sio->fsp_name_ptr = fsp->fsp_name;
+       sio->handle = handle;
+       sio->fsp = fsp;
+
        return fakefd;
 
  fail:
@@ -1390,20 +1412,6 @@ static int streams_xattr_fsetxattr(struct vfs_handle_struct *handle,
        return -1;
 }
 
-static int streams_xattr_fchmod_acl(vfs_handle_struct *handle,
-                                   files_struct *fsp,
-                                   mode_t mode)
-{
-       struct stream_io *sio =
-               (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
-
-       if (sio == NULL) {
-               return SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
-       }
-
-       return 0;
-}
-
 static SMB_ACL_T streams_xattr_sys_acl_get_fd(vfs_handle_struct *handle,
                                              files_struct *fsp,
                                              TALLOC_CTX *mem_ctx)
@@ -1677,8 +1685,6 @@ static struct vfs_fn_pointers vfs_streams_xattr_fns = {
        .fremovexattr_fn = streams_xattr_fremovexattr,
        .fsetxattr_fn = streams_xattr_fsetxattr,
 
-       .fchmod_acl_fn = streams_xattr_fchmod_acl,
-
        .sys_acl_get_fd_fn = streams_xattr_sys_acl_get_fd,
        .sys_acl_blob_get_fd_fn = streams_xattr_sys_acl_blob_get_fd,
        .sys_acl_set_fd_fn = streams_xattr_sys_acl_set_fd,