librpc/ndr/libndr.h

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    rpc interface definitions
00004    Copyright (C) Andrew Tridgell 2003
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 }/* [public] */;
00033 
00034 /*
00035   this provides definitions for the libcli/rpc/ MSRPC library
00036 */
00037 
00038 
00039 /*
00040   this is used by the token store/retrieve code
00041 */
00042 struct ndr_token_list {
00043         struct ndr_token_list *next, *prev;
00044         const void *key;
00045         uint32_t value;
00046 };
00047 
00048 /* this is the base structure passed to routines that 
00049    parse MSRPC formatted data 
00050 
00051    note that in Samba4 we use separate routines and structures for
00052    MSRPC marshalling and unmarshalling. Also note that these routines
00053    are being kept deliberately very simple, and are not tied to a
00054    particular transport
00055 */
00056 struct ndr_pull {
00057         uint32_t flags; /* LIBNDR_FLAG_* */
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         /* this is used to ensure we generate unique reference IDs
00073            between request and reply */
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 /* structure passed to functions that generate NDR formatted data */
00084 struct ndr_push {
00085         uint32_t flags; /* LIBNDR_FLAG_* */
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         /* this is used to ensure we generate unique reference IDs */
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 /* structure passed to functions that print IDL structures */
00108 struct ndr_print {
00109         uint32_t flags; /* LIBNDR_FLAG_* */
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 /* used to force a section of IDL to be little-endian */
00146 #define LIBNDR_FLAG_LITTLE_ENDIAN (1<<27)
00147 
00148 /* used to check if alignment padding is zero */
00149 #define LIBNDR_FLAG_PAD_CHECK     (1<<28)
00150 
00151 /* set if an object uuid will be present */
00152 #define LIBNDR_FLAG_OBJECT_PRESENT    (1<<30)
00153 
00154 /* set to avoid recursion in ndr_size_*() calculation */
00155 #define LIBNDR_FLAG_NO_NDR_SIZE         (1<<31)
00156 
00157 /* useful macro for debugging */
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   flags passed to control parse flow
00192 */
00193 #define NDR_SCALARS 1
00194 #define NDR_BUFFERS 2
00195 
00196 /*
00197   flags passed to ndr_print_*()
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 /* these are used to make the error checking on each element in libndr
00236    less tedious, hopefully making the code more readable */
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 /* these are used when generic fn pointers are needed for ndr push/pull fns */
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 /* __LIBNDR_H__ */

Sambaに対してSat Aug 29 21:23:03 2009に生成されました。  doxygen 1.4.7