python-samba3: Secrets file loaded from private dir, not lib dir
[idra/samba.git] / source4 / scripting / python / pyglue.c
index 8a404a3b146333d5d9cc968b1e28fdc86d2114f4..cc312ba0689b38e9aff4330314ec59b180c8c074 100644 (file)
 #include "param/pyparam.h"
 #include "lib/socket/netif.h"
 
+void init_glue(void);
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
 static PyObject *py_generate_random_str(PyObject *self, PyObject *args)
 {
        int len;
@@ -57,9 +63,13 @@ static PyObject *py_generate_random_password(PyObject *self, PyObject *args)
 static PyObject *py_unix2nttime(PyObject *self, PyObject *args)
 {
        time_t t;
+       unsigned int _t;
        NTTIME nt;
-       if (!PyArg_ParseTuple(args, "I", &t))
+
+       if (!PyArg_ParseTuple(args, "I", &_t)) {
                return NULL;
+       }
+       t = _t;
 
        unix_to_nt_time(&nt, t);
 
@@ -88,6 +98,10 @@ static PyObject *py_nttime2string(PyObject *self, PyObject *args)
                return NULL;
 
        tmp_ctx = talloc_new(NULL);
+       if (tmp_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
 
        string = nt_time_string(tmp_ctx, nt);
        ret =  PyString_FromString(string);
@@ -143,22 +157,22 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       load_interfaces(tmp_ctx, lpcfg_interfaces(lp_ctx), &ifaces);
+       load_interface_list(tmp_ctx, lp_ctx, &ifaces);
 
-       count = iface_count(ifaces);
+       count = iface_list_count(ifaces);
 
        /* first count how many are not loopback addresses */
        for (ifcount = i = 0; i<count; i++) {
-               const char *ip = iface_n_ip(ifaces, i);
-               if (!(!all_interfaces && iface_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
+               const char *ip = iface_list_n_ip(ifaces, i);
+               if (!(!all_interfaces && iface_list_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
                        ifcount++;
                }
        }
 
        pylist = PyList_New(ifcount);
        for (ifcount = i = 0; i<count; i++) {
-               const char *ip = iface_n_ip(ifaces, i);
-               if (!(!all_interfaces && iface_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
+               const char *ip = iface_list_n_ip(ifaces, i);
+               if (!(!all_interfaces && iface_list_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
                        PyList_SetItem(pylist, ifcount, PyString_FromString(ip));
                        ifcount++;
                }
@@ -167,6 +181,30 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
        return pylist;
 }
 
+static PyObject *py_strcasecmp_m(PyObject *self, PyObject *args)
+{
+       char *s1, *s2;
+
+       if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
+               return NULL;
+
+       return PyInt_FromLong(strcasecmp_m(s1, s2));
+}
+
+static PyObject *py_strstr_m(PyObject *self, PyObject *args)
+{
+       char *s1, *s2, *ret;
+
+       if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
+               return NULL;
+
+       ret = strstr_m(s1, s2);
+       if (!ret) {
+               Py_RETURN_NONE;
+       }
+       return PyString_FromString(ret);
+}
+
 static PyMethodDef py_misc_methods[] = {
        { "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
                "generate_random_str(len) -> string\n"
@@ -186,6 +224,10 @@ static PyMethodDef py_misc_methods[] = {
                "get debug level" },
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
                "get interface IP address list"},
+       { "strcasecmp_m", (PyCFunction)py_strcasecmp_m, METH_VARARGS,
+               "(for testing) compare two strings using Samba's strcasecmp_m()"},
+       { "strstr_m", (PyCFunction)py_strstr_m, METH_VARARGS,
+               "(for testing) find one string in another with Samba's strstr_m()"},
        { NULL }
 };