source: vendor/current/source4/lib/policy/pypolicy.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 3.6 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * Python bindings for libpolicy
4 * Copyright (C) Jelmer Vernooij 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#include "includes.h"
22#include "policy.h"
23#include "libcli/util/pyerrors.h"
24
25void initpolicy(void);
26
27static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args)
28{
29 int flags;
30 PyObject *py_ret;
31 const char **ret;
32 TALLOC_CTX *mem_ctx;
33 int i;
34 NTSTATUS status;
35
36 if (!PyArg_ParseTuple(args, "i", &flags))
37 return NULL;
38
39 mem_ctx = talloc_new(NULL);
40 if (mem_ctx == NULL) {
41 PyErr_NoMemory();
42 return NULL;
43 }
44
45 status = gp_get_gpo_flags(mem_ctx, flags, &ret);
46 if (!NT_STATUS_IS_OK(status)) {
47 PyErr_SetNTSTATUS(status);
48 talloc_free(mem_ctx);
49 return NULL;
50 }
51
52 py_ret = PyList_New(0);
53 for (i = 0; ret[i]; i++) {
54 PyObject *item = PyString_FromString(ret[i]);
55 if (item == NULL) {
56 talloc_free(mem_ctx);
57 Py_DECREF(py_ret);
58 PyErr_NoMemory();
59 return NULL;
60 }
61 PyList_Append(py_ret, item);
62 }
63
64 talloc_free(mem_ctx);
65
66 return py_ret;
67}
68
69static PyObject *py_get_gplink_options(PyObject *self, PyObject *args)
70{
71 int flags;
72 PyObject *py_ret;
73 const char **ret;
74 TALLOC_CTX *mem_ctx;
75 int i;
76 NTSTATUS status;
77
78 if (!PyArg_ParseTuple(args, "i", &flags))
79 return NULL;
80
81 mem_ctx = talloc_new(NULL);
82 if (mem_ctx == NULL) {
83 PyErr_NoMemory();
84 return NULL;
85 }
86
87 status = gp_get_gplink_options(mem_ctx, flags, &ret);
88 if (!NT_STATUS_IS_OK(status)) {
89 PyErr_SetNTSTATUS(status);
90 talloc_free(mem_ctx);
91 return NULL;
92 }
93
94 py_ret = PyList_New(0);
95 for (i = 0; ret[i]; i++) {
96 PyObject *item = PyString_FromString(ret[i]);
97 if (item == NULL) {
98 talloc_free(mem_ctx);
99 Py_DECREF(py_ret);
100 PyErr_NoMemory();
101 return NULL;
102 }
103 PyList_Append(py_ret, item);
104 }
105
106 talloc_free(mem_ctx);
107
108 return py_ret;
109}
110
111static PyObject *py_ads_to_dir_access_mask(PyObject *self, PyObject *args)
112{
113 uint32_t access_mask, dir_mask;
114
115 if (! PyArg_ParseTuple(args, "I", &access_mask))
116 return NULL;
117
118 dir_mask = gp_ads_to_dir_access_mask(access_mask);
119
120 return Py_BuildValue("I", dir_mask);
121}
122
123
124static PyMethodDef py_policy_methods[] = {
125 { "get_gpo_flags", (PyCFunction)py_get_gpo_flags, METH_VARARGS,
126 "get_gpo_flags(flags) -> list" },
127 { "get_gplink_options", (PyCFunction)py_get_gplink_options, METH_VARARGS,
128 "get_gplink_options(options) -> list" },
129 { "ads_to_dir_access_mask", (PyCFunction)py_ads_to_dir_access_mask, METH_VARARGS,
130 "ads_to_dir_access_mask(access_mask) -> dir_mask" },
131 { NULL }
132};
133
134void initpolicy(void)
135{
136 PyObject *m;
137
138 m = Py_InitModule3("policy", py_policy_methods, "(Group) Policy manipulation");
139 if (!m)
140 return;
141
142 PyModule_AddObject(m, "GPO_FLAG_USER_DISABLE",
143 PyInt_FromLong(GPO_FLAG_USER_DISABLE));
144 PyModule_AddObject(m, "GPO_MACHINE_USER_DISABLE",
145 PyInt_FromLong(GPO_FLAG_MACHINE_DISABLE));
146 PyModule_AddObject(m, "GPLINK_OPT_DISABLE",
147 PyInt_FromLong(GPLINK_OPT_DISABLE ));
148 PyModule_AddObject(m, "GPLINK_OPT_ENFORCE ",
149 PyInt_FromLong(GPLINK_OPT_ENFORCE ));
150}
Note: See TracBrowser for help on using the repository browser.