s3:registry: use regsubkey_ctr_get_seqnum() in reg_backend_db.c
[amitay/samba.git] / source3 / modules / vfs_xattr_tdb.c
index 171022b01b631332872cd487c894e4d3631fdc57..4e37ed6477bd0a1eed7171c5a45df52b1491b189 100644 (file)
@@ -48,7 +48,7 @@ static NTSTATUS xattr_tdb_pull_attrs(TALLOC_CTX *mem_ctx,
        blob = data_blob_const(data->dptr, data->dsize);
 
        ndr_err = ndr_pull_struct_blob(
-               &blob, result, result,
+               &blob, result, NULL, result,
                (ndr_pull_flags_fn_t)ndr_pull_tdb_xattrs);
 
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
@@ -74,7 +74,7 @@ static NTSTATUS xattr_tdb_push_attrs(TALLOC_CTX *mem_ctx,
        enum ndr_err_code ndr_err;
 
        ndr_err = ndr_push_struct_blob(
-               &blob, mem_ctx, attribs,
+               &blob, mem_ctx, NULL, attribs,
                (ndr_push_flags_fn_t)ndr_push_tdb_xattrs);
 
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
@@ -100,6 +100,7 @@ static NTSTATUS xattr_tdb_load_attrs(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        TDB_DATA data;
 
+       /* For backwards compatibility only store the dev/inode. */
        push_file_id_16((char *)id_buf, id);
 
        if (db_ctx->fetch(db_ctx, mem_ctx,
@@ -122,6 +123,8 @@ static struct db_record *xattr_tdb_lock_attrs(TALLOC_CTX *mem_ctx,
                                              const struct file_id *id)
 {
        uint8 id_buf[16];
+
+       /* 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)));
@@ -177,25 +180,25 @@ static ssize_t xattr_tdb_getattr(struct db_context *db_ctx,
                return -1;
        }
 
-       for (i=0; i<attribs->num_xattrs; i++) {
-               if (strcmp(attribs->xattrs[i].name, name) == 0) {
+       for (i=0; i<attribs->num_eas; i++) {
+               if (strcmp(attribs->eas[i].name, name) == 0) {
                        break;
                }
        }
 
-       if (i == attribs->num_xattrs) {
+       if (i == attribs->num_eas) {
                errno = ENOATTR;
                goto fail;
        }
 
-       if (attribs->xattrs[i].value.length > size) {
+       if (attribs->eas[i].value.length > size) {
                errno = ERANGE;
                goto fail;
        }
 
-       memcpy(value, attribs->xattrs[i].value.data,
-              attribs->xattrs[i].value.length);
-       result = attribs->xattrs[i].value.length;
+       memcpy(value, attribs->eas[i].value.data,
+              attribs->eas[i].value.length);
+       result = attribs->eas[i].value.length;
 
  fail:
        TALLOC_FREE(attribs);
@@ -216,7 +219,7 @@ static ssize_t xattr_tdb_getxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_getattr(db, &id, name, value, size);
 }
@@ -235,7 +238,7 @@ static ssize_t xattr_tdb_fgetxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_getattr(db, &id, name, value, size);
 }
@@ -273,8 +276,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
                return -1;
        }
 
-       for (i=0; i<attribs->num_xattrs; i++) {
-               if (strcmp(attribs->xattrs[i].name, name) == 0) {
+       for (i=0; i<attribs->num_eas; i++) {
+               if (strcmp(attribs->eas[i].name, name) == 0) {
                        if (flags & XATTR_CREATE) {
                                TALLOC_FREE(rec);
                                errno = EEXIST;
@@ -284,8 +287,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
                }
        }
 
-       if (i == attribs->num_xattrs) {
-               struct tdb_xattr *tmp;
+       if (i == attribs->num_eas) {
+               struct xattr_EA *tmp;
 
                if (flags & XATTR_REPLACE) {
                        TALLOC_FREE(rec);
@@ -294,8 +297,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
                }
 
                tmp = TALLOC_REALLOC_ARRAY(
-                       attribs, attribs->xattrs, struct tdb_xattr,
-                       attribs->num_xattrs + 1);
+                       attribs, attribs->eas, struct xattr_EA,
+                       attribs->num_eas+ 1);
 
                if (tmp == NULL) {
                        DEBUG(0, ("TALLOC_REALLOC_ARRAY failed\n"));
@@ -304,13 +307,13 @@ static int xattr_tdb_setattr(struct db_context *db_ctx,
                        return -1;
                }
 
-               attribs->xattrs = tmp;
-               attribs->num_xattrs += 1;
+               attribs->eas = tmp;
+               attribs->num_eas += 1;
        }
 
-       attribs->xattrs[i].name = name;
-       attribs->xattrs[i].value.data = CONST_DISCARD(uint8 *, value);
-       attribs->xattrs[i].value.length = size;
+       attribs->eas[i].name = name;
+       attribs->eas[i].value.data = CONST_DISCARD(uint8 *, value);
+       attribs->eas[i].value.length = size;
 
        status = xattr_tdb_save_attrs(rec, attribs);
 
@@ -338,7 +341,7 @@ static int xattr_tdb_setxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_setattr(db, &id, name, value, size, flags);
 }
@@ -358,7 +361,7 @@ static int xattr_tdb_fsetxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_setattr(db, &id, name, value, size, flags);
 }
@@ -386,15 +389,15 @@ static ssize_t xattr_tdb_listattr(struct db_context *db_ctx,
        }
 
        DEBUG(10, ("xattr_tdb_listattr: Found %d xattrs\n",
-                  attribs->num_xattrs));
+                  attribs->num_eas));
 
-       for (i=0; i<attribs->num_xattrs; i++) {
+       for (i=0; i<attribs->num_eas; i++) {
                size_t tmp;
 
                DEBUG(10, ("xattr_tdb_listattr: xattrs[i].name: %s\n",
-                          attribs->xattrs[i].name));
+                          attribs->eas[i].name));
 
-               tmp = strlen(attribs->xattrs[i].name);
+               tmp = strlen(attribs->eas[i].name);
 
                /*
                 * Try to protect against overflow
@@ -420,10 +423,10 @@ static ssize_t xattr_tdb_listattr(struct db_context *db_ctx,
 
        len = 0;
 
-       for (i=0; i<attribs->num_xattrs; i++) {
-               strlcpy(list+len, attribs->xattrs[i].name,
+       for (i=0; i<attribs->num_eas; i++) {
+               strlcpy(list+len, attribs->eas[i].name,
                        size-len);
-               len += (strlen(attribs->xattrs[i].name) + 1);
+               len += (strlen(attribs->eas[i].name) + 1);
        }
 
        TALLOC_FREE(attribs);
@@ -443,7 +446,7 @@ static ssize_t xattr_tdb_listxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_listattr(db, &id, list, size);
 }
@@ -462,7 +465,7 @@ static ssize_t xattr_tdb_flistxattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_listattr(db, &id, list, size);
 }
@@ -496,23 +499,23 @@ static int xattr_tdb_removeattr(struct db_context *db_ctx,
                return -1;
        }
 
-       for (i=0; i<attribs->num_xattrs; i++) {
-               if (strcmp(attribs->xattrs[i].name, name) == 0) {
+       for (i=0; i<attribs->num_eas; i++) {
+               if (strcmp(attribs->eas[i].name, name) == 0) {
                        break;
                }
        }
 
-       if (i == attribs->num_xattrs) {
+       if (i == attribs->num_eas) {
                TALLOC_FREE(rec);
                errno = ENOATTR;
                return -1;
        }
 
-       attribs->xattrs[i] =
-               attribs->xattrs[attribs->num_xattrs-1];
-       attribs->num_xattrs -= 1;
+       attribs->eas[i] =
+               attribs->eas[attribs->num_eas-1];
+       attribs->num_eas -= 1;
 
-       if (attribs->num_xattrs == 0) {
+       if (attribs->num_eas == 0) {
                rec->delete_rec(rec);
                TALLOC_FREE(rec);
                return 0;
@@ -543,7 +546,7 @@ static int xattr_tdb_removexattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_removeattr(db, &id, name);
 }
@@ -561,7 +564,7 @@ static int xattr_tdb_fremovexattr(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        return xattr_tdb_removeattr(db, &id, name);
 }
@@ -574,25 +577,34 @@ static bool xattr_tdb_init(int snum, struct db_context **p_db)
 {
        struct db_context *db;
        const char *dbname;
+       char *def_dbname;
 
-       dbname = lp_parm_const_string(snum, "xattr", "tdb",
-                                     lock_path("xattr.tdb"));
-
-       if (dbname == NULL) {
+       def_dbname = state_path("xattr.tdb");
+       if (def_dbname == NULL) {
                errno = ENOSYS;
                return false;
        }
 
+       dbname = lp_parm_const_string(snum, "xattr_tdb", "file", def_dbname);
+
+       /* now we know dbname is not NULL */
+
        become_root();
        db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
        unbecome_root();
 
        if (db == NULL) {
+#if defined(ENOTSUP)
                errno = ENOTSUP;
+#else
+               errno = ENOSYS;
+#endif
+               TALLOC_FREE(def_dbname);
                return false;
        }
 
        *p_db = db;
+       TALLOC_FREE(def_dbname);
        return true;
 }
 
@@ -619,7 +631,7 @@ static int xattr_tdb_unlink(vfs_handle_struct *handle, const char *path)
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        rec = xattr_tdb_lock_attrs(talloc_tos(), db, &id);
 
@@ -658,7 +670,7 @@ static int xattr_tdb_rmdir(vfs_handle_struct *handle, const char *path)
                return -1;
        }
 
-       id = SMB_VFS_FILE_ID_CREATE(handle->conn, sbuf.st_dev, sbuf.st_ino);
+       id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
 
        rec = xattr_tdb_lock_attrs(talloc_tos(), db, &id);