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

« back to all changes in this revision

Viewing changes to servers/slapd/back-ldap/bind.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-09-07 13:41:10 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090907134110-jsdrvn0atu1fex4m
Tags: upstream-2.4.18
ImportĀ upstreamĀ versionĀ 2.4.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* bind.c - ldap backend bind function */
2
 
/* $OpenLDAP: pkg/ldap/servers/slapd/back-ldap/bind.c,v 1.162.2.22 2009/06/11 21:48:11 quanah Exp $ */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-ldap/bind.c,v 1.162.2.24 2009/09/01 22:50:21 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
5
5
 * Copyright 1999-2009 The OpenLDAP Foundation.
32
32
#define AVL_INTERNAL
33
33
#include "slap.h"
34
34
#include "back-ldap.h"
 
35
#include "lutil.h"
35
36
#undef ldap_debug       /* silence a warning in ldap-int.h */
36
37
#include "../../../libraries/libldap/ldap-int.h"
37
38
 
40
41
#define LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ       "2.16.840.1.113730.3.4.12"
41
42
 
42
43
#if LDAP_BACK_PRINT_CONNTREE > 0
 
44
 
 
45
static const struct {
 
46
        slap_mask_t     f;
 
47
        char            c;
 
48
} flagsmap[] = {
 
49
        { LDAP_BACK_FCONN_ISBOUND,      'B' },
 
50
        { LDAP_BACK_FCONN_ISANON,       'A' },
 
51
        { LDAP_BACK_FCONN_ISPRIV,       'P' },
 
52
        { LDAP_BACK_FCONN_ISTLS,        'T' },
 
53
        { LDAP_BACK_FCONN_BINDING,      'X' },
 
54
        { LDAP_BACK_FCONN_TAINTED,      'E' },
 
55
        { LDAP_BACK_FCONN_ABANDON,      'N' },
 
56
        { LDAP_BACK_FCONN_ISIDASR,      'S' },
 
57
        { LDAP_BACK_FCONN_CACHED,       'C' },
 
58
        { 0,                            '\0' }
 
59
};
 
60
 
 
61
static void
 
62
ldap_back_conn_print( ldapconn_t *lc, const char *avlstr )
 
63
{
 
64
        char buf[ SLAP_TEXT_BUFLEN ];
 
65
        char fbuf[ sizeof("BAPTIENSC") ];
 
66
        int i;
 
67
 
 
68
        ldap_back_conn2str( &lc->lc_base, buf, sizeof( buf ) );
 
69
        for ( i = 0; flagsmap[ i ].c != '\0'; i++ ) {
 
70
                if ( lc->lc_lcflags & flagsmap[i].f ) {
 
71
                        fbuf[i] = flagsmap[i].c;
 
72
 
 
73
                } else {
 
74
                        fbuf[i] = '.';
 
75
                }
 
76
        }
 
77
        fbuf[i] = '\0';
 
78
        
 
79
        fprintf( stderr, "lc=%p %s %s flags=0x%08x (%s)\n",
 
80
                (void *)lc, buf, avlstr, lc->lc_lcflags, fbuf );
 
81
}
 
82
 
43
83
static void
44
84
ldap_back_ravl_print( Avlnode *root, int depth )
45
85
{
57
97
        }
58
98
 
59
99
        lc = root->avl_data;
60
 
        fprintf( stderr, "lc=%p local=\"%s\" conn=%p %s refcnt=%d flags=0x%08x\n",
61
 
                (void *)lc,
62
 
                lc->lc_local_ndn.bv_val ? lc->lc_local_ndn.bv_val : "",
63
 
                (void *)lc->lc_conn,
64
 
                avl_bf2str( root->avl_bf ), lc->lc_refcnt, lc->lc_lcflags );
65
 
        
66
 
        ldap_back_ravl_print( root->avl_left, depth+1 );
 
