s3-xattr_tdb: Fix listxattr
[tridge/samba.git] / source3 / modules / vfs_xattr_tdb.c
index 40ccf06dd951e39943872e8a775b8579017b5baa..1f3f20e4993042509bc49fc7ac9bb1b58a71ea9c 100644 (file)
@@ -23,7 +23,8 @@
 #include "librpc/gen_ndr/xattr.h"
 #include "librpc/gen_ndr/ndr_xattr.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
 #include "util_tdb.h"
 
 #undef DBGC_CLASS
@@ -106,9 +107,10 @@ static NTSTATUS xattr_tdb_load_attrs(TALLOC_CTX *mem_ctx,
        /* For backwards compatibility only store the dev/inode. */
        push_file_id_16((char *)id_buf, id);
 
-       if (db_ctx->fetch(db_ctx, mem_ctx,
-                         make_tdb_data(id_buf, sizeof(id_buf)),
-                         &data) != 0) {
+       status = dbwrap_fetch(db_ctx, mem_ctx,
+                             make_tdb_data(id_buf, sizeof(id_buf)),
+                             &data);
+       if (!NT_STATUS_IS_OK(status)) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
@@ -129,8 +131,8 @@ static struct db_record *xattr_tdb_lock_attrs(TALLOC_CTX *mem_ctx,
 
        /* For backwards compatibility only store the dev/inode. */
        push_file_id_16((char *)id_buf, id);
-       return db_ctx->fetch_locked(db_ctx, mem_ctx,
-                                   make_tdb_data(id_buf, sizeof(id_buf)));
+       return dbwrap_fetch_locked(db_ctx, mem_ctx,
+                                  make_tdb_data(id_buf, sizeof(id_buf)));
 }
 
 /*
@@ -151,7 +153,7 @@ static NTSTATUS xattr_tdb_save_attrs(struct db_record *rec,
                return status;
        }
 
-       status = rec->store(rec, data, 0);
+       status = dbwrap_record_store(rec, data, 0);
 
        TALLOC_FREE(data.dptr);
 
@@ -258,6 +260,7 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
        struct db_record *rec;
        struct tdb_xattrs *attribs;
        uint32_t i;
+       TDB_DATA data;
 
        DEBUG(10, ("xattr_tdb_setattr called for file %s, name %s\n",
                   file_id_string_tos(id), name));
@@ -270,7 +273,9 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
                return -1;
        }
 
-       status = xattr_tdb_pull_attrs(rec, &rec->value, &attribs);
+       data = dbwrap_record_get_value(rec);
+
+       status = xattr_tdb_pull_attrs(rec, &data, &attribs);
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("xattr_tdb_fetch_attrs failed: %s\n",
@@ -421,7 +426,7 @@ static ssize_t xattr_tdb_listattr(struct db_context *db_ctx,
        if (len > size) {
                TALLOC_FREE(attribs);
                errno = ERANGE;
-               return -1;
+               return len;
        }
 
        len = 0;
@@ -484,6 +489,7 @@ static int xattr_tdb_removeattr(struct db_context *db_ctx,
        struct db_record *rec;
        struct tdb_xattrs *attribs;
        uint32_t i;
+       TDB_DATA value;
 
        rec = xattr_tdb_lock_attrs(talloc_tos(), db_ctx, id);
 
@@ -493,7 +499,9 @@ static int xattr_tdb_removeattr(struct db_context *db_ctx,
                return -1;
        }
 
-       status = xattr_tdb_pull_attrs(rec, &rec->value, &attribs);
+       value = dbwrap_record_get_value(rec);
+
+       status = xattr_tdb_pull_attrs(rec, &value, &attribs);
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("xattr_tdb_fetch_attrs failed: %s\n",
@@ -519,7 +527,7 @@ static int xattr_tdb_removeattr(struct db_context *db_ctx,
        attribs->num_eas -= 1;
 
        if (attribs->num_eas == 0) {
-               rec->delete_rec(rec);
+               dbwrap_record_delete(rec);
                TALLOC_FREE(rec);
                return 0;
        }
@@ -593,7 +601,8 @@ static bool xattr_tdb_init(int snum, struct db_context **p_db)
        /* now we know dbname is not NULL */
 
        become_root();
-       db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+       db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+                    DBWRAP_LOCK_ORDER_2);
        unbecome_root();
 
        if (db == NULL) {
@@ -666,7 +675,7 @@ static int xattr_tdb_unlink(vfs_handle_struct *handle,
         */
 
        if (rec != NULL) {
-               rec->delete_rec(rec);
+               dbwrap_record_delete(rec);
                TALLOC_FREE(rec);
        }
 
@@ -707,7 +716,7 @@ static int xattr_tdb_rmdir(vfs_handle_struct *handle, const char *path)
         */
 
        if (rec != NULL) {
-               rec->delete_rec(rec);
+               dbwrap_record_delete(rec);
                TALLOC_FREE(rec);
        }
 
@@ -759,16 +768,16 @@ static int xattr_tdb_connect(vfs_handle_struct *handle, const char *service,
 }
 
 static struct vfs_fn_pointers vfs_xattr_tdb_fns = {
-       .getxattr = xattr_tdb_getxattr,
-       .fgetxattr = xattr_tdb_fgetxattr,
-       .setxattr = xattr_tdb_setxattr,
-       .fsetxattr = xattr_tdb_fsetxattr,
-       .listxattr = xattr_tdb_listxattr,
-       .flistxattr = xattr_tdb_flistxattr,
-       .removexattr = xattr_tdb_removexattr,
-       .fremovexattr = xattr_tdb_fremovexattr,
-       .unlink = xattr_tdb_unlink,
-       .rmdir = xattr_tdb_rmdir,
+       .getxattr_fn = xattr_tdb_getxattr,
+       .fgetxattr_fn = xattr_tdb_fgetxattr,
+       .setxattr_fn = xattr_tdb_setxattr,
+       .fsetxattr_fn = xattr_tdb_fsetxattr,
+       .listxattr_fn = xattr_tdb_listxattr,
+       .flistxattr_fn = xattr_tdb_flistxattr,
+       .removexattr_fn = xattr_tdb_removexattr,
+       .fremovexattr_fn = xattr_tdb_fremovexattr,
+       .unlink_fn = xattr_tdb_unlink,
+       .rmdir_fn = xattr_tdb_rmdir,
        .connect_fn = xattr_tdb_connect,
 };