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