2 Unix SMB/CIFS implementation.
3 rpc interface definitions
5 Copyright (C) Andrew Tridgell 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /* This is a public header file that is installed as part of Samba.
22 * If you remove any functions or change their signature, update
23 * the so version number. */
29 #include "lib/util/util.h" /* for discard_const */
30 #include "lib/charset/charset.h"
33 this provides definitions for the libcli/rpc/ MSRPC library
38 this is used by the token store/retrieve code
40 struct ndr_token_list {
41 struct ndr_token_list *next, *prev;
46 /* this is the base structure passed to routines that
47 parse MSRPC formatted data
49 note that in Samba4 we use separate routines and structures for
50 MSRPC marshalling and unmarshalling. Also note that these routines
51 are being kept deliberately very simple, and are not tied to a
55 uint32_t flags; /* LIBNDR_FLAG_* */
60 struct smb_iconv_convenience *iconv_convenience;
62 uint32_t relative_base_offset;
63 struct ndr_token_list *relative_base_list;
65 struct ndr_token_list *relative_list;
66 struct ndr_token_list *array_size_list;
67 struct ndr_token_list *array_length_list;
68 struct ndr_token_list *switch_list;
70 TALLOC_CTX *current_mem_ctx;
72 /* this is used to ensure we generate unique reference IDs
73 between request and reply */
77 /* structure passed to functions that generate NDR formatted data */
79 uint32_t flags; /* LIBNDR_FLAG_* */
84 uint32_t relative_base_offset;
85 struct ndr_token_list *relative_base_list;
87 struct ndr_token_list *switch_list;
88 struct ndr_token_list *relative_list;
89 struct ndr_token_list *nbt_string_list;
90 struct ndr_token_list *full_ptr_list;
92 /* this is used to ensure we generate unique reference IDs */
95 struct smb_iconv_convenience *iconv_convenience;
98 /* structure passed to functions that print IDL structures */
100 uint32_t flags; /* LIBNDR_FLAG_* */
102 struct ndr_token_list *switch_list;
103 void (*print)(struct ndr_print *, const char *, ...) PRINTF_ATTRIBUTE(2,3);
107 #define LIBNDR_FLAG_BIGENDIAN (1<<0)
108 #define LIBNDR_FLAG_NOALIGN (1<<1)
110 #define LIBNDR_FLAG_STR_ASCII (1<<2)
111 #define LIBNDR_FLAG_STR_LEN4 (1<<3)
112 #define LIBNDR_FLAG_STR_SIZE4 (1<<4)
113 #define LIBNDR_FLAG_STR_NOTERM (1<<5)
114 #define LIBNDR_FLAG_STR_NULLTERM (1<<6)
115 #define LIBNDR_FLAG_STR_SIZE2 (1<<7)
116 #define LIBNDR_FLAG_STR_BYTESIZE (1<<8)
117 #define LIBNDR_FLAG_STR_CONFORMANT (1<<10)
118 #define LIBNDR_FLAG_STR_CHARLEN (1<<11)
119 #define LIBNDR_FLAG_STR_UTF8 (1<<12)
120 #define LIBNDR_STRING_FLAGS (0x7FFC)
123 #define LIBNDR_FLAG_REF_ALLOC (1<<20)
124 #define LIBNDR_FLAG_REMAINING (1<<21)
125 #define LIBNDR_FLAG_ALIGN2 (1<<22)
126 #define LIBNDR_FLAG_ALIGN4 (1<<23)
127 #define LIBNDR_FLAG_ALIGN8 (1<<24)
129 #define LIBNDR_ALIGN_FLAGS (LIBNDR_FLAG_ALIGN2|LIBNDR_FLAG_ALIGN4|LIBNDR_FLAG_ALIGN8)
131 #define LIBNDR_PRINT_ARRAY_HEX (1<<25)
132 #define LIBNDR_PRINT_SET_VALUES (1<<26)
134 /* used to force a section of IDL to be little-endian */
135 #define LIBNDR_FLAG_LITTLE_ENDIAN (1<<27)
137 /* used to check if alignment padding is zero */
138 #define LIBNDR_FLAG_PAD_CHECK (1<<28)
140 /* set if an object uuid will be present */
141 #define LIBNDR_FLAG_OBJECT_PRESENT (1<<30)
143 /* set to avoid recursion in ndr_size_*() calculation */
144 #define LIBNDR_FLAG_NO_NDR_SIZE (1<<31)
146 /* useful macro for debugging */
147 #define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
148 #define NDR_PRINT_UNION_DEBUG(type, level, p) ndr_print_union_debug((ndr_print_fn_t)ndr_print_ ##type, #p, level, p)
149 #define NDR_PRINT_FUNCTION_DEBUG(type, flags, p) ndr_print_function_debug((ndr_print_function_t)ndr_print_ ##type, #type, flags, p)
150 #define NDR_PRINT_BOTH_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_BOTH, p)
151 #define NDR_PRINT_OUT_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_OUT, p)
152 #define NDR_PRINT_IN_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_IN | NDR_SET_VALUES, p)
154 #define NDR_BE(ndr) (((ndr)->flags & (LIBNDR_FLAG_BIGENDIAN|LIBNDR_FLAG_LITTLE_ENDIAN)) == LIBNDR_FLAG_BIGENDIAN)
173 NDR_ERR_INVALID_POINTER,
177 #define NDR_ERR_CODE_IS_SUCCESS(x) (x == NDR_ERR_SUCCESS)
179 #define NDR_ERR_HAVE_NO_MEMORY(x) do { \
181 return NDR_ERR_ALLOC; \
185 enum ndr_compression_alg {
186 NDR_COMPRESSION_MSZIP = 2,
187 NDR_COMPRESSION_XPRESS = 3
191 flags passed to control parse flow
193 #define NDR_SCALARS 1
194 #define NDR_BUFFERS 2
197 flags passed to ndr_print_*()
202 #define NDR_SET_VALUES 4
204 #define NDR_PULL_NEED_BYTES(ndr, n) do { \
205 if ((n) > ndr->data_size || ndr->offset + (n) > ndr->data_size) { \
206 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE, "Pull bytes %u", (unsigned)n); \
210 #define NDR_ALIGN(ndr, n) ndr_align_size(ndr->offset, n)
212 #define NDR_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
214 #define NDR_PULL_ALIGN(ndr, n) do { \
215 if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
216 if (ndr->flags & LIBNDR_FLAG_PAD_CHECK) { \
217 ndr_check_padding(ndr, n); \
219 ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
221 if (ndr->offset > ndr->data_size) { \
222 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE, "Pull align %u", (unsigned)n); \
226 #define NDR_PUSH_NEED_BYTES(ndr, n) NDR_CHECK(ndr_push_expand(ndr, n))
228 #define NDR_PUSH_ALIGN(ndr, n) do { \
229 if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
230 uint32_t _pad = ((ndr->offset + (n-1)) & ~(n-1)) - ndr->offset; \
231 while (_pad--) NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 0)); \
235 /* these are used to make the error checking on each element in libndr
236 less tedious, hopefully making the code more readable */
237 #define NDR_CHECK(call) do { \
238 enum ndr_err_code _status; \
240 if (!NDR_ERR_CODE_IS_SUCCESS(_status)) { \
245 #define NDR_PULL_GET_MEM_CTX(ndr) (ndr->current_mem_ctx)
247 #define NDR_PULL_SET_MEM_CTX(ndr, mem_ctx, flgs) do {\
248 if ( !(flgs) || (ndr->flags & flgs) ) {\
250 return ndr_pull_error(ndr, NDR_ERR_ALLOC, "NDR_PULL_SET_MEM_CTX(NULL): %s\n", __location__); \
252 ndr->current_mem_ctx = discard_const(mem_ctx);\
256 #define _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr) do {\
257 if (!ndr->current_mem_ctx) {\
258 ndr->current_mem_ctx = talloc_new(ndr);\
259 if (!ndr->current_mem_ctx) {\
260 return ndr_pull_error(ndr, NDR_ERR_ALLOC, "_NDR_PULL_FIX_CURRENT_MEM_CTX() failed: %s\n", __location__); \
265 #define NDR_PULL_ALLOC(ndr, s) do { \
266 _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\
267 (s) = talloc_ptrtype(ndr->current_mem_ctx, (s)); \
268 if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %s failed: %s\n", # s, __location__); \
271 #define NDR_PULL_ALLOC_N(ndr, s, n) do { \
272 _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\
273 (s) = talloc_array_ptrtype(ndr->current_mem_ctx, (s), n); \
274 if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %s failed: %s\n", (unsigned)n, # s, __location__); \
278 #define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \
279 (s) = talloc_array(ndr, uint8_t, size); \
280 if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %u failed: %s\n", (unsigned)size, __location__); \
283 #define NDR_PUSH_ALLOC(ndr, s) do { \
284 (s) = talloc_ptrtype(ndr, (s)); \
285 if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %s failed: %s\n", # s, __location__); \
288 /* these are used when generic fn pointers are needed for ndr push/pull fns */
289 typedef enum ndr_err_code (*ndr_push_flags_fn_t)(struct ndr_push *, int ndr_flags, const void *);
290 typedef enum ndr_err_code (*ndr_pull_flags_fn_t)(struct ndr_pull *, int ndr_flags, void *);
291 typedef void (*ndr_print_fn_t)(struct ndr_print *, const char *, const void *);
292 typedef void (*ndr_print_function_t)(struct ndr_print *, const char *, int, const void *);
294 #include "libcli/util/error.h"
295 #include "librpc/gen_ndr/ndr_misc.h"
296 #include "librpc/ndr/libndr_proto.h"
298 extern const struct ndr_syntax_id ndr_transfer_syntax;
299 extern const struct ndr_syntax_id ndr64_transfer_syntax;
301 struct ndr_interface_call {
304 ndr_push_flags_fn_t ndr_push;
305 ndr_pull_flags_fn_t ndr_pull;
306 ndr_print_function_t ndr_print;
310 struct ndr_interface_string_array {
312 const char * const *names;
315 struct ndr_interface_table {
317 struct ndr_syntax_id syntax_id;
318 const char *helpstring;
320 const struct ndr_interface_call *calls;
321 const struct ndr_interface_string_array *endpoints;
322 const struct ndr_interface_string_array *authservices;
325 struct ndr_interface_list {
326 struct ndr_interface_list *prev, *next;
327 const struct ndr_interface_table *table;
330 /* FIXME: Use represent_as instead */
332 enum ndr_err_code ndr_push_dom_sid2(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid);
333 enum ndr_err_code ndr_pull_dom_sid2(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid);
334 void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, const struct dom_sid *sid);
335 enum ndr_err_code ndr_push_dom_sid28(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid);
336 enum ndr_err_code ndr_pull_dom_sid28(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid);
337 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid);
338 size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags);
339 void ndr_print_ipv4_addr(struct ndr_print *ndr, const char *name, const struct in_addr *_ip);
340 void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid);
342 #endif /* __LIBNDR_H__ */