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 */
90 if ( method == LDAP_AUTH_SIMPLE && cred->bv_len == 0 ) {
92 * bind successful, but return 1 so we don't
93 * authorize based on noauth credentials
95 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
97 } else if ( be_isroot_pw( be, dn, cred ) ) {
98 /* front end will send result */
99 *edn = ch_strdup( be_root_dn( be ) );
102 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
105 if ( matched != NULL ) {
111 *edn = ch_strdup( e->e_dn );
113 /* check for deleted */
116 if ( ! access_allowed( be, conn, op, e,
117 "entry", NULL, ACL_AUTH ) )
119 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
126 case LDAP_AUTH_SIMPLE:
127 if ( cred->bv_len == 0 ) {
128 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
130 /* stop front end from sending result */
135 /* check for root dn/passwd */
136 if ( be_isroot_pw( be, dn, cred ) ) {
137 /* front end will send result */
138 if(*edn != NULL) free( *edn );
139 *edn = ch_strdup( be_root_dn( be ) );
145 if ( ! access_allowed( be, conn, op, e,
146 "userpassword", NULL, ACL_AUTH ) )
148 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
154 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
155 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
158 /* stop front end from sending result */
163 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
165 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
167 /* stop front end from sending result */
176 case LDAP_AUTH_KRBV41:
178 if ( ! access_allowed( be, conn, op, e,
179 "krbname", NULL, ACL_AUTH ) )
181 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
186 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
187 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
192 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
193 : "", ad.pinst, ad.prealm );
194 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
196 * no krbName values present: check against DN
198 if ( strcasecmp( dn, krbname ) == 0 ) {
202 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
207 } else { /* look for krbName match */
208 struct berval krbval;
210 krbval.bv_val = krbname;
211 krbval.bv_len = strlen( krbname );
213 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
214 send_ldap_result( conn, op,
215 LDAP_INVALID_CREDENTIALS, NULL, NULL );
223 case LDAP_AUTH_KRBV42:
224 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
225 /* stop front end from sending result */
231 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
232 NULL, "auth method not supported" );
238 /* free entry and reader lock */
239 cache_return_entry_r( &li->li_cache, e );
241 /* front end with send result on success (rc==0) */