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 */
121 } else if ( be_isroot_pw( be, dn, cred ) ) {
122 /* front end will send result */
123 *edn = ch_strdup( be_root_dn( be ) );
128 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
129 if ( be_isroot_pw( be, dn, cred ) ) {
130 /* front end will send result */
131 *edn = ch_strdup( be_root_dn( be ) );
135 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
141 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
143 if ( be_isroot_pw( be, dn, cred ) ) {
144 /* front end will send result */
145 *edn = ch_strdup( be_root_dn( be ) );
149 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
158 case LDAP_AUTH_KRBV41:
159 if ( bdb2i_krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
160 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
165 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
166 : "", ad.pinst, ad.prealm );
167 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
169 * no krbName values present: check against DN
171 if ( strcasecmp( dn, krbname ) == 0 ) {
172 rc = 0; /* XXX wild ass guess */
175 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
179 } else { /* look for krbName match */
180 struct berval krbval;
182 krbval.bv_val = krbname;
183 krbval.bv_len = strlen( krbname );
185 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
186 send_ldap_result( conn, op,
187 LDAP_INVALID_CREDENTIALS, NULL, NULL );
195 case LDAP_AUTH_KRBV42:
196 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
197 /* stop front end from sending result */
203 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
204 NULL, "auth method not supported" );
210 /* free entry and reader lock */
211 bdb2i_cache_return_entry_r( &li->li_cache, e );
213 /* front end with send result on success (rc==0) */
230 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
232 struct timeval time1, time2;
236 gettimeofday( &time1, NULL );
238 if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
240 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
245 ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
247 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
249 if ( bdb2i_do_timing ) {
251 gettimeofday( &time2, NULL);
252 elapsed_time = bdb2i_elapsed( time1, time2 );
253 Debug( LDAP_DEBUG_ANY, "conn=%d op=%d BIND elapsed=%s\n",
254 conn->c_connid, op->o_opid, elapsed_time );
255 free( elapsed_time );