python/py_srvsvc.c

説明を見る。
00001 /* 
00002    Python wrappers for DCERPC/SMB client routines.
00003 
00004    Copyright (C) Tim Potter, 2003
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_srvsvc.h"
00022 
00023 /* Exceptions this module can raise */
00024 
00025 PyObject *srvsvc_error, *srvsvc_werror;
00026 
00027 static struct const_vals {
00028         char *name;
00029         uint32 value;
00030 } module_const_vals[] = {
00031         { "SV_TYPE_WORKSTATION", SV_TYPE_WORKSTATION },
00032         { "SV_TYPE_SERVER", SV_TYPE_SERVER },
00033         { "SV_TYPE_SQLSERVER", SV_TYPE_SQLSERVER },
00034         { "SV_TYPE_DOMAIN_CTRL", SV_TYPE_DOMAIN_CTRL },
00035         { "SV_TYPE_DOMAIN_BAKCTRL", SV_TYPE_DOMAIN_BAKCTRL },
00036         { "SV_TYPE_TIME_SOURCE", SV_TYPE_TIME_SOURCE },
00037         { "SV_TYPE_AFP", SV_TYPE_AFP },
00038         { "SV_TYPE_NOVELL", SV_TYPE_NOVELL },
00039         { "SV_TYPE_DOMAIN_MEMBER", SV_TYPE_DOMAIN_MEMBER },
00040         { "SV_TYPE_PRINTQ_SERVER", SV_TYPE_PRINTQ_SERVER },
00041         { "SV_TYPE_DIALIN_SERVER", SV_TYPE_DIALIN_SERVER },
00042         { "SV_TYPE_SERVER_UNIX", SV_TYPE_SERVER_UNIX },
00043         { "SV_TYPE_NT", SV_TYPE_NT },
00044         { "SV_TYPE_WFW", SV_TYPE_WFW },
00045         { "SV_TYPE_SERVER_MFPN", SV_TYPE_SERVER_MFPN },
00046         { "SV_TYPE_SERVER_NT", SV_TYPE_SERVER_NT },
00047         { "SV_TYPE_POTENTIAL_BROWSER", SV_TYPE_POTENTIAL_BROWSER },
00048         { "SV_TYPE_BACKUP_BROWSER", SV_TYPE_BACKUP_BROWSER },
00049         { "SV_TYPE_MASTER_BROWSER", SV_TYPE_MASTER_BROWSER },
00050         { "SV_TYPE_DOMAIN_MASTER", SV_TYPE_DOMAIN_MASTER },
00051         { "SV_TYPE_SERVER_OSF", SV_TYPE_SERVER_OSF },
00052         { "SV_TYPE_SERVER_VMS", SV_TYPE_SERVER_VMS },
00053         { "SV_TYPE_WIN95_PLUS", SV_TYPE_WIN95_PLUS },
00054         { "SV_TYPE_DFS_SERVER", SV_TYPE_DFS_SERVER },
00055         { "SV_TYPE_ALTERNATE_XPORT", SV_TYPE_ALTERNATE_XPORT },
00056         { "SV_TYPE_LOCAL_LIST_ONLY", SV_TYPE_LOCAL_LIST_ONLY },
00057         { "SV_TYPE_DOMAIN_ENUM", SV_TYPE_DOMAIN_ENUM },
00058         { NULL },
00059 };
00060 
00061 static void const_init(PyObject *dict)
00062 {
00063         struct const_vals *tmp;
00064         PyObject *obj;
00065 
00066         for (tmp = module_const_vals; tmp->name; tmp++) {
00067                 obj = PyInt_FromLong(tmp->value);
00068                 PyDict_SetItemString(dict, tmp->name, obj);
00069                 Py_DECREF(obj);
00070         }
00071 }
00072 
00073 /* NetServerGetInfo */
00074 
00075 PyObject *srvsvc_netservergetinfo(PyObject *self, PyObject *args,
00076                                   PyObject *kw)
00077 {
00078         static char *kwlist[] = { "server", "level", "creds", NULL };
00079         char *unc_name, *server, *errstr;
00080         PyObject *creds = NULL, *result = NULL;
00081         struct cli_state *cli;
00082         TALLOC_CTX *mem_ctx = NULL;
00083         uint32 level;
00084         SRV_INFO_CTR ctr;
00085         WERROR status;
00086 
00087         if (!PyArg_ParseTupleAndKeywords(
00088                     args, kw, "si|O", kwlist, &unc_name, &level, &creds))
00089                 return NULL;
00090 
00091         if (unc_name[0] != '\\' || unc_name[1] != '\\') {
00092                 PyErr_SetString(PyExc_ValueError, "UNC name required");
00093                 return NULL;
00094         }
00095 
00096         server = SMB_STRDUP(unc_name + 2);
00097 
00098         if (strchr(server, '\\')) {
00099                 char *c = strchr(server, '\\');
00100                 *c = 0;
00101         }
00102 
00103         if (creds && creds != Py_None && !PyDict_Check(creds)) {
00104                 PyErr_SetString(PyExc_TypeError, 
00105                                 "credentials must be dictionary or None");
00106                 return NULL;
00107         }
00108 
00109         if (!(cli = open_pipe_creds(server, creds, PI_SRVSVC, &errstr))) {
00110                 PyErr_SetString(srvsvc_error, errstr);
00111                 free(errstr);
00112                 goto done;
00113         }
00114 
00115         if (!(mem_ctx = talloc_init("srvsvc_netservergetinfo"))) {
00116                 PyErr_SetString(srvsvc_error, 
00117                                 "unable to init talloc context\n");
00118                 goto done;
00119         }
00120 
00121         ZERO_STRUCT(ctr);
00122 
00123         status = rpccli_srvsvc_net_srv_get_info(cli->pipe_list, mem_ctx, level, &ctr);
00124 
00125         if (!W_ERROR_IS_OK(status)) {
00126                 PyErr_SetObject(srvsvc_error, py_werror_tuple(status));
00127                 goto done;
00128         }
00129 
00130         if (level != ctr.switch_value) {
00131                 PyErr_SetString(srvsvc_error, "container level value wrong");
00132                 goto done;
00133         }
00134 
00135         switch(level) {
00136         case 101:
00137                 py_from_SRV_INFO_101(&result, &ctr.srv.sv101);
00138                 break;
00139         }
00140 
00141         Py_INCREF(result);
00142 
00143 done:
00144         if (mem_ctx)
00145                 talloc_destroy(mem_ctx);
00146 
00147         return result;
00148 }
00149 
00150 /*
00151  * Module initialisation 
00152  */
00153 
00154 static PyMethodDef srvsvc_methods[] = {
00155         { "netservergetinfo", (PyCFunction)srvsvc_netservergetinfo,
00156           METH_VARARGS | METH_KEYWORDS,
00157           "Retrieve information about a particular server." },
00158 
00159         { "setup_logging", (PyCFunction)py_setup_logging, 
00160           METH_VARARGS | METH_KEYWORDS, 
00161           "Set up debug logging.\n"
00162 "\n"
00163 "Initialises Samba's debug logging system.  One argument is expected which\n"
00164 "is a boolean specifying whether debugging is interactive and sent to stdout\n"
00165 "or logged to a file.\n"
00166 "\n"
00167 "Example:\n"
00168 "\n"
00169 ">>> srvsvc.setup_logging(interactive = 1)" },
00170 
00171         { "get_debuglevel", (PyCFunction)get_debuglevel, 
00172           METH_VARARGS, 
00173           "Set the current debug level.\n"
00174 "\n"
00175 "Example:\n"
00176 "\n"
00177 ">>> srvsvc.get_debuglevel()\n"
00178 "0" },
00179 
00180         { "set_debuglevel", (PyCFunction)set_debuglevel, 
00181           METH_VARARGS, 
00182           "Get the current debug level.\n"
00183 "\n"
00184 "Example:\n"
00185 "\n"
00186 ">>> srvsvc.set_debuglevel(10)" },
00187 
00188         { NULL }
00189 };
00190 
00191 void initsrvsvc(void)
00192 {
00193         PyObject *module, *dict;
00194 
00195         /* Initialise module */
00196 
00197         module = Py_InitModule("srvsvc", srvsvc_methods);
00198         dict = PyModule_GetDict(module);
00199 
00200         /* Exceptions we can raise */
00201 
00202         srvsvc_error = PyErr_NewException("srvsvc.error", NULL, NULL);
00203         PyDict_SetItemString(dict, "error", srvsvc_error);
00204 
00205         srvsvc_werror = PyErr_NewException("srvsvc.werror", NULL, NULL);
00206         PyDict_SetItemString(dict, "werror", srvsvc_werror);
00207 
00208         /* Initialise constants */
00209 
00210         const_init(dict);
00211 
00212         /* Do samba initialisation */
00213 
00214         py_samba_init();
00215 }

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