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/>.
23 #include "libcli/util/pyerrors.h"
25 void initpolicy(void);
27 static PyObject
*py_get_gpo_flags(PyObject
*self
, PyObject
*args
)
36 if (!PyArg_ParseTuple(args
, "i", &flags
))
39 mem_ctx
= talloc_new(NULL
);
40 if (mem_ctx
== NULL
) {
45 status
= gp_get_gpo_flags(mem_ctx
, flags
, &ret
);
46 if (!NT_STATUS_IS_OK(status
)) {
47 PyErr_SetNTSTATUS(status
);
52 py_ret
= PyList_New(0);
53 for (i
= 0; ret
[i
]; i
++) {
54 PyObject
*item
= PyString_FromString(ret
[i
]);
61 PyList_Append(py_ret
, item
);
69 static PyObject
*py_get_gplink_options(PyObject
*self
, PyObject
*args
)
78 if (!PyArg_ParseTuple(args
, "i", &flags
))
81 mem_ctx
= talloc_new(NULL
);
82 if (mem_ctx
== NULL
) {
87 status
= gp_get_gplink_options(mem_ctx
, flags
, &ret
);
88 if (!NT_STATUS_IS_OK(status
)) {
89 PyErr_SetNTSTATUS(status
);
94 py_ret
= PyList_New(0);
95 for (i
= 0; ret
[i
]; i
++) {
96 PyObject
*item
= PyString_FromString(ret
[i
]);
103 PyList_Append(py_ret
, item
);
106 talloc_free(mem_ctx
);
111 static PyObject
*py_ads_to_dir_access_mask(PyObject
*self
, PyObject
*args
)
113 uint32_t access_mask
, dir_mask
;
115 if (! PyArg_ParseTuple(args
, "I", &access_mask
))
118 dir_mask
= gp_ads_to_dir_access_mask(access_mask
);
120 return Py_BuildValue("I", dir_mask
);
124 static 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" },
134 void initpolicy(void)
138 m
= Py_InitModule3("policy", py_policy_methods
, "(Group) Policy manipulation");
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
));