Home | History | Annotate | Line # | Download | only in back-wt
bind.c revision 1.1
      1  1.1  christos /*	$NetBSD: bind.c,v 1.1 2021/08/14 16:05:24 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /* OpenLDAP WiredTiger backend */
      4  1.1  christos /* $OpenLDAP$ */
      5  1.1  christos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  1.1  christos  *
      7  1.1  christos  * Copyright 2002-2021 The OpenLDAP Foundation.
      8  1.1  christos  * All rights reserved.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted only as authorized by the OpenLDAP
     12  1.1  christos  * Public License.
     13  1.1  christos  *
     14  1.1  christos  * A copy of this license is available in the file LICENSE in the
     15  1.1  christos  * top-level directory of the distribution or, alternatively, at
     16  1.1  christos  * <http://www.OpenLDAP.org/license.html>.
     17  1.1  christos  */
     18  1.1  christos /* ACKNOWLEDGEMENTS:
     19  1.1  christos  * This work was developed by HAMANO Tsukasa <hamano (at) osstech.co.jp>
     20  1.1  christos  * based on back-bdb for inclusion in OpenLDAP Software.
     21  1.1  christos  * WiredTiger is a product of MongoDB Inc.
     22  1.1  christos  */
     23  1.1  christos 
     24  1.1  christos #include <sys/cdefs.h>
     25  1.1  christos __RCSID("$NetBSD: bind.c,v 1.1 2021/08/14 16:05:24 christos Exp $");
     26  1.1  christos 
     27  1.1  christos #include "portable.h"
     28  1.1  christos 
     29  1.1  christos #include <stdio.h>
     30  1.1  christos #include "back-wt.h"
     31  1.1  christos #include "slap-config.h"
     32  1.1  christos 
     33  1.1  christos int
     34  1.1  christos wt_bind( Operation *op, SlapReply *rs )
     35  1.1  christos {
     36  1.1  christos     struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
     37  1.1  christos 	WT_SESSION *session;
     38  1.1  christos 	wt_ctx *wc;
     39  1.1  christos 	int rc;
     40  1.1  christos 	Entry *e = NULL;
     41  1.1  christos 	Attribute *a;
     42  1.1  christos 	AttributeDescription *password = slap_schema.si_ad_userPassword;
     43  1.1  christos 
     44  1.1  christos     Debug( LDAP_DEBUG_ARGS,
     45  1.1  christos 		   "==> " LDAP_XSTRING(wt_bind) ": dn: %s\n",
     46  1.1  christos 		   op->o_req_dn.bv_val );
     47  1.1  christos 
     48  1.1  christos 	/* allow noauth binds */
     49  1.1  christos 	switch ( be_rootdn_bind( op, NULL ) ) {
     50  1.1  christos 	case LDAP_SUCCESS:
     51  1.1  christos         /* frontend will send result */
     52  1.1  christos         return rs->sr_err = LDAP_SUCCESS;
     53  1.1  christos 
     54  1.1  christos     default:
     55  1.1  christos         /* give the database a chance */
     56  1.1  christos         /* NOTE: this behavior departs from that of other backends,
     57  1.1  christos          * since the others, in case of password checking failure
     58  1.1  christos          * do not give the database a chance.  If an entry with
     59  1.1  christos          * rootdn's name does not exist in the database the result
     60  1.1  christos          * will be the same.  See ITS#4962 for discussion. */
     61  1.1  christos         break;
     62  1.1  christos 	}
     63  1.1  christos 
     64  1.1  christos 	wc = wt_ctx_get(op, wi);
     65  1.1  christos 	if( !wc ){
     66  1.1  christos 		Debug( LDAP_DEBUG_ANY,
     67  1.1  christos 			   LDAP_XSTRING(wt_bind)
     68  1.1  christos 			   ": wt_ctx_get failed\n" );
     69  1.1  christos 		rs->sr_err = LDAP_OTHER;
     70  1.1  christos 		rs->sr_text = "internal error";
     71  1.1  christos         send_ldap_result( op, rs );
     72  1.1  christos         return rs->sr_err;
     73  1.1  christos 	}
     74  1.1  christos 
     75  1.1  christos 	/* get entry */
     76  1.1  christos 	rc = wt_dn2entry(op->o_bd, wc, &op->o_req_ndn, &e);
     77  1.1  christos 	switch( rc ) {
     78  1.1  christos 	case 0:
     79  1.1  christos 		break;
     80  1.1  christos 	case WT_NOTFOUND:
     81  1.1  christos 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
     82  1.1  christos 		send_ldap_result( op, rs );
     83  1.1  christos 		return rs->sr_err;
     84  1.1  christos 	default:
     85  1.1  christos 		rs->sr_err = LDAP_OTHER;
     86  1.1  christos 		rs->sr_text = "internal error";
     87  1.1  christos         send_ldap_result( op, rs );
     88  1.1  christos         return rs->sr_err;
     89  1.1  christos 	}
     90  1.1  christos 
     91  1.1  christos 	ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
     92  1.1  christos 
     93  1.1  christos     /* check for deleted */
     94  1.1  christos 	if ( is_entry_subentry( e ) ) {
     95  1.1  christos         /* entry is an subentry, don't allow bind */
     96  1.1  christos 		Debug( LDAP_DEBUG_TRACE, "entry is subentry\n" );
     97  1.1  christos 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
     98  1.1  christos 		goto done;
     99  1.1  christos 	}
    100  1.1  christos 
    101  1.1  christos 	if ( is_entry_alias( e ) ) {
    102  1.1  christos         /* entry is an alias, don't allow bind */
    103  1.1  christos 		Debug( LDAP_DEBUG_TRACE, "entry is alias\n" );
    104  1.1  christos 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
    105  1.1  christos 		goto done;
    106  1.1  christos 	}
    107  1.1  christos 
    108  1.1  christos 	if ( is_entry_referral( e ) ) {
    109  1.1  christos 		Debug( LDAP_DEBUG_TRACE, "entry is referral\n" );
    110  1.1  christos 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
    111  1.1  christos 		goto done;
    112  1.1  christos 	}
    113  1.1  christos 
    114  1.1  christos 	switch ( op->oq_bind.rb_method ) {
    115  1.1  christos 	case LDAP_AUTH_SIMPLE:
    116  1.1  christos 		a = attr_find( e->e_attrs, password );
    117  1.1  christos 		if ( a == NULL ) {
    118  1.1  christos 			rs->sr_err = LDAP_INVALID_CREDENTIALS;
    119  1.1  christos 			goto done;
    120  1.1  christos 		}
    121  1.1  christos 
    122  1.1  christos 		if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
    123  1.1  christos 								&rs->sr_text ) != 0 )
    124  1.1  christos 		{
    125  1.1  christos             /* failure; stop front end from sending result */
    126  1.1  christos 			rs->sr_err = LDAP_INVALID_CREDENTIALS;
    127  1.1  christos 			goto done;
    128  1.1  christos 		}
    129  1.1  christos 		rs->sr_err = 0;
    130  1.1  christos 		break;
    131  1.1  christos 
    132  1.1  christos     default:
    133  1.1  christos 		rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
    134  1.1  christos 		rs->sr_text = "authentication method not supported";
    135  1.1  christos 	}
    136  1.1  christos 
    137  1.1  christos done:
    138  1.1  christos 	/* free entry */
    139  1.1  christos 	if (e) {
    140  1.1  christos 		wt_entry_return(e);
    141  1.1  christos 	}
    142  1.1  christos 	if (rs->sr_err) {
    143  1.1  christos 		send_ldap_result( op, rs );
    144  1.1  christos         if ( rs->sr_ref ) {
    145  1.1  christos             ber_bvarray_free( rs->sr_ref );
    146  1.1  christos 			rs->sr_ref = NULL;
    147  1.1  christos 		}
    148  1.1  christos 	}
    149  1.1  christos 	return rs->sr_err;
    150  1.1  christos }
    151  1.1  christos 
    152  1.1  christos /*
    153  1.1  christos  * Local variables:
    154  1.1  christos  * indent-tabs-mode: t
    155  1.1  christos  * tab-width: 4
    156  1.1  christos  * c-basic-offset: 4
    157  1.1  christos  * End:
    158  1.1  christos  */
    159