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