Back to index

openldap  2.4.31
lutil.h
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 #ifndef _LUTIL_H
00017 #define _LUTIL_H 1
00018 
00019 #include <ldap_cdefs.h>
00020 #include <lber_types.h>
00021 
00022 /*
00023  * Include file for LDAP utility routine
00024  */
00025 
00026 LDAP_BEGIN_DECL
00027 
00028 /* n octets encode into ceiling(n/3) * 4 bytes */
00029 /* Avoid floating point math through extra padding */
00030 
00031 #define LUTIL_BASE64_ENCODE_LEN(n) (((n)+2)/3 * 4)
00032 #define LUTIL_BASE64_DECODE_LEN(n) ((n)/4*3)
00033 
00034 /* ISC Base64 Routines */
00035 /* base64.c */
00036 
00037 LDAP_LUTIL_F( int )
00038 lutil_b64_ntop LDAP_P((
00039        unsigned char const *,
00040        size_t,
00041        char *,
00042        size_t));
00043 
00044 LDAP_LUTIL_F( int )
00045 lutil_b64_pton LDAP_P((
00046        char const *,
00047        unsigned char *,
00048        size_t));
00049 
00050 /* detach.c */
00051 LDAP_LUTIL_F( int )
00052 lutil_detach LDAP_P((
00053        int debug,
00054        int do_close));
00055 
00056 /* entropy.c */
00057 LDAP_LUTIL_F( int )
00058 lutil_entropy LDAP_P((
00059        unsigned char *buf,
00060        ber_len_t nbytes ));
00061 
00062 /* passfile.c */
00063 struct berval;       /* avoid pulling in lber.h */
00064 
00065 LDAP_LUTIL_F( int )
00066 lutil_get_filed_password LDAP_P((
00067        const char *filename,
00068        struct berval * ));
00069 
00070 /* passwd.c */
00071 struct lutil_pw_scheme;
00072 
00073 #define LUTIL_PASSWD_OK            (0)
00074 #define LUTIL_PASSWD_ERR    (-1)
00075 
00076 typedef int (LUTIL_PASSWD_CHK_FUNC)(
00077        const struct berval *scheme,
00078        const struct berval *passwd,
00079        const struct berval *cred,
00080        const char **text );
00081 
00082 typedef int (LUTIL_PASSWD_HASH_FUNC) (
00083        const struct berval *scheme,
00084        const struct berval *passwd,
00085        struct berval *hash, 
00086        const char **text );
00087 
00088 LDAP_LUTIL_F( int )
00089 lutil_passwd_add LDAP_P((
00090        struct berval *scheme,
00091        LUTIL_PASSWD_CHK_FUNC *chk_fn,
00092        LUTIL_PASSWD_HASH_FUNC *hash_fn ));
00093 
00094 LDAP_LUTIL_F( void )
00095 lutil_passwd_init LDAP_P(( void ));
00096 
00097 LDAP_LUTIL_F( void )
00098 lutil_passwd_destroy LDAP_P(( void ));
00099 
00100 LDAP_LUTIL_F( int )
00101 lutil_authpasswd LDAP_P((
00102        const struct berval *passwd,       /* stored password */
00103        const struct berval *cred,  /* user supplied value */
00104        const char **methods ));
00105 
00106 LDAP_LUTIL_F( int )
00107 lutil_authpasswd_hash LDAP_P((
00108        const struct berval *cred,
00109        struct berval **passwd,     /* password to store */
00110        struct berval **salt,       /* salt to store */
00111        const char *method ));
00112 
00113 #ifdef SLAPD_CRYPT
00114 typedef int (lutil_cryptfunc) LDAP_P((
00115        const char *key,
00116        const char *salt,
00117        char **hash ));
00118 LDAP_LUTIL_V (lutil_cryptfunc *) lutil_cryptptr;
00119 #endif
00120 
00121 LDAP_LUTIL_F( int )
00122 lutil_passwd LDAP_P((
00123        const struct berval *passwd,       /* stored password */
00124        const struct berval *cred,  /* user supplied value */
00125        const char **methods,
00126        const char **text ));                     /* error message */
00127 
00128 LDAP_LUTIL_F( int )
00129 lutil_passwd_generate LDAP_P(( struct berval *pw, ber_len_t ));
00130 
00131 LDAP_LUTIL_F( int )
00132 lutil_passwd_hash LDAP_P((
00133        const struct berval *passwd,
00134        const char *method,
00135        struct berval *hash,
00136        const char **text ));
00137 
00138 LDAP_LUTIL_F( int )
00139 lutil_passwd_scheme LDAP_P((
00140        const char *scheme ));
00141 
00142 LDAP_LUTIL_F( int )
00143 lutil_salt_format LDAP_P((
00144        const char *format ));
00145 
00146 LDAP_LUTIL_F( int )
00147 lutil_passwd_string64 LDAP_P((
00148        const struct berval *sc,
00149        const struct berval *hash,
00150        struct berval *b64,
00151        const struct berval *salt ));
00152 
00153 /* utils.c */
00154 LDAP_LUTIL_F( char* )
00155 lutil_progname LDAP_P((
00156        const char* name,
00157        int argc,
00158        char *argv[] ));
00159 
00160 typedef struct lutil_tm {
00161        int tm_sec;   /* seconds 0-60 (1 leap second) */
00162        int tm_min;   /* minutes 0-59 */
00163        int tm_hour;  /* hours 0-23 */
00164        int tm_mday;  /* day 1-31 */
00165        int tm_mon;   /* month 0-11 */
00166        int tm_year;  /* year - 1900 */
00167        int tm_usec;  /* microseconds */
00168        int tm_usub;  /* submicro */
00169 } lutil_tm;
00170 
00171 typedef struct lutil_timet {
00172        unsigned int tt_sec; /* seconds since 1900 */
00173        int tt_gsec;         /* seconds since 1900, high 7 bits */
00174        unsigned int tt_usec;       /* microseconds */
00175 } lutil_timet;
00176 
00177 /* Parse a timestamp string into a structure */
00178 LDAP_LUTIL_F( int )
00179 lutil_parsetime LDAP_P((
00180        char *atm, struct lutil_tm * ));
00181 
00182 /* Convert structured time to time in seconds since 1900 */
00183 LDAP_LUTIL_F( int )
00184 lutil_tm2time LDAP_P((
00185        struct lutil_tm *, struct lutil_timet * ));
00186 
00187 #ifdef _WIN32
00188 LDAP_LUTIL_F( void )
00189 lutil_slashpath LDAP_P(( char* path ));
00190 #define       LUTIL_SLASHPATH(p)   lutil_slashpath(p)
00191 #else
00192 #define       LUTIL_SLASHPATH(p)
00193 #endif
00194 
00195 LDAP_LUTIL_F( char* )
00196 lutil_strcopy LDAP_P(( char *dst, const char *src ));
00197 
00198 LDAP_LUTIL_F( char* )
00199 lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
00200 
00201 LDAP_LUTIL_F( char* )
00202 lutil_memcopy LDAP_P(( char *dst, const char *src, size_t n ));
00203 
00204 #define lutil_strbvcopy(a, bv) lutil_memcopy((a),(bv)->bv_val,(bv)->bv_len)
00205 
00206 struct tm;
00207 
00208 /* use this macro to statically allocate buffer for lutil_gentime */
00209 #define LDAP_LUTIL_GENTIME_BUFSIZE 22
00210 #define lutil_gentime(s,m,t)       lutil_localtime((s),(m),(t),0)
00211 LDAP_LUTIL_F( size_t )
00212 lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
00213                      long delta ));
00214 
00215 #ifndef HAVE_MKSTEMP
00216 LDAP_LUTIL_F( int )
00217 mkstemp LDAP_P (( char * template ));
00218 #endif
00219 
00220 /* sockpair.c */
00221 LDAP_LUTIL_F( int )
00222 lutil_pair( ber_socket_t sd[2] );
00223 
00224 /* uuid.c */
00225 /* use this macro to allocate buffer for lutil_uuidstr */
00226 #define LDAP_LUTIL_UUIDSTR_BUFSIZE 40
00227 LDAP_LUTIL_F( size_t )
00228 lutil_uuidstr( char *buf, size_t len );
00229 
00230 LDAP_LUTIL_F( int )
00231 lutil_uuidstr_from_normalized(
00232        char          *uuid,
00233        size_t        uuidlen,
00234        char          *buf,
00235        size_t        buflen );
00236 
00237 /*
00238  * Sometimes not all declarations in a header file are needed.
00239  * An indicator to this is whether or not the symbol's type has
00240  * been defined. Thus, we don't need to include a symbol if
00241  * its type has not been defined through another header file.
00242  */
00243 
00244 #ifdef HAVE_NT_SERVICE_MANAGER
00245 LDAP_LUTIL_V (int) is_NT_Service;
00246 
00247 #ifdef _LDAP_PVT_THREAD_H
00248 LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
00249 #endif /* _LDAP_PVT_THREAD_H */
00250 
00251 /* macros are different between Windows and Mingw */
00252 #if defined(_WINSVC_H) || defined(_WINSVC_)
00253 LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
00254 LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
00255 #endif /* _WINSVC_H */
00256 
00257 LDAP_LUTIL_F (void)
00258 lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
00259 
00260 LDAP_LUTIL_F (void)
00261 lutil_ReportShutdownComplete( void );
00262 
00263 LDAP_LUTIL_F (void *)
00264 lutil_getRegParam( char *svc, char *value );
00265 
00266 LDAP_LUTIL_F (int)
00267 lutil_srv_install( char* service, char * displayName, char* filename,
00268                int auto_start );
00269 LDAP_LUTIL_F (int)
00270 lutil_srv_remove ( char* service, char* filename );
00271 
00272 #endif /* HAVE_NT_SERVICE_MANAGER */
00273 
00274 #ifdef HAVE_NT_EVENT_LOG
00275 LDAP_LUTIL_F (void)
00276 lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
00277 
00278 LDAP_LUTIL_F (void)
00279 lutil_LogStoppedEvent( char *svc );
00280 #endif
00281 
00282 #ifdef HAVE_EBCDIC
00283 /* Generally this has only been used to put '\n' to stdout. We need to
00284  * make sure it is output in EBCDIC.
00285  */
00286 #undef putchar
00287 #undef putc
00288 #define putchar(c)     putc((c), stdout)
00289 #define putc(c,fp)     do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
00290 #endif
00291 
00292 LDAP_LUTIL_F (int)
00293 lutil_atoix( int *v, const char *s, int x );
00294 
00295 LDAP_LUTIL_F (int)
00296 lutil_atoux( unsigned *v, const char *s, int x );
00297 
00298 LDAP_LUTIL_F (int)
00299 lutil_atolx( long *v, const char *s, int x );
00300 
00301 LDAP_LUTIL_F (int)
00302 lutil_atoulx( unsigned long *v, const char *s, int x );
00303 
00304 #define lutil_atoi(v, s)    lutil_atoix((v), (s), 10)
00305 #define lutil_atou(v, s)    lutil_atoux((v), (s), 10)
00306 #define lutil_atol(v, s)    lutil_atolx((v), (s), 10)
00307 #define lutil_atoul(v, s)   lutil_atoulx((v), (s), 10)
00308 
00309 #ifdef HAVE_LONG_LONG
00310 #if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ)
00311 LDAP_LUTIL_F (int)
00312 lutil_atollx( long long *v, const char *s, int x );
00313 #define lutil_atoll(v, s)   lutil_atollx((v), (s), 10)
00314 #endif /* HAVE_STRTOLL || HAVE_STRTOQ */
00315 
00316 #if defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ)
00317 LDAP_LUTIL_F (int)
00318 lutil_atoullx( unsigned long long *v, const char *s, int x );
00319 #define lutil_atoull(v, s)  lutil_atoullx((v), (s), 10)
00320 #endif /* HAVE_STRTOULL || HAVE_STRTOUQ */
00321 #endif /* HAVE_LONG_LONG */
00322 
00323 LDAP_LUTIL_F (int)
00324 lutil_str2bin( struct berval *in, struct berval *out, void *ctx );
00325 
00326 /* Parse and unparse time intervals */
00327 LDAP_LUTIL_F (int)
00328 lutil_parse_time( const char *in, unsigned long *tp );
00329 
00330 LDAP_LUTIL_F (int)
00331 lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
00332 
00333 #ifdef timerdiv
00334 #define lutil_timerdiv timerdiv
00335 #else /* ! timerdiv */
00336 /* works inplace (x == t) */
00337 #define lutil_timerdiv(t,d,x) \
00338        do { \
00339               time_t s = (t)->tv_sec; \
00340               assert( d > 0 ); \
00341               (x)->tv_sec = s / d; \
00342               (x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \
00343        } while ( 0 )
00344 #endif /* ! timerdiv */
00345 
00346 #ifdef timermul
00347 #define lutil_timermul timermul
00348 #else /* ! timermul */
00349 /* works inplace (x == t) */
00350 #define lutil_timermul(t,m,x) \
00351        do { \
00352               time_t u = (t)->tv_usec * m; \
00353               assert( m > 0 ); \
00354               (x)->tv_sec = (t)->tv_sec * m + u / 1000000; \
00355               (x)->tv_usec = u % 1000000; \
00356        } while ( 0 );
00357 #endif /* ! timermul */
00358 
00359 LDAP_END_DECL
00360 
00361 #endif /* _LUTIL_H */