2 * Unix SMB/CIFS implementation.
3 * Python bindings for libpolicy
4 * Copyright (C) Jelmer Vernooij 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 "lib/replace/system/python.h"
22 #include "python/py3compat.h"
24 #include "libcli/util/pyerrors.h"
26 void initpolicy(void);
28 static PyObject
*py_get_gpo_flags(PyObject
*self
, PyObject
*args
)
37 if (!PyArg_ParseTuple(args
, "i", &flags
))
40 mem_ctx
= talloc_new(NULL
);
41 if (mem_ctx
== NULL
) {
46 status
= gp_get_gpo_flags(mem_ctx
, flags
, &ret
);
47 if (!NT_STATUS_IS_OK(status
)) {
48 PyErr_SetNTSTATUS(status
);
53 py_ret
= PyList_New(0);
54 for (i
= 0; ret
[i
]; i
++) {
56 PyObject
*item
= PyUnicode_FromString(ret
[i
]);
63 res
= PyList_Append(py_ret
, item
);
77 static PyObject
*py_get_gplink_options(PyObject
*self
, PyObject
*args
)
86 if (!PyArg_ParseTuple(args
, "i", &flags
))
89 mem_ctx
= talloc_new(NULL
);
90 if (mem_ctx
== NULL
) {
95 status
= gp_get_gplink_options(mem_ctx
, flags
, &ret
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 PyErr_SetNTSTATUS(status
);
102 py_ret
= PyList_New(0);
103 for (i
= 0; ret
[i
]; i
++) {
105 PyObject
*item
= PyUnicode_FromString(ret
[i
]);
107 talloc_free(mem_ctx
);
112 res
= PyList_Append(py_ret
, item
);
116 talloc_free(mem_ctx
);
121 talloc_free(mem_ctx
);
126 static PyObject
*py_ads_to_dir_access_mask(PyObject
*self
, PyObject
*args
)
128 uint32_t access_mask
, dir_mask
;
130 if (! PyArg_ParseTuple(args
, "I", &access_mask
))
133 dir_mask
= gp_ads_to_dir_access_mask(access_mask
);
135 return Py_BuildValue("I", dir_mask
);
139 static PyMethodDef py_policy_methods
[] = {
140 { "get_gpo_flags", (PyCFunction
)py_get_gpo_flags
, METH_VARARGS
,
141 "get_gpo_flags(flags) -> list" },
142 { "get_gplink_options", (PyCFunction
)py_get_gplink_options
, METH_VARARGS
,
143 "get_gplink_options(options) -> list" },
144 { "ads_to_dir_access_mask", (PyCFunction
)py_ads_to_dir_access_mask
, METH_VARARGS
,
145 "ads_to_dir_access_mask(access_mask) -> dir_mask" },
149 static struct PyModuleDef moduledef
= {
150 PyModuleDef_HEAD_INIT
,
152 .m_doc
= "(Group) Policy manipulation",
154 .m_methods
= py_policy_methods
,
157 MODULE_INIT_FUNC(policy
)
161 m
= PyModule_Create(&moduledef
);
165 PyModule_AddObject(m
, "GPO_FLAG_USER_DISABLE",
166 PyLong_FromLong(GPO_FLAG_USER_DISABLE
));
167 PyModule_AddObject(m
, "GPO_MACHINE_USER_DISABLE",
168 PyLong_FromLong(GPO_FLAG_MACHINE_DISABLE
));
169 PyModule_AddObject(m
, "GPLINK_OPT_DISABLE",
170 PyLong_FromLong(GPLINK_OPT_DISABLE
));
171 PyModule_AddObject(m
, "GPLINK_OPT_ENFORCE ",
172 PyLong_FromLong(GPLINK_OPT_ENFORCE
));