~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to libraries/libldap/cyrus.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Steve Langasek, Mathias Gug
  • Date: 2009-02-18 18:44:00 UTC
  • mfrom: (1.1.2 upstream) (0.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090218184400-zw4mjse9eywt5566
Tags: 2.4.14-0ubuntu1
[ Steve Langasek ]
* New upstream version
  - Fixes a bug with the pcache overlay not returning cached entries
    (closes: #497697)
  - Update evolution-ntlm patch to apply to current Makefiles.
  - (tentatively) drop gnutls-ciphers, since this bug was reported to be
    fixed upstream in 2.4.8.  The fix applied in 2.4.8 didn't match the
    patch from the bug report, so this should be watched for regressions.
* Build against db4.7 instead of db4.2 at last!  Closes: #421946.
* Build with --disable-ndb, to avoid a misbuild when libmysqlclient is
  installed in the build environment.
* New patch, no-crlcheck-for-gnutls, to fix a build failure when using
  --with-tls=gnutls.

[ Mathias Gug ]
* Merge from debian unstable, remaining changes:
  - debian/apparmor-profile: add AppArmor profile
  - debian/slapd.postinst: Reload AA profile on configuration
  - updated debian/slapd.README.Debian for note on AppArmor
  - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6
  - debian/control: Conflicts with apparmor-profiles << 2.1+1075-0ubuntu4
    to make sure that if earlier version of apparmour-profiles gets
    installed it won't overwrite our profile.
  - Modify Maintainer value to match the DebianMaintainerField
    speficication.
  - follow ApparmorProfileMigration and force apparmor compalin mode on 
    some upgrades (LP: #203529)
  - debian/slapd.dirs: add etc/apparmor.d/force-complain
  - debian/slapd.preinst: create symlink for force-complain on pre-feisty
    upgrades, upgrades where apparmor-profiles profile is unchanged (ie
    non-enforcing) and upgrades where apparmor profile does not exist.
  - debian/slapd.postrm: remove symlink in force-complain/ on purge
  - debian/patches/fix-ucred-libc due to changes how newer glibc handle
    the ucred struct now.
  - debian/control:
    - Build-depend on libltdl7-dev rather then libltdl3-dev.
  - debian/patches/autogen.sh:
    - Call libtoolize with the --install option to install config.{guess,sub}
      files.
  - Don't use local statement in config script as it fails if /bin/sh
    points to bash (LP: #286063).
  - Disable the testsuite on hppa. Allows building of packages on this
    architecture again, once this package is in the archive.
    LP: #288908.
  - debian/slapd.postinst, debian/slapd.script-common: set correct ownership
    and permissions on /var/lib/ldap, /etc/ldap/slapd.d (group readable) and
    /var/run/slapd (world readable). (LP: #257667).
  - debian/patches/nssov-build, debian/rules: 
    Build and package the nss overlay.
    debian/schema/misc.ldif: add ldif file for the misc schema, which defines
    rfc822MailMember (required by the nss overlay).
  - debian/{control,rules}: enable PIE hardening
  - Use cn=config as the default configuration backend instead of 
    slapd.conf. Migrate slapd.conf  file to /etc/ldap/slapd.d/ on upgrade
    asking the end user to enter a new password to control the access to the
    cn=config tree.
* debian/patches/corrupt-contextCSN: The contextCSN can get corrupted at
  times. (ITS: #5947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenLDAP: pkg/ldap/libraries/libldap/cyrus.c,v 1.133.2.8 2008/02/11 23:26:41 kurt Exp $ */
 
1
/* $OpenLDAP: pkg/ldap/libraries/libldap/cyrus.c,v 1.133.2.13 2009/02/08 06:06:04 quanah Exp $ */
2
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
3
 *
4
 
 * Copyright 1998-2008 The OpenLDAP Foundation.
 
4
 * Copyright 1998-2009 The OpenLDAP Foundation.
5
5
 * All rights reserved.
6
6
 *
7
7
 * Redistribution and use in source and binary forms, with or without
133
133
        return -1;
134
134
}
135
135
 
136
 
/*
137
 
 * SASL encryption support for LBER Sockbufs
138
 
 */
139
 
 
140
 
struct sb_sasl_data {
141
 
        sasl_conn_t             *sasl_context;
142
 
        unsigned                *sasl_maxbuf;
143
 
        Sockbuf_Buf             sec_buf_in;
144
 
        Sockbuf_Buf             buf_in;
145
 
        Sockbuf_Buf             buf_out;
146
 
};
147
 
 
148
 
static int
149
 
sb_sasl_setup( Sockbuf_IO_Desc *sbiod, void *arg )
150
 
{
151
 
        struct sb_sasl_data     *p;
152
 
 
153
 
        assert( sbiod != NULL );
154
 
 
155
 
        p = LBER_MALLOC( sizeof( *p ) );
156
 
        if ( p == NULL )
157
 
                return -1;
158
 
        p->sasl_context = (sasl_conn_t *)arg;
159
 
        ber_pvt_sb_buf_init( &p->sec_buf_in );
160
 
        ber_pvt_sb_buf_init( &p->buf_in );
161
 
        ber_pvt_sb_buf_init( &p->buf_out );
162
 
        if ( ber_pvt_sb_grow_buffer( &p->sec_buf_in, SASL_MIN_BUFF_SIZE ) < 0 ) {
163
 
                LBER_FREE( p );
164
 
                sock_errset(ENOMEM);
165
 
                return -1;
166
 
        }
167
 
        sasl_getprop( p->sasl_context, SASL_MAXOUTBUF,
168
 
                (SASL_CONST void **)(char *) &p->sasl_maxbuf );
169
 
            
170
 
        sbiod->sbiod_pvt = p;
171
 
 
172
 
        return 0;
173
 
}
174
 
 
175
 
static int
176
 
sb_sasl_remove( Sockbuf_IO_Desc *sbiod )
177
 
{
178
 
        struct sb_sasl_data     *p;
179
 
 
180
 
        assert( sbiod != NULL );
181
 
        
182
 
        p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
 
136
static void
 
137
sb_sasl_cyrus_init(
 
138
        struct sb_sasl_generic_data *p,
 
139
        ber_len_t *min_send,
 
140
        ber_len_t *max_send,
 
141
        ber_len_t *max_recv)
 
142
{
 
143
        sasl_conn_t *sasl_context = (sasl_conn_t *)p->ops_private;
 
144
        ber_len_t maxbuf;
 
145
 
 
146
        sasl_getprop( sasl_context, SASL_MAXOUTBUF,
 
147
                      (SASL_CONST void **)(char *) &maxbuf );
 
148
 
 
149
        *min_send = SASL_MIN_BUFF_SIZE;
 
150
        *max_send = maxbuf;
 
151
        *max_recv = SASL_MAX_BUFF_SIZE;
 
152
}
 
153
 
 
154
static ber_int_t
 
155
sb_sasl_cyrus_encode(
 
156
        struct sb_sasl_generic_data *p,
 
157
        unsigned char *buf,
 
158
        ber_len_t len,
 
159
        Sockbuf_Buf *dst)
 
160
{
 
161
        sasl_conn_t *sasl_context = (sasl_conn_t *)p->ops_private;
 
162
        ber_int_t ret;
 
163
        unsigned tmpsize = dst->buf_size;
 
164
 
 
165
        ret = sasl_encode( sasl_context, (char *)buf, len,
 
166
                           (SASL_CONST char **)&dst->buf_base,
 
167
                           &tmpsize );
 
168
 
 
169
        dst->buf_size = tmpsize;
 
170
        dst->buf_end = dst->buf_size;
 
171
 
 
172
        if ( ret != SASL_OK ) {
 
173
                ber_log_printf( LDAP_DEBUG_ANY, p->sbiod->sbiod_sb->sb_debug,
 
174
                                "sb_sasl_cyrus_encode: failed to encode packet: %s\n",
 
175
                                sasl_errstring( ret, NULL, NULL ) );
 
176
                return -1;
 
177
        }
 
178
 
 
179
        return 0;
 
180
}
 
181
 
 
182
static ber_int_t
 
183
sb_sasl_cyrus_decode(
 
184
        struct sb_sasl_generic_data *p,
 
185
        const Sockbuf_Buf *src,
 
186
        Sockbuf_Buf *dst)
 
187
{
 
188
        sasl_conn_t *sasl_context = (sasl_conn_t *)p->ops_private;
 
189
        ber_int_t ret;
 
190
        unsigned tmpsize = dst->buf_size;
 
191
 
 
192
        ret = sasl_decode( sasl_context,
 
193
                           src->buf_base, src->buf_end,
 
194
                           (SASL_CONST char **)&dst->buf_base,
 
195
                           (unsigned *)&tmpsize );
 
196
 
 
197
 
 
198
        dst->buf_size = tmpsize;
 
199
        dst->buf_end = dst->buf_size;
 
200
 
 
201
        if ( ret != SASL_OK ) {
 
202
                ber_log_printf( LDAP_DEBUG_ANY, p->sbiod->sbiod_sb->sb_debug,
 
203
                                "sb_sasl_cyrus_decode: failed to decode packet: %s\n",
 
204
                                sasl_errstring( ret, NULL, NULL ) );
 
205
                return -1;
 
206
        }
 
207
 
 
208
        return 0;
 
209
}
 
210
 
 
211
static void
 
212
sb_sasl_cyrus_reset_buf(
 
213
        struct sb_sasl_generic_data *p,
 
214
        Sockbuf_Buf *buf)
 
215
{
 
216
#if SASL_VERSION_MAJOR >= 2
 
217
        ber_pvt_sb_buf_init( buf );
 
218
#else
 
219
        ber_pvt_sb_buf_destroy( buf );
 
220
#endif
 
221
}
 
222
 
 
223
static void
 
224
sb_sasl_cyrus_fini(
 
225
        struct sb_sasl_generic_data *p)
 
226
{
183
227
#if SASL_VERSION_MAJOR >= 2
184
228
        /*
185
229
         * SASLv2 encode/decode buffers are managed by
188
232
        p->buf_in.buf_base = NULL;
189
233
        p->buf_out.buf_base = NULL;
190
234
#endif
191
 
        ber_pvt_sb_buf_destroy( &p->sec_buf_in );
192
 
        ber_pvt_sb_buf_destroy( &p->buf_in );
193
 
        ber_pvt_sb_buf_destroy( &p->buf_out );
194
 
        LBER_FREE( p );
195
 
        sbiod->sbiod_pvt = NULL;
196
 
        return 0;
197
 
}
198
 
 
199
 
static ber_len_t
200
 
sb_sasl_pkt_length( const unsigned char *buf, int debuglevel )
201
 
{
202
 
        ber_len_t               size;
203
 
 
204
 
        assert( buf != NULL );
205
 
 
206
 
        size = buf[0] << 24
207
 
                | buf[1] << 16
208
 
                | buf[2] << 8
209
 
                | buf[3];
210
 
 
211
 
        if ( size > SASL_MAX_BUFF_SIZE ) {
212
 
                /* somebody is trying to mess me up. */
213
 
                ber_log_printf( LDAP_DEBUG_ANY, debuglevel,
214
 
                        "sb_sasl_pkt_length: received illegal packet length "
215
 
                        "of %lu bytes\n", (unsigned long)size );      
216
 
                size = 16; /* this should lead to an error. */
217
 
        }
218
 
 
219
 
        return size + 4; /* include the size !!! */
220
 
}
221
 
 
222
 
/* Drop a processed packet from the input buffer */
223
 
static void
224
 
sb_sasl_drop_packet ( Sockbuf_Buf *sec_buf_in, int debuglevel )
225
 
{
226
 
        ber_slen_t                      len;
227
 
 
228
 
        len = sec_buf_in->buf_ptr - sec_buf_in->buf_end;
229
 
        if ( len > 0 )
230
 
                AC_MEMCPY( sec_buf_in->buf_base, sec_buf_in->buf_base +
231
 
                        sec_buf_in->buf_end, len );
232
 
   
233
 
        if ( len >= 4 ) {
234
 
                sec_buf_in->buf_end = sb_sasl_pkt_length(
235
 
                        (unsigned char *) sec_buf_in->buf_base, debuglevel);
236
 
        }
237
 
        else {
238
 
                sec_buf_in->buf_end = 0;
239
 
        }
240
 
        sec_buf_in->buf_ptr = len;
241
 
}
242
 
 
243
 
static ber_slen_t
244
 
sb_sasl_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
245
 
{
246
 
        struct sb_sasl_data     *p;
247
 
        ber_slen_t              ret, bufptr;
248
 
   
249
 
        assert( sbiod != NULL );
250
 
        assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
251
 
 
252
 
        p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
253
 
 
254
 
        /* Are there anything left in the buffer? */
255
 
        ret = ber_pvt_sb_copy_out( &p->buf_in, buf, len );
256
 
        bufptr = ret;
257
 
        len -= ret;
258
 
 
259
 
        if ( len == 0 )
260
 
                return bufptr;
261
 
 
262
 
#if SASL_VERSION_MAJOR >= 2
263
 
        ber_pvt_sb_buf_init( &p->buf_in );
264
 
#else
265
 
        ber_pvt_sb_buf_destroy( &p->buf_in );
266
 
#endif
267
 
 
268
 
        /* Read the length of the packet */
269
 
        while ( p->sec_buf_in.buf_ptr < 4 ) {
270
 
                ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base +
271
 
                        p->sec_buf_in.buf_ptr,
272
 
                        4 - p->sec_buf_in.buf_ptr );
273
 
#ifdef EINTR
274
 
                if ( ( ret < 0 ) && ( errno == EINTR ) )
275
 
                        continue;
276
 
#endif
277
 
                if ( ret <= 0 )
278
 
                        return bufptr ? bufptr : ret;
279
 
 
280
 
                p->sec_buf_in.buf_ptr += ret;
281
 
        }
282
 
 
283
 
        /* The new packet always starts at p->sec_buf_in.buf_base */
284
 
        ret = sb_sasl_pkt_length( (unsigned char *) p->sec_buf_in.buf_base,
285
 
                sbiod->sbiod_sb->sb_debug );
286
 
 
287
 
        /* Grow the packet buffer if neccessary */
288
 
        if ( ( p->sec_buf_in.buf_size < (ber_len_t) ret ) && 
289
 
                ber_pvt_sb_grow_buffer( &p->sec_buf_in, ret ) < 0 )
290
 
        {
291
 
                sock_errset(ENOMEM);
292
 
                return -1;
293
 
        }
294
 
        p->sec_buf_in.buf_end = ret;
295
 
 
296
 
        /* Did we read the whole encrypted packet? */
297
 
        while ( p->sec_buf_in.buf_ptr < p->sec_buf_in.buf_end ) {
298
 
                /* No, we have got only a part of it */
299
 
                ret = p->sec_buf_in.buf_end - p->sec_buf_in.buf_ptr;
300
 
 
301
 
                ret = LBER_SBIOD_READ_NEXT( sbiod, p->sec_buf_in.buf_base +
302
 
                        p->sec_buf_in.buf_ptr, ret );
303
 
#ifdef EINTR
304
 
                if ( ( ret < 0 ) && ( errno == EINTR ) )
305
 
                        continue;
306
 
#endif
307
 
                if ( ret <= 0 )
308
 
                        return bufptr ? bufptr : ret;
309
 
 
310
 
                p->sec_buf_in.buf_ptr += ret;
311
 
        }
312
 
 
313
 
        /* Decode the packet */
314
 
        {
315
 
                unsigned tmpsize = p->buf_in.buf_end;
316
 
                ret = sasl_decode( p->sasl_context, p->sec_buf_in.buf_base,
317
 
                        p->sec_buf_in.buf_end,
318
 
                        (SASL_CONST char **)&p->buf_in.buf_base,
319
 
                        (unsigned *)&tmpsize );
320
 
                p->buf_in.buf_end = tmpsize;
321
 
        }
322
 
 
323
 
        /* Drop the packet from the input buffer */
324
 
        sb_sasl_drop_packet( &p->sec_buf_in, sbiod->sbiod_sb->sb_debug );
325
 
 
326
 
        if ( ret != SASL_OK ) {
327
 
                ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
328
 
                        "sb_sasl_read: failed to decode packet: %s\n",
329
 
                        sasl_errstring( ret, NULL, NULL ) );
330
 
                sock_errset(EIO);
331
 
                return -1;
332
 
        }
333
 
        
334
 
        p->buf_in.buf_size = p->buf_in.buf_end;
335
 
 
336
 
        bufptr += ber_pvt_sb_copy_out( &p->buf_in, (char*) buf + bufptr, len );
337
 
 
338
 
        return bufptr;
339
 
}
340
 
 
341
 
static ber_slen_t
342
 
sb_sasl_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
343
 
{
344
 
        struct sb_sasl_data     *p;
345
 
        int                     ret;
346
 
 
347
 
        assert( sbiod != NULL );
348
 
        assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
349
 
 
350
 
        p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
351
 
 
352
 
        /* Are there anything left in the buffer? */
353
 
        if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
354
 
                ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
355
 
                if ( ret < 0 ) return ret;
356
 
 
357
 
                /* Still have something left?? */
358
 
                if ( p->buf_out.buf_ptr != p->buf_out.buf_end ) {
359
 
                        sock_errset(EAGAIN);
360
 
                        return -1;
361
 
                }
362
 
        }
363
 
 
364
 
        /* now encode the next packet. */
365
 
#if SASL_VERSION_MAJOR >= 2
366
 
        ber_pvt_sb_buf_init( &p->buf_out );
367
 
#else
368
 
        ber_pvt_sb_buf_destroy( &p->buf_out );
369
 
#endif
370
 
        if ( len > *p->sasl_maxbuf - 100 ) {
371
 
                len = *p->sasl_maxbuf - 100;    /* For safety margin */
372
 
        }
373
 
 
374
 
        {
375
 
                unsigned tmpsize = p->buf_out.buf_size;
376
 
                ret = sasl_encode( p->sasl_context, buf, len,
377
 
                        (SASL_CONST char **)&p->buf_out.buf_base,
378
 
                        &tmpsize );
379
 
                p->buf_out.buf_size = tmpsize;
380
 
        }
381
 
 
382
 
        if ( ret != SASL_OK ) {
383
 
                ber_log_printf( LDAP_DEBUG_ANY, sbiod->sbiod_sb->sb_debug,
384
 
                        "sb_sasl_write: failed to encode packet: %s\n",
385
 
                        sasl_errstring( ret, NULL, NULL ) );
386
 
                sock_errset(EIO);
387
 
                return -1;
388
 
        }
389
 
        p->buf_out.buf_end = p->buf_out.buf_size;
390
 
 
391
 
        ret = ber_pvt_sb_do_write( sbiod, &p->buf_out );
392
 
 
393
 
        /* return number of bytes encoded, not written, to ensure
394
 
         * no byte is encoded twice (even if only sent once).
395
 
         */
396
 
        return len;
397
 
}
398
 
 
399
 
static int
400
 
sb_sasl_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
401
 
{
402
 
        struct sb_sasl_data     *p;
403
 
 
404
 
        p = (struct sb_sasl_data *)sbiod->sbiod_pvt;
405
 
 
406
 
        if ( opt == LBER_SB_OPT_DATA_READY ) {
407
 
                if ( p->buf_in.buf_ptr != p->buf_in.buf_end ) return 1;
408
 
        }
409
 
        
410
 
        return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
411
 
}
412
 
 
413
 
Sockbuf_IO ldap_pvt_sockbuf_io_sasl = {
414
 
        sb_sasl_setup,          /* sbi_setup */
415
 
        sb_sasl_remove,         /* sbi_remove */
416
 
        sb_sasl_ctrl,           /* sbi_ctrl */
417
 
        sb_sasl_read,           /* sbi_read */
418
 
        sb_sasl_write,          /* sbi_write */
419
 
        NULL                    /* sbi_close */
420
 
};
 
235
}
 
236
 
 
237
static const struct sb_sasl_generic_ops sb_sasl_cyrus_ops = {
 
238
        sb_sasl_cyrus_init,
 
239
        sb_sasl_cyrus_encode,
 
240
        sb_sasl_cyrus_decode,
 
241
        sb_sasl_cyrus_reset_buf,
 
242
        sb_sasl_cyrus_fini
 
243
 };
421
244
 
422
245
int ldap_pvt_sasl_install( Sockbuf *sb, void *ctx_arg )
423
246
{
424
 
        Debug( LDAP_DEBUG_TRACE, "ldap_pvt_sasl_install\n",
425
 
                0, 0, 0 );
426
 
 
427
 
        /* don't install the stuff unless security has been negotiated */
428
 
 
429
 
        if ( !ber_sockbuf_ctrl( sb, LBER_SB_OPT_HAS_IO,
430
 
                        &ldap_pvt_sockbuf_io_sasl ) )
431
 
        {
432
 
#ifdef LDAP_DEBUG
433
 
                ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
434
 
                        LBER_SBIOD_LEVEL_APPLICATION, (void *)"sasl_" );
435
 
#endif
436
 
                ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_sasl,
437
 
                        LBER_SBIOD_LEVEL_APPLICATION, ctx_arg );
438
 
        }
