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 2 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, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 /* This symbol is used in both includes.h and Python.h which causes an
30 annoying compiler warning. */
37 #include "dynconfig.h"
41 PyObject *ntstatus_exception, *werror_exception;
43 /* Set up return of a dcerpc.NTSTATUS exception */
45 void set_ntstatus_exception(int status)
47 PyObject *obj = Py_BuildValue("(i,s)", status,
48 nt_errstr(NT_STATUS(status)));
50 PyErr_SetObject(ntstatus_exception, obj);
53 void set_werror_exception(int status)
55 PyObject *obj = Py_BuildValue("(i,s)", status,
56 win_errstr(W_ERROR(status)));
58 PyErr_SetObject(werror_exception, obj);
66 NTSTATUS = _dcerpc.NTSTATUS
67 WERROR = _dcerpc.WERROR
71 setup_logging("python", DEBUG_STDOUT);
72 lp_load(dyn_CONFIGFILE, True, False, False);
74 ntstatus_exception = PyErr_NewException("_dcerpc.NTSTATUS", NULL, NULL);
75 werror_exception = PyErr_NewException("_dcerpc.WERROR", NULL, NULL);
76 PyDict_SetItemString(d, "NTSTATUS", ntstatus_exception);
77 PyDict_SetItemString(d, "WERROR", werror_exception);
79 /* BINARY swig_dcerpc INIT */
81 extern NTSTATUS dcerpc_misc_init(void);
82 extern NTSTATUS dcerpc_krb5pac_init(void);
83 extern NTSTATUS dcerpc_samr_init(void);
84 extern NTSTATUS dcerpc_dcerpc_init(void);
85 extern NTSTATUS auth_sam_init(void);
86 extern NTSTATUS dcerpc_lsa_init(void);
87 extern NTSTATUS dcerpc_netlogon_init(void);
88 extern NTSTATUS gensec_init(void);
89 extern NTSTATUS auth_developer_init(void);
90 extern NTSTATUS gensec_spnego_init(void);
91 extern NTSTATUS auth_winbind_init(void);
92 extern NTSTATUS gensec_gssapi_init(void);
93 extern NTSTATUS gensec_ntlmssp_init(void);
94 extern NTSTATUS dcerpc_nbt_init(void);
95 extern NTSTATUS auth_anonymous_init(void);
96 extern NTSTATUS gensec_krb5_init(void);
97 extern NTSTATUS dcerpc_schannel_init(void);
98 extern NTSTATUS dcerpc_epmapper_init(void);
99 if (NT_STATUS_IS_ERR(dcerpc_misc_init())) exit(1);
100 if (NT_STATUS_IS_ERR(dcerpc_krb5pac_init())) exit(1);
101 if (NT_STATUS_IS_ERR(dcerpc_samr_init())) exit(1);
102 if (NT_STATUS_IS_ERR(dcerpc_dcerpc_init())) exit(1);
103 if (NT_STATUS_IS_ERR(auth_sam_init())) exit(1);
104 if (NT_STATUS_IS_ERR(dcerpc_lsa_init())) exit(1);
105 if (NT_STATUS_IS_ERR(dcerpc_netlogon_init())) exit(1);
106 if (NT_STATUS_IS_ERR(gensec_init())) exit(1);
107 if (NT_STATUS_IS_ERR(auth_developer_init())) exit(1);
108 if (NT_STATUS_IS_ERR(gensec_spnego_init())) exit(1);
109 if (NT_STATUS_IS_ERR(auth_winbind_init())) exit(1);
110 if (NT_STATUS_IS_ERR(gensec_gssapi_init())) exit(1);
111 if (NT_STATUS_IS_ERR(gensec_ntlmssp_init())) exit(1);
112 if (NT_STATUS_IS_ERR(dcerpc_nbt_init())) exit(1);
113 if (NT_STATUS_IS_ERR(auth_anonymous_init())) exit(1);
114 if (NT_STATUS_IS_ERR(gensec_krb5_init())) exit(1);
115 if (NT_STATUS_IS_ERR(dcerpc_schannel_init())) exit(1);
116 if (NT_STATUS_IS_ERR(dcerpc_epmapper_init())) exit(1);
120 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
121 $1 = &temp_dcerpc_pipe;
124 %typemap(in, numinputs=0) TALLOC_CTX * {
125 $1 = talloc_init("$symname");
128 %typemap(freearg) TALLOC_CTX * {
132 %typemap(argout) struct dcerpc_pipe ** {
133 long status = PyLong_AsLong(resultobj);
135 /* Throw exception if result was not OK */
138 set_ntstatus_exception(status);
142 /* Set REF_ALLOC flag so we don't have to do too much extra
143 mucking around with ref variables in ndr unmarshalling. */
145 (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC;
147 /* Return swig handle on dcerpc_pipe */
149 resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
152 %types(struct dcerpc_pipe *);
154 %rename(pipe_connect) dcerpc_pipe_connect;
156 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
157 struct dcerpc_pipe **OUT,
159 const char *pipe_uuid,
160 uint32_t pipe_version,
161 struct cli_credentials *credentials);
163 %typemap(in) DATA_BLOB * (DATA_BLOB temp_data_blob) {
164 temp_data_blob.data = PyString_AsString($input);
165 temp_data_blob.length = PyString_Size($input);
166 $1 = &temp_data_blob;
169 const char *dcerpc_server_name(struct dcerpc_pipe *p);
171 char *nt_errstr(NTSTATUS nt_code);
173 /* Some typemaps for easier access to resume handles. Really this can
174 also be done using the uint32 carray functions, but it's a bit of a
175 hassle. TODO: Fix memory leak here. */
177 %typemap(in) uint32_t *resume_handle {
178 $1 = malloc(sizeof(*$1));
179 *$1 = PyLong_AsLong($input);
182 %typemap(out) uint32_t *resume_handle {
183 $result = PyLong_FromLong(*$1);
186 %typemap(in) struct policy_handle * {
188 if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,
189 SWIG_POINTER_EXCEPTION)) == -1)
193 PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle");
198 /* When returning a policy handle to Python we need to make a copy of
199 as the talloc context it is created under is destroyed after the
200 wrapper function returns. TODO: Fix memory leak created here. */
202 %typemap(out) struct policy_handle * {
204 struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle));
205 memcpy(temp, $1, sizeof(struct policy_handle));
206 $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0);
214 #include "librpc/gen_ndr/ndr_misc.h"
215 #include "librpc/gen_ndr/ndr_security.h"
216 #include "librpc/gen_ndr/ndr_samr.h"
221 /* Some functions for accessing arrays of fixed-width integers. */
223 %array_functions(uint8_t, uint8_array);
224 %array_functions(uint16_t, uint16_array);
225 %array_functions(uint32_t, uint32_array);
227 /* Functions for handling arrays of structures. It would be nice for
228 pidl to automatically generating these instead of having to find
231 %array_functions(struct samr_String, samr_String_array);
232 %array_functions(struct samr_SamEntry, samr_SamEntry_array);
233 %array_functions(union samr_ConnectInfo, samr_ConnectInfo_array);
234 %array_functions(struct samr_RidType, samr_RidType_array);
236 %array_functions(struct lsa_SidPtr, lsa_SidPtr_array);
238 %include "librpc/gen_ndr/misc.i"
239 %include "librpc/gen_ndr/security.i"
240 %include "librpc/gen_ndr/samr.i"
241 %include "librpc/gen_ndr/lsa.i"