openldap 0.0.1pre11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/History.md +4 -0
- data/Manifest.txt +20 -0
- data/README.md +100 -0
- data/Rakefile +152 -0
- data/Roadmap.md +55 -0
- data/ext/connection.c +1125 -0
- data/ext/extconf.rb +24 -0
- data/ext/openldap.c +558 -0
- data/ext/openldap.h +91 -0
- data/lib/openldap.rb +102 -0
- data/lib/openldap/connection.rb +179 -0
- data/lib/openldap/exceptions.rb +246 -0
- data/lib/openldap/mixins.rb +65 -0
- data/lib/openldap/utils.rb +123 -0
- data/spec/lib/constants.rb +29 -0
- data/spec/lib/helpers.rb +128 -0
- data/spec/openldap/connection_spec.rb +190 -0
- data/spec/openldap/exceptions_spec.rb +46 -0
- data/spec/openldap_spec.rb +83 -0
- data/test.conf-example +2 -0
- metadata +181 -0
data/ext/extconf.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mkmf'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
if ENV['MAINTAINER_MODE']
|
7
|
+
$stderr.puts "** Maintainer mode enabled. **"
|
8
|
+
$CFLAGS << ' -Wall' << ' -Wno-unused' << " -O0" << ' -ggdb' << ' -DDEBUG'
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
dir_config( 'openldap' )
|
13
|
+
|
14
|
+
find_header( 'ldap.h' ) or
|
15
|
+
abort( "missing ldap.h; do you need to install a developer package?" )
|
16
|
+
find_library( 'ldap', 'ldap_initialize' ) or
|
17
|
+
abort( "Could not find LDAP library (http://openldap.org/)." )
|
18
|
+
have_const( 'LDAP_API_VERSION', 'ldap.h' ) or
|
19
|
+
abort "no LDAP_API_VERSION constant defined"
|
20
|
+
|
21
|
+
have_func( 'ldap_tls_inplace' )
|
22
|
+
|
23
|
+
create_header()
|
24
|
+
create_makefile( 'openldap_ext' )
|
data/ext/openldap.c
ADDED
@@ -0,0 +1,558 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* Ruby-OpenLDAP -- a Ruby binding to OpenLDAP's libldap
|
4
|
+
* $Id: openldap.c,v 8fbea29a30e3 2011/08/11 23:16:07 ged $
|
5
|
+
*
|
6
|
+
* Authors
|
7
|
+
*
|
8
|
+
* - Michael Granger <ged@FaerieMUD.org>
|
9
|
+
*
|
10
|
+
* Copyright (c) 2011 Michael Granger
|
11
|
+
*
|
12
|
+
* All rights reserved.
|
13
|
+
*
|
14
|
+
* Redistribution and use in source and binary forms, with or without modification, are
|
15
|
+
* permitted provided that the following conditions are met:
|
16
|
+
*
|
17
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
18
|
+
* list of conditions and the following disclaimer.
|
19
|
+
*
|
20
|
+
* * Redistributions in binary form must reproduce the above copyright notice, this
|
21
|
+
* list of conditions and the following disclaimer in the documentation and/or
|
22
|
+
* other materials provided with the distribution.
|
23
|
+
*
|
24
|
+
* * Neither the name of the authors, nor the names of its contributors may be used to
|
25
|
+
* endorse or promote products derived from this software without specific prior
|
26
|
+
* written permission.
|
27
|
+
*
|
28
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
29
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
30
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
31
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
32
|
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
33
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
35
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
36
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
37
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
38
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
39
|
+
*
|
40
|
+
*
|
41
|
+
*/
|
42
|
+
|
43
|
+
#include "openldap.h"
|
44
|
+
|
45
|
+
VALUE ropenldap_mOpenLDAP;
|
46
|
+
VALUE ropenldap_mOpenLDAPLoggable;
|
47
|
+
|
48
|
+
VALUE ropenldap_eOpenLDAPError;
|
49
|
+
|
50
|
+
VALUE ropenldap_rbmURI;
|
51
|
+
|
52
|
+
|
53
|
+
/* --------------------------------------------------------------
|
54
|
+
* Logging Functions
|
55
|
+
* -------------------------------------------------------------- */
|
56
|
+
|
57
|
+
/*
|
58
|
+
* Log a message to the given +context+ object's logger.
|
59
|
+
*/
|
60
|
+
void
|
61
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
62
|
+
ropenldap_log_obj( VALUE context, const char *level, const char *fmt, ... )
|
63
|
+
#else
|
64
|
+
ropenldap_log_obj( VALUE context, const char *level, const char *fmt, va_dcl )
|
65
|
+
#endif
|
66
|
+
{
|
67
|
+
char buf[BUFSIZ];
|
68
|
+
va_list args;
|
69
|
+
VALUE logger = Qnil;
|
70
|
+
VALUE message = Qnil;
|
71
|
+
|
72
|
+
va_start( args, fmt );
|
73
|
+
vsnprintf( buf, BUFSIZ, fmt, args );
|
74
|
+
message = rb_str_new2( buf );
|
75
|
+
|
76
|
+
logger = rb_funcall( context, rb_intern("log"), 0, 0 );
|
77
|
+
rb_funcall( logger, rb_intern(level), 1, message );
|
78
|
+
|
79
|
+
va_end( args );
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
/*
|
84
|
+
* Log a message to the global logger.
|
85
|
+
*/
|
86
|
+
void
|
87
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
88
|
+
ropenldap_log( const char *level, const char *fmt, ... )
|
89
|
+
#else
|
90
|
+
ropenldap_log( const char *level, const char *fmt, va_dcl )
|
91
|
+
#endif
|
92
|
+
{
|
93
|
+
char buf[BUFSIZ];
|
94
|
+
va_list args;
|
95
|
+
VALUE logger = Qnil;
|
96
|
+
VALUE message = Qnil;
|
97
|
+
|
98
|
+
va_init_list( args, fmt );
|
99
|
+
vsnprintf( buf, BUFSIZ, fmt, args );
|
100
|
+
message = rb_str_new2( buf );
|
101
|
+
|
102
|
+
logger = rb_funcall( ropenldap_mOpenLDAP, rb_intern("logger"), 0, 0 );
|
103
|
+
rb_funcall( logger, rb_intern(level), 1, message );
|
104
|
+
|
105
|
+
va_end( args );
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/*
|
110
|
+
* Raise an appropriate exception with an appropriate message for the given
|
111
|
+
* resultcode.
|
112
|
+
*/
|
113
|
+
void
|
114
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
115
|
+
ropenldap_check_result( int resultcode, const char *func, ... )
|
116
|
+
#else
|
117
|
+
ropenldap_check_result( int resultcode, const char *func, va_dcl )
|
118
|
+
#endif
|
119
|
+
{
|
120
|
+
char buf[BUFSIZ];
|
121
|
+
va_list args;
|
122
|
+
VALUE exception_class = Qnil;
|
123
|
+
|
124
|
+
if ( resultcode == LDAP_SUCCESS ) return;
|
125
|
+
|
126
|
+
va_init_list( args, func );
|
127
|
+
vsnprintf( buf, BUFSIZ, func, args );
|
128
|
+
|
129
|
+
exception_class =
|
130
|
+
rb_funcall( ropenldap_eOpenLDAPError, rb_intern("subclass_for"), 1, INT2FIX(resultcode) );
|
131
|
+
|
132
|
+
rb_raise( exception_class, "%s", buf );
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/*
|
137
|
+
* Convert an array of string pointers to a Ruby Array of Strings.
|
138
|
+
*/
|
139
|
+
VALUE
|
140
|
+
ropenldap_rb_string_array( char **strings )
|
141
|
+
{
|
142
|
+
VALUE ary = rb_ary_new();
|
143
|
+
char **iter;
|
144
|
+
|
145
|
+
/* If there aren't any pointers, just return the empty Array */
|
146
|
+
if ( !strings ) return ary;
|
147
|
+
|
148
|
+
for ( iter = strings ; *iter != NULL ; iter++ ) {
|
149
|
+
ropenldap_log( "debug", " adding %s to string array", *iter );
|
150
|
+
rb_ary_push( ary, rb_str_new2(*iter) );
|
151
|
+
}
|
152
|
+
|
153
|
+
return ary;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
/*
|
159
|
+
* call-seq:
|
160
|
+
* OpenLDAP.split_url( str ) -> array
|
161
|
+
*
|
162
|
+
* Split an LDAP URL into an array of its parts:
|
163
|
+
* - uri_scheme
|
164
|
+
* - host
|
165
|
+
* - port
|
166
|
+
* - base
|
167
|
+
* - attrs
|
168
|
+
* - scope
|
169
|
+
* - filter
|
170
|
+
* - exts
|
171
|
+
* - crit_exts
|
172
|
+
*/
|
173
|
+
static VALUE
|
174
|
+
ropenldap_s_split_url( VALUE UNUSED(module), VALUE urlstring )
|
175
|
+
{
|
176
|
+
const char *url = StringValueCStr( urlstring );
|
177
|
+
LDAPURLDesc *urldesc;
|
178
|
+
VALUE rval = Qnil, obj = Qnil;
|
179
|
+
|
180
|
+
if ( !ldap_is_ldap_url(url) )
|
181
|
+
rb_raise( rb_eArgError, "Not an LDAP URL." );
|
182
|
+
|
183
|
+
/* Parse the URL */
|
184
|
+
if ( ldap_url_parse(url, &urldesc) != 0 )
|
185
|
+
rb_raise( rb_eRuntimeError, "Error parsing %s as an LDAP URL!", url );
|
186
|
+
|
187
|
+
rval = rb_ary_new2( 9 );
|
188
|
+
|
189
|
+
/* Scheme */
|
190
|
+
if ( urldesc->lud_scheme ) {
|
191
|
+
ropenldap_log( "debug", " parsed scheme: %s", urldesc->lud_scheme );
|
192
|
+
obj = rb_str_new2( urldesc->lud_scheme );
|
193
|
+
OBJ_INFECT( obj, urlstring );
|
194
|
+
rb_ary_store( rval, 0L, obj );
|
195
|
+
}
|
196
|
+
|
197
|
+
/* LDAP host to contact */
|
198
|
+
if ( urldesc->lud_host ) {
|
199
|
+
ropenldap_log( "debug", " parsed host: %s", urldesc->lud_host );
|
200
|
+
obj = rb_str_new2( urldesc->lud_host );
|
201
|
+
OBJ_INFECT( obj, urlstring );
|
202
|
+
rb_ary_store( rval, 1L, obj );
|
203
|
+
}
|
204
|
+
|
205
|
+
/* Port */
|
206
|
+
rb_ary_store( rval, 2L, INT2FIX(urldesc->lud_port) );
|
207
|
+
|
208
|
+
/* Base DN */
|
209
|
+
if ( urldesc->lud_dn ) {
|
210
|
+
ropenldap_log( "debug", " parsed DN: %s", urldesc->lud_dn );
|
211
|
+
obj = rb_str_new2( urldesc->lud_dn );
|
212
|
+
OBJ_INFECT( obj, urlstring );
|
213
|
+
rb_ary_store( rval, 3L, obj );
|
214
|
+
}
|
215
|
+
|
216
|
+
/* Attributes */
|
217
|
+
rb_ary_store( rval, 4L, ropenldap_rb_string_array(urldesc->lud_attrs) );
|
218
|
+
|
219
|
+
/* Numeric scope (LDAP_SCOPE_*) */
|
220
|
+
rb_ary_store( rval, 5L, INT2FIX(urldesc->lud_scope) );
|
221
|
+
|
222
|
+
/* Filter */
|
223
|
+
if ( urldesc->lud_filter ) {
|
224
|
+
ropenldap_log( "debug", " parsed filter: %s", urldesc->lud_filter );
|
225
|
+
obj = rb_str_new2( urldesc->lud_filter );
|
226
|
+
OBJ_INFECT( obj, urlstring );
|
227
|
+
rb_ary_store( rval, 6L, obj );
|
228
|
+
}
|
229
|
+
|
230
|
+
/* lists of LDAP extensions */
|
231
|
+
rb_ary_store( rval, 7L, ropenldap_rb_string_array(urldesc->lud_exts) );
|
232
|
+
|
233
|
+
/* Critical extension/s flag */
|
234
|
+
rb_ary_store( rval, 8L, urldesc->lud_crit_exts ? Qtrue : Qfalse );
|
235
|
+
|
236
|
+
ldap_free_urldesc( urldesc );
|
237
|
+
|
238
|
+
return rval;
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
/*
|
243
|
+
* call-seq:
|
244
|
+
* OpenLDAP.err2string( resultcode ) -> string
|
245
|
+
*
|
246
|
+
* Return a short description of the +resultcode+ returned by routines in this library.
|
247
|
+
*
|
248
|
+
*/
|
249
|
+
static VALUE
|
250
|
+
ropenldap_s_err2string( VALUE UNUSED(module), VALUE resultcode )
|
251
|
+
{
|
252
|
+
int err = FIX2INT( resultcode );
|
253
|
+
char *string = ldap_err2string( err );
|
254
|
+
|
255
|
+
return rb_str_new2( string );
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
/* Check to be sure the library that's dynamically-linked is the same
|
260
|
+
* one it was compiled against. */
|
261
|
+
static void
|
262
|
+
ropenldap_check_link()
|
263
|
+
{
|
264
|
+
LDAPAPIInfo api;
|
265
|
+
api.ldapai_info_version = LDAP_API_INFO_VERSION;
|
266
|
+
|
267
|
+
if ( ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) != LDAP_OPT_SUCCESS ) {
|
268
|
+
rb_warn( "ldap_get_option(API_INFO) failed" );
|
269
|
+
return;
|
270
|
+
}
|
271
|
+
|
272
|
+
if ( api.ldapai_info_version != LDAP_API_INFO_VERSION ) {
|
273
|
+
rb_warn( "LDAP APIInfo version mismatch: library %d, header %d",
|
274
|
+
api.ldapai_info_version, LDAP_API_INFO_VERSION );
|
275
|
+
}
|
276
|
+
|
277
|
+
if ( api.ldapai_api_version != LDAP_API_VERSION ) {
|
278
|
+
rb_warn( "LDAP API version mismatch: library %d, header %d",
|
279
|
+
api.ldapai_api_version, LDAP_API_VERSION );
|
280
|
+
}
|
281
|
+
|
282
|
+
if ( strcmp(api.ldapai_vendor_name, LDAP_VENDOR_NAME ) != 0 ) {
|
283
|
+
rb_warn( "LDAP vendor name mismatch: library %s, header %s\n",
|
284
|
+
api.ldapai_vendor_name, LDAP_VENDOR_NAME );
|
285
|
+
}
|
286
|
+
|
287
|
+
if( api.ldapai_vendor_version != LDAP_VENDOR_VERSION ) {
|
288
|
+
rb_warn( "LDAP vendor version mismatch: library %d, header %d\n",
|
289
|
+
api.ldapai_vendor_version, LDAP_VENDOR_VERSION );
|
290
|
+
}
|
291
|
+
|
292
|
+
ropenldap_log( "info", "LDAP library: %s %d",
|
293
|
+
LDAP_VENDOR_NAME, LDAP_VENDOR_VERSION );
|
294
|
+
|
295
|
+
ldap_memfree( api.ldapai_vendor_name );
|
296
|
+
ber_memvfree( (void **)api.ldapai_extensions );
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
/*
|
301
|
+
* call-seq:
|
302
|
+
* OpenLDAP.api_info -> hash
|
303
|
+
*
|
304
|
+
* Return a Hash describing the API version, vendor, extensions, etc.
|
305
|
+
*
|
306
|
+
* conn.api_info
|
307
|
+
* # => {:api_version=>3001, :protocol_version=>3,
|
308
|
+
* :extensions=>["X_OPENLDAP", "THREAD_SAFE", "X_OPENLDAP_THREAD_SAFE"],
|
309
|
+
* :vendor_name=>"OpenLDAP", :vendor_version=>20423}
|
310
|
+
*/
|
311
|
+
static VALUE
|
312
|
+
ropenldap_s_api_info( VALUE self )
|
313
|
+
{
|
314
|
+
VALUE rval = rb_hash_new();
|
315
|
+
LDAPAPIInfo info;
|
316
|
+
info.ldapai_info_version = LDAP_API_INFO_VERSION;
|
317
|
+
|
318
|
+
if ( ldap_get_option(NULL, LDAP_OPT_API_INFO, &info) != LDAP_SUCCESS )
|
319
|
+
rb_raise( ropenldap_eOpenLDAPError, "ldap_get_option(API_INFO) failed." );
|
320
|
+
|
321
|
+
rb_hash_aset( rval, ID2SYM(rb_intern("api_version")), INT2FIX(info.ldapai_api_version) );
|
322
|
+
rb_hash_aset( rval, ID2SYM(rb_intern("protocol_version")), INT2FIX(info.ldapai_protocol_version) );
|
323
|
+
rb_hash_aset( rval, ID2SYM(rb_intern("extensions")), ropenldap_rb_string_array(info.ldapai_extensions) );
|
324
|
+
rb_hash_aset( rval, ID2SYM(rb_intern("vendor_name")), rb_str_new2(info.ldapai_vendor_name) );
|
325
|
+
rb_hash_aset( rval, ID2SYM(rb_intern("vendor_version")), INT2FIX(info.ldapai_vendor_version) );
|
326
|
+
|
327
|
+
ldap_memfree( info.ldapai_vendor_name );
|
328
|
+
ber_memvfree( (void **)info.ldapai_extensions );
|
329
|
+
|
330
|
+
return rval;
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
/*
|
335
|
+
* call-seq:
|
336
|
+
* OpenLDAP.api_feature_info -> hash
|
337
|
+
*
|
338
|
+
* Returns a hash of the versions of the extensions in .api_info[:extensions]
|
339
|
+
*
|
340
|
+
* conn.api_feature_info
|
341
|
+
* # => {"X_OPENLDAP"=>20423, "THREAD_SAFE"=>1, "X_OPENLDAP_THREAD_SAFE"=>1}
|
342
|
+
*/
|
343
|
+
static VALUE
|
344
|
+
ropenldap_s_api_feature_info( VALUE self )
|
345
|
+
{
|
346
|
+
VALUE rval = rb_hash_new();
|
347
|
+
int i;
|
348
|
+
LDAPAPIInfo info;
|
349
|
+
info.ldapai_info_version = LDAP_API_INFO_VERSION;
|
350
|
+
|
351
|
+
if ( ldap_get_option(NULL, LDAP_OPT_API_INFO, &info) != LDAP_SUCCESS )
|
352
|
+
rb_raise( ropenldap_eOpenLDAPError, "ldap_get_option(API_INFO) failed." );
|
353
|
+
|
354
|
+
for( i=0; info.ldapai_extensions[i] != NULL; i++ ) {
|
355
|
+
LDAPAPIFeatureInfo fi;
|
356
|
+
fi.ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
|
357
|
+
fi.ldapaif_name = info.ldapai_extensions[i];
|
358
|
+
fi.ldapaif_version = 0;
|
359
|
+
|
360
|
+
if ( ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &fi) == LDAP_SUCCESS ) {
|
361
|
+
if(fi.ldapaif_info_version == LDAP_FEATURE_INFO_VERSION) {
|
362
|
+
rb_hash_aset( rval, rb_str_new2(fi.ldapaif_name), INT2FIX(fi.ldapaif_version) );
|
363
|
+
} else {
|
364
|
+
ropenldap_log( "warn", "Feature info version mismatch for %s; expected %d, got %d",
|
365
|
+
fi.ldapaif_name, LDAP_FEATURE_INFO_VERSION, fi.ldapaif_info_version );
|
366
|
+
rb_hash_aset( rval, rb_str_new2(fi.ldapaif_name), Qnil );
|
367
|
+
}
|
368
|
+
} else {
|
369
|
+
ldap_memfree( info.ldapai_vendor_name );
|
370
|
+
ber_memvfree( (void **)info.ldapai_extensions );
|
371
|
+
rb_raise( ropenldap_eOpenLDAPError, "ldap_get_option(API_FEATURE_INFO) failed." );
|
372
|
+
}
|
373
|
+
}
|
374
|
+
|
375
|
+
ldap_memfree( info.ldapai_vendor_name );
|
376
|
+
ber_memvfree( (void **)info.ldapai_extensions );
|
377
|
+
|
378
|
+
return rval;
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
/*
|
383
|
+
* call-seq:
|
384
|
+
* OpenLDAP.uris -> array
|
385
|
+
*
|
386
|
+
* Return an Array of URIs to be contacted by the library when trying to establish a connection.
|
387
|
+
*
|
388
|
+
* OpenLDAP.uris
|
389
|
+
* # => ['ldap://ldap.example.com:389']
|
390
|
+
*/
|
391
|
+
static VALUE
|
392
|
+
ropenldap_s_uris( VALUE self )
|
393
|
+
{
|
394
|
+
VALUE rval;
|
395
|
+
char *uris;
|
396
|
+
|
397
|
+
if ( ldap_get_option(NULL, LDAP_OPT_URI, &uris) != LDAP_SUCCESS )
|
398
|
+
rb_raise( ropenldap_eOpenLDAPError, "ldap_get_option(URI) failed." );
|
399
|
+
|
400
|
+
rval = rb_str_new2( uris );
|
401
|
+
ldap_memfree( uris );
|
402
|
+
|
403
|
+
return rb_funcall( rval, rb_intern("split"), 1, rb_str_new(" ", 1) );
|
404
|
+
}
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
void
|
409
|
+
Init_openldap_ext( void )
|
410
|
+
{
|
411
|
+
rb_require( "uri" );
|
412
|
+
ropenldap_rbmURI = rb_const_get( rb_cObject, rb_intern("URI") );
|
413
|
+
|
414
|
+
rb_require( "openldap" );
|
415
|
+
ropenldap_mOpenLDAP = rb_define_module( "OpenLDAP" );
|
416
|
+
|
417
|
+
rb_require( "openldap/mixins" );
|
418
|
+
ropenldap_mOpenLDAPLoggable = rb_define_module_under( ropenldap_mOpenLDAP, "Loggable" );
|
419
|
+
ropenldap_eOpenLDAPError =
|
420
|
+
rb_define_class_under( ropenldap_mOpenLDAP, "Error", rb_eRuntimeError );
|
421
|
+
|
422
|
+
/* Constants */
|
423
|
+
|
424
|
+
/* versions */
|
425
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_API_VERSION", INT2FIX(LDAP_API_VERSION) );
|
426
|
+
|
427
|
+
/* Ports */
|
428
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_PORT", INT2FIX(LDAP_PORT) );
|
429
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAPS_PORT", INT2FIX(LDAPS_PORT) );
|
430
|
+
|
431
|
+
/* RFC constants */
|
432
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ROOT_DSE", rb_str_new2(LDAP_ROOT_DSE) );
|
433
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_ATTRS", rb_str_new2(LDAP_NO_ATTRS) );
|
434
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ALL_USER_ATTRIBUTES",
|
435
|
+
rb_str_new2(LDAP_ALL_USER_ATTRIBUTES) );
|
436
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ALL_OPERATIONAL_ATTRIBUTES",
|
437
|
+
rb_str_new2(LDAP_ALL_OPERATIONAL_ATTRIBUTES) );
|
438
|
+
|
439
|
+
/* RFC4511 maxInt */
|
440
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_MAXINT", INT2NUM(LDAP_MAXINT) );
|
441
|
+
|
442
|
+
/* search scopes */
|
443
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_BASE", INT2FIX(LDAP_SCOPE_BASE) );
|
444
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_BASEOBJECT", INT2FIX(LDAP_SCOPE_BASEOBJECT) );
|
445
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_ONELEVEL", INT2FIX(LDAP_SCOPE_ONELEVEL) );
|
446
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_ONE", INT2FIX(LDAP_SCOPE_ONE) );
|
447
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_SUBTREE", INT2FIX(LDAP_SCOPE_SUBTREE) );
|
448
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_SUB", INT2FIX(LDAP_SCOPE_SUB) );
|
449
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_SUBORDINATE", INT2FIX(LDAP_SCOPE_SUBORDINATE) );
|
450
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_CHILDREN", INT2FIX(LDAP_SCOPE_CHILDREN) );
|
451
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SCOPE_DEFAULT", INT2FIX(LDAP_SCOPE_DEFAULT) );
|
452
|
+
|
453
|
+
/* result codes */
|
454
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SUCCESS", INT2FIX(LDAP_SUCCESS) );
|
455
|
+
|
456
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPERATIONS_ERROR", INT2FIX(LDAP_OPERATIONS_ERROR) );
|
457
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_PROTOCOL_ERROR", INT2FIX(LDAP_PROTOCOL_ERROR) );
|
458
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_TIMELIMIT_EXCEEDED", INT2FIX(LDAP_TIMELIMIT_EXCEEDED) );
|
459
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SIZELIMIT_EXCEEDED", INT2FIX(LDAP_SIZELIMIT_EXCEEDED) );
|
460
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_COMPARE_FALSE", INT2FIX(LDAP_COMPARE_FALSE) );
|
461
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_COMPARE_TRUE", INT2FIX(LDAP_COMPARE_TRUE) );
|
462
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_AUTH_METHOD_NOT_SUPPORTED", INT2FIX(LDAP_AUTH_METHOD_NOT_SUPPORTED) );
|
463
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_STRONG_AUTH_NOT_SUPPORTED", INT2FIX(LDAP_STRONG_AUTH_NOT_SUPPORTED) );
|
464
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_STRONG_AUTH_REQUIRED", INT2FIX(LDAP_STRONG_AUTH_REQUIRED) );
|
465
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_STRONGER_AUTH_REQUIRED", INT2FIX(LDAP_STRONGER_AUTH_REQUIRED) );
|
466
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_PARTIAL_RESULTS", INT2FIX(LDAP_PARTIAL_RESULTS) );
|
467
|
+
|
468
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_REFERRAL", INT2FIX(LDAP_REFERRAL) );
|
469
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ADMINLIMIT_EXCEEDED", INT2FIX(LDAP_ADMINLIMIT_EXCEEDED) );
|
470
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_UNAVAILABLE_CRITICAL_EXTENSION", INT2FIX(LDAP_UNAVAILABLE_CRITICAL_EXTENSION) );
|
471
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_CONFIDENTIALITY_REQUIRED", INT2FIX(LDAP_CONFIDENTIALITY_REQUIRED) );
|
472
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SASL_BIND_IN_PROGRESS", INT2FIX(LDAP_SASL_BIND_IN_PROGRESS) );
|
473
|
+
|
474
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_SUCH_ATTRIBUTE", INT2FIX(LDAP_NO_SUCH_ATTRIBUTE) );
|
475
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_UNDEFINED_TYPE", INT2FIX(LDAP_UNDEFINED_TYPE) );
|
476
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INAPPROPRIATE_MATCHING", INT2FIX(LDAP_INAPPROPRIATE_MATCHING) );
|
477
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_CONSTRAINT_VIOLATION", INT2FIX(LDAP_CONSTRAINT_VIOLATION) );
|
478
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_TYPE_OR_VALUE_EXISTS", INT2FIX(LDAP_TYPE_OR_VALUE_EXISTS) );
|
479
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INVALID_SYNTAX", INT2FIX(LDAP_INVALID_SYNTAX) );
|
480
|
+
|
481
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_SUCH_OBJECT", INT2FIX(LDAP_NO_SUCH_OBJECT) );
|
482
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ALIAS_PROBLEM", INT2FIX(LDAP_ALIAS_PROBLEM) );
|
483
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INVALID_DN_SYNTAX", INT2FIX(LDAP_INVALID_DN_SYNTAX) );
|
484
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_IS_LEAF", INT2FIX(LDAP_IS_LEAF) );
|
485
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ALIAS_DEREF_PROBLEM", INT2FIX(LDAP_ALIAS_DEREF_PROBLEM) );
|
486
|
+
|
487
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_X_PROXY_AUTHZ_FAILURE", INT2FIX(LDAP_X_PROXY_AUTHZ_FAILURE) );
|
488
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INAPPROPRIATE_AUTH", INT2FIX(LDAP_INAPPROPRIATE_AUTH) );
|
489
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INVALID_CREDENTIALS", INT2FIX(LDAP_INVALID_CREDENTIALS) );
|
490
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_INSUFFICIENT_ACCESS", INT2FIX(LDAP_INSUFFICIENT_ACCESS) );
|
491
|
+
|
492
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_BUSY", INT2FIX(LDAP_BUSY) );
|
493
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_UNAVAILABLE", INT2FIX(LDAP_UNAVAILABLE) );
|
494
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_UNWILLING_TO_PERFORM", INT2FIX(LDAP_UNWILLING_TO_PERFORM) );
|
495
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_LOOP_DETECT", INT2FIX(LDAP_LOOP_DETECT) );
|
496
|
+
|
497
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NAMING_VIOLATION", INT2FIX(LDAP_NAMING_VIOLATION) );
|
498
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OBJECT_CLASS_VIOLATION", INT2FIX(LDAP_OBJECT_CLASS_VIOLATION) );
|
499
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NOT_ALLOWED_ON_NONLEAF", INT2FIX(LDAP_NOT_ALLOWED_ON_NONLEAF) );
|
500
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NOT_ALLOWED_ON_RDN", INT2FIX(LDAP_NOT_ALLOWED_ON_RDN) );
|
501
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ALREADY_EXISTS", INT2FIX(LDAP_ALREADY_EXISTS) );
|
502
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_OBJECT_CLASS_MODS", INT2FIX(LDAP_NO_OBJECT_CLASS_MODS) );
|
503
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_RESULTS_TOO_LARGE", INT2FIX(LDAP_RESULTS_TOO_LARGE) );
|
504
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_AFFECTS_MULTIPLE_DSAS", INT2FIX(LDAP_AFFECTS_MULTIPLE_DSAS) );
|
505
|
+
|
506
|
+
#ifdef LDAP_VLV_ERROR
|
507
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_VLV_ERROR", INT2FIX(LDAP_VLV_ERROR) );
|
508
|
+
#endif
|
509
|
+
|
510
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_SUCCESS", INT2FIX(LDAP_OPT_SUCCESS) );
|
511
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_ERROR", INT2FIX(LDAP_OPT_ERROR) );
|
512
|
+
|
513
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OTHER", INT2FIX(LDAP_OTHER) );
|
514
|
+
|
515
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_SERVER_DOWN", INT2FIX(LDAP_SERVER_DOWN) );
|
516
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_LOCAL_ERROR", INT2FIX(LDAP_LOCAL_ERROR) );
|
517
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_ENCODING_ERROR", INT2FIX(LDAP_ENCODING_ERROR) );
|
518
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_DECODING_ERROR", INT2FIX(LDAP_DECODING_ERROR) );
|
519
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_TIMEOUT", INT2FIX(LDAP_TIMEOUT) );
|
520
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_AUTH_UNKNOWN", INT2FIX(LDAP_AUTH_UNKNOWN) );
|
521
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_FILTER_ERROR", INT2FIX(LDAP_FILTER_ERROR) );
|
522
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_USER_CANCELLED", INT2FIX(LDAP_USER_CANCELLED) );
|
523
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_PARAM_ERROR", INT2FIX(LDAP_PARAM_ERROR) );
|
524
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_MEMORY", INT2FIX(LDAP_NO_MEMORY) );
|
525
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_CONNECT_ERROR", INT2FIX(LDAP_CONNECT_ERROR) );
|
526
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NOT_SUPPORTED", INT2FIX(LDAP_NOT_SUPPORTED) );
|
527
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_CONTROL_NOT_FOUND", INT2FIX(LDAP_CONTROL_NOT_FOUND) );
|
528
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_NO_RESULTS_RETURNED", INT2FIX(LDAP_NO_RESULTS_RETURNED) );
|
529
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_MORE_RESULTS_TO_RETURN", INT2FIX(LDAP_MORE_RESULTS_TO_RETURN) );
|
530
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_CLIENT_LOOP", INT2FIX(LDAP_CLIENT_LOOP) );
|
531
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_REFERRAL_LIMIT_EXCEEDED", INT2FIX(LDAP_REFERRAL_LIMIT_EXCEEDED) );
|
532
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_X_CONNECTING", INT2FIX(LDAP_X_CONNECTING) );
|
533
|
+
|
534
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_NEVER", INT2FIX(LDAP_OPT_X_TLS_NEVER) );
|
535
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_HARD", INT2FIX(LDAP_OPT_X_TLS_HARD) );
|
536
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_DEMAND", INT2FIX(LDAP_OPT_X_TLS_DEMAND) );
|
537
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_ALLOW", INT2FIX(LDAP_OPT_X_TLS_ALLOW) );
|
538
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_TRY", INT2FIX(LDAP_OPT_X_TLS_TRY) );
|
539
|
+
|
540
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_CRL_NONE", INT2FIX(LDAP_OPT_X_TLS_CRL_NONE) );
|
541
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_CRL_PEER", INT2FIX(LDAP_OPT_X_TLS_CRL_PEER) );
|
542
|
+
rb_define_const( ropenldap_mOpenLDAP, "LDAP_OPT_X_TLS_CRL_ALL", INT2FIX(LDAP_OPT_X_TLS_CRL_ALL) );
|
543
|
+
|
544
|
+
/* Module functions */
|
545
|
+
rb_define_singleton_method( ropenldap_mOpenLDAP, "split_url", ropenldap_s_split_url, 1 );
|
546
|
+
rb_define_singleton_method( ropenldap_mOpenLDAP, "err2string", ropenldap_s_err2string, 1 );
|
547
|
+
rb_define_singleton_method( ropenldap_mOpenLDAP, "api_info", ropenldap_s_api_info, 0 );
|
548
|
+
rb_define_singleton_method( ropenldap_mOpenLDAP, "api_feature_info", ropenldap_s_api_feature_info, 0 );
|
549
|
+
|
550
|
+
rb_define_singleton_method( ropenldap_mOpenLDAP, "uris", ropenldap_s_uris, 0 );
|
551
|
+
|
552
|
+
/* Initialize the other parts of the extension */
|
553
|
+
ropenldap_init_connection();
|
554
|
+
|
555
|
+
/* Detect mismatched linking */
|
556
|
+
ropenldap_check_link();
|
557
|
+
}
|
558
|
+
|