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.
19 #include <ac/string.h>
20 #include <ac/socket.h>
24 extern Backend *select_backend();
26 extern char *default_referral;
34 BerElement *ber = op->o_ber;
35 int version, method, len, rc;
40 Debug( LDAP_DEBUG_TRACE, "do_bind\n", 0, 0, 0 );
43 * Parse the bind request. It looks like this:
45 * BindRequest ::= SEQUENCE {
46 * version INTEGER, -- version
47 * name DistinguishedName, -- dn
48 * authentication CHOICE {
49 * simple [0] OCTET STRING -- passwd
50 * krbv42ldap [1] OCTET STRING
51 * krbv42dsa [1] OCTET STRING
58 * in version 3.0 there is an extra SEQUENCE tag after the
59 * BindRequest SEQUENCE tag.
64 unsigned long tlen, ttag;
67 ttag = ber_skip_tag( &tber, &tlen );
68 if ( ber_peek_tag( &tber, &tlen ) == LBER_SEQUENCE ) {
69 Debug( LDAP_DEBUG_ANY, "version 3.0 detected\n", 0, 0, 0 );
71 rc = ber_scanf(ber, "{{iato}}", &version, &dn, &method, &cred);
73 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
77 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
79 if ( rc == LBER_ERROR ) {
80 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
81 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
86 if ( conn->c_version == 30 ) {
88 case LDAP_AUTH_SIMPLE_30:
89 method = LDAP_AUTH_SIMPLE;
92 case LDAP_AUTH_KRBV41_30:
93 method = LDAP_AUTH_KRBV41;
95 case LDAP_AUTH_KRBV42_30:
96 method = LDAP_AUTH_KRBV42;
101 #endif /* compat30 */
104 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d BIND dn=\"%s\" method=%d\n",
105 conn->c_connid, op->o_opid, dn, method, 0 );
107 if ( version != LDAP_VERSION2 ) {
111 if ( cred.bv_val != NULL ) {
115 Debug( LDAP_DEBUG_ANY, "unknown version %d\n", version, 0, 0 );
116 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
117 "version not supported" );
121 Debug( LDAP_DEBUG_TRACE, "do_bind: version %d dn (%s) method %d\n",
122 version, dn, method );
124 /* accept null binds */
125 if ( dn == NULL || *dn == '\0' ) {
129 if ( cred.bv_val != NULL ) {
133 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
138 * We could be serving multiple database backends. Select the
139 * appropriate one, or send a referral to our "referral server"
140 * if we don't hold it.
143 if ( (be = select_backend( dn )) == NULL ) {
145 if ( cred.bv_val != NULL ) {
148 if ( cred.bv_len == 0 ) {
149 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
151 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
157 if ( be->be_bind != NULL ) {
158 if ( (*be->be_bind)( be, conn, op, dn, method, &cred ) == 0 ) {
159 pthread_mutex_lock( &conn->c_dnmutex );
160 if ( conn->c_dn != NULL ) {
163 conn->c_dn = strdup( dn );
164 pthread_mutex_unlock( &conn->c_dnmutex );
166 /* send this here to avoid a race condition */
167 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
170 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
171 "Function not implemented" );
175 if ( cred.bv_val != NULL ) {