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 <sys/types.h>
20 #include <sys/socket.h>
23 extern Backend *select_backend();
25 extern char *default_referral;
33 BerElement *ber = op->o_ber;
34 int version, method, len, rc;
39 Debug( LDAP_DEBUG_TRACE, "do_bind\n", 0, 0, 0 );
42 * Parse the bind request. It looks like this:
44 * BindRequest ::= SEQUENCE {
45 * version INTEGER, -- version
46 * name DistinguishedName, -- dn
47 * authentication CHOICE {
48 * simple [0] OCTET STRING -- passwd
49 * krbv42ldap [1] OCTET STRING
50 * krbv42dsa [1] OCTET STRING
57 * in version 3.0 there is an extra SEQUENCE tag after the
58 * BindRequest SEQUENCE tag.
63 unsigned long tlen, ttag;
66 ttag = ber_skip_tag( &tber, &tlen );
67 if ( ber_peek_tag( &tber, &tlen ) == LBER_SEQUENCE ) {
68 Debug( LDAP_DEBUG_ANY, "version 3.0 detected\n", 0, 0, 0 );
70 rc = ber_scanf(ber, "{{iato}}", &version, &dn, &method, &cred);
72 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
76 rc = ber_scanf( ber, "{iato}", &version, &dn, &method, &cred );
78 if ( rc == LBER_ERROR ) {
79 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
80 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
85 if ( conn->c_version == 30 ) {
87 case LDAP_AUTH_SIMPLE_30:
88 method = LDAP_AUTH_SIMPLE;
91 case LDAP_AUTH_KRBV41_30:
92 method = LDAP_AUTH_KRBV41;
94 case LDAP_AUTH_KRBV42_30:
95 method = LDAP_AUTH_KRBV42;
100 #endif /* compat30 */
103 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d BIND dn=\"%s\" method=%d\n",
104 conn->c_connid, op->o_opid, dn, method, 0 );
106 if ( version != LDAP_VERSION2 ) {
110 if ( cred.bv_val != NULL ) {
114 Debug( LDAP_DEBUG_ANY, "unknown version %d\n", version, 0, 0 );
115 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
116 "version not supported" );
120 Debug( LDAP_DEBUG_TRACE, "do_bind: version %d dn (%s) method %d\n",
121 version, dn, method );
123 /* accept null binds */
124 if ( dn == NULL || *dn == '\0' ) {
128 if ( cred.bv_val != NULL ) {
132 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
137 * We could be serving multiple database backends. Select the
138 * appropriate one, or send a referral to our "referral server"
139 * if we don't hold it.
142 if ( (be = select_backend( dn )) == NULL ) {
144 if ( cred.bv_val != NULL ) {
147 if ( cred.bv_len == 0 ) {
148 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
150 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
156 if ( be->be_bind != NULL ) {
157 if ( (*be->be_bind)( be, conn, op, dn, method, &cred ) == 0 ) {
158 pthread_mutex_lock( &conn->c_dnmutex );
159 if ( conn->c_dn != NULL ) {
162 conn->c_dn = strdup( dn );
163 pthread_mutex_unlock( &conn->c_dnmutex );
165 /* send this here to avoid a race condition */
166 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
169 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
170 "Function not implemented" );
174 if ( cred.bv_val != NULL ) {