#include <Python.h>
#include "includes.h"
-#include "param/param.h"
#include "version.h"
-#include "libcli/util/pyerrors.h"
#include "param/pyparam.h"
#include "lib/socket/netif.h"
-#include "lib/socket/netif_proto.h"
-#include "lib/talloc/pytalloc.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)
{
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);
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);
Py_RETURN_NONE;
}
+static PyObject *py_get_debug_level(PyObject *self)
+{
+ return PyInt_FromLong(DEBUGLEVEL);
+}
+
/*
return the list of interface IPs we have configured
takes an loadparm context, returns a list of IPs in string form
return NULL;
tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
- lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); /* FIXME: leaky */
+ lp_ctx = lpcfg_from_py_object(tmp_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
- PyErr_SetString(PyExc_TypeError, "Expected loadparm object");
talloc_free(tmp_ctx);
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++;
}
return pylist;
}
-/* print a talloc tree report for a talloc python object */
-static PyObject *py_talloc_report_full(PyObject *self, PyObject *args)
+static PyObject *py_strcasecmp_m(PyObject *self, PyObject *args)
{
- PyObject *py_obj;
- PyTypeObject *type;
+ char *s1, *s2;
- if (!PyArg_ParseTuple(args, "O", &py_obj))
+ if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
return NULL;
- if (py_obj == Py_None) {
- talloc_report_full(NULL, stdout);
- } else {
- type = (PyTypeObject*)PyObject_Type(py_obj);
- talloc_report_full(py_talloc_get_mem_ctx(py_obj), stdout);
- }
- return Py_None;
-}
-
-/* enable null tracking */
-static PyObject *py_talloc_enable_null_tracking(PyObject *self, PyObject *args)
-{
- talloc_enable_null_tracking();
- return Py_None;
+ return PyInt_FromLong(strcasecmp_m(s1, s2));
}
-/* return the number of talloc blocks */
-static PyObject *py_talloc_total_blocks(PyObject *self, PyObject *args)
+static PyObject *py_strstr_m(PyObject *self, PyObject *args)
{
- PyObject *py_obj;
- PyTypeObject *type;
+ char *s1, *s2, *ret;
- if (!PyArg_ParseTuple(args, "O", &py_obj))
+ if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
return NULL;
- if (py_obj == Py_None) {
- return PyLong_FromLong(talloc_total_blocks(NULL));
+ ret = strstr_m(s1, s2);
+ if (!ret) {
+ Py_RETURN_NONE;
}
-
- type = (PyTypeObject*)PyObject_Type(py_obj);
-
- return PyLong_FromLong(talloc_total_blocks(py_talloc_get_mem_ctx(py_obj)));
+ 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"
"nttime2string(nttime) -> string" },
{ "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
"set debug level" },
+ { "get_debug_level", (PyCFunction)py_get_debug_level, METH_NOARGS,
+ "get debug level" },
{ "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
"get interface IP address list"},
- { "talloc_report_full", (PyCFunction)py_talloc_report_full, METH_VARARGS,
- "show a talloc tree for an object"},
- { "talloc_enable_null_tracking", (PyCFunction)py_talloc_enable_null_tracking, METH_VARARGS,
- "enable tracking of the NULL object"},
- { "talloc_total_blocks", (PyCFunction)py_talloc_total_blocks, METH_VARARGS,
- "return talloc block count"},
+ { "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 }
};
PyModule_AddObject(m, "version",
PyString_FromString(SAMBA_VERSION_STRING));
-
- /* one of the most annoying things about python scripts is
- that they don't die when you hit control-C. This fixes that
- sillyness. As we do all database operations using
- transactions, this is also safe.
- */
- signal(SIGINT, SIG_DFL);
}