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 if ( strcasecmp( dn, krbname ) == 0 ) {
167 rc = 0; /* XXX wild ass guess */
170 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
174 } else { /* look for krbName match */
175 struct berval krbval;
177 krbval.bv_val = krbname;
178 krbval.bv_len = strlen( krbname );
180 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
181 send_ldap_result( conn, op,
182 LDAP_INVALID_CREDENTIALS, NULL, NULL );
190 case LDAP_AUTH_KRBV42:
191 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
192 /* stop front end from sending result */
198 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
199 NULL, "auth method not supported" );
205 /* free entry and reader lock */
206 bdb2i_cache_return_entry_r( &li->li_cache, e );
208 /* front end with send result on success (rc==0) */
225 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
226 struct timeval time1;
229 bdb2i_start_timing( be->bd_info, &time1 );
231 if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
233 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
238 ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
240 (void) bdb2i_leave_backend_r( lock );
242 bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );