gpo: Add python libgpo bindings
[nivanova/samba-autobuild/.git] / libgpo / pygpo.c
1 /*
2    Unix SMB/CIFS implementation.
3    Copyright (C) Luke Morrison <luc785@hotmail.com> 2013
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <Python.h>
20 #include "includes.h"
21 #include "version.h"
22 #include "param/pyparam.h"
23 #include "gpo.h"
24 #include "ads.h"
25
26 /* A Python C API module to use LIBGPO */
27
28 #ifndef Py_RETURN_NONE
29 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
30 #endif
31
32 /* Parameter mapping and functions for the GP_EXT struct */
33 void initgpo(void);
34
35 /* Global methods aka do not need a special pyobject type */
36 static PyObject *py_gpo_get_sysvol_gpt_version(PyObject * self, PyObject * args)
37 {
38         TALLOC_CTX *tmp_ctx = NULL;
39         char *unix_path;
40         char *display_name = NULL;
41         uint32_t sysvol_version = 0;
42         PyObject *result;
43
44         tmp_ctx = talloc_new(NULL);
45
46         if (!PyArg_ParseTuple(args, "s", &unix_path)) {
47                 return NULL;
48         }
49         gpo_get_sysvol_gpt_version(tmp_ctx, unix_path, &sysvol_version, &display_name);
50         talloc_free(tmp_ctx);
51         result = Py_BuildValue("[s,i]", display_name, sysvol_version);
52         return result;
53 }
54
55 static PyMethodDef py_gpo_methods[] = {
56         {"gpo_get_sysvol_gpt_version", (PyCFunction) py_gpo_get_sysvol_gpt_version, METH_VARARGS, NULL},
57         {NULL}
58 };
59
60 /* Will be called by python when loading this module */
61 void initgpo(void)
62 {
63         PyObject *m;
64
65         debug_setup_talloc_log();
66         /* Instantiate the types */
67         m = Py_InitModule3("gpo", py_gpo_methods, "libgpo python bindings");
68         if (m == NULL)
69                 return;
70         PyModule_AddObject(m, "version", PyString_FromString(SAMBA_VERSION_STRING));
71 }