100
        ldap_back_conn_print( lc, avl_bf2str( root->avl_bf ) );
 
101
 
 
102
        ldap_back_ravl_print( root->avl_left, depth + 1 );
67
103
}
68
104
 
69
105
static char* priv2str[] = {
91
127
 
92
128
                LDAP_TAILQ_FOREACH( lc, &li->li_conn_priv[ c ].lic_priv, lc_q )
93
129
                {
94
 
                        fprintf( stderr, "    [%d] lc=%p local=\"%s\" conn=%p refcnt=%d flags=0x%08x\n",
95
 
                                i,
96
 
                                (void *)lc,
97
 
                                lc->lc_local_ndn.bv_val ? lc->lc_local_ndn.bv_val : "",
98
 
                                (void *)lc->lc_conn, lc->lc_refcnt, lc->lc_lcflags );
 
130
                        fprintf( stderr, "    [%d] ", i );
 
131
                        ldap_back_conn_print( lc, "" );
99
132
                        i++;
100
133
                }
101
134
        }
303
336
                if ( LDAP_BACK_SINGLECONN( li ) ) {
304
337
                        while ( ( tmplc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc, ldap_back_conn_cmp ) ) != NULL )
305
338
                        {
 
339
                                assert( !LDAP_BACK_PCONN_ISPRIV( lc ) );
306
340
                                Debug( LDAP_DEBUG_TRACE,
307
 
                                        "=>ldap_back_bind: destroying conn %ld (refcnt=%u)\n",
308
 
                                        LDAP_BACK_PCONN_ID( lc ), lc->lc_refcnt, 0 );
 
341
                                        "=>ldap_back_bind: destroying conn %lu (refcnt=%u)\n",
 
342
                                        lc->lc_conn->c_connid, lc->lc_refcnt, 0 );
309
343
 
310
344
                                if ( tmplc->lc_refcnt != 0 ) {
311
345
                                        /* taint it */
631
665
        LDAP            *ld = NULL;
632
666
#ifdef HAVE_TLS
633
667
        int             is_tls = op->o_conn->c_is_tls;
634
 
        time_t          lc_time = (time_t)(-1);
 
668
        time_t          lctime = (time_t)(-1);
635
669
        slap_bindconf *sb;
636
670
#endif /* HAVE_TLS */
637
671
 
704
738
 
705
739
        } else if ( li->li_idle_timeout ) {
706
740
                /* only touch when activity actually took place... */
707
 
                lc_time = op->o_time;
 
741
                lctime = op->o_time;
708
742
        }
709
743
#endif /* HAVE_TLS */
710
744
 
716
750
        } else {
717
751
                LDAP_BACK_CONN_ISTLS_CLEAR( lc );
718
752
        }
