2 Unix SMB/CIFS implementation. Xattr manipulation bindings.
3 Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010
4 Base on work of pyglue.c by Jelmer Vernooij <jelmer@samba.org> 2007 and
5 Matthias Dieter Wallnöfer 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "librpc/ndr/libndr.h"
26 #include "lib/util/wrap_xattr.h"
27 #include "ntvfs/posix/vfs_posix.h"
28 #include "libcli/util/pyerrors.h"
30 static PyObject
*py_is_xattr_supported(PyObject
*self
)
35 static PyObject
*py_wrap_setxattr(PyObject
*self
, PyObject
*args
)
37 char *filename
, *attribute
, *tdbname
;
42 struct tdb_wrap
*eadb
;
44 if (!PyArg_ParseTuple(args
, "ssss#", &tdbname
, &filename
, &attribute
,
45 &blob
.data
, &blobsize
))
48 blob
.length
= blobsize
;
49 mem_ctx
= talloc_new(NULL
);
50 eadb
= tdb_wrap_open(mem_ctx
, tdbname
, 50000,
51 TDB_DEFAULT
, O_RDWR
|O_CREAT
, 0600);
54 PyErr_SetFromErrno(PyExc_IOError
);
58 status
= push_xattr_blob_tdb_raw(eadb
, mem_ctx
, attribute
, filename
, -1,
60 if (!NT_STATUS_IS_OK(status
)) {
61 PyErr_FromNTSTATUS(status
);
69 static PyObject
*py_wrap_getxattr(PyObject
*self
, PyObject
*args
)
71 char *filename
, *attribute
, *tdbname
;
76 struct tdb_wrap
*eadb
= NULL
;
78 if (!PyArg_ParseTuple(args
, "sss", &tdbname
, &filename
, &attribute
))
81 mem_ctx
= talloc_new(NULL
);
82 eadb
= tdb_wrap_open(mem_ctx
, tdbname
, 50000,
83 TDB_DEFAULT
, O_RDWR
|O_CREAT
, 0600);
85 PyErr_SetFromErrno(PyExc_IOError
);
89 status
= pull_xattr_blob_tdb_raw(eadb
, mem_ctx
, attribute
, filename
,
91 if (!NT_STATUS_IS_OK(status
) || blob
.length
< 0) {
92 PyErr_FromNTSTATUS(status
);
96 ret
= PyString_FromStringAndSize((char *)blob
.data
, blob
.length
);
101 static PyMethodDef py_xattr_methods
[] = {
102 { "wrap_getxattr", (PyCFunction
)py_wrap_getxattr
, METH_VARARGS
,
103 "wrap_getxattr(filename,attribute) -> blob\n"
104 "Retreive given attribute on the given file." },
105 { "wrap_setxattr", (PyCFunction
)py_wrap_setxattr
, METH_VARARGS
,
106 "wrap_setxattr(filename,attribute,value)\n"
107 "Set the given attribute to the given value on the given file." },
108 { "is_xattr_supported", (PyCFunction
)py_is_xattr_supported
, METH_NOARGS
,
109 "Return true if xattr are supported on this system\n"},
113 void initxattr_tdb(void)
117 m
= Py_InitModule3("xattr_tdb", py_xattr_methods
,
118 "Python bindings for xattr manipulation.");