Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. winber.h Basic Encoding Rules (BER) API header file
  5. Abstract:
  6. This module is the header file for the 32 bit BER library on
  7. Windows NT and Windows 95.
  8. Updates :
  9. Environments :
  10. Win32 user mode
  11. --*/
  12. //
  13. // Only pull in this header file once.
  14. //
  15. #ifndef _WINBER_DEFINED_
  16. #define _WINBER_DEFINED_
  17. #if _MSC_VER > 1000
  18. #pragma once
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #if !defined(_WINBER_)
  24. #define WINBERAPI DECLSPEC_IMPORT
  25. #else
  26. //#define WINBERAPI __declspec(dllexport)
  27. #define WINBERAPI
  28. #endif
  29. #ifndef BERAPI
  30. #define BERAPI __cdecl
  31. #endif
  32. #define LBER_ERROR 0xffffffffL
  33. #define LBER_DEFAULT 0xffffffffL
  34. typedef unsigned int ber_tag_t; /* for BER tags */
  35. typedef int ber_int_t; /* for BER ints, enums, and Booleans */
  36. typedef unsigned int ber_uint_t; /* unsigned equivalent of ber_int_t */
  37. typedef int ber_slen_t; /* signed equivalent of ber_len_t */
  38. //
  39. // This constructs a new BerElement structure containing a copy of the
  40. // data in the supplied berval structure.
  41. //
  42. WINBERAPI BerElement * BERAPI ber_init( BERVAL *pBerVal );
  43. //
  44. // This frees a BerElement which is returned from ber_alloc_t()
  45. // or ber_init(). The second argument - fbuf should always be set
  46. // to 1.
  47. //
  48. //
  49. WINBERAPI VOID BERAPI ber_free( BerElement *pBerElement, INT fbuf );
  50. //
  51. // Frees a BERVAL structure. Applications should not call
  52. // this API to free BERVAL structures which they themselves
  53. // have allocated
  54. //
  55. WINBERAPI VOID BERAPI ber_bvfree( BERVAL *pBerVal );
  56. //
  57. // Frees an array of BERVAL structures.
  58. //
  59. WINBERAPI VOID BERAPI ber_bvecfree( PBERVAL *pBerVal );
  60. //
  61. // Returns a copy of a the supplied berval structure
  62. //
  63. WINBERAPI BERVAL * BERAPI ber_bvdup( BERVAL *pBerVal );
  64. //
  65. // Constructs and returns a BerElement structure. The options field
  66. // contains a bitwise-or of options which are to be used when generating
  67. // the encoding of the BerElement
  68. //
  69. // The LBER_USE_DER options should always be specified.
  70. //
  71. WINBERAPI BerElement * BERAPI ber_alloc_t( INT options );
  72. //
  73. // This skips over the current tag and returns the tag of the next
  74. // element in the supplied BerElement. The lenght of this element is
  75. // stored in the pLen argument.
  76. //
  77. // LBER_DEFAULT is returned if there is no further data to be read
  78. // else the tag of the next element is returned.
  79. //
  80. // The difference between ber_skip_tag() and ber_peek_tag() is that the
  81. // state pointer is advanced past the first tag+lenght and is pointed to
  82. // the value part of the next element
  83. //
  84. WINBERAPI ULONG BERAPI ber_skip_tag( BerElement *pBerElement, ULONG *pLen );
  85. //
  86. // This returns the tag of the next element to be parsed in the
  87. // supplied BerElement. The length of this element is stored in the
  88. // pLen argument.
  89. //
  90. // LBER_DEFAULT is returned if there is no further data to be read
  91. // else the tag of the next element is returned.
  92. //
  93. WINBERAPI ULONG BERAPI ber_peek_tag( BerElement *pBerElement, ULONG *pLen);
  94. //
  95. // This returns the tag and length of the first element in a SET, SET OF
  96. // or SEQUENCE OF data value.
  97. //
  98. // LBER_DEFAULT is returned if the constructed value is empty else, the tag
  99. // is returned. It also returns an opaque cookie which has to be passed to
  100. // subsequent invocations of ber_next_element().
  101. //
  102. WINBERAPI ULONG BERAPI ber_first_element( BerElement *pBerElement, ULONG *pLen, CHAR **ppOpaque );
  103. //
  104. // This positions the state at the start of the next element in the
  105. // constructed type.
  106. //
  107. // LBER_DEFAULT is returned if the constructed value is empty else, the tag
  108. // is returned.
  109. //
  110. WINBERAPI ULONG BERAPI ber_next_element( BerElement *pBerElement, ULONG *pLen, CHAR *opaque );
  111. //
  112. // This allocates a BerVal structure whose contents are taken from the
  113. // supplied BerElement structure.
  114. //
  115. // The return values are 0 on success and -1 on error.
  116. //
  117. WINBERAPI INT BERAPI ber_flatten( BerElement *pBerElement, PBERVAL *pBerVal );
  118. /*
  119. The ber_printf() routine is used to encode a BER element in much the
  120. same way that sprintf() works. One important difference, though, is
  121. that state information is kept in the ber argument so that multiple
  122. calls can be made to ber_printf() to append to the end of the BER ele-
  123. ment. ber MUST be a pointer to a BerElement returned by ber_alloc_t().
  124. ber_printf() interprets and formats its arguments according to the for-
  125. mat string fmt. ber_printf() returns -1 if there is an error during
  126. encoding and a non-negative number if successful. As with sprintf(),
  127. each character in fmt refers to an argument to ber_printf().
  128. The format string can contain the following format characters:
  129. 't' Tag. The next argument is a ber_tag_t specifying the tag to
  130. override the next element to be written to the ber. This works
  131. across calls. The integer tag value SHOULD contain the tag
  132. class, constructed bit, and tag value. For example, a tag of
  133. "[3]" for a constructed type is 0xA3U. All implementations MUST
  134. support tags that fit in a single octet (i.e., where the tag
  135. value is less than 32) and they MAY support larger tags.
  136. 'b' Boolean. The next argument is an ber_int_t, containing either 0
  137. for FALSE or 0xff for TRUE. A boolean element is output. If
  138. this format character is not preceded by the 't' format modif-
  139. ier, the tag 0x01U is used for the element.
  140. 'e' Enumerated. The next argument is a ber_int_t, containing the
  141. enumerated value in the host's byte order. An enumerated ele-
  142. ment is output. If this format character is not preceded by the
  143. 't' format modifier, the tag 0x0AU is used for the element.
  144. 'i' Integer. The next argument is a ber_int_t, containing the
  145. integer in the host's byte order. An integer element is output.
  146. If this format character is not preceded by the 't' format
  147. modifier, the tag 0x02U is used for the element.
  148. 'n' Null. No argument is needed. An ASN.1 NULL element is output.
  149. If this format character is not preceded by the 't' format
  150. modifier, the tag 0x05U is used for the element.
  151. 'o' Octet string. The next two arguments are a char *, followed by
  152. a ber_len_t with the length of the string. The string MAY con-
  153. tain null bytes and are do not have to be zero-terminated. An
  154. octet string element is output, in primitive form. If this for-
  155. mat character is not preceded by the 't' format modifier, the
  156. tag 0x04U is used for the element.
  157. 's' Octet string. The next argument is a char * pointing to a
  158. zero-terminated string. An octet string element in primitive
  159. form is output, which does not include the trailing '\0' (null)
  160. byte. If this format character is not preceded by the 't' format
  161. modifier, the tag 0x04U is used for the element.
  162. 'v' Several octet strings. The next argument is a char **, an array
  163. of char * pointers to zero-terminated strings. The last element
  164. in the array MUST be a NULL pointer. The octet strings do not
  165. include the trailing '\0' (null) byte. Note that a construct
  166. like '{v}' is used to get an actual SEQUENCE OF octet strings.
  167. The 't' format modifier cannot be used with this format charac-
  168. ter.
  169. 'V' Several octet strings. A NULL-terminated array of struct berval
  170. *'s is supplied. Note that a construct like '{V}' is used to
  171. get an actual SEQUENCE OF octet strings. The 't' format modifier
  172. cannot be used with this format character.
  173. '{' Begin sequence. No argument is needed. If this format charac-
  174. ter is not preceded by the 't' format modifier, the tag 0x30U is
  175. used.
  176. '}' End sequence. No argument is needed. The 't' format modifier
  177. cannot be used with this format character.
  178. '[' Begin set. No argument is needed. If this format character is
  179. not preceded by the 't' format modifier, the tag 0x31U is used.
  180. ']' End set. No argument is needed. The 't' format modifier cannot
  181. be used with this format character.
  182. */
  183. WINBERAPI INT BERAPI ber_printf( BerElement *pBerElement, PCHAR fmt, ... );
  184. /*
  185. The ber_scanf() routine is used to decode a BER element in much the same
  186. way that sscanf() works. One important difference, though, is that some
  187. state information is kept with the ber argument so that multiple calls
  188. can be made to ber_scanf() to sequentially read from the BER element.
  189. The ber argument SHOULD be a pointer to a BerElement returned by
  190. ber_init(). ber_scanf interprets the bytes according to the format
  191. string fmt, and stores the results in its additional arguments.
  192. ber_scanf() returns LBER_ERROR on error, and a different value on suc-
  193. cess.
  194. The format string contains conversion specifications which are used to
  195. direct the interpretation of the BER element. The format string can
  196. contain the following characters:
  197. 'a' Octet string. A char ** argument MUST be supplied. Memory is
  198. allocated, filled with the contents of the octet string, zero-
  199. terminated, and the pointer to the string is stored in the argu-
  200. ment. The returned value SHOULD be freed using ldap_memfree.
  201. The tag of the element MUST indicate the primitive form
  202. (constructed strings are not supported) but is otherwise ignored
  203. and discarded during the decoding. This format cannot be used
  204. with octet strings which could contain null bytes.
  205. 'O' Octet string. A struct berval ** argument MUST be supplied,
  206. which upon return points to an allocated struct berval contain-
  207. ing the octet string and its length. ber_bvfree() SHOULD be
  208. called to free the allocated memory. The tag of the element
  209. MUST indicate the primitive form (constructed strings are not
  210. supported) but is otherwise ignored during the decoding.
  211. 'b' Boolean. A pointer to a ber_int_t MUST be supplied. The
  212. ber_int_t value stored will be 0 for FALSE or nonzero for TRUE.
  213. The tag of the element MUST indicate the primitive form but is
  214. otherwise ignored during the decoding.
  215. 'e' Enumerated. A pointer to a ber_int_t MUST be supplied. The
  216. enumerated value stored will be in host byte order. The tag of
  217. the element MUST indicate the primitive form but is otherwise
  218. ignored during the decoding. ber_scanf() will return an error
  219. if the value of the enumerated value cannot be stored in a
  220. ber_int_t.
  221. 'i' Integer. A pointer to a ber_int_t MUST be supplied. The
  222. ber_int_t value stored will be in host byte order. The tag of
  223. the element MUST indicate the primitive form but is otherwise
  224. ignored during the decoding. ber_scanf() will return an error
  225. if the integer cannot be stored in a ber_int_t.
  226. 'B' Bitstring. A char ** argument MUST be supplied which will point
  227. to the allocated bits, followed by a ber_len_t * argument, which
  228. will point to the length (in bits) of the bitstring returned.
  229. ldap_memfree SHOULD be called to free the bitstring. The tag of
  230. the element MUST indicate the primitive form (constructed bit-
  231. strings are not supported) but is otherwise ignored during the
  232. decoding.
  233. 'n' Null. No argument is needed. The element is verified to have a
  234. zero-length value and is skipped. The tag is ignored.
  235. 'v' Several octet strings. A char *** argument MUST be supplied,
  236. which upon return points to an allocated NULL-terminated array
  237. of char *'s containing the octet strings. NULL is stored if the
  238. sequence is empty. ldap_memfree SHOULD be called to free each
  239. element of the array and the array itself. The tag of the
  240. sequence and of the octet strings are ignored.
  241. 'V' Several octet strings (which could contain null bytes). A
  242. struct berval *** MUST be supplied, which upon return points to
  243. a allocated NULL-terminated array of struct berval *'s contain-
  244. ing the octet strings and their lengths. NULL is stored if the
  245. sequence is empty. ber_bvecfree() can be called to free the
  246. allocated memory. The tag of the sequence and of the octet
  247. strings are ignored.
  248. 'x' Skip element. The next element is skipped. No argument is
  249. needed.
  250. '{' Begin sequence. No argument is needed. The initial sequence
  251. tag and length are skipped.
  252. '}' End sequence. No argument is needed.
  253. '[' Begin set. No argument is needed. The initial set tag and
  254. length are skipped.
  255. ']' End set. No argument is needed.
  256. */
  257. WINBERAPI ULONG BERAPI ber_scanf( BerElement *pBerElement, PCHAR fmt, ... );
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif // _WINBER_DEFINED_