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
[] = {
31 { "SV_TYPE_WORKSTATION", SV_TYPE_WORKSTATION
},
32 { "SV_TYPE_SERVER", SV_TYPE_SERVER
},
33 { "SV_TYPE_SQLSERVER", SV_TYPE_SQLSERVER
},
34 { "SV_TYPE_DOMAIN_CTRL", SV_TYPE_DOMAIN_CTRL
},
35 { "SV_TYPE_DOMAIN_BAKCTRL", SV_TYPE_DOMAIN_BAKCTRL
},
36 { "SV_TYPE_TIME_SOURCE", SV_TYPE_TIME_SOURCE
},
37 { "SV_TYPE_AFP", SV_TYPE_AFP
},
38 { "SV_TYPE_NOVELL", SV_TYPE_NOVELL
},
39 { "SV_TYPE_DOMAIN_MEMBER", SV_TYPE_DOMAIN_MEMBER
},
40 { "SV_TYPE_PRINTQ_SERVER", SV_TYPE_PRINTQ_SERVER
},
41 { "SV_TYPE_DIALIN_SERVER", SV_TYPE_DIALIN_SERVER
},
42 { "SV_TYPE_SERVER_UNIX", SV_TYPE_SERVER_UNIX
},
43 { "SV_TYPE_NT", SV_TYPE_NT
},
44 { "SV_TYPE_WFW", SV_TYPE_WFW
},
45 { "SV_TYPE_SERVER_MFPN", SV_TYPE_SERVER_MFPN
},
46 { "SV_TYPE_SERVER_NT", SV_TYPE_SERVER_NT
},
47 { "SV_TYPE_POTENTIAL_BROWSER", SV_TYPE_POTENTIAL_BROWSER
},
48 { "SV_TYPE_BACKUP_BROWSER", SV_TYPE_BACKUP_BROWSER
},
49 { "SV_TYPE_MASTER_BROWSER", SV_TYPE_MASTER_BROWSER
},
50 { "SV_TYPE_DOMAIN_MASTER", SV_TYPE_DOMAIN_MASTER
},
51 { "SV_TYPE_SERVER_OSF", SV_TYPE_SERVER_OSF
},
52 { "SV_TYPE_SERVER_VMS", SV_TYPE_SERVER_VMS
},
53 { "SV_TYPE_WIN95_PLUS", SV_TYPE_WIN95_PLUS
},
54 { "SV_TYPE_DFS_SERVER", SV_TYPE_DFS_SERVER
},
55 { "SV_TYPE_ALTERNATE_XPORT", SV_TYPE_ALTERNATE_XPORT
},
56 { "SV_TYPE_LOCAL_LIST_ONLY", SV_TYPE_LOCAL_LIST_ONLY
},
57 { "SV_TYPE_DOMAIN_ENUM", SV_TYPE_DOMAIN_ENUM
},
61 static void const_init(PyObject
*dict
)
63 struct const_vals
*tmp
;
66 for (tmp
= module_const_vals
; tmp
->name
; tmp
++) {
67 obj
= PyInt_FromLong(tmp
->value
);
68 PyDict_SetItemString(dict
, tmp
->name
, obj
);
73 /* NetServerGetInfo */
75 PyObject
*srvsvc_netservergetinfo(PyObject
*self
, PyObject
*args
,
78 static char *kwlist
[] = { "server", "level", "creds", NULL
};
79 char *unc_name
, *server
, *errstr
;
80 PyObject
*creds
= NULL
, *result
= NULL
;
81 struct cli_state
*cli
;
82 TALLOC_CTX
*mem_ctx
= NULL
;
87 if (!PyArg_ParseTupleAndKeywords(
88 args
, kw
, "si|O", kwlist
, &unc_name
, &level
, &creds
))
91 if (unc_name
[0] != '\\' || unc_name
[1] != '\\') {
92 PyErr_SetString(PyExc_ValueError
, "UNC name required");
96 server
= SMB_STRDUP(unc_name
+ 2);
98 if (strchr(server
, '\\')) {
99 char *c
= strchr(server
, '\\');
103 if (creds
&& creds
!= Py_None
&& !PyDict_Check(creds
)) {
104 PyErr_SetString(PyExc_TypeError
,
105 "credentials must be dictionary or None");
109 if (!(cli
= open_pipe_creds(server
, creds
, PI_SRVSVC
, &errstr
))) {
110 PyErr_SetString(srvsvc_error
, errstr
);
115 if (!(mem_ctx
= talloc_init("srvsvc_netservergetinfo"))) {
116 PyErr_SetString(srvsvc_error
,
117 "unable to init talloc context\n");
123 status
= rpccli_srvsvc_net_srv_get_info(cli
->pipe_list
, mem_ctx
, level
, &ctr
);
125 if (!W_ERROR_IS_OK(status
)) {
126 PyErr_SetObject(srvsvc_error
, py_werror_tuple(status
));
130 if (level
!= ctr
.switch_value
) {
131 PyErr_SetString(srvsvc_error
, "container level value wrong");
137 py_from_SRV_INFO_101(&result
, &ctr
.srv
.sv101
);
145 talloc_destroy(mem_ctx
);
151 * Module initialisation
154 static PyMethodDef srvsvc_methods
[] = {
155 { "netservergetinfo", (PyCFunction
)srvsvc_netservergetinfo
,
156 METH_VARARGS
| METH_KEYWORDS
,
157 "Retrieve information about a particular server." },
159 { "setup_logging", (PyCFunction
)py_setup_logging
,
160 METH_VARARGS
| METH_KEYWORDS
,
161 "Set up debug logging.\n"
163 "Initialises Samba's debug logging system. One argument is expected which\n"
164 "is a boolean specifying whether debugging is interactive and sent to stdout\n"
165 "or logged to a file.\n"
169 ">>> srvsvc.setup_logging(interactive = 1)" },
171 { "get_debuglevel", (PyCFunction
)get_debuglevel
,
173 "Set the current debug level.\n"
177 ">>> srvsvc.get_debuglevel()\n"
180 { "set_debuglevel", (PyCFunction
)set_debuglevel
,
182 "Get the current debug level.\n"
186 ">>> srvsvc.set_debuglevel(10)" },
191 void initsrvsvc(void)
193 PyObject
*module
, *dict
;
195 /* Initialise module */
197 module
= Py_InitModule("srvsvc", srvsvc_methods
);
198 dict
= PyModule_GetDict(module
);
200 /* Exceptions we can raise */
202 srvsvc_error
= PyErr_NewException("srvsvc.error", NULL
, NULL
);
203 PyDict_SetItemString(dict
, "error", srvsvc_error
);
205 srvsvc_werror
= PyErr_NewException("srvsvc.werror", NULL
, NULL
);
206 PyDict_SetItemString(dict
, "werror", srvsvc_werror
);
208 /* Initialise constants */
212 /* Do samba initialisation */