summaryrefslogtreecommitdiff
path: root/source3/modules
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-04-16 17:14:06 +1000
committerAndrew Bartlett <abartlet@samba.org>2012-04-18 12:05:00 +1000
commit492942a66ad89172135512cd433b50c13726f777 (patch)
treebd609f41480fb71ca51eb9add04a5d386eba1735 /source3/modules
parent351c78fc670d5e26ebc2deea7ef930a94b116697 (diff)
downloadsamba-492942a66ad89172135512cd433b50c13726f777.tar.gz
samba-492942a66ad89172135512cd433b50c13726f777.tar.bz2
samba-492942a66ad89172135512cd433b50c13726f777.zip
s3-xattr_tdb: Be nice to xattr_tdb_getxattr callers, return the full blob
In this case, the blob is already in memory, so it is easier to return the full blob to the caller, and let the caller decide if some interface restriction stops the full blob from being passed all the way up the stack. This allows us to quickly write a python wrapper for this xattr storage mechanism. Andrew Bartlett
Diffstat (limited to 'source3/modules')
-rw-r--r--source3/modules/vfs_xattr_tdb.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c
index f5e5440e16..5c105b5194 100644
--- a/source3/modules/vfs_xattr_tdb.c
+++ b/source3/modules/vfs_xattr_tdb.c
@@ -34,16 +34,35 @@ static ssize_t xattr_tdb_getxattr(struct vfs_handle_struct *handle,
SMB_STRUCT_STAT sbuf;
struct file_id id;
struct db_context *db;
+ ssize_t xattr_size;
+ DATA_BLOB blob;
+ TALLOC_CTX *frame = talloc_stackframe();
+ if (!frame) {
+ errno = ENOMEM;
+ return -1;
+ }
SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
if (vfs_stat_smb_fname(handle->conn, path, &sbuf) == -1) {
+ TALLOC_FREE(frame);
return -1;
}
id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
- return xattr_tdb_getattr(db, &id, name, value, size);
+ xattr_size = xattr_tdb_getattr(db, frame, &id, name, &blob);
+ if (xattr_size < 0) {
+ TALLOC_FREE(frame);
+ return -1;
+ }
+ if (blob.length > size) {
+ TALLOC_FREE(frame);
+ errno = ERANGE;
+ return -1;
+ }
+ memcpy(value, blob.data, size);
+ return xattr_size;
}
static ssize_t xattr_tdb_fgetxattr(struct vfs_handle_struct *handle,
@@ -53,16 +72,36 @@ static ssize_t xattr_tdb_fgetxattr(struct vfs_handle_struct *handle,
SMB_STRUCT_STAT sbuf;
struct file_id id;
struct db_context *db;
+ ssize_t xattr_size;
+ DATA_BLOB blob;
+ TALLOC_CTX *frame = talloc_stackframe();
+ if (!frame) {
+ errno = ENOMEM;
+ return -1;
+ }
SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) {
+ TALLOC_FREE(frame);
return -1;
}
id = SMB_VFS_FILE_ID_CREATE(handle->conn, &sbuf);
- return xattr_tdb_getattr(db, &id, name, value, size);
+ xattr_size = xattr_tdb_getattr(db, frame, &id, name, &blob);
+ if (xattr_size < 0) {
+ TALLOC_FREE(frame);
+ return -1;
+ }
+ if (blob.length > size) {
+ TALLOC_FREE(frame);
+ errno = ERANGE;
+ return -1;
+ }
+ memcpy(value, blob.data, size);
+ TALLOC_FREE(frame);
+ return xattr_size;
}
static int xattr_tdb_setxattr(struct vfs_handle_struct *handle,