]> 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-2004 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 typedef int (LUTIL_PASSWD_CHK_FUNC)(
74         const struct berval *scheme,
75         const struct berval *passwd,
76         const struct berval *cred,
77         const char **text );
78
79 typedef struct berval * (LUTIL_PASSWD_HASH_FUNC) (
80         const struct berval *scheme,
81         const struct berval *passwd,
82         const char **text );
83
84 LDAP_LUTIL_F( int )
85 lutil_passwd_add LDAP_P((
86         struct berval *scheme,
87         LUTIL_PASSWD_CHK_FUNC *chk_fn,
88         LUTIL_PASSWD_HASH_FUNC *hash_fn ));
89
90 LDAP_LUTIL_F( void )
91 lutil_passwd_init LDAP_P(( void ));
92
93 LDAP_LUTIL_F( void )
94 lutil_passwd_destroy LDAP_P(( void ));
95
96 LDAP_LUTIL_F( int )
97 lutil_authpasswd LDAP_P((
98         const struct berval *passwd,    /* stored password */
99         const struct berval *cred,      /* user supplied value */
100         const char **methods ));
101
102 LDAP_LUTIL_F( int )
103 lutil_authpasswd_hash LDAP_P((
104         const struct berval *cred,
105         struct berval **passwd, /* password to store */
106         struct berval **salt,   /* salt to store */
107         const char *method ));
108
109 #if defined( SLAPD_SPASSWD ) && defined( HAVE_CYRUS_SASL )
110         /* cheat to avoid pulling in <sasl.h> */
111 LDAP_LUTIL_V( struct sasl_conn * ) lutil_passwd_sasl_conn;
112 #endif
113
114 LDAP_LUTIL_F( int )
115 lutil_passwd LDAP_P((
116         const struct berval *passwd,    /* stored password */
117         const struct berval *cred,      /* user supplied value */
118         const char **methods,
119         const char **text ));                   /* error message */
120
121 LDAP_LUTIL_F( struct berval * )
122 lutil_passwd_generate LDAP_P(( ber_len_t ));
123
124 LDAP_LUTIL_F( struct berval * )
125 lutil_passwd_hash LDAP_P((
126         const struct berval *passwd,
127         const char *method,
128         const char **text ));
129
130 LDAP_LUTIL_F( int )
131 lutil_passwd_scheme LDAP_P((
132         const char *scheme ));
133
134 LDAP_LUTIL_F( int )
135 lutil_salt_format LDAP_P((
136         const char *format ));
137
138 /* utils.c */
139 LDAP_LUTIL_F( char* )
140 lutil_progname LDAP_P((
141         const char* name,
142         int argc,
143         char *argv[] ));
144
145 LDAP_LUTIL_F( char* )
146 lutil_strcopy LDAP_P(( char *dst, const char *src ));
147
148 LDAP_LUTIL_F( char* )
149 lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
150
151 struct tm;
152
153 /* use this macro to statically allocate buffer for lutil_gentime */
154 #define LDAP_LUTIL_GENTIME_BUFSIZE      22
155 #define lutil_gentime(s,m,t)    lutil_localtime((s),(m),(t),0)
156 LDAP_LUTIL_F( size_t )
157 lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
158                         long delta ));
159
160 #ifndef HAVE_MKSTEMP
161 LDAP_LUTIL_F( int )
162 mkstemp LDAP_P (( char * template ));
163 #endif
164
165 /* sockpair.c */
166 LDAP_LUTIL_F( int )
167 lutil_pair( ber_socket_t sd[2] );
168
169 /* uuid.c */
170 /* use this macro to allocate buffer for lutil_uuidstr */
171 #define LDAP_LUTIL_UUIDSTR_BUFSIZE      40
172 LDAP_LUTIL_F( size_t )
173 lutil_uuidstr( char *buf, size_t len );
174
175 /* csn.c */
176 /* use this macro to allocate buffer for lutil_csnstr */
177 #define LDAP_LUTIL_CSNSTR_BUFSIZE       64
178 LDAP_LUTIL_F( size_t )
179 lutil_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
180
181 /*
182  * Sometimes not all declarations in a header file are needed.
183  * An indicator to this is whether or not the symbol's type has
184  * been defined. Thus, we don't need to include a symbol if
185  * its type has not been defined through another header file.
186  */
187
188 #ifdef HAVE_NT_SERVICE_MANAGER
189 LDAP_LUTIL_V (int) is_NT_Service;
190
191 #ifdef _LDAP_PVT_THREAD_H
192 LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
193 #endif /* _LDAP_PVT_THREAD_H */
194
195 /* macros are different between Windows and Mingw */
196 #if defined(_WINSVC_H) || defined(_WINSVC_)
197 LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
198 LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
199 #endif /* _WINSVC_H */
200
201 LDAP_LUTIL_F (void)
202 lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
203
204 LDAP_LUTIL_F (void)
205 lutil_ReportShutdownComplete( void );
206
207 LDAP_LUTIL_F (void *)
208 lutil_getRegParam( char *svc, char *value );
209
210 LDAP_LUTIL_F (int)
211 lutil_srv_install( char* service, char * displayName, char* filename,
212                  int auto_start );
213 LDAP_LUTIL_F (int)
214 lutil_srv_remove ( char* service, char* filename );
215
216 #endif /* HAVE_NT_SERVICE_MANAGER */
217
218 #ifdef HAVE_NT_EVENT_LOG
219 LDAP_LUTIL_F (void)
220 lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
221
222 LDAP_LUTIL_F (void)
223 lutil_LogStoppedEvent( char *svc );
224 #endif
225
226 #ifdef HAVE_EBCDIC
227 /* Generally this has only been used to put '\n' to stdout. We need to
228  * make sure it is output in EBCDIC.
229  */
230 #undef putchar
231 #undef putc
232 #define putchar(c)     putc((c), stdout)
233 #define putc(c,fp)     do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
234 #endif
235
236 LDAP_END_DECL
237
238 #endif /* _LUTIL_H */