| 1 | /*
|
|---|
| 2 | Python wrappers for DCERPC/SMB client routines.
|
|---|
| 3 |
|
|---|
| 4 | Copyright (C) Tim Potter, 2002
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "python/py_spoolss.h"
|
|---|
| 22 |
|
|---|
| 23 | /* Enumerate printer drivers */
|
|---|
| 24 |
|
|---|
| 25 | PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
|
|---|
| 26 | PyObject *kw)
|
|---|
| 27 | {
|
|---|
| 28 | WERROR werror;
|
|---|
| 29 | PyObject *result = NULL, *creds = NULL;
|
|---|
| 30 | PRINTER_DRIVER_CTR ctr;
|
|---|
| 31 | int level = 1, i;
|
|---|
| 32 | uint32 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;
|
|---|
| 37 |
|
|---|
| 38 | /* Parse parameters */
|
|---|
| 39 |
|
|---|
| 40 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 41 | args, kw, "s|iOs", kwlist, &server, &level, &creds,
|
|---|
| 42 | &arch))
|
|---|
| 43 | return NULL;
|
|---|
| 44 |
|
|---|
| 45 | if (server[0] != '\\' || server[1] != '\\') {
|
|---|
| 46 | PyErr_SetString(PyExc_ValueError, "UNC name required");
|
|---|
| 47 | return NULL;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | server += 2;
|
|---|
| 51 |
|
|---|
| 52 | if (creds && creds != Py_None && !PyDict_Check(creds)) {
|
|---|
| 53 | PyErr_SetString(PyExc_TypeError,
|
|---|
| 54 | "credentials must be dictionary or None");
|
|---|
| 55 | return NULL;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /* Call rpc function */
|
|---|
| 59 |
|
|---|
| 60 | if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
|
|---|
| 61 | PyErr_SetString(spoolss_error, errstr);
|
|---|
| 62 | free(errstr);
|
|---|
| 63 | goto done;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | if (!(mem_ctx = talloc_init("spoolss_enumprinterdrivers"))) {
|
|---|
| 67 | PyErr_SetString(
|
|---|
| 68 | spoolss_error, "unable to init talloc context\n");
|
|---|
| 69 | goto done;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | werror = rpccli_spoolss_enumprinterdrivers(
|
|---|
| 73 | cli->pipe_list, mem_ctx, level, arch,
|
|---|
| 74 | &num_drivers, &ctr);
|
|---|
| 75 |
|
|---|
| 76 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 77 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 78 | goto done;
|
|---|
| 79 | }
|
|---|
|
|---|