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;
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|iOs", kwlist, &server, &level, &creds,
45 if (server[0] != '\\' || server[1] != '\\') {
46 PyErr_SetString(PyExc_ValueError, "UNC name required");
52 if (creds && creds != Py_None && !PyDict_Check(creds)) {
53 PyErr_SetString(PyExc_TypeError,
54 "credentials must be dictionary or None");
58 /* Call rpc function */
60 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
61 PyErr_SetString(spoolss_error, errstr);
66 if (!(mem_ctx = talloc_init("spoolss_enumprinterdrivers"))) {
68 spoolss_error, "unable to init talloc context\n");
72 werror = rpccli_spoolss_enumprinterdrivers(
73 cli, mem_ctx, level, arch,
76 if (!W_ERROR_IS_OK(werror)) {
77 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
85 result = PyDict_New();
87 for (i = 0; i < num_drivers; i++) {
91 rpcstr_pull(name, ctr.info1[i].name.buffer,
92 sizeof(fstring), -1, STR_TERMINATE);
94 py_from_DRIVER_INFO_1(&value, &ctr.info1[i]);
96 PyDict_SetItemString(result, name, value);
101 result = PyDict_New();
103 for(i = 0; i < num_drivers; i++) {
107 rpcstr_pull(name, ctr.info2[i].name.buffer,
108 sizeof(fstring), -1, STR_TERMINATE);
110 py_from_DRIVER_INFO_2(&value, &ctr.info2[i]);
112 PyDict_SetItemString(result, name, value);
117 result = PyDict_New();
119 for(i = 0; i < num_drivers; i++) {
123 rpcstr_pull(name, ctr.info3[i].name.buffer,
124 sizeof(fstring), -1, STR_TERMINATE);
126 py_from_DRIVER_INFO_3(&value, &ctr.info3[i]);
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 PyList_SetItem(result, i, value);
149 PyErr_SetString(spoolss_error, "unknown info level");
158 talloc_destroy(mem_ctx);
163 /* Fetch printer driver */
165 PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
168 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
170 PyObject *result = Py_None;
171 PRINTER_DRIVER_CTR ctr;
173 char *arch = "Windows NT x86";
175 static char *kwlist[] = {"level", "arch", NULL};
177 /* Parse parameters */
179 if (!PyArg_ParseTupleAndKeywords(
180 args, kw, "|is", kwlist, &level, &arch))
183 /* Call rpc function */
185 werror = rpccli_spoolss_getprinterdriver(
186 hnd->cli, hnd->mem_ctx, &hnd->pol, level, arch, version, &ctr);
188 if (!W_ERROR_IS_OK(werror)) {
189 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
197 py_from_DRIVER_INFO_1(&result, ctr.info1);
200 py_from_DRIVER_INFO_2(&result, ctr.info2);
203 py_from_DRIVER_INFO_3(&result, ctr.info3);
206 py_from_DRIVER_INFO_6(&result, ctr.info6);
209 PyErr_SetString(spoolss_error, "unsupported info level");
217 /* Fetch printer driver directory */
219 PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
223 PyObject *result = NULL, *creds = NULL;
224 DRIVER_DIRECTORY_CTR ctr;
226 char *arch = "Windows NT x86", *server, *errstr;
227 static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
228 struct cli_state *cli = NULL;
229 TALLOC_CTX *mem_ctx = NULL;
231 /* Parse parameters */
233 if (!PyArg_ParseTupleAndKeywords(
234 args, kw, "s|isO", kwlist, &server, &level,
238 if (server[0] != '\\' || server[1] != '\\') {
239 PyErr_SetString(PyExc_ValueError, "UNC name required");
245 if (creds && creds != Py_None && !PyDict_Check(creds)) {
246 PyErr_SetString(PyExc_TypeError,
247 "credentials must be dictionary or None");
251 /* Call rpc function */
253 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
254 PyErr_SetString(spoolss_error, errstr);
259 if (!(mem_ctx = talloc_init("spoolss_getprinterdriverdir"))) {
261 spoolss_error, "unable to init talloc context\n");
265 werror = rpccli_spoolss_getprinterdriverdir(
266 cli, mem_ctx, level, arch, &ctr);
268 if (!W_ERROR_IS_OK(werror)) {
269 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
277 py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
280 PyErr_SetString(spoolss_error, "unknown info level");
289 talloc_destroy(mem_ctx);
294 PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
297 static char *kwlist[] = { "server", "info", "creds", NULL };
298 char *server, *errstr;
300 PyObject *info, *result = NULL, *creds = NULL;
302 TALLOC_CTX *mem_ctx = NULL;
303 struct cli_state *cli = NULL;
304 PRINTER_DRIVER_CTR ctr;
306 DRIVER_INFO_3 driver_3;
309 if (!PyArg_ParseTupleAndKeywords(
310 args, kw, "sO!|O", kwlist, &server, &PyDict_Type,
314 if (server[0] == '\\' || server[1] == '\\')
317 if (creds && creds != Py_None && !PyDict_Check(creds)) {
318 PyErr_SetString(PyExc_TypeError,
319 "credentials must be dictionary or None");
323 if (!(mem_ctx = talloc_init("spoolss_addprinterdriver"))) {
325 spoolss_error, "unable to init talloc context\n");
329 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &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");
350 ctr.info3 = &dinfo.driver_3;
352 if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info, mem_ctx)) {
353 PyErr_SetString(spoolss_error,
354 "error converting to driver info 3");
360 PyErr_SetString(spoolss_error, "unsupported info level");
364 werror = rpccli_spoolss_addprinterdriver(cli, mem_ctx, level, &ctr);
366 if (!W_ERROR_IS_OK(werror)) {
367 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
379 talloc_destroy(mem_ctx);
385 PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args,
388 /* Not supported by Samba server */
390 PyErr_SetString(spoolss_error, "Not implemented");
394 PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args,
397 PyErr_SetString(spoolss_error, "Not implemented");
401 PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args,
404 PyErr_SetString(spoolss_error, "Not implemented");