]> git.sur5r.net Git - openldap/blob - include/lutil.h
ITS#2217 fix option sorting
[openldap] / include / lutil.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.  A copy of this license is available at
9  * http://www.OpenLDAP.org/license.html or in file LICENSE in the
10  * top-level directory of the distribution.
11  */
12
13 #ifndef _LUTIL_H
14 #define _LUTIL_H 1
15
16 #include <ldap_cdefs.h>
17 #include <lber_types.h>
18
19 /*
20  * Include file for LDAP utility routine
21  */
22
23 LDAP_BEGIN_DECL
24
25 /* n octets encode into ceiling(n/3) * 4 bytes */
26 /* Avoid floating point math through extra padding */
27
28 #define LUTIL_BASE64_ENCODE_LEN(n)      (((n)+2)/3 * 4)
29 #define LUTIL_BASE64_DECODE_LEN(n)      (((n)+3)/4 * 3)
30
31 /* ISC Base64 Routines */
32 /* base64.c */
33
34 LDAP_LUTIL_F( int )
35 lutil_b64_ntop LDAP_P((
36         unsigned char const *,
37         size_t,
38         char *,
39         size_t));
40
41 LDAP_LUTIL_F( int )
42 lutil_b64_pton LDAP_P((
43         char const *,
44         unsigned char *,
45         size_t));
46
47 /* detach.c */
48 LDAP_LUTIL_F( void )
49 lutil_detach LDAP_P((
50         int debug,
51         int do_close));
52
53 /* entropy.c */
54 LDAP_LUTIL_F( int )
55 lutil_entropy LDAP_P((
56         unsigned char *buf,
57         ber_len_t nbytes ));
58
59 /* passfile.c */
60 struct berval;  /* avoid pulling in lber.h */
61
62 LDAP_LUTIL_F( int )
63 lutil_get_filed_password LDAP_P((
64         const char *filename,
65         struct berval * ));
66
67 /* passwd.c */
68 struct lutil_pw_scheme;
69
70 typedef int (LUTIL_PASSWD_CHK_FUNC)(
71         const struct berval *scheme,
72         const struct berval *passwd,
73         const struct berval *cred,
74         const char **text );
75
76 typedef struct berval * (LUTIL_PASSWD_HASH_FUNC) (
77         const struct berval *scheme,
78         const struct berval *passwd,
79         const char **text );
80
81 LDAP_LUTIL_F( int )
82 lutil_passwd_add LDAP_P((
83         struct berval *scheme,
84         LUTIL_PASSWD_CHK_FUNC *chk_fn,
85         LUTIL_PASSWD_HASH_FUNC *hash_fn ));
86
87 LDAP_LUTIL_F( void )
88 lutil_passwd_init LDAP_P(( void ));
89
90 LDAP_LUTIL_F( void )
91 lutil_passwd_destroy LDAP_P(( void ));
92
93 LDAP_LUTIL_F( int )
94 lutil_authpasswd LDAP_P((
95         const struct berval *passwd,    /* stored password */
96         const struct berval *cred,      /* user supplied value */
97         const char **methods ));
98
99 LDAP_LUTIL_F( int )
100 lutil_authpasswd_hash LDAP_P((
101         const struct berval *cred,
102         struct berval **passwd, /* password to store */
103         struct berval **salt,   /* salt to store */
104         const char *method ));
105
106 #if defined( SLAPD_SPASSWD ) && defined( HAVE_CYRUS_SASL )
107         /* cheat to avoid pulling in <sasl.h> */
108 LDAP_LUTIL_V( struct sasl_conn * ) lutil_passwd_sasl_conn;
109 #endif
110
111 LDAP_LUTIL_F( int )
112 lutil_passwd LDAP_P((
113         const struct berval *passwd,    /* stored password */
114         const struct berval *cred,      /* user supplied value */
115         const char **methods,
116         const char **text ));                   /* error message */
117
118 LDAP_LUTIL_F( struct berval * )
119 lutil_passwd_generate LDAP_P(( ber_len_t ));
120
121 LDAP_LUTIL_F( struct berval * )
122 lutil_passwd_hash LDAP_P((
123         const struct berval *passwd,
124         const char *method,
125         const char **text ));
126
127 LDAP_LUTIL_F( int )
128 lutil_passwd_scheme LDAP_P((
129         const char *scheme ));
130
131 LDAP_LUTIL_F( int )
132 lutil_salt_format LDAP_P((
133         const char *format ));
134
135 /* utils.c */
136 LDAP_LUTIL_F( char* )
137 lutil_progname LDAP_P((
138         const char* name,
139         int argc,
140         char *argv[] ));
141
142 LDAP_LUTIL_F( char* )
143 lutil_strcopy LDAP_P(( char *dst, const char *src ));
144
145 LDAP_LUTIL_F( char* )
146 lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
147
148 struct tm;
149
150 /* use this macro to statically allocate buffer for lutil_gentime */
151 #define LDAP_LUTIL_GENTIME_BUFSIZE      22
152 #define lutil_gentime(s,m,t)    lutil_localtime((s),(m),(t),0)
153 LDAP_LUTIL_F( size_t )
154 lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
155                         long delta ));
156
157 #ifndef HAVE_MKSTEMP
158 LDAP_LUTIL_F( int )
159 mkstemp LDAP_P (( char * template ));
160 #endif
161
162 /* sockpair.c */
163 LDAP_LUTIL_F( int )
164 lutil_pair( ber_socket_t sd[2] );
165
166 /* uuid.c */
167 /* use this macro to allocate buffer for lutil_uuidstr */
168 #define LDAP_LUTIL_UUIDSTR_BUFSIZE      40
169 LDAP_LUTIL_F( size_t )
170 lutil_uuidstr( char *buf, size_t len );
171
172 /* csn.c */
173 /* use this macro to allocate buffer for lutil_csnstr */
174 #define LDAP_LUTIL_CSNSTR_BUFSIZE       64
175 LDAP_LUTIL_F( size_t )
176 lutil_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
177
178 /*
179  * Sometimes not all declarations in a header file are needed.
180  * An indicator to this is whether or not the symbol's type has
181  * been defined. Thus, we don't need to include a symbol if
182  * its type has not been defined through another header file.
183  */
184
185 #ifdef HAVE_NT_SERVICE_MANAGER
186 LDAP_LUTIL_V (int) is_NT_Service;
187
188 #ifdef _LDAP_PVT_THREAD_H
189 LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
190 #endif /* _LDAP_PVT_THREAD_H */
191
192 /* macros are different between Windows and Mingw */
193 #if defined(_WINSVC_H) || defined(_WINSVC_)
194 LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
195 LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
196 #endif /* _WINSVC_H */
197
198 LDAP_LUTIL_F (void)
199 lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
200
201 LDAP_LUTIL_F (void)
202 lutil_ReportShutdownComplete( void );
203
204 LDAP_LUTIL_F (void *)
205 lutil_getRegParam( char *svc, char *value );
206
207 LDAP_LUTIL_F (int)
208 lutil_srv_install( char* service, char * displayName, char* filename,
209                  int auto_start );
210 LDAP_LUTIL_F (int)
211 lutil_srv_remove ( char* service, char* filename );
212
213 #endif /* HAVE_NT_SERVICE_MANAGER */
214
215 #ifdef HAVE_NT_EVENT_LOG
216 LDAP_LUTIL_F (void)
217 lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
218
219 LDAP_LUTIL_F (void)
220 lutil_LogStoppedEvent( char *svc );
221 #endif
222
223 #ifdef HAVE_EBCDIC
224 /* Generally this has only been used to put '\n' to stdout. We need to
225  * make sure it is output in EBCDIC.
226  */
227 #undef putchar
228 #undef putc
229 #define putchar(c)     putc((c), stdout)
230 #define putc(c,fp)     do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
231 #endif
232
233 LDAP_END_DECL
234
235 #endif /* _LUTIL_H */