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 );
76 refs = default_referral;
79 /* allow noauth binds */
81 if ( method == LDAP_AUTH_SIMPLE ) {
82 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
83 *edn = ch_strdup( be_root_dn( be ) );
84 rc = LDAP_SUCCESS; /* front end will send result */
86 } else if ( refs != NULL ) {
87 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
88 matched_dn, NULL, refs, NULL );
91 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
92 NULL, NULL, NULL, NULL );
95 } else if ( refs != NULL ) {
96 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
97 matched_dn, NULL, refs, NULL );
100 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
101 NULL, NULL, NULL, NULL );
104 if ( matched != NULL ) {
105 ber_bvecfree( refs );
112 *edn = ch_strdup( e->e_dn );
114 /* check for deleted */
116 if ( is_entry_alias( e ) ) {
117 /* entry is an alias, don't allow bind */
118 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
121 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
122 NULL, "entry is alias", NULL, NULL );
127 if ( is_entry_referral( e ) ) {
128 /* entry is a referral, don't allow bind */
129 struct berval **refs = get_entry_referrals( be,
132 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
136 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
137 e->e_dn, NULL, refs, NULL );
140 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
141 NULL, NULL, NULL, NULL );
144 ber_bvecfree( refs );
150 case LDAP_AUTH_SIMPLE:
151 /* check for root dn/passwd */
152 if ( be_isroot_pw( be, conn, dn, cred ) ) {
153 /* front end will send result */
154 if(*edn != NULL) free( *edn );
155 *edn = ch_strdup( be_root_dn( be ) );
160 if ( ! access_allowed( be, conn, op, e,
161 password, NULL, ACL_AUTH ) )
163 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
164 NULL, NULL, NULL, NULL );
168 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
169 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
170 NULL, NULL, NULL, NULL );
174 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
175 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
176 NULL, NULL, NULL, NULL );
183 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
184 case LDAP_AUTH_KRBV41:
185 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
186 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
187 NULL, NULL, NULL, NULL );
191 if ( ! access_allowed( be, conn, op, e,
192 krbattr, NULL, ACL_AUTH ) )
194 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
195 NULL, NULL, NULL, NULL );
199 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
200 : "", ad.pinst, ad.prealm );
202 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
204 * no krbname values present: check against DN
206 if ( strcasecmp( dn, krbname ) == 0 ) {
210 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
211 NULL, NULL, NULL, NULL );
214 } else { /* look for krbname match */
215 struct berval krbval;
217 krbval.bv_val = krbname;
218 krbval.bv_len = strlen( krbname );
220 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
221 send_ldap_result( conn, op,
222 rc = LDAP_INVALID_CREDENTIALS,
223 NULL, NULL, NULL, NULL );
230 case LDAP_AUTH_KRBV42:
231 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
232 NULL, "Kerberos bind step 2 not supported",
238 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
239 NULL, "authentication method not supported", NULL, NULL );
244 /* free entry and reader lock */
246 bdb_entry_return( be, e );
249 /* front end with send result on success (rc==0) */