PageRenderTime 68ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/openldap-2.4.31/evo-openldap-2.4.31/include/lutil.h

#
C++ Header | 361 lines | 245 code | 71 blank | 45 comment | 5 complexity | 2835308fd95909cfedc78bf253f37761 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2012 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. #ifndef _LUTIL_H
  16. #define _LUTIL_H 1
  17. #include <ldap_cdefs.h>
  18. #include <lber_types.h>
  19. /*
  20. * Include file for LDAP utility routine
  21. */
  22. LDAP_BEGIN_DECL
  23. /* n octets encode into ceiling(n/3) * 4 bytes */
  24. /* Avoid floating point math through extra padding */
  25. #define LUTIL_BASE64_ENCODE_LEN(n) (((n)+2)/3 * 4)
  26. #define LUTIL_BASE64_DECODE_LEN(n) ((n)/4*3)
  27. /* ISC Base64 Routines */
  28. /* base64.c */
  29. LDAP_LUTIL_F( int )
  30. lutil_b64_ntop LDAP_P((
  31. unsigned char const *,
  32. size_t,
  33. char *,
  34. size_t));
  35. LDAP_LUTIL_F( int )
  36. lutil_b64_pton LDAP_P((
  37. char const *,
  38. unsigned char *,
  39. size_t));
  40. /* detach.c */
  41. LDAP_LUTIL_F( int )
  42. lutil_detach LDAP_P((
  43. int debug,
  44. int do_close));
  45. /* entropy.c */
  46. LDAP_LUTIL_F( int )
  47. lutil_entropy LDAP_P((
  48. unsigned char *buf,
  49. ber_len_t nbytes ));
  50. /* passfile.c */
  51. struct berval; /* avoid pulling in lber.h */
  52. LDAP_LUTIL_F( int )
  53. lutil_get_filed_password LDAP_P((
  54. const char *filename,
  55. struct berval * ));
  56. /* passwd.c */
  57. struct lutil_pw_scheme;
  58. #define LUTIL_PASSWD_OK (0)
  59. #define LUTIL_PASSWD_ERR (-1)
  60. typedef int (LUTIL_PASSWD_CHK_FUNC)(
  61. const struct berval *scheme,
  62. const struct berval *passwd,
  63. const struct berval *cred,
  64. const char **text );
  65. typedef int (LUTIL_PASSWD_HASH_FUNC) (
  66. const struct berval *scheme,
  67. const struct berval *passwd,
  68. struct berval *hash,
  69. const char **text );
  70. LDAP_LUTIL_F( int )
  71. lutil_passwd_add LDAP_P((
  72. struct berval *scheme,
  73. LUTIL_PASSWD_CHK_FUNC *chk_fn,
  74. LUTIL_PASSWD_HASH_FUNC *hash_fn ));
  75. LDAP_LUTIL_F( void )
  76. lutil_passwd_init LDAP_P(( void ));
  77. LDAP_LUTIL_F( void )
  78. lutil_passwd_destroy LDAP_P(( void ));
  79. LDAP_LUTIL_F( int )
  80. lutil_authpasswd LDAP_P((
  81. const struct berval *passwd, /* stored password */
  82. const struct berval *cred, /* user supplied value */
  83. const char **methods ));
  84. LDAP_LUTIL_F( int )
  85. lutil_authpasswd_hash LDAP_P((
  86. const struct berval *cred,
  87. struct berval **passwd, /* password to store */
  88. struct berval **salt, /* salt to store */
  89. const char *method ));
  90. #ifdef SLAPD_CRYPT
  91. typedef int (lutil_cryptfunc) LDAP_P((
  92. const char *key,
  93. const char *salt,
  94. char **hash ));
  95. LDAP_LUTIL_V (lutil_cryptfunc *) lutil_cryptptr;
  96. #endif
  97. LDAP_LUTIL_F( int )
  98. lutil_passwd LDAP_P((
  99. const struct berval *passwd, /* stored password */
  100. const struct berval *cred, /* user supplied value */
  101. const char **methods,
  102. const char **text )); /* error message */
  103. LDAP_LUTIL_F( int )
  104. lutil_passwd_generate LDAP_P(( struct berval *pw, ber_len_t ));
  105. LDAP_LUTIL_F( int )
  106. lutil_passwd_hash LDAP_P((
  107. const struct berval *passwd,
  108. const char *method,
  109. struct berval *hash,
  110. const char **text ));
  111. LDAP_LUTIL_F( int )
  112. lutil_passwd_scheme LDAP_P((
  113. const char *scheme ));
  114. LDAP_LUTIL_F( int )
  115. lutil_salt_format LDAP_P((
  116. const char *format ));
  117. LDAP_LUTIL_F( int )
  118. lutil_passwd_string64 LDAP_P((
  119. const struct berval *sc,
  120. const struct berval *hash,
  121. struct berval *b64,
  122. const struct berval *salt ));
  123. /* utils.c */
  124. LDAP_LUTIL_F( char* )
  125. lutil_progname LDAP_P((
  126. const char* name,
  127. int argc,
  128. char *argv[] ));
  129. typedef struct lutil_tm {
  130. int tm_sec; /* seconds 0-60 (1 leap second) */
  131. int tm_min; /* minutes 0-59 */
  132. int tm_hour; /* hours 0-23 */
  133. int tm_mday; /* day 1-31 */
  134. int tm_mon; /* month 0-11 */
  135. int tm_year; /* year - 1900 */
  136. int tm_usec; /* microseconds */
  137. int tm_usub; /* submicro */
  138. } lutil_tm;
  139. typedef struct lutil_timet {
  140. unsigned int tt_sec; /* seconds since 1900 */
  141. int tt_gsec; /* seconds since 1900, high 7 bits */
  142. unsigned int tt_usec; /* microseconds */
  143. } lutil_timet;
  144. /* Parse a timestamp string into a structure */
  145. LDAP_LUTIL_F( int )
  146. lutil_parsetime LDAP_P((
  147. char *atm, struct lutil_tm * ));
  148. /* Convert structured time to time in seconds since 1900 */
  149. LDAP_LUTIL_F( int )
  150. lutil_tm2time LDAP_P((
  151. struct lutil_tm *, struct lutil_timet * ));
  152. #ifdef _WIN32
  153. LDAP_LUTIL_F( void )
  154. lutil_slashpath LDAP_P(( char* path ));
  155. #define LUTIL_SLASHPATH(p) lutil_slashpath(p)
  156. #else
  157. #define LUTIL_SLASHPATH(p)
  158. #endif
  159. LDAP_LUTIL_F( char* )
  160. lutil_strcopy LDAP_P(( char *dst, const char *src ));
  161. LDAP_LUTIL_F( char* )
  162. lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
  163. LDAP_LUTIL_F( char* )
  164. lutil_memcopy LDAP_P(( char *dst, const char *src, size_t n ));
  165. #define lutil_strbvcopy(a, bv) lutil_memcopy((a),(bv)->bv_val,(bv)->bv_len)
  166. struct tm;
  167. /* use this macro to statically allocate buffer for lutil_gentime */
  168. #define LDAP_LUTIL_GENTIME_BUFSIZE 22
  169. #define lutil_gentime(s,m,t) lutil_localtime((s),(m),(t),0)
  170. LDAP_LUTIL_F( size_t )
  171. lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
  172. long delta ));
  173. #ifndef HAVE_MKSTEMP
  174. LDAP_LUTIL_F( int )
  175. mkstemp LDAP_P (( char * template ));
  176. #endif
  177. /* sockpair.c */
  178. LDAP_LUTIL_F( int )
  179. lutil_pair( ber_socket_t sd[2] );
  180. /* uuid.c */
  181. /* use this macro to allocate buffer for lutil_uuidstr */
  182. #define LDAP_LUTIL_UUIDSTR_BUFSIZE 40
  183. LDAP_LUTIL_F( size_t )
  184. lutil_uuidstr( char *buf, size_t len );
  185. LDAP_LUTIL_F( int )
  186. lutil_uuidstr_from_normalized(
  187. char *uuid,
  188. size_t uuidlen,
  189. char *buf,
  190. size_t buflen );
  191. /*
  192. * Sometimes not all declarations in a header file are needed.
  193. * An indicator to this is whether or not the symbol's type has
  194. * been defined. Thus, we don't need to include a symbol if
  195. * its type has not been defined through another header file.
  196. */
  197. #ifdef HAVE_NT_SERVICE_MANAGER
  198. LDAP_LUTIL_V (int) is_NT_Service;
  199. #ifdef _LDAP_PVT_THREAD_H
  200. LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
  201. #endif /* _LDAP_PVT_THREAD_H */
  202. /* macros are different between Windows and Mingw */
  203. #if defined(_WINSVC_H) || defined(_WINSVC_)
  204. LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
  205. LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
  206. #endif /* _WINSVC_H */
  207. LDAP_LUTIL_F (void)
  208. lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
  209. LDAP_LUTIL_F (void)
  210. lutil_ReportShutdownComplete( void );
  211. LDAP_LUTIL_F (void *)
  212. lutil_getRegParam( char *svc, char *value );
  213. LDAP_LUTIL_F (int)
  214. lutil_srv_install( char* service, char * displayName, char* filename,
  215. int auto_start );
  216. LDAP_LUTIL_F (int)
  217. lutil_srv_remove ( char* service, char* filename );
  218. #endif /* HAVE_NT_SERVICE_MANAGER */
  219. #ifdef HAVE_NT_EVENT_LOG
  220. LDAP_LUTIL_F (void)
  221. lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
  222. LDAP_LUTIL_F (void)
  223. lutil_LogStoppedEvent( char *svc );
  224. #endif
  225. #ifdef HAVE_EBCDIC
  226. /* Generally this has only been used to put '\n' to stdout. We need to
  227. * make sure it is output in EBCDIC.
  228. */
  229. #undef putchar
  230. #undef putc
  231. #define putchar(c) putc((c), stdout)
  232. #define putc(c,fp) do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
  233. #endif
  234. LDAP_LUTIL_F (int)
  235. lutil_atoix( int *v, const char *s, int x );
  236. LDAP_LUTIL_F (int)
  237. lutil_atoux( unsigned *v, const char *s, int x );
  238. LDAP_LUTIL_F (int)
  239. lutil_atolx( long *v, const char *s, int x );
  240. LDAP_LUTIL_F (int)
  241. lutil_atoulx( unsigned long *v, const char *s, int x );
  242. #define lutil_atoi(v, s) lutil_atoix((v), (s), 10)
  243. #define lutil_atou(v, s) lutil_atoux((v), (s), 10)
  244. #define lutil_atol(v, s) lutil_atolx((v), (s), 10)
  245. #define lutil_atoul(v, s) lutil_atoulx((v), (s), 10)
  246. #ifdef HAVE_LONG_LONG
  247. #if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ)
  248. LDAP_LUTIL_F (int)
  249. lutil_atollx( long long *v, const char *s, int x );
  250. #define lutil_atoll(v, s) lutil_atollx((v), (s), 10)
  251. #endif /* HAVE_STRTOLL || HAVE_STRTOQ */
  252. #if defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ)
  253. LDAP_LUTIL_F (int)
  254. lutil_atoullx( unsigned long long *v, const char *s, int x );
  255. #define lutil_atoull(v, s) lutil_atoullx((v), (s), 10)
  256. #endif /* HAVE_STRTOULL || HAVE_STRTOUQ */
  257. #endif /* HAVE_LONG_LONG */
  258. LDAP_LUTIL_F (int)
  259. lutil_str2bin( struct berval *in, struct berval *out, void *ctx );
  260. /* Parse and unparse time intervals */
  261. LDAP_LUTIL_F (int)
  262. lutil_parse_time( const char *in, unsigned long *tp );
  263. LDAP_LUTIL_F (int)
  264. lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
  265. #ifdef timerdiv
  266. #define lutil_timerdiv timerdiv
  267. #else /* ! timerdiv */
  268. /* works inplace (x == t) */
  269. #define lutil_timerdiv(t,d,x) \
  270. do { \
  271. time_t s = (t)->tv_sec; \
  272. assert( d > 0 ); \
  273. (x)->tv_sec = s / d; \
  274. (x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \
  275. } while ( 0 )
  276. #endif /* ! timerdiv */
  277. #ifdef timermul
  278. #define lutil_timermul timermul
  279. #else /* ! timermul */
  280. /* works inplace (x == t) */
  281. #define lutil_timermul(t,m,x) \
  282. do { \
  283. time_t u = (t)->tv_usec * m; \
  284. assert( m > 0 ); \
  285. (x)->tv_sec = (t)->tv_sec * m + u / 1000000; \
  286. (x)->tv_usec = u % 1000000; \
  287. } while ( 0 );
  288. #endif /* ! timermul */
  289. LDAP_END_DECL
  290. #endif /* _LUTIL_H */