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/saslconn.c ADDED
@@ -0,0 +1,242 @@
1
+ /*
2
+ * saslconn.c
3
+ * $Id: saslconn.c,v 1.25 2006/02/13 17:20:32 ianmacd Exp $
4
+ */
5
+
6
+ #include "ruby.h"
7
+ #include "rbldap.h"
8
+ #if defined(HAVE_SYS_TIME_H)
9
+ # include <sys/time.h>
10
+ #endif
11
+ #if defined(HAVE_UNISTD_H)
12
+ # include <unistd.h>
13
+ #endif
14
+
15
+ extern VALUE rb_ldap_conn_initialize (int argc, VALUE argv[], VALUE self);
16
+ extern VALUE rb_ldap_conn_rebind (VALUE self);
17
+
18
+ #if defined(HAVE_LDAP_SASL_BIND_S)
19
+ #include <sasl/sasl.h>
20
+ VALUE
21
+ rb_ldap_indifferent_hash_aref(VALUE hash, const char *key)
22
+ {
23
+ VALUE symval = rb_hash_aref(hash, ID2SYM(rb_intern(key)));
24
+ if (!NIL_P(symval))
25
+ {
26
+ return symval;
27
+ }
28
+ return rb_hash_aref(hash, rb_str_new2(key)); /* this could be Qnil */
29
+ }
30
+
31
+ int
32
+ rb_ldap_sasl_interaction (LDAP * ld, unsigned flags, void *de, void *in)
33
+ {
34
+ sasl_interact_t *interact = in;
35
+ VALUE options = (VALUE)de;
36
+
37
+ VALUE defvalue;
38
+ const char *dflt = NULL;
39
+
40
+ if (ld == NULL)
41
+ {
42
+ return LDAP_PARAM_ERROR;
43
+ }
44
+ if (flags == LDAP_SASL_INTERACTIVE)
45
+ {
46
+ rb_raise (rb_eLDAP_Error, "interactive bind not supported.");
47
+ }
48
+ while (!NIL_P(options) && interact->id != SASL_CB_LIST_END)
49
+ {
50
+ dflt = interact->defresult;
51
+ switch (interact->id)
52
+ {
53
+ case SASL_CB_GETREALM:
54
+ if (!NIL_P(defvalue = rb_ldap_indifferent_hash_aref(options, "realm")))
55
+ {
56
+ dflt = StringValuePtr(defvalue);
57
+ }
58
+ break;
59
+ case SASL_CB_AUTHNAME:
60
+ if (!NIL_P(defvalue = rb_ldap_indifferent_hash_aref(options, "authcid")))
61
+ {
62
+ dflt = StringValuePtr(defvalue);
63
+ }
64
+ break;
65
+ case SASL_CB_USER:
66
+ if (!NIL_P(defvalue = rb_ldap_indifferent_hash_aref(options, "authzid")))
67
+ {
68
+ dflt = StringValuePtr(defvalue);
69
+ }
70
+ break;
71
+ default:
72
+ /* Nothing. */
73
+ break;
74
+ }
75
+ if (dflt != NULL)
76
+ {
77
+ interact->result = dflt;
78
+ interact->len = strlen(dflt);
79
+ }
80
+ interact++;
81
+ }
82
+ return LDAP_SUCCESS;
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * conn.sasl_bind(dn=nil, mech=nil, cred=nil, sctrls=nil, cctrls=nil, sasl_options=nil) => self
88
+ * conn.sasl_bind(dn=nil, mech=nil, cred=nil, sctrls=nil, cctrls=nil, sasl_options=nil)
89
+ * { |conn| } => nil
90
+ *
91
+ * Bind an LDAP connection, using the DN, +dn+, the mechanism, +mech+, and the
92
+ * credential, +cred+.
93
+ *
94
+ * +sctrls+ is an array of server controls, whilst +cctrls+ is an array of
95
+ * client controls.
96
+ *
97
+ * sasl_options is a hash which should have the following keys:
98
+ *
99
+ * - +:authcid+ and +:authzid+ for alternate SASL authentication
100
+ * - +realm+ to specify the SASL realm
101
+ *
102
+ * If a block is given, +self+ is yielded to the block.
103
+ */
104
+ VALUE
105
+ rb_ldap_conn_sasl_bind (int argc, VALUE argv[], VALUE self)
106
+ {
107
+ RB_LDAP_DATA *ldapdata;
108
+
109
+ VALUE arg1, arg2, arg3, arg4, arg5, sasl_options, other_options = Qnil;
110
+ int version;
111
+ char *dn = NULL;
112
+ char *mechanism = NULL;
113
+ struct berval *cred = ALLOCA_N (struct berval, 1);
114
+ LDAPControl **serverctrls = NULL;
115
+ LDAPControl **clientctrls = NULL;
116
+
117
+ /*
118
+ struct berval *servercred = NULL;
119
+ char *sasl_realm = NULL;
120
+ char *sasl_authc_id = NULL;
121
+ char *sasl_authz_id = NULL;
122
+ char *sasl_secprops = NULL;
123
+ struct berval passwd = { 0, NULL };
124
+ */
125
+
126
+ unsigned sasl_flags = LDAP_SASL_AUTOMATIC;
127
+
128
+ Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
129
+ if (!ldapdata->ldap)
130
+ {
131
+ if (rb_iv_get (self, "@args") != Qnil)
132
+ {
133
+ rb_ldap_conn_rebind (self);
134
+ GET_LDAP_DATA (self, ldapdata);
135
+ }
136
+ else
137
+ {
138
+ rb_raise (rb_eLDAP_InvalidDataError,
139
+ "The LDAP handler has already unbound.");
140
+ }
141
+ }
142
+
143
+ if (ldapdata->bind)
144
+ {
145
+ rb_raise (rb_eLDAP_Error, "already bound.");
146
+ };
147
+
148
+ switch (rb_scan_args (argc, argv, "25", &arg1, &arg2, &arg3, &arg4, &arg5, &sasl_options, &other_options))
149
+ {
150
+ case 7:
151
+ /* Parse through the hash. Currently there's only one option, nothing fancy needed. */
152
+ if (!NIL_P(rb_ldap_indifferent_hash_aref(other_options, "nocanon")))
153
+ {
154
+ /* Inspired by the ldapsearch -N option, inspired by the code in OpenLDAP (BSD style license) in clients/tools/common.c */
155
+ ldapdata->err = ldap_set_option( ldapdata->ldap, LDAP_OPT_X_SASL_NOCANON, LDAP_OPT_ON);
156
+ Check_LDAP_Result(ldapdata->err);
157
+ }
158
+ case 6:
159
+ /* nothing. this requires credentials to be parsed first. we'll get defaults after arg-scanning */
160
+ case 5:
161
+ if(!NIL_P(arg5))
162
+ clientctrls = rb_ldap_get_controls (arg5);
163
+ /* down seems more likely */
164
+ case 4:
165
+ if(!NIL_P(arg4))
166
+ serverctrls = rb_ldap_get_controls (arg4);
167
+ /* down seems more likely */
168
+ case 3:
169
+ if(!NIL_P(arg3))
170
+ {
171
+ cred->bv_val = StringValueCStr (arg3);
172
+ cred->bv_len = RSTRING_LEN (arg3);
173
+ }
174
+ /* down seems more likely */
175
+ case 2: /* don't need the cred for GSSAPI */
176
+ dn = StringValuePtr (arg1);
177
+ mechanism = StringValuePtr (arg2);
178
+ if (rb_iv_get (self, "@sasl_quiet") == Qtrue)
179
+ sasl_flags = LDAP_SASL_QUIET;
180
+ break;
181
+ default:
182
+ rb_bug ("rb_ldap_conn_bind_s");
183
+ }
184
+
185
+ ldap_get_option (ldapdata->ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
186
+ if (version < LDAP_VERSION3)
187
+ {
188
+ version = LDAP_VERSION3;
189
+ ldapdata->err =
190
+ ldap_set_option (ldapdata->ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
191
+ Check_LDAP_Result (ldapdata->err);
192
+ }
193
+
194
+ /* the following works for GSSAPI, at least */
195
+ ldapdata->err =
196
+ ldap_sasl_interactive_bind_s (ldapdata->ldap, dn, mechanism,
197
+ serverctrls, clientctrls, sasl_flags,
198
+ rb_ldap_sasl_interaction, (void*)sasl_options);
199
+
200
+ if (ldapdata->err == LDAP_SASL_BIND_IN_PROGRESS)
201
+ {
202
+ rb_raise (rb_eNotImpError,
203
+ "SASL authentication is not fully supported.");
204
+ /* How can I implement this with portability? */
205
+ /*
206
+ VALUE scred;
207
+ scred = rb_tainted_str_new(servercred->bv_val,
208
+ servercred->bv_len);
209
+ */
210
+ }
211
+ else
212
+ {
213
+ Check_LDAP_Result (ldapdata->err);
214
+ ldapdata->bind = 1;
215
+ }
216
+
217
+ if (rb_block_given_p ())
218
+ {
219
+ rb_ensure (rb_yield, self, rb_ldap_conn_unbind, self);
220
+ return Qnil;
221
+ }
222
+ else
223
+ {
224
+ return self;
225
+ };
226
+ }
227
+
228
+ #else /* HAVE_LDAP_SASL_BIND_S */
229
+
230
+ VALUE
231
+ rb_ldap_conn_sasl_bind (int argc, VALUE argv[], VALUE self)
232
+ {
233
+ rb_notimplement ();
234
+ }
235
+
236
+ #endif /* HAVE_LDAP_SASL_BIND_S */
237
+
238
+ void
239
+ Init_ldap_saslconn ()
240
+ {
241
+ rb_define_method (rb_cLDAP_Conn, "sasl_bind", rb_ldap_conn_sasl_bind, -1);
242
+ }
data/sslconn.c ADDED
@@ -0,0 +1,377 @@
1
+ /*
2
+ * sslconn.c
3
+ * $Id: sslconn.c,v 1.18 2006/04/19 22:13:26 ianmacd Exp $
4
+ */
5
+
6
+ #include "ruby.h"
7
+ #include "rbldap.h"
8
+ #if defined(HAVE_SYS_TIME_H)
9
+ # include <sys/time.h>
10
+ #endif
11
+ #if defined(HAVE_UNISTD_H)
12
+ # include <unistd.h>
13
+ #endif
14
+
15
+ #if defined(HAVE_LDAP_START_TLS_S)
16
+ # define USE_OPENLDAP_SSLCONN
17
+ #elif defined(HAVE_LDAPSSL_INIT)
18
+ # define USE_NSSLDAP_SSLCONN
19
+ #elif defined(HAVE_LDAP_SSLINIT)
20
+ # define USE_WLDAP32_SSLCONN
21
+ #endif
22
+
23
+ VALUE rb_cLDAP_SSLConn;
24
+
25
+ #ifdef USE_OPENLDAP_SSLCONN
26
+ static VALUE
27
+ rb_openldap_sslconn_initialize (int argc, VALUE argv[], VALUE self)
28
+ {
29
+ RB_LDAP_DATA *ldapdata;
30
+ LDAP *cldap;
31
+ char *chost = NULL;
32
+ int cport = LDAP_PORT;
33
+
34
+ VALUE arg1, arg2, arg3, arg4, arg5;
35
+
36
+ LDAPControl **serverctrls = NULL;
37
+ LDAPControl **clientctrls = NULL;
38
+ int version;
39
+ int start_tls;
40
+
41
+
42
+ Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
43
+ if (ldapdata->ldap)
44
+ return Qnil;
45
+
46
+ switch (rb_scan_args (argc, argv, "05", &arg1, &arg2, &arg3, &arg4, &arg5))
47
+ {
48
+ case 0:
49
+ chost = ALLOCA_N (char, strlen ("localhost") + 1);
50
+ strcpy (chost, "localhost");
51
+ cport = LDAP_PORT;
52
+ start_tls = 0;
53
+ break;
54
+ case 1:
55
+ chost = StringValueCStr (arg1);
56
+ cport = LDAP_PORT;
57
+ start_tls = 0;
58
+ break;
59
+ case 2:
60
+ chost = StringValueCStr (arg1);
61
+ cport = NUM2INT (arg2);
62
+ start_tls = 0;
63
+ break;
64
+ case 3:
65
+ chost = StringValueCStr (arg1);
66
+ cport = NUM2INT (arg2);
67
+ start_tls = (arg3 == Qtrue) ? 1 : 0;
68
+ break;
69
+ case 4:
70
+ chost = StringValueCStr (arg1);
71
+ cport = NUM2INT (arg2);
72
+ start_tls = (arg3 == Qtrue) ? 1 : 0;
73
+ serverctrls = rb_ldap_get_controls (arg4);
74
+ break;
75
+ case 5:
76
+ chost = StringValueCStr (arg1);
77
+ cport = NUM2INT (arg2);
78
+ start_tls = (arg3 == Qtrue) ? 1 : 0;
79
+ serverctrls = rb_ldap_get_controls (arg4);
80
+ clientctrls = rb_ldap_get_controls (arg5);
81
+ break;
82
+ default:
83
+ rb_bug ("rb_ldap_conn_new");
84
+ }
85
+
86
+ cldap = ldap_init (chost, cport);
87
+ if (!cldap)
88
+ rb_raise (rb_eLDAP_ResultError, "can't initialise an LDAP session");
89
+
90
+ ldapdata->ldap = cldap;
91
+
92
+ if (rb_block_given_p ())
93
+ {
94
+ rb_yield (self);
95
+ }
96
+
97
+ ldap_get_option (cldap, LDAP_OPT_PROTOCOL_VERSION, &version);
98
+ if (version < LDAP_VERSION3)
99
+ {
100
+ version = LDAP_VERSION3;
101
+ ldapdata->err =
102
+ ldap_set_option (cldap, LDAP_OPT_PROTOCOL_VERSION, &version);
103
+ Check_LDAP_Result (ldapdata->err);
104
+ }
105
+
106
+ if (start_tls)
107
+ {
108
+ ldapdata->err = ldap_start_tls_s (cldap, serverctrls, clientctrls);
109
+ Check_LDAP_Result (ldapdata->err);
110
+ }
111
+ else
112
+ {
113
+ int opt = LDAP_OPT_X_TLS_HARD;
114
+ ldapdata->err = ldap_set_option (cldap, LDAP_OPT_X_TLS, &opt);
115
+ Check_LDAP_Result (ldapdata->err);
116
+ }
117
+
118
+ rb_iv_set (self, "@args", rb_ary_new4 (argc, argv));
119
+ rb_iv_set (self, "@sasl_quiet", Qfalse);
120
+
121
+ return Qnil;
122
+ }
123
+ #endif /* USE_OPENLDAP_SSLCONN */
124
+
125
+
126
+ #ifdef USE_NSSLDAP_SSLCONN
127
+ static VALUE
128
+ rb_nssldap_sslconn_initialize (int argc, VALUE argv[], VALUE self)
129
+ {
130
+ RB_LDAP_DATA *ldapdata;
131
+ LDAP *cldap;
132
+ char *chost = NULL;
133
+ char *certpath = NULL;
134
+ int cport = LDAP_PORT;
135
+ int csecure = 0;
136
+
137
+ VALUE arg1, arg2, arg3, arg4;
138
+
139
+ Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
140
+ if (ldapdata->ldap)
141
+ return Qnil;
142
+
143
+ switch (rb_scan_args (argc, argv, "04", &arg1, &arg2, &arg3, &arg4))
144
+ {
145
+ case 0:
146
+ chost = ALLOCA_N (char, strlen ("localhost") + 1);
147
+ strcpy (chost, "localhost");
148
+ cport = LDAP_PORT;
149
+ csecure = 0;
150
+ certpath = NULL;
151
+ break;
152
+ case 1:
153
+ chost = StringValueCStr (arg1);
154
+ cport = LDAP_PORT;
155
+ csecure = 0;
156
+ certpath = NULL;
157
+ break;
158
+ case 2:
159
+ chost = StringValueCStr (arg1);
160
+ cport = NUM2INT (arg2);
161
+ csecure = 0;
162
+ certpath = NULL;
163
+ break;
164
+ case 3:
165
+ chost = StringValueCStr (arg1);
166
+ cport = NUM2INT (arg2);
167
+ csecure = (arg3 == Qtrue) ? 1 : 0;
168
+ certpath = NULL;
169
+ break;
170
+ case 4:
171
+ chost = StringValueCStr (arg1);
172
+ cport = NUM2INT (arg2);
173
+ csecure = (arg3 == Qtrue) ? 1 : 0;
174
+ certpath = (arg4 == Qnil) ? NULL : StringValueCStr (arg4);
175
+ break;
176
+ default:
177
+ rb_bug ("rb_ldap_conn_new");
178
+ }
179
+
180
+ /***
181
+ ldapssl_client_init():
182
+ http://docs.iplanet.com/docs/manuals/dirsdk/csdk41/html/function.htm#25963
183
+ ldapssl_client_authinit():
184
+ http://docs.iplanet.com/docs/manuals/dirsdk/csdk41/html/function.htm#26024
185
+ ***/
186
+ ldapssl_client_init (certpath, NULL);
187
+ cldap = ldapssl_init (chost, cport, csecure);
188
+ ldapdata->ldap = cldap;
189
+
190
+ rb_iv_set (self, "@args", Qnil);
191
+
192
+ return Qnil;
193
+ }
194
+ #endif /* USE_NSSLDAP_SSLCONN */
195
+
196
+ #if defined(USE_WLDAP32_SSLCONN)
197
+ static VALUE
198
+ rb_wldap32_sslconn_initialize (int argc, VALUE argv[], VALUE self)
199
+ {
200
+ RB_LDAP_DATA *ldapdata;
201
+ LDAP *cldap;
202
+ char *chost;
203
+ int cport;
204
+ int csecure;
205
+ int version;
206
+
207
+ VALUE arg1, arg2, arg3;
208
+
209
+ Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
210
+ if (ldapdata->ldap)
211
+ return Qnil;
212
+
213
+ switch (rb_scan_args (argc, argv, "02", &arg1, &arg2, &arg3))
214
+ {
215
+ case 0:
216
+ chost = ALLOCA_N (char, strlen ("localhost") + 1);
217
+ strcpy (chost, "localhost");
218
+ cport = LDAP_PORT;
219
+ csecure = 1;
220
+ break;
221
+ case 1:
222
+ chost = StringValueCStr (arg1);
223
+ cport = LDAP_PORT;
224
+ csecure = 1;
225
+ break;
226
+ case 2:
227
+ chost = StringValueCStr (arg1);
228
+ cport = NUM2INT (arg2);
229
+ csecure = 1;
230
+ break;
231
+ case 3:
232
+ chost = StringValueCStr (arg1);
233
+ cport = NUM2INT (arg2);
234
+ csecure = (arg3 == Qtrue) ? 1 : 0;
235
+ break;
236
+ default:
237
+ rb_bug ("rb_ldap_conn_new");
238
+ }
239
+
240
+ cldap = ldap_sslinit (chost, cport, csecure);
241
+ ldapdata->ldap = cldap;
242
+
243
+ #if defined(HAVE_LDAP_GET_OPTION) && defined(HAVE_LDAP_SET_OPTION)
244
+ ldap_get_option (cldap, LDAP_OPT_PROTOCOL_VERSION, &version);
245
+ if (version < LDAP_VERSION3)
246
+ {
247
+ version = LDAP_VERSION3;
248
+ ldapdata->err =
249
+ ldap_set_option (cldap, LDAP_OPT_PROTOCOL_VERSION, &version);
250
+ Check_LDAP_Result (ldapdata->err);
251
+ }
252
+ #endif
253
+
254
+ rb_iv_set (self, "@args", Qnil);
255
+
256
+ return Qnil;
257
+ }
258
+
259
+ VALUE
260
+ rb_ldap_sslconn_bind_f (int argc, VALUE argv[], VALUE self,
261
+ VALUE (*rb_ldap_sslconn_bind_func) (int, VALUE[],
262
+ VALUE))
263
+ {
264
+ RB_LDAP_DATA *ldapdata;
265
+
266
+ Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
267
+ if (!ldapdata->ldap)
268
+ {
269
+ if (rb_iv_get (self, "@args") != Qnil)
270
+ {
271
+ rb_ldap_conn_rebind (self);
272
+ GET_LDAP_DATA (self, ldapdata);
273
+ }
274
+ else
275
+ {
276
+ rb_raise (rb_eLDAP_InvalidDataError,
277
+ "The LDAP handler has already unbound.");
278
+ }
279
+ }
280
+
281
+ ldapdata->err = ldap_connect (ldapdata->ldap, NULL);
282
+ Check_LDAP_Result (ldapdata->err);
283
+
284
+ return rb_ldap_sslconn_bind_func (argc, argv, self);
285
+ }
286
+
287
+ /*
288
+ * call-seq:
289
+ * conn.bind(dn=nil, password=nil, method=LDAP::LDAP_AUTH_SIMPLE) => self
290
+ * conn.bind(dn=nil, password=nil, method=LDAP::LDAP_AUTH_SIMPLE)
291
+ * { |conn| } => self
292
+ *
293
+ * Bind an LDAP connection, using the DN, +dn+, the credential, +password+,
294
+ * and the bind method, +method+. If a block is given, +self+ is yielded to
295
+ * the block.
296
+ */
297
+ VALUE
298
+ rb_ldap_sslconn_bind_s (int argc, VALUE argv[], VALUE self)
299
+ {
300
+ return rb_ldap_sslconn_bind_f (argc, argv, self, rb_ldap_conn_bind_s);
301
+ }
302
+
303
+ /*
304
+ * call-seq:
305
+ * conn.simple_bind(dn=nil, password=nil) => self
306
+ * conn.simple_bind(dn=nil, password=nil) { |conn| } => self
307
+ *
308
+ * Bind an LDAP connection, using the DN, +dn+, and the credential, +password+.
309
+ * If a block is given, +self+ is yielded to the block.
310
+ */
311
+ VALUE
312
+ rb_ldap_sslconn_simple_bind_s (int argc, VALUE argv[], VALUE self)
313
+ {
314
+ return rb_ldap_sslconn_bind_f (argc, argv, self,
315
+ rb_ldap_conn_simple_bind_s);
316
+ }
317
+ #endif /* USE_WLDAP32_SSLCONN */
318
+
319
+ /*
320
+ * call-seq:
321
+ * LDAP::SSLConn.new(host='localhost', port=LDAP_PORT,
322
+ * start_tls=false, sctrls=nil, cctrls=nil)
323
+ * => LDAP::SSLConn
324
+ * LDAP::SSLConn.new(host='localhost', port=LDAP_PORT,
325
+ * start_tls=false, sctrls=nil, cctrls=nil) { |conn| }
326
+ * => LDAP::SSLConn
327
+ *
328
+ * Return a new LDAP::SSLConn connection to the server, +host+, on port +port+.
329
+ * If +start_tls+ is *true*, START_TLS will be used to establish the
330
+ * connection, automatically setting the LDAP protocol version to v3 if it is
331
+ * not already set.
332
+ *
333
+ * +sctrls+ is an array of server controls, whilst +cctrls+ is an array of
334
+ * client controls.
335
+ */
336
+ VALUE
337
+ rb_ldap_sslconn_initialize (int argc, VALUE argv[], VALUE self)
338
+ {
339
+ #if defined(USE_OPENLDAP_SSLCONN)
340
+ return rb_openldap_sslconn_initialize (argc, argv, self);
341
+ #elif defined(USE_NSSLDAP_SSLCONN)
342
+ return rb_nssldap_sslconn_initialize (argc, argv, self);
343
+ #elif defined(USE_WLDAP32_SSLCONN)
344
+ return rb_wldap32_sslconn_initialize (argc, argv, self);
345
+ #else
346
+ rb_notimplement ();
347
+ #endif
348
+ }
349
+
350
+ /* :nodoc: */
351
+ VALUE
352
+ rb_ldap_sslconn_s_open (int argc, VALUE argv[], VALUE klass)
353
+ {
354
+ rb_notimplement ();
355
+ }
356
+
357
+ /* Document-class: LDAP::SSLConn
358
+ *
359
+ * Create and manipulate encrypted LDAP connections. LDAP::SSLConn is a
360
+ * subclass of LDAP::Conn and so has access to the same methods, except for
361
+ * LDAP::SSLConn.open, which is not implemented.
362
+ */
363
+ void
364
+ Init_ldap_sslconn ()
365
+ {
366
+ rb_cLDAP_SSLConn =
367
+ rb_define_class_under (rb_mLDAP, "SSLConn", rb_cLDAP_Conn);
368
+ rb_define_singleton_method (rb_cLDAP_SSLConn, "open",
369
+ rb_ldap_sslconn_s_open, -1);
370
+ rb_define_method (rb_cLDAP_SSLConn, "initialize",
371
+ rb_ldap_sslconn_initialize, -1);
372
+ #ifdef USE_WLDAP32_SSLCONN
373
+ rb_define_method (rb_cLDAP_SSLConn, "bind", rb_ldap_sslconn_bind_s, -1);
374
+ rb_define_method (rb_cLDAP_SSLConn, "simple_bind",
375
+ rb_ldap_sslconn_simple_bind_s, -1);
376
+ #endif
377
+ }
data/test/add.rb ADDED
@@ -0,0 +1,31 @@
1
+ # -*- ruby -*-
2
+ # This file is a part of test scripts of LDAP extension module.
3
+
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
7
+
8
+ conn = LDAP::Conn.new($HOST, $PORT)
9
+ conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
10
+ conn.perror("bind")
11
+ entry1 = [
12
+ LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectclass', ['top', 'domain']),
13
+ LDAP.mod(LDAP::LDAP_MOD_ADD, 'o', ['TTSKY.NET']),
14
+ LDAP.mod(LDAP::LDAP_MOD_ADD, 'dc', ['localhost']),
15
+ ]
16
+
17
+ entry2 = [
18
+ LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectclass', ['top', 'person']),
19
+ LDAP.mod(LDAP::LDAP_MOD_ADD, 'cn', ['Takaaki Tateishi']),
20
+ LDAP.mod(LDAP::LDAP_MOD_ADD | LDAP::LDAP_MOD_BVALUES, 'sn', ['ttate','Tateishi', "zero\000zero"]),
21
+ ]
22
+
23
+ begin
24
+ conn.add("dc=localhost, dc=localdomain", entry1)
25
+ conn.add("cn=Takaaki Tateishi, dc=localhost, dc=localdomain", entry2)
26
+ rescue LDAP::ResultError
27
+ conn.perror("add")
28
+ exit
29
+ end
30
+ conn.perror("add")
31
+ }
data/test/add2.rb ADDED
@@ -0,0 +1,31 @@
1
+ # -*- ruby -*-
2
+ # This file is a part of test scripts of LDAP extension module.
3
+
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
7
+
8
+ conn = LDAP::Conn.new($HOST, $PORT)
9
+ conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
10
+ conn.perror("bind")
11
+ entry1 = {
12
+ 'objectclass' => ['top', 'person'],
13
+ 'cn' => ['Tatsuya Kawai'],
14
+ 'sn' => ['kawai'],
15
+ }
16
+
17
+ entry2 = {
18
+ 'objectclass' => ['top', 'person'],
19
+ 'cn' => ['Mio Tanaka'],
20
+ 'sn' => ['mit','mio'],
21
+ }
22
+
23
+ begin
24
+ conn.add("cn=#{entry1['cn'][0]}, dc=localhost, dc=localdomain", entry1)
25
+ conn.add("cn=#{entry2['cn'][0]}, dc=localhost, dc=localdomain", entry2)
26
+ rescue LDAP::ResultError
27
+ conn.perror("add")
28
+ exit
29
+ end
30
+ conn.perror("add")
31
+ }
data/test/add3.rb ADDED
@@ -0,0 +1,33 @@
1
+ # -*- ruby -*-
2
+ # This file is a part of test scripts of LDAP extension module.
3
+
4
+ $test = File.dirname($0)
5
+ require "#{$test}/conf"
6
+ require "./ldap"
7
+
8
+ $KCODE = "UTF8"
9
+
10
+ conn = LDAP::Conn.new($HOST, $PORT)
11
+ conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
12
+ conn.perror("bind")
13
+ entry1 = {
14
+ 'objectclass' => ['top', 'person'],
15
+ 'cn' => ['立石 孝彰'],
16
+ 'sn' => ['孝彰'],
17
+ }
18
+
19
+ entry2 = {
20
+ 'objectclass' => ['top', 'person'],
21
+ 'cn' => ['たていし たかあき'],
22
+ 'sn' => ['たていし','たかあき'],
23
+ }
24
+
25
+ begin
26
+ conn.add("cn=#{entry1['cn'][0]}, dc=localhost, dc=localdomain", entry1)
27
+ conn.add("cn=#{entry2['cn'][0]}, dc=localhost, dc=localdomain", entry2)
28
+ rescue LDAP::ResultError
29
+ conn.perror("add")
30
+ exit
31
+ end
32
+ conn.perror("add")
33
+ }