Debian Codegraph @

servers/slapd/back-wt/bind.c

raw
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2002-2024 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 <[email protected]>
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 "slap-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_ctx *wc;
33 int rc;
34 Entry *e = NULL;
35 Attribute *a;
36 AttributeDescription *password = slap_schema.si_ad_userPassword;
37
38 Debug( LDAP_DEBUG_ARGS, "==> wt_bind: dn: %s\n",
39 op->o_req_dn.bv_val );
40
41 /* allow noauth binds */
42 switch ( be_rootdn_bind( op, NULL ) ) {
43 case LDAP_SUCCESS:
44 /* frontend will send result */
45 return rs->sr_err = LDAP_SUCCESS;
46
47 default:
48 /* give the database a chance */
49 /* NOTE: this behavior departs from that of other backends,
50 * since the others, in case of password checking failure
51 * do not give the database a chance. If an entry with
52 * rootdn's name does not exist in the database the result
53 * will be the same. See ITS#4962 for discussion. */
54 break;
55 }
56
57 wc = wt_ctx_get(op, wi);
58 if( !wc ){
59 Debug( LDAP_DEBUG_ANY,
60 "wt_bind: wt_ctx_get failed\n" );
61 rs->sr_err = LDAP_OTHER;
62 rs->sr_text = "internal error";
63 send_ldap_result( op, rs );
64 return rs->sr_err;
65 }
66
67 /* get entry */
68 rc = wt_dn2entry(op->o_bd, wc, &op->o_req_ndn, &e);
69 switch( rc ) {
70 case 0:
71 break;
72 case WT_NOTFOUND:
73 rs->sr_err = LDAP_INVALID_CREDENTIALS;
74 send_ldap_result( op, rs );
75 return rs->sr_err;
76 default:
77 rs->sr_err = LDAP_OTHER;
78 rs->sr_text = "internal error";
79 send_ldap_result( op, rs );
80 return rs->sr_err;
81 }
82
83 ber_dupbv( &op->oq_bind.rb_edn, &e->e_name );
84
85 /* check for deleted */
86 if ( is_entry_subentry( e ) ) {
87 /* entry is an subentry, don't allow bind */
88 Debug( LDAP_DEBUG_TRACE, "entry is subentry\n" );
89 rs->sr_err = LDAP_INVALID_CREDENTIALS;
90 goto done;
91 }
92
93 if ( is_entry_alias( e ) ) {
94 /* entry is an alias, don't allow bind */
95 Debug( LDAP_DEBUG_TRACE, "entry is alias\n" );
96 rs->sr_err = LDAP_INVALID_CREDENTIALS;
97 goto done;
98 }
99
100 if ( is_entry_referral( e ) ) {
101 Debug( LDAP_DEBUG_TRACE, "entry is referral\n" );
102 rs->sr_err = LDAP_INVALID_CREDENTIALS;
103 goto done;
104 }
105
106 switch ( op->oq_bind.rb_method ) {
107 case LDAP_AUTH_SIMPLE:
108 a = attr_find( e->e_attrs, password );
109 if ( a == NULL ) {
110 rs->sr_err = LDAP_INVALID_CREDENTIALS;
111 goto done;
112 }
113
114 if ( slap_passwd_check( op, e, a, &op->oq_bind.rb_cred,
115 &rs->sr_text ) != 0 )
116 {
117 /* failure; stop front end from sending result */
118 rs->sr_err = LDAP_INVALID_CREDENTIALS;
119 goto done;
120 }
121 rs->sr_err = 0;
122 break;
123
124 default:
125 rs->sr_err = LDAP_STRONG_AUTH_NOT_SUPPORTED;
126 rs->sr_text = "authentication method not supported";
127 }
128
129 done:
130 /* free entry */
131 if (e) {
132 wt_entry_return(e);
133 }
134 if (rs->sr_err) {
135 send_ldap_result( op, rs );
136 if ( rs->sr_ref ) {
137 ber_bvarray_free( rs->sr_ref );
138 rs->sr_ref = NULL;
139 }
140 }
141 return rs->sr_err;
142 }
143
144 /*
145 * Local variables:
146 * indent-tabs-mode: t
147 * tab-width: 4
148 * c-basic-offset: 4
149 * End:
150 */