bind.c revision 1.1.1.6 1 1.1.1.6 christos /* $NetBSD: bind.c,v 1.1.1.6 2018/02/06 01:53:18 christos Exp $ */
2 1.1.1.2 lukem
3 1.1.1.4 tron /* $OpenLDAP$ */
4 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 1.1 lukem *
6 1.1.1.6 christos * Copyright 1999-2017 The OpenLDAP Foundation.
7 1.1 lukem * Portions Copyright 1999 Dmitry Kovalev.
8 1.1 lukem * Portions Copyright 2002 Pierangelo Masarati.
9 1.1 lukem * All rights reserved.
10 1.1 lukem *
11 1.1 lukem * Redistribution and use in source and binary forms, with or without
12 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
13 1.1 lukem * Public License.
14 1.1 lukem *
15 1.1 lukem * A copy of this license is available in the file LICENSE in the
16 1.1 lukem * top-level directory of the distribution or, alternatively, at
17 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
18 1.1 lukem */
19 1.1 lukem /* ACKNOWLEDGEMENTS:
20 1.1 lukem * This work was initially developed by Dmitry Kovalev for inclusion
21 1.1 lukem * by OpenLDAP Software. Additional significant contributors include
22 1.1 lukem * Pierangelo Masarati.
23 1.1 lukem */
24 1.1 lukem
25 1.1.1.5 christos #include <sys/cdefs.h>
26 1.1.1.6 christos __RCSID("$NetBSD: bind.c,v 1.1.1.6 2018/02/06 01:53:18 christos Exp $");
27 1.1.1.5 christos
28 1.1 lukem #include "portable.h"
29 1.1 lukem
30 1.1 lukem #include <stdio.h>
31 1.1 lukem #include <sys/types.h>
32 1.1 lukem
33 1.1 lukem #include "slap.h"
34 1.1 lukem #include "proto-sql.h"
35 1.1 lukem
36 1.1 lukem int
37 1.1 lukem backsql_bind( Operation *op, SlapReply *rs )
38 1.1 lukem {
39 1.1 lukem SQLHDBC dbh = SQL_NULL_HDBC;
40 1.1 lukem Entry e = { 0 };
41 1.1 lukem Attribute *a;
42 1.1 lukem backsql_srch_info bsi = { 0 };
43 1.1 lukem AttributeName anlist[2];
44 1.1 lukem int rc;
45 1.1 lukem
46 1.1 lukem Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 );
47 1.1 lukem
48 1.1 lukem switch ( be_rootdn_bind( op, rs ) ) {
49 1.1 lukem case SLAP_CB_CONTINUE:
50 1.1 lukem break;
51 1.1 lukem
52 1.1 lukem default:
53 1.1 lukem /* in case of success, front end will send result;
54 1.1 lukem * otherwise, be_rootdn_bind() did */
55 1.1 lukem Debug( LDAP_DEBUG_TRACE, "<==backsql_bind(%d)\n",
56 1.1 lukem rs->sr_err, 0, 0 );
57 1.1 lukem return rs->sr_err;
58 1.1 lukem }
59 1.1 lukem
60 1.1 lukem rs->sr_err = backsql_get_db_conn( op, &dbh );
61 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
62 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
63 1.1 lukem "could not get connection handle - exiting\n",
64 1.1 lukem 0, 0, 0 );
65 1.1 lukem
66 1.1 lukem rs->sr_text = ( rs->sr_err == LDAP_OTHER )
67 1.1 lukem ? "SQL-backend error" : NULL;
68 1.1 lukem goto error_return;
69 1.1 lukem }
70 1.1 lukem
71 1.1 lukem anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
72 1.1 lukem anlist[0].an_desc = slap_schema.si_ad_userPassword;
73 1.1 lukem anlist[1].an_name.bv_val = NULL;
74 1.1 lukem
75 1.1 lukem bsi.bsi_e = &e;
76 1.1 lukem rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
77 1.1 lukem (time_t)(-1), NULL, dbh, op, rs, anlist,
78 1.1 lukem BACKSQL_ISF_GET_ENTRY );
79 1.1 lukem if ( rc != LDAP_SUCCESS ) {
80 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_bind(): "
81 1.1 lukem "could not retrieve bindDN ID - no such entry\n",
82 1.1 lukem 0, 0, 0 );
83 1.1 lukem rs->sr_err = LDAP_INVALID_CREDENTIALS;
84 1.1 lukem goto error_return;
85 1.1 lukem }
86 1.1 lukem
87 1.1 lukem a = attr_find( e.e_attrs, slap_schema.si_ad_userPassword );
88 1.1 lukem if ( a == NULL ) {
89 1.1 lukem rs->sr_err = LDAP_INVALID_CREDENTIALS;
90 1.1 lukem goto error_return;
91 1.1 lukem }
92 1.1 lukem
93 1.1 lukem if ( slap_passwd_check( op, &e, a, &op->oq_bind.rb_cred,
94 1.1 lukem &rs->sr_text ) != 0 )
95 1.1 lukem {
96 1.1 lukem rs->sr_err = LDAP_INVALID_CREDENTIALS;
97 1.1 lukem goto error_return;
98 1.1 lukem }
99 1.1 lukem
100 1.1 lukem error_return:;
101 1.1 lukem if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
102 1.1 lukem (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
103 1.1 lukem }
104 1.1 lukem
105 1.1 lukem if ( !BER_BVISNULL( &e.e_nname ) ) {
106 1.1 lukem backsql_entry_clean( op, &e );
107 1.1 lukem }
108 1.1 lukem
109 1.1 lukem if ( bsi.bsi_attrs != NULL ) {
110 1.1 lukem op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
111 1.1 lukem }
112 1.1 lukem
113 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
114 1.1 lukem send_ldap_result( op, rs );
115 1.1 lukem }
116 1.1 lukem
117 1.1 lukem Debug( LDAP_DEBUG_TRACE,"<==backsql_bind()\n", 0, 0, 0 );
118 1.1 lukem
119 1.1 lukem return rs->sr_err;
120 1.1 lukem }
121 1.1 lukem
122