00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __LIBNDR_H__
00022 #define __LIBNDR_H__
00023
00024 #define _PRINTF_ATTRIBUTE(a,b)
00025
00026 #include "librpc/ndr/misc.h"
00027 #include "librpc/ndr/security.h"
00028
00029 struct dcerpc_syntax_id {
00030 struct GUID uuid;
00031 uint32_t if_version;
00032 };
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 struct ndr_token_list {
00043 struct ndr_token_list *next, *prev;
00044 const void *key;
00045 uint32_t value;
00046 };
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 struct ndr_pull {
00057 uint32_t flags;
00058 uint8_t *data;
00059 uint32_t data_size;
00060 uint32_t offset;
00061
00062 uint32_t relative_base_offset;
00063 struct ndr_token_list *relative_base_list;
00064
00065 struct ndr_token_list *relative_list;
00066 struct ndr_token_list *array_size_list;
00067 struct ndr_token_list *array_length_list;
00068 struct ndr_token_list *switch_list;
00069
00070 TALLOC_CTX *current_mem_ctx;
00071
00072
00073
00074 uint32_t ptr_count;
00075 };
00076
00077 struct ndr_pull_save {
00078 uint32_t data_size;
00079 uint32_t offset;
00080 struct ndr_pull_save *next;
00081 };
00082
00083
00084 struct ndr_push {
00085 uint32_t flags;
00086 uint8_t *data;
00087 uint32_t alloc_size;
00088 uint32_t offset;
00089
00090 uint32_t relative_base_offset;
00091 struct ndr_token_list *relative_base_list;
00092
00093 struct ndr_token_list *switch_list;
00094 struct ndr_token_list *relative_list;
00095 struct ndr_token_list *nbt_string_list;
00096
00097
00098 uint32_t ptr_count;
00099 };
00100
00101 struct ndr_push_save {
00102 uint32_t offset;
00103 struct ndr_push_save *next;
00104 };
00105
00106
00107
00108 struct ndr_print {
00109 uint32_t flags;
00110 uint32_t depth;
00111 struct ndr_token_list *switch_list;
00112 void (*print)(struct ndr_print *, const char *, ...);
00113 void *private_data;
00114 };
00115
00116 #define LIBNDR_FLAG_BIGENDIAN (1<<0)
00117 #define LIBNDR_FLAG_NOALIGN (1<<1)
00118
00119 #define LIBNDR_FLAG_STR_ASCII (1<<2)
00120 #define LIBNDR_FLAG_STR_LEN4 (1<<3)
00121 #define LIBNDR_FLAG_STR_SIZE4 (1<<4)
00122 #define LIBNDR_FLAG_STR_NOTERM (1<<5)
00123 #define LIBNDR_FLAG_STR_NULLTERM (1<<6)
00124 #define LIBNDR_FLAG_STR_SIZE2 (1<<7)
00125 #define LIBNDR_FLAG_STR_BYTESIZE (1<<8)
00126 #define LIBNDR_FLAG_STR_FIXLEN32 (1<<9)
00127 #define LIBNDR_FLAG_STR_CONFORMANT (1<<10)
00128 #define LIBNDR_FLAG_STR_CHARLEN (1<<11)
00129 #define LIBNDR_FLAG_STR_UTF8 (1<<12)
00130 #define LIBNDR_FLAG_STR_FIXLEN15 (1<<13)
00131 #define LIBNDR_STRING_FLAGS (0x7FFC)
00132
00133
00134 #define LIBNDR_FLAG_REF_ALLOC (1<<20)
00135 #define LIBNDR_FLAG_REMAINING (1<<21)
00136 #define LIBNDR_FLAG_ALIGN2 (1<<22)
00137 #define LIBNDR_FLAG_ALIGN4 (1<<23)
00138 #define LIBNDR_FLAG_ALIGN8 (1<<24)
00139
00140 #define LIBNDR_ALIGN_FLAGS (LIBNDR_FLAG_ALIGN2|LIBNDR_FLAG_ALIGN4|LIBNDR_FLAG_ALIGN8)
00141
00142 #define LIBNDR_PRINT_ARRAY_HEX (1<<25)
00143 #define LIBNDR_PRINT_SET_VALUES (1<<26)
00144
00145
00146 #define LIBNDR_FLAG_LITTLE_ENDIAN (1<<27)
00147
00148
00149 #define LIBNDR_FLAG_PAD_CHECK (1<<28)
00150
00151
00152 #define LIBNDR_FLAG_OBJECT_PRESENT (1<<30)
00153
00154
00155 #define LIBNDR_FLAG_NO_NDR_SIZE (1<<31)
00156
00157
00158 #define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
00159 #define NDR_PRINT_UNION_DEBUG(type, level, p) ndr_print_union_debug((ndr_print_fn_t)ndr_print_ ##type, #p, level, p)
00160 #define NDR_PRINT_FUNCTION_DEBUG(type, flags, p) ndr_print_function_debug((ndr_print_function_t)ndr_print_ ##type, #type, flags, p)
00161 #define NDR_PRINT_BOTH_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_BOTH, p)
00162 #define NDR_PRINT_OUT_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_OUT, p)
00163 #define NDR_PRINT_IN_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_IN | NDR_SET_VALUES, p)
00164
00165 #define NDR_BE(ndr) (((ndr)->flags & (LIBNDR_FLAG_BIGENDIAN|LIBNDR_FLAG_LITTLE_ENDIAN)) == LIBNDR_FLAG_BIGENDIAN)
00166
00167 enum ndr_err_code {
00168 NDR_ERR_ARRAY_SIZE,
00169 NDR_ERR_BAD_SWITCH,
00170 NDR_ERR_OFFSET,
00171 NDR_ERR_RELATIVE,
00172 NDR_ERR_CHARCNV,
00173 NDR_ERR_LENGTH,
00174 NDR_ERR_SUBCONTEXT,
00175 NDR_ERR_COMPRESSION,
00176 NDR_ERR_STRING,
00177 NDR_ERR_VALIDATE,
00178 NDR_ERR_BUFSIZE,
00179 NDR_ERR_ALLOC,
00180 NDR_ERR_RANGE,
00181 NDR_ERR_TOKEN,
00182 NDR_ERR_IPV4ADDRESS
00183 };
00184
00185 enum ndr_compression_alg {
00186 NDR_COMPRESSION_MSZIP = 2,
00187 NDR_COMPRESSION_XPRESS = 3
00188 };
00189
00190
00191
00192
00193 #define NDR_SCALARS 1
00194 #define NDR_BUFFERS 2
00195
00196
00197
00198
00199 #define NDR_IN 1
00200 #define NDR_OUT 2
00201 #define NDR_BOTH 3
00202 #define NDR_SET_VALUES 4
00203
00204 #define NDR_PULL_NEED_BYTES(ndr, n) do { \
00205 if ((n) > ndr->data_size || ndr->offset + (n) > ndr->data_size) { \
00206 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE, "Pull bytes %u", (unsigned)n); \
00207 } \
00208 } while(0)
00209
00210 #define NDR_ALIGN(ndr, n) ndr_align_size(ndr->offset, n)
00211
00212 #define NDR_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
00213
00214 #define NDR_PULL_ALIGN(ndr, n) do { \
00215 if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
00216 if (ndr->flags & LIBNDR_FLAG_PAD_CHECK) { \
00217 ndr_check_padding(ndr, n); \
00218 } \
00219 ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
00220 } \
00221 if (ndr->offset > ndr->data_size) { \
00222 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE, "Pull align %u", (unsigned)n); \
00223 } \
00224 } while(0)
00225
00226 #define NDR_PUSH_NEED_BYTES(ndr, n) NDR_CHECK(ndr_push_expand(ndr, n))
00227
00228 #define NDR_PUSH_ALIGN(ndr, n) do { \
00229 if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
00230 uint32_t _pad = ((ndr->offset + (n-1)) & ~(n-1)) - ndr->offset; \
00231 while (_pad--) NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 0)); \
00232 } \
00233 } while(0)
00234
00235
00236
00237 #define NDR_CHECK(call) do { NTSTATUS _status; \
00238 _status = call; \
00239 if (!NT_STATUS_IS_OK(_status)) \
00240 return _status; \
00241 } while (0)
00242
00243 #define NDR_PULL_GET_MEM_CTX(ndr) (ndr->current_mem_ctx)
00244
00245 #define NDR_PULL_SET_MEM_CTX(ndr, mem_ctx, flgs) do {\
00246 if ( !(flgs) || (ndr->flags & flgs) ) {\
00247 if (!(mem_ctx)) {\
00248 return ndr_pull_error(ndr, NDR_ERR_ALLOC, "NDR_PULL_SET_MEM_CTX(NULL): %s\n", __location__); \
00249 }\
00250 ndr->current_mem_ctx = CONST_DISCARD(TALLOC_CTX *, mem_ctx);\
00251 }\
00252 } while(0)
00253
00254 #define _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr) do {\
00255 if (!ndr->current_mem_ctx) {\
00256 ndr->current_mem_ctx = talloc_new(ndr);\
00257 if (!ndr->current_mem_ctx) {\
00258 return ndr_pull_error(ndr, NDR_ERR_ALLOC, "_NDR_PULL_FIX_CURRENT_MEM_CTX() failed: %s\n", __location__); \
00259 }\
00260 }\
00261 } while(0)
00262
00263 #define NDR_PULL_ALLOC(ndr, s) do { \
00264 _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\
00265 (s) = talloc_ptrtype(ndr->current_mem_ctx, (s)); \
00266 if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %s failed: %s\n", # s, __location__); \
00267 } while (0)
00268
00269 #define NDR_PULL_ALLOC_N(ndr, s, n) do { \
00270 _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\
00271 (s) = talloc_array_ptrtype(ndr->current_mem_ctx, (s), n); \
00272 if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %s failed: %s\n", (unsigned)n, # s, __location__); \
00273 } while (0)
00274
00275
00276 #define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \
00277 (s) = talloc_array(ndr, uint8, size); \
00278 if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %u failed: %s\n", (unsigned)size, __location__); \
00279 } while (0)
00280
00281 #define NDR_PUSH_ALLOC(ndr, s) do { \
00282 (s) = talloc_ptrtype(ndr, (s)); \
00283 if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %s failed: %s\n", # s, __location__); \
00284 } while (0)
00285
00286
00287 typedef NTSTATUS (*ndr_push_flags_fn_t)(struct ndr_push *, int ndr_flags, const void *);
00288 typedef NTSTATUS (*ndr_pull_flags_fn_t)(struct ndr_pull *, int ndr_flags, void *);
00289 typedef void (*ndr_print_fn_t)(struct ndr_print *, const char *, const void *);
00290 typedef void (*ndr_print_function_t)(struct ndr_print *, const char *, int, const void *);
00291
00292 extern const struct dcerpc_syntax_id ndr_transfer_syntax;
00293 extern const struct dcerpc_syntax_id ndr64_transfer_syntax;
00294
00295 #include "dcerpc.h"
00296
00297 #endif