pyldb: avoid segfault when adding an element with no name
[sfrench/samba-autobuild/.git] / examples / VFS / skel_opaque.c
index f88e9258c733da8955fb60def4b615899b3edad6..6510ef30d6f5087183f48ca370b6ebaf3e4073c9 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "../source3/include/includes.h"
+#include "lib/util/tevent_unix.h"
 #include "lib/util/tevent_ntstatus.h"
 
 /* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE 
@@ -706,6 +707,51 @@ static NTSTATUS skel_get_dos_attributes(struct vfs_handle_struct *handle,
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
+struct skel_get_dos_attributes_state {
+       struct vfs_aio_state aio_state;
+       uint32_t dosmode;
+};
+
+static struct tevent_req *skel_get_dos_attributes_send(
+                       TALLOC_CTX *mem_ctx,
+                       struct tevent_context *ev,
+                       struct vfs_handle_struct *handle,
+                       files_struct *dir_fsp,
+                       struct smb_filename *smb_fname)
+{
+       struct tevent_req *req = NULL;
+       struct skel_get_dos_attributes_state *state = NULL;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct skel_get_dos_attributes_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
+       return tevent_req_post(req, ev);
+}
+
+static NTSTATUS skel_get_dos_attributes_recv(struct tevent_req *req,
+                                            struct vfs_aio_state *aio_state,
+                                            uint32_t *dosmode)
+{
+       struct skel_get_dos_attributes_state *state =
+               tevent_req_data(req,
+               struct skel_get_dos_attributes_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               tevent_req_received(req);
+               return status;
+       }
+
+       *aio_state = state->aio_state;
+       *dosmode = state->dosmode;
+       tevent_req_received(req);
+       return NT_STATUS_OK;
+}
+
 static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle,
                                struct files_struct *fsp,
                                uint32_t *dosmode)
@@ -818,6 +864,58 @@ static ssize_t skel_getxattr(vfs_handle_struct *handle,
        return -1;
 }
 
+struct skel_getxattrat_state {
+       struct vfs_aio_state aio_state;
+       ssize_t xattr_size;
+       uint8_t *xattr_value;
+};
+
+static struct tevent_req *skel_getxattrat_send(
+                       TALLOC_CTX *mem_ctx,
+                       struct tevent_context *ev,
+                       struct vfs_handle_struct *handle,
+                       files_struct *dir_fsp,
+                       const struct smb_filename *smb_fname,
+                       const char *xattr_name,
+                       size_t alloc_hint)
+{
+       struct tevent_req *req = NULL;
+       struct skel_getxattrat_state *state = NULL;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct skel_getxattrat_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       tevent_req_error(req, ENOSYS);
+       return tevent_req_post(req, ev);
+}
+
+static ssize_t skel_getxattrat_recv(struct tevent_req *req,
+                                   struct vfs_aio_state *aio_state,
+                                   TALLOC_CTX *mem_ctx,
+                                   uint8_t **xattr_value)
+{
+       struct skel_getxattrat_state *state = tevent_req_data(
+               req, struct skel_getxattrat_state);
+       ssize_t xattr_size;
+
+       if (tevent_req_is_unix_error(req, &aio_state->error)) {
+               tevent_req_received(req);
+               return -1;
+       }
+
+       *aio_state = state->aio_state;
+       xattr_size = state->xattr_size;
+       if (xattr_value != NULL) {
+               *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
+       }
+
+       tevent_req_received(req);
+       return xattr_size;
+}
+
 static ssize_t skel_fgetxattr(vfs_handle_struct *handle,
                              struct files_struct *fsp, const char *name,
                              void *value, size_t size)
@@ -856,7 +954,6 @@ static int skel_fremovexattr(vfs_handle_struct *handle,
 {
        errno = ENOSYS;
        return -1;
-       return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
 }
 
 static int skel_setxattr(vfs_handle_struct *handle,
@@ -924,7 +1021,7 @@ static NTSTATUS skel_durable_reconnect(struct vfs_handle_struct *handle,
 
 /* VFS operations structure */
 
-struct vfs_fn_pointers skel_opaque_fns = {
+static struct vfs_fn_pointers skel_opaque_fns = {
        /* Disk operations */
 
        .connect_fn = skel_connect,
@@ -1016,6 +1113,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
 
        /* DOS attributes. */
        .get_dos_attributes_fn = skel_get_dos_attributes,
+       .get_dos_attributes_send_fn = skel_get_dos_attributes_send,
+       .get_dos_attributes_recv_fn = skel_get_dos_attributes_recv,
        .fget_dos_attributes_fn = skel_fget_dos_attributes,
        .set_dos_attributes_fn = skel_set_dos_attributes,
        .fset_dos_attributes_fn = skel_fset_dos_attributes,
@@ -1038,6 +1137,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
 
        /* EA operations. */
        .getxattr_fn = skel_getxattr,
+       .getxattrat_send_fn = skel_getxattrat_send,
+       .getxattrat_recv_fn = skel_getxattrat_recv,
        .fgetxattr_fn = skel_fgetxattr,
        .listxattr_fn = skel_listxattr,
        .flistxattr_fn = skel_flistxattr,
@@ -1058,6 +1159,13 @@ struct vfs_fn_pointers skel_opaque_fns = {
 static_decl_vfs;
 NTSTATUS vfs_skel_opaque_init(TALLOC_CTX *ctx)
 {
+       /*
+        * smb_vfs_assert_all_fns() makes sure every
+        * call is implemented.
+        *
+        * An opaque module requires this!
+        */
+       smb_vfs_assert_all_fns(&skel_opaque_fns, "skel_opaque");
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_opaque",
                                &skel_opaque_fns);
 }