2 Python wrappers for DCERPC/SMB client routines.
4 Copyright (C) Tim Potter, 2002
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/py_spoolss.h"
24 PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
27 PyObject *result = NULL, *creds = NULL;
29 uint32 i, needed, num_ports;
30 static char *kwlist[] = {"server", "level", "creds", NULL};
31 TALLOC_CTX *mem_ctx = NULL;
32 struct cli_state *cli = NULL;
33 char *server, *errstr;
36 /* Parse parameters */
38 if (!PyArg_ParseTupleAndKeywords(
39 args, kw, "s|iO", kwlist, &server, &level, &creds))
42 if (server[0] != '\\' || server[1] != '\\') {
43 PyErr_SetString(PyExc_ValueError, "UNC name required");
49 if (creds && creds != Py_None && !PyDict_Check(creds)) {
50 PyErr_SetString(PyExc_TypeError,
51 "credentials must be dictionary or None");
55 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
56 PyErr_SetString(spoolss_error, errstr);
61 if (!(mem_ctx = talloc_init("spoolss_enumports"))) {
63 spoolss_error, "unable to init talloc context\n");
67 /* Call rpc function */
69 werror = rpccli_spoolss_enum_ports(
70 cli->pipe_list, mem_ctx, level, &num_ports, &ctr);
72 if (!W_ERROR_IS_OK(werror)) {
73 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
81 result = PyDict_New();
83 for (i = 0; i < num_ports; i++) {
87 rpcstr_pull(name, ctr.port.info_1[i].port_name.buffer,
88 sizeof(fstring), -1, STR_TERMINATE);
90 py_from_PORT_INFO_1(&value, &ctr.port.info_1[i]);
93 value, "level", PyInt_FromLong(1));
95 PyDict_SetItemString(result, name, value);
100 result = PyDict_New();
102 for(i = 0; i < num_ports; i++) {
106 rpcstr_pull(name, ctr.port.info_2[i].port_name.buffer,
107 sizeof(fstring), -1, STR_TERMINATE);
109 py_from_PORT_INFO_2(&value, &ctr.port.info_2[i]);
111 PyDict_SetItemString(
112 value, "level", PyInt_FromLong(2));
114 PyDict_SetItemString(result, name, value);
119 PyErr_SetString(spoolss_error, "unknown info level");
128 talloc_destroy(mem_ctx);