python/py_spoolss.c

説明を見る。
00001 /* 
00002    Python wrappers for DCERPC/SMB client routines.
00003 
00004    Copyright (C) Tim Potter, 2002
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "python/py_spoolss.h"
00022 
00023 /* Exceptions this module can raise */
00024 
00025 PyObject *spoolss_error, *spoolss_werror;
00026 
00027 /* 
00028  * Method dispatch table
00029  */
00030 
00031 static PyMethodDef spoolss_methods[] = {
00032 
00033         /* Open/close printer handles */
00034         
00035         { "openprinter", (PyCFunction)spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, 
00036           "Open a printer by name in UNC format.\n"
00037 "\n"
00038 "Optionally a dictionary of (domain, username, password) may be given in\n"
00039 "which case they are used when opening the RPC pipe.  An access mask may\n"
00040 "also be given which defaults to MAXIMUM_ALLOWED_ACCESS.\n"
00041 "\n"
00042 "Example:\n"
00043 "\n"
00044 ">>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")"},
00045         
00046         { "closeprinter", spoolss_closeprinter, METH_VARARGS, 
00047           "Close a printer handle opened with openprinter or addprinter.\n"
00048 "\n"
00049 "Example:\n"
00050 "\n"
00051 ">>> spoolss.closeprinter(hnd)"},
00052 
00053         { "addprinterex", (PyCFunction)spoolss_addprinterex, METH_VARARGS, 
00054           "addprinterex()"},
00055 
00056         /* Server enumeratation functions */
00057 
00058         { "enumprinters", (PyCFunction)spoolss_enumprinters, 
00059           METH_VARARGS | METH_KEYWORDS,
00060           "Enumerate printers on a print server.\n"
00061 "\n"
00062 "Return a list of printers on a print server.  The credentials, info level\n"
00063 "and flags may be specified as keyword arguments.\n"
00064 "\n"
00065 "Example:\n"
00066 "\n"
00067 ">>> print spoolss.enumprinters(\"\\\\\\\\npsd-pdc2\")\n"
00068 "[{'comment': 'i am a comment', 'printer_name': 'meanie', 'flags': 8388608, \n"
00069 "  'description': 'meanie,Generic / Text Only,i am a location'}, \n"
00070 " {'comment': '', 'printer_name': 'fileprint', 'flags': 8388608, \n"
00071 "  'description': 'fileprint,Generic / Text Only,'}]"},
00072 
00073         { "enumports", (PyCFunction)spoolss_enumports, 
00074           METH_VARARGS | METH_KEYWORDS,
00075           "Enumerate ports on a print server.\n"
00076 "\n"
00077 "Return a list of ports on a print server.\n"
00078 "\n"
00079 "Example:\n"
00080 "\n"
00081 ">>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\")\n"
00082 "[{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, \n"
00083 "{'name': 'COM2:'}, {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]"},
00084 
00085         { "enumprinterdrivers", (PyCFunction)spoolss_enumprinterdrivers, 
00086           METH_VARARGS | METH_KEYWORDS, 
00087           "Enumerate printer drivers on a print server.\n"
00088 "\n"
00089 "Return a list of printer drivers."},
00090 
00091         /* Miscellaneous other commands */
00092 
00093         { "getprinterdriverdir", (PyCFunction)spoolss_getprinterdriverdir, 
00094           METH_VARARGS | METH_KEYWORDS, 
00095           "Return printer driver directory.\n"
00096 "\n"
00097 "Return the printer driver directory for a given architecture.  The\n"
00098 "architecture defaults to \"Windows NT x86\"."},
00099 
00100         /* Other stuff - this should really go into a samba config module
00101            but for the moment let's leave it here. */
00102 
00103         { "setup_logging", (PyCFunction)py_setup_logging, 
00104           METH_VARARGS | METH_KEYWORDS, 
00105           "Set up debug logging.\n"
00106 "\n"
00107 "Initialises Samba's debug logging system.  One argument is expected which\n"
00108 "is a boolean specifying whether debugging is interactive and sent to stdout\n"
00109 "or logged to a file.\n"
00110 "\n"
00111 "Example:\n"
00112 "\n"
00113 ">>> spoolss.setup_logging(interactive = 1)" },
00114 
00115         { "get_debuglevel", (PyCFunction)get_debuglevel, 
00116           METH_VARARGS, 
00117           "Set the current debug level.\n"
00118 "\n"
00119 "Example:\n"
00120 "\n"
00121 ">>> spoolss.get_debuglevel()\n"
00122 "0" },
00123 
00124         { "set_debuglevel", (PyCFunction)set_debuglevel, 
00125           METH_VARARGS, 
00126           "Get the current debug level.\n"
00127 "\n"
00128 "Example:\n"
00129 "\n"
00130 ">>> spoolss.set_debuglevel(10)" },
00131 
00132         /* Printer driver routines */
00133         
00134         { "addprinterdriver", (PyCFunction)spoolss_addprinterdriver, 
00135           METH_VARARGS | METH_KEYWORDS, 
00136           "Add a printer driver." },
00137 
00138         { "addprinterdriverex", (PyCFunction)spoolss_addprinterdriverex, 
00139           METH_VARARGS | METH_KEYWORDS, 
00140           "Add a printer driver." },
00141 
00142         { "deleteprinterdriver", (PyCFunction)spoolss_deleteprinterdriver, 
00143           METH_VARARGS | METH_KEYWORDS, 
00144           "Delete a printer driver." },
00145 
00146         { "deleteprinterdriverex", (PyCFunction)spoolss_deleteprinterdriverex, 
00147           METH_VARARGS | METH_KEYWORDS, 
00148           "Delete a printer driver." },
00149 
00150         { NULL }
00151 };
00152 
00153 /* Methods attached to a spoolss handle object */
00154 
00155 static PyMethodDef spoolss_hnd_methods[] = {
00156 
00157         /* Printer info */
00158 
00159         { "getprinter", (PyCFunction)spoolss_hnd_getprinter, 
00160            METH_VARARGS | METH_KEYWORDS,
00161           "Get printer information.\n"
00162 "\n"
00163 "Return a dictionary of print information.  The info level defaults to 1.\n"
00164 "\n"
00165 "Example:\n"
00166 "\n"
00167 ">>> hnd.getprinter()\n"
00168 "{'comment': 'i am a comment', 'printer_name': '\\\\NPSD-PDC2\\meanie',\n"
00169 " 'description': '\\\\NPSD-PDC2\\meanie,Generic / Text Only,i am a location',\n"
00170 " 'flags': 8388608}"},
00171 
00172         { "setprinter", (PyCFunction)spoolss_hnd_setprinter, 
00173           METH_VARARGS | METH_KEYWORDS,
00174           "Set printer information."},
00175 
00176         /* Printer drivers */
00177 
00178         { "getprinterdriver", (PyCFunction)spoolss_hnd_getprinterdriver, 
00179           METH_VARARGS | METH_KEYWORDS, 
00180           "Return printer driver information.\n"
00181 "\n"
00182 "Return a dictionary of printer driver information for the printer driver\n"
00183 "bound to this printer."},
00184 
00185         /* Forms */
00186 
00187         { "enumforms", (PyCFunction)spoolss_hnd_enumforms, 
00188           METH_VARARGS | METH_KEYWORDS,
00189           "Enumerate supported forms.\n"
00190 "\n"
00191 "Return a list of forms supported by this printer or print server."},
00192 
00193         { "setform", (PyCFunction)spoolss_hnd_setform, 
00194           METH_VARARGS | METH_KEYWORDS,
00195           "Set form data.\n"
00196 "\n"
00197 "Set the form given by the dictionary argument."},
00198 
00199         { "addform", (PyCFunction)spoolss_hnd_addform, 
00200           METH_VARARGS | METH_KEYWORDS,
00201           "Add a new form." },
00202 
00203         { "getform", (PyCFunction)spoolss_hnd_getform, 
00204           METH_VARARGS | METH_KEYWORDS,
00205           "Get form properties." },
00206 
00207         { "deleteform", (PyCFunction)spoolss_hnd_deleteform, 
00208           METH_VARARGS | METH_KEYWORDS,
00209           "Delete a form." },
00210 
00211         /* Job related methods */
00212 
00213         { "enumjobs", (PyCFunction)spoolss_hnd_enumjobs, 
00214           METH_VARARGS | METH_KEYWORDS,
00215           "Enumerate jobs." },
00216 
00217         { "setjob", (PyCFunction)spoolss_hnd_setjob, 
00218           METH_VARARGS | METH_KEYWORDS,
00219           "Set job information." },
00220 
00221         { "getjob", (PyCFunction)spoolss_hnd_getjob, 
00222           METH_VARARGS | METH_KEYWORDS,
00223           "Get job information." },
00224 
00225         { "startpageprinter", (PyCFunction)spoolss_hnd_startpageprinter, 
00226            METH_VARARGS | METH_KEYWORDS,
00227           "Notify spooler that a page is about to be printed." },
00228 
00229         { "endpageprinter", (PyCFunction)spoolss_hnd_endpageprinter, 
00230            METH_VARARGS | METH_KEYWORDS,
00231           "Notify spooler that a page is about to be printed." },
00232 
00233         { "startdocprinter", (PyCFunction)spoolss_hnd_startdocprinter, 
00234            METH_VARARGS | METH_KEYWORDS,
00235           "Notify spooler that a document is about to be printed." },
00236 
00237         { "enddocprinter", (PyCFunction)spoolss_hnd_enddocprinter, 
00238            METH_VARARGS | METH_KEYWORDS,
00239           "Notify spooler that a document is about to be printed." },
00240 
00241         { "writeprinter", (PyCFunction)spoolss_hnd_writeprinter,
00242           METH_VARARGS | METH_KEYWORDS,
00243           "Write job data to a printer." },
00244 
00245         { "addjob", (PyCFunction)spoolss_hnd_addjob,
00246           METH_VARARGS | METH_KEYWORDS,
00247           "Add a job to the list of print jobs." },
00248 
00249         /* Printer data */
00250 
00251         { "getprinterdata", (PyCFunction)spoolss_hnd_getprinterdata,
00252            METH_VARARGS | METH_KEYWORDS,
00253           "Get printer data." },
00254 
00255         { "setprinterdata", (PyCFunction)spoolss_hnd_setprinterdata,
00256            METH_VARARGS | METH_KEYWORDS,
00257           "Set printer data." },
00258 
00259         { "enumprinterdata", (PyCFunction)spoolss_hnd_enumprinterdata,
00260            METH_VARARGS | METH_KEYWORDS,
00261           "Enumerate printer data." },
00262 
00263         { "deleteprinterdata", (PyCFunction)spoolss_hnd_deleteprinterdata,
00264            METH_VARARGS | METH_KEYWORDS,
00265           "Delete printer data." },
00266 
00267         { "getprinterdataex", (PyCFunction)spoolss_hnd_getprinterdataex,
00268            METH_VARARGS | METH_KEYWORDS,
00269           "Get printer data." },
00270 
00271         { "setprinterdataex", (PyCFunction)spoolss_hnd_setprinterdataex,
00272            METH_VARARGS | METH_KEYWORDS,
00273           "Set printer data." },
00274 
00275         { "enumprinterdataex", (PyCFunction)spoolss_hnd_enumprinterdataex,
00276            METH_VARARGS | METH_KEYWORDS,
00277           "Enumerate printer data." },
00278 
00279         { "deleteprinterdataex", (PyCFunction)spoolss_hnd_deleteprinterdataex,
00280            METH_VARARGS | METH_KEYWORDS,
00281           "Delete printer data." },
00282 
00283         { "enumprinterkey", (PyCFunction)spoolss_hnd_enumprinterkey,
00284            METH_VARARGS | METH_KEYWORDS,
00285           "Enumerate printer key." },
00286 
00287 #if 0
00288         /* Not implemented */
00289 
00290         { "deleteprinterkey", (PyCFunction)spoolss_hnd_deleteprinterkey,
00291            METH_VARARGS | METH_KEYWORDS,
00292           "Delete printer key." },
00293 #endif
00294 
00295         { NULL }
00296 
00297 };
00298 
00299 static void py_policy_hnd_dealloc(PyObject* self)
00300 {
00301         spoolss_policy_hnd_object *hnd;
00302 
00303         /* Close down policy handle and free talloc context */
00304 
00305         hnd = (spoolss_policy_hnd_object*)self;
00306 
00307         cli_shutdown(hnd->cli);
00308         talloc_destroy(hnd->mem_ctx);
00309 
00310         PyObject_Del(self);
00311 }
00312 
00313 static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname)
00314 {
00315         return Py_FindMethod(spoolss_hnd_methods, self, attrname);
00316 }
00317 
00318 static char spoolss_type_doc[] = 
00319 "Python wrapper for Windows NT SPOOLSS rpc pipe.";
00320 
00321 PyTypeObject spoolss_policy_hnd_type = {
00322         PyObject_HEAD_INIT(NULL)
00323         0,
00324         "spoolss.hnd",
00325         sizeof(spoolss_policy_hnd_object),
00326         0,
00327         py_policy_hnd_dealloc,  /* tp_dealloc*/
00328         0,                      /* tp_print*/
00329         py_policy_hnd_getattr,  /* tp_getattr*/
00330         0,                      /* tp_setattr*/
00331         0,                      /* tp_compare*/
00332         0,                      /* tp_repr*/
00333         0,                      /* tp_as_number*/
00334         0,                      /* tp_as_sequence*/
00335         0,                      /* tp_as_mapping*/
00336         0,                      /* tp_hash */
00337         0,                      /* tp_call */
00338         0,                      /* tp_str */
00339         0,                      /* tp_getattro */
00340         0,                      /* tp_setattro */
00341         0,                      /* tp_as_buffer*/
00342         Py_TPFLAGS_DEFAULT,     /* tp_flags */
00343         spoolss_type_doc,       /* tp_doc */
00344 };
00345 
00346 /* Initialise constants */
00347 
00348 static struct const_vals {
00349         char *name;
00350         uint32 value;
00351 } module_const_vals[] = {
00352         
00353         /* Access permissions */
00354 
00355         { "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS },
00356         { "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS },
00357         { "SERVER_READ", SERVER_READ },
00358         { "SERVER_WRITE", SERVER_WRITE },
00359         { "SERVER_EXECUTE", SERVER_EXECUTE },
00360         { "SERVER_ACCESS_ADMINISTER", SERVER_ACCESS_ADMINISTER },
00361         { "SERVER_ACCESS_ENUMERATE", SERVER_ACCESS_ENUMERATE },
00362         { "PRINTER_ALL_ACCESS", PRINTER_ALL_ACCESS },
00363         { "PRINTER_READ", PRINTER_READ },
00364         { "PRINTER_WRITE", PRINTER_WRITE },
00365         { "PRINTER_EXECUTE", PRINTER_EXECUTE },
00366         { "PRINTER_ACCESS_ADMINISTER", PRINTER_ACCESS_ADMINISTER },
00367         { "PRINTER_ACCESS_USE", PRINTER_ACCESS_USE },
00368         { "JOB_ACCESS_ADMINISTER", JOB_ACCESS_ADMINISTER },
00369         { "JOB_ALL_ACCESS", JOB_ALL_ACCESS },
00370         { "JOB_READ", JOB_READ },
00371         { "JOB_WRITE", JOB_WRITE },
00372         { "JOB_EXECUTE", JOB_EXECUTE },
00373         { "STANDARD_RIGHTS_ALL_ACCESS", STANDARD_RIGHTS_ALL_ACCESS },
00374         { "STANDARD_RIGHTS_EXECUTE_ACCESS", STANDARD_RIGHTS_EXECUTE_ACCESS },
00375         { "STANDARD_RIGHTS_READ_ACCESS", STANDARD_RIGHTS_READ_ACCESS },
00376         { "STANDARD_RIGHTS_REQUIRED_ACCESS", STANDARD_RIGHTS_REQUIRED_ACCESS },
00377         { "STANDARD_RIGHTS_WRITE_ACCESS", STANDARD_RIGHTS_WRITE_ACCESS },
00378 
00379         /* Printer enumeration flags */
00380 
00381         { "PRINTER_ENUM_DEFAULT", PRINTER_ENUM_DEFAULT },
00382         { "PRINTER_ENUM_LOCAL", PRINTER_ENUM_LOCAL },
00383         { "PRINTER_ENUM_CONNECTIONS", PRINTER_ENUM_CONNECTIONS },
00384         { "PRINTER_ENUM_FAVORITE", PRINTER_ENUM_FAVORITE },
00385         { "PRINTER_ENUM_NAME", PRINTER_ENUM_NAME },
00386         { "PRINTER_ENUM_REMOTE", PRINTER_ENUM_REMOTE },
00387         { "PRINTER_ENUM_SHARED", PRINTER_ENUM_SHARED },
00388         { "PRINTER_ENUM_NETWORK", PRINTER_ENUM_NETWORK },
00389 
00390         /* Form types */
00391 
00392         { "FORM_USER", FORM_USER },
00393         { "FORM_BUILTIN", FORM_BUILTIN },
00394         { "FORM_PRINTER", FORM_PRINTER },
00395 
00396         /* WERRORs */
00397 
00398         { "WERR_OK", 0 },
00399         { "WERR_BADFILE", 2 },
00400         { "WERR_ACCESS_DENIED", 5 },
00401         { "WERR_BADFID", 6 },
00402         { "WERR_BADFUNC", 1 },
00403         { "WERR_INSUFFICIENT_BUFFER", 122 },
00404         { "WERR_NO_SUCH_SHARE", 67 },
00405         { "WERR_ALREADY_EXISTS", 80 },
00406         { "WERR_INVALID_PARAM", 87 },
00407         { "WERR_NOT_SUPPORTED", 50 },
00408         { "WERR_BAD_PASSWORD", 86 },
00409         { "WERR_NOMEM", 8 },
00410         { "WERR_INVALID_NAME", 123 },
00411         { "WERR_UNKNOWN_LEVEL", 124 },
00412         { "WERR_OBJECT_PATH_INVALID", 161 },
00413         { "WERR_NO_MORE_ITEMS", 259 },
00414         { "WERR_MORE_DATA", 234 },
00415         { "WERR_UNKNOWN_PRINTER_DRIVER", 1797 },
00416         { "WERR_INVALID_PRINTER_NAME", 1801 },
00417         { "WERR_PRINTER_ALREADY_EXISTS", 1802 },
00418         { "WERR_INVALID_DATATYPE", 1804 },
00419         { "WERR_INVALID_ENVIRONMENT", 1805 },
00420         { "WERR_INVALID_FORM_NAME", 1902 },
00421         { "WERR_INVALID_FORM_SIZE", 1903 },
00422         { "WERR_BUF_TOO_SMALL", 2123 },
00423         { "WERR_JOB_NOT_FOUND", 2151 },
00424         { "WERR_DEST_NOT_FOUND", 2152 },
00425         { "WERR_NOT_LOCAL_DOMAIN", 2320 },
00426         { "WERR_PRINTER_DRIVER_IN_USE", 3001 },
00427         { "WERR_STATUS_MORE_ENTRIES  ", 0x0105 },
00428 
00429         /* Job control constants */
00430 
00431         { "JOB_CONTROL_PAUSE", JOB_CONTROL_PAUSE },
00432         { "JOB_CONTROL_RESUME", JOB_CONTROL_RESUME },
00433         { "JOB_CONTROL_CANCEL", JOB_CONTROL_CANCEL },
00434         { "JOB_CONTROL_RESTART", JOB_CONTROL_RESTART },
00435         { "JOB_CONTROL_DELETE", JOB_CONTROL_DELETE },
00436 
00437         { NULL },
00438 };
00439 
00440 static void const_init(PyObject *dict)
00441 {
00442         struct const_vals *tmp;
00443         PyObject *obj;
00444 
00445         for (tmp = module_const_vals; tmp->name; tmp++) {
00446                 obj = PyInt_FromLong(tmp->value);
00447                 PyDict_SetItemString(dict, tmp->name, obj);
00448                 Py_DECREF(obj);
00449         }
00450 }
00451 
00452 /* Module initialisation */
00453 
00454 void initspoolss(void)
00455 {
00456         PyObject *module, *dict;
00457 
00458         /* Initialise module */
00459 
00460         module = Py_InitModule("spoolss", spoolss_methods);
00461         dict = PyModule_GetDict(module);
00462 
00463         /* Exceptions we can raise */
00464 
00465         spoolss_error = PyErr_NewException("spoolss.error", NULL, NULL);
00466         PyDict_SetItemString(dict, "error", spoolss_error);
00467 
00468         spoolss_werror = PyErr_NewException("spoolss.werror", NULL, NULL);
00469         PyDict_SetItemString(dict, "werror", spoolss_werror);
00470 
00471         /* Initialise policy handle object */
00472 
00473         spoolss_policy_hnd_type.ob_type = &PyType_Type;
00474 
00475         PyDict_SetItemString(dict, "spoolss.hnd", 
00476                              (PyObject *)&spoolss_policy_hnd_type);
00477 
00478         /* Initialise constants */
00479 
00480         const_init(dict);
00481 
00482         /* Do samba initialisation */
00483 
00484         py_samba_init();
00485 }

Sambaに対してSat Aug 29 21:23:14 2009に生成されました。  doxygen 1.4.7