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.

184 lines
5.1 KiB

  1. /*
  2. * Copyright (c) 1990 Regents of the University of Michigan.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms are permitted
  6. * provided that this notice is preserved and that due credit is given
  7. * to the University of Michigan at Ann Arbor. The name of the University
  8. * may not be used to endorse or promote products derived from this
  9. * software without specific prior written permission. This software
  10. * is provided ``as is'' without express or implied warranty.
  11. */
  12. #ifndef _LBER_H
  13. #define _LBER_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #if !defined( NEEDPROTOS ) && defined(__STDC__)
  18. #define NEEDPROTOS 1
  19. #endif
  20. /* BER classes and mask */
  21. #define LBER_CLASS_UNIVERSAL 0x00
  22. #define LBER_CLASS_APPLICATION 0x40
  23. #define LBER_CLASS_CONTEXT 0x80
  24. #define LBER_CLASS_PRIVATE 0xc0
  25. #define LBER_CLASS_MASK 0xc0
  26. /* BER encoding type and mask */
  27. #define LBER_PRIMITIVE 0x00
  28. #define LBER_CONSTRUCTED 0x20
  29. #define LBER_ENCODING_MASK 0x20
  30. #define LBER_BIG_TAG_MASK 0x1f
  31. #define LBER_MORE_TAG_MASK 0x80
  32. /*
  33. * Note that LBER_ERROR and LBER_DEFAULT are values that can never appear
  34. * as valid BER tags, and so it is safe to use them to report errors. In
  35. * fact, any tag for which the following is true is invalid:
  36. * (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )
  37. */
  38. #define LBER_ERROR 0xffffffffL
  39. #define LBER_DEFAULT 0xffffffffL
  40. /* general BER types we know about */
  41. #define LBER_BOOLEAN 0x01L
  42. #define LBER_INTEGER 0x02L
  43. #define LBER_BITSTRING 0x03L
  44. #define LBER_OCTETSTRING 0x04L
  45. #define LBER_NULL 0x05L
  46. #define LBER_ENUMERATED 0x0aL
  47. #define LBER_SEQUENCE 0x30L /* constructed */
  48. #define LBER_SET 0x31L /* constructed */
  49. #define OLD_LBER_SEQUENCE 0x10L /* w/o constructed bit - broken */
  50. #define OLD_LBER_SET 0x11L /* w/o constructed bit - broken */
  51. #ifdef NEEDPROTOS
  52. typedef int (*BERTranslateProc)( char **bufp, unsigned long *buflenp,
  53. int free_input );
  54. #else /* NEEDPROTOS */
  55. typedef int (*BERTranslateProc)();
  56. #endif /* NEEDPROTOS */
  57. typedef struct berelement {
  58. char *ber_buf;
  59. char *ber_ptr;
  60. char *ber_end;
  61. struct seqorset *ber_sos;
  62. unsigned long ber_tag;
  63. unsigned long ber_len;
  64. int ber_usertag;
  65. char ber_options;
  66. #define LBER_USE_DER 0x01
  67. #define LBER_USE_INDEFINITE_LEN 0x02
  68. #define LBER_TRANSLATE_STRINGS 0x04
  69. char *ber_rwptr;
  70. BERTranslateProc ber_encode_translate_proc;
  71. BERTranslateProc ber_decode_translate_proc;
  72. } BerElement;
  73. #define NULLBER ((BerElement *) 0)
  74. typedef struct sockbuf {
  75. #ifndef MACOS
  76. int sb_sd;
  77. #else /* MACOS */
  78. void *sb_sd;
  79. #endif /* MACOS */
  80. BerElement sb_ber;
  81. int sb_naddr; /* > 0 implies using CLDAP (UDP) */
  82. void *sb_useaddr; /* pointer to sockaddr to use next */
  83. void *sb_fromaddr; /* pointer to message source sockaddr */
  84. void **sb_addrs; /* actually an array of pointers to
  85. sockaddrs */
  86. int sb_options; /* to support copying ber elements */
  87. #define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
  88. #define LBER_TO_FILE_ONLY 0x02 /* only write to file, not network */
  89. #define LBER_MAX_INCOMING_SIZE 0x04 /* impose limit on incoming stuff */
  90. #define LBER_NO_READ_AHEAD 0x08 /* read only as much as requested */
  91. int sb_fd;
  92. long sb_max_incoming;
  93. } Sockbuf;
  94. #define READBUFSIZ 8192
  95. typedef struct seqorset {
  96. BerElement *sos_ber;
  97. unsigned long sos_clen;
  98. unsigned long sos_tag;
  99. char *sos_first;
  100. char *sos_ptr;
  101. struct seqorset *sos_next;
  102. } Seqorset;
  103. #define NULLSEQORSET ((Seqorset *) 0)
  104. /* structure for returning a sequence of octet strings + length */
  105. struct berval {
  106. unsigned long bv_len;
  107. char *bv_val;
  108. };
  109. #ifndef NEEDPROTOS
  110. extern BerElement *ber_alloc();
  111. extern BerElement *der_alloc();
  112. extern BerElement *ber_alloc_t();
  113. extern BerElement *ber_dup();
  114. extern int lber_debug;
  115. extern void ber_bvfree();
  116. extern void ber_bvecfree();
  117. extern struct berval *ber_bvdup();
  118. extern void ber_dump();
  119. extern void ber_sos_dump();
  120. extern void lber_bprint();
  121. extern void ber_reset();
  122. extern void ber_init();
  123. #else /* NEEDPROTOS */
  124. #if defined(WINSOCK)
  125. #include "proto-lb.h"
  126. #else
  127. #include "proto-lber.h"
  128. #endif
  129. #endif /* NEEDPROTOS */
  130. #if !defined(__alpha) || defined(VMS)
  131. #define LBER_HTONL( l ) htonl( l )
  132. #define LBER_NTOHL( l ) ntohl( l )
  133. #else /* __alpha */
  134. /*
  135. * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
  136. * lower-order 32-bits of a (64-bit) long, so we define correct versions
  137. * here.
  138. */
  139. #define LBER_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
  140. | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
  141. #define LBER_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
  142. | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
  143. #endif /* __alpha */
  144. /*
  145. * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
  146. */
  147. #ifdef MACOS
  148. #define SAFEMEMCPY( d, s, n ) BlockMoveData( (Ptr)s, (Ptr)d, n )
  149. #else /* MACOS */
  150. #ifdef sunos4
  151. #define SAFEMEMCPY( d, s, n ) bcopy( s, d, n )
  152. #else /* sunos4 */
  153. #define SAFEMEMCPY( d, s, n ) memmove( d, s, n )
  154. #endif /* sunos4 */
  155. #endif /* MACOS */
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif /* _LBER_H */