s4-samba-tool: add password verification in change user pass
[Samba/gebeck_regimport.git] / source4 / lib / policy / pypolicy.c
blob8a9aa47f1fdfa62071587fd37f42c25b3a9c818b
1 /*
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 <Python.h>
21 #include "includes.h"
22 #include "policy.h"
23 #include "libcli/util/pyerrors.h"
25 void initpolicy(void);
27 static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args)
29 int flags;
30 PyObject *py_ret;
31 const char **ret;
32 TALLOC_CTX *mem_ctx;
33 int i;
34 NTSTATUS status;
36 if (!PyArg_ParseTuple(args, "i", &flags))
37 return NULL;
39 mem_ctx = talloc_new(NULL);
40 if (mem_ctx == NULL) {
41 PyErr_NoMemory();
42 return NULL;
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;
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;
61 PyList_Append(py_ret, item);
64 talloc_free(mem_ctx);
66 return py_ret;
69 static PyObject *py_get_gplink_options(PyObject *self, PyObject *args)
71 int flags;
72 PyObject *py_ret;
73 const char **ret;
74 TALLOC_CTX *mem_ctx;
75 int i;
76 NTSTATUS status;
78 if (!PyArg_ParseTuple(args, "i", &flags))
79 return NULL;
81 mem_ctx = talloc_new(NULL);
82 if (mem_ctx == NULL) {
83 PyErr_NoMemory();
84 return NULL;
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;
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;
103 PyList_Append(py_ret, item);
106 talloc_free(mem_ctx);
108 return py_ret;
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))
116 return NULL;
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" },
131 { NULL }
134 void initpolicy(void)
136 PyObject *m;
138 m = Py_InitModule3("policy", py_policy_methods, "(Group) Policy manipulation");
139 if (!m)
140 return;
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 ));