1 /* bind.c - bdb backend bind routine */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/unistd.h>
30 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
35 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
36 char krbname[MAX_K_NAME_SZ + 1];
37 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
41 AttributeDescription *password = slap_schema.si_ad_userPassword;
43 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn, 0, 0);
48 rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 );
55 send_ldap_result( conn, op, rc=LDAP_OTHER,
56 NULL, "internal error", NULL, NULL );
60 /* get entry with reader lock */
62 char *matched_dn = NULL;
63 struct berval **refs = NULL;
65 if( matched != NULL ) {
66 matched_dn = ch_strdup( matched->e_dn );
68 refs = is_entry_referral( matched )
69 ? get_entry_referrals( be, conn, op, matched )
72 bdb_entry_return( be, matched );
74 refs = default_referral;
77 /* allow noauth binds */
79 if ( method == LDAP_AUTH_SIMPLE ) {
80 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
81 *edn = ch_strdup( be_root_dn( be ) );
82 rc = LDAP_SUCCESS; /* front end will send result */
84 } else if ( refs != NULL ) {
85 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
86 matched_dn, NULL, refs, NULL );
89 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
90 NULL, NULL, NULL, NULL );
93 } else if ( refs != NULL ) {
94 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
95 matched_dn, NULL, refs, NULL );
98 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
99 NULL, NULL, NULL, NULL );
102 if ( matched != NULL ) {
103 ber_bvecfree( refs );
110 *edn = ch_strdup( e->e_dn );
112 /* check for deleted */
114 if ( is_entry_alias( e ) ) {
115 /* entry is an alias, don't allow bind */
116 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
119 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
120 NULL, "entry is alias", NULL, NULL );
125 if ( is_entry_referral( e ) ) {
126 /* entry is a referral, don't allow bind */
127 struct berval **refs = get_entry_referrals( be,
130 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
134 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
135 e->e_dn, NULL, refs, NULL );
138 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
139 NULL, NULL, NULL, NULL );
142 ber_bvecfree( refs );
148 case LDAP_AUTH_SIMPLE:
149 /* check for root dn/passwd */
150 if ( be_isroot_pw( be, conn, dn, cred ) ) {
151 /* front end will send result */
152 if(*edn != NULL) free( *edn );
153 *edn = ch_strdup( be_root_dn( be ) );
158 if ( ! access_allowed( be, conn, op, e,
159 password, NULL, ACL_AUTH ) )
161 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
162 NULL, NULL, NULL, NULL );
166 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
167 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
168 NULL, NULL, NULL, NULL );
172 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
173 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
174 NULL, NULL, NULL, NULL );
181 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
182 case LDAP_AUTH_KRBV41:
183 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
184 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
185 NULL, NULL, NULL, NULL );
189 if ( ! access_allowed( be, conn, op, e,
190 krbattr, NULL, ACL_AUTH ) )
192 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
193 NULL, NULL, NULL, NULL );
197 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
198 : "", ad.pinst, ad.prealm );
200 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
202 * no krbname values present: check against DN
204 if ( strcasecmp( dn, krbname ) == 0 ) {
208 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
209 NULL, NULL, NULL, NULL );
212 } else { /* look for krbname match */
213 struct berval krbval;
215 krbval.bv_val = krbname;
216 krbval.bv_len = strlen( krbname );
218 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
219 send_ldap_result( conn, op,
220 rc = LDAP_INVALID_CREDENTIALS,
221 NULL, NULL, NULL, NULL );
228 case LDAP_AUTH_KRBV42:
229 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
230 NULL, "Kerberos bind step 2 not supported",
236 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
237 NULL, "authentication method not supported", NULL, NULL );
242 /* free entry and reader lock */
243 bdb_entry_return( be, e );
245 /* front end with send result on success (rc==0) */