X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-sql%2Fbind.c;h=f87ebdd972cc2d2b48ac938c5d9c4c754e742e2b;hb=5487575086d2060ab05a408543ff07be31b400a8;hp=f7c091592d6d68e3c49f56df22548efeb2d28308;hpb=94d3673dbe25b4b5de62018a82d54126368b0b61;p=openldap diff --git a/servers/slapd/back-sql/bind.c b/servers/slapd/back-sql/bind.c index f7c091592d..f87ebdd972 100644 --- a/servers/slapd/back-sql/bind.c +++ b/servers/slapd/back-sql/bind.c @@ -1,39 +1,123 @@ -/* - * Copyright 1999, Dmitry Kovalev (zmit@mail.ru), All rights reserved. +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . * - * Redistribution and use in source and binary forms are permitted only - * as authorized by the OpenLDAP Public License. A copy of this - * license is available at http://www.OpenLDAP.org/license.html or - * in file LICENSE in the top-level directory of the distribution. + * Copyright 1999-2006 The OpenLDAP Foundation. + * Portions Copyright 1999 Dmitry Kovalev. + * Portions Copyright 2002 Pierangelo Masarati. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Dmitry Kovalev for inclusion + * by OpenLDAP Software. Additional significant contributors include + * Pierangelo Masarati. */ #include "portable.h" -#ifdef SLAPD_SQL - #include #include + #include "slap.h" -#include "back-sql.h" -#include "sql-wrap.h" +#include "proto-sql.h" -int backsql_bind(Backend *be,Connection *conn,Operation *op, - char *dn,char *ndn,int method,char *mech,struct berval *cred,char** edn) +int +backsql_bind( Operation *op, SlapReply *rs ) { - Debug(LDAP_DEBUG_TRACE,"==>backsql_bind()\n",0,0,0); - //for now, just return OK, allowing to test modify operations - send_ldap_result(conn,op,LDAP_SUCCESS,NULL,NULL,NULL,0); - Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0); - return 0; -} + SQLHDBC dbh = SQL_NULL_HDBC; + Entry e = { 0 }; + Attribute *a; + backsql_srch_info bsi = { 0 }; + AttributeName anlist[2]; + int rc; -int backsql_unbind(Backend *be,Connection *conn,Operation *op) -{ - Debug(LDAP_DEBUG_TRACE,"==>backsql_unbind()\n",0,0,0); - backsql_free_db_conn(be,conn); - send_ldap_result(conn,op,LDAP_SUCCESS,NULL,NULL,NULL,0); - Debug(LDAP_DEBUG_TRACE,"<==backsql_unbind()\n",0,0,0); - return 0; -} + Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 ); + + if ( be_isroot_pw( op ) ) { + ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n", + 0, 0, 0 ); + return LDAP_SUCCESS; + } + + ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn ); + + if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) { + rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED; + rs->sr_text = "authentication method not supported"; + send_ldap_result( op, rs ); + return rs->sr_err; + } + + /* + * method = LDAP_AUTH_SIMPLE + */ + rs->sr_err = backsql_get_db_conn( op, &dbh ); + if ( !dbh ) { + Debug( LDAP_DEBUG_TRACE, "backsql_bind(): " + "could not get connection handle - exiting\n", + 0, 0, 0 ); -#endif /* SLAPD_SQL */ \ No newline at end of file + rs->sr_text = ( rs->sr_err == LDAP_OTHER ) + ? "SQL-backend error" : NULL; + goto error_return; + } + + anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname; + anlist[0].an_desc = slap_schema.si_ad_userPassword; + anlist[1].an_name.bv_val = NULL; + + bsi.bsi_e = &e; + rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, + (time_t)(-1), NULL, dbh, op, rs, anlist, + BACKSQL_ISF_GET_ENTRY ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, "backsql_bind(): " + "could not retrieve bindDN ID - no such entry\n", + 0, 0, 0 ); + rs->sr_err = LDAP_INVALID_CREDENTIALS; + goto error_return; + } + + a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword ); + if ( a == NULL ) { + rs->sr_err = LDAP_INVALID_CREDENTIALS; + goto error_return; + } + + if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred, + &rs->sr_text ) != 0 ) + { + rs->sr_err = LDAP_INVALID_CREDENTIALS; + goto error_return; + } + +error_return:; + if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) { + (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 ); + } + + if ( !BER_BVISNULL( &e.e_nname ) ) { + backsql_entry_clean( op, &e ); + } + + if ( bsi.bsi_attrs != NULL ) { + op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx ); + } + + if ( rs->sr_err != LDAP_SUCCESS ) { + send_ldap_result( op, rs ); + } + + Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 ); + + return rs->sr_err; +} +