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 /* allow noauth binds */
91 if ( method == LDAP_AUTH_SIMPLE ) {
92 if( cred->bv_len == 0 ) {
94 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
96 } else if ( be_isroot_pw( be, dn, cred ) ) {
97 *edn = ch_strdup( be_root_dn( be ) );
98 rc = 0; /* front end will send result */
101 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
104 } else if ( method == LDAP_AUTH_SASL ) {
105 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") ) {
106 /* insert DIGEST calls here */
107 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH, NULL, NULL );
110 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH, NULL, NULL );
114 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
117 if ( matched != NULL ) {
123 *edn = ch_strdup( e->e_dn );
125 /* check for deleted */
127 if ( ! access_allowed( be, conn, op, e,
128 "entry", NULL, ACL_AUTH ) )
130 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
136 case LDAP_AUTH_SIMPLE:
137 if ( cred->bv_len == 0 ) {
138 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
140 /* stop front end from sending result */
145 /* check for root dn/passwd */
146 if ( be_isroot_pw( be, dn, cred ) ) {
147 /* front end will send result */
148 if(*edn != NULL) free( *edn );
149 *edn = ch_strdup( be_root_dn( be ) );
154 if ( ! access_allowed( be, conn, op, e,
155 "userpassword", NULL, ACL_AUTH ) )
157 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
162 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
163 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
166 /* stop front end from sending result */
171 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
173 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
175 /* stop front end from sending result */
184 case LDAP_AUTH_KRBV41:
185 if ( ! access_allowed( be, conn, op, e,
186 "krbname", NULL, ACL_AUTH ) )
188 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
193 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
194 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
200 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
201 : "", ad.pinst, ad.prealm );
203 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
205 * no krbName values present: check against DN
207 if ( strcasecmp( dn, krbname ) == 0 ) {
211 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
216 } else { /* look for krbName match */
217 struct berval krbval;
219 krbval.bv_val = krbname;
220 krbval.bv_len = strlen( krbname );
222 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
223 send_ldap_result( conn, op,
224 LDAP_INVALID_CREDENTIALS, NULL, NULL );
232 case LDAP_AUTH_KRBV42:
233 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
234 /* stop front end from sending result */
240 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
241 NULL, "auth method not supported" );
247 /* free entry and reader lock */
248 cache_return_entry_r( &li->li_cache, e );
250 /* front end with send result on success (rc==0) */