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