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 ) {
72 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
78 char krbname[MAX_K_NAME_SZ + 1];
82 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_bind: dn: %s\n", dn, 0, 0);
86 /* get entry with reader lock */
87 if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
88 /* allow noauth binds */
89 if ( method == LDAP_AUTH_SIMPLE && cred->bv_len == 0 ) {
91 * bind successful, but return 1 so we don't
92 * authorize based on noauth credentials
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 ) );
101 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, NULL );
104 if ( matched != NULL ) {
110 *edn = ch_strdup( e->e_dn );
112 /* check for deleted */
115 case LDAP_AUTH_SIMPLE:
116 if ( cred->bv_len == 0 ) {
117 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
119 /* stop front end from sending result */
124 /* check for root dn/passwd */
125 if ( be_isroot_pw( be, dn, cred ) ) {
126 /* front end will send result */
127 if(*edn != NULL) free( *edn );
128 *edn = ch_strdup( be_root_dn( be ) );
133 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
134 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
137 /* stop front end from sending result */
142 if ( crypted_value_find( a->a_vals, cred, a->a_syntax, 0, cred ) != 0 )
144 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
146 /* stop front end from sending result */
155 case LDAP_AUTH_KRBV41:
156 if ( krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
157 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
162 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
163 : "", ad.pinst, ad.prealm );
164 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
166 * no krbName values present: check against DN
168 if ( strcasecmp( dn, krbname ) == 0 ) {
169 rc = 0; /* XXX wild ass guess */
172 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
177 } else { /* look for krbName match */
178 struct berval krbval;
180 krbval.bv_val = krbname;
181 krbval.bv_len = strlen( krbname );
183 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
184 send_ldap_result( conn, op,
185 LDAP_INVALID_CREDENTIALS, NULL, NULL );
193 case LDAP_AUTH_KRBV42:
194 send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
195 /* stop front end from sending result */
201 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
202 NULL, "auth method not supported" );
208 /* free entry and reader lock */
209 cache_return_entry_r( &li->li_cache, e );
211 /* front end with send result on success (rc==0) */