ldap_pvt.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2022 The OpenLDAP Foundation.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted only as authorized by the OpenLDAP
  9. * Public License.
  10. *
  11. * A copy of this license is available in file LICENSE in the
  12. * top-level directory of the distribution or, alternatively, at
  13. * <http://www.OpenLDAP.org/license.html>.
  14. */
  15. /* ldap-pvt.h - Header for ldap_pvt_ functions.
  16. * These are meant to be internal to OpenLDAP Software.
  17. */
  18. #ifndef _LDAP_PVT_H
  19. #define _LDAP_PVT_H 1
  20. #include <openldap.h> /* get public interfaces */
  21. #include <lber.h> /* get ber_slen_t */
  22. #include <lber_pvt.h> /* get Sockbuf_Buf */
  23. LDAP_BEGIN_DECL
  24. LDAP_F ( int )
  25. ldap_pvt_url_scheme2proto LDAP_P((
  26. const char * ));
  27. LDAP_F ( int )
  28. ldap_pvt_url_scheme2tls LDAP_P((
  29. const char * ));
  30. LDAP_F ( int )
  31. ldap_pvt_url_scheme2proxied LDAP_P((
  32. const char * ));
  33. LDAP_F ( int )
  34. ldap_pvt_url_scheme_port LDAP_P((
  35. const char *, int ));
  36. struct ldap_url_desc; /* avoid pulling in <ldap.h> */
  37. #define LDAP_PVT_URL_PARSE_NONE (0x00U)
  38. #define LDAP_PVT_URL_PARSE_NOEMPTY_HOST (0x01U)
  39. #define LDAP_PVT_URL_PARSE_DEF_PORT (0x02U)
  40. #define LDAP_PVT_URL_PARSE_NOEMPTY_DN (0x04U)
  41. #define LDAP_PVT_URL_PARSE_NODEF_SCOPE (0x08U)
  42. #define LDAP_PVT_URL_PARSE_HISTORIC (LDAP_PVT_URL_PARSE_NODEF_SCOPE | \
  43. LDAP_PVT_URL_PARSE_NOEMPTY_HOST | \
  44. LDAP_PVT_URL_PARSE_DEF_PORT)
  45. LDAP_F( int )
  46. ldap_url_parse_ext LDAP_P((
  47. LDAP_CONST char *url,
  48. struct ldap_url_desc **ludpp,
  49. unsigned flags ));
  50. LDAP_F (int) ldap_url_parselist LDAP_P(( /* deprecated, use ldap_url_parselist_ext() */
  51. struct ldap_url_desc **ludlist,
  52. const char *url ));
  53. LDAP_F (int) ldap_url_parselist_ext LDAP_P((
  54. struct ldap_url_desc **ludlist,
  55. const char *url,
  56. const char *sep,
  57. unsigned flags ));
  58. LDAP_F (char *) ldap_url_list2urls LDAP_P((
  59. struct ldap_url_desc *ludlist ));
  60. LDAP_F (void) ldap_free_urllist LDAP_P((
  61. struct ldap_url_desc *ludlist ));
  62. LDAP_F (int) ldap_pvt_scope2bv LDAP_P ((
  63. int scope, struct berval *bv ));
  64. LDAP_F (LDAP_CONST char *) ldap_pvt_scope2str LDAP_P ((
  65. int scope ));
  66. LDAP_F (int) ldap_pvt_bv2scope LDAP_P ((
  67. struct berval *bv ));
  68. LDAP_F (int) ldap_pvt_str2scope LDAP_P ((
  69. LDAP_CONST char * ));
  70. LDAP_F( char * )
  71. ldap_pvt_ctime LDAP_P((
  72. const time_t *tp,
  73. char *buf ));
  74. # if defined( HAVE_GMTIME_R )
  75. # define USE_GMTIME_R
  76. # define ldap_pvt_gmtime(timep, result) gmtime_r((timep), (result))
  77. # else
  78. LDAP_F( struct tm * )
  79. ldap_pvt_gmtime LDAP_P((
  80. LDAP_CONST time_t *timep,
  81. struct tm *result ));
  82. #endif
  83. # if defined( HAVE_LOCALTIME_R )
  84. # define USE_LOCALTIME_R
  85. # define ldap_pvt_localtime(timep, result) localtime_r((timep), (result))
  86. # else
  87. LDAP_F( struct tm * )
  88. ldap_pvt_localtime LDAP_P((
  89. LDAP_CONST time_t *timep,
  90. struct tm *result ));
  91. # endif
  92. #if defined( USE_GMTIME_R ) && defined( USE_LOCALTIME_R )
  93. # define ldap_pvt_gmtime_lock() (0)
  94. # define ldap_pvt_gmtime_unlock() (0)
  95. #else
  96. LDAP_F( int )
  97. ldap_pvt_gmtime_lock LDAP_P(( void ));
  98. LDAP_F( int )
  99. ldap_pvt_gmtime_unlock LDAP_P(( void ));
  100. #endif /* USE_GMTIME_R && USE_LOCALTIME_R */
  101. /* Get current time as a structured time */
  102. struct lutil_tm;
  103. LDAP_F( void )
  104. ldap_pvt_gettime LDAP_P(( struct lutil_tm * ));
  105. #ifdef _WIN32
  106. #define gettimeofday(tv,tz) ldap_pvt_gettimeofday(tv,tz)
  107. struct timeval;
  108. LDAP_F( int )
  109. ldap_pvt_gettimeofday LDAP_P(( struct timeval *tv, void *unused ));
  110. #ifndef CLOCK_REALTIME
  111. #define CLOCK_REALTIME 0
  112. #endif
  113. #define clock_gettime(clkid,tv) ldap_pvt_clock_gettime(clkid,tv)
  114. struct timespec;
  115. LDAP_F( int )
  116. ldap_pvt_clock_gettime LDAP_P(( int clkid, struct timespec *tv ));
  117. #endif
  118. /* use this macro to allocate buffer for ldap_pvt_csnstr */
  119. #define LDAP_PVT_CSNSTR_BUFSIZE 64
  120. LDAP_F( size_t )
  121. ldap_pvt_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
  122. LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
  123. struct hostent; /* avoid pulling in <netdb.h> */
  124. LDAP_F( int )
  125. ldap_pvt_gethostbyname_a LDAP_P((
  126. const char *name,
  127. struct hostent *resbuf,
  128. char **buf,
  129. struct hostent **result,
  130. int *herrno_ptr ));
  131. LDAP_F( int )
  132. ldap_pvt_gethostbyaddr_a LDAP_P((
  133. const char *addr,
  134. int len,
  135. int type,
  136. struct hostent *resbuf,
  137. char **buf,
  138. struct hostent **result,
  139. int *herrno_ptr ));
  140. struct sockaddr;
  141. LDAP_F( int )
  142. ldap_pvt_get_hname LDAP_P((
  143. const struct sockaddr * sa,
  144. int salen,
  145. char *name,
  146. int namelen,
  147. char **herr ));
  148. #ifdef LDAP_PF_LOCAL
  149. #define LDAP_IPADDRLEN (MAXPATHLEN + sizeof("PATH="))
  150. #elif defined(LDAP_PF_INET6)
  151. #define LDAP_IPADDRLEN sizeof("IP=[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535")
  152. #else
  153. #define LDAP_IPADDRLEN sizeof("IP=255.255.255.255:65336")
  154. #endif
  155. union Sockaddr;
  156. LDAP_F (void)
  157. ldap_pvt_sockaddrstr LDAP_P((
  158. union Sockaddr *sa,
  159. struct berval * ));
  160. /* charray.c */
  161. LDAP_F( int )
  162. ldap_charray_add LDAP_P((
  163. char ***a,
  164. const char *s ));
  165. LDAP_F( int )
  166. ldap_charray_merge LDAP_P((
  167. char ***a,
  168. char **s ));
  169. LDAP_F( void )
  170. ldap_charray_free LDAP_P(( char **a ));
  171. LDAP_F( int )
  172. ldap_charray_inlist LDAP_P((
  173. char **a,
  174. const char *s ));
  175. LDAP_F( char ** )
  176. ldap_charray_dup LDAP_P(( char **a ));
  177. LDAP_F( char ** )
  178. ldap_str2charray LDAP_P((
  179. const char *str,
  180. const char *brkstr ));
  181. LDAP_F( char * )
  182. ldap_charray2str LDAP_P((
  183. char **array, const char* sep ));
  184. /* getdn.c */
  185. #ifdef LDAP_AVA_NULL /* in ldap.h */
  186. LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
  187. LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
  188. LDAP_F( int ) ldap_bv2dn_x LDAP_P((
  189. struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
  190. LDAP_F( int ) ldap_dn2bv_x LDAP_P((
  191. LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
  192. LDAP_F( int ) ldap_bv2rdn_x LDAP_P((
  193. struct berval *, LDAPRDN *, char **, unsigned flags, void *ctx ));
  194. LDAP_F( int ) ldap_rdn2bv_x LDAP_P((
  195. LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
  196. #endif /* LDAP_AVA_NULL */
  197. /* url.c */
  198. LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
  199. /*
  200. * these macros assume 'x' is an ASCII x
  201. * and assume the "C" locale
  202. */
  203. #define LDAP_ASCII(c) (!((c) & 0x80))
  204. #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
  205. #define LDAP_DIGIT(c) ((c) >= '0' && (c) <= '9')
  206. #define LDAP_LOWER(c) ((c) >= 'a' && (c) <= 'z')
  207. #define LDAP_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
  208. #define LDAP_ALPHA(c) (LDAP_LOWER(c) || LDAP_UPPER(c))
  209. #define LDAP_ALNUM(c) (LDAP_ALPHA(c) || LDAP_DIGIT(c))
  210. #define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-')
  211. #define LDAP_HEXLOWER(c) ((c) >= 'a' && (c) <= 'f')
  212. #define LDAP_HEXUPPER(c) ((c) >= 'A' && (c) <= 'F')
  213. #define LDAP_HEX(c) (LDAP_DIGIT(c) || \
  214. LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c))
  215. /* controls.c */
  216. struct ldapcontrol;
  217. LDAP_F (int)
  218. ldap_pvt_put_control LDAP_P((
  219. const struct ldapcontrol *c,
  220. BerElement *ber ));
  221. LDAP_F (int) ldap_pvt_get_controls LDAP_P((
  222. BerElement *be,
  223. struct ldapcontrol ***ctrlsp));
  224. #ifdef HAVE_CYRUS_SASL
  225. /* cyrus.c */
  226. struct sasl_security_properties; /* avoid pulling in <sasl.h> */
  227. LDAP_F (int) ldap_pvt_sasl_secprops LDAP_P((
  228. const char *in,
  229. struct sasl_security_properties *secprops ));
  230. LDAP_F (void) ldap_pvt_sasl_secprops_unparse LDAP_P((
  231. struct sasl_security_properties *secprops,
  232. struct berval *out ));
  233. LDAP_F (void *) ldap_pvt_sasl_mutex_new LDAP_P((void));
  234. LDAP_F (int) ldap_pvt_sasl_mutex_lock LDAP_P((void *mutex));
  235. LDAP_F (int) ldap_pvt_sasl_mutex_unlock LDAP_P((void *mutex));
  236. LDAP_F (void) ldap_pvt_sasl_mutex_dispose LDAP_P((void *mutex));
  237. LDAP_F (int) ldap_pvt_sasl_cbinding_parse LDAP_P(( const char *arg ));
  238. LDAP_F (void *) ldap_pvt_sasl_cbinding LDAP_P(( void *ssl, int type,
  239. int is_server ));
  240. #endif /* HAVE_CYRUS_SASL */
  241. struct sockbuf; /* avoid pulling in <lber.h> */
  242. LDAP_F (int) ldap_pvt_sasl_install LDAP_P(( struct sockbuf *, void * ));
  243. LDAP_F (void) ldap_pvt_sasl_remove LDAP_P(( struct sockbuf * ));
  244. /*
  245. * SASL encryption support for LBER Sockbufs
  246. */
  247. struct sb_sasl_generic_data;
  248. struct sb_sasl_generic_ops {
  249. void (*init)(struct sb_sasl_generic_data *p,
  250. ber_len_t *min_send,
  251. ber_len_t *max_send,
  252. ber_len_t *max_recv);
  253. ber_int_t (*encode)(struct sb_sasl_generic_data *p,
  254. unsigned char *buf,
  255. ber_len_t len,
  256. Sockbuf_Buf *dst);
  257. ber_int_t (*decode)(struct sb_sasl_generic_data *p,
  258. const Sockbuf_Buf *src,
  259. Sockbuf_Buf *dst);
  260. void (*reset_buf)(struct sb_sasl_generic_data *p,
  261. Sockbuf_Buf *buf);
  262. void (*fini)(struct sb_sasl_generic_data *p);
  263. };
  264. struct sb_sasl_generic_install {
  265. const struct sb_sasl_generic_ops *ops;
  266. void *ops_private;
  267. };
  268. struct sb_sasl_generic_data {
  269. const struct sb_sasl_generic_ops *ops;
  270. void *ops_private;
  271. Sockbuf_IO_Desc *sbiod;
  272. ber_len_t min_send;
  273. ber_len_t max_send;
  274. ber_len_t max_recv;
  275. Sockbuf_Buf sec_buf_in;
  276. Sockbuf_Buf buf_in;
  277. Sockbuf_Buf buf_out;
  278. unsigned int flags;
  279. #define LDAP_PVT_SASL_PARTIAL_WRITE 1
  280. };
  281. #ifndef LDAP_PVT_SASL_LOCAL_SSF
  282. #define LDAP_PVT_SASL_LOCAL_SSF 71 /* SSF for Unix Domain Sockets */
  283. #endif /* ! LDAP_PVT_SASL_LOCAL_SSF */
  284. struct ldap;
  285. struct ldapmsg;
  286. struct ldifrecord;
  287. /* abandon */
  288. LDAP_F ( int ) ldap_pvt_discard LDAP_P((
  289. struct ldap *ld, ber_int_t msgid ));
  290. /* init.c */
  291. LDAP_F( int )
  292. ldap_pvt_conf_option LDAP_P((
  293. char *cmd, char *opt, int userconf ));
  294. /* ldifutil.c */
  295. LDAP_F( int )
  296. ldap_parse_ldif_record_x LDAP_P((
  297. struct berval *rbuf,
  298. unsigned long linenum,
  299. struct ldifrecord *lr,
  300. const char *errstr,
  301. unsigned int flags,
  302. void *ctx ));
  303. /* messages.c */
  304. LDAP_F( BerElement * )
  305. ldap_get_message_ber LDAP_P((
  306. struct ldapmsg * ));
  307. /* open */
  308. LDAP_F (int) ldap_open_internal_connection LDAP_P((
  309. struct ldap **ldp, ber_socket_t *fdp ));
  310. /* sasl.c */
  311. LDAP_F (int) ldap_pvt_sasl_generic_install LDAP_P(( Sockbuf *sb,
  312. struct sb_sasl_generic_install *install_arg ));
  313. LDAP_F (void) ldap_pvt_sasl_generic_remove LDAP_P(( Sockbuf *sb ));
  314. /* search.c */
  315. LDAP_F( int ) ldap_pvt_put_filter LDAP_P((
  316. BerElement *ber,
  317. const char *str ));
  318. LDAP_F( char * )
  319. ldap_pvt_find_wildcard LDAP_P(( const char *s ));
  320. LDAP_F( ber_slen_t )
  321. ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
  322. LDAP_F( ber_len_t )
  323. ldap_bv2escaped_filter_value_len LDAP_P(( struct berval *in ));
  324. LDAP_F( int )
  325. ldap_bv2escaped_filter_value_x LDAP_P(( struct berval *in, struct berval *out,
  326. int inplace, void *ctx ));
  327. LDAP_F (int) ldap_pvt_search LDAP_P((
  328. struct ldap *ld,
  329. LDAP_CONST char *base,
  330. int scope,
  331. LDAP_CONST char *filter,
  332. char **attrs,
  333. int attrsonly,
  334. struct ldapcontrol **sctrls,
  335. struct ldapcontrol **cctrls,
  336. struct timeval *timeout,
  337. int sizelimit,
  338. int deref,
  339. int *msgidp ));
  340. LDAP_F(int) ldap_pvt_search_s LDAP_P((
  341. struct ldap *ld,
  342. LDAP_CONST char *base,
  343. int scope,
  344. LDAP_CONST char *filter,
  345. char **attrs,
  346. int attrsonly,
  347. struct ldapcontrol **sctrls,
  348. struct ldapcontrol **cctrls,
  349. struct timeval *timeout,
  350. int sizelimit,
  351. int deref,
  352. struct ldapmsg **res ));
  353. /* string.c */
  354. LDAP_F( char * )
  355. ldap_pvt_str2upper LDAP_P(( char *str ));
  356. LDAP_F( char * )
  357. ldap_pvt_str2lower LDAP_P(( char *str ));
  358. LDAP_F( struct berval * )
  359. ldap_pvt_str2upperbv LDAP_P(( char *str, struct berval *bv ));
  360. LDAP_F( struct berval * )
  361. ldap_pvt_str2lowerbv LDAP_P(( char *str, struct berval *bv ));
  362. /* tls.c */
  363. LDAP_F (int) ldap_pvt_tls_config LDAP_P(( struct ldap *ld,
  364. int option, const char *arg ));
  365. LDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldap *ld,
  366. int option, void *arg ));
  367. LDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldap *ld,
  368. int option, void *arg ));
  369. LDAP_F (void) ldap_pvt_tls_destroy LDAP_P(( void ));
  370. LDAP_F (int) ldap_pvt_tls_init LDAP_P(( int do_threads ));
  371. LDAP_F (int) ldap_pvt_tls_init_def_ctx LDAP_P(( int is_server ));
  372. LDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
  373. LDAP_F (int) ldap_pvt_tls_connect LDAP_P(( struct ldap *ld, Sockbuf *sb, const char *host ));
  374. LDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
  375. LDAP_F (void *) ldap_pvt_tls_sb_ctx LDAP_P(( Sockbuf *sb ));
  376. LDAP_F (void) ldap_pvt_tls_ctx_free LDAP_P(( void * ));
  377. typedef int LDAPDN_rewrite_dummy LDAP_P (( void *dn, unsigned flags ));
  378. typedef int (LDAP_TLS_CONNECT_CB) LDAP_P (( struct ldap *ld, void *ssl,
  379. void *ctx, void *arg ));
  380. LDAP_F (int) ldap_pvt_tls_get_my_dn LDAP_P(( void *ctx, struct berval *dn,
  381. LDAPDN_rewrite_dummy *func, unsigned flags ));
  382. LDAP_F (int) ldap_pvt_tls_get_peer_dn LDAP_P(( void *ctx, struct berval *dn,
  383. LDAPDN_rewrite_dummy *func, unsigned flags ));
  384. LDAP_F (int) ldap_pvt_tls_get_strength LDAP_P(( void *ctx ));
  385. LDAP_F (int) ldap_pvt_tls_get_unique LDAP_P(( void *ctx, struct berval *buf, int is_server ));
  386. LDAP_F (int) ldap_pvt_tls_get_endpoint LDAP_P(( void *ctx, struct berval *buf, int is_server ));
  387. LDAP_F (const char *) ldap_pvt_tls_get_version LDAP_P(( void *ctx ));
  388. LDAP_F (const char *) ldap_pvt_tls_get_cipher LDAP_P(( void *ctx ));
  389. LDAP_END_DECL
  390. /*
  391. * Multiple precision stuff
  392. *
  393. * May use OpenSSL's BIGNUM if built with TLS,
  394. * or GNU's multiple precision library. But if
  395. * long long is available, that's big enough
  396. * and much more efficient.
  397. *
  398. * If none is available, unsigned long data is used.
  399. */
  400. LDAP_BEGIN_DECL
  401. #ifdef USE_MP_BIGNUM
  402. /*
  403. * Use OpenSSL's BIGNUM
  404. */
  405. #error #include <openssl/crypto.h>
  406. #error #include <openssl/bn.h>
  407. typedef BIGNUM* ldap_pvt_mp_t;
  408. #define LDAP_PVT_MP_INIT (NULL)
  409. #define ldap_pvt_mp_init(mp) \
  410. do { (mp) = BN_new(); } while (0)
  411. /* FIXME: we rely on mpr being initialized */
  412. #define ldap_pvt_mp_init_set(mpr,mpv) \
  413. do { ldap_pvt_mp_init((mpr)); BN_add((mpr), (mpr), (mpv)); } while (0)
  414. #define ldap_pvt_mp_add(mpr,mpv) \
  415. BN_add((mpr), (mpr), (mpv))
  416. #define ldap_pvt_mp_add_ulong(mp,v) \
  417. BN_add_word((mp), (v))
  418. #define ldap_pvt_mp_clear(mp) \
  419. do { BN_free((mp)); (mp) = 0; } while (0)
  420. #elif defined(USE_MP_GMP)
  421. /*
  422. * Use GNU's multiple precision library
  423. */
  424. #include <gmp.h>
  425. typedef mpz_t ldap_pvt_mp_t;
  426. #define LDAP_PVT_MP_INIT { 0 }
  427. #define ldap_pvt_mp_init(mp) \
  428. mpz_init((mp))
  429. #define ldap_pvt_mp_init_set(mpr,mpv) \
  430. mpz_init_set((mpr), (mpv))
  431. #define ldap_pvt_mp_add(mpr,mpv) \
  432. mpz_add((mpr), (mpr), (mpv))
  433. #define ldap_pvt_mp_add_ulong(mp,v) \
  434. mpz_add_ui((mp), (mp), (v))
  435. #define ldap_pvt_mp_clear(mp) \
  436. mpz_clear((mp))
  437. #else
  438. /*
  439. * Use unsigned long long
  440. */
  441. #ifdef USE_MP_LONG_LONG
  442. typedef unsigned long long ldap_pvt_mp_t;
  443. #define LDAP_PVT_MP_INIT (0LL)
  444. #elif defined(USE_MP_LONG)
  445. typedef unsigned long ldap_pvt_mp_t;
  446. #define LDAP_PVT_MP_INIT (0L)
  447. #elif defined(HAVE_LONG_LONG)
  448. typedef unsigned long long ldap_pvt_mp_t;
  449. #define LDAP_PVT_MP_INIT (0LL)
  450. #else
  451. typedef unsigned long ldap_pvt_mp_t;
  452. #define LDAP_PVT_MP_INIT (0L)
  453. #endif
  454. #define ldap_pvt_mp_init(mp) \
  455. do { (mp) = 0; } while (0)
  456. #define ldap_pvt_mp_init_set(mpr,mpv) \
  457. do { (mpr) = (mpv); } while (0)
  458. #define ldap_pvt_mp_add(mpr,mpv) \
  459. do { (mpr) += (mpv); } while (0)
  460. #define ldap_pvt_mp_add_ulong(mp,v) \
  461. do { (mp) += (v); } while (0)
  462. #define ldap_pvt_mp_clear(mp) \
  463. do { (mp) = 0; } while (0)
  464. #endif /* MP */
  465. #include "ldap_pvt_uc.h"
  466. LDAP_END_DECL
  467. LDAP_BEGIN_DECL
  468. #include <limits.h> /* get CHAR_BIT */
  469. /* Buffer space for sign, decimal digits and \0. Note: log10(2) < 146/485. */
  470. #define LDAP_PVT_INTTYPE_CHARS(type) (((sizeof(type)*CHAR_BIT-1)*146)/485 + 3)
  471. LDAP_END_DECL
  472. #endif /* _LDAP_PVT_H */