1 /* bind.c - ldbm backend bind and unbind routines */
10 #include <ac/unistd.h>
13 #include "back-ldbm.h"
14 #include "proto-back-ldbm.h"
19 extern int krbv4_ldap_auth();
32 for ( i = 0; vals[i] != NULL; i++ ) {
33 if ( syntax != SYNTAX_BIN ) {
37 ldap_pvt_thread_mutex_lock( &crypt_mutex );
40 result = lutil_passwd(
42 (char*) vals[i]->bv_val,
46 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
52 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
73 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
79 char krbname[MAX_K_NAME_SZ + 1];
83 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
87 /* get entry with reader lock */
88 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
89 char *matched_dn = NULL;
90 struct berval **refs = NULL;
92 if( matched != NULL ) {
93 matched_dn = ch_strdup( matched->e_dn );
95 refs = is_entry_referral( matched )
96 ? get_entry_referrals( be, conn, op, matched )
99 cache_return_entry_r( &li->li_cache, matched );
101 refs = default_referral;
104 /* allow noauth binds */
106 if ( method == LDAP_AUTH_SIMPLE ) {
107 if( cred->bv_len == 0 ) {
109 send_ldap_result( conn, op, LDAP_SUCCESS,
110 NULL, NULL, NULL, NULL );
112 } else if ( be_isroot_pw( be, dn, cred ) ) {
113 *edn = ch_strdup( be_root_dn( be ) );
114 rc = 0; /* front end will send result */
117 send_ldap_result( conn, op, LDAP_REFERRAL,
118 matched_dn, NULL, refs, NULL );
121 } else if ( method == LDAP_AUTH_SASL ) {
122 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
123 /* insert DIGEST calls here */
124 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
125 NULL, NULL, NULL, NULL );
128 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
129 NULL, NULL, NULL, NULL );
133 send_ldap_result( conn, op, LDAP_REFERRAL,
134 matched_dn, NULL, refs, NULL );
137 if ( matched != NULL ) {
138 ber_bvecfree( refs );
144 *edn = ch_strdup( e->e_dn );
146 /* check for deleted */
148 if ( ! access_allowed( be, conn, op, e,
149 "entry", NULL, ACL_AUTH ) )
151 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
152 NULL, NULL, NULL, NULL );
157 if ( is_entry_alias( e ) ) {
158 /* entry is an alias, don't allow bind */
159 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
162 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
163 NULL, NULL, NULL, NULL );
169 if ( is_entry_referral( e ) ) {
170 /* entry is a referral, don't allow bind */
171 struct berval **refs = get_entry_referrals( be,
174 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
177 send_ldap_result( conn, op, LDAP_REFERRAL,
178 e->e_dn, NULL, refs, NULL );
180 ber_bvecfree( refs );
187 case LDAP_AUTH_SIMPLE:
188 if ( cred->bv_len == 0 ) {
189 send_ldap_result( conn, op, LDAP_SUCCESS,
190 NULL, NULL, NULL, NULL );
192 /* stop front end from sending result */
197 /* check for root dn/passwd */
198 if ( be_isroot_pw( be, dn, cred ) ) {
199 /* front end will send result */
200 if(*edn != NULL) free( *edn );
201 *edn = ch_strdup( be_root_dn( be ) );
206 if ( ! access_allowed( be, conn, op, e,
207 "userpassword", NULL, ACL_AUTH ) )
209 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
210 NULL, NULL, NULL, NULL );
215 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
216 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
217 NULL, NULL, NULL, NULL );
219 /* stop front end from sending result */
224 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
226 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
227 NULL, NULL, NULL, NULL );
228 /* stop front end from sending result */
237 case LDAP_AUTH_KRBV41:
238 if ( ! access_allowed( be, conn, op, e,
239 "krbname", NULL, ACL_AUTH ) )
241 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
242 NULL, NULL, NULL, NULL );
247 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
248 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
249 NULL, NULL, NULL, NULL );
254 if ( ! access_allowed( be, conn, op, e,
255 "krbname", NULL, ACL_AUTH ) )
257 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
258 NULL, NULL, NULL, NULL );
263 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
264 : "", ad.pinst, ad.prealm );
267 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
269 * no krbName values present: check against DN
271 if ( strcasecmp( dn, krbname ) == 0 ) {
275 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
276 NULL, NULL, NULL, NULL );
280 } else { /* look for krbName match */
281 struct berval krbval;
283 krbval.bv_val = krbname;
284 krbval.bv_len = strlen( krbname );
286 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
287 send_ldap_result( conn, op,
288 LDAP_INVALID_CREDENTIALS,
289 NULL, NULL, NULL, NULL );
297 case LDAP_AUTH_KRBV42:
298 send_ldap_result( conn, op, LDAP_SUCCESS,
299 NULL, NULL, NULL, NULL );
300 /* stop front end from sending result */
306 /* insert SASL code here */
309 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
310 NULL, "auth method not supported", NULL, NULL );
316 /* free entry and reader lock */
317 cache_return_entry_r( &li->li_cache, e );
319 /* front end with send result on success (rc==0) */