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 */
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 *edn = ch_strdup( be_root_dn( be ) );
98 rc = 0; /* front end will send result */
101 send_ldap_result( conn, op,
102 LDAP_NO_SUCH_OBJECT, matched, NULL );
105 } else if ( method == LDAP_AUTH_SASL ) {
106 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
107 /* insert DIGEST calls here */
108 send_ldap_result( conn, op,
109 LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL, NULL );
112 send_ldap_result( conn, op,
113 LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL, NULL );
117 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
120 if ( matched != NULL ) {
126 *edn = ch_strdup( e->e_dn );
128 /* check for deleted */
130 if ( ! access_allowed( be, conn, op, e,
131 "entry", NULL, ACL_AUTH ) )
133 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
139 case LDAP_AUTH_SIMPLE:
140 if ( cred->bv_len == 0 ) {
141 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
143 /* stop front end from sending result */
148 /* check for root dn/passwd */
149 if ( be_isroot_pw( be, dn, cred ) ) {
150 /* front end will send result */
151 if(*edn != NULL) free( *edn );
152 *edn = ch_strdup( be_root_dn( be ) );
157 if ( ! access_allowed( be, conn, op, e,
158 "userpassword", NULL, ACL_AUTH ) )
160 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
165 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
166 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
169 /* stop front end from sending result */
174 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
176 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
178 /* stop front end from sending result */
187 case LDAP_AUTH_KRBV41:
188 if ( ! access_allowed( be, conn, op, e,
189 "krbname", NULL, ACL_AUTH ) )
191 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
196 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
197 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
203 if ( ! access_allowed( be, conn, op, e,
204 "krbname", NULL, ACL_AUTH ) )
206 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
211 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
212 : "", ad.pinst, ad.prealm );
215 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
217 * no krbName values present: check against DN
219 if ( strcasecmp( dn, krbname ) == 0 ) {
223 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
228 } else { /* look for krbName match */
229 struct berval krbval;
231 krbval.bv_val = krbname;
232 krbval.bv_len = strlen( krbname );
234 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
235 send_ldap_result( conn, op,
236 LDAP_INVALID_CREDENTIALS, NULL, NULL );
244 case LDAP_AUTH_KRBV42:
245 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
246 /* stop front end from sending result */
252 /* insert SASL code here */
255 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
256 NULL, "auth method not supported" );
262 /* free entry and reader lock */
263 cache_return_entry_r( &li->li_cache, e );
265 /* front end with send result on success (rc==0) */