s4:scripting/python/modules.c - fix "asprintf" calls
[Samba/ekacnet.git] / source4 / scripting / python / modules.c
blob6cc3ca58d2892694c995290821d84b143a3bfe5e
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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 "scripting/python/modules.h"
23 #include "dynconfig/dynconfig.h"
25 extern void init_ldb(void);
26 extern void init_security(void);
27 extern void init_registry(void);
28 extern void init_param(void);
29 extern void init_misc(void);
30 extern void init_ldb(void);
31 extern void init_auth(void);
32 extern void init_credentials(void);
33 extern void init_tdb(void);
34 extern void init_dcerpc(void);
35 extern void init_events(void);
36 extern void inituuid(void);
37 extern void init_net(void);
38 extern void initecho(void);
39 extern void initdfs(void);
40 extern void initdrsuapi(void);
41 extern void initwinreg(void);
42 extern void initepmapper(void);
43 extern void initinitshutdown(void);
44 extern void initmgmt(void);
45 extern void initnet(void);
46 extern void initatsvc(void);
47 extern void initsamr(void);
48 extern void initlsa(void);
49 extern void initsvcctl(void);
50 extern void initwkssvc(void);
51 extern void initunixinfo(void);
52 extern void init_libcli_nbt(void);
53 extern void init_libcli_smb(void);
55 static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES };
57 void py_load_samba_modules(void)
59 int i;
60 for (i = 0; i < ARRAY_SIZE(py_modules); i++) {
61 PyImport_ExtendInittab(&py_modules[i]);
65 static bool PySys_PathPrepend(PyObject *list, const char *path)
67 PyObject *py_path = PyString_FromString(path);
68 if (py_path == NULL)
69 return false;
71 return (PyList_Insert(list, 0, py_path) == 0);
74 bool py_update_path(const char *bindir)
76 char *newpath;
77 PyObject *mod_sys, *py_path;
79 mod_sys = PyImport_ImportModule("sys");
80 if (mod_sys == NULL) {
81 return false;
84 py_path = PyObject_GetAttrString(mod_sys, "path");
85 if (py_path == NULL) {
86 return false;
89 if (!PyList_Check(py_path)) {
90 return false;
93 if (!PySys_PathPrepend(py_path, dyn_PYTHONDIR)) {
94 return false;
97 if (asprintf(&newpath, "%s/../scripting/python", bindir) < 0) {
98 return false;
100 if (!PySys_PathPrepend(py_path, newpath)) {
101 free(newpath);
102 return false;
104 free(newpath);
106 if (asprintf(&newpath, "%s/python", bindir) < 0) {
107 return false;
109 if (!PySys_PathPrepend(py_path, newpath)) {
110 free(newpath);
111 return false;
113 free(newpath);
115 return true;