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; if (!PyArg_ParseTuple(args, "sss", &tdbname, &filename, &attribute)) return NULL; mem_ctx = talloc_new(NULL); eadb = tdb_wrap_open( mem_ctx, tdbname, 50000, lpcfg_tdb_flags(py_default_loadparm_context(mem_ctx), TDB_DEFAULT), O_RDWR|O_CREAT, 0600); 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); talloc_free(mem_ctx); return NULL; } ret = PyString_FromStringAndSize((char *)blob.data, blob.length); talloc_free(mem_ctx); return ret; }
static ssize_t posix_eadb_getattr(struct tdb_wrap *db_ctx, const char *fname, int fd, const char *name, void *value, size_t size) { ssize_t result = -1; NTSTATUS status; DATA_BLOB blob; DEBUG(10, ("posix_eadb_getattr called for file %s/fd %d, name %s\n", fname, fd, name)); status = pull_xattr_blob_tdb_raw(db_ctx, talloc_tos(), name, fname, fd, size, &blob); if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { errno = ENOATTR; return -1; } if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("posix_eadb_fetch_attrs failed: %s\n", nt_errstr(status))); errno = EINVAL; return -1; } if (blob.length > size) { errno = ERANGE; goto fail; } memcpy(value, blob.data, blob.length); result = blob.length; fail: return result; }