Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-sql / bind.c
blobe0c1cd78d84fd9ce5db0d1eac6d156d202a81237
1 /* $OpenLDAP: pkg/ldap/servers/slapd/back-sql/bind.c,v 1.41.2.3 2008/02/11 23:26:48 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
6 * Portions Copyright 2002 Pierangelo Masarati.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
17 /* ACKNOWLEDGEMENTS:
18 * This work was initially developed by Dmitry Kovalev for inclusion
19 * by OpenLDAP Software. Additional significant contributors include
20 * Pierangelo Masarati.
23 #include "portable.h"
25 #include <stdio.h>
26 #include <sys/types.h>
28 #include "slap.h"
29 #include "proto-sql.h"
31 int
32 backsql_bind( Operation *op, SlapReply *rs )
34 SQLHDBC dbh = SQL_NULL_HDBC;
35 Entry e = { 0 };
36 Attribute *a;
37 backsql_srch_info bsi = { 0 };
38 AttributeName anlist[2];
39 int rc;
41 Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
43 switch ( be_rootdn_bind( op, rs ) ) {
44 case SLAP_CB_CONTINUE:
45 break;
47 default:
48 /* in case of success, front end will send result;
49 * otherwise, be_rootdn_bind() did */
50 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind(%d)\n",
51 rs->sr_err, 0, 0 );
52 return rs->sr_err;
55 rs->sr_err = backsql_get_db_conn( op, &dbh );
56 if ( rs->sr_err != LDAP_SUCCESS ) {
57 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
58 "could not get connection handle - exiting\n",
59 0, 0, 0 );
61 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
62 ? "SQL-backend error" : NULL;
63 goto error_return;
66 anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
67 anlist[0].an_desc = slap_schema.si_ad_userPassword;
68 anlist[1].an_name.bv_val = NULL;
70 bsi.bsi_e = &e;
71 rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
72 (time_t)(-1), NULL, dbh, op, rs, anlist,
73 BACKSQL_ISF_GET_ENTRY );
74 if ( rc != LDAP_SUCCESS ) {
75 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
76 "could not retrieve bindDN ID - no such entry\n",
77 0, 0, 0 );
78 rs->sr_err = LDAP_INVALID_CREDENTIALS;
79 goto error_return;
82 a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
83 if ( a == NULL ) {
84 rs->sr_err = LDAP_INVALID_CREDENTIALS;
85 goto error_return;
88 if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
89 &rs->sr_text ) != 0 )
91 rs->sr_err = LDAP_INVALID_CREDENTIALS;
92 goto error_return;
95 error_return:;
96 if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
97 (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
100 if ( !BER_BVISNULL( &e.e_nname ) ) {
101 backsql_entry_clean( op, &e );
104 if ( bsi.bsi_attrs != NULL ) {
105 op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
108 if ( rs->sr_err != LDAP_SUCCESS ) {
109 send_ldap_result( op, rs );
112 Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 );
114 return rs->sr_err;