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 = Py_None, *creds = NULL;
30 PRINTER_DRIVER_CTR ctr;
32 uint32 needed, num_drivers;
33 char *arch = "Windows NT x86", *server_name;
34 static char *kwlist[] = {"server", "creds", "level", "arch", NULL};
35 struct cli_state *cli = NULL;
36 TALLOC_CTX *mem_ctx = NULL;
38 /* Parse parameters */
40 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|O!is", kwlist,
41 &server_name, &PyDict_Type, &creds,
45 /* Call rpc function */
47 if (!(cli = open_pipe_creds(server_name, creds,
48 cli_spoolss_initialise, NULL))) {
49 fprintf(stderr, "could not initialise cli state\n");
53 if (!(mem_ctx = talloc_init())) {
54 fprintf(stderr, "unable to initialise talloc context\n");
58 werror = cli_spoolss_enumprinterdrivers(
59 cli, mem_ctx, 0, &needed, level, arch,
62 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
63 werror = cli_spoolss_enumprinterdrivers(
64 cli, mem_ctx, needed, NULL, level, arch,
67 if (!W_ERROR_IS_OK(werror)) {
68 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
76 result = PyDict_New();
78 for (i = 0; i < num_drivers; i++) {
82 rpcstr_pull(name, ctr.info1[i].name.buffer,
83 sizeof(fstring), -1, STR_TERMINATE);
85 py_from_DRIVER_INFO_1(&value, &ctr.info1[i]);
88 value, "level", PyInt_FromLong(1));
90 PyDict_SetItemString(result, name, value);
95 result = PyDict_New();
97 for(i = 0; i < num_drivers; i++) {
101 rpcstr_pull(name, ctr.info2[i].name.buffer,
102 sizeof(fstring), -1, STR_TERMINATE);
104 py_from_DRIVER_INFO_2(&value, &ctr.info2[i]);
106 PyDict_SetItemString(
107 value, "level", PyInt_FromLong(2));
109 PyDict_SetItemString(result, name, value);
114 result = PyDict_New();
116 for(i = 0; i < num_drivers; i++) {
120 rpcstr_pull(name, ctr.info3[i].name.buffer,
121 sizeof(fstring), -1, STR_TERMINATE);
123 py_from_DRIVER_INFO_3(&value, &ctr.info3[i]);
125 PyDict_SetItemString(
126 value, "level", PyInt_FromLong(3));
128 PyDict_SetItemString(result, name, value);
133 result = PyDict_New();
135 for(i = 0; i < num_drivers; i++) {
139 rpcstr_pull(name, ctr.info6[i].name.buffer,
140 sizeof(fstring), -1, STR_TERMINATE);
142 py_from_DRIVER_INFO_6(&value, &ctr.info6[i]);
144 PyDict_SetItemString(
145 value, "level", PyInt_FromLong(6));
147 PyList_SetItem(result, i, value);
152 PyErr_SetString(spoolss_error, "unknown info level returned");
162 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(args, kw, "|is", kwlist,
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_6(&result, ctr.info6);
224 /* Fetch printer driver directory */
226 PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
230 PyObject *result = Py_None, *creds = NULL;
231 DRIVER_DIRECTORY_CTR ctr;
232 uint32 needed, level;
233 char *arch = "Windows NT x86", *server_name;
234 static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
235 struct cli_state *cli = NULL;
236 TALLOC_CTX *mem_ctx = NULL;
238 /* Parse parameters */
240 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist,
241 &server_name, &level, &arch,
242 &PyDict_Type, &creds))
245 /* Call rpc function */
247 if (!(cli = open_pipe_creds(server_name, creds,
248 cli_spoolss_initialise, NULL))) {
249 fprintf(stderr, "could not initialise cli state\n");
253 if (!(mem_ctx = talloc_init())) {
254 fprintf(stderr, "unable to initialise talloc context\n");
258 werror = cli_spoolss_getprinterdriverdir(
259 cli, mem_ctx, 0, &needed, level, arch, &ctr);
261 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
262 werror = cli_spoolss_getprinterdriverdir(
263 cli, mem_ctx, needed, NULL, level, arch, &ctr);
265 if (!W_ERROR_IS_OK(werror)) {
266 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
274 py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
283 talloc_destroy(mem_ctx);
289 PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
292 static char *kwlist[] = { "server", "info", "creds", NULL };
295 PyObject *info, *result = NULL, *creds = NULL, *level_obj;
298 struct cli_state *cli;
299 PRINTER_DRIVER_CTR ctr;
301 DRIVER_INFO_3 driver_3;
304 if (!PyArg_ParseTupleAndKeywords(
305 args, kw, "sO!|O!", kwlist, &server, &PyDict_Type,
306 &info, &PyDict_Type, &creds))
309 if (server[0] == '\\' && server[1] == '\\')
312 mem_ctx = talloc_init();
314 if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise,
318 if ((level_obj = PyDict_GetItemString(info, "level"))) {
320 if (!PyInt_Check(level_obj)) {
321 PyErr_SetString(spoolss_error,
322 "level not an integer");
326 level = PyInt_AsLong(level_obj);
328 /* Only level 2, 3 supported by NT */
331 PyErr_SetString(spoolss_error,
332 "unsupported info level");
337 PyErr_SetString(spoolss_error, "no info level present");
345 ctr.info3 = &dinfo.driver_3;
347 if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info)) {
348 PyErr_SetString(spoolss_error,
349 "error converting to driver info 3");
355 PyErr_SetString(spoolss_error, "unsupported info level");
359 werror = cli_spoolss_addprinterdriver(cli, mem_ctx, level, &ctr);
361 if (!W_ERROR_IS_OK(werror)) {
362 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
371 talloc_destroy(mem_ctx);
376 PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args,
379 /* Not supported by Samba server */
381 PyErr_SetString(spoolss_error, "Not implemented");
385 PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args,
388 PyErr_SetString(spoolss_error, "Not implemented");
392 PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args,
395 PyErr_SetString(spoolss_error, "Not implemented");