samba3-python: Add methods to get any entry (user/group) and its sid from idmap
[idra/samba.git] / source4 / scripting / python / modules.c
index 5365c5007d6aa97f50b0595685d03fccf75f3c95..78cdbc0d87966dfe9fb5d0d2d4f574b4c2745a4e 100644 (file)
 #include <Python.h>
 #include "includes.h"
 #include "scripting/python/modules.h"
+#include "dynconfig/dynconfig.h"
 
-extern void init_ldb(void);
-extern void init_security(void);
-extern void init_registry(void);
-extern void init_param(void);
-extern void init_misc(void);
-extern void init_ldb(void);
-extern void init_auth(void);
-extern void init_credentials(void);
-extern void init_tdb(void);
-extern void init_dcerpc(void);
-extern void init_events(void);
-extern void inituuid(void);
-extern void init_net(void);
-extern void initecho(void);
-extern void initdfs(void);
-extern void initdrsuapi(void);
-extern void initwinreg(void);
-extern void initepmapper(void);
-extern void initinitshutdown(void);
-extern void initmgmt(void);
-extern void initnet(void);
-extern void initatsvc(void);
-extern void initsamr(void);
-extern void initlsa(void);
-extern void initsvcctl(void);
-extern void initwkssvc(void);
-extern void initunixinfo(void);
-extern void init_libcli_nbt(void);
-extern void init_libcli_smb(void);
+static bool PySys_PathPrepend(PyObject *list, const char *path)
+{
+       PyObject *py_path = PyString_FromString(path);
+       if (py_path == NULL)
+               return false;
 
-static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES };
+       return (PyList_Insert(list, 0, py_path) == 0);
+}
 
-void py_load_samba_modules(void)
+bool py_update_path(void)
 {
-       int i;
-       for (i = 0; i < ARRAY_SIZE(py_modules); i++) {
-               PyImport_ExtendInittab(&py_modules[i]);
+       PyObject *mod_sys, *py_path;
+
+       mod_sys = PyImport_ImportModule("sys");
+       if (mod_sys == NULL) {
+               return false;
        }
-}
 
-void py_update_path(const char *bindir)
-{
-       char *newpath;
-       asprintf(&newpath, "%s/python:%s/../scripting/python:%s", bindir, bindir, Py_GetPath());
-       PySys_SetPath(newpath);
-       free(newpath);
+       py_path = PyObject_GetAttrString(mod_sys, "path");
+       if (py_path == NULL) {
+               return false;
+       }       
+
+       if (!PyList_Check(py_path)) {
+               return false;
+       }
+
+       if (!PySys_PathPrepend(py_path, dyn_PYTHONDIR)) {
+               return false;
+       }
+
+       if (strcmp(dyn_PYTHONARCHDIR, dyn_PYTHONDIR) != 0) {
+               if (!PySys_PathPrepend(py_path, dyn_PYTHONARCHDIR)) {
+                       return false;
+               }
+       }
+
+       return true;
 }