| 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 | /* Exceptions this module can raise */
|
|---|
| 24 |
|
|---|
| 25 | PyObject *spoolss_error, *spoolss_werror;
|
|---|
| 26 |
|
|---|
| 27 | /*
|
|---|
| 28 | * Method dispatch table
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | static PyMethodDef spoolss_methods[] = {
|
|---|
| 32 |
|
|---|
| 33 | /* Open/close printer handles */
|
|---|
| 34 |
|
|---|
| 35 | { "openprinter", (PyCFunction)spoolss_openprinter, METH_VARARGS | METH_KEYWORDS,
|
|---|
| 36 | "Open a printer by name in UNC format.\n"
|
|---|
| 37 | "\n"
|
|---|
| 38 | "Optionally a dictionary of (domain, username, password) may be given in\n"
|
|---|
| 39 | "which case they are used when opening the RPC pipe. An access mask may\n"
|
|---|
| 40 | "also be given which defaults to MAXIMUM_ALLOWED_ACCESS.\n"
|
|---|
| 41 | "\n"
|
|---|
| 42 | "Example:\n"
|
|---|
| 43 | "\n"
|
|---|
| 44 | ">>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")"},
|
|---|
| 45 |
|
|---|
| 46 | { "closeprinter", spoolss_closeprinter, METH_VARARGS,
|
|---|
| 47 | "Close a printer handle opened with openprinter or addprinter.\n"
|
|---|
| 48 | "\n"
|
|---|
| 49 | "Example:\n"
|
|---|
| 50 | "\n"
|
|---|
| 51 | ">>> spoolss.closeprinter(hnd)"},
|
|---|
| 52 |
|
|---|
| 53 | { "addprinterex", (PyCFunction)spoolss_addprinterex, METH_VARARGS,
|
|---|
| 54 | "addprinterex()"},
|
|---|
| 55 |
|
|---|
| 56 | /* Server enumeratation functions */
|
|---|
| 57 |
|
|---|
| 58 | { "enumprinters", (PyCFunction)spoolss_enumprinters,
|
|---|
| 59 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 60 | "Enumerate printers on a print server.\n"
|
|---|
| 61 | "\n"
|
|---|
| 62 | "Return a list of printers on a print server. The credentials, info level\n"
|
|---|
| 63 | "and flags may be specified as keyword arguments.\n"
|
|---|
| 64 | "\n"
|
|---|
| 65 | "Example:\n"
|
|---|
| 66 | "\n"
|
|---|
| 67 | ">>> print spoolss.enumprinters(\"\\\\\\\\npsd-pdc2\")\n"
|
|---|
| 68 | "[{'comment': 'i am a comment', 'printer_name': 'meanie', 'flags': 8388608, \n"
|
|---|
| 69 | " 'description': 'meanie,Generic / Text Only,i am a location'}, \n"
|
|---|
| 70 | " {'comment': '', 'printer_name': 'fileprint', 'flags': 8388608, \n"
|
|---|
| 71 | " 'description': 'fileprint,Generic / Text Only,'}]"},
|
|---|
| 72 |
|
|---|
| 73 | { "enumports", (PyCFunction)spoolss_enumports,
|
|---|
| 74 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 75 | "Enumerate ports on a print server.\n"
|
|---|
| 76 | "\n"
|
|---|
| 77 | "Return a list of ports on a print server.\n"
|
|---|
| 78 | "\n"
|
|---|
| 79 | "Example:\n"
|
|---|
| 80 | "\n"
|
|---|
| 81 | ">>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\")\n"
|
|---|
| 82 | "[{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, \n"
|
|---|
| 83 | "{'name': 'COM2:'}, {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]"},
|
|---|
| 84 |
|
|---|
| 85 | { "enumprinterdrivers", (PyCFunction)spoolss_enumprinterdrivers,
|
|---|
| 86 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 87 | "Enumerate printer drivers on a print server.\n"
|
|---|
| 88 | "\n"
|
|---|
| 89 | "Return a list of printer drivers."},
|
|---|
| 90 |
|
|---|
| 91 | /* Miscellaneous other commands */
|
|---|
| 92 |
|
|---|
| 93 | { "getprinterdriverdir", (PyCFunction)spoolss_getprinterdriverdir,
|
|---|
| 94 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 95 | "Return printer driver directory.\n"
|
|---|
| 96 | "\n"
|
|---|
| 97 | "Return the printer driver directory for a given architecture. The\n"
|
|---|
| 98 | "architecture defaults to \"Windows NT x86\"."},
|
|---|
| 99 |
|
|---|
| 100 | /* Other stuff - this should really go into a samba config module
|
|---|
| 101 | but for the moment let's leave it here. */
|
|---|
| 102 |
|
|---|
| 103 | { "setup_logging", (PyCFunction)py_setup_logging,
|
|---|
| 104 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 105 | "Set up debug logging.\n"
|
|---|
| 106 | "\n"
|
|---|
| 107 | "Initialises Samba's debug logging system. One argument is expected which\n"
|
|---|
| 108 | "is a boolean specifying whether debugging is interactive and sent to stdout\n"
|
|---|
| 109 | "or logged to a file.\n"
|
|---|
| 110 | "\n"
|
|---|
| 111 | "Example:\n"
|
|---|
| 112 | "\n"
|
|---|
| 113 | ">>> spoolss.setup_logging(interactive = 1)" },
|
|---|
| 114 |
|
|---|
| 115 | { "get_debuglevel", (PyCFunction)get_debuglevel,
|
|---|
| 116 | METH_VARARGS,
|
|---|
| 117 | "Set the current debug level.\n"
|
|---|
| 118 | "\n"
|
|---|
| 119 | "Example:\n"
|
|---|
| 120 | "\n"
|
|---|
| 121 | ">>> spoolss.get_debuglevel()\n"
|
|---|
| 122 | "0" },
|
|---|
| 123 |
|
|---|
| 124 | { "set_debuglevel", (PyCFunction)set_debuglevel,
|
|---|
| 125 | METH_VARARGS,
|
|---|
| 126 | "Get the current debug level.\n"
|
|---|
| 127 | "\n"
|
|---|
| 128 | "Example:\n"
|
|---|
| 129 | "\n"
|
|---|
| 130 | ">>> spoolss.set_debuglevel(10)" },
|
|---|
| 131 |
|
|---|
| 132 | /* Printer driver routines */
|
|---|
| 133 |
|
|---|
| 134 | { "addprinterdriver", (PyCFunction)spoolss_addprinterdriver,
|
|---|
| 135 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 136 | "Add a printer driver." },
|
|---|
| 137 |
|
|---|
| 138 | { "addprinterdriverex", (PyCFunction)spoolss_addprinterdriverex,
|
|---|
| 139 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 140 | "Add a printer driver." },
|
|---|
| 141 |
|
|---|
| 142 | { "deleteprinterdriver", (PyCFunction)spoolss_deleteprinterdriver,
|
|---|
| 143 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 144 | "Delete a printer driver." },
|
|---|
| 145 |
|
|---|
| 146 | { "deleteprinterdriverex", (PyCFunction)spoolss_deleteprinterdriverex,
|
|---|
| 147 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 148 | "Delete a printer driver." },
|
|---|
| 149 |
|
|---|
| 150 | { NULL }
|
|---|
| 151 | };
|
|---|
| 152 |
|
|---|
| 153 | /* Methods attached to a spoolss handle object */
|
|---|
| 154 |
|
|---|
| 155 | static PyMethodDef spoolss_hnd_methods[] = {
|
|---|
| 156 |
|
|---|
| 157 | /* Printer info */
|
|---|
| 158 |
|
|---|
| 159 | { "getprinter", (PyCFunction)spoolss_hnd_getprinter,
|
|---|
| 160 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 161 | "Get printer information.\n"
|
|---|
| 162 | "\n"
|
|---|
| 163 | "Return a dictionary of print information. The info level defaults to 1.\n"
|
|---|
| 164 | "\n"
|
|---|
| 165 | "Example:\n"
|
|---|
| 166 | "\n"
|
|---|
| 167 | ">>> hnd.getprinter()\n"
|
|---|
| 168 | "{'comment': 'i am a comment', 'printer_name': '\\\\NPSD-PDC2\\meanie',\n"
|
|---|
| 169 | " 'description': '\\\\NPSD-PDC2\\meanie,Generic / Text Only,i am a location',\n"
|
|---|
| 170 | " 'flags': 8388608}"},
|
|---|
| 171 |
|
|---|
| 172 | { "setprinter", (PyCFunction)spoolss_hnd_setprinter,
|
|---|
| 173 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 174 | "Set printer information."},
|
|---|
| 175 |
|
|---|
| 176 | /* Printer drivers */
|
|---|
| 177 |
|
|---|
| 178 | { "getprinterdriver", (PyCFunction)spoolss_hnd_getprinterdriver,
|
|---|
| 179 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 180 | "Return printer driver information.\n"
|
|---|
| 181 | "\n"
|
|---|
| 182 | "Return a dictionary of printer driver information for the printer driver\n"
|
|---|
| 183 | "bound to this printer."},
|
|---|
| 184 |
|
|---|
| 185 | /* Forms */
|
|---|
| 186 |
|
|---|
| 187 | { "enumforms", (PyCFunction)spoolss_hnd_enumforms,
|
|---|
| 188 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 189 | "Enumerate supported forms.\n"
|
|---|
| 190 | "\n"
|
|---|
| 191 | "Return a list of forms supported by this printer or print server."},
|
|---|
| 192 |
|
|---|
| 193 | { "setform", (PyCFunction)spoolss_hnd_setform,
|
|---|
| 194 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 195 | "Set form data.\n"
|
|---|
| 196 | "\n"
|
|---|
| 197 | "Set the form given by the dictionary argument."},
|
|---|
| 198 |
|
|---|
| 199 | { "addform", (PyCFunction)spoolss_hnd_addform,
|
|---|
| 200 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 201 | "Add a new form." },
|
|---|
| 202 |
|
|---|
| 203 | { "getform", (PyCFunction)spoolss_hnd_getform,
|
|---|
| 204 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 205 | "Get form properties." },
|
|---|
| 206 |
|
|---|
| 207 | { "deleteform", (PyCFunction)spoolss_hnd_deleteform,
|
|---|
| 208 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 209 | "Delete a form." },
|
|---|
| 210 |
|
|---|
| 211 | /* Job related methods */
|
|---|
| 212 |
|
|---|
| 213 | { "enumjobs", (PyCFunction)spoolss_hnd_enumjobs,
|
|---|
| 214 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 215 | "Enumerate jobs." },
|
|---|
| 216 |
|
|---|
| 217 | { "setjob", (PyCFunction)spoolss_hnd_setjob,
|
|---|
| 218 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 219 | "Set job information." },
|
|---|
| 220 |
|
|---|
| 221 | { "getjob", (PyCFunction)spoolss_hnd_getjob,
|
|---|
| 222 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 223 | "Get job information." },
|
|---|
| 224 |
|
|---|
| 225 | { "startpageprinter", (PyCFunction)spoolss_hnd_startpageprinter,
|
|---|
| 226 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 227 | "Notify spooler that a page is about to be printed." },
|
|---|
| 228 |
|
|---|
| 229 | { "endpageprinter", (PyCFunction)spoolss_hnd_endpageprinter,
|
|---|
| 230 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 231 | "Notify spooler that a page is about to be printed." },
|
|---|
| 232 |
|
|---|
| 233 | { "startdocprinter", (PyCFunction)spoolss_hnd_startdocprinter,
|
|---|
| 234 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 235 | "Notify spooler that a document is about to be printed." },
|
|---|
| 236 |
|
|---|
| 237 | { "enddocprinter", (PyCFunction)spoolss_hnd_enddocprinter,
|
|---|
| 238 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 239 | "Notify spooler that a document is about to be printed." },
|
|---|
| 240 |
|
|---|
| 241 | { "writeprinter", (PyCFunction)spoolss_hnd_writeprinter,
|
|---|
| 242 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 243 | "Write job data to a printer." },
|
|---|
| 244 |
|
|---|
| 245 | { "addjob", (PyCFunction)spoolss_hnd_addjob,
|
|---|
| 246 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 247 | "Add a job to the list of print jobs." },
|
|---|
| 248 |
|
|---|
| 249 | /* Printer data */
|
|---|
| 250 |
|
|---|
| 251 | { "getprinterdata", (PyCFunction)spoolss_hnd_getprinterdata,
|
|---|
| 252 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 253 | "Get printer data." },
|
|---|
| 254 |
|
|---|
| 255 | { "setprinterdata", (PyCFunction)spoolss_hnd_setprinterdata,
|
|---|
| 256 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 257 | "Set printer data." },
|
|---|
| 258 |
|
|---|
| 259 | { "enumprinterdata", (PyCFunction)spoolss_hnd_enumprinterdata,
|
|---|
| 260 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 261 | "Enumerate printer data." },
|
|---|
| 262 |
|
|---|
| 263 | { "deleteprinterdata", (PyCFunction)spoolss_hnd_deleteprinterdata,
|
|---|
| 264 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 265 | "Delete printer data." },
|
|---|
| 266 |
|
|---|
| 267 | { "getprinterdataex", (PyCFunction)spoolss_hnd_getprinterdataex,
|
|---|
| 268 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 269 | "Get printer data." },
|
|---|
| 270 |
|
|---|
| 271 | { "setprinterdataex", (PyCFunction)spoolss_hnd_setprinterdataex,
|
|---|
| 272 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 273 | "Set printer data." },
|
|---|
| 274 |
|
|---|
| 275 | { "enumprinterdataex", (PyCFunction)spoolss_hnd_enumprinterdataex,
|
|---|
| 276 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 277 | "Enumerate printer data." },
|
|---|
| 278 |
|
|---|
| 279 | { "deleteprinterdataex", (PyCFunction)spoolss_hnd_deleteprinterdataex,
|
|---|
| 280 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 281 | "Delete printer data." },
|
|---|
| 282 |
|
|---|
| 283 | { "enumprinterkey", (PyCFunction)spoolss_hnd_enumprinterkey,
|
|---|
| 284 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 285 | "Enumerate printer key." },
|
|---|
| 286 |
|
|---|
| 287 | #if 0
|
|---|
| 288 | /* Not implemented */
|
|---|
| 289 |
|
|---|
| 290 | { "deleteprinterkey", (PyCFunction)spoolss_hnd_deleteprinterkey,
|
|---|
| 291 | METH_VARARGS | METH_KEYWORDS,
|
|---|
| 292 | "Delete printer key." },
|
|---|
| 293 | #endif
|
|---|
| 294 |
|
|---|
| 295 | { NULL }
|
|---|
| 296 |
|
|---|
| 297 | };
|
|---|
| 298 |
|
|---|
| 299 | static void py_policy_hnd_dealloc(PyObject* self)
|
|---|
| 300 | {
|
|---|
| 301 | spoolss_policy_hnd_object *hnd;
|
|---|
| 302 |
|
|---|
| 303 | /* Close down policy handle and free talloc context */
|
|---|
| 304 |
|
|---|
| 305 | hnd = (spoolss_policy_hnd_object*)self;
|
|---|
| 306 |
|
|---|
| 307 | cli_shutdown(hnd->cli);
|
|---|
| 308 | talloc_destroy(hnd->mem_ctx);
|
|---|
| 309 |
|
|---|
| 310 | PyObject_Del(self);
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname)
|
|---|
| 314 | {
|
|---|
| 315 | return Py_FindMethod(spoolss_hnd_methods, self, attrname);
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | static char spoolss_type_doc[] =
|
|---|
| 319 | "Python wrapper for Windows NT SPOOLSS rpc pipe.";
|
|---|
| 320 |
|
|---|
| 321 | PyTypeObject spoolss_policy_hnd_type = {
|
|---|
| 322 | PyObject_HEAD_INIT(NULL)
|
|---|
| 323 | 0,
|
|---|
| 324 | "spoolss.hnd",
|
|---|
| 325 | sizeof(spoolss_policy_hnd_object),
|
|---|
| 326 | 0,
|
|---|
| 327 | py_policy_hnd_dealloc, /* tp_dealloc*/
|
|---|
| 328 | 0, /* tp_print*/
|
|---|
| 329 | py_policy_hnd_getattr, /* tp_getattr*/
|
|---|
| 330 | 0, /* tp_setattr*/
|
|---|
| 331 | 0, /* tp_compare*/
|
|---|
| 332 | 0, /* tp_repr*/
|
|---|
| 333 | 0, /* tp_as_number*/
|
|---|
| 334 | 0, /* tp_as_sequence*/
|
|---|
| 335 | 0, /* tp_as_mapping*/
|
|---|
| 336 | 0, /* tp_hash */
|
|---|
| 337 | 0, /* tp_call */
|
|---|
| 338 | 0, /* tp_str */
|
|---|
| 339 | 0, /* tp_getattro */
|
|---|
| 340 | 0, /* tp_setattro */
|
|---|
| 341 | 0, /* tp_as_buffer*/
|
|---|
| 342 | Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|---|
| 343 | spoolss_type_doc, /* tp_doc */
|
|---|
| 344 | };
|
|---|
| 345 |
|
|---|
| 346 | /* Initialise constants */
|
|---|
| 347 |
|
|---|
| 348 | static struct const_vals {
|
|---|
| 349 | char *name;
|
|---|
| 350 | uint32 value;
|
|---|
| 351 | } module_const_vals[] = {
|
|---|
| 352 |
|
|---|
| 353 | /* Access permissions */
|
|---|
| 354 |
|
|---|
| 355 | { "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS },
|
|---|
| 356 | { "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS },
|
|---|
|
|---|