2 Python wrappers for DCERPC/SMB client routines.
4 Copyright (C) Tim Potter, 2003
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.
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.
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.
21 #include "python/py_srvsvc.h"
23 /* Exceptions this module can raise */
25 PyObject *srvsvc_error, *srvsvc_werror;
27 static struct const_vals {
30 } module_const_vals[] = {
34 static void const_init(PyObject *dict)
36 struct const_vals *tmp;
39 for (tmp = module_const_vals; tmp->name; tmp++) {
40 obj = PyInt_FromLong(tmp->value);
41 PyDict_SetItemString(dict, tmp->name, obj);
46 /* NetServerGetInfo */
48 PyObject *srvsvc_netservergetinfo(PyObject *self, PyObject *args,
51 static char *kwlist[] = { "server", "level", "creds", NULL };
52 char *unc_name, *server, *errstr;
53 PyObject *creds = NULL, *result = NULL;
54 struct cli_state *cli;
55 TALLOC_CTX *mem_ctx = NULL;
60 if (!PyArg_ParseTupleAndKeywords(
61 args, kw, "si|O", kwlist, &unc_name, &level, &creds))
64 if (unc_name[0] != '\\' || unc_name[1] != '\\') {
65 PyErr_SetString(PyExc_ValueError, "UNC name required");
69 server = strdup(unc_name + 2);
71 if (strchr(server, '\\')) {
72 char *c = strchr(server, '\\');
76 if (creds && creds != Py_None && !PyDict_Check(creds)) {
77 PyErr_SetString(PyExc_TypeError,
78 "credentials must be dictionary or None");
82 if (!(cli = open_pipe_creds(server, creds, PI_SRVSVC, &errstr))) {
83 PyErr_SetString(srvsvc_error, errstr);
88 if (!(mem_ctx = talloc_init("srvsvc_netservergetinfo"))) {
89 PyErr_SetString(srvsvc_error,
90 "unable to init talloc context\n");
96 status = cli_srvsvc_net_srv_get_info(cli, mem_ctx, level, &ctr);
98 if (!NT_STATUS_IS_OK(status)) {
99 PyErr_SetObject(srvsvc_error, py_werror_tuple(status));
108 talloc_destroy(mem_ctx);
114 * Module initialisation
117 static PyMethodDef srvsvc_methods[] = {
118 { "netservergetinfo", (PyCFunction)srvsvc_netservergetinfo,
119 METH_VARARGS | METH_KEYWORDS,
120 "Retrieve information about a particular server." },
122 { "setup_logging", (PyCFunction)py_setup_logging,
123 METH_VARARGS | METH_KEYWORDS,
124 "Set up debug logging.
126 Initialises Samba's debug logging system. One argument is expected which
127 is a boolean specifying whether debugging is interactive and sent to stdout
132 >>> srvsvc.setup_logging(interactive = 1)" },
134 { "get_debuglevel", (PyCFunction)get_debuglevel,
136 "Set the current debug level.
140 >>> srvsvc.get_debuglevel()
143 { "set_debuglevel", (PyCFunction)set_debuglevel,
145 "Get the current debug level.
149 >>> srvsvc.set_debuglevel(10)" },
154 void initsrvsvc(void)
156 PyObject *module, *dict;
158 /* Initialise module */
160 module = Py_InitModule("srvsvc", srvsvc_methods);
161 dict = PyModule_GetDict(module);
163 /* Exceptions we can raise */
165 srvsvc_error = PyErr_NewException("srvsvc.error", NULL, NULL);
166 PyDict_SetItemString(dict, "error", srvsvc_error);
168 srvsvc_werror = PyErr_NewException("srvsvc.werror", NULL, NULL);
169 PyDict_SetItemString(dict, "werror", srvsvc_werror);
171 /* Initialise constants */
175 /* Do samba initialisation */