]> git.sur5r.net Git - openldap/blob - include/ldap_pvt.h
ITS#503: Extend ldap tools to support SASL/TLS
[openldap] / include / ldap_pvt.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  */
11 /*
12  * ldap-pvt.h - Header for ldap_pvt_ functions. These are meant to be used
13  *              by the OpenLDAP distribution only.
14  */
15
16 #ifndef _LDAP_PVT_H
17 #define _LDAP_PVT_H 1
18
19 #include <ldap_cdefs.h>
20 #include <lber.h>                               /* get ber_slen_t */
21
22 LDAP_BEGIN_DECL
23
24 LIBLDAP_F ( int )
25 ldap_pvt_domain2dn LDAP_P((
26         LDAP_CONST char *domain,
27         char **dn ));
28
29 struct hostent; /* avoid pulling in <netdb.h> */
30
31 LIBLDAP_F( char * )
32 ldap_pvt_ctime LDAP_P((
33         const time_t *tp,
34         char *buf ));
35
36 LIBLDAP_F( int )
37 ldap_pvt_gethostbyname_a LDAP_P((
38         const char *name, 
39         struct hostent *resbuf,
40         char **buf,
41         struct hostent **result,
42         int *herrno_ptr ));
43
44 LIBLDAP_F( int )
45 ldap_pvt_gethostbyaddr_a LDAP_P((
46         const char *addr,
47         int len,
48         int type,
49         struct hostent *resbuf,
50         char **buf,
51         struct hostent **result,
52         int *herrno_ptr ));
53
54
55 /* charray.c */
56
57 LIBLDAP_F( int )
58 ldap_charray_add LDAP_P((
59     char        ***a,
60     char        *s ));
61
62 LIBLDAP_F( int )
63 ldap_charray_merge LDAP_P((
64     char        ***a,
65     char        **s ));
66
67 LIBLDAP_F( void )
68 ldap_charray_free LDAP_P(( char **a ));
69
70 LIBLDAP_F( int )
71 ldap_charray_inlist LDAP_P((
72     char        **a,
73     char        *s ));
74
75 LIBLDAP_F( char ** )
76 ldap_charray_dup LDAP_P(( char **a ));
77
78 LIBLDAP_F( char ** )
79 ldap_str2charray LDAP_P((
80         const char *str,
81         const char *brkstr ));
82
83 /* url.c */
84 LIBLDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s ));
85 LIBLDAP_F (int) ldap_pvt_unhex( int c );
86
87 /* these macros assume 'x' is an ASCII x */
88 #define LDAP_DNSEPARATOR(c)     ((c) == ',' || (c) == ';')
89 #define LDAP_SEPARATOR(c)       ((c) == ',' || (c) == ';' || (c) == '+')
90 #define LDAP_SPACE(c)           ((c) == ' ' || (c) == '\n')
91
92 #define LDAP_LOWER(c)           ( (c) >= 'a' && (c) <= 'z' )
93 #define LDAP_UPPER(c)           ( (c) >= 'A' && (c) <= 'Z' )
94 #define LDAP_ALPHA(c)           ( LDAP_LOWER(c) || LDAP_UPPER(c) )
95 #define LDAP_DIGIT(c)           ( (c) >= '0' && (c) <= '9' )
96 #define LDAP_ALNUM(c)           ( LDAP_ALPHA(c) || LDAP_DIGIT(c) )
97
98 #define LDAP_LEADKEYCHAR(c)     ( LDAP_ALPHA(c) )
99 #define LDAP_KEYCHAR(c)         ( LDAP_ALNUM(c) || (c) == '-' )
100 #define LDAP_LEADOIDCHAR(c)     ( LDAP_DIGIT(c) )
101 #define LDAP_OIDCHAR(c)         ( LDAP_DIGIT(c) || (c) == '.' )
102
103 #define LDAP_LEADATTRCHAR(c)    ( LDAP_LEADKEYCHAR(c) || LDAP_LEADOIDCHAR(c) )
104 #define LDAP_ATTRCHAR(c)                ( LDAP_KEYCHAR((c)) || (c) == '.' )
105
106 #define LDAP_NEEDSESCAPE(c)     ((c) == '\\' || (c) == '"')
107
108 #ifdef HAVE_CYRUS_SASL
109 /* sasl.c */
110
111 #include <sasl.h>
112 #include <ldap.h> 
113
114 LIBLDAP_F (int) ldap_pvt_sasl_init LDAP_P(( void )); /* clientside init */
115 LIBLDAP_F (int) ldap_pvt_sasl_install LDAP_P(( Sockbuf *, void * ));
116 LIBLDAP_F (int) ldap_pvt_sasl_err2ldap LDAP_P(( int ));
117 LIBLDAP_F (int) ldap_pvt_sasl_bind LDAP_P(( LDAP *, LDAP_CONST char *,
118         LDAP_CONST char *, LDAP_CONST sasl_callback_t *, LDAPControl **,
119         LDAPControl ** ));
120 LIBLDAP_F (int) ldap_pvt_sasl_get_option LDAP_P(( LDAP *ld, int option,
121         void *arg ));
122 LIBLDAP_F (int) ldap_pvt_sasl_set_option LDAP_P(( LDAP *ld, int option,
123         void *arg ));
124 #endif /* HAVE_CYRUS_SASL */
125
126 /* search.c */
127 LIBLDAP_F( char * )
128 ldap_pvt_find_wildcard LDAP_P(( const char *s ));
129
130 LIBLDAP_F( ber_slen_t )
131 ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
132
133 /* string.c */
134 LIBLDAP_F( char * )
135 ldap_pvt_str2upper LDAP_P(( char *str ));
136
137 LIBLDAP_F( char * )
138 ldap_pvt_str2lower LDAP_P(( char *str ));
139
140 /* tls.c */
141 struct ldapoptions;
142
143 LIBLDAP_F (int) ldap_pvt_tls_init LDAP_P(( void ));
144 LIBLDAP_F (int) ldap_pvt_tls_config LDAP_P(( struct ldapoptions *lo, int option, const char *arg ));
145 LIBLDAP_F (int) ldap_pvt_tls_connect LDAP_P(( Sockbuf *sb, void *ctx_arg ));
146 LIBLDAP_F (int) ldap_pvt_tls_accept LDAP_P(( Sockbuf *sb, void *ctx_arg ));
147 LIBLDAP_F (int) ldap_pvt_tls_get_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
148 LIBLDAP_F (int) ldap_pvt_tls_set_option LDAP_P(( struct ldapoptions *lo, int option, void *arg ));
149 LIBLDAP_F (int) ldap_pvt_tls_inplace LDAP_P(( Sockbuf *sb ));
150 LIBLDAP_F (int) ldap_pvt_tls_start LDAP_P(( Sockbuf *sb, void *ctx_arg ));
151
152 /*  
153  * UTF-8 (in utf-8.c)
154  */
155
156 typedef ber_int_t ldap_ucs4_t;
157 typedef short ldap_ucs2_t;
158 typedef ldap_ucs2_t ldap_unicode_t;
159
160 /* returns the number of bytes in the UTF-8 string */
161 LIBLDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
162 /* returns the number of UTF-8 characters in the string */
163 LIBLDAP_F (ber_len_t) ldap_utf8_chars( const char * );
164 /* returns the length (in bytes) of the UTF-8 character */
165 LIBLDAP_F (int) ldap_utf8_offset( const char * );
166 /* returns the length (in bytes) indicated by the UTF-8 character */
167 LIBLDAP_F (int) ldap_utf8_charlen( const char * );
168 /* copies a UTF-8 character and returning number of bytes copied */
169 LIBLDAP_F (int) ldap_utf8_copy( char *, const char *);
170
171 /* returns pointer of next UTF-8 character in string */
172 LIBLDAP_F (char*) ldap_utf8_next( const char * );
173 /* returns pointer of previous UTF-8 character in string */
174 LIBLDAP_F (char*) ldap_utf8_prev( const char * );
175
176 /* primitive ctype routines -- not aware of non-ascii characters */
177 LIBLDAP_F (int) ldap_utf8_isascii( const char * );
178 LIBLDAP_F (int) ldap_utf8_isalpha( const char * );
179 LIBLDAP_F (int) ldap_utf8_isalnum( const char * );
180 LIBLDAP_F (int) ldap_utf8_isdigit( const char * );
181 LIBLDAP_F (int) ldap_utf8_isxdigit( const char * );
182 LIBLDAP_F (int) ldap_utf8_isspace( const char * );
183
184 /* span characters not in set, return bytes spanned */
185 LIBLDAP_F (ber_len_t) ldap_utf8_strcspn( const char* str, const char *set);
186 /* span characters in set, return bytes spanned */
187 LIBLDAP_F (ber_len_t) ldap_utf8_strspn( const char* str, const char *set);
188 /* return first occurance of character in string */
189 LIBLDAP_F (char *) ldap_utf8_strchr( const char* str, const char *chr);
190 /* return first character of set in string */
191 LIBLDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
192 /* reentrant tokenizer */
193 LIBLDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
194
195 /* Optimizations */
196 #define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x100 )
197 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
198         ? 1 : ldap_utf8_charlen((p)) )
199 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
200         ? 1 : ldap_utf8_offset((p)) )
201
202 #define LDAP_UTF8_COPY(d,s) (   LDAP_UTF8_ISASCII(s) \
203         ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
204
205 #define LDAP_UTF8_NEXT(p) (     LDAP_UTF8_ISASCII(p) \
206         ? (char *)(p)+1 : ldap_utf8_next((p)) )
207
208 #define LDAP_UTF8_INCR(p) ((p) = LDAP_UTF8_NEXT(p))
209
210 /* For symmetry */
211 #define LDAP_UTF8_PREV(p) (ldap_utf8_prev((p)))
212 #define LDAP_UTF8_DECR(p) ((p)=LDAP_UTF8_PREV((p)))
213
214 LDAP_END_DECL
215
216 #endif
217