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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "python/py_srvsvc.h"
22 /* Exceptions this module can raise */
24 PyObject
*srvsvc_error
, *srvsvc_werror
;
26 static struct const_vals
{
29 } module_const_vals
[] = {
30 { "SV_TYPE_WORKSTATION", SV_TYPE_WORKSTATION
},
31 { "SV_TYPE_SERVER", SV_TYPE_SERVER
},
32 { "SV_TYPE_SQLSERVER", SV_TYPE_SQLSERVER
},
33 { "SV_TYPE_DOMAIN_CTRL", SV_TYPE_DOMAIN_CTRL
},
34 { "SV_TYPE_DOMAIN_BAKCTRL", SV_TYPE_DOMAIN_BAKCTRL
},
35 { "SV_TYPE_TIME_SOURCE", SV_TYPE_TIME_SOURCE
},
36 { "SV_TYPE_AFP", SV_TYPE_AFP
},
37 { "SV_TYPE_NOVELL", SV_TYPE_NOVELL
},
38 { "SV_TYPE_DOMAIN_MEMBER", SV_TYPE_DOMAIN_MEMBER
},
39 { "SV_TYPE_PRINTQ_SERVER", SV_TYPE_PRINTQ_SERVER
},
40 { "SV_TYPE_DIALIN_SERVER", SV_TYPE_DIALIN_SERVER
},
41 { "SV_TYPE_SERVER_UNIX", SV_TYPE_SERVER_UNIX
},
42 { "SV_TYPE_NT", SV_TYPE_NT
},
43 { "SV_TYPE_WFW", SV_TYPE_WFW
},
44 { "SV_TYPE_SERVER_MFPN", SV_TYPE_SERVER_MFPN
},
45 { "SV_TYPE_SERVER_NT", SV_TYPE_SERVER_NT
},
46 { "SV_TYPE_POTENTIAL_BROWSER", SV_TYPE_POTENTIAL_BROWSER
},
47 { "SV_TYPE_BACKUP_BROWSER", SV_TYPE_BACKUP_BROWSER
},
48 { "SV_TYPE_MASTER_BROWSER", SV_TYPE_MASTER_BROWSER
},
49 { "SV_TYPE_DOMAIN_MASTER", SV_TYPE_DOMAIN_MASTER
},
50 { "SV_TYPE_SERVER_OSF", SV_TYPE_SERVER_OSF
},
51 { "SV_TYPE_SERVER_VMS", SV_TYPE_SERVER_VMS
},
52 { "SV_TYPE_WIN95_PLUS", SV_TYPE_WIN95_PLUS
},
53 { "SV_TYPE_DFS_SERVER", SV_TYPE_DFS_SERVER
},
54 { "SV_TYPE_ALTERNATE_XPORT", SV_TYPE_ALTERNATE_XPORT
},
55 { "SV_TYPE_LOCAL_LIST_ONLY", SV_TYPE_LOCAL_LIST_ONLY
},
56 { "SV_TYPE_DOMAIN_ENUM", SV_TYPE_DOMAIN_ENUM
},
60 static void const_init(PyObject
*dict
)
62 struct const_vals
*tmp
;
65 for (tmp
= module_const_vals
; tmp
->name
; tmp
++) {
66 obj
= PyInt_FromLong(tmp
->value
);
67 PyDict_SetItemString(dict
, tmp
->name
, obj
);
72 /* NetServerGetInfo */
74 PyObject
*srvsvc_netservergetinfo(PyObject
*self
, PyObject
*args
,
77 static char *kwlist
[] = { "server", "level", "creds", NULL
};
78 char *unc_name
, *server
, *errstr
;
79 PyObject
*creds
= NULL
, *result
= NULL
;
80 struct cli_state
*cli
;
81 TALLOC_CTX
*mem_ctx
= NULL
;
86 if (!PyArg_ParseTupleAndKeywords(
87 args
, kw
, "si|O", kwlist
, &unc_name
, &level
, &creds
))
90 if (unc_name
[0] != '\\' || unc_name
[1] != '\\') {
91 PyErr_SetString(PyExc_ValueError
, "UNC name required");
95 server
= SMB_STRDUP(unc_name
+ 2);
97 if (strchr(server
, '\\')) {
98 char *c
= strchr(server
, '\\');
102 if (creds
&& creds
!= Py_None
&& !PyDict_Check(creds
)) {
103 PyErr_SetString(PyExc_TypeError
,
104 "credentials must be dictionary or None");
108 if (!(cli
= open_pipe_creds(server
, creds
, PI_SRVSVC
, &errstr
))) {
109 PyErr_SetString(srvsvc_error
, errstr
);
114 if (!(mem_ctx
= talloc_init("srvsvc_netservergetinfo"))) {
115 PyErr_SetString(srvsvc_error
,
116 "unable to init talloc context\n");
122 status
= rpccli_srvsvc_net_srv_get_info(cli
->pipe_list
, mem_ctx
, level
, &ctr
);
124 if (!NT_STATUS_IS_OK(status
)) {
125 PyErr_SetObject(srvsvc_error
, py_werror_tuple(status
));
129 if (level
!= ctr
.switch_value
) {
130 PyErr_SetString(srvsvc_error
, "container level value wrong");
136 py_from_SRV_INFO_101(&result
, &ctr
.srv
.sv101
);
144 talloc_destroy(mem_ctx
);
150 * Module initialisation
153 static PyMethodDef srvsvc_methods
[] = {
154 { "netservergetinfo", (PyCFunction
)srvsvc_netservergetinfo
,
155 METH_VARARGS
| METH_KEYWORDS
,
156 "Retrieve information about a particular server." },
158 { "setup_logging", (PyCFunction
)py_setup_logging
,
159 METH_VARARGS
| METH_KEYWORDS
,
160 "Set up debug logging.\n"
162 "Initialises Samba's debug logging system. One argument is expected which\n"
163 "is a boolean specifying whether debugging is interactive and sent to stdout\n"
164 "or logged to a file.\n"
168 ">>> srvsvc.setup_logging(interactive = 1)" },
170 { "get_debuglevel", (PyCFunction
)get_debuglevel
,
172 "Set the current debug level.\n"
176 ">>> srvsvc.get_debuglevel()\n"
179 { "set_debuglevel", (PyCFunction
)set_debuglevel
,
181 "Get the current debug level.\n"
185 ">>> srvsvc.set_debuglevel(10)" },
190 void initsrvsvc(void)
192 PyObject
*module
, *dict
;
194 /* Initialise module */
196 module
= Py_InitModule("srvsvc", srvsvc_methods
);
197 dict
= PyModule_GetDict(module
);
199 /* Exceptions we can raise */
201 srvsvc_error
= PyErr_NewException("srvsvc.error", NULL
, NULL
);
202 PyDict_SetItemString(dict
, "error", srvsvc_error
);
204 srvsvc_werror
= PyErr_NewException("srvsvc.werror", NULL
, NULL
);
205 PyDict_SetItemString(dict
, "werror", srvsvc_werror
);
207 /* Initialise constants */
211 /* Do samba initialisation */