439
 
 
440
 
        return LDAP_SUCCESS;
 
247
        struct sb_sasl_generic_install install_arg;
 
248
 
 
249
        install_arg.ops         = &sb_sasl_cyrus_ops;
 
250
        install_arg.ops_private = ctx_arg;
 
251
 
 
252
        return ldap_pvt_sasl_generic_install( sb, &install_arg );
441
253
}
442
254
 
443
255
void ldap_pvt_sasl_remove( Sockbuf *sb )
444
256
{
445
 
        ber_sockbuf_remove_io( sb, &ldap_pvt_sockbuf_io_sasl,
446
 
                LBER_SBIOD_LEVEL_APPLICATION );
447
 
#ifdef LDAP_DEBUG
448
 
        ber_sockbuf_remove_io( sb, &ber_sockbuf_io_debug,
449
 
                LBER_SBIOD_LEVEL_APPLICATION );
450
 
#endif
 
257
        ldap_pvt_sasl_generic_remove( sb );
451
258
}
452
259
 
453
260
static int
639
446
        }
640
447
 
641
448
        {
642
 
                char *saslhost = ldap_host_connected_to( ld->ld_defconn->lconn_sb,
 
449
                char *saslhost;
 
450
                int nocanon = (int)LDAP_BOOL_GET( &ld->ld_options,
 
451
                        LDAP_BOOL_SASL_NOCANON );
 
452
 
 
453
                /* If we don't need to canonicalize just use the host
 
454
                 * from the LDAP URI.
 
455
                 */
 
456
                if ( nocanon )
 
457
                        saslhost = ld->ld_defconn->lconn_server->lud_host;
 
458
                else 
 
459
                        saslhost = ldap_host_connected_to( ld->ld_defconn->lconn_sb,
643
460
                        "localhost" );
644
461
                rc = ldap_int_sasl_open( ld, ld->ld_defconn, saslhost );
645
 
                LDAP_FREE( saslhost );
 
462
                if ( !nocanon )
 
463
                        LDAP_FREE( saslhost );
646
464
        }
647
465
 
648
466
        if ( rc != LDAP_SUCCESS ) return rc;
649
467
 
650
468
        ctx = ld->ld_defconn->lconn_sasl_authctx;
651
469
 
 
470
#ifdef HAVE_TLS
652
471
        /* Check for TLS */
653
472
        ssl = ldap_pvt_tls_sb_ctx( ld->ld_defconn->lconn_sb );
654
473
        if ( ssl ) {
662
481
                (void) ldap_int_sasl_external( ld, ld->ld_defconn, authid.bv_val, fac );
663
482
                LDAP_FREE( authid.bv_val );
664
483
        }
 
484
#endif
665
485
 
666
486
#if !defined(_WIN32)
667
487
        /* Check for local */
749
569
                                /* and server provided us with data? */
750
570
                                Debug( LDAP_DEBUG_TRACE,
751
571
                                        "ldap_int_sasl_bind: rc=%d sasl=%d len=%ld\n",
752
 
                                        rc, saslrc, scred ? scred->bv_len : -1 );
 
572
                                        rc, saslrc, scred ? (long) scred->bv_len : -1L );
