Home | History | Annotate | Line # | Download | only in back-sql
bind.c revision 1.1.1.3
      1  1.1.1.2  lukem /*	$NetBSD: bind.c,v 1.1.1.3 2010/12/12 15:23:23 adam Exp $	*/
      2  1.1.1.2  lukem 
      3  1.1.1.3   adam /* OpenLDAP: pkg/ldap/servers/slapd/back-sql/bind.c,v 1.41.2.5 2010/04/13 20:23:42 kurt Exp */
      4      1.1  lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      5      1.1  lukem  *
      6  1.1.1.3   adam  * Copyright 1999-2010 The OpenLDAP Foundation.
      7      1.1  lukem  * Portions Copyright 1999 Dmitry Kovalev.
      8      1.1  lukem  * Portions Copyright 2002 Pierangelo Masarati.
      9      1.1  lukem  * All rights reserved.
     10      1.1  lukem  *
     11      1.1  lukem  * Redistribution and use in source and binary forms, with or without
     12      1.1  lukem  * modification, are permitted only as authorized by the OpenLDAP
     13      1.1  lukem  * Public License.
     14      1.1  lukem  *
     15      1.1  lukem  * A copy of this license is available in the file LICENSE in the
     16      1.1  lukem  * top-level directory of the distribution or, alternatively, at
     17      1.1  lukem  * <http://www.OpenLDAP.org/license.html>.
     18      1.1  lukem  */
     19      1.1  lukem /* ACKNOWLEDGEMENTS:
     20      1.1  lukem  * This work was initially developed by Dmitry Kovalev for inclusion
     21      1.1  lukem  * by OpenLDAP Software.  Additional significant contributors include
     22      1.1  lukem  * Pierangelo Masarati.
     23      1.1  lukem  */
     24      1.1  lukem 
     25      1.1  lukem #include "portable.h"
     26      1.1  lukem 
     27      1.1  lukem #include <stdio.h>
     28      1.1  lukem #include <sys/types.h>
     29      1.1  lukem 
     30      1.1  lukem #include "slap.h"
     31      1.1  lukem #include "proto-sql.h"
     32      1.1  lukem 
     33      1.1  lukem int
     34      1.1  lukem backsql_bind( Operation *op, SlapReply *rs )
     35      1.1  lukem {
     36      1.1  lukem 	SQLHDBC			dbh = SQL_NULL_HDBC;
     37      1.1  lukem 	Entry			e = { 0 };
     38      1.1  lukem 	Attribute		*a;
     39      1.1  lukem 	backsql_srch_info	bsi = { 0 };
     40      1.1  lukem 	AttributeName		anlist[2];
     41      1.1  lukem 	int			rc;
     42      1.1  lukem 
     43      1.1  lukem  	Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
     44      1.1  lukem 
     45      1.1  lukem 	switch ( be_rootdn_bind( op, rs ) ) {
     46      1.1  lukem 	case SLAP_CB_CONTINUE:
     47      1.1  lukem 		break;
     48      1.1  lukem 
     49      1.1  lukem 	default:
     50      1.1  lukem 		/* in case of success, front end will send result;
     51      1.1  lukem 		 * otherwise, be_rootdn_bind() did */
     52      1.1  lukem  		Debug( LDAP_DEBUG_TRACE, "<==backsql_bind(%d)\n",
     53      1.1  lukem 			rs->sr_err, 0, 0 );
     54      1.1  lukem 		return rs->sr_err;
     55      1.1  lukem 	}
     56      1.1  lukem 
     57      1.1  lukem 	rs->sr_err = backsql_get_db_conn( op, &dbh );
     58      1.1  lukem 	if ( rs->sr_err != LDAP_SUCCESS ) {
     59      1.1  lukem      		Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
     60      1.1  lukem 			"could not get connection handle - exiting\n",
     61      1.1  lukem 			0, 0, 0 );
     62      1.1  lukem 
     63      1.1  lukem 		rs->sr_text = ( rs->sr_err == LDAP_OTHER )
     64      1.1  lukem 			? "SQL-backend error" : NULL;
     65      1.1  lukem 		goto error_return;
     66      1.1  lukem 	}
     67      1.1  lukem 
     68      1.1  lukem 	anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
     69      1.1  lukem 	anlist[0].an_desc = slap_schema.si_ad_userPassword;
     70      1.1  lukem 	anlist[1].an_name.bv_val = NULL;
     71      1.1  lukem 
     72      1.1  lukem 	bsi.bsi_e = &e;
     73      1.1  lukem 	rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
     74      1.1  lukem 			(time_t)(-1), NULL, dbh, op, rs, anlist,
     75      1.1  lukem 			BACKSQL_ISF_GET_ENTRY );
     76      1.1  lukem 	if ( rc != LDAP_SUCCESS ) {
     77      1.1  lukem 		Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
     78      1.1  lukem 			"could not retrieve bindDN ID - no such entry\n",
     79      1.1  lukem 			0, 0, 0 );
     80      1.1  lukem 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
     81      1.1  lukem 		goto error_return;
     82      1.1  lukem 	}
     83      1.1  lukem 
     84      1.1  lukem 	a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
     85      1.1  lukem 	if ( a == NULL ) {
     86      1.1  lukem 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
     87      1.1  lukem 		goto error_return;
     88      1.1  lukem 	}
     89      1.1  lukem 
     90      1.1  lukem 	if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
     91      1.1  lukem 				&rs->sr_text ) != 0 )
     92      1.1  lukem 	{
     93      1.1  lukem 		rs->sr_err = LDAP_INVALID_CREDENTIALS;
     94      1.1  lukem 		goto error_return;
     95      1.1  lukem 	}
     96      1.1  lukem 
     97      1.1  lukem error_return:;
     98      1.1  lukem 	if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
     99      1.1  lukem 		(void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
    100      1.1  lukem 	}
    101      1.1  lukem 
    102      1.1  lukem 	if ( !BER_BVISNULL( &e.e_nname ) ) {
    103      1.1  lukem 		backsql_entry_clean( op, &e );
    104      1.1  lukem 	}
    105      1.1  lukem 
    106      1.1  lukem 	if ( bsi.bsi_attrs != NULL ) {
    107      1.1  lukem 		op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
    108      1.1  lukem 	}
    109      1.1  lukem 
    110      1.1  lukem 	if ( rs->sr_err != LDAP_SUCCESS ) {
    111      1.1  lukem 		send_ldap_result( op, rs );
    112      1.1  lukem 	}
    113      1.1  lukem 
    114      1.1  lukem 	Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 );
    115      1.1  lukem 
    116      1.1  lukem 	return rs->sr_err;
    117      1.1  lukem }
    118      1.1  lukem 
    119