1 /* Tastes like -*- C -*- */
4 Unix SMB/CIFS implementation.
6 Swig interface to librpc functions.
8 Copyright (C) Tim Potter 2004
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /* This symbol is used in both includes.h and Python.h which causes an
29 annoying compiler warning. */
36 #include "dynconfig.h"
40 PyObject *ntstatus_exception, *werror_exception;
42 /* Set up return of a dcerpc.NTSTATUS exception */
44 void set_ntstatus_exception(int status)
46 PyObject *obj = Py_BuildValue("(i,s)", status,
47 nt_errstr(NT_STATUS(status)));
49 PyErr_SetObject(ntstatus_exception, obj);
52 void set_werror_exception(int status)
54 PyObject *obj = Py_BuildValue("(i,s)", status,
55 win_errstr(W_ERROR(status)));
57 PyErr_SetObject(werror_exception, obj);
65 NTSTATUS = _dcerpc.NTSTATUS
66 WERROR = _dcerpc.WERROR
70 setup_logging("python", DEBUG_STDOUT);
72 ntstatus_exception = PyErr_NewException("_dcerpc.NTSTATUS", NULL, NULL);
73 werror_exception = PyErr_NewException("_dcerpc.WERROR", NULL, NULL);
74 PyDict_SetItemString(d, "NTSTATUS", ntstatus_exception);
75 PyDict_SetItemString(d, "WERROR", werror_exception);
77 /* BINARY swig_dcerpc INIT */
79 extern NTSTATUS dcerpc_misc_init(void);
80 extern NTSTATUS dcerpc_krb5pac_init(void);
81 extern NTSTATUS dcerpc_samr_init(void);
82 extern NTSTATUS dcerpc_dcerpc_init(void);
83 extern NTSTATUS auth_sam_init(void);
84 extern NTSTATUS dcerpc_lsa_init(void);
85 extern NTSTATUS dcerpc_netlogon_init(void);
86 extern NTSTATUS gensec_init(void);
87 extern NTSTATUS auth_developer_init(void);
88 extern NTSTATUS gensec_spnego_init(void);
89 extern NTSTATUS auth_winbind_init(void);
90 extern NTSTATUS gensec_gssapi_init(void);
91 extern NTSTATUS gensec_ntlmssp_init(void);
92 extern NTSTATUS dcerpc_nbt_init(void);
93 extern NTSTATUS auth_anonymous_init(void);
94 extern NTSTATUS gensec_krb5_init(void);
95 extern NTSTATUS dcerpc_schannel_init(void);
96 extern NTSTATUS dcerpc_epmapper_init(void);
97 if (NT_STATUS_IS_ERR(dcerpc_misc_init())) exit(1);
98 if (NT_STATUS_IS_ERR(dcerpc_krb5pac_init())) exit(1);
99 if (NT_STATUS_IS_ERR(dcerpc_samr_init())) exit(1);
100 if (NT_STATUS_IS_ERR(dcerpc_dcerpc_init())) exit(1);
101 if (NT_STATUS_IS_ERR(auth_sam_init())) exit(1);
102 if (NT_STATUS_IS_ERR(dcerpc_lsa_init())) exit(1);
103 if (NT_STATUS_IS_ERR(dcerpc_netlogon_init())) exit(1);
104 if (NT_STATUS_IS_ERR(gensec_init())) exit(1);
105 if (NT_STATUS_IS_ERR(auth_developer_init())) exit(1);
106 if (NT_STATUS_IS_ERR(gensec_spnego_init())) exit(1);
107 if (NT_STATUS_IS_ERR(auth_winbind_init())) exit(1);
108 if (NT_STATUS_IS_ERR(gensec_gssapi_init())) exit(1);
109 if (NT_STATUS_IS_ERR(gensec_ntlmssp_init())) exit(1);
110 if (NT_STATUS_IS_ERR(dcerpc_nbt_init())) exit(1);
111 if (NT_STATUS_IS_ERR(auth_anonymous_init())) exit(1);
112 if (NT_STATUS_IS_ERR(gensec_krb5_init())) exit(1);
113 if (NT_STATUS_IS_ERR(dcerpc_schannel_init())) exit(1);
114 if (NT_STATUS_IS_ERR(dcerpc_epmapper_init())) exit(1);
118 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
119 $1 = &temp_dcerpc_pipe;
122 %typemap(in, numinputs=0) TALLOC_CTX * {
123 $1 = talloc_init("$symname");
126 %typemap(freearg) TALLOC_CTX * {
130 %typemap(argout) struct dcerpc_pipe ** {
131 long status = PyLong_AsLong(resultobj);
133 /* Throw exception if result was not OK */
136 set_ntstatus_exception(status);
140 /* Set REF_ALLOC flag so we don't have to do too much extra
141 mucking around with ref variables in ndr unmarshalling. */
143 (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC;
145 /* Return swig handle on dcerpc_pipe */
147 resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
150 %types(struct dcerpc_pipe *);
152 %rename(pipe_connect) dcerpc_pipe_connect;
154 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
155 struct dcerpc_pipe **OUT,
157 const char *pipe_uuid,
158 uint32_t pipe_version,
159 struct cli_credentials *credentials);
161 %typemap(in) DATA_BLOB * (DATA_BLOB temp_data_blob) {
162 temp_data_blob.data = PyString_AsString($input);
163 temp_data_blob.length = PyString_Size($input);
164 $1 = &temp_data_blob;
167 const char *dcerpc_server_name(struct dcerpc_pipe *p);
169 char *nt_errstr(NTSTATUS nt_code);
171 /* Some typemaps for easier access to resume handles. Really this can
172 also be done using the uint32 carray functions, but it's a bit of a
173 hassle. TODO: Fix memory leak here. */
175 %typemap(in) uint32_t *resume_handle {
176 $1 = malloc(sizeof(*$1));
177 *$1 = PyLong_AsLong($input);
180 %typemap(out) uint32_t *resume_handle {
181 $result = PyLong_FromLong(*$1);
184 %typemap(in) struct policy_handle * {
186 if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,
187 SWIG_POINTER_EXCEPTION)) == -1)
191 PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle");
196 /* When returning a policy handle to Python we need to make a copy of
197 as the talloc context it is created under is destroyed after the
198 wrapper function returns. TODO: Fix memory leak created here. */
200 %typemap(out) struct policy_handle * {
202 struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle));
203 memcpy(temp, $1, sizeof(struct policy_handle));
204 $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0);
212 #include "librpc/gen_ndr/ndr_misc.h"
213 #include "librpc/gen_ndr/ndr_security.h"
214 #include "librpc/gen_ndr/ndr_samr.h"
219 /* Some functions for accessing arrays of fixed-width integers. */
221 %array_functions(uint8_t, uint8_array);
222 %array_functions(uint16_t, uint16_array);
223 %array_functions(uint32_t, uint32_array);
225 /* Functions for handling arrays of structures. It would be nice for
226 pidl to automatically generating these instead of having to find
229 %array_functions(struct samr_SamEntry, samr_SamEntry_array);
230 %array_functions(union samr_ConnectInfo, samr_ConnectInfo_array);
231 %array_functions(struct samr_RidWithAttribute, samr_RidWithAttribute_array);
233 %array_functions(struct lsa_SidPtr, lsa_SidPtr_array);
235 %include "librpc/gen_ndr/misc.i"
236 %include "librpc/gen_ndr/security.i"
237 %include "librpc/gen_ndr/samr.i"
238 %include "librpc/gen_ndr/lsa.i"