1 /* bind.c - decode an ldap bind operation and pass it to a backend db */
4 * Copyright (c) 1995 Regents of the University of Michigan.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that this notice is preserved and that due credit is given
9 * to the University of Michigan at Ann Arbor. The name of the University
10 * may not be used to endorse or promote products derived from this
11 * software without specific prior written permission. This software
12 * is provided ``as is'' without express or implied warranty.
17 #include <sys/types.h>
18 #include <sys/socket.h>
21 extern Backend *select_backend();
23 extern char *default_referral;
31 BerElement *ber = op->o_ber;
32 int version, method, len, rc;
37 Debug( LDAP_DEBUG_TRACE, "do_bind\n", 0, 0, 0 );
40 * Parse the bind request. It looks like this:
42 * BindRequest ::= SEQUENCE {
43 * version INTEGER, -- version
44 * name DistinguishedName, -- dn
45 * authentication CHOICE {
46 * simple [0] OCTET STRING -- passwd
47 * krbv42ldap [1] OCTET STRING
48 * krbv42dsa [1] OCTET STRING
55 * in version 3.0 there is an extra SEQUENCE tag after the
56 * BindRequest SEQUENCE tag.
61 unsigned long tlen, ttag;
64 ttag = ber_skip_tag( &tber, &tlen );
65 if ( ber_peek_tag( &tber, &tlen ) == LBER_SEQUENCE ) {
66 Debug( LDAP_DEBUG_ANY, "version 3.0 detected\n", 0, 0, 0 );
68 rc = ber_scanf(ber, "{{iato}}", &version, &dn, &method, &cred);
70 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
74 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
76 if ( rc == LBER_ERROR ) {
77 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
78 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
83 if ( conn->c_version == 30 ) {
85 case LDAP_AUTH_SIMPLE_30:
86 method = LDAP_AUTH_SIMPLE;
89 case LDAP_AUTH_KRBV41_30:
90 method = LDAP_AUTH_KRBV41;
92 case LDAP_AUTH_KRBV42_30:
93 method = LDAP_AUTH_KRBV42;
101 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d BIND dn=\"%s\" method=%d\n",
102 conn->c_connid, op->o_opid, dn, method, 0 );
104 if ( version != LDAP_VERSION2 ) {
108 if ( cred.bv_val != NULL ) {
112 Debug( LDAP_DEBUG_ANY, "unknown version %d\n", version, 0, 0 );
113 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
114 "version not supported" );
118 Debug( LDAP_DEBUG_TRACE, "do_bind: version %d dn (%s) method %d\n",
119 version, dn, method );
121 /* accept null binds */
122 if ( dn == NULL || *dn == '\0' ) {
126 if ( cred.bv_val != NULL ) {
130 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
135 * We could be serving multiple database backends. Select the
136 * appropriate one, or send a referral to our "referral server"
137 * if we don't hold it.
140 if ( (be = select_backend( dn )) == NULL ) {
142 if ( cred.bv_val != NULL ) {
145 if ( cred.bv_len == 0 ) {
146 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
148 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
154 if ( be->be_bind != NULL ) {
155 if ( (*be->be_bind)( be, conn, op, dn, method, &cred ) == 0 ) {
156 pthread_mutex_lock( &conn->c_dnmutex );
157 if ( conn->c_dn != NULL ) {
160 conn->c_dn = strdup( dn );
161 pthread_mutex_unlock( &conn->c_dnmutex );
163 /* send this here to avoid a race condition */
164 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
167 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
168 "Function not implemented" );
172 if ( cred.bv_val != NULL ) {