]> git.sur5r.net Git - openldap/blob - servers/slapd/back-wt/bind.c
Merge remote-tracking branch 'origin/mdb.RE/0.9'
[openldap] / servers / slapd / back-wt / bind.c
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2002-2017 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
18  * based on back-bdb for inclusion in OpenLDAP Software.
19  * WiredTiger is a product of MongoDB Inc.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include "back-wt.h"
26 #include "config.h"
27
28 int
29 wt_bind( Operation *op, SlapReply *rs )
30 {
31     struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
32         WT_SESSION *session;
33         wt_ctx *wc;
34         int rc;
35         Entry *e = NULL;
36         Attribute *a;
37         AttributeDescription *password = slap_schema.si_ad_userPassword;
38
39     Debug( LDAP_DEBUG_ARGS,
40                    "==> " LDAP_XSTRING(wt_bind) ": dn: %s\n",
41                    op->o_req_dn.bv_val, 0, 0);
42
43         /* allow noauth binds */
44         switch ( be_rootdn_bind( op, NULL ) ) {
45         case LDAP_SUCCESS:
46         /* frontend will send result */
47         return rs->sr_err = LDAP_SUCCESS;
48
49     default:
50         /* give the database a chance */
51         /* NOTE: this behavior departs from that of other backends,
52          * since the others, in case of password checking failure
53          * do not give the database a chance.  If an entry with
54          * rootdn's name does not exist in the database the result
55          * will be the same.  See ITS#4962 for discussion. */
56         break;
57         }
58
59         wc = wt_ctx_get(op, wi);
60         if( !wc ){
61                 Debug( LDAP_DEBUG_ANY,
62                            LDAP_XSTRING(wt_bind)
63                            ": wt_ctx_get failed\n",
64                            0, 0, 0 );
65                 rs->sr_err = LDAP_OTHER;
66                 rs->sr_text = "internal error";
67         send_ldap_result( op, rs );
68         return rs->sr_err;
69         }
70
71         /* get entry */
72         rc = wt_dn2entry(op->o_bd, wc, &op->o_req_ndn, &e);
73         switch( rc ) {
74         case 0:
75                 break;
76         case WT_NOTFOUND:
77                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
78                 send_ldap_result( op, rs );
79                 return rs->sr_err;
80         default:
81                 rs->sr_err = LDAP_OTHER;
82                 rs->sr_text = "internal error";
83         send_ldap_result( op, rs );
84         return rs->sr_err;
85         }
86
87         ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
88
89     /* check for deleted */
90         if ( is_entry_subentry( e ) ) {
91         /* entry is an subentry, don't allow bind */
92                 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n", 0,
93                            0, 0 );
94                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
95                 goto done;
96         }
97
98         if ( is_entry_alias( e ) ) {
99         /* entry is an alias, don't allow bind */
100                 Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
101                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
102                 goto done;
103         }
104
105         if ( is_entry_referral( e ) ) {
106                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
107                            0, 0 );
108                 rs->sr_err = LDAP_INVALID_CREDENTIALS;
109                 goto done;
110         }
111
112         switch ( op->oq_bind.rb_method ) {
113         case LDAP_AUTH_SIMPLE:
114                 a = attr_find( e->e_attrs, password );
115                 if ( a == NULL ) {
116                         rs->sr_err = LDAP_INVALID_CREDENTIALS;
117                         goto done;
118                 }
119
120                 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
121                                                                 &rs->sr_text ) != 0 )
122                 {
123             /* failure; stop front end from sending result */
124                         rs->sr_err = LDAP_INVALID_CREDENTIALS;
125                         goto done;
126                 }
127                 rs->sr_err = 0;
128                 break;
129
130     default:
131                 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
132                 rs->sr_text = "authentication method not supported";
133         }
134
135 done:
136         /* free entry */
137         if (e) {
138                 wt_entry_return(e);
139         }
140         if (rs->sr_err) {
141                 send_ldap_result( op, rs );
142         if ( rs->sr_ref ) {
143             ber_bvarray_free( rs->sr_ref );
144                         rs->sr_ref = NULL;
145                 }
146         }
147         return rs->sr_err;
148 }
149
150 /*
151  * Local variables:
152  * indent-tabs-mode: t
153  * tab-width: 4
154  * c-basic-offset: 4
155  * End:
156  */