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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "python/py_spoolss.h"
23 static BOOL py_from_printerdata(PyObject **dict, char *key, char *value,
24 uint32 data_type, char *data,
29 PyDict_SetItemString(*dict, "key", Py_BuildValue("s", key ? key : ""));
30 PyDict_SetItemString(*dict, "value", Py_BuildValue("s", value));
31 PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type));
33 PyDict_SetItemString(*dict, "data",
34 Py_BuildValue("s#", data, data_size));
39 static BOOL py_to_printerdata(char **key, char **value, uint32 *data_type,
40 char **data, uint32 *data_size,
45 if ((obj = PyDict_GetItemString(dict, "key"))) {
47 if (!PyString_Check(obj)) {
48 PyErr_SetString(spoolss_error,
53 *key = PyString_AsString(obj);
60 if ((obj = PyDict_GetItemString(dict, "value"))) {
62 if (!PyString_Check(obj)) {
63 PyErr_SetString(spoolss_error,
64 "value not a string");
68 *value = PyString_AsString(obj);
70 PyErr_SetString(spoolss_error, "no value present");
74 if ((obj = PyDict_GetItemString(dict, "type"))) {
76 if (!PyInt_Check(obj)) {
77 PyErr_SetString(spoolss_error,
78 "type not an integer");
82 *data_type = PyInt_AsLong(obj);
84 PyErr_SetString(spoolss_error, "no type present");
88 if ((obj = PyDict_GetItemString(dict, "data"))) {
90 if (!PyString_Check(obj)) {
91 PyErr_SetString(spoolss_error,
96 *data = PyString_AsString(obj);
97 *data_size = PyString_Size(obj);
99 PyErr_SetString(spoolss_error, "no data present");
106 PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw)
108 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
109 static char *kwlist[] = { "value", NULL };
112 uint32 needed, data_type, data_size;
116 /* Parse parameters */
118 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
121 /* Call rpc function */
123 werror = cli_spoolss_getprinterdata(
124 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, value,
125 &data_type, &data, &data_size);
127 if (W_ERROR_V(werror) == ERRmoredata)
128 werror = cli_spoolss_getprinterdata(
129 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, value,
130 &data_type, &data, &data_size);
132 if (!W_ERROR_IS_OK(werror)) {
133 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
137 py_from_printerdata(&result, NULL, value, data_type, data, needed);
142 PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw)
144 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
145 static char *kwlist[] = { "data", NULL };
147 char *key, *value, *data;
148 uint32 data_size, data_type;
151 if (!PyArg_ParseTupleAndKeywords(
152 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
155 if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data))
158 /* Call rpc function */
160 werror = cli_spoolss_setprinterdata(
161 hnd->cli, hnd->mem_ctx, &hnd->pol, value, data_type,
164 if (!W_ERROR_IS_OK(werror)) {
165 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
173 PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw)
175 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
176 static char *kwlist[] = { NULL };
177 uint32 data_needed, value_needed, ndx = 0, data_size, data_type;
182 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
185 /* Get max buffer sizes for value and data */
187 werror = cli_spoolss_enumprinterdata(
188 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0,
189 &value_needed, &data_needed, NULL, NULL, NULL, NULL);
191 if (!W_ERROR_IS_OK(werror)) {
192 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
196 /* Iterate over all printerdata */
198 result = PyDict_New();
200 while (W_ERROR_IS_OK(werror)) {
203 werror = cli_spoolss_enumprinterdata(
204 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx,
205 value_needed, data_needed, NULL, NULL,
206 &value, &data_type, &data, &data_size);
208 if (py_from_printerdata(
209 &obj, NULL, value, data_type, data, data_size))
210 PyDict_SetItemString(result, value, obj);
218 PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw)
220 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
221 static char *kwlist[] = { "value", NULL };
225 /* Parse parameters */
227 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
230 /* Call rpc function */
232 werror = cli_spoolss_deleteprinterdata(
233 hnd->cli, hnd->mem_ctx, &hnd->pol, value);
235 if (!W_ERROR_IS_OK(werror)) {
236 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
244 PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
246 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
247 static char *kwlist[] = { "key", "value", NULL };
250 uint32 needed, data_type, data_size;
254 /* Parse parameters */
256 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value))
259 /* Call rpc function */
261 werror = cli_spoolss_getprinterdataex(
262 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key,
263 value, &data_type, &data, &data_size);
265 if (W_ERROR_V(werror) == ERRmoredata)
266 werror = cli_spoolss_getprinterdataex(
267 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key,
268 value, &data_type, &data, &data_size);
270 if (!W_ERROR_IS_OK(werror)) {
271 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
275 py_from_printerdata(&result, key, value, data_type, data, needed);
280 PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
282 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
283 static char *kwlist[] = { "data", NULL };
285 char *key, *value, *data;
286 uint32 data_size, data_type;
289 if (!PyArg_ParseTupleAndKeywords(
290 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
293 if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data))
296 /* Call rpc function */
298 werror = cli_spoolss_setprinterdataex(
299 hnd->cli, hnd->mem_ctx, &hnd->pol, key, value, data_type,
302 if (!W_ERROR_IS_OK(werror)) {
303 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
311 PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
313 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
314 static char *kwlist[] = { NULL };
315 uint32 needed, returned, i;
319 PRINTER_ENUM_VALUES *values;
321 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key))
324 /* Get max buffer sizes for value and data */
326 werror = cli_spoolss_enumprinterdataex(
327 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key,
330 if (W_ERROR_V(werror) == ERRmoredata)
331 werror = cli_spoolss_enumprinterdataex(
332 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key,
335 if (!W_ERROR_IS_OK(werror)) {
336 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
340 /* Iterate over all printerdata */
342 result = PyDict_New();
344 for (i = 0; i < returned; i++) {
348 rpcstr_pull(value, values[i].valuename.buffer, sizeof(value), -1, STR_TERMINATE);
350 py_from_printerdata(&item, key, value, values[i].type, values[i].data,
353 PyDict_SetItemString(result, value, item);
359 PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
361 PyErr_SetString(spoolss_error, "Not implemented");