1 /* bind.c - bdb2 backend bind and unbind routines */
10 #include <ac/string.h>
11 #include <ac/unistd.h>
14 #include "back-bdb2.h"
15 #include "proto-back-bdb2.h"
18 bdb2i_back_bind_internal(
28 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
34 char krbname[MAX_K_NAME_SZ + 1];
38 Debug(LDAP_DEBUG_ARGS, "==> bdb2_back_bind: dn: %s\n", dn, 0, 0);
42 /* get entry with reader lock */
43 if ( (e = bdb2i_dn2entry_r( be, dn, &matched )) == NULL ) {
44 char *matched_dn = NULL;
45 struct berval **refs = NULL;
47 if ( matched != NULL ) {
48 matched_dn = ch_strdup( matched->e_dn );
49 refs = is_entry_referral( matched )
50 ? get_entry_referrals( be, conn, op, matched )
52 bdb2i_cache_return_entry_r( &li->li_cache, matched );
54 refs = default_referral;
57 /* allow noauth binds */
59 if ( method == LDAP_AUTH_SIMPLE ) {
60 if( cred->bv_len == 0 ) {
62 send_ldap_result( conn, op, LDAP_SUCCESS,
63 NULL, NULL, NULL, NULL );
65 } else if ( be_isroot_pw( be, dn, cred ) ) {
66 /* front end will send result */
67 *edn = ch_strdup( be_root_dn( be ) );
70 } else if ( refs != NULL ) {
71 send_ldap_result( conn, op, LDAP_REFERRAL,
72 matched_dn, NULL, refs, NULL );
75 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
76 NULL, NULL, NULL, NULL );
79 } else if ( method == LDAP_AUTH_SASL ) {
80 if( mech != NULL && strcasecmp(mech,"DIGEST-MD5") == 0 ) {
81 /* insert DIGEST calls here */
82 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
83 NULL, NULL, NULL, NULL );
86 send_ldap_result( conn, op, LDAP_AUTH_METHOD_NOT_SUPPORTED,
87 NULL, NULL, NULL, NULL );
90 } else if ( refs != NULL ) {
91 send_ldap_result( conn, op, LDAP_REFERRAL,
92 matched_dn, NULL, refs, NULL );
95 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
96 NULL, NULL, NULL, NULL );
99 if ( matched != NULL ) {
100 ber_bvecfree( refs );
106 *edn = ch_strdup( e->e_dn );
108 /* check for deleted */
110 if ( ! access_allowed( be, conn, op, e,
111 "entry", NULL, ACL_AUTH ) )
113 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
114 NULL, NULL, NULL, NULL );
119 if ( is_entry_alias( e ) ) {
120 /* entry is a alias, don't allow bind */
121 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
124 send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
125 NULL, NULL, NULL, NULL );
132 if ( is_entry_referral( e ) ) {
133 /* entry is a referral, don't allow bind */
134 struct berval **refs = get_entry_referrals( be,
137 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
141 send_ldap_result( conn, op, LDAP_REFERRAL,
142 e->e_dn, NULL, refs, NULL );
144 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
145 NULL, NULL, NULL, NULL );
148 ber_bvecfree( refs );
155 case LDAP_AUTH_SIMPLE:
156 if ( cred->bv_len == 0 ) {
157 send_ldap_result( conn, op, LDAP_SUCCESS,
158 NULL, NULL, NULL, NULL );
160 /* stop front end from sending result */
165 /* check for root dn/passwd */
166 if ( be_isroot_pw( be, dn, cred ) ) {
167 /* front end will send result */
168 if( *edn != NULL ) free( *edn );
169 *edn = ch_strdup( be_root_dn( be ) );
174 if ( ! access_allowed( be, conn, op, e,
175 "userpassword", NULL, ACL_AUTH ) )
177 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
178 NULL, NULL, NULL, NULL);
183 if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
184 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
185 NULL, NULL, NULL, NULL);
187 /* stop front end from sending result */
192 if ( slap_passwd_check( a, cred ) != 0 ) {
193 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
194 NULL, NULL, NULL, NULL);
195 /* stop front end from sending result */
202 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
203 case LDAP_AUTH_KRBV41:
204 if ( bdb2i_krbv4_ldap_auth( be, cred, &ad ) != LDAP_SUCCESS ) {
205 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
206 NULL, NULL, NULL, NULL);
211 if ( ! access_allowed( be, conn, op, e,
212 "krbname", NULL, ACL_AUTH ) )
214 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
215 NULL, NULL, NULL, NULL);
220 sprintf( krbname, "%s%s%s@%s", ad.pname, *ad.pinst ? "."
221 : "", ad.pinst, ad.prealm );
223 if ( (a = attr_find( e->e_attrs, "krbname" )) == NULL ) {
225 * no krbName values present: check against DN
227 if ( strcasecmp( dn, krbname ) == 0 ) {
228 rc = 0; /* XXX wild ass guess */
231 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
232 NULL, NULL, NULL, NULL);
235 } else { /* look for krbName match */
236 struct berval krbval;
238 krbval.bv_val = krbname;
239 krbval.bv_len = strlen( krbname );
241 if ( value_find( a->a_vals, &krbval, a->a_syntax, 3 ) != 0 ) {
242 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
243 NULL, NULL, NULL, NULL);
251 case LDAP_AUTH_KRBV42:
252 send_ldap_result( conn, op, LDAP_SUCCESS,
253 NULL, NULL, NULL, NULL );
254 /* stop front end from sending result */
260 /* insert sasl code here */
263 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
264 NULL, "auth method not supported", NULL, NULL );
270 /* free entry and reader lock */
271 bdb2i_cache_return_entry_r( &li->li_cache, e );
273 /* front end with send result on success (rc==0) */
292 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
293 struct timeval time1;
296 bdb2i_start_timing( be->bd_info, &time1 );
298 if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
299 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
300 NULL, NULL, NULL, NULL );
304 ret = bdb2i_back_bind_internal( be, conn, op, ndn, method, mech, cred, edn );
306 (void) bdb2i_leave_backend_r( lock );
308 bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );