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 uint16 data_type, uint8 *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, uint16 *data_type,
40 uint8 **data, uint32 *data_size,
45 if ((obj = PyDict_GetItemString(dict, "key"))) {
47 if (!PyString_Check(obj)) {
48 PyErr_SetString(spoolss_error,
54 *key = PyString_AsString(obj);
62 if ((obj = PyDict_GetItemString(dict, "value"))) {
64 if (!PyString_Check(obj)) {
65 PyErr_SetString(spoolss_error,
66 "value not a string");
70 *value = PyString_AsString(obj);
72 PyErr_SetString(spoolss_error, "no value present");
76 if ((obj = PyDict_GetItemString(dict, "type"))) {
78 if (!PyInt_Check(obj)) {
79 PyErr_SetString(spoolss_error,
80 "type not an integer");
84 *data_type = PyInt_AsLong(obj);
86 PyErr_SetString(spoolss_error, "no type present");
90 if ((obj = PyDict_GetItemString(dict, "data"))) {
92 if (!PyString_Check(obj)) {
93 PyErr_SetString(spoolss_error,
98 *data = PyString_AsString(obj);
99 *data_size = PyString_Size(obj);
101 PyErr_SetString(spoolss_error, "no data present");
108 PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw)
110 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
111 static char *kwlist[] = { "value", NULL };
116 REGISTRY_VALUE value;
118 /* Parse parameters */
120 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &valuename))
123 /* Call rpc function */
125 werror = cli_spoolss_getprinterdata(
126 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, valuename,
129 if (W_ERROR_V(werror) == ERRmoredata)
130 werror = cli_spoolss_getprinterdata(
131 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
134 if (!W_ERROR_IS_OK(werror)) {
135 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
140 &result, NULL, valuename, value.type, value.data_p,
146 PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw)
148 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
149 static char *kwlist[] = { "data", NULL };
153 REGISTRY_VALUE value;
155 if (!PyArg_ParseTupleAndKeywords(
156 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
159 if (!py_to_printerdata(
160 NULL, &valuename, &value.type, &value.data_p,
161 &value.size, py_data))
164 fstrcpy(value.valuename, valuename);
166 /* Call rpc function */
168 werror = cli_spoolss_setprinterdata(
169 hnd->cli, hnd->mem_ctx, &hnd->pol, &value);
171 if (!W_ERROR_IS_OK(werror)) {
172 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
180 PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw)
182 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
183 static char *kwlist[] = { NULL };
184 uint32 data_needed, value_needed, ndx = 0;
187 REGISTRY_VALUE value;
189 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
192 /* Get max buffer sizes for value and data */
194 werror = cli_spoolss_enumprinterdata(
195 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0,
196 &value_needed, &data_needed, NULL);
198 if (!W_ERROR_IS_OK(werror)) {
199 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
203 /* Iterate over all printerdata */
205 result = PyDict_New();
207 while (W_ERROR_IS_OK(werror)) {
210 werror = cli_spoolss_enumprinterdata(
211 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx,
212 value_needed, data_needed, NULL, NULL, &value);
214 if (py_from_printerdata(
215 &obj, NULL, value.valuename, value.type,
216 value.data_p, value.size))
217 PyDict_SetItemString(result, value.valuename, obj);
225 PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw)
227 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
228 static char *kwlist[] = { "value", NULL };
232 /* Parse parameters */
234 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
237 /* Call rpc function */
239 werror = cli_spoolss_deleteprinterdata(
240 hnd->cli, hnd->mem_ctx, &hnd->pol, value);
242 if (!W_ERROR_IS_OK(werror)) {
243 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
251 PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
253 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
254 static char *kwlist[] = { "key", "value", NULL };
255 char *key, *valuename;
259 REGISTRY_VALUE value;
261 /* Parse parameters */
263 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &valuename))
266 /* Call rpc function */
268 werror = cli_spoolss_getprinterdataex(
269 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key,
272 if (W_ERROR_V(werror) == ERRmoredata)
273 werror = cli_spoolss_getprinterdataex(
274 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key,
277 if (!W_ERROR_IS_OK(werror)) {
278 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
283 &result, key, valuename, value.type, value.data_p, value.size);
288 PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
290 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
291 static char *kwlist[] = { "data", NULL };
293 char *keyname, *valuename;
295 REGISTRY_VALUE value;
297 if (!PyArg_ParseTupleAndKeywords(
298 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
301 if (!py_to_printerdata(
302 &keyname, &valuename, &value.type, &value.data_p, &value.size, py_data))
305 fstrcpy(value.valuename, valuename);
307 /* Call rpc function */
309 werror = cli_spoolss_setprinterdataex(
310 hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &value);
312 if (!W_ERROR_IS_OK(werror)) {
313 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
321 PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
323 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
324 static char *kwlist[] = { "key", NULL };
331 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key))
334 /* Get max buffer sizes for value and data */
336 werror = cli_spoolss_enumprinterdataex(
337 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, &ctr);
339 if (W_ERROR_V(werror) == ERRmoredata)
340 werror = cli_spoolss_enumprinterdataex(
341 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key,
344 if (!W_ERROR_IS_OK(werror)) {
345 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
349 /* Iterate over all printerdata */
351 result = PyDict_New();
353 for (i = 0; i < regval_ctr_numvals(&ctr); i++) {
354 REGISTRY_VALUE *value;
358 value = regval_ctr_specific_value(&ctr, i);
360 if (py_from_printerdata(
361 &item, key, value->valuename, value->type,
362 value->data_p, value->size))
363 PyDict_SetItemString(result, value->valuename, item);
369 PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
371 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
372 static char *kwlist[] = { "key", "value", NULL };
376 /* Parse parameters */
378 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value))
381 /* Call rpc function */
383 werror = cli_spoolss_deleteprinterdataex(
384 hnd->cli, hnd->mem_ctx, &hnd->pol, key, value);
386 if (!W_ERROR_IS_OK(werror)) {
387 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
395 PyObject *spoolss_hnd_enumprinterkey(PyObject *self, PyObject *args,
398 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
399 static char *kwlist[] = { "key", NULL };
402 uint32 needed, keylist_len;
406 /* Parse parameters */
408 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))
411 /* Call rpc function */
413 werror = cli_spoolss_enumprinterkey(
414 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol,
415 keyname, &keylist, &keylist_len);
417 if (W_ERROR_V(werror) == ERRmoredata)
418 werror = cli_spoolss_enumprinterkey(
419 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
420 keyname, &keylist, &keylist_len);
422 if (!W_ERROR_IS_OK(werror)) {
423 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
427 result = from_unistr_list(keylist);
434 PyObject *spoolss_hnd_deleteprinterkey(PyObject *self, PyObject *args,
437 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
438 static char *kwlist[] = { "key", NULL };
442 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))