s3: Make torture_nprocs globally available
[Samba/gebeck_regimport.git] / source4 / librpc / ndr / py_xattr.c
blob5a61c734a52f92a12db0e0e2e51bb6bbfb3f912a
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Matthieu Patou <mat@matws.net> 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <Python.h>
22 #ifndef Py_RETURN_NONE
23 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
24 #endif
26 static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
28 PyObject *dict;
29 int i;
30 if (type->tp_dict == NULL)
31 type->tp_dict = PyDict_New();
32 dict = type->tp_dict;
33 for (i = 0; methods[i].ml_name; i++) {
34 PyObject *descr;
35 if (methods[i].ml_flags & METH_CLASS)
36 descr = PyCFunction_New(&methods[i], (PyObject *)type);
37 else
38 descr = PyDescr_NewMethod(type, &methods[i]);
39 PyDict_SetItemString(dict, methods[i].ml_name,
40 descr);
44 static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
46 static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
48 va_list ap;
49 char *s = NULL;
50 int i;
52 va_start(ap, format);
53 vasprintf(&s, format, ap);
54 va_end(ap);
56 for (i=0;i<ndr->depth;i++) {
57 printf(" ");
60 printf("%s\n", s);
61 free(s);
64 static PyObject *py_ntacl_print(PyObject *self, PyObject *args)
66 struct xattr_NTACL *ntacl = pytalloc_get_ptr(self);
67 struct ndr_print *pr;
68 TALLOC_CTX *mem_ctx;
70 mem_ctx = talloc_new(NULL);
72 pr = talloc_zero(mem_ctx, struct ndr_print);
73 if (!pr) {
74 PyErr_NoMemory();
75 talloc_free(mem_ctx);
76 return NULL;
78 pr->print = ntacl_print_debug_helper;
79 ndr_print_xattr_NTACL(pr, "file", ntacl);
81 talloc_free(mem_ctx);
83 Py_RETURN_NONE;
86 static PyMethodDef py_ntacl_extra_methods[] = {
87 { "dump", (PyCFunction)py_ntacl_print, METH_NOARGS,
88 NULL },
89 { NULL }
92 static void py_xattr_NTACL_patch(PyTypeObject *type)
94 PyType_AddMethods(type, py_ntacl_extra_methods);
97 #define PY_NTACL_PATCH py_xattr_NTACL_patch