1 /* bind.c - ldbm backend bind and unbind routines */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
18 #include "back-ldbm.h"
19 #include "proto-back-ldbm.h"
34 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
39 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
40 char krbname[MAX_K_NAME_SZ + 1];
44 #ifdef SLAPD_SCHEMA_NOT_COMPAT
45 static AttributeDescription *password = NULL;
46 static AttributeDescription *entry = NULL;
48 static const char *password = "userpassword";
49 static const char *entry = "entry";
52 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
57 /* get entry with reader lock */
58 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
59 char *matched_dn = NULL;
60 struct berval **refs = NULL;
62 if( matched != NULL ) {
63 matched_dn = ch_strdup( matched->e_dn );
65 refs = is_entry_referral( matched )
66 ? get_entry_referrals( be, conn, op, matched )
69 cache_return_entry_r( &li->li_cache, matched );
71 refs = default_referral;
74 /* allow noauth binds */
76 if ( method == LDAP_AUTH_SIMPLE ) {
77 if ( be_isroot_pw( be, dn, cred ) ) {
78 *edn = ch_strdup( be_root_dn( be ) );
79 rc = 0; /* front end will send result */
81 } else if ( refs != NULL ) {
82 send_ldap_result( conn, op, LDAP_REFERRAL,
83 matched_dn, NULL, refs, NULL );
86 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
87 NULL, NULL, NULL, NULL );
90 } else if ( refs != NULL ) {
91 send_ldap_result( conn, op, LDAP_REFERRAL,
92 matched_dn, NULL, refs, NULL );
95 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
96 NULL, NULL, NULL, NULL );
99 if ( matched != NULL ) {
100 ber_bvecfree( refs );
106 *edn = ch_strdup( e->e_dn );
108 /* check for deleted */
110 if ( ! access_allowed( be, conn, op, e,
111 entry, NULL, ACL_AUTH ) )
113 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
114 NULL, NULL, NULL, NULL );
119 if ( is_entry_alias( e ) ) {
120 /* entry is an alias, don't allow bind */
121 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
124 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
125 NULL, "entry is alias", NULL, NULL );
131 if ( is_entry_referral( e ) ) {
132 /* entry is a referral, don't allow bind */
133 struct berval **refs = get_entry_referrals( be,
136 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
140 send_ldap_result( conn, op, LDAP_REFERRAL,
141 e->e_dn, NULL, refs, NULL );
144 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
145 NULL, NULL, NULL, NULL );
148 ber_bvecfree( refs );
155 case LDAP_AUTH_SIMPLE:
156 /* check for root dn/passwd */
157 if ( be_isroot_pw( be, dn, cred ) ) {
158 /* front end will send result */
159 if(*edn != NULL) free( *edn );
160 *edn = ch_strdup( be_root_dn( be ) );
165 if ( ! access_allowed( be, conn, op, e,
166 password, NULL, ACL_AUTH ) )
168 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
169 NULL, NULL, NULL, NULL );
174 if ( (a = attr_find( e->e_attrs, password )) == NULL ) {
175 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
176 NULL, NULL, NULL, NULL );
178 /* stop front end from sending result */
183 if ( slap_passwd_check( a, cred ) != 0 ) {
184 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
185 NULL, NULL, NULL, NULL );
186 /* stop front end from sending result */
194 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
195 case LDAP_AUTH_KRBV41:
196 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
197 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
198 NULL, NULL, NULL, NULL );
203 if ( ! access_allowed( be, conn, op, e,
204 "krbname", NULL, ACL_AUTH ) )
206 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
207 NULL, NULL, NULL, NULL );
212 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
213 : "", ad.pinst, ad.prealm );
215 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
217 * no krbname values present: check against DN
219 if ( strcasecmp( dn, krbname ) == 0 ) {
223 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
224 NULL, NULL, NULL, NULL );
228 } else { /* look for krbname match */
229 struct berval krbval;
231 krbval.bv_val = krbname;
232 krbval.bv_len = strlen( krbname );
234 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
235 send_ldap_result( conn, op,
236 LDAP_INVALID_CREDENTIALS,
237 NULL, NULL, NULL, NULL );
245 case LDAP_AUTH_KRBV42:
246 send_ldap_result( conn, op, LDAP_SUCCESS,
247 NULL, NULL, NULL, NULL );
248 /* stop front end from sending result */
254 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
255 NULL, "authentication method not supported", NULL, NULL );
261 /* free entry and reader lock */
262 cache_return_entry_r( &li->li_cache, e );
264 /* front end with send result on success (rc==0) */