Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Samba utility functions
4 : Copyright (C) Matthieu Patou <mat@matws.net> 2010
5 :
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.
10 :
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.
15 :
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/>.
18 : */
19 :
20 : #include <Python.h>
21 :
22 1184 : static void PyType_AddMethods(PyTypeObject *type, PyMethodDef *methods)
23 : {
24 : PyObject *dict;
25 : int i;
26 1184 : if (type->tp_dict == NULL)
27 0 : type->tp_dict = PyDict_New();
28 1184 : dict = type->tp_dict;
29 2368 : for (i = 0; methods[i].ml_name; i++) {
30 : PyObject *descr;
31 1184 : if (methods[i].ml_flags & METH_CLASS)
32 0 : descr = PyCFunction_New(&methods[i], (PyObject *)type);
33 : else
34 1184 : descr = PyDescr_NewMethod(type, &methods[i]);
35 1184 : PyDict_SetItemString(dict, methods[i].ml_name,
36 : descr);
37 1184 : Py_CLEAR(descr);
38 : }
39 1184 : }
40 :
41 : static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
42 :
43 0 : static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
44 : {
45 : va_list ap;
46 0 : char *s = NULL;
47 : int i, ret;
48 :
49 0 : va_start(ap, format);
50 0 : ret = vasprintf(&s, format, ap);
51 0 : va_end(ap);
52 :
53 0 : if (ret == -1) {
54 0 : return;
55 : }
56 :
57 0 : for (i=0;i<ndr->depth;i++) {
58 0 : printf(" ");
59 : }
60 :
61 0 : printf("%s\n", s);
62 0 : free(s);
63 : }
64 :
65 0 : static PyObject *py_ntacl_print(PyObject *self, PyObject *args)
66 : {
67 0 : struct xattr_NTACL *ntacl = pytalloc_get_ptr(self);
68 : struct ndr_print *pr;
69 : TALLOC_CTX *mem_ctx;
70 :
71 0 : mem_ctx = talloc_new(NULL);
72 :
73 0 : pr = talloc_zero(mem_ctx, struct ndr_print);
74 0 : if (!pr) {
75 0 : PyErr_NoMemory();
76 0 : talloc_free(mem_ctx);
77 0 : return NULL;
78 : }
79 0 : pr->print = ntacl_print_debug_helper;
80 0 : ndr_print_xattr_NTACL(pr, "file", ntacl);
81 :
82 0 : talloc_free(mem_ctx);
83 :
84 0 : Py_RETURN_NONE;
85 : }
86 :
87 : static PyMethodDef py_ntacl_extra_methods[] = {
88 : { "dump", (PyCFunction)py_ntacl_print, METH_NOARGS,
89 : NULL },
90 : {0}
91 : };
92 :
93 1184 : static void py_xattr_NTACL_patch(PyTypeObject *type)
94 : {
95 1184 : PyType_AddMethods(type, py_ntacl_extra_methods);
96 1184 : }
97 :
98 : #define PY_NTACL_PATCH py_xattr_NTACL_patch
99 :
100 :
|