Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/ldap/include/lutil.h
4394 views
1
/* $OpenLDAP$ */
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
*
4
* Copyright 1998-2024 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
#include <ac/socket.h>
22
23
#ifdef HAVE_TCPD
24
# include <tcpd.h>
25
# define LUTIL_STRING_UNKNOWN STRING_UNKNOWN
26
#else /* ! TCP Wrappers */
27
# define LUTIL_STRING_UNKNOWN "unknown"
28
#endif /* ! TCP Wrappers */
29
30
/*
31
* Include file for LDAP utility routine
32
*/
33
34
LDAP_BEGIN_DECL
35
36
/* n octets encode into ceiling(n/3) * 4 bytes */
37
/* Avoid floating point math through extra padding */
38
39
#define LUTIL_BASE64_ENCODE_LEN(n) (((n)+2)/3 * 4)
40
#define LUTIL_BASE64_DECODE_LEN(n) ((n)/4*3)
41
42
/* ISC Base64 Routines */
43
/* base64.c */
44
45
LDAP_LUTIL_F( int )
46
lutil_b64_ntop LDAP_P((
47
unsigned char const *,
48
size_t,
49
char *,
50
size_t));
51
52
LDAP_LUTIL_F( int )
53
lutil_b64_pton LDAP_P((
54
char const *,
55
unsigned char *,
56
size_t));
57
58
/* detach.c */
59
LDAP_LUTIL_F( int )
60
lutil_detach LDAP_P((
61
int debug,
62
int do_close));
63
64
/* entropy.c */
65
LDAP_LUTIL_F( int )
66
lutil_entropy LDAP_P((
67
unsigned char *buf,
68
ber_len_t nbytes ));
69
70
/* passfile.c */
71
struct berval; /* avoid pulling in lber.h */
72
73
LDAP_LUTIL_F( int )
74
lutil_get_filed_password LDAP_P((
75
const char *filename,
76
struct berval * ));
77
78
/* passwd.c */
79
struct lutil_pw_scheme;
80
81
#define LUTIL_PASSWD_OK (0)
82
#define LUTIL_PASSWD_ERR (-1)
83
84
typedef int (LUTIL_PASSWD_CHK_FUNC)(
85
const struct berval *scheme,
86
const struct berval *passwd,
87
const struct berval *cred,
88
const char **text );
89
90
typedef int (LUTIL_PASSWD_HASH_FUNC) (
91
const struct berval *scheme,
92
const struct berval *passwd,
93
struct berval *hash,
94
const char **text );
95
96
LDAP_LUTIL_F( int )
97
lutil_passwd_add LDAP_P((
98
struct berval *scheme,
99
LUTIL_PASSWD_CHK_FUNC *chk_fn,
100
LUTIL_PASSWD_HASH_FUNC *hash_fn ));
101
102
LDAP_LUTIL_F( void )
103
lutil_passwd_init LDAP_P(( void ));
104
105
LDAP_LUTIL_F( void )
106
lutil_passwd_destroy LDAP_P(( void ));
107
108
LDAP_LUTIL_F( int )
109
lutil_authpasswd LDAP_P((
110
const struct berval *passwd, /* stored password */
111
const struct berval *cred, /* user supplied value */
112
const char **methods ));
113
114
LDAP_LUTIL_F( int )
115
lutil_authpasswd_hash LDAP_P((
116
const struct berval *cred,
117
struct berval **passwd, /* password to store */
118
struct berval **salt, /* salt to store */
119
const char *method ));
120
121
#ifdef SLAPD_CRYPT
122
typedef int (lutil_cryptfunc) LDAP_P((
123
const char *key,
124
const char *salt,
125
char **hash ));
126
LDAP_LUTIL_V (lutil_cryptfunc *) lutil_cryptptr;
127
#endif
128
129
LDAP_LUTIL_F( int )
130
lutil_passwd LDAP_P((
131
const struct berval *passwd, /* stored password */
132
const struct berval *cred, /* user supplied value */
133
const char **methods,
134
const char **text )); /* error message */
135
136
LDAP_LUTIL_F( int )
137
lutil_passwd_generate LDAP_P(( struct berval *pw, ber_len_t ));
138
139
LDAP_LUTIL_F( int )
140
lutil_passwd_hash LDAP_P((
141
const struct berval *passwd,
142
const char *method,
143
struct berval *hash,
144
const char **text ));
145
146
LDAP_LUTIL_F( int )
147
lutil_passwd_scheme LDAP_P((
148
const char *scheme ));
149
150
LDAP_LUTIL_F( int )
151
lutil_salt_format LDAP_P((
152
const char *format ));
153
154
LDAP_LUTIL_F( int )
155
lutil_passwd_string64 LDAP_P((
156
const struct berval *sc,
157
const struct berval *hash,
158
struct berval *b64,
159
const struct berval *salt ));
160
161
/* utils.c */
162
LDAP_LUTIL_F( char* )
163
lutil_progname LDAP_P((
164
const char* name,
165
int argc,
166
char *argv[] ));
167
168
typedef struct lutil_tm {
169
int tm_sec; /* seconds 0-60 (1 leap second) */
170
int tm_min; /* minutes 0-59 */
171
int tm_hour; /* hours 0-23 */
172
int tm_mday; /* day 1-31 */
173
int tm_mon; /* month 0-11 */
174
int tm_year; /* year - 1900 */
175
int tm_nsec; /* nanoseconds */
176
int tm_usub; /* submicro */
177
} lutil_tm;
178
179
typedef struct lutil_timet {
180
unsigned int tt_sec; /* seconds since epoch, 0000 or 1970 */
181
int tt_gsec; /* seconds since epoch, high 7 bits, maybe sign-flipped */
182
/* sign flipped to sort properly as unsigned ints */
183
unsigned int tt_nsec; /* nanoseconds */
184
} lutil_timet;
185
186
/* Parse a timestamp string into a structure */
187
LDAP_LUTIL_F( int )
188
lutil_parsetime LDAP_P((
189
char *atm, struct lutil_tm * ));
190
191
/* Convert structured time to time in seconds since 1970 (Unix epoch) */
192
LDAP_LUTIL_F( int )
193
lutil_tm2time LDAP_P((
194
struct lutil_tm *, struct lutil_timet * ));
195
196
/* Convert structured time to time in seconds since 0000 (Proleptic Gregorian) */
197
LDAP_LUTIL_F( int )
198
lutil_tm2gtime LDAP_P((
199
struct lutil_tm *, struct lutil_timet * ));
200
201
#ifdef _WIN32
202
LDAP_LUTIL_F( void )
203
lutil_slashpath LDAP_P(( char* path ));
204
#define LUTIL_SLASHPATH(p) lutil_slashpath(p)
205
#else
206
#define LUTIL_SLASHPATH(p)
207
#endif
208
209
LDAP_LUTIL_F( char* )
210
lutil_strcopy LDAP_P(( char *dst, const char *src ));
211
212
LDAP_LUTIL_F( char* )
213
lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
214
215
LDAP_LUTIL_F( char* )
216
lutil_memcopy LDAP_P(( char *dst, const char *src, size_t n ));
217
218
#define lutil_strbvcopy(a, bv) lutil_memcopy((a),(bv)->bv_val,(bv)->bv_len)
219
220
struct tm;
221
222
/* use this macro to statically allocate buffer for lutil_gentime */
223
#define LDAP_LUTIL_GENTIME_BUFSIZE 22
224
#define lutil_gentime(s,m,t) lutil_localtime((s),(m),(t),0)
225
LDAP_LUTIL_F( size_t )
226
lutil_localtime LDAP_P(( char *s, size_t smax, const struct tm *tm,
227
long delta ));
228
229
#ifndef HAVE_MKSTEMP
230
LDAP_LUTIL_F( int )
231
mkstemp LDAP_P (( char * template ));
232
#endif
233
234
/* sockpair.c */
235
LDAP_LUTIL_F( int )
236
lutil_pair( ber_socket_t sd[2] );
237
238
/* uuid.c */
239
/* use this macro to allocate buffer for lutil_uuidstr */
240
#define LDAP_LUTIL_UUIDSTR_BUFSIZE 40
241
LDAP_LUTIL_F( size_t )
242
lutil_uuidstr( char *buf, size_t len );
243
244
LDAP_LUTIL_F( int )
245
lutil_uuidstr_from_normalized(
246
char *uuid,
247
size_t uuidlen,
248
char *buf,
249
size_t buflen );
250
251
/*
252
* Sometimes not all declarations in a header file are needed.
253
* An indicator to this is whether or not the symbol's type has
254
* been defined. Thus, we don't need to include a symbol if
255
* its type has not been defined through another header file.
256
*/
257
258
#ifdef HAVE_NT_SERVICE_MANAGER
259
LDAP_LUTIL_V (int) is_NT_Service;
260
261
#ifdef _LDAP_PVT_THREAD_H
262
LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
263
#endif /* _LDAP_PVT_THREAD_H */
264
265
/* macros are different between Windows and Mingw */
266
#if defined(_WINSVC_H) || defined(_WINSVC_)
267
LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
268
LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
269
#endif /* _WINSVC_H */
270
271
LDAP_LUTIL_F (void)
272
lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
273
274
LDAP_LUTIL_F (void)
275
lutil_ReportShutdownComplete( void );
276
277
LDAP_LUTIL_F (void *)
278
lutil_getRegParam( char *svc, char *value );
279
280
LDAP_LUTIL_F (int)
281
lutil_srv_install( char* service, char * displayName, char* filename,
282
int auto_start );
283
LDAP_LUTIL_F (int)
284
lutil_srv_remove ( char* service, char* filename );
285
286
#endif /* HAVE_NT_SERVICE_MANAGER */
287
288
#ifdef HAVE_NT_EVENT_LOG
289
LDAP_LUTIL_F (void)
290
lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
291
292
LDAP_LUTIL_F (void)
293
lutil_LogStoppedEvent( char *svc );
294
#endif
295
296
#ifdef HAVE_EBCDIC
297
/* Generally this has only been used to put '\n' to stdout. We need to
298
* make sure it is output in EBCDIC.
299
*/
300
#undef putchar
301
#undef putc
302
#define putchar(c) putc((c), stdout)
303
#define putc(c,fp) do { char x=(c); __atoe_l(&x,1); putc(x,fp); } while(0)
304
#endif
305
306
LDAP_LUTIL_F (int)
307
lutil_atoix( int *v, const char *s, int x );
308
309
LDAP_LUTIL_F (int)
310
lutil_atoux( unsigned *v, const char *s, int x );
311
312
LDAP_LUTIL_F (int)
313
lutil_atolx( long *v, const char *s, int x );
314
315
LDAP_LUTIL_F (int)
316
lutil_atoulx( unsigned long *v, const char *s, int x );
317
318
#define lutil_atoi(v, s) lutil_atoix((v), (s), 10)
319
#define lutil_atou(v, s) lutil_atoux((v), (s), 10)
320
#define lutil_atol(v, s) lutil_atolx((v), (s), 10)
321
#define lutil_atoul(v, s) lutil_atoulx((v), (s), 10)
322
323
#ifdef HAVE_LONG_LONG
324
#if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ)
325
LDAP_LUTIL_F (int)
326
lutil_atollx( long long *v, const char *s, int x );
327
#define lutil_atoll(v, s) lutil_atollx((v), (s), 10)
328
#endif /* HAVE_STRTOLL || HAVE_STRTOQ */
329
330
#if defined(HAVE_STRTOULL) || defined(HAVE_STRTOUQ)
331
LDAP_LUTIL_F (int)
332
lutil_atoullx( unsigned long long *v, const char *s, int x );
333
#define lutil_atoull(v, s) lutil_atoullx((v), (s), 10)
334
#endif /* HAVE_STRTOULL || HAVE_STRTOUQ */
335
#endif /* HAVE_LONG_LONG */
336
337
LDAP_LUTIL_F (int)
338
lutil_str2bin( struct berval *in, struct berval *out, void *ctx );
339
340
/* Parse and unparse time intervals */
341
LDAP_LUTIL_F (int)
342
lutil_parse_time( const char *in, unsigned long *tp );
343
344
LDAP_LUTIL_F (int)
345
lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
346
347
#ifdef timerdiv
348
#define lutil_timerdiv timerdiv
349
#else /* ! timerdiv */
350
/* works inplace (x == t) */
351
#define lutil_timerdiv(t,d,x) \
352
do { \
353
time_t s = (t)->tv_sec; \
354
assert( d > 0 ); \
355
(x)->tv_sec = s / d; \
356
(x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \
357
} while ( 0 )
358
#endif /* ! timerdiv */
359
360
#ifdef timermul
361
#define lutil_timermul timermul
362
#else /* ! timermul */
363
/* works inplace (x == t) */
364
#define lutil_timermul(t,m,x) \
365
do { \
366
time_t u = (t)->tv_usec * m; \
367
assert( m > 0 ); \
368
(x)->tv_sec = (t)->tv_sec * m + u / 1000000; \
369
(x)->tv_usec = u % 1000000; \
370
} while ( 0 );
371
#endif /* ! timermul */
372
373
LDAP_END_DECL
374
375
#endif /* _LUTIL_H */
376
377