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 */
90 if ( method == LDAP_AUTH_SIMPLE && cred->bv_len == 0 ) {
92 * bind successful, but return 1 so we don't
93 * authorize based on noauth credentials
95 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
97 } else if ( be_isroot_pw( be, dn, cred ) ) {
98 /* front end will send result */
99 *edn = ch_strdup( be_root_dn( be ) );
102 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
105 if ( matched != NULL ) {
111 *edn = ch_strdup( e->e_dn );
113 /* check for deleted */
116 case LDAP_AUTH_SIMPLE:
117 if ( cred->bv_len == 0 ) {
118 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
120 /* stop front end from sending result */
125 /* check for root dn/passwd */
126 if ( be_isroot_pw( be, dn, cred ) ) {
127 /* front end will send result */
128 if(*edn != NULL) free( *edn );
129 *edn = ch_strdup( be_root_dn( be ) );
134 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
135 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
138 /* stop front end from sending result */
143 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
145 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
147 /* stop front end from sending result */
156 case LDAP_AUTH_KRBV41:
157 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
158 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
163 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
164 : "", ad.pinst, ad.prealm );
165 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
167 * no krbName values present: check against DN
169 if ( strcasecmp( dn, krbname ) == 0 ) {
170 rc = 0; /* XXX wild ass guess */
173 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
178 } else { /* look for krbName match */
179 struct berval krbval;
181 krbval.bv_val = krbname;
182 krbval.bv_len = strlen( krbname );
184 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
185 send_ldap_result( conn, op,
186 LDAP_INVALID_CREDENTIALS, NULL, NULL );
194 case LDAP_AUTH_KRBV42:
195 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
196 /* stop front end from sending result */
202 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
203 NULL, "auth method not supported" );
209 /* free entry and reader lock */
210 cache_return_entry_r( &li->li_cache, e );
212 /* front end with send result on success (rc==0) */