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>
29 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
34 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
35 char krbname[MAX_K_NAME_SZ + 1];
36 AttributeDescription *krbattr = slap_schema.si_ad_krbName;
40 AttributeDescription *password = slap_schema.si_ad_userPassword;
42 Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn, 0, 0);
47 rc = dn2entry_r( be, NULL, ndn, &e, &matched );
54 send_ldap_result( conn, op, rc=LDAP_OTHER,
55 NULL, "internal error", NULL, NULL );
59 /* get entry with reader lock */
61 char *matched_dn = NULL;
62 struct berval **refs = NULL;
64 if( matched != NULL ) {
65 matched_dn = ch_strdup( matched->e_dn );
67 refs = is_entry_referral( matched )
68 ? get_entry_referrals( be, conn, op, matched )
71 bdb_entry_return( be, matched );
73 refs = default_referral;
76 /* allow noauth binds */
78 if ( method == LDAP_AUTH_SIMPLE ) {
79 if ( be_isroot_pw( be, conn, ndn, cred ) ) {
80 *edn = ch_strdup( be_root_dn( be ) );
81 rc = LDAP_SUCCESS; /* front end will send result */
83 } else if ( refs != NULL ) {
84 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
85 matched_dn, NULL, refs, NULL );
88 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
89 NULL, NULL, NULL, NULL );
92 } else if ( refs != NULL ) {
93 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
94 matched_dn, NULL, refs, NULL );
97 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
98 NULL, NULL, NULL, NULL );
101 if ( matched != NULL ) {
102 ber_bvecfree( refs );
109 *edn = ch_strdup( e->e_dn );
111 /* check for deleted */
113 if ( is_entry_alias( e ) ) {
114 /* entry is an alias, don't allow bind */
115 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
118 send_ldap_result( conn, op, rc = LDAP_ALIAS_PROBLEM,
119 NULL, "entry is alias", NULL, NULL );
124 if ( is_entry_referral( e ) ) {
125 /* entry is a referral, don't allow bind */
126 struct berval **refs = get_entry_referrals( be,
129 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
133 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
134 e->e_dn, NULL, refs, NULL );
137 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
138 NULL, NULL, NULL, NULL );
141 ber_bvecfree( refs );
147 case LDAP_AUTH_SIMPLE:
148 /* check for root dn/passwd */
149 if ( be_isroot_pw( be, conn, dn, cred ) ) {
150 /* front end will send result */
151 if(*edn != NULL) free( *edn );
152 *edn = ch_strdup( be_root_dn( be ) );
157 if ( ! access_allowed( be, conn, op, e,
158 password, NULL, ACL_AUTH ) )
160 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
161 NULL, NULL, NULL, NULL );
165 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
166 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
167 NULL, NULL, NULL, NULL );
171 if ( slap_passwd_check( conn, a, cred ) != 0 ) {
172 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
173 NULL, NULL, NULL, NULL );
180 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
181 case LDAP_AUTH_KRBV41:
182 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
183 send_ldap_result( conn, op, rc = LDAP_INVALID_CREDENTIALS,
184 NULL, NULL, NULL, NULL );
188 if ( ! access_allowed( be, conn, op, e,
189 krbattr, NULL, ACL_AUTH ) )
191 send_ldap_result( conn, op, rc = LDAP_INSUFFICIENT_ACCESS,
192 NULL, NULL, NULL, NULL );
196 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
197 : "", ad.pinst, ad.prealm );
199 if ( (a = attr_find( e->e_attrs, krbattr )) == NULL ) {
201 * no krbname values present: check against DN
203 if ( strcasecmp( dn, krbname ) == 0 ) {
207 send_ldap_result( conn, op, rc = LDAP_INAPPROPRIATE_AUTH,
208 NULL, NULL, NULL, NULL );
211 } else { /* look for krbname match */
212 struct berval krbval;
214 krbval.bv_val = krbname;
215 krbval.bv_len = strlen( krbname );
217 if ( value_find( a->a_desc, a->a_vals, &krbval ) != 0 ) {
218 send_ldap_result( conn, op,
219 rc = LDAP_INVALID_CREDENTIALS,
220 NULL, NULL, NULL, NULL );
227 case LDAP_AUTH_KRBV42:
228 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
229 NULL, "Kerberos bind step 2 not supported",
235 send_ldap_result( conn, op, rc = LDAP_STRONG_AUTH_NOT_SUPPORTED,
236 NULL, "authentication method not supported", NULL, NULL );
241 /* free entry and reader lock */
242 bdb_entry_return( be, e );
244 /* front end with send result on success (rc==0) */