753
573
                                ber_bvfree( scred );
754
574
                                scred = NULL;
755
575
                        }
1033
853
        const char *in,
1034
854
        sasl_security_properties_t *secprops )
1035
855
{
1036
 
        int i, j, l;
 
856
        unsigned i, j, l;
1037
857
        char **props;
1038
858
        unsigned sflags = 0;
1039
859
        int got_sflags = 0;
1123
943
int
1124
944
ldap_int_sasl_get_option( LDAP *ld, int option, void *arg )
1125
945
{
 
946
        if ( option == LDAP_OPT_X_SASL_MECHLIST ) {
 
947
                if ( ldap_int_sasl_init() )
 
948
                        return -1;
 
949
                *(char ***)arg = (char **)sasl_global_listmech();
 
950
                return 0;
 
951
        }
 
952
 
1126
953
        if ( ld == NULL )
1127
954
                return -1;
1128
955
 
1182
1009
                case LDAP_OPT_X_SASL_MAXBUFSIZE:
1183
1010
                        *(ber_len_t *)arg = ld->ld_options.ldo_sasl_secprops.maxbufsize;
1184
1011
                        break;
 
1012
                case LDAP_OPT_X_SASL_NOCANON:
 
1013
                        *(int *)arg = (int) LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
 
1014
                        break;
1185
1015
 
1186
1016
                case LDAP_OPT_X_SASL_SECPROPS:
1187
1017
                        /* this option is write only */
1196
1026
int
1197
1027
ldap_int_sasl_set_option( LDAP *ld, int option, void *arg )
1198
1028
{
1199
 
        if ( ld == NULL || arg == NULL )
 
1029
        if ( ld == NULL )
 
1030
                return -1;
 
1031
 
 
1032
        if ( arg == NULL && option != LDAP_OPT_X_SASL_NOCANON )
1200
1033
                return -1;
1201
1034
 
1202
1035
        switch ( option ) {
1249
1082
        case LDAP_OPT_X_SASL_MAXBUFSIZE:
1250
1083
                ld->ld_options.ldo_sasl_secprops.maxbufsize = *(ber_len_t *)arg;
1251
1084
                break;
 
1085
        case LDAP_OPT_X_SASL_NOCANON:
 
1086
                if ( arg == LDAP_OPT_OFF ) {
 
1087
                        LDAP_BOOL_CLR(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
 
1088
                } else {
 
1089
                        LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_SASL_NOCANON );
 
1090
                }
 
1091
                break;
1252
1092
 
1253
1093
        case LDAP_OPT_X_SASL_SECPROPS: {
1254
1094
                int sc;