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", "level", "arch", "creds", NULL};
35 struct cli_state *cli = NULL;
36 TALLOC_CTX *mem_ctx = NULL;
38 /* Parse parameters */
40 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist,
41 &server_name, &level, &arch,
42 &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 = PyList_New(num_drivers);
78 for (i = 0; i < num_drivers; i++) {
81 py_from_DRIVER_INFO_1(&value, ctr.info1);
82 PyList_SetItem(result, i, value);
87 result = PyList_New(num_drivers);
89 for(i = 0; i < num_drivers; i++) {
92 py_from_DRIVER_INFO_2(&value, ctr.info2);
93 PyList_SetItem(result, i, value);
98 result = PyList_New(num_drivers);
100 for(i = 0; i < num_drivers; i++) {
103 py_from_DRIVER_INFO_6(&value, ctr.info6);
104 PyList_SetItem(result, i, value);
118 talloc_destroy(mem_ctx);
124 /* Fetch printer driver */
126 PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args,
129 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
131 PyObject *result = Py_None;
132 PRINTER_DRIVER_CTR ctr;
135 char *arch = "Windows NT x86";
136 static char *kwlist[] = {"level", "arch", NULL};
138 /* Parse parameters */
140 if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
144 /* Call rpc function */
146 werror = cli_spoolss_getprinterdriver(
147 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
150 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
151 werror = cli_spoolss_getprinterdriver(
152 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
155 if (!W_ERROR_IS_OK(werror)) {
156 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
164 py_from_DRIVER_INFO_1(&result, ctr.info1);
167 py_from_DRIVER_INFO_2(&result, ctr.info2);
170 py_from_DRIVER_INFO_6(&result, ctr.info6);
180 /* Fetch printer driver directory */
182 PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
186 PyObject *result = Py_None, *creds = NULL;
187 DRIVER_DIRECTORY_CTR ctr;
188 uint32 needed, level;
189 char *arch = "Windows NT x86", *server_name;
190 static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
191 struct cli_state *cli = NULL;
192 TALLOC_CTX *mem_ctx = NULL;
194 /* Parse parameters */
196 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist,
197 &server_name, &level, &arch,
198 &PyDict_Type, &creds))
201 /* Call rpc function */
203 if (!(cli = open_pipe_creds(server_name, creds,
204 cli_spoolss_initialise, NULL))) {
205 fprintf(stderr, "could not initialise cli state\n");
209 if (!(mem_ctx = talloc_init())) {
210 fprintf(stderr, "unable to initialise talloc context\n");
214 werror = cli_spoolss_getprinterdriverdir(
215 cli, mem_ctx, 0, &needed, level, arch, &ctr);
217 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
218 werror = cli_spoolss_getprinterdriverdir(
219 cli, mem_ctx, needed, NULL, level, arch, &ctr);
221 if (!W_ERROR_IS_OK(werror)) {
222 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
230 py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
239 talloc_destroy(mem_ctx);