summaryrefslogtreecommitdiff
path: root/source3/python
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-05-16 05:19:30 +0000
committerTim Potter <tpot@samba.org>2002-05-16 05:19:30 +0000
commit66115cf64be78907cf33ab5f7b0d3a33a3c7afd4 (patch)
tree49fd4a1df883da4be413b8b60a63c7e737f6b303 /source3/python
parent0227141bd1e9543d8d8f2dddfc9f729e7975d6a1 (diff)
downloadsamba-66115cf64be78907cf33ab5f7b0d3a33a3c7afd4.tar.gz
samba-66115cf64be78907cf33ab5f7b0d3a33a3c7afd4.tar.bz2
samba-66115cf64be78907cf33ab5f7b0d3a33a3c7afd4.zip
Fix memory leaks and return values in error returns for enumports().
Return enumerated ports as a hash of hashes instead of a list of hashes. (This used to be commit c469ada3d3b12b6a6e243d004faaae5f96cd3d96)
Diffstat (limited to 'source3/python')
-rw-r--r--source3/python/py_spoolss_ports.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c
index fb3f47c746..54ccf32fcc 100644
--- a/source3/python/py_spoolss_ports.c
+++ b/source3/python/py_spoolss_ports.c
@@ -25,7 +25,7 @@
PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
{
WERROR werror;
- PyObject *result, *creds = NULL;
+ PyObject *result = NULL, *creds = NULL;
int level = 1;
uint32 i, needed, num_ports;
static char *kwlist[] = {"server", "level", "creds", NULL};
@@ -37,8 +37,8 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(
- args, kw, "s|iO!", kwlist, &server, &creds, &level,
- &PyDict_Type))
+ args, kw, "s|iO!", kwlist, &server, &level,
+ &PyDict_Type, &creds))
return NULL;
if (server[0] == '\\' && server[1] == '\\')
@@ -48,13 +48,13 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
server, creds, cli_spoolss_initialise, &errstr))) {
PyErr_SetString(spoolss_error, errstr);
free(errstr);
- return NULL;
+ goto done;
}
if (!(mem_ctx = talloc_init())) {
PyErr_SetString(
- spoolss_error, "unable to initialise talloc context\n");
- return NULL;
+ spoolss_error, "unable to init talloc context\n");
+ goto done;
}
/* Call rpc function */
@@ -67,39 +67,63 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
cli, mem_ctx, needed, NULL, level,
&num_ports, &ctr);
- /* Return value */
-
- result = Py_None;
-
- if (!W_ERROR_IS_OK(werror))
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
goto done;
+ }
- result = PyList_New(num_ports);
-
+ /* Return value */
+
switch (level) {
case 1:
+ result = PyDict_New();
+
for (i = 0; i < num_ports; i++) {
PyObject *value;
+ fstring name;
+
+ rpcstr_pull(name, ctr.port.info_1[i].port_name.buffer,
+ sizeof(fstring), -1, STR_TERMINATE);
py_from_PORT_INFO_1(&value, &ctr.port.info_1[i]);
- PyList_SetItem(result, i, value);
+ PyDict_SetItemString(
+ value, "level", PyInt_FromLong(1));
+
+ PyDict_SetItemString(result, name, value);
}
break;
case 2:
+ result = PyDict_New();
+
for(i = 0; i < num_ports; i++) {
PyObject *value;
+ fstring name;
+
+ rpcstr_pull(name, ctr.port.info_2[i].port_name.buffer,
+ sizeof(fstring), -1, STR_TERMINATE);
py_from_PORT_INFO_2(&value, &ctr.port.info_2[i]);
- PyList_SetItem(result, i, value);
+ PyDict_SetItemString(
+ value, "level", PyInt_FromLong(2));
+
+ PyDict_SetItemString(result, name, value);
}
break;
+ default:
+ PyErr_SetString(spoolss_error, "unknown info level");
+ goto done;
}
done:
- Py_INCREF(result);
+ if (cli)
+ cli_shutdown(cli);
+
+ if (mem_ctx)
+ talloc_destroy(mem_ctx);
+
return result;
}