]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/bind.c
matched values is "global"
[openldap] / servers / slapd / back-sql / bind.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2005 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
6  * Portions Copyright 2002 Pierangelo Masarati.
7  * All rights reserved.
8  *
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.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Dmitry Kovalev for inclusion
19  * by OpenLDAP Software.  Additional significant contributors include
20  * Pierangelo Masarati.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26 #include <sys/types.h>
27
28 #include "slap.h"
29 #include "proto-sql.h"
30
31 int 
32 backsql_bind( Operation *op, SlapReply *rs )
33 {
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;
40  
41         Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
42
43         if ( be_isroot_pw( op ) ) {
44                 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
45                 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n", 
46                                 0, 0, 0 );
47                 return LDAP_SUCCESS;
48         }
49
50         ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
51
52         if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
53                 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
54                 rs->sr_text = "authentication method not supported"; 
55                 send_ldap_result( op, rs );
56                 return rs->sr_err;
57         }
58
59         /*
60          * method = LDAP_AUTH_SIMPLE
61          */
62         rs->sr_err = backsql_get_db_conn( op, &dbh );
63         if ( !dbh ) {
64                 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
65                         "could not get connection handle - exiting\n",
66                         0, 0, 0 );
67
68                 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
69                         ? "SQL-backend error" : NULL;
70                 goto error_return;
71         }
72
73         anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
74         anlist[0].an_desc = slap_schema.si_ad_userPassword;
75         anlist[1].an_name.bv_val = NULL;
76
77         bsi.bsi_e = &e;
78         rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
79                         SLAP_NO_LIMIT, SLAP_NO_LIMIT,
80                         (time_t)(-1), NULL, dbh, op, rs, anlist,
81                         BACKSQL_ISF_GET_ENTRY );
82         if ( rc != LDAP_SUCCESS ) {
83                 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
84                         "could not retrieve bindDN ID - no such entry\n", 
85                         0, 0, 0 );
86                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
87                 goto error_return;
88         }
89
90         a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
91         if ( a == NULL ) {
92                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
93                 goto error_return;
94         }
95
96         if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
97                                 &rs->sr_text ) != 0 )
98         {
99                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
100                 goto error_return;
101         }
102
103 error_return:;
104         if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
105                 (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
106         }
107
108         if ( !BER_BVISNULL( &e.e_nname ) ) {
109                 entry_clean( &e );
110         }
111
112         if ( bsi.bsi_attrs != NULL ) {
113                 op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
114         }
115
116         if ( rs->sr_err != LDAP_SUCCESS ) {
117                 send_ldap_result( op, rs );
118         }
119         
120         Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 );
121
122         return rs->sr_err;
123 }
124