summaryrefslogtreecommitdiff
path: root/source4/ntvfs/posix/python/pyxattr_tdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/ntvfs/posix/python/pyxattr_tdb.c')
-rw-r--r--source4/ntvfs/posix/python/pyxattr_tdb.c72
1 files changed, 52 insertions, 20 deletions
diff --git a/source4/ntvfs/posix/python/pyxattr_tdb.c b/source4/ntvfs/posix/python/pyxattr_tdb.c
index d1be879514..18ac091787 100644
--- a/source4/ntvfs/posix/python/pyxattr_tdb.c
+++ b/source4/ntvfs/posix/python/pyxattr_tdb.c
@@ -28,6 +28,10 @@
#include "ntvfs/posix/posix_eadb.h"
#include "libcli/util/pyerrors.h"
#include "param/pyparam.h"
+#include "source3/lib/dbwrap/dbwrap.h"
+#include "source3/lib/dbwrap/dbwrap_open.h"
+#include "source3/lib/dbwrap/dbwrap_tdb.h"
+#include "source3/lib/xattr_tdb.h"
void initxattr_tdb(void);
@@ -41,9 +45,11 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
char *filename, *attribute, *tdbname;
DATA_BLOB blob;
int blobsize;
- NTSTATUS status;
+ int ret;
TALLOC_CTX *mem_ctx;
- struct tdb_wrap *eadb;
+ struct db_context *eadb = NULL;
+ struct file_id id;
+ struct stat sbuf;
if (!PyArg_ParseTuple(args, "ssss#", &tdbname, &filename, &attribute,
&blob.data, &blobsize))
@@ -51,19 +57,29 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
blob.length = blobsize;
mem_ctx = talloc_new(NULL);
- eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
- py_default_loadparm_context(mem_ctx));
+ eadb = db_open_tdb(mem_ctx, py_default_loadparm_context(mem_ctx), tdbname, 50000,
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_2);
if (eadb == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
talloc_free(mem_ctx);
return NULL;
}
- status = push_xattr_blob_tdb_raw(eadb, attribute, filename, -1,
- &blob);
- if (!NT_STATUS_IS_OK(status)) {
- PyErr_SetNTSTATUS(status);
+
+ ret = stat(filename, &sbuf);
+ if (ret < 0) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ ZERO_STRUCT(id);
+ id.devid = sbuf.st_dev;
+ id.inode = sbuf.st_ino;
+
+ ret = xattr_tdb_setattr(eadb, &id, attribute, blob.data, blob.length, 0);
+ if (ret < 0) {
+ PyErr_SetFromErrno(PyExc_TypeError);
talloc_free(mem_ctx);
return NULL;
}
@@ -76,31 +92,47 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
char *filename, *attribute, *tdbname;
TALLOC_CTX *mem_ctx;
DATA_BLOB blob;
- PyObject *ret;
- NTSTATUS status;
- struct tdb_wrap *eadb = NULL;
+ PyObject *ret_obj;
+ int ret;
+ ssize_t xattr_size;
+ struct db_context *eadb = NULL;
+ struct file_id id;
+ struct stat sbuf;
if (!PyArg_ParseTuple(args, "sss", &tdbname, &filename, &attribute))
return NULL;
mem_ctx = talloc_new(NULL);
- eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600, py_default_loadparm_context(mem_ctx));
+
+ eadb = db_open_tdb(mem_ctx, py_default_loadparm_context(mem_ctx), tdbname, 50000,
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_2);
+
if (eadb == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
talloc_free(mem_ctx);
return NULL;
}
- status = pull_xattr_blob_tdb_raw(eadb, mem_ctx, attribute, filename,
- -1, 100, &blob);
- if (!NT_STATUS_IS_OK(status)) {
- PyErr_SetNTSTATUS(status);
+
+ ret = stat(filename, &sbuf);
+ if (ret < 0) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ ZERO_STRUCT(id);
+ id.devid = sbuf.st_dev;
+ id.inode = sbuf.st_ino;
+
+ xattr_size = xattr_tdb_getattr(eadb, mem_ctx, &id, attribute, &blob);
+ if (xattr_size < 0) {
+ PyErr_SetFromErrno(PyExc_TypeError);
talloc_free(mem_ctx);
return NULL;
}
- ret = PyString_FromStringAndSize((char *)blob.data, blob.length);
+ ret_obj = PyString_FromStringAndSize((char *)blob.data, xattr_size);
talloc_free(mem_ctx);
- return ret;
+ return ret_obj;
}
static PyMethodDef py_xattr_methods[] = {