1 /* bind.c - bdb2 backend bind and unbind routines */
10 #include <ac/unistd.h>
13 #include "back-bdb2.h"
14 #include "proto-back-bdb2.h"
19 extern int bdb2i_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);
45 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
51 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
61 bdb2i_back_bind_internal(
71 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
77 char krbname[MAX_K_NAME_SZ + 1];
81 Debug(LDAP_DEBUG_ARGS, "==> bdb2_back_bind: dn: %s\n", dn, 0, 0);
85 /* get entry with reader lock */
86 if ( (e = bdb2i_dn2entry_r( be, dn, &matched )) == NULL ) {
87 /* allow noauth binds */
88 if ( method == LDAP_AUTH_SIMPLE && cred->bv_len == 0 ) {
90 * bind successful, but return 1 so we don't
91 * authorize based on noauth credentials
93 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
95 } else if ( be_isroot_pw( be, dn, cred ) ) {
96 /* front end will send result */
97 *edn = ch_strdup( be_root_dn( be ) );
100 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
103 if ( matched != NULL ) {
109 *edn = ch_strdup( e->e_dn );
111 /* check for deleted */
114 case LDAP_AUTH_SIMPLE:
115 if ( cred->bv_len == 0 ) {
116 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
118 /* stop front end from sending result */
123 /* check for root dn/passwd */
124 if ( be_isroot_pw( be, dn, cred ) ) {
125 /* front end will send result */
126 if( *edn != NULL ) free( *edn );
127 *edn = ch_strdup( be_root_dn( be ) );
132 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
133 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
136 /* stop front end from sending result */
141 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
143 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
145 /* stop front end from sending result */
153 case LDAP_AUTH_KRBV41:
154 if ( bdb2i_krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
155 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
160 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
161 : "", ad.pinst, ad.prealm );
162 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
164 * no krbName values present: check against DN
166 /*###??? Should this be some variant of dn_casecmp? */
167 if ( strcasecmp( dn, krbname ) == 0 ) {
168 rc = 0; /* XXX wild ass guess */
171 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
175 } else { /* look for krbName match */
176 struct berval krbval;
178 krbval.bv_val = krbname;
179 krbval.bv_len = strlen( krbname );
181 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
182 send_ldap_result( conn, op,
183 LDAP_INVALID_CREDENTIALS, NULL, NULL );
191 case LDAP_AUTH_KRBV42:
192 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
193 /* stop front end from sending result */
199 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
200 NULL, "auth method not supported" );
206 /* free entry and reader lock */
207 bdb2i_cache_return_entry_r( &li->li_cache, e );
209 /* front end with send result on success (rc==0) */
226 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
227 struct timeval time1;
230 bdb2i_start_timing( be->bd_info, &time1 );
232 if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
234 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
239 ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
241 (void) bdb2i_leave_backend_r( lock );
243 bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );