diff options
author | Andrew Bartlett <abartlet@samba.org> | 2012-04-16 18:59:34 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-04-18 12:05:00 +1000 |
commit | 628a24172f3bb759324582c439ba9d081aa4d392 (patch) | |
tree | ecb71dd83d54f06aed7977149e926ecf3e72b374 /source4/ntvfs/posix/python/pyposix_eadb.c | |
parent | 44b6bf9130ec5207da148af0f56a660ce9e08c32 (diff) | |
download | samba-628a24172f3bb759324582c439ba9d081aa4d392.tar.gz samba-628a24172f3bb759324582c439ba9d081aa4d392.tar.bz2 samba-628a24172f3bb759324582c439ba9d081aa4d392.zip |
s4-python: Add python wrapper for xattr_tdb format xattr storage
This uses the format used by the vfs_xattr_tdb module. The s4
posix:eadb format is kept, just in a new file and module.
Andrew Bartlett
Diffstat (limited to 'source4/ntvfs/posix/python/pyposix_eadb.c')
-rw-r--r-- | source4/ntvfs/posix/python/pyposix_eadb.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c new file mode 100644 index 0000000000..226160f88d --- /dev/null +++ b/source4/ntvfs/posix/python/pyposix_eadb.c @@ -0,0 +1,126 @@ +/* + Unix SMB/CIFS implementation. Xattr manipulation bindings. + Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010 + Base on work of pyglue.c by Jelmer Vernooij <jelmer@samba.org> 2007 and + Matthias Dieter Wallnöfer 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <Python.h> +#include "includes.h" +#include "system/filesys.h" +#include "tdb_compat.h" +#include "lib/tdb_wrap/tdb_wrap.h" +#include "librpc/ndr/libndr.h" +#include "lib/util/wrap_xattr.h" +#include "ntvfs/posix/posix_eadb.h" +#include "libcli/util/pyerrors.h" +#include "param/pyparam.h" + +void initxattr_tdb(void); + +static PyObject *py_is_xattr_supported(PyObject *self) +{ + return Py_True; +} + +static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) +{ + char *filename, *attribute, *tdbname; + DATA_BLOB blob; + int blobsize; + NTSTATUS status; + TALLOC_CTX *mem_ctx; + struct tdb_wrap *eadb; + + if (!PyArg_ParseTuple(args, "ssss#", &tdbname, &filename, &attribute, + &blob.data, &blobsize)) + return NULL; + + 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)); + + 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); + talloc_free(mem_ctx); + return NULL; + } + talloc_free(mem_ctx); + Py_RETURN_NONE; +} + +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, + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, py_default_loadparm_context(mem_ctx)); + 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 PyMethodDef py_posix_eadb_methods[] = { + { "wrap_getxattr", (PyCFunction)py_wrap_getxattr, METH_VARARGS, + "wrap_getxattr(filename,attribute) -> blob\n" + "Retreive given attribute on the given file." }, + { "wrap_setxattr", (PyCFunction)py_wrap_setxattr, METH_VARARGS, + "wrap_setxattr(filename,attribute,value)\n" + "Set the given attribute to the given value on the given file." }, + { "is_xattr_supported", (PyCFunction)py_is_xattr_supported, METH_NOARGS, + "Return true if xattr are supported on this system\n"}, + { NULL } +}; + +void initposix_eadb(void) +{ + PyObject *m; + + m = Py_InitModule3("posix_eadb", py_posix_eadb_methods, + "Python bindings for xattr manipulation."); + if (m == NULL) + return; +} |