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);
45 ldap_pvt_thread_mutex_unlock( &crypt_mutex );
51 if ( value_cmp( vals[i], v, syntax, normalize ) == 0 ) {
71 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
77 char krbname[MAX_K_NAME_SZ + 1];
81 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
85 /* get entry with reader lock */
86 if ( (e = 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 */
154 case LDAP_AUTH_KRBV41:
155 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
156 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
161 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
162 : "", ad.pinst, ad.prealm );
163 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
165 * no krbName values present: check against DN
167 if ( strcasecmp( dn, krbname ) == 0 ) {
168 rc = 0; /* XXX wild ass guess */
171 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
176 } else { /* look for krbName match */
177 struct berval krbval;
179 krbval.bv_val = krbname;
180 krbval.bv_len = strlen( krbname );
182 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
183 send_ldap_result( conn, op,
184 LDAP_INVALID_CREDENTIALS, NULL, NULL );
192 case LDAP_AUTH_KRBV42:
193 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
194 /* stop front end from sending result */
200 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
201 NULL, "auth method not supported" );
207 /* free entry and reader lock */
208 cache_return_entry_r( &li->li_cache, e );
210 /* front end with send result on success (rc==0) */