2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2010 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
19 #include <ldap_cdefs.h>
20 #include <lber_types.h>
23 * Include file for LDAP utility routine
28 /* n octets encode into ceiling(n/3) * 4 bytes */
29 /* Avoid floating point math through extra padding */
31 #define LUTIL_BASE64_ENCODE_LEN(n) (((n)+2)/3 * 4)
32 #define LUTIL_BASE64_DECODE_LEN(n) ((n)/4*3)
34 /* ISC Base64 Routines */
38 lutil_b64_ntop LDAP_P((
39 unsigned char const *,
45 lutil_b64_pton LDAP_P((
58 lutil_entropy LDAP_P((
63 struct berval; /* avoid pulling in lber.h */
66 lutil_get_filed_password LDAP_P((
71 struct lutil_pw_scheme;
73 #define LUTIL_PASSWD_OK (0)
74 #define LUTIL_PASSWD_ERR (-1)
76 typedef int (LUTIL_PASSWD_CHK_FUNC)(
77 const struct berval *scheme,
78 const struct berval *passwd,
79 const struct berval *cred,
82 typedef int (LUTIL_PASSWD_HASH_FUNC) (
83 const struct berval *scheme,
84 const struct berval *passwd,
89 lutil_passwd_add LDAP_P((
90 struct berval *scheme,
91 LUTIL_PASSWD_CHK_FUNC *chk_fn,
92 LUTIL_PASSWD_HASH_FUNC *hash_fn ));
95 lutil_passwd_init LDAP_P(( void ));
98 lutil_passwd_destroy LDAP_P(( void ));
101 lutil_authpasswd LDAP_P((
102 const struct berval *passwd, /* stored password */
103 const struct berval *cred, /* user supplied value */
104 const char **methods ));
107 lutil_authpasswd_hash LDAP_P((
108 const struct berval *cred,
109 struct berval **passwd, /* password to store */
110 struct berval **salt, /* salt to store */
111 const char *method ));
114 typedef int (lutil_cryptfunc) LDAP_P((
118 LDAP_LUTIL_V (lutil_cryptfunc *) lutil_cryptptr;
122 lutil_passwd LDAP_P((
123 const struct berval *passwd, /* stored password */
124 const struct berval *cred, /* user supplied value */
125 const char **methods,
126 const char **text )); /* error message */
129 lutil_passwd_generate LDAP_P(( struct berval *pw, ber_len_t ));
132 lutil_passwd_hash LDAP_P((
133 const struct berval *passwd,
136 const char **text ));
139 lutil_passwd_scheme LDAP_P((
140 const char *scheme ));
143 lutil_salt_format LDAP_P((
144 const char *format ));
147 LDAP_LUTIL_F( char* )
148 lutil_progname LDAP_P((
153 typedef struct lutil_tm {
154 int tm_sec; /* seconds 0-60 (1 leap second) */
155 int tm_min; /* minutes 0-59 */
156 int tm_hour; /* hours 0-23 */
157 int tm_mday; /* day 1-31 */
158 int tm_mon; /* month 0-11 */
159 int tm_year; /* year - 1900 */
160 int tm_usec; /* microseconds */
161 int tm_usub; /* submicro */
164 typedef struct lutil_timet {
165 unsigned int tt_sec; /* seconds since 1900 */
166 int tt_gsec; /* seconds since 1900, high 7 bits */
167 unsigned int tt_usec; /* microseconds */
170 /* Parse a timestamp string into a structure */
172 lutil_parsetime LDAP_P((
173 char *atm, struct lutil_tm * ));
175 /* Convert structured time to time in seconds since 1900 */
177 lutil_tm2time LDAP_P((
178 struct lutil_tm *, struct lutil_timet * ));
182 lutil_slashpath LDAP_P(( char* path ));
183 #define LUTIL_SLASHPATH(p) lutil_slashpath(p)
185 #define LUTIL_SLASHPATH(p)
188 LDAP_LUTIL_F( char* )
189 lutil_strcopy LDAP_P(( char *dst, const char *src ));
191 LDAP_LUTIL_F( char* )
192 lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
194 LDAP_LUTIL_F( char* )
195 lutil_memcopy LDAP_P(( char *dst, const char *src, size_t n ));
197 #define lutil_strbvcopy(a, bv) lutil_memcopy((a),(bv)->bv_val,(bv)->bv_len)
201 /* use this macro to statically allocate buffer for lutil_gentime */
202 #define LDAP_LUTIL_GENTIME_BUFSIZE 22
203 #define lutil_gentime(s,m,t) lutil_localtime((s),(m),(t),0)
204 LDAP_LUTIL_F( size_t )
205 lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
210 mkstemp LDAP_P (( char * template ));
215 lutil_pair( ber_socket_t sd[2] );
218 /* use this macro to allocate buffer for lutil_uuidstr */
219 #define LDAP_LUTIL_UUIDSTR_BUFSIZE 40
220 LDAP_LUTIL_F( size_t )
221 lutil_uuidstr( char *buf, size_t len );
224 lutil_uuidstr_from_normalized(
231 * Sometimes not all declarations in a header file are needed.
232 * An indicator to this is whether or not the symbol's type has
233 * been defined. Thus, we don't need to include a symbol if
234 * its type has not been defined through another header file.
237 #ifdef HAVE_NT_SERVICE_MANAGER
238 LDAP_LUTIL_V (int) is_NT_Service;
240 #ifdef _LDAP_PVT_THREAD_H
241 LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
242 #endif /* _LDAP_PVT_THREAD_H */
244 /* macros are different between Windows and Mingw */
245 #if defined(_WINSVC_H) || defined(_WINSVC_)
246 LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
247 LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
248 #endif /* _WINSVC_H */
251 lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
254 lutil_ReportShutdownComplete( void );
256 LDAP_LUTIL_F (void *)
257 lutil_getRegParam( char *svc, char *value );
260 lutil_srv_install( char* service, char * displayName, char* filename,
263 lutil_srv_remove ( char* service, char* filename );
265 #endif /* HAVE_NT_SERVICE_MANAGER */
267 #ifdef HAVE_NT_EVENT_LOG
269 lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
272 lutil_LogStoppedEvent( char *svc );
276 /* Generally this has only been used to put '\n' to stdout. We need to
277 * make sure it is output in EBCDIC.
281 #define putchar(c) putc((c), stdout)
282 #define putc(c,fp) do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
286 lutil_atoix( int *v, const char *s, int x );
289 lutil_atoux( unsigned *v, const char *s, int x );
292 lutil_atolx( long *v, const char *s, int x );
295 lutil_atoulx( unsigned long *v, const char *s, int x );
297 #define lutil_atoi(v, s) lutil_atoix((v), (s), 10)
298 #define lutil_atou(v, s) lutil_atoux((v), (s), 10)
299 #define lutil_atol(v, s) lutil_atolx((v), (s), 10)
300 #define lutil_atoul(v, s) lutil_atoulx((v), (s), 10)
302 #ifdef HAVE_LONG_LONG
303 #if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ)
305 lutil_atollx( long long *v, const char *s, int x );
306 #define lutil_atoll(v, s) lutil_atollx((v), (s), 10)
307 #endif /* HAVE_STRTOLL || HAVE_STRTOQ */
309 #if defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ)
311 lutil_atoullx( unsigned long long *v, const char *s, int x );
312 #define lutil_atoull(v, s) lutil_atoullx((v), (s), 10)
313 #endif /* HAVE_STRTOULL || HAVE_STRTOUQ */
314 #endif /* HAVE_LONG_LONG */
317 lutil_str2bin( struct berval *in, struct berval *out, void *ctx );
319 /* Parse and unparse time intervals */
321 lutil_parse_time( const char *in, unsigned long *tp );
324 lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
327 #define lutil_timerdiv timerdiv
328 #else /* ! timerdiv */
329 /* works inplace (x == t) */
330 #define lutil_timerdiv(t,d,x) \
332 time_t s = (t)->tv_sec; \
334 (x)->tv_sec = s / d; \
335 (x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \
337 #endif /* ! timerdiv */
340 #define lutil_timermul timermul
341 #else /* ! timermul */
342 /* works inplace (x == t) */
343 #define lutil_timermul(t,m,x) \
345 time_t u = (t)->tv_usec * m; \
347 (x)->tv_sec = (t)->tv_sec * m + u / 1000000; \
348 (x)->tv_usec = u % 1000000; \
350 #endif /* ! timermul */
354 #endif /* _LUTIL_H */