python/py_spoolss_ports.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 /* Enumerate ports */
00024 
00025 PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
00026 {
00027         WERROR werror;
00028         PyObject *result = NULL, *creds = NULL;
00029         uint32 level = 1;
00030         uint32 i, needed, num_ports;
00031         static char *kwlist[] = {"server", "level", "creds", NULL};
00032         TALLOC_CTX *mem_ctx = NULL;
00033         struct cli_state *cli = NULL;
00034         char *server, *errstr;
00035         PORT_INFO_CTR ctr;
00036 
00037         /* Parse parameters */
00038 
00039         if (!PyArg_ParseTupleAndKeywords(
00040                     args, kw, "s|iO", kwlist, &server, &level, &creds))
00041                 return NULL;
00042         
00043         if (server[0] != '\\' || server[1] != '\\') {
00044                 PyErr_SetString(PyExc_ValueError, "UNC name required");
00045                 return NULL;
00046         }
00047 
00048         server += 2;
00049 
00050         if (creds && creds != Py_None && !PyDict_Check(creds)) {
00051                 PyErr_SetString(PyExc_TypeError, 
00052                                 "credentials must be dictionary or None");
00053                 return NULL;
00054         }
00055 
00056         if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) {
00057                 PyErr_SetString(spoolss_error, errstr);
00058                 free(errstr);
00059                 goto done;
00060         }
00061 
00062         if (!(mem_ctx = talloc_init("spoolss_enumports"))) {
00063                 PyErr_SetString(
00064                         spoolss_error, "unable to init talloc context\n");
00065                 goto done;
00066         }
00067 
00068         /* Call rpc function */
00069         
00070         werror = rpccli_spoolss_enum_ports( 
00071                 cli->pipe_list, mem_ctx, level, &num_ports, &ctr);
00072 
00073         if (!W_ERROR_IS_OK(werror)) {
00074                 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00075                 goto done;
00076         }
00077 
00078         /* Return value */
00079         
00080         switch (level) {
00081         case 1: 
00082                 result = PyDict_New();
00083 
00084                 for (i = 0; i < num_ports; i++) {
00085                         PyObject *value;
00086                         fstring name;
00087 
00088                         rpcstr_pull(name, ctr.port.info_1[i].port_name.buffer,
00089                                     sizeof(fstring), -1, STR_TERMINATE);
00090 
00091                         py_from_PORT_INFO_1(&value, &ctr.port.info_1[i]);
00092 
00093                         PyDict_SetItemString(
00094                                 value, "level", PyInt_FromLong(1));
00095 
00096                         PyDict_SetItemString(result, name, value);
00097                 }
00098 
00099                 break;
00100         case 2:
00101                 result = PyDict_New();
00102 
00103                 for(i = 0; i < num_ports; i++) {
00104                         PyObject *value;
00105                         fstring name;
00106 
00107                         rpcstr_pull(name, ctr.port.info_2[i].port_name.buffer,
00108                                     sizeof(fstring), -1, STR_TERMINATE);
00109 
00110                         py_from_PORT_INFO_2(&value, &ctr.port.info_2[i]);
00111 
00112                         PyDict_SetItemString(
00113                                 value, "level", PyInt_FromLong(2));
00114 
00115                         PyDict_SetItemString(result, name, value);
00116                 }
00117                 
00118                 break;
00119         default:
00120                 PyErr_SetString(spoolss_error, "unknown info level");
00121                 goto done;
00122         }
00123 
00124  done:
00125         if (cli)
00126                 cli_shutdown(cli);
00127         
00128         if (mem_ctx)
00129                 talloc_destroy(mem_ctx);
00130 
00131         return result;
00132 }

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