Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : auth functions
5 :
6 : Copyright (C) Simo Sorce 2005
7 : Copyright (C) Andrew Tridgell 2005
8 : Copyright (C) Andrew Bartlett 2005
9 :
10 : This program is free software; you can redistribute it and/or modify
11 : it under the terms of the GNU General Public License as published by
12 : the Free Software Foundation; either version 3 of the License, or
13 : (at your option) any later version.
14 :
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 :
20 : You should have received a copy of the GNU General Public License
21 : along with this program. If not, see <http://www.gnu.org/licenses/>.
22 : */
23 :
24 : #include "includes.h"
25 : #include <tevent.h>
26 : #include "lib/util/tevent_ntstatus.h"
27 : #include "auth/auth.h"
28 : #include "dsdb/samdb/samdb.h"
29 : #include "lib/param/param.h"
30 :
31 : #undef DBGC_CLASS
32 : #define DBGC_CLASS DBGC_AUTH
33 :
34 : struct authenticate_ldap_simple_bind_state {
35 : bool using_tls;
36 : struct auth4_context *auth_context;
37 : struct auth_usersupplied_info *user_info;
38 : struct auth_session_info *session_info;
39 : };
40 :
41 : static void authenticate_ldap_simple_bind_done(struct tevent_req *subreq);
42 :
43 374 : _PUBLIC_ struct tevent_req *authenticate_ldap_simple_bind_send(TALLOC_CTX *mem_ctx,
44 : struct tevent_context *ev,
45 : struct imessaging_context *msg,
46 : struct loadparm_context *lp_ctx,
47 : struct tsocket_address *remote_address,
48 : struct tsocket_address *local_address,
49 : bool using_tls,
50 : const char *dn,
51 : const char *password)
52 : {
53 374 : struct tevent_req *req = NULL;
54 374 : struct authenticate_ldap_simple_bind_state *state = NULL;
55 374 : struct auth_usersupplied_info *user_info = NULL;
56 374 : const char *nt4_domain = NULL;
57 374 : const char *nt4_username = NULL;
58 374 : struct tevent_req *subreq = NULL;
59 : NTSTATUS status;
60 :
61 374 : req = tevent_req_create(mem_ctx, &state,
62 : struct authenticate_ldap_simple_bind_state);
63 374 : if (req == NULL) {
64 0 : return NULL;
65 : }
66 374 : state->using_tls = using_tls;
67 :
68 374 : status = auth_context_create(state, ev, msg, lp_ctx,
69 374 : &state->auth_context);
70 374 : if (tevent_req_nterror(req, status)) {
71 0 : return tevent_req_post(req, ev);
72 : }
73 :
74 374 : user_info = talloc_zero(state, struct auth_usersupplied_info);
75 374 : if (tevent_req_nomem(user_info, req)) {
76 0 : return tevent_req_post(req, ev);
77 : }
78 374 : state->user_info = user_info;
79 :
80 374 : user_info->client.account_name = dn;
81 : /* No client.domain_name, use account_name instead */
82 : /* user_info->mapped.* will be filled below */
83 :
84 374 : user_info->workstation_name = lpcfg_netbios_name(lp_ctx);
85 :
86 374 : user_info->remote_host = remote_address;
87 374 : user_info->local_host = local_address;
88 :
89 374 : user_info->service_description = "LDAP";
90 :
91 374 : if (using_tls) {
92 336 : user_info->auth_description = "simple bind/TLS";
93 : } else {
94 38 : user_info->auth_description = "simple bind";
95 : }
96 :
97 374 : user_info->password_state = AUTH_PASSWORD_PLAIN;
98 374 : user_info->password.plaintext = talloc_strdup(user_info, password);
99 374 : if (tevent_req_nomem(user_info->password.plaintext, req)) {
100 0 : return tevent_req_post(req, ev);
101 : }
102 :
103 374 : user_info->flags = USER_INFO_CASE_INSENSITIVE_USERNAME |
104 : USER_INFO_DONT_CHECK_UNIX_ACCOUNT;
105 :
106 374 : user_info->logon_parameters =
107 : MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
108 : MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
109 : MSV1_0_CLEARTEXT_PASSWORD_ALLOWED |
110 : MSV1_0_CLEARTEXT_PASSWORD_SUPPLIED;
111 :
112 374 : status = crack_auto_name_to_nt4_name(state, state->auth_context->sam_ctx,
113 : dn, &nt4_domain, &nt4_username);
114 374 : if (!NT_STATUS_IS_OK(status)) {
115 3 : log_authentication_event(msg, lp_ctx,
116 3 : &state->auth_context->start_time,
117 : user_info, status,
118 : NULL, NULL, NULL);
119 : }
120 374 : if (tevent_req_nterror(req, status)) {
121 3 : return tevent_req_post(req, ev);
122 : }
123 :
124 371 : user_info->orig_client = user_info->client;
125 371 : user_info->client.account_name = nt4_username;
126 371 : user_info->client.domain_name = nt4_domain;
127 371 : user_info->cracknames_called = true;
128 :
129 371 : subreq = auth_check_password_send(state, ev,
130 371 : state->auth_context,
131 371 : state->user_info);
132 371 : if (tevent_req_nomem(subreq, req)) {
133 0 : return tevent_req_post(req, ev);
134 : }
135 371 : tevent_req_set_callback(subreq, authenticate_ldap_simple_bind_done, req);
136 :
137 371 : return req;
138 : }
139 :
140 371 : static void authenticate_ldap_simple_bind_done(struct tevent_req *subreq)
141 : {
142 : struct tevent_req *req =
143 371 : tevent_req_callback_data(subreq,
144 : struct tevent_req);
145 : struct authenticate_ldap_simple_bind_state *state =
146 371 : tevent_req_data(req,
147 : struct authenticate_ldap_simple_bind_state);
148 371 : struct auth4_context *auth_context = state->auth_context;
149 371 : struct auth_usersupplied_info *user_info = state->user_info;
150 371 : const char *nt4_username = user_info->mapped.account_name;
151 371 : const struct tsocket_address *remote_address = user_info->remote_host;
152 371 : const struct tsocket_address *local_address = user_info->local_host;
153 371 : const char *transport_protection = AUTHZ_TRANSPORT_PROTECTION_NONE;
154 371 : struct auth_user_info_dc *user_info_dc = NULL;
155 371 : uint8_t authoritative = 1;
156 371 : uint32_t flags = 0;
157 : NTSTATUS nt_status;
158 :
159 371 : if (state->using_tls) {
160 333 : transport_protection = AUTHZ_TRANSPORT_PROTECTION_TLS;
161 : }
162 :
163 371 : nt_status = auth_check_password_recv(subreq, state,
164 : &user_info_dc,
165 : &authoritative);
166 371 : TALLOC_FREE(subreq);
167 371 : if (tevent_req_nterror(req, nt_status)) {
168 88 : return;
169 : }
170 :
171 283 : flags = AUTH_SESSION_INFO_DEFAULT_GROUPS;
172 283 : if (user_info_dc->info->authenticated) {
173 279 : flags |= AUTH_SESSION_INFO_AUTHENTICATED;
174 : }
175 :
176 283 : nt_status = auth_context->generate_session_info(auth_context,
177 : state,
178 : user_info_dc,
179 : nt4_username,
180 : flags,
181 : &state->session_info);
182 283 : if (tevent_req_nterror(req, nt_status)) {
183 0 : return;
184 : }
185 :
186 283 : log_successful_authz_event(auth_context->msg_ctx,
187 : auth_context->lp_ctx,
188 : remote_address,
189 : local_address,
190 : "LDAP",
191 : "simple bind",
192 : transport_protection,
193 : state->session_info);
194 :
195 283 : tevent_req_done(req);
196 : }
197 :
198 374 : _PUBLIC_ NTSTATUS authenticate_ldap_simple_bind_recv(struct tevent_req *req,
199 : TALLOC_CTX *mem_ctx,
200 : struct auth_session_info **session_info)
201 : {
202 : struct authenticate_ldap_simple_bind_state *state =
203 374 : tevent_req_data(req,
204 : struct authenticate_ldap_simple_bind_state);
205 : NTSTATUS status;
206 :
207 374 : *session_info = NULL;
208 :
209 374 : if (tevent_req_is_nterror(req, &status)) {
210 91 : tevent_req_received(req);
211 91 : return status;
212 : }
213 :
214 283 : *session_info = talloc_move(mem_ctx, &state->session_info);
215 283 : tevent_req_received(req);
216 283 : return NT_STATUS_OK;
217 : }
|