]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/bind.c
apparently Oracle does not support AS in joins (ITS#2642)
[openldap] / servers / slapd / back-sql / bind.c
1 /*
2  *       Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
3  *
4  *       Redistribution and use in source and binary forms are permitted only
5  *       as authorized by the OpenLDAP Public License.  A copy of this
6  *       license is available at http://www.OpenLDAP.org/license.html or
7  *       in file LICENSE in the top-level directory of the distribution.
8  */
9
10 #include "portable.h"
11
12 #ifdef SLAPD_SQL
13
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include "slap.h"
17 #include "back-sql.h"
18 #include "sql-wrap.h"
19 #include "util.h"
20 #include "entry-id.h"
21
22 int 
23 backsql_bind( Operation *op, SlapReply *rs )
24 {
25         backsql_info            *bi = (backsql_info*)op->o_bd->be_private;
26         backsql_entryID         user_id;
27         SQLHDBC                 dbh;
28         AttributeDescription    *password = slap_schema.si_ad_userPassword;
29         Entry                   *e, user_entry;
30         Attribute               *a;
31         backsql_srch_info       bsi;
32         AttributeName           anlist[2];
33         int                     rc;
34  
35         Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
36
37         if ( be_isroot_pw( op ) ) {
38                 ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
39                 Debug( LDAP_DEBUG_TRACE, "<==backsql_bind() root bind\n", 
40                                 0, 0, 0 );
41                 return 0;
42         }
43
44         ber_dupbv( &op->oq_bind.rb_edn, &op->o_req_ndn );
45
46         if ( op->oq_bind.rb_method != LDAP_AUTH_SIMPLE ) {
47                 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
48                 rs->sr_text = "authentication method not supported"; 
49                 send_ldap_result( op, rs );
50                 return 1;
51         }
52
53         /*
54          * method = LDAP_AUTH_SIMPLE
55          */
56         rs->sr_err = backsql_get_db_conn( op, &dbh );
57         if (!dbh) {
58                 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
59                         "could not get connection handle - exiting\n",
60                         0, 0, 0 );
61
62                 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
63                         ? "SQL-backend error" : NULL;
64                 send_ldap_result( op, rs );
65                 return 1;
66         }
67
68         rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
69         if ( rc != LDAP_SUCCESS ) {
70                 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
71                         "could not retrieve bind dn id - no such entry\n", 
72                         0, 0, 0 );
73                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
74                 send_ldap_result( op, rs );
75                 return 1;
76         }
77
78         anlist[0].an_name = password->ad_cname;
79         anlist[0].an_desc = password;
80         anlist[1].an_name.bv_val = NULL;
81         backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
82                         -1, -1, -1, NULL, dbh, op, anlist );
83         e = backsql_id2entry( &bsi, &user_entry, &user_id );
84         if ( e == NULL ) {
85                 Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
86                         "error in backsql_id2entry() - auth failed\n",
87                         0, 0, 0 );
88                 rs->sr_err = LDAP_OTHER;
89                 send_ldap_result( op, rs );
90                 return 1;
91         }
92
93         if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) {
94                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
95                 send_ldap_result( op, rs );
96                 return 1;
97         }
98
99         if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) {
100                 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
101                 send_ldap_result( op, rs );
102                 return 1;
103         }
104
105         if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) {
106                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
107                 send_ldap_result( op, rs );
108                 return 1;
109         }
110
111         Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
112         return 0;
113 }
114  
115 #endif /* SLAPD_SQL */
116