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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "python/py_spoolss.h"
22 #include "python/py_conv.h"
24 static BOOL py_from_printerdata(PyObject **dict, char *key, char *value,
25 uint16 data_type, uint8 *data,
30 PyDict_SetItemString(*dict, "key", Py_BuildValue("s", key ? key : ""));
31 PyDict_SetItemString(*dict, "value", Py_BuildValue("s", value));
32 PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type));
34 PyDict_SetItemString(*dict, "data",
35 Py_BuildValue("s#", data, data_size));
40 static BOOL py_to_printerdata(char **key, char **value, uint16 *data_type,
41 uint8 **data, uint32 *data_size,
46 if ((obj = PyDict_GetItemString(dict, "key"))) {
48 if (!PyString_Check(obj)) {
49 PyErr_SetString(spoolss_error,
55 *key = PyString_AsString(obj);
63 if ((obj = PyDict_GetItemString(dict, "value"))) {
65 if (!PyString_Check(obj)) {
66 PyErr_SetString(spoolss_error,
67 "value not a string");
71 *value = PyString_AsString(obj);
73 PyErr_SetString(spoolss_error, "no value present");
77 if ((obj = PyDict_GetItemString(dict, "type"))) {
79 if (!PyInt_Check(obj)) {
80 PyErr_SetString(spoolss_error,
81 "type not an integer");
85 *data_type = PyInt_AsLong(obj);
87 PyErr_SetString(spoolss_error, "no type present");
91 if ((obj = PyDict_GetItemString(dict, "data"))) {
93 if (!PyString_Check(obj)) {
94 PyErr_SetString(spoolss_error,
99 *data = PyString_AsString(obj);
100 *data_size = PyString_Size(obj);
102 PyErr_SetString(spoolss_error, "no data present");
109 PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw)
111 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
112 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 = rpccli_spoolss_getprinterdata(
126 hnd->cli, hnd->mem_ctx, &hnd->pol, valuename,
129 if (!W_ERROR_IS_OK(werror)) {
130 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
135 &result, NULL, valuename, value.type, value.data_p,
141 PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw)
143 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
144 static char *kwlist[] = { "data", NULL };
148 REGISTRY_VALUE value;
150 if (!PyArg_ParseTupleAndKeywords(
151 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
154 if (!py_to_printerdata(
155 NULL, &valuename, &value.type, &value.data_p,
156 &value.size, py_data))
159 fstrcpy(value.valuename, valuename);
161 /* Call rpc function */
163 werror = rpccli_spoolss_setprinterdata(
164 hnd->cli, hnd->mem_ctx, &hnd->pol, &value);
166 if (!W_ERROR_IS_OK(werror)) {
167 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
175 PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw)
177 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
178 static char *kwlist[] = { NULL };
179 uint32 data_needed, value_needed, ndx = 0;
182 REGISTRY_VALUE value;
184 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
187 /* Get max buffer sizes for value and data */
189 werror = rpccli_spoolss_enumprinterdata(
190 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0,
191 &value_needed, &data_needed, NULL);
193 if (!W_ERROR_IS_OK(werror)) {
194 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
198 /* Iterate over all printerdata */
200 result = PyDict_New();
202 while (W_ERROR_IS_OK(werror)) {
205 werror = rpccli_spoolss_enumprinterdata(
206 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx,
207 value_needed, data_needed, NULL, NULL, &value);
209 if (py_from_printerdata(
210 &obj, NULL, value.valuename, value.type,
211 value.data_p, value.size))
212 PyDict_SetItemString(result, value.valuename, obj);
220 PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw)
222 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
223 static char *kwlist[] = { "value", NULL };
227 /* Parse parameters */
229 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
232 /* Call rpc function */
234 werror = rpccli_spoolss_deleteprinterdata(
235 hnd->cli, hnd->mem_ctx, &hnd->pol, value);
237 if (!W_ERROR_IS_OK(werror)) {
238 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
246 PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
248 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
249 static char *kwlist[] = { "key", "value", NULL };
250 char *key, *valuename;
253 REGISTRY_VALUE value;
255 /* Parse parameters */
257 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &valuename))
260 /* Call rpc function */
262 werror = rpccli_spoolss_getprinterdataex(
263 hnd->cli, hnd->mem_ctx, &hnd->pol, key,
266 if (!W_ERROR_IS_OK(werror)) {
267 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
272 &result, key, valuename, value.type, value.data_p, value.size);
277 PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
279 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
280 static char *kwlist[] = { "data", NULL };
282 char *keyname, *valuename;
284 REGISTRY_VALUE value;
286 if (!PyArg_ParseTupleAndKeywords(
287 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
290 if (!py_to_printerdata(
291 &keyname, &valuename, &value.type, &value.data_p, &value.size, py_data))
294 fstrcpy(value.valuename, valuename);
296 /* Call rpc function */
298 werror = rpccli_spoolss_setprinterdataex(
299 hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &value);
301 if (!W_ERROR_IS_OK(werror)) {
302 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
310 PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
312 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
313 static char *kwlist[] = { "key", NULL };
320 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key))
323 if (!(ctr = TALLOC_ZERO_P(hnd->mem_ctx, REGVAL_CTR))) {
324 PyErr_SetString(spoolss_error, "talloc failed");
328 /* Get max buffer sizes for value and data */
330 werror = rpccli_spoolss_enumprinterdataex(
331 hnd->cli, hnd->mem_ctx, &hnd->pol, key, &ctr);
333 if (!W_ERROR_IS_OK(werror)) {
334 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
338 /* Iterate over all printerdata */
340 result = PyDict_New();
342 for (i = 0; i < regval_ctr_numvals(&ctr); i++) {
343 REGISTRY_VALUE *value;
347 value = regval_ctr_specific_value(&ctr, i);
349 if (py_from_printerdata(
350 &item, key, value->valuename, value->type,
351 value->data_p, value->size))
352 PyDict_SetItemString(result, value->valuename, item);
358 PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
360 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
361 static char *kwlist[] = { "key", "value", NULL };
365 /* Parse parameters */
367 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value))
370 /* Call rpc function */
372 werror = rpccli_spoolss_deleteprinterdataex(
373 hnd->cli, hnd->mem_ctx, &hnd->pol, key, value);
375 if (!W_ERROR_IS_OK(werror)) {
376 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
384 PyObject *spoolss_hnd_enumprinterkey(PyObject *self, PyObject *args,
387 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
388 static char *kwlist[] = { "key", NULL };
395 /* Parse parameters */
397 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))
400 /* Call rpc function */
402 werror = rpccli_spoolss_enumprinterkey(
403 hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &keylist,
406 if (!W_ERROR_IS_OK(werror)) {
407 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
411 result = from_unistr_list(keylist);
418 PyObject *spoolss_hnd_deleteprinterkey(PyObject *self, PyObject *args,
421 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
422 static char *kwlist[] = { "key", NULL };
426 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))