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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "python/py_spoolss.h"
22 /* Enumerate printer drivers */
24 PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
28 PyObject *result = NULL, *creds = NULL;
29 PRINTER_DRIVER_CTR ctr;
32 char *arch = "Windows NT x86", *server, *errstr;
33 static char *kwlist[] = {"server", "level", "creds", "arch", NULL};
34 struct cli_state *cli = NULL;
35 TALLOC_CTX *mem_ctx = NULL;
37 /* Parse parameters */
39 if (!PyArg_ParseTupleAndKeywords(
40 args, kw, "s|iOs", kwlist, &server, &level, &creds,
44 if (server[0] != '\\' || server[1] != '\\') {
45 PyErr_SetString(PyExc_ValueError, "UNC name required");
51 if (creds && creds != Py_None && !PyDict_Check(creds)) {
52 PyErr_SetString(PyExc_TypeError,
53 "credentials must be dictionary or None");
57 /* Call rpc function */
59 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
60 PyErr_SetString(spoolss_error, errstr);
65 if (!(mem_ctx = talloc_init("spoolss_enumprinterdrivers"))) {
67 spoolss_error, "unable to init talloc context\n");
71 werror = rpccli_spoolss_enumprinterdrivers(
72 cli->pipe_list, mem_ctx, level, arch,
75 if (!W_ERROR_IS_OK(werror)) {
76 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
84 result = PyDict_New();
86 for (i = 0; i < num_drivers; i++) {
90 rpcstr_pull(name, ctr.info1[i].name.buffer,
91 sizeof(fstring), -1, STR_TERMINATE);
93 py_from_DRIVER_INFO_1(&value, &ctr.info1[i]);
95 PyDict_SetItemString(result, name, value);
100 result = PyDict_New();
102 for(i = 0; i < num_drivers; i++) {
106 rpcstr_pull(name, ctr.info2[i].name.buffer,
107 sizeof(fstring), -1, STR_TERMINATE);
109 py_from_DRIVER_INFO_2(&value, &ctr.info2[i]);
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(result, name, value);
132 result = PyDict_New();
134 for(i = 0; i < num_drivers; i++) {
138 rpcstr_pull(name, ctr.info6[i].name.buffer,
139 sizeof(fstring), -1, STR_TERMINATE);
141 py_from_DRIVER_INFO_6(&value, &ctr.info6[i]);
143 PyList_SetItem(result, i, value);
148 PyErr_SetString(spoolss_error, "unknown info level");
157 talloc_destroy(mem_ctx);
162 /* Fetch printer driver */
164 PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args,
167 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
169 PyObject *result = Py_None;
170 PRINTER_DRIVER_CTR ctr;
172 char *arch = "Windows NT x86";
174 static char *kwlist[] = {"level", "arch", NULL};
176 /* Parse parameters */
178 if (!PyArg_ParseTupleAndKeywords(
179 args, kw, "|is", kwlist, &level, &arch))
182 /* Call rpc function */
184 werror = rpccli_spoolss_getprinterdriver(
185 hnd->cli, hnd->mem_ctx, &hnd->pol, level, arch, version, &ctr);
187 if (!W_ERROR_IS_OK(werror)) {
188 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
196 py_from_DRIVER_INFO_1(&result, ctr.info1);
199 py_from_DRIVER_INFO_2(&result, ctr.info2);
202 py_from_DRIVER_INFO_3(&result, ctr.info3);
205 py_from_DRIVER_INFO_6(&result, ctr.info6);
208 PyErr_SetString(spoolss_error, "unsupported info level");
216 /* Fetch printer driver directory */
218 PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
222 PyObject *result = NULL, *creds = NULL;
223 DRIVER_DIRECTORY_CTR ctr;
225 char *arch = "Windows NT x86", *server, *errstr;
226 static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
227 struct cli_state *cli = NULL;
228 TALLOC_CTX *mem_ctx = NULL;
230 /* Parse parameters */
232 if (!PyArg_ParseTupleAndKeywords(
233 args, kw, "s|isO", kwlist, &server, &level,
237 if (server[0] != '\\' || server[1] != '\\') {
238 PyErr_SetString(PyExc_ValueError, "UNC name required");
244 if (creds && creds != Py_None && !PyDict_Check(creds)) {
245 PyErr_SetString(PyExc_TypeError,
246 "credentials must be dictionary or None");
250 /* Call rpc function */
252 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
253 PyErr_SetString(spoolss_error, errstr);
258 if (!(mem_ctx = talloc_init("spoolss_getprinterdriverdir"))) {
260 spoolss_error, "unable to init talloc context\n");
264 werror = rpccli_spoolss_getprinterdriverdir(
265 cli->pipe_list, mem_ctx, level, arch, &ctr);
267 if (!W_ERROR_IS_OK(werror)) {
268 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
276 py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
279 PyErr_SetString(spoolss_error, "unknown info level");
288 talloc_destroy(mem_ctx);
293 PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
296 static char *kwlist[] = { "server", "info", "creds", NULL };
297 char *server, *errstr;
299 PyObject *info, *result = NULL, *creds = NULL;
301 TALLOC_CTX *mem_ctx = NULL;
302 struct cli_state *cli = NULL;
303 PRINTER_DRIVER_CTR ctr;
305 DRIVER_INFO_3 driver_3;
308 if (!PyArg_ParseTupleAndKeywords(
309 args, kw, "sO!|O", kwlist, &server, &PyDict_Type,
313 if (server[0] == '\\' || server[1] == '\\')
316 if (creds && creds != Py_None && !PyDict_Check(creds)) {
317 PyErr_SetString(PyExc_TypeError,
318 "credentials must be dictionary or None");
322 if (!(mem_ctx = talloc_init("spoolss_addprinterdriver"))) {
324 spoolss_error, "unable to init talloc context\n");
328 if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
329 PyErr_SetString(spoolss_error, errstr);
334 if (!get_level_value(info, &level)) {
335 PyErr_SetString(spoolss_error, "invalid info level");
340 PyErr_SetString(spoolss_error, "unsupported info level");
349 ctr.info3 = &dinfo.driver_3;
351 if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info, mem_ctx)) {
352 PyErr_SetString(spoolss_error,
353 "error converting to driver info 3");
359 PyErr_SetString(spoolss_error, "unsupported info level");
363 werror = rpccli_spoolss_addprinterdriver(cli->pipe_list, mem_ctx, level, &ctr);
365 if (!W_ERROR_IS_OK(werror)) {
366 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
378 talloc_destroy(mem_ctx);
384 PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args,
387 /* Not supported by Samba server */
389 PyErr_SetString(spoolss_error, "Not implemented");
393 PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args,
396 PyErr_SetString(spoolss_error, "Not implemented");
400 PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args,
403 PyErr_SetString(spoolss_error, "Not implemented");