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 /* Exceptions this module can raise */
25 PyObject *spoolss_error, *spoolss_werror;
28 * Routines to convert from python hashes to Samba structures
31 PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,
34 spoolss_policy_hnd_object *o;
36 o = PyObject_New(spoolss_policy_hnd_object, &spoolss_policy_hnd_type);
40 memcpy(&o->pol, pol, sizeof(POLICY_HND));
46 * Method dispatch table
49 static PyMethodDef spoolss_methods[] = {
51 /* Open/close printer handles */
53 { "openprinter", spoolss_openprinter, METH_VARARGS | METH_KEYWORDS,
54 "openprinter(printername, [creds, access]) -> <spoolss hnd object>
56 Open a printer given by printername in UNC format. Optionally a
57 dictionary of (username, password) may be given in which case they are
58 used when opening the RPC pipe. An access mask may also be given which
59 defaults to MAXIMUM_ALLOWED_ACCESS.
63 >>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")
66 { "closeprinter", spoolss_closeprinter, METH_VARARGS,
69 Close a printer handle opened with openprinter or addprinter.
73 >>> spoolss.closeprinter(hnd)
76 /* Server enumeratation functions */
78 { "enumprinters", spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS,
79 "enumprinters(server, [creds, level, flags]) -> list
81 Return a list of printers on a print server. The credentials, info level
82 and flags may be specified as keyword arguments.
86 >>> print spoolss.enumprinters(\"\\\\\\\\npsd-pdc2\")
87 [{'comment': 'i am a comment', 'printer_name': 'meanie', 'flags': 8388608,
88 'description': 'meanie,Generic / Text Only,i am a location'},
89 {'comment': '', 'printer_name': 'fileprint', 'flags': 8388608,
90 'description': 'fileprint,Generic / Text Only,'}]
93 { "enumports", spoolss_enumports, METH_VARARGS | METH_KEYWORDS,
94 "enumports(server, [creds, level]) -> list
96 Return a list of ports on a print server.
100 >>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\")
101 [{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, {'name': 'COM2:'},
102 {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]
105 { "enumprinterdrivers", spoolss_enumprinterdrivers, METH_VARARGS |
107 "enumprinterdrivers(server, [level, arch, creds]) -> list
109 Return a list of printer drivers.
111 /* Miscellaneous other commands */
113 { "getprinterdriverdir", spoolss_getprinterdriverdir, METH_VARARGS |
114 METH_KEYWORDS, "getprinterdriverdir(server, [creds]) -> string
116 Return the printer driver directory for a given architecture. The
117 architecture defaults to \"Windows NT x86\".
120 /* Other stuff - this should really go into a samba config module
121 but for the moment let's leave it here. */
123 { "setup_logging", py_setup_logging, METH_VARARGS | METH_KEYWORDS,
126 { "get_debuglevel", get_debuglevel, METH_VARARGS, "" },
127 { "set_debuglevel", set_debuglevel, METH_VARARGS, "" },
132 /* Methods attached to a spoolss handle object */
134 static PyMethodDef spoolss_hnd_methods[] = {
138 { "getprinter", spoolss_getprinter, METH_VARARGS | METH_KEYWORDS,
139 "getprinter([level]) -> dict
141 Return a dictionary of print information. The info level defaults to 1.
146 {'comment': 'i am a comment', 'printer_name': '\\\\NPSD-PDC2\\meanie',
147 'description': '\\\\NPSD-PDC2\\meanie,Generic / Text Only,i am a location',
151 { "setprinter", spoolss_setprinter, METH_VARARGS | METH_KEYWORDS,
152 "setprinter(dict) -> None
154 Set printer information.
157 /* Printer drivers */
159 { "getprinterdriver", spoolss_getprinterdriver,
160 METH_VARARGS | METH_KEYWORDS,
161 "getprinterdriver([level = 1, arch = \"Windows NT x86\"] -> dict
163 Return a dictionary of printer driver information.
168 { "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS,
169 "enumforms([level = 1]) -> list
171 Return a list of forms supported by a printer.
174 { "setform", spoolss_setform, METH_VARARGS | METH_KEYWORDS,
175 "setform(dict) -> None
177 Set the form given by the dictionary argument.
180 { "addform", spoolss_addform, METH_VARARGS | METH_KEYWORDS,
183 { "getform", spoolss_getform, METH_VARARGS | METH_KEYWORDS,
184 "Fetch form properties" },
186 { "deleteform", spoolss_deleteform, METH_VARARGS | METH_KEYWORDS,
193 static void py_policy_hnd_dealloc(PyObject* self)
195 spoolss_policy_hnd_object *hnd;
197 /* Close down policy handle and free talloc context */
199 hnd = (spoolss_policy_hnd_object*)self;
201 cli_shutdown(hnd->cli);
202 talloc_destroy(hnd->mem_ctx);
207 static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname)
209 return Py_FindMethod(spoolss_hnd_methods, self, attrname);
212 static char spoolss_type_doc[] =
213 "Python wrapper for Windows NT SPOOLSS rpc pipe.";
215 PyTypeObject spoolss_policy_hnd_type = {
216 PyObject_HEAD_INIT(NULL)
219 sizeof(spoolss_policy_hnd_object),
221 py_policy_hnd_dealloc, /* tp_dealloc*/
223 py_policy_hnd_getattr, /* tp_getattr*/
228 0, /* tp_as_sequence*/
229 0, /* tp_as_mapping*/
236 Py_TPFLAGS_DEFAULT, /* tp_flags */
237 spoolss_type_doc, /* tp_doc */
240 /* Initialise constants */
242 struct spoolss_const {
245 } spoolss_const_vals[] = {
247 /* Access permissions */
249 { "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS },
250 { "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS },
251 { "SERVER_READ", SERVER_READ },
252 { "SERVER_WRITE", SERVER_WRITE },
253 { "SERVER_EXECUTE", SERVER_EXECUTE },
254 { "SERVER_ACCESS_ADMINISTER", SERVER_ACCESS_ADMINISTER },
255 { "SERVER_ACCESS_ENUMERATE", SERVER_ACCESS_ENUMERATE },
256 { "PRINTER_ALL_ACCESS", PRINTER_ALL_ACCESS },
257 { "PRINTER_READ", PRINTER_READ },
258 { "PRINTER_WRITE", PRINTER_WRITE },
259 { "PRINTER_EXECUTE", PRINTER_EXECUTE },
260 { "PRINTER_ACCESS_ADMINISTER", PRINTER_ACCESS_ADMINISTER },
261 { "PRINTER_ACCESS_USE", PRINTER_ACCESS_USE },
262 { "JOB_ACCESS_ADMINISTER", JOB_ACCESS_ADMINISTER },
263 { "JOB_ALL_ACCESS", JOB_ALL_ACCESS },
264 { "JOB_READ", JOB_READ },
265 { "JOB_WRITE", JOB_WRITE },
266 { "JOB_EXECUTE", JOB_EXECUTE },
267 { "STANDARD_RIGHTS_ALL_ACCESS", STANDARD_RIGHTS_ALL_ACCESS },
268 { "STANDARD_RIGHTS_EXECUTE_ACCESS", STANDARD_RIGHTS_EXECUTE_ACCESS },
269 { "STANDARD_RIGHTS_READ_ACCESS", STANDARD_RIGHTS_READ_ACCESS },
270 { "STANDARD_RIGHTS_REQUIRED_ACCESS", STANDARD_RIGHTS_REQUIRED_ACCESS },
271 { "STANDARD_RIGHTS_WRITE_ACCESS", STANDARD_RIGHTS_WRITE_ACCESS },
273 /* Printer enumeration flags */
275 { "PRINTER_ENUM_DEFAULT", PRINTER_ENUM_DEFAULT },
276 { "PRINTER_ENUM_LOCAL", PRINTER_ENUM_LOCAL },
277 { "PRINTER_ENUM_CONNECTIONS", PRINTER_ENUM_CONNECTIONS },
278 { "PRINTER_ENUM_FAVORITE", PRINTER_ENUM_FAVORITE },
279 { "PRINTER_ENUM_NAME", PRINTER_ENUM_NAME },
280 { "PRINTER_ENUM_REMOTE", PRINTER_ENUM_REMOTE },
281 { "PRINTER_ENUM_SHARED", PRINTER_ENUM_SHARED },
282 { "PRINTER_ENUM_NETWORK", PRINTER_ENUM_NETWORK },
286 { "FORM_USER", FORM_USER },
287 { "FORM_BUILTIN", FORM_BUILTIN },
288 { "FORM_PRINTER", FORM_PRINTER },
293 { "WERR_BADFILE", 2 },
294 { "WERR_ACCESS_DENIED", 5 },
295 { "WERR_BADFID", 6 },
296 { "WERR_BADFUNC", 1 },
297 { "WERR_INSUFFICIENT_BUFFER", 122 },
298 { "WERR_NO_SUCH_SHARE", 67 },
299 { "WERR_ALREADY_EXISTS", 80 },
300 { "WERR_INVALID_PARAM", 87 },
301 { "WERR_NOT_SUPPORTED", 50 },
302 { "WERR_BAD_PASSWORD", 86 },
304 { "WERR_INVALID_NAME", 123 },
305 { "WERR_UNKNOWN_LEVEL", 124 },
306 { "WERR_OBJECT_PATH_INVALID", 161 },
307 { "WERR_NO_MORE_ITEMS", 259 },
308 { "WERR_MORE_DATA", 234 },
309 { "WERR_UNKNOWN_PRINTER_DRIVER", 1797 },
310 { "WERR_INVALID_PRINTER_NAME", 1801 },
311 { "WERR_PRINTER_ALREADY_EXISTS", 1802 },
312 { "WERR_INVALID_DATATYPE", 1804 },
313 { "WERR_INVALID_ENVIRONMENT", 1805 },
314 { "WERR_INVALID_FORM_NAME", 1902 },
315 { "WERR_INVALID_FORM_SIZE", 1903 },
316 { "WERR_BUF_TOO_SMALL", 2123 },
317 { "WERR_JOB_NOT_FOUND", 2151 },
318 { "WERR_DEST_NOT_FOUND", 2152 },
319 { "WERR_NOT_LOCAL_DOMAIN", 2320 },
320 { "WERR_PRINTER_DRIVER_IN_USE", 3001 },
321 { "WERR_STATUS_MORE_ENTRIES ", 0x0105 },
326 static void const_init(PyObject *dict)
328 struct spoolss_const *tmp;
331 for (tmp = spoolss_const_vals; tmp->name; tmp++) {
332 obj = PyInt_FromLong(tmp->value);
333 PyDict_SetItemString(dict, tmp->name, obj);
338 /* Module initialisation */
340 void initspoolss(void)
342 PyObject *module, *dict;
344 /* Initialise module */
346 module = Py_InitModule("spoolss", spoolss_methods);
347 dict = PyModule_GetDict(module);
349 /* Exceptions we can raise */
351 spoolss_error = PyErr_NewException("spoolss.error", NULL, NULL);
352 PyDict_SetItemString(dict, "error", spoolss_error);
354 spoolss_werror = PyErr_NewException("spoolss.werror", NULL, NULL);
355 PyDict_SetItemString(dict, "werror", spoolss_werror);
357 /* Initialise policy handle object */
359 spoolss_policy_hnd_type.ob_type = &PyType_Type;
361 PyDict_SetItemString(dict, "spoolss.hnd",
362 (PyObject *)&spoolss_policy_hnd_type);
364 /* Initialise constants */
368 /* Do samba initialisation */