s3: vfs: add SMB_VFS_GET_DOS_ATTRIBUTES_SEND/RECV
[amitay/samba.git] / source3 / smbd / vfs.c
index 501eafe1c02853506c97e89a216dc7b62a7255ae..2687e3540b89e916b05d942fa606fe88db68ba4b 100644 (file)
@@ -31,6 +31,7 @@
 #include "transfer_file.h"
 #include "ntioctl.h"
 #include "lib/util/tevent_unix.h"
+#include "lib/util/tevent_ntstatus.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
@@ -3250,6 +3251,102 @@ NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle,
        return handle->fns->offload_write_recv_fn(handle, req, copied);
 }
 
+struct smb_vfs_call_get_dos_attributes_state {
+       NTSTATUS (*recv_fn)(struct tevent_req *req,
+                           struct vfs_aio_state *aio_state,
+                           uint32_t *dosmode);
+       struct vfs_aio_state aio_state;
+       uint32_t dos_attributes;
+};
+
+static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq);
+
+struct tevent_req *smb_vfs_call_get_dos_attributes_send(
+                       TALLOC_CTX *mem_ctx,
+                       const struct smb_vfs_ev_glue *evg,
+                       struct vfs_handle_struct *handle,
+                       files_struct *dir_fsp,
+                       struct smb_filename *smb_fname)
+{
+       struct tevent_req *req = NULL;
+       struct smb_vfs_call_get_dos_attributes_state *state = NULL;
+       struct tevent_req *subreq = NULL;
+       bool ok;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct smb_vfs_call_get_dos_attributes_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       VFS_FIND(get_dos_attributes_send);
+       state->recv_fn = handle->fns->get_dos_attributes_recv_fn;
+
+       ok = smb_vfs_ev_glue_push_use(evg, req);
+       if (!ok) {
+               tevent_req_error(req, EIO);
+               return tevent_req_post(req, evg->return_ev);
+       }
+
+       subreq = handle->fns->get_dos_attributes_send_fn(mem_ctx,
+                                                        evg->next_glue,
+                                                        handle,
+                                                        dir_fsp,
+                                                        smb_fname);
+       smb_vfs_ev_glue_pop_use(evg);
+
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, evg->return_ev);
+       }
+       tevent_req_set_callback(subreq,
+                               smb_vfs_call_get_dos_attributes_done,
+                               req);
+
+       return req;
+}
+
+static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req =
+               tevent_req_callback_data(subreq,
+               struct tevent_req);
+       struct smb_vfs_call_get_dos_attributes_state *state =
+               tevent_req_data(req,
+               struct smb_vfs_call_get_dos_attributes_state);
+       NTSTATUS status;
+
+       status = state->recv_fn(subreq,
+                               &state->aio_state,
+                               &state->dos_attributes);
+       TALLOC_FREE(subreq);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+
+       tevent_req_done(req);
+}
+
+NTSTATUS smb_vfs_call_get_dos_attributes_recv(
+               struct tevent_req *req,
+               struct vfs_aio_state *aio_state,
+               uint32_t *dos_attributes)
+{
+       struct smb_vfs_call_get_dos_attributes_state *state =
+               tevent_req_data(req,
+               struct smb_vfs_call_get_dos_attributes_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               tevent_req_received(req);
+               return status;
+       }
+
+       *aio_state = state->aio_state;
+       *dos_attributes = state->dos_attributes;
+       tevent_req_received(req);
+       return NT_STATUS_OK;
+}
+
 NTSTATUS smb_vfs_call_get_compression(vfs_handle_struct *handle,
                                      TALLOC_CTX *mem_ctx,
                                      struct files_struct *fsp,