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"
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
};
117 REGISTRY_VALUE value
;
119 /* Parse parameters */
121 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "s", kwlist
, &valuename
))
124 /* Call rpc function */
126 werror
= cli_spoolss_getprinterdata(
127 hnd
->cli
, hnd
->mem_ctx
, 0, &needed
, &hnd
->pol
, valuename
,
130 if (W_ERROR_V(werror
) == ERRmoredata
)
131 werror
= cli_spoolss_getprinterdata(
132 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
,
135 if (!W_ERROR_IS_OK(werror
)) {
136 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
141 &result
, NULL
, valuename
, value
.type
, value
.data_p
,
147 PyObject
*spoolss_hnd_setprinterdata(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
149 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
150 static char *kwlist
[] = { "data", NULL
};
154 REGISTRY_VALUE value
;
156 if (!PyArg_ParseTupleAndKeywords(
157 args
, kw
, "O!", kwlist
, &PyDict_Type
, &py_data
))
160 if (!py_to_printerdata(
161 NULL
, &valuename
, &value
.type
, &value
.data_p
,
162 &value
.size
, py_data
))
165 fstrcpy(value
.valuename
, valuename
);
167 /* Call rpc function */
169 werror
= cli_spoolss_setprinterdata(
170 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, &value
);
172 if (!W_ERROR_IS_OK(werror
)) {
173 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
181 PyObject
*spoolss_hnd_enumprinterdata(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
183 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
184 static char *kwlist
[] = { NULL
};
185 uint32 data_needed
, value_needed
, ndx
= 0;
188 REGISTRY_VALUE value
;
190 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
193 /* Get max buffer sizes for value and data */
195 werror
= cli_spoolss_enumprinterdata(
196 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, ndx
, 0, 0,
197 &value_needed
, &data_needed
, NULL
);
199 if (!W_ERROR_IS_OK(werror
)) {
200 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
204 /* Iterate over all printerdata */
206 result
= PyDict_New();
208 while (W_ERROR_IS_OK(werror
)) {
211 werror
= cli_spoolss_enumprinterdata(
212 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, ndx
,
213 value_needed
, data_needed
, NULL
, NULL
, &value
);
215 if (py_from_printerdata(
216 &obj
, NULL
, value
.valuename
, value
.type
,
217 value
.data_p
, value
.size
))
218 PyDict_SetItemString(result
, value
.valuename
, obj
);
226 PyObject
*spoolss_hnd_deleteprinterdata(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
228 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
229 static char *kwlist
[] = { "value", NULL
};
233 /* Parse parameters */
235 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "s", kwlist
, &value
))
238 /* Call rpc function */
240 werror
= cli_spoolss_deleteprinterdata(
241 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, value
);
243 if (!W_ERROR_IS_OK(werror
)) {
244 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
252 PyObject
*spoolss_hnd_getprinterdataex(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
254 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
255 static char *kwlist
[] = { "key", "value", NULL
};
256 char *key
, *valuename
;
260 REGISTRY_VALUE value
;
262 /* Parse parameters */
264 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "ss", kwlist
, &key
, &valuename
))
267 /* Call rpc function */
269 werror
= cli_spoolss_getprinterdataex(
270 hnd
->cli
, hnd
->mem_ctx
, 0, &needed
, &hnd
->pol
, key
,
273 if (W_ERROR_V(werror
) == ERRmoredata
)
274 werror
= cli_spoolss_getprinterdataex(
275 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
, key
,
278 if (!W_ERROR_IS_OK(werror
)) {
279 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
284 &result
, key
, valuename
, value
.type
, value
.data_p
, value
.size
);
289 PyObject
*spoolss_hnd_setprinterdataex(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
291 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
292 static char *kwlist
[] = { "data", NULL
};
294 char *keyname
, *valuename
;
296 REGISTRY_VALUE value
;
298 if (!PyArg_ParseTupleAndKeywords(
299 args
, kw
, "O!", kwlist
, &PyDict_Type
, &py_data
))
302 if (!py_to_printerdata(
303 &keyname
, &valuename
, &value
.type
, &value
.data_p
, &value
.size
, py_data
))
306 fstrcpy(value
.valuename
, valuename
);
308 /* Call rpc function */
310 werror
= cli_spoolss_setprinterdataex(
311 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, keyname
, &value
);
313 if (!W_ERROR_IS_OK(werror
)) {
314 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
322 PyObject
*spoolss_hnd_enumprinterdataex(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
324 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
325 static char *kwlist
[] = { "key", NULL
};
332 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "s", kwlist
, &key
))
335 /* Get max buffer sizes for value and data */
337 werror
= cli_spoolss_enumprinterdataex(
338 hnd
->cli
, hnd
->mem_ctx
, 0, &needed
, &hnd
->pol
, key
, &ctr
);
340 if (W_ERROR_V(werror
) == ERRmoredata
)
341 werror
= cli_spoolss_enumprinterdataex(
342 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
, key
,
345 if (!W_ERROR_IS_OK(werror
)) {
346 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
350 /* Iterate over all printerdata */
352 result
= PyDict_New();
354 for (i
= 0; i
< regval_ctr_numvals(&ctr
); i
++) {
355 REGISTRY_VALUE
*value
;
359 value
= regval_ctr_specific_value(&ctr
, i
);
361 if (py_from_printerdata(
362 &item
, key
, value
->valuename
, value
->type
,
363 value
->data_p
, value
->size
))
364 PyDict_SetItemString(result
, value
->valuename
, item
);
370 PyObject
*spoolss_hnd_deleteprinterdataex(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
372 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
373 static char *kwlist
[] = { "key", "value", NULL
};
377 /* Parse parameters */
379 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "ss", kwlist
, &key
, &value
))
382 /* Call rpc function */
384 werror
= cli_spoolss_deleteprinterdataex(
385 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, key
, value
);
387 if (!W_ERROR_IS_OK(werror
)) {
388 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
396 PyObject
*spoolss_hnd_enumprinterkey(PyObject
*self
, PyObject
*args
,
399 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
400 static char *kwlist
[] = { "key", NULL
};
403 uint32 needed
, keylist_len
;
407 /* Parse parameters */
409 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "s", kwlist
, &keyname
))
412 /* Call rpc function */
414 werror
= cli_spoolss_enumprinterkey(
415 hnd
->cli
, hnd
->mem_ctx
, 0, &needed
, &hnd
->pol
,
416 keyname
, &keylist
, &keylist_len
);
418 if (W_ERROR_V(werror
) == ERRmoredata
)
419 werror
= cli_spoolss_enumprinterkey(
420 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
,
421 keyname
, &keylist
, &keylist_len
);
423 if (!W_ERROR_IS_OK(werror
)) {
424 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
428 result
= from_unistr_list(keylist
);
435 PyObject
*spoolss_hnd_deleteprinterkey(PyObject
*self
, PyObject
*args
,
438 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
439 static char *kwlist
[] = { "key", NULL
};
443 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "s", kwlist
, &keyname
))