Back to index

openldap  2.4.31
bind.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 1999 Dmitry Kovalev.
00006  * Portions Copyright 2002 Pierangelo Masarati.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by Dmitry Kovalev for inclusion
00019  * by OpenLDAP Software.  Additional significant contributors include
00020  * Pierangelo Masarati.
00021  */
00022 
00023 #include "portable.h"
00024 
00025 #include <stdio.h>
00026 #include <sys/types.h>
00027 
00028 #include "slap.h"
00029 #include "proto-sql.h"
00030 
00031 int 
00032 backsql_bind( Operation *op, SlapReply *rs )
00033 {
00034        SQLHDBC                     dbh = SQL_NULL_HDBC;
00035        Entry                e = { 0 };
00036        Attribute            *a;
00037        backsql_srch_info    bsi = { 0 };
00038        AttributeName        anlist[2];
00039        int                  rc;
00040  
00041        Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
00042 
00043        switch ( be_rootdn_bind( op, rs ) ) {
00044        case SLAP_CB_CONTINUE:
00045               break;
00046 
00047        default:
00048               /* in case of success, front end will send result;
00049                * otherwise, be_rootdn_bind() did */
00050               Debug( LDAP_DEBUG_TRACE, "<==backsql_bind(%d)\n",
00051                      rs->sr_err, 0, 0 );
00052               return rs->sr_err;
00053        }
00054 
00055        rs->sr_err = backsql_get_db_conn( op, &dbh );
00056        if ( rs->sr_err != LDAP_SUCCESS ) {
00057               Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
00058                      "could not get connection handle - exiting\n",
00059                      0, 0, 0 );
00060 
00061               rs->sr_text = ( rs->sr_err == LDAP_OTHER )
00062                      ? "SQL-backend error" : NULL;
00063               goto error_return;
00064        }
00065 
00066        anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
00067        anlist[0].an_desc = slap_schema.si_ad_userPassword;
00068        anlist[1].an_name.bv_val = NULL;
00069 
00070        bsi.bsi_e = &e;
00071        rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
00072                      (time_t)(-1), NULL, dbh, op, rs, anlist,
00073                      BACKSQL_ISF_GET_ENTRY );
00074        if ( rc != LDAP_SUCCESS ) {
00075               Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
00076                      "could not retrieve bindDN ID - no such entry\n", 
00077                      0, 0, 0 );
00078               rs->sr_err = LDAP_INVALID_CREDENTIALS;
00079               goto error_return;
00080        }
00081 
00082        a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
00083        if ( a == NULL ) {
00084               rs->sr_err = LDAP_INVALID_CREDENTIALS;
00085               goto error_return;
00086        }
00087 
00088        if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
00089                             &rs->sr_text ) != 0 )
00090        {
00091               rs->sr_err = LDAP_INVALID_CREDENTIALS;
00092               goto error_return;
00093        }
00094 
00095 error_return:;
00096        if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
00097               (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
00098        }
00099 
00100        if ( !BER_BVISNULL( &e.e_nname ) ) {
00101               backsql_entry_clean( op, &e );
00102        }
00103 
00104        if ( bsi.bsi_attrs != NULL ) {
00105               op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
00106        }
00107 
00108        if ( rs->sr_err != LDAP_SUCCESS ) {
00109               send_ldap_result( op, rs );
00110        }
00111        
00112        Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 );
00113 
00114        return rs->sr_err;
00115 }
00116