vfs_catia: Fix return value in lock functions
[bbaumbach/samba-autobuild/.git] / source3 / modules / vfs_tsmsm.c
index db9df25a9069ee2d3be41ff78ca3b320bcec2dde..85a9bfdfa9c0bb4a0d7082debe3d646e34b6c864 100644 (file)
@@ -266,6 +266,33 @@ done:
        return offline;
 }
 
+static NTSTATUS tsmsm_get_dos_attributes(struct vfs_handle_struct *handle,
+                                        struct smb_filename *fname,
+                                        uint32_t *dosmode)
+{
+       bool offline;
+
+       offline = tsmsm_is_offline(handle, fname, &fname->st);
+       if (offline) {
+               *dosmode |= FILE_ATTRIBUTE_OFFLINE;
+       }
+
+       return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, fname, dosmode);
+}
+
+static NTSTATUS tsmsm_fget_dos_attributes(struct vfs_handle_struct *handle,
+                                         files_struct *fsp,
+                                         uint32_t *dosmode)
+{
+       bool offline;
+
+       offline = tsmsm_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
+       if (offline) {
+               *dosmode |= FILE_ATTRIBUTE_OFFLINE;
+       }
+
+       return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
+}
 
 static bool tsmsm_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
 {
@@ -289,7 +316,8 @@ static bool tsmsm_aio_force(struct vfs_handle_struct *handle, struct files_struc
 struct tsmsm_pread_state {
        struct files_struct *fsp;
        ssize_t ret;
-       int err;
+       bool was_offline;
+       struct vfs_aio_state vfs_aio_state;
 };
 
 static void tsmsm_pread_done(struct tevent_req *subreq);
@@ -308,6 +336,7 @@ static struct tevent_req *tsmsm_pread_send(struct vfs_handle_struct *handle,
                return NULL;
        }
        state->fsp = fsp;
+       state->was_offline = tsmsm_aio_force(handle, fsp);
        subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
                                         n, offset);
        if (tevent_req_nomem(subreq, req)) {
@@ -324,33 +353,35 @@ static void tsmsm_pread_done(struct tevent_req *subreq)
        struct tsmsm_pread_state *state = tevent_req_data(
                req, struct tsmsm_pread_state);
 
-       state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
+       state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
        TALLOC_FREE(subreq);
        tevent_req_done(req);
 }
 
-static ssize_t tsmsm_pread_recv(struct tevent_req *req, int *err)
+static ssize_t tsmsm_pread_recv(struct tevent_req *req,
+                               struct vfs_aio_state *vfs_aio_state)
 {
        struct tsmsm_pread_state *state = tevent_req_data(
                req, struct tsmsm_pread_state);
 
-       if (tevent_req_is_unix_error(req, err)) {
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
-       if (state->ret >= 0) {
+       if (state->ret >= 0 && state->was_offline) {
                struct files_struct *fsp = state->fsp;
                notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
                             FILE_NOTIFY_CHANGE_ATTRIBUTES,
                             fsp->fsp_name->base_name);
        }
-       *err = state->err;
+       *vfs_aio_state = state->vfs_aio_state;
        return state->ret;
 }
 
 struct tsmsm_pwrite_state {
        struct files_struct *fsp;
        ssize_t ret;
-       int err;
+       bool was_offline;
+       struct vfs_aio_state vfs_aio_state;
 };
 
 static void tsmsm_pwrite_done(struct tevent_req *subreq);
@@ -370,6 +401,7 @@ static struct tevent_req *tsmsm_pwrite_send(struct vfs_handle_struct *handle,
                return NULL;
        }
        state->fsp = fsp;
+       state->was_offline = tsmsm_aio_force(handle, fsp);
        subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
                                          n, offset);
        if (tevent_req_nomem(subreq, req)) {
@@ -386,26 +418,27 @@ static void tsmsm_pwrite_done(struct tevent_req *subreq)
        struct tsmsm_pwrite_state *state = tevent_req_data(
                req, struct tsmsm_pwrite_state);
 
-       state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
+       state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
        TALLOC_FREE(subreq);
        tevent_req_done(req);
 }
 
-static ssize_t tsmsm_pwrite_recv(struct tevent_req *req, int *err)
+static ssize_t tsmsm_pwrite_recv(struct tevent_req *req,
+                                struct vfs_aio_state *vfs_aio_state)
 {
        struct tsmsm_pwrite_state *state = tevent_req_data(
                req, struct tsmsm_pwrite_state);
 
-       if (tevent_req_is_unix_error(req, err)) {
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
-       if (state->ret >= 0) {
+       if (state->ret >= 0 && state->was_offline) {
                struct files_struct *fsp = state->fsp;
                notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
                             FILE_NOTIFY_CHANGE_ATTRIBUTES,
                             fsp->fsp_name->base_name);
        }
-       *err = state->err;
+       *vfs_aio_state = state->vfs_aio_state;
        return state->ret;
 }
 
@@ -461,8 +494,8 @@ static ssize_t tsmsm_pwrite(struct vfs_handle_struct *handle, struct files_struc
        return result;
 }
 
-static int tsmsm_set_offline(struct vfs_handle_struct *handle, 
-                             const struct smb_filename *fname)
+static NTSTATUS tsmsm_set_offline(struct vfs_handle_struct *handle,
+                                 const struct smb_filename *fname)
 {
        struct tsmsm_struct *tsmd = (struct tsmsm_struct *) handle->data;
        int result = 0;
@@ -473,27 +506,83 @@ static int tsmsm_set_offline(struct vfs_handle_struct *handle,
        if (tsmd->hsmscript == NULL) {
                /* no script enabled */
                DEBUG(1, ("tsmsm_set_offline: No 'tsmsm:hsm script' configured\n"));
-               return 0;
+               return NT_STATUS_OK;
        }
 
         status = get_full_smb_filename(talloc_tos(), fname, &path);
         if (!NT_STATUS_IS_OK(status)) {
-                errno = map_errno_from_nt_status(status);
-                return false;
+               return status;
         }
 
        /* Now, call the script */
        command = talloc_asprintf(tsmd, "%s offline \"%s\"", tsmd->hsmscript, path);
        if(!command) {
                DEBUG(1, ("tsmsm_set_offline: can't allocate memory to run hsm script"));
-               return -1;
+               return NT_STATUS_NO_MEMORY;
        }
        DEBUG(10, ("tsmsm_set_offline: Running [%s]\n", command));
-       if((result = smbrun(command, NULL)) != 0) {
+       result = smbrun(command, NULL, NULL);
+       if(result != 0) {
                DEBUG(1,("tsmsm_set_offline: Running [%s] returned %d\n", command, result));
+               TALLOC_FREE(command);
+               return NT_STATUS_INTERNAL_ERROR;
        }
        TALLOC_FREE(command);
-       return result;
+       return NT_STATUS_OK;
+}
+
+static NTSTATUS tsmsm_set_dos_attributes(struct vfs_handle_struct *handle,
+                                        const struct smb_filename *smb_fname,
+                                        uint32_t dosmode)
+{
+       NTSTATUS status;
+       uint32_t old_dosmode;
+       struct smb_filename *fname = NULL;
+
+       /* dos_mode() doesn't like const smb_fname */
+       fname = cp_smb_filename(talloc_tos(), smb_fname);
+       if (fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       old_dosmode = dos_mode(handle->conn, fname);
+       TALLOC_FREE(fname);
+
+       status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle, smb_fname, dosmode);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (!(old_dosmode & FILE_ATTRIBUTE_OFFLINE) &&
+           (dosmode & FILE_ATTRIBUTE_OFFLINE))
+       {
+               return NT_STATUS_OK;
+       }
+
+       return tsmsm_set_offline(handle, smb_fname);
+}
+
+static NTSTATUS tsmsm_fset_dos_attributes(struct vfs_handle_struct *handle,
+                                         struct files_struct *fsp,
+                                         uint32_t dosmode)
+{
+       NTSTATUS status;
+       uint32_t old_dosmode;
+
+       old_dosmode = dos_mode(handle->conn, fsp->fsp_name);
+
+       status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (!(old_dosmode & FILE_ATTRIBUTE_OFFLINE) &&
+           (dosmode & FILE_ATTRIBUTE_OFFLINE))
+       {
+               return NT_STATUS_OK;
+       }
+
+       return tsmsm_set_offline(handle, fsp->fsp_name);
 }
 
 static uint32_t tsmsm_fs_capabilities(struct vfs_handle_struct *handle,
@@ -513,12 +602,16 @@ static struct vfs_fn_pointers tsmsm_fns = {
        .pwrite_send_fn = tsmsm_pwrite_send,
        .pwrite_recv_fn = tsmsm_pwrite_recv,
        .sendfile_fn = tsmsm_sendfile,
-       .is_offline_fn = tsmsm_is_offline,
-       .set_offline_fn = tsmsm_set_offline,
+       .set_dos_attributes_fn = tsmsm_set_dos_attributes,
+       .fset_dos_attributes_fn = tsmsm_fset_dos_attributes,
+       .get_dos_attributes_fn = tsmsm_get_dos_attributes,
+       .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
+       .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
+       .fget_dos_attributes_fn = tsmsm_fget_dos_attributes,
 };
 
-NTSTATUS vfs_tsmsm_init(void);
-NTSTATUS vfs_tsmsm_init(void)
+static_decl_vfs;
+NTSTATUS vfs_tsmsm_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
                                "tsmsm", &tsmsm_fns);