719
 
        if ( lc_time != (time_t)(-1) ) {
720
 
                lc->lc_time = lc_time;
 
753
        if ( lctime != (time_t)(-1) ) {
 
754
                lc->lc_time = lctime;
721
755
        }
722
756
#endif /* HAVE_TLS */
723
757
 
750
784
{
751
785
        ldapinfo_t      *li = (ldapinfo_t *)op->o_bd->be_private;
752
786
        ldapconn_t      *lc = NULL,
753
 
                        lc_curr = { 0 };
 
787
                        lc_curr = {{ 0 }};
754
788
        int             refcnt = 1,
755
789
                        lookupconn = !( sendok & LDAP_BACK_BINDING );
756
790
 
2714
2748
 
2715
2749
        return 0;
2716
2750
}
 
2751
 
 
2752
int
 
2753
ldap_back_conn2str( const ldapconn_base_t *lc, char *buf, ber_len_t buflen )
 
2754
{
 
2755
        char tbuf[ SLAP_TEXT_BUFLEN ];
 
2756
        char *ptr = buf, *end = buf + buflen;
 
2757
        int len;
 
2758
 
 
2759
        if ( ptr + sizeof("conn=") > end ) return -1;
 
2760
        ptr = lutil_strcopy( ptr, "conn=" );
 
2761
 
 
2762
        len = ldap_back_connid2str( lc, ptr, (ber_len_t)(end - ptr) );
 
2763
        ptr += len;
 
2764
        if ( ptr >= end ) return -1;
 
2765
 
 
2766
        if ( !BER_BVISNULL( &lc->lcb_local_ndn ) ) {
 
2767
                if ( ptr + sizeof(" DN=\"\"") + lc->lcb_local_ndn.bv_len > end ) return -1;
 
2768
                ptr = lutil_strcopy( ptr, " DN=\"" );
 
2769
                ptr = lutil_strncopy( ptr, lc->lcb_local_ndn.bv_val, lc->lcb_local_ndn.bv_len );
 
2770
                *ptr++ = '"';
 
2771
        }
 
2772
 
 
2773
        if ( lc->lcb_create_time != 0 ) {
 
2774
                len = snprintf( tbuf, sizeof(tbuf), "%ld", lc->lcb_create_time );
 
2775
                if ( ptr + sizeof(" created=") + len >= end ) return -1;
 
2776
                ptr = lutil_strcopy( ptr, " created=" );
 
2777
                ptr = lutil_strcopy( ptr, tbuf );
 
2778
        }
 
2779
 
 
2780
        if ( lc->lcb_time != 0 ) {
 
2781
                len = snprintf( tbuf, sizeof(tbuf), "%ld", lc->lcb_time );
 
2782
                if ( ptr + sizeof(" modified=") + len >= end ) return -1;
 
2783
                ptr = lutil_strcopy( ptr, " modified=" );
 
2784
                ptr = lutil_strcopy( ptr, tbuf );
 
2785
        }
 
2786
 
 
2787
        len = snprintf( tbuf, sizeof(tbuf), "%u", lc->lcb_refcnt );
 
2788
        if ( ptr + sizeof(" refcnt=") + len >= end ) return -1;
 
2789
        ptr = lutil_strcopy( ptr, " refcnt=" );
 
2790
        ptr = lutil_strcopy( ptr, tbuf );
 
2791
 
 
2792
        return ptr - buf;
 
2793
}
 
2794
 
 
2795
int
 
2796
ldap_back_connid2str( const ldapconn_base_t *lc, char *buf, ber_len_t buflen )
 
2797
{
 
2798
        static struct berval conns[] = {
 
2799
                BER_BVC("ROOTDN"),
 
2800
                BER_BVC("ROOTDN-TLS"),
 
2801
                BER_BVC("ANON"),
 
2802
                BER_BVC("ANON-TLS"),
 
2803
                BER_BVC("BIND"),
 
2804
                BER_BVC("BIND-TLS"),
 
2805
                BER_BVNULL
 
2806
        };
 
2807
 
 
2808
        int len = 0;
 
2809
 
 
2810
        if ( LDAP_BACK_PCONN_ISPRIV( (const ldapconn_t *)lc ) ) {
 
2811
                long cid;
 
2812
                struct berval *bv;
 
2813
 
 
2814
                cid = (long)lc->lcb_conn;
 
2815
                assert( cid >= LDAP_BACK_PCONN_FIRST && cid < LDAP_BACK_PCONN_LAST );
 
2816
 
 
2817
                bv = &conns[ cid ];
 
2818
 
 
2819
                if ( bv->bv_len >= buflen ) {
 
2820
                        return bv->bv_len + 1;
 
2821
                }
 
2822
 
 
2823
                len = bv->bv_len;
 
2824
                lutil_strncopy( buf, bv->bv_val, bv->bv_len + 1 );
 
2825
 
 
2826
        } else {
 
2827
                len = snprintf( buf, buflen, "%lu", lc->lcb_conn->c_connid );
 
2828
        }
 
2829
 
 
2830
        return len;
 
2831
}