ruby-ldap3 0.10.0

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/ldap.c ADDED
@@ -0,0 +1,650 @@
1
+ /* -*- C -*-
2
+ *
3
+ * ldap.c
4
+ * $Id: ldap.c,v 1.14 2005/03/15 10:07:48 ianmacd Exp $
5
+ */
6
+
7
+ #include "ruby.h"
8
+ #include "rbldap.h"
9
+
10
+ VALUE rb_mLDAP;
11
+ VALUE rb_eLDAP_Error;
12
+ VALUE rb_eLDAP_ResultError;
13
+ VALUE rb_eLDAP_InvalidDataError;
14
+ VALUE rb_eLDAP_InvalidEntryError;
15
+
16
+ VALUE
17
+ rb_ldap_class_new (int argc, VALUE argv[], VALUE klass)
18
+ {
19
+ VALUE obj;
20
+
21
+ obj = rb_funcall (klass, rb_intern ("allocate"), 0);
22
+ rb_obj_call_init (obj, argc, argv);
23
+
24
+ return obj;
25
+ }
26
+
27
+ VALUE
28
+ rb_ldap_dummy_method (int argc, VALUE argv[], VALUE self)
29
+ {
30
+ /* do nothing */
31
+ return Qnil;
32
+ }
33
+
34
+ /*
35
+ * call-seq:
36
+ * LDAP.err2string(err) => String
37
+ *
38
+ * Return the text string associated with the LDAP error, +err+.
39
+ */
40
+ VALUE
41
+ rb_ldap_err2string (VALUE self, VALUE err)
42
+ {
43
+ char *cmsg;
44
+ VALUE msg;
45
+
46
+ cmsg = ldap_err2string (NUM2INT (err));
47
+ msg = rb_tainted_str_new2 (cmsg);
48
+
49
+ return msg;
50
+ }
51
+
52
+ /*
53
+ * call-seq:
54
+ * LDAP.dn2ufn(dn) => String or nil
55
+ *
56
+ * Translate the DN, +dn+, to a more User-Friendly Name (UFN).
57
+ *
58
+ * For example:
59
+ *
60
+ * <code>LDAP.dn2ufn('uid=ianmacd,ou=People,dc=google,dc=com')</code>
61
+ *
62
+ * produces:
63
+ *
64
+ * ianmacd, People, google.com
65
+ *
66
+ * The UFN format is described in
67
+ * RFC1781[http://www.faqs.org/rfcs/rfc1781.html].
68
+ */
69
+ VALUE
70
+ rb_ldap_dn2ufn (VALUE self, VALUE dn)
71
+ {
72
+ char *c_dn;
73
+ char *c_ufn;
74
+
75
+ if (dn == Qnil)
76
+ {
77
+ return Qnil;
78
+ }
79
+
80
+ c_dn = StringValueCStr (dn);
81
+ if ((c_ufn = ldap_dn2ufn (c_dn)))
82
+ {
83
+ return rb_tainted_str_new2 (c_ufn);
84
+ }
85
+ else
86
+ {
87
+ return Qnil;
88
+ }
89
+ }
90
+
91
+ VALUE
92
+ rb_ldap_explode_dn (VALUE self, VALUE dn, VALUE notypes)
93
+ {
94
+ char **c_arr, **p;
95
+ char *c_dn;
96
+ VALUE ary;
97
+
98
+ if (dn == Qnil)
99
+ {
100
+ return Qnil;
101
+ }
102
+
103
+ c_dn = StringValueCStr (dn);
104
+ if ((c_arr = ldap_explode_dn (c_dn, RTEST (notypes) ? 1 : 0)))
105
+ {
106
+ ary = rb_ary_new ();
107
+ for (p = c_arr; *p != NULL; p++)
108
+ {
109
+ rb_ary_push (ary, rb_tainted_str_new2 (*p));
110
+ }
111
+ ldap_value_free (c_arr);
112
+
113
+ return ary;
114
+ }
115
+ else
116
+ {
117
+ return Qnil;
118
+ }
119
+ }
120
+
121
+ VALUE
122
+ rb_ldap_explode_rdn (VALUE self, VALUE rdn, VALUE notypes)
123
+ {
124
+ char **c_arr, **p;
125
+ char *c_dn;
126
+ VALUE ary;
127
+
128
+ if (rdn == Qnil)
129
+ {
130
+ return Qnil;
131
+ }
132
+
133
+ c_dn = StringValueCStr (rdn);
134
+ if ((c_arr = ldap_explode_rdn (c_dn, RTEST (notypes) ? 1 : 0)))
135
+ {
136
+ ary = rb_ary_new ();
137
+ for (p = c_arr; *p != NULL; p++) {
138
+ rb_ary_push (ary, rb_tainted_str_new2 (*p));
139
+ }
140
+ ldap_value_free (c_arr);
141
+
142
+ return ary;
143
+ }
144
+ else
145
+ {
146
+ return Qnil;
147
+ }
148
+ }
149
+
150
+ /*
151
+ * call-seq:
152
+ * LDAP.mod(mod_type, attr, vals) => LDAP::Mod
153
+ *
154
+ * Create a new LDAP::Mod object of type, +mod_type+. This is most commonly
155
+ * *LDAP_MOD_ADD*, *LDAP_MOD_REPLACE* or *LDAP_MOD_DELETE*, although some LDAP
156
+ * servers may offer extension types.
157
+ *
158
+ * +attr+ should be the name of the attribute on which to operate, whilst
159
+ * +vals+ is an array of values pertaining to +attr+. If +vals+ contains
160
+ * binary data, +mod_type+ should be logically OR'ed (|) with
161
+ * *LDAP_MOD_BVALUES*.
162
+ *
163
+ * LDAP::Mod objects can be passed to methods in the LDAP::Conn class, such as
164
+ * Conn#add, Conn#add_ext, Conn#modify and Conn#modify_ext.
165
+ */
166
+ static VALUE
167
+ rb_ldap_mod_s_new (int argc, VALUE argv[], VALUE klass)
168
+ {
169
+ return rb_ldap_class_new (argc, argv, rb_cLDAP_Mod);
170
+ }
171
+
172
+ static VALUE
173
+ rb_ldap_hash2mods_i (VALUE type_vals, VALUE tmp)
174
+ {
175
+ VALUE type, vals, op, result;
176
+ VALUE args[3];
177
+
178
+ op = rb_ary_entry (tmp, 0);
179
+ result = rb_ary_entry (tmp, 1);
180
+
181
+ type = rb_ary_entry (type_vals, 0);
182
+ vals = rb_ary_entry (type_vals, 1);
183
+
184
+ args[0] = op, args[1] = type, args[2] = vals;
185
+ rb_ary_push (result, rb_ldap_mod_s_new (3, args, rb_cLDAP_Mod));
186
+ return Qnil;
187
+ }
188
+
189
+ /*
190
+ * call-seq:
191
+ * LDAP.hash2mods(mod_type, hash) => Array of LDAP::Mod
192
+ *
193
+ * Convert a hash into an array of LDAP::Mod objects. +mod_type+ should
194
+ * contain the mod type, which is most commonly *LDAP_MOD_ADD*,
195
+ * *LDAP_MOD_REPLACE* or *LDAP_MOD_DELETE*, although some LDAP servers may
196
+ * offer extension types.
197
+ */
198
+ VALUE
199
+ rb_ldap_hash2mods (VALUE self, VALUE op, VALUE hash)
200
+ {
201
+ VALUE tmp;
202
+
203
+ tmp = rb_assoc_new (op, rb_ary_new ());
204
+ rb_iterate (rb_each, hash, rb_ldap_hash2mods_i, tmp);
205
+
206
+ return rb_ary_entry (tmp, 1);
207
+ }
208
+
209
+ /*
210
+ * call-seq:
211
+ * LDAP.entry2hash(entry) => Hash
212
+ *
213
+ * Convert the entry, +entry+, to a hash.
214
+ */
215
+ VALUE
216
+ rb_ldap_entry2hash (VALUE self, VALUE entry)
217
+ {
218
+ return rb_ldap_entry_to_hash (entry);
219
+ }
220
+
221
+
222
+
223
+ extern void Init_ldap_entry ();
224
+ extern void Init_ldap_conn ();
225
+ extern void Init_ldap_sslconn ();
226
+ extern void Init_ldap_saslconn ();
227
+ #ifdef USE_SSL_CLIENTAUTH
228
+ extern void Init_ldap_clientauth ();
229
+ #endif
230
+ extern void Init_ldap_mod ();
231
+ extern void Init_ldap_misc ();
232
+
233
+ /* Document-class: LDAP
234
+ *
235
+ * Container module for LDAP-related classes.
236
+ */
237
+ void
238
+ Init_ldap ()
239
+ {
240
+ rb_mLDAP = rb_define_module ("LDAP");
241
+
242
+ rb_define_const (rb_mLDAP, "LDAP_VERSION", INT2NUM (LDAP_VERSION));
243
+
244
+ #ifdef LDAP_VERSION1
245
+ rb_define_const (rb_mLDAP, "LDAP_VERSION1", INT2NUM (LDAP_VERSION1));
246
+ #endif
247
+
248
+ #ifdef LDAP_VERSION2
249
+ rb_define_const (rb_mLDAP, "LDAP_VERSION2", INT2NUM (LDAP_VERSION2));
250
+ #endif
251
+
252
+ #ifdef LDAP_VERSION3
253
+ rb_define_const (rb_mLDAP, "LDAP_VERSION3", INT2NUM (LDAP_VERSION3));
254
+ #endif
255
+
256
+ #ifdef LDAP_VERSION_MAX
257
+ rb_define_const (rb_mLDAP, "LDAP_VERSION_MAX", INT2NUM (LDAP_VERSION_MAX));
258
+ #else
259
+ rb_define_const (rb_mLDAP, "LDAP_VERSION_MAX", INT2NUM (LDAP_VERSION));
260
+ #endif
261
+
262
+ rb_define_const (rb_mLDAP, "VERSION",
263
+ rb_tainted_str_new2 (RB_LDAP_VERSION));
264
+ rb_define_const (rb_mLDAP, "MAJOR_VERSION",
265
+ INT2NUM (RB_LDAP_MAJOR_VERSION));
266
+ rb_define_const (rb_mLDAP, "MINOR_VERSION",
267
+ INT2NUM (RB_LDAP_MINOR_VERSION));
268
+ rb_define_const (rb_mLDAP, "PATCH_VERSION",
269
+ INT2NUM (RB_LDAP_PATCH_VERSION));
270
+
271
+ #ifdef LDAP_API_INFO_VERSION
272
+ rb_define_const (rb_mLDAP, "LDAP_API_INFO_VERSION",
273
+ INT2NUM (LDAP_API_INFO_VERSION));
274
+ #else
275
+ rb_define_const (rb_mLDAP, "LDAP_API_INFO_VERSION", Qnil);
276
+ #endif
277
+
278
+ #ifdef LDAP_VENDOR_VERSION
279
+ rb_define_const (rb_mLDAP, "LDAP_VENDOR_VERSION",
280
+ INT2NUM (LDAP_VENDOR_VERSION));
281
+ #else
282
+ rb_define_const (rb_mLDAP, "LDAP_VENDOR_VERSION", Qnil);
283
+ #endif
284
+ #ifdef LDAP_VENDOR_NAME
285
+ rb_define_const (rb_mLDAP, "LDAP_VENDOR_NAME",
286
+ rb_tainted_str_new2 (LDAP_VENDOR_NAME));
287
+ #else
288
+ rb_define_const (rb_mLDAP, "LDAP_VENDOR_NAME", Qnil);
289
+ #endif
290
+
291
+ #ifdef LDAP_API_VERSION
292
+ rb_define_const (rb_mLDAP, "LDAP_API_VERSION", INT2NUM (LDAP_API_VERSION));
293
+ #else
294
+ rb_define_const (rb_mLDAP, "LDAP_API_VERSION", Qnil);
295
+ #endif
296
+
297
+ rb_define_const (rb_mLDAP, "LDAP_PORT", INT2NUM (389));
298
+ rb_define_const (rb_mLDAP, "LDAPS_PORT", INT2NUM (636));
299
+ rb_eLDAP_Error =
300
+ rb_define_class_under (rb_mLDAP, "Error", rb_eStandardError);
301
+ rb_eLDAP_ResultError =
302
+ rb_define_class_under (rb_mLDAP, "ResultError", rb_eLDAP_Error);
303
+ rb_eLDAP_InvalidDataError =
304
+ rb_define_class_under (rb_mLDAP, "InvalidDataError", rb_eLDAP_Error);
305
+ rb_eLDAP_InvalidEntryError =
306
+ rb_define_class_under (rb_mLDAP, "InvalidEntryError",
307
+ rb_eLDAP_InvalidDataError);
308
+
309
+
310
+ rb_define_module_function (rb_mLDAP, "err2string", rb_ldap_err2string, 1);
311
+ rb_define_module_function (rb_mLDAP, "explode_dn", rb_ldap_explode_dn, 2);
312
+ rb_define_module_function (rb_mLDAP, "explode_rdn", rb_ldap_explode_rdn, 2);
313
+ rb_define_module_function (rb_mLDAP, "dn2ufn", rb_ldap_dn2ufn, 1);
314
+ rb_define_module_function (rb_mLDAP, "mod", rb_ldap_mod_s_new, -1);
315
+ rb_define_module_function (rb_mLDAP, "hash2mods", rb_ldap_hash2mods, 2);
316
+ rb_define_module_function (rb_mLDAP, "entry2hash", rb_ldap_entry2hash, 1);
317
+
318
+ /* the following error code must be defined in ldap.h */
319
+ #define rb_ldap_define_err_code(code) rb_define_const(rb_mLDAP,#code,INT2NUM(code))
320
+ rb_ldap_define_err_code (LDAP_SUCCESS);
321
+ rb_ldap_define_err_code (LDAP_OPERATIONS_ERROR);
322
+ rb_ldap_define_err_code (LDAP_PROTOCOL_ERROR);
323
+ rb_ldap_define_err_code (LDAP_TIMELIMIT_EXCEEDED);
324
+ rb_ldap_define_err_code (LDAP_SIZELIMIT_EXCEEDED);
325
+ rb_ldap_define_err_code (LDAP_COMPARE_FALSE);
326
+ rb_ldap_define_err_code (LDAP_COMPARE_TRUE);
327
+ #ifdef LDAP_STRONG_AUTH_NOT_SUPPORTED
328
+ rb_ldap_define_err_code (LDAP_STRONG_AUTH_NOT_SUPPORTED);
329
+ #endif
330
+ #ifdef LDAP_AUTH_METHOD_NOT_SUPPORTED
331
+ rb_ldap_define_err_code (LDAP_AUTH_METHOD_NOT_SUPPORTED);
332
+ #endif
333
+ rb_ldap_define_err_code (LDAP_STRONG_AUTH_REQUIRED);
334
+ #ifdef LDAP_REFERRAL
335
+ rb_ldap_define_err_code (LDAP_REFERRAL);
336
+ #endif
337
+ #ifdef LDAP_ADMINLIMIT_EXCEEDED
338
+ rb_ldap_define_err_code (LDAP_ADMINLIMIT_EXCEEDED);
339
+ #endif
340
+ #ifdef LDAP_UNAVAILABLE_CRITICAL_EXTENSION
341
+ rb_ldap_define_err_code (LDAP_UNAVAILABLE_CRITICAL_EXTENSION);
342
+ #endif
343
+ #ifdef LDAP_CONFIDENTIALITY_REQUIRED
344
+ rb_ldap_define_err_code (LDAP_CONFIDENTIALITY_REQUIRED);
345
+ #endif
346
+ #ifdef LDAP_SASL_BIND_IN_PROGRESS
347
+ rb_ldap_define_err_code (LDAP_SASL_BIND_IN_PROGRESS);
348
+ #endif
349
+ #ifdef LDAP_PARTIAL_RESULTS
350
+ rb_ldap_define_err_code (LDAP_PARTIAL_RESULTS);
351
+ #endif
352
+ rb_ldap_define_err_code (LDAP_NO_SUCH_ATTRIBUTE);
353
+ rb_ldap_define_err_code (LDAP_UNDEFINED_TYPE);
354
+ rb_ldap_define_err_code (LDAP_INAPPROPRIATE_MATCHING);
355
+ rb_ldap_define_err_code (LDAP_CONSTRAINT_VIOLATION);
356
+ rb_ldap_define_err_code (LDAP_TYPE_OR_VALUE_EXISTS);
357
+ rb_ldap_define_err_code (LDAP_INVALID_SYNTAX);
358
+ rb_ldap_define_err_code (LDAP_NO_SUCH_OBJECT);
359
+ rb_ldap_define_err_code (LDAP_ALIAS_PROBLEM);
360
+ rb_ldap_define_err_code (LDAP_INVALID_DN_SYNTAX);
361
+ rb_ldap_define_err_code (LDAP_IS_LEAF);
362
+ rb_ldap_define_err_code (LDAP_ALIAS_DEREF_PROBLEM);
363
+ rb_ldap_define_err_code (LDAP_INAPPROPRIATE_AUTH);
364
+ rb_ldap_define_err_code (LDAP_INVALID_CREDENTIALS);
365
+ rb_ldap_define_err_code (LDAP_INSUFFICIENT_ACCESS);
366
+ rb_ldap_define_err_code (LDAP_BUSY);
367
+ rb_ldap_define_err_code (LDAP_UNAVAILABLE);
368
+ rb_ldap_define_err_code (LDAP_UNWILLING_TO_PERFORM);
369
+ rb_ldap_define_err_code (LDAP_LOOP_DETECT);
370
+ rb_ldap_define_err_code (LDAP_NAMING_VIOLATION);
371
+ rb_ldap_define_err_code (LDAP_OBJECT_CLASS_VIOLATION);
372
+ rb_ldap_define_err_code (LDAP_NOT_ALLOWED_ON_NONLEAF);
373
+ rb_ldap_define_err_code (LDAP_NOT_ALLOWED_ON_RDN);
374
+ rb_ldap_define_err_code (LDAP_ALREADY_EXISTS);
375
+ rb_ldap_define_err_code (LDAP_NO_OBJECT_CLASS_MODS);
376
+ rb_ldap_define_err_code (LDAP_RESULTS_TOO_LARGE);
377
+ rb_ldap_define_err_code (LDAP_OTHER);
378
+ rb_ldap_define_err_code (LDAP_SERVER_DOWN);
379
+ rb_ldap_define_err_code (LDAP_LOCAL_ERROR);
380
+ rb_ldap_define_err_code (LDAP_ENCODING_ERROR);
381
+ rb_ldap_define_err_code (LDAP_DECODING_ERROR);
382
+ rb_ldap_define_err_code (LDAP_TIMEOUT);
383
+ rb_ldap_define_err_code (LDAP_AUTH_UNKNOWN);
384
+ rb_ldap_define_err_code (LDAP_FILTER_ERROR);
385
+ rb_ldap_define_err_code (LDAP_USER_CANCELLED);
386
+ rb_ldap_define_err_code (LDAP_PARAM_ERROR);
387
+ rb_ldap_define_err_code (LDAP_NO_MEMORY);
388
+ /* rb_ldap_define_err_code(LDAP_CONNECT_ERROR); */
389
+ #undef rb_ldap_define_err_code
390
+
391
+ #define rb_ldap_define_opt(code) rb_define_const(rb_mLDAP,#code,INT2NUM((int)code))
392
+ #ifdef LDAP_OPT_ON
393
+ rb_ldap_define_opt (LDAP_OPT_ON);
394
+ #endif
395
+ #ifdef LDAP_OPT_OFF
396
+ rb_ldap_define_opt (LDAP_OPT_OFF);
397
+ #endif
398
+ #ifdef LDAP_OPT_DESC
399
+ rb_ldap_define_opt (LDAP_OPT_DESC);
400
+ #endif
401
+ #ifdef LDAP_OPT_DEREF
402
+ rb_ldap_define_opt (LDAP_OPT_DEREF);
403
+ #endif
404
+ #ifdef LDAP_OPT_SIZELIMIT
405
+ rb_ldap_define_opt (LDAP_OPT_SIZELIMIT);
406
+ #endif
407
+ #ifdef LDAP_OPT_TIMELIMIT
408
+ rb_ldap_define_opt (LDAP_OPT_TIMELIMIT);
409
+ #endif
410
+ #ifdef LDAP_OPT_NETWORK_TIMEOUT
411
+ rb_ldap_define_opt (LDAP_OPT_NETWORK_TIMEOUT);
412
+ #endif
413
+ #ifdef LDAP_OPT_THREAD_FN_PTRS
414
+ rb_ldap_define_opt (LDAP_OPT_THREAD_FN_PTRS);
415
+ #endif
416
+ #ifdef LDAP_OPT_REBIND_FN
417
+ rb_ldap_define_opt (LDAP_OPT_REBIND_FN);
418
+ #endif
419
+ #ifdef LDAP_OPT_REBIND_ARG
420
+ rb_ldap_define_opt (LDAP_OPT_REBIND_ARG);
421
+ #endif
422
+ #ifdef LDAP_OPT_REFERRALS
423
+ rb_ldap_define_opt (LDAP_OPT_REFERRALS);
424
+ #endif
425
+ #ifdef LDAP_OPT_RESTART
426
+ rb_ldap_define_opt (LDAP_OPT_RESTART);
427
+ #endif
428
+ #ifdef LDAP_OPT_SSL
429
+ rb_ldap_define_opt (LDAP_OPT_SSL);
430
+ #endif
431
+ #ifdef LDAP_OPT_IO_FN_PTRS
432
+ rb_ldap_define_opt (LDAP_OPT_IO_FN_PTRS);
433
+ #endif
434
+ #ifdef LDAP_OPT_CACHE_FN_PTRS
435
+ rb_ldap_define_opt (LDAP_OPT_CACHE_FN_PTRS);
436
+ #endif
437
+ #ifdef LDAP_OPT_CACHE_STRATEGY
438
+ rb_ldap_define_opt (LDAP_OPT_CACHE_STRATEGY);
439
+ #endif
440
+ #ifdef LDAP_OPT_CACHE_ENABLE
441
+ rb_ldap_define_opt (LDAP_OPT_CACHE_ENABLE);
442
+ #endif
443
+ #ifdef LDAP_OPT_REFERRAL_HOP_LIMIT
444
+ rb_ldap_define_opt (LDAP_OPT_REFERRAL_HOP_LIMIT);
445
+ #endif
446
+ #ifdef LDAP_OPT_PROTOCOL_VERSION
447
+ rb_ldap_define_opt (LDAP_OPT_PROTOCOL_VERSION);
448
+ #endif
449
+ #ifdef LDAP_OPT_SERVER_CONTROLS
450
+ rb_ldap_define_opt (LDAP_OPT_SERVER_CONTROLS);
451
+ #endif
452
+ #ifdef LDAP_OPT_CLIENT_CONTROLS
453
+ rb_ldap_define_opt (LDAP_OPT_CLIENT_CONTROLS);
454
+ #endif
455
+ #ifdef LDAP_OPT_PREFERRED_LANGUAGE
456
+ rb_ldap_define_opt (LDAP_OPT_PREFERRED_LANGUAGE);
457
+ #endif
458
+ #ifdef LDAP_OPT_API_INFO
459
+ rb_ldap_define_opt (LDAP_OPT_API_INFO);
460
+ #endif
461
+ #ifdef LDAP_OPT_API_FEATURE_INFO
462
+ rb_ldap_define_opt (LDAP_OPT_API_FEATURE_INFO);
463
+ #endif
464
+ #ifdef LDAP_OPT_HOST_NAME
465
+ rb_ldap_define_opt (LDAP_OPT_HOST_NAME);
466
+ #endif
467
+
468
+ #ifdef USE_OPENLDAP2 /* OpenLDAP TLS,SASL options */
469
+ #ifdef LDAP_OPT_X_TLS_CACERTFILE
470
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_CACERTFILE);
471
+ #endif
472
+ #ifdef LDAP_OPT_X_TLS_CACERTDIR
473
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_CACERTDIR);
474
+ #endif
475
+ #ifdef LDAP_OPT_X_TLS_CERT
476
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_CERT);
477
+ #endif
478
+ #ifdef LDAP_OPT_X_TLS_CERTFILE
479
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_CERTFILE);
480
+ #endif
481
+ #ifdef LDAP_OPT_X_TLS_KEYFILE
482
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_KEYFILE);
483
+ #endif
484
+ #ifdef LDAP_OPT_X_TLS_REQUIRE_CERT
485
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_REQUIRE_CERT);
486
+ #endif
487
+ #ifdef LDAP_OPT_X_TLS
488
+ rb_ldap_define_opt (LDAP_OPT_X_TLS);
489
+ #endif
490
+ #ifdef LDAP_OPT_X_TLS_PROTOCOL_MIN
491
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_PROTOCOL_MIN);
492
+ #endif
493
+ #ifdef LDAP_OPT_X_TLS_CIPHER_SUITE
494
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_CIPHER_SUITE);
495
+ #endif
496
+ #ifdef LDAP_OPT_X_TLS_RANDOM_FILE
497
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_RANDOM_FILE);
498
+ #endif
499
+ #ifdef LDAP_OPT_X_TLS_NEWCTX
500
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_NEWCTX);
501
+ #endif
502
+ #ifdef LDAP_OPT_X_TLS_NEVER
503
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_NEVER);
504
+ #endif
505
+ #ifdef LDAP_OPT_X_TLS_HARD
506
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_HARD);
507
+ #endif
508
+ #ifdef LDAP_OPT_X_TLS_DEMAND
509
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_DEMAND);
510
+ #endif
511
+ #ifdef LDAP_OPT_X_TLS_ALLOW
512
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_ALLOW);
513
+ #endif
514
+ #ifdef LDAP_OPT_X_TLS_TRY
515
+ rb_ldap_define_opt (LDAP_OPT_X_TLS_TRY);
516
+ #endif
517
+ #ifdef LDAP_OPT_X_SASL_MECH
518
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_MECH);
519
+ #endif
520
+ #ifdef LDAP_OPT_X_SASL_REALM
521
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_REALM);
522
+ #endif
523
+ #ifdef LDAP_OPT_X_SASL_AUTHCID
524
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_AUTHCID);
525
+ #endif
526
+ #ifdef LDAP_OPT_X_SASL_AUTHZID
527
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_AUTHZID);
528
+ #endif
529
+ #ifdef LDAP_OPT_X_SASL_SSF
530
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_SSF);
531
+ #endif
532
+ #ifdef LDAP_OPT_X_SASL_SSF_EXTERNAL
533
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_SSF_EXTERNAL);
534
+ #endif
535
+ #ifdef LDAP_OPT_X_SASL_SECPROPS
536
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_SECPROPS);
537
+ #endif
538
+ #ifdef LDAP_OPT_X_SASL_SSF_MIN
539
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_SSF_MIN);
540
+ #endif
541
+ #ifdef LDAP_OPT_X_SASL_SSF_MAX
542
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_SSF_MAX);
543
+ #endif
544
+ #ifdef LDAP_OPT_X_SASL_MAXBUFSIZE
545
+ rb_ldap_define_opt (LDAP_OPT_X_SASL_MAXBUFSIZE);
546
+ #endif
547
+ #endif /* USE_OPENLDAP2 */
548
+
549
+
550
+ #undef rb_ldap_define_opt
551
+
552
+ /* these constants indicate search scopes */
553
+ #define rb_ldap_define_scope(scope) rb_define_const(rb_mLDAP,#scope,INT2NUM(scope))
554
+ rb_ldap_define_scope (LDAP_SCOPE_BASE);
555
+ rb_ldap_define_scope (LDAP_SCOPE_SUBTREE);
556
+ rb_ldap_define_scope (LDAP_SCOPE_ONELEVEL);
557
+ #undef rb_ldap_define_scope
558
+
559
+ #define rb_ldap_define_deref(x) rb_define_const(rb_mLDAP,#x,INT2NUM(x))
560
+ #ifdef LDAP_DEREF_NEVER
561
+ rb_ldap_define_deref (LDAP_DEREF_NEVER);
562
+ #endif
563
+ #ifdef LDAP_DEREF_SEARCHING
564
+ rb_ldap_define_deref (LDAP_DEREF_SEARCHING);
565
+ #endif
566
+ #ifdef LDAP_DEREF_FINDING
567
+ rb_ldap_define_deref (LDAP_DEREF_FINDING);
568
+ #endif
569
+ #ifdef LDAP_DEREF_ALWAYS
570
+ rb_ldap_define_deref (LDAP_DEREF_ALWAYS);
571
+ #endif
572
+ #undef rb_ldap_define_deref
573
+
574
+ #define rb_ldap_define_sasl_mech(c) \
575
+ (c ? rb_define_const(rb_mLDAP,#c,rb_str_new2(c)) : rb_define_const(rb_mLDAP,#c,Qnil))
576
+ #ifdef LDAP_SASL_SIMPLE
577
+ rb_ldap_define_sasl_mech (LDAP_SASL_SIMPLE);
578
+ #endif
579
+ #undef rb_ldap_define_sasl_mech
580
+
581
+ #define rb_ldap_define_auth_method(c) rb_define_const(rb_mLDAP,#c,INT2NUM(c))
582
+ rb_ldap_define_auth_method (LDAP_AUTH_NONE);
583
+ rb_ldap_define_auth_method (LDAP_AUTH_SIMPLE);
584
+ #ifdef LDAP_AUTH_KRBV41
585
+ rb_ldap_define_auth_method (LDAP_AUTH_KRBV41);
586
+ #endif
587
+ #ifdef LDAP_AUTH_KRBV42
588
+ rb_ldap_define_auth_method (LDAP_AUTH_KRBV42);
589
+ #endif
590
+ #ifdef LDAP_AUTH_SASL
591
+ rb_ldap_define_auth_method (LDAP_AUTH_SASL);
592
+ #endif
593
+ #ifdef LDAP_KRBV4
594
+ rb_ldap_define_auth_method (LDAP_KRBV4);
595
+ #endif
596
+ /* wldap32.h */
597
+ #ifdef LDAP_AUTH_OTHERKIND
598
+ rb_ldap_define_auth_method (LDAP_AUTH_OTHERKIND);
599
+ #endif
600
+ #ifdef LDAP_AUTH_DPA
601
+ rb_ldap_define_auth_method (LDAP_AUTH_DPA);
602
+ #endif
603
+ #ifdef LDAP_AUTH_MSN
604
+ rb_ldap_define_auth_method (LDAP_AUTH_MSN);
605
+ #endif
606
+ #ifdef LDAP_AUTH_NEGOTIATE
607
+ rb_ldap_define_auth_method (LDAP_AUTH_NEGOTIATE);
608
+ #endif
609
+ #ifdef LDAP_AUTH_NTLM
610
+ rb_ldap_define_auth_method (LDAP_AUTH_NTLM);
611
+ #endif
612
+ #ifdef LDAP_AUTH_SICILY
613
+ rb_ldap_define_auth_method (LDAP_AUTH_SICILY);
614
+ #endif
615
+ #ifdef LDAP_AUTH_SSPI
616
+ rb_ldap_define_auth_method (LDAP_AUTH_SSPI);
617
+ #endif
618
+ #undef rb_ldap_define_auth_method
619
+
620
+ #ifdef LDAP_CONTROL_PAGEDRESULTS
621
+ rb_define_const (rb_mLDAP, "LDAP_CONTROL_PAGEDRESULTS",
622
+ rb_str_new2 (LDAP_CONTROL_PAGEDRESULTS));
623
+ #endif
624
+
625
+ #define rb_ldap_define_const(c) rb_define_const(rb_mLDAP,#c,INT2NUM(c))
626
+ rb_ldap_define_const (LDAP_MOD_ADD);
627
+ rb_ldap_define_const (LDAP_MOD_DELETE);
628
+ rb_ldap_define_const (LDAP_MOD_REPLACE);
629
+ rb_ldap_define_const (LDAP_MOD_BVALUES);
630
+ #ifdef LDAP_MOD_INCREMENT
631
+ /*
632
+ * See http://www.ietf.org/internet-drafts/draft-zeilenga-ldap-incr-00.txt
633
+ */
634
+ rb_ldap_define_const (LDAP_MOD_INCREMENT);
635
+ #endif
636
+ #ifdef LDAP_MOD_OP
637
+ rb_ldap_define_const (LDAP_MOD_OP);
638
+ #endif
639
+ #undef rb_ldap_define_const
640
+
641
+ Init_ldap_conn ();
642
+ Init_ldap_sslconn ();
643
+ Init_ldap_saslconn ();
644
+ #ifdef USE_SSL_CLIENTAUTH
645
+ Init_ldap_clientauth();
646
+ #endif
647
+ Init_ldap_entry ();
648
+ Init_ldap_mod ();
649
+ Init_ldap_misc ();
650
+ }
@@ -0,0 +1,50 @@
1
+ # Manipulation of LDAP control data.
2
+ #
3
+ #--
4
+ # $Id: control.rb,v 1.2 2005/02/28 05:02:25 ianmacd Exp $
5
+ #++
6
+ #
7
+ # Copyright (C) 2004 Ian Macdonald <ian@caliban.org>
8
+ #
9
+
10
+ module LDAP
11
+ class Control
12
+
13
+ require 'openssl'
14
+
15
+ # Take +vals+, produce an Array of values in ASN.1 format and then
16
+ # convert the Array to DER.
17
+ #
18
+ def Control.encode( *vals )
19
+ encoded_vals = []
20
+
21
+ vals.each do |val|
22
+ encoded_vals <<
23
+ case val
24
+ when Integer
25
+ OpenSSL::ASN1::Integer( val )
26
+ when String
27
+ OpenSSL::ASN1::OctetString.new( val )
28
+ else
29
+ # What other types may exist?
30
+ end
31
+ end
32
+
33
+ OpenSSL::ASN1::Sequence.new( encoded_vals ).to_der
34
+ end
35
+
36
+
37
+ # Take an Array of ASN.1 data and return an Array of decoded values.
38
+ #
39
+ def decode
40
+ values = []
41
+
42
+ OpenSSL::ASN1::decode( self.value ).value.each do |val|
43
+ values << val.value
44
+ end
45
+
46
+ values
47
+ end
48
+
49
+ end
50
+ end