関数 | |
PyObject * | spoolss_enumports (PyObject *self, PyObject *args, PyObject *kw) |
PyObject* spoolss_enumports | ( | PyObject * | self, | |
PyObject * | args, | |||
PyObject * | kw | |||
) |
py_spoolss_ports.c の 25 行で定義されています。
参照先 UNISTR::buffer・cli・cli_shutdown()・port_info_ctr_info::info_1・port_info_ctr_info::info_2・level・name・open_pipe_creds()・cli_state::pipe_list・port_info_ctr_info::port・s_port_info_2::port_name・s_port_info_1::port_name・py_from_PORT_INFO_1()・py_from_PORT_INFO_2()・py_werror_tuple()・result・rpccli_spoolss_enum_ports()・rpcstr_pull()・server・spoolss_error・spoolss_werror・talloc_init()・werror.
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 }