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,
46 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
52 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
62 bdb2i_back_bind_internal(
73 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
79 char krbname[MAX_K_NAME_SZ + 1];
83 Debug(LDAP_DEBUG_ARGS, "==> bdb2_back_bind: dn: %s\n", dn, 0, 0);
87 /* get entry with reader lock */
88 if ( (e = bdb2i_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 /* front end will send result */
98 *edn = ch_strdup( be_root_dn( be ) );
102 send_ldap_result( conn, op,
103 LDAP_NO_SUCH_OBJECT, matched, NULL );
106 } else if ( method == LDAP_AUTH_SASL ) {
107 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
108 /* insert DIGEST calls here */
109 send_ldap_result( conn, op,
110 LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL, NULL );
113 send_ldap_result( conn, op,
114 LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL, NULL );
118 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
121 if ( matched != NULL ) {
127 *edn = ch_strdup( e->e_dn );
129 /* check for deleted */
131 if ( ! access_allowed( be, conn, op, e,
132 "entry", NULL, ACL_AUTH ) )
134 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
140 case LDAP_AUTH_SIMPLE:
141 if ( cred->bv_len == 0 ) {
142 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
144 /* stop front end from sending result */
149 /* check for root dn/passwd */
150 if ( be_isroot_pw( be, dn, cred ) ) {
151 /* front end will send result */
152 if( *edn != NULL ) free( *edn );
153 *edn = ch_strdup( be_root_dn( be ) );
158 if ( ! access_allowed( be, conn, op, e,
159 "userpassword", NULL, ACL_AUTH ) )
161 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
166 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
167 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
170 /* stop front end from sending result */
175 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
177 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
179 /* stop front end from sending result */
187 case LDAP_AUTH_KRBV41:
188 if ( bdb2i_krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
189 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
195 if ( ! access_allowed( be, conn, op, e,
196 "krbname", NULL, ACL_AUTH ) )
198 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
203 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
204 : "", ad.pinst, ad.prealm );
206 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
208 * no krbName values present: check against DN
210 if ( strcasecmp( dn, krbname ) == 0 ) {
211 rc = 0; /* XXX wild ass guess */
214 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
218 } else { /* look for krbName match */
219 struct berval krbval;
221 krbval.bv_val = krbname;
222 krbval.bv_len = strlen( krbname );
224 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
225 send_ldap_result( conn, op,
226 LDAP_INVALID_CREDENTIALS, NULL, NULL );
234 case LDAP_AUTH_KRBV42:
235 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
236 /* stop front end from sending result */
242 /* insert sasl code here */
245 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
246 NULL, "auth method not supported" );
252 /* free entry and reader lock */
253 bdb2i_cache_return_entry_r( &li->li_cache, e );
255 /* front end with send result on success (rc==0) */
273 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
274 struct timeval time1;
277 bdb2i_start_timing( be->bd_info, &time1 );
279 if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
281 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
286 ret = bdb2i_back_bind_internal( be, conn, op, dn, method, mech, cred, edn );
288 (void) bdb2i_leave_backend_r( lock );
290 bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );