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 /* Enumerate printer drivers */
25 PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
29 PyObject *result = NULL, *creds = NULL;
30 PRINTER_DRIVER_CTR ctr;
32 uint32 needed, num_drivers;
33 char *arch = "Windows NT x86", *server, *errstr;
34 static char *kwlist[] = {"server", "level", "creds", "arch", NULL};
35 struct cli_state *cli = NULL;
36 TALLOC_CTX *mem_ctx = NULL;
38 /* Parse parameters */
40 if (!PyArg_ParseTupleAndKeywords(
41 args, kw, "s|iO!s", kwlist, &server, &level, &PyDict_Type,
45 /* Call rpc function */
47 if (!(cli = open_pipe_creds(
48 server, creds, cli_spoolss_initialise, &errstr))) {
49 PyErr_SetString(spoolss_error, errstr);
54 if (!(mem_ctx = talloc_init())) {
56 spoolss_error, "unable to init talloc context\n");
60 werror = cli_spoolss_enumprinterdrivers(
61 cli, mem_ctx, 0, &needed, level, arch,
64 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
65 werror = cli_spoolss_enumprinterdrivers(
66 cli, mem_ctx, needed, NULL, level, arch,
69 if (!W_ERROR_IS_OK(werror)) {
70 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
78 result = PyDict_New();
80 for (i = 0; i < num_drivers; i++) {
84 rpcstr_pull(name, ctr.info1[i].name.buffer,
85 sizeof(fstring), -1, STR_TERMINATE);
87 py_from_DRIVER_INFO_1(&value, &ctr.info1[i]);
90 value, "level", PyInt_FromLong(1));
92 PyDict_SetItemString(result, name, value);
97 result = PyDict_New();
99 for(i = 0; i < num_drivers; i++) {
103 rpcstr_pull(name, ctr.info2[i].name.buffer,
104 sizeof(fstring), -1, STR_TERMINATE);
106 py_from_DRIVER_INFO_2(&value, &ctr.info2[i]);
108 PyDict_SetItemString(
109 value, "level", PyInt_FromLong(2));
111 PyDict_SetItemString(result, name, value);
116 result = PyDict_New();
118 for(i = 0; i < num_drivers; i++) {
122 rpcstr_pull(name, ctr.info3[i].name.buffer,
123 sizeof(fstring), -1, STR_TERMINATE);
125 py_from_DRIVER_INFO_3(&value, &ctr.info3[i]);
127 PyDict_SetItemString(
128 value, "level", PyInt_FromLong(3));
130 PyDict_SetItemString(result, name, value);
135 result = PyDict_New();
137 for(i = 0; i < num_drivers; i++) {
141 rpcstr_pull(name, ctr.info6[i].name.buffer,
142 sizeof(fstring), -1, STR_TERMINATE);
144 py_from_DRIVER_INFO_6(&value, &ctr.info6[i]);
146 PyDict_SetItemString(
147 value, "level", PyInt_FromLong(6));
149 PyList_SetItem(result, i, value);
154 PyErr_SetString(spoolss_error, "unknown info level");
163 talloc_destroy(mem_ctx);
168 /* Fetch printer driver */
170 PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
173 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
175 PyObject *result = Py_None;
176 PRINTER_DRIVER_CTR ctr;
179 char *arch = "Windows NT x86";
180 static char *kwlist[] = {"level", "arch", NULL};
182 /* Parse parameters */
184 if (!PyArg_ParseTupleAndKeywords(
185 args, kw, "|is", kwlist, &level, &arch))
188 /* Call rpc function */
190 werror = cli_spoolss_getprinterdriver(
191 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
194 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
195 werror = cli_spoolss_getprinterdriver(
196 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
199 if (!W_ERROR_IS_OK(werror)) {
200 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
208 py_from_DRIVER_INFO_1(&result, ctr.info1);
211 py_from_DRIVER_INFO_2(&result, ctr.info2);
214 py_from_DRIVER_INFO_3(&result, ctr.info3);
217 py_from_DRIVER_INFO_6(&result, ctr.info6);
220 PyErr_SetString(spoolss_error, "unsupported info level");
228 /* Fetch printer driver directory */
230 PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
234 PyObject *result = NULL, *creds = NULL;
235 DRIVER_DIRECTORY_CTR ctr;
236 uint32 needed, level = 1;
237 char *arch = "Windows NT x86", *server, *errstr;
238 static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
239 struct cli_state *cli = NULL;
240 TALLOC_CTX *mem_ctx = NULL;
242 /* Parse parameters */
244 if (!PyArg_ParseTupleAndKeywords(
245 args, kw, "s|isO!", kwlist, &server, &level,
246 &arch, &PyDict_Type, &creds))
249 /* Call rpc function */
251 if (!(cli = open_pipe_creds(
252 server, creds, cli_spoolss_initialise, &errstr))) {
253 PyErr_SetString(spoolss_error, errstr);
258 if (!(mem_ctx = talloc_init())) {
260 spoolss_error, "unable to init talloc context\n");
264 werror = cli_spoolss_getprinterdriverdir(
265 cli, mem_ctx, 0, &needed, level, arch, &ctr);
267 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
268 werror = cli_spoolss_getprinterdriverdir(
269 cli, mem_ctx, needed, NULL, level, arch, &ctr);
271 if (!W_ERROR_IS_OK(werror)) {
272 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
280 py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
281 PyDict_SetItemString(
282 result, "level", PyInt_FromLong(1));
285 PyErr_SetString(spoolss_error, "unknown info level");
294 talloc_destroy(mem_ctx);
299 PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
302 static char *kwlist[] = { "server", "info", "creds", NULL };
303 char *server, *errstr;
305 PyObject *info, *result = NULL, *creds = NULL;
308 struct cli_state *cli;
309 PRINTER_DRIVER_CTR ctr;
311 DRIVER_INFO_3 driver_3;
314 if (!PyArg_ParseTupleAndKeywords(
315 args, kw, "sO!|O!", kwlist, &server, &PyDict_Type,
316 &info, &PyDict_Type, &creds))
319 if (server[0] == '\\' && server[1] == '\\')
322 if (!(mem_ctx = talloc_init())) {
324 spoolss_error, "unable to init talloc context\n");
328 if (!(cli = open_pipe_creds(
329 server, creds, cli_spoolss_initialise, &errstr))) {
330 PyErr_SetString(spoolss_error, errstr);
335 if (!get_level_value(info, &level)) {
336 PyErr_SetString(spoolss_error, "invalid info level");
341 PyErr_SetString(spoolss_error, "unsupported info level");
349 ctr.info3 = &dinfo.driver_3;
351 if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info)) {
352 PyErr_SetString(spoolss_error,
353 "error converting to driver info 3");
359 PyErr_SetString(spoolss_error, "unsupported info level");
363 werror = cli_spoolss_addprinterdriver(cli, mem_ctx, level, &ctr);
365 if (!W_ERROR_IS_OK(werror)) {
366 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
375 talloc_destroy(mem_ctx);
381 PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args,
384 /* Not supported by Samba server */
386 PyErr_SetString(spoolss_error, "Not implemented");
390 PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args,
393 PyErr_SetString(spoolss_error, "Not implemented");
397 PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args,
400 PyErr_SetString(spoolss_error, "Not implemented");