summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2009-11-09 20:53:34 +0300
committerAndrew Bartlett <abartlet@samba.org>2010-01-21 07:11:13 +1300
commitc80ecd9964285f3c4a5128389c4e330ab25cca1c (patch)
treee79aa9774fda428db600009aca8b047da315ad13 /source4
parent45465cb7da75645f656e9c5dda136d782477ee68 (diff)
downloadsamba-c80ecd9964285f3c4a5128389c4e330ab25cca1c.tar.gz
samba-c80ecd9964285f3c4a5128389c4e330ab25cca1c.tar.bz2
samba-c80ecd9964285f3c4a5128389c4e330ab25cca1c.zip
s4: add python bindings for wrap_(s|g)etxattr
Diffstat (limited to 'source4')
-rw-r--r--source4/librpc/config.mk11
-rw-r--r--source4/scripting/python/config.mk21
-rw-r--r--source4/scripting/python/pyglue.c4
-rw-r--r--source4/scripting/python/pyxattr_native.c130
-rw-r--r--source4/scripting/python/pyxattr_tdb.c133
5 files changed, 297 insertions, 2 deletions
diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk
index 5f8bc880d1..589cb5f52e 100644
--- a/source4/librpc/config.mk
+++ b/source4/librpc/config.mk
@@ -361,6 +361,11 @@ PUBLIC_DEPENDENCIES = \
NDR_TABLE_OBJ_FILES = ../librpc/ndr/ndr_table.o $(gen_ndrsrcdir)/tables.o
+[SUBSYSTEM::RPC_NDR_XATTR]
+PUBLIC_DEPENDENCIES = NDR_XATTR dcerpc
+
+RPC_NDR_XATTR_OBJ_FILES = ../librpc/gen_ndr/ndr_xattr_c.o
+
[SUBSYSTEM::RPC_NDR_ROT]
PUBLIC_DEPENDENCIES = NDR_ROT dcerpc
@@ -713,6 +718,12 @@ PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc python_dcerpc NDR_SECURITY
python_dcerpc_security_OBJ_FILES = ../librpc/gen_ndr/py_security.o
+[PYTHON::python_dcerpc_xattr]
+LIBRARY_REALNAME = samba/dcerpc/xattr.$(SHLIBEXT)
+PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc python_dcerpc python_dcerpc_security NDR_XATTR RPC_NDR_XATTR
+
+python_dcerpc_xattr_OBJ_FILES = ../librpc/gen_ndr/py_xattr.o
+
$(IDL_HEADER_FILES) $(IDL_NDR_PARSE_H_FILES) $(IDL_NDR_PARSE_C_FILES) \
$(IDL_NDR_CLIENT_C_FILES) $(IDL_NDR_CLIENT_H_FILES) \
$(IDL_NDR_SERVER_C_FILES) $(IDL_SWIG_FILES) \
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index 3d255de00e..2aae592674 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -23,6 +23,27 @@ python_glue_OBJ_FILES = $(pyscriptsrcdir)/pyglue.o
$(python_glue_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)
+[PYTHON::python_xattr_native]
+LIBRARY_REALNAME = samba/xattr_native.$(SHLIBEXT)
+PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS python_dcerpc_security pyparam_util WRAP_XATTR
+
+python_xattr_native_OBJ_FILES = $(pyscriptsrcdir)/pyxattr_native.o
+
+$(python_xattr_native_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)
+
+#ntvfs_common pvfs_acl
+#$(ntvfs_posix_OBJ_FILES)
+[PYTHON::python_xattr_tdb]
+LIBRARY_REALNAME = samba/xattr_tdb.$(SHLIBEXT)
+PRIVATE_DEPENDENCIES = LIBNDR LIBLDB python_dcerpc_security pyparam_util share
+#dcerpc_server
+
+python_xattr_tdb_OBJ_FILES = $(pyscriptsrcdir)/pyxattr_tdb.o $(ntvfssrcdir)/posix/xattr_tdb.o
+#{$(ntvfssrcdir)/ntvfs_interface.o
+#$(ntvfs_posix_OBJ_FILES)
+
+$(python_xattr_tdb_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)
+
_PY_FILES = $(shell find $(pyscriptsrcdir)/samba ../lib/subunit/python -name "*.py")
$(eval $(foreach pyfile, $(_PY_FILES),$(call python_py_module_template,$(patsubst $(pyscriptsrcdir)/%,%,$(subst ../lib/subunit/python,,$(pyfile))),$(pyfile))))
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index 3d33e605db..6ef7033128 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -54,8 +54,8 @@ static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_
return; /* Python exception should already be set, just keep that */
PyErr_SetObject(error,
- Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
- ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
+ Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
+ ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
}
static PyObject *py_ldb_get_exception(void)
diff --git a/source4/scripting/python/pyxattr_native.c b/source4/scripting/python/pyxattr_native.c
new file mode 100644
index 0000000000..7cff42cebe
--- /dev/null
+++ b/source4/scripting/python/pyxattr_native.c
@@ -0,0 +1,130 @@
+/*
+ Unix SMB/CIFS implementation. Xattr manipulation bindings.
+ Copyright (C) Matthieu Patou <mat@matws.net> 2009
+ 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 "version.h"
+#include "includes.h"
+#include "librpc/ndr/libndr.h"
+#include "lib/util/wrap_xattr.h"
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
+static PyObject *py_is_xattr_supported(PyObject *self)
+{
+#if !defined(HAVE_XATTR_SUPPORT)
+ return Py_False;
+#else
+ return Py_True;
+#endif
+}
+static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
+{
+ char *filename, *attribute;
+ int ret = 0;
+ int blobsize;
+ DATA_BLOB blob;
+
+ if (!PyArg_ParseTuple(args, "sss#", &filename,&attribute,&blob.data,&blobsize))
+ return NULL;
+
+ blob.length = blobsize;
+ ret = wrap_setxattr(filename,attribute,blob.data,blob.length,0);
+ if( ret < 0 ) {
+ if (errno == ENOTSUP) {
+ PyErr_SetString(PyExc_IOError, strerror(errno));
+ } else {
+ PyErr_SetString(PyExc_TypeError, strerror(errno));
+ }
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
+{
+ char *filename, *attribute;
+ int len;
+ TALLOC_CTX *mem_ctx;
+ uint8_t *buf;
+ PyObject *ret;
+ if (!PyArg_ParseTuple(args, "ss", &filename,&attribute))
+ return NULL;
+ mem_ctx = talloc_new(NULL);
+ len = wrap_getxattr(filename,attribute,NULL,0);
+ if( len < 0 ) {
+ if (errno == ENOTSUP) {
+ PyErr_SetString(PyExc_IOError, strerror(errno));
+ } else {
+ PyErr_SetString(PyExc_TypeError, strerror(errno));
+ }
+ return NULL;
+ }
+ /* check length ... */
+ buf = talloc_zero_array(mem_ctx, uint8_t, len);
+ len = wrap_getxattr(filename,attribute,buf,len);
+ if( len < 0 ) {
+ if (errno == ENOTSUP) {
+ PyErr_SetString(PyExc_IOError, strerror(errno));
+ } else {
+ PyErr_SetString(PyExc_TypeError, strerror(errno));
+ }
+ return NULL;
+ }
+ ret = PyString_FromStringAndSize(buf,len);
+ talloc_free(buf);
+ return ret;
+}
+
+static PyMethodDef py_xattr_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 initxattr_native(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("xattr_native", py_xattr_methods,
+ "Python bindings for xattr manipulation.");
+ if (m == NULL)
+ return;
+
+ PyModule_AddObject(m, "version", PyString_FromString(SAMBA_VERSION_STRING));
+
+ /* one of the most annoying things about python scripts is
+ that they don't die when you hit control-C. This fixes that
+ sillyness. As we do all database operations using
+ transactions, this is also safe. In fact, not dying
+ immediately is unsafe as we could end up treating the
+ control-C exception as a different error and try to modify
+ as database incorrectly
+ */
+ signal(SIGINT, SIG_DFL);
+}
+
diff --git a/source4/scripting/python/pyxattr_tdb.c b/source4/scripting/python/pyxattr_tdb.c
new file mode 100644
index 0000000000..19b4f417a8
--- /dev/null
+++ b/source4/scripting/python/pyxattr_tdb.c
@@ -0,0 +1,133 @@
+/*
+ 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 "version.h"
+#include "includes.h"
+#include "../tdb/include/tdb.h"
+#include "tdb_wrap.h"
+#include "librpc/ndr/libndr.h"
+#include "lib/util/wrap_xattr.h"
+#include "ntvfs/posix/vfs_posix.h"
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
+static PyObject *py_is_xattr_supported(PyObject *self)
+{
+/*#if !defined(HAVE_XATTR_SUPPORT)
+ return Py_False;
+#else
+ return Py_True;
+#endif*/
+ 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);
+
+ if (eadb == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ } status = push_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,&blob);
+ if( !NT_STATUS_IS_OK(status) ) {
+ PyErr_SetString(PyExc_TypeError, strerror(errno));
+ return NULL;
+ }
+ 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);
+ if (eadb == NULL) {
+
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+ status = pull_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,100,&blob);
+ if( !NT_STATUS_IS_OK(status) || blob.length < 0 ) {
+ PyErr_SetString(PyExc_TypeError, get_friendly_nt_error_msg(status));
+ return NULL;
+ }
+ ret = PyString_FromStringAndSize(blob.data,blob.length);
+ return ret;
+}
+
+static PyMethodDef py_xattr_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 backed by tdb are supported on this system\n"},
+ { NULL }
+};
+
+void initxattr_tdb(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("xattr_tdb", py_xattr_methods,
+ "Python bindings for xattr manipulation.");
+ if (m == NULL)
+ return;
+
+ PyModule_AddObject(m, "version", PyString_FromString(SAMBA_VERSION_STRING));
+
+ /* one of the most annoying things about python scripts is
+ that they don't die when you hit control-C. This fixes that
+ sillyness. As we do all database operations using
+ transactions, this is also safe. In fact, not dying
+ immediately is unsafe as we could end up treating the
+ control-C exception as a different error and try to modify
+ as database incorrectly
+ */
+ signal(SIGINT, SIG_DFL);
+}
+