2 Unix SMB/Netbios implementation.
4 handle NLTMSSP, server side
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2001-2003,2011
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "../auth/ntlmssp/ntlmssp.h"
26 #include "ntlmssp_wrap.h"
27 #include "../librpc/gen_ndr/netlogon.h"
28 #include "../librpc/gen_ndr/dcerpc.h"
29 #include "../lib/tsocket/tsocket.h"
30 #include "auth/gensec/gensec.h"
31 #include "librpc/rpc/dcerpc.h"
32 #include "lib/param/param.h"
34 NTSTATUS auth_generic_prepare(const struct tsocket_address *remote_address,
35 struct auth_generic_state **auth_ntlmssp_state)
37 struct auth_context *auth_context;
38 struct auth_generic_state *ans;
41 ans = talloc_zero(NULL, struct auth_generic_state);
43 DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
44 return NT_STATUS_NO_MEMORY;
47 nt_status = make_auth_context_subsystem(talloc_tos(), &auth_context);
48 if (!NT_STATUS_IS_OK(nt_status)) {
53 ans->auth_context = talloc_steal(ans, auth_context);
55 if (auth_context->prepare_gensec) {
56 nt_status = auth_context->prepare_gensec(ans,
57 &ans->gensec_security);
58 if (!NT_STATUS_IS_OK(nt_status)) {
62 *auth_ntlmssp_state = ans;
65 struct gensec_settings *gensec_settings;
66 struct loadparm_context *lp_ctx;
68 lp_ctx = loadparm_init_s3(ans, loadparm_s3_context());
70 DEBUG(10, ("loadparm_init_s3 failed\n"));
72 return NT_STATUS_INVALID_SERVER_STATE;
75 gensec_settings = lpcfg_gensec_settings(ans, lp_ctx);
77 DEBUG(10, ("lpcfg_gensec_settings failed\n"));
79 return NT_STATUS_NO_MEMORY;
82 nt_status = gensec_server_start(ans, gensec_settings,
83 NULL, &ans->gensec_security);
85 if (!NT_STATUS_IS_OK(nt_status)) {
89 talloc_unlink(ans, lp_ctx);
90 talloc_unlink(ans, gensec_settings);
93 nt_status = gensec_set_remote_address(ans->gensec_security,
95 if (!NT_STATUS_IS_OK(nt_status)) {
100 *auth_ntlmssp_state = ans;
104 NTSTATUS auth_generic_start(struct auth_generic_state *auth_ntlmssp_state, const char *oid)
106 struct gensec_ntlmssp_context *gensec_ntlmssp;
109 if (auth_ntlmssp_state->auth_context->gensec_start_mech_by_oid) {
110 return auth_ntlmssp_state->auth_context->gensec_start_mech_by_oid(
111 auth_ntlmssp_state->gensec_security, oid);
114 if (strcmp(oid, GENSEC_OID_NTLMSSP) != 0) {
115 return NT_STATUS_NOT_IMPLEMENTED;
118 status = gensec_start_mech_by_ops(auth_ntlmssp_state->gensec_security,
119 &gensec_ntlmssp3_server_ops);
120 if (!NT_STATUS_IS_OK(status)) {
125 talloc_get_type_abort(auth_ntlmssp_state->gensec_security->private_data,
126 struct gensec_ntlmssp_context);
128 gensec_ntlmssp->auth_context = talloc_move(gensec_ntlmssp, &auth_ntlmssp_state->auth_context);
133 NTSTATUS auth_generic_authtype_start(struct auth_generic_state *auth_ntlmssp_state,
134 uint8_t auth_type, uint8_t auth_level)
136 struct gensec_ntlmssp_context *gensec_ntlmssp;
139 if (auth_ntlmssp_state->auth_context->gensec_start_mech_by_authtype) {
140 return auth_ntlmssp_state->auth_context->gensec_start_mech_by_authtype(
141 auth_ntlmssp_state->gensec_security,
142 auth_type, auth_level);
145 if (auth_type != DCERPC_AUTH_TYPE_NTLMSSP) {
146 /* The caller will then free the auth_ntlmssp_state,
147 * undoing what was done in auth_generic_prepare().
149 * We can't do that logic here, as
150 * auth_ntlmssp_want_feature() may have been called in
153 return NT_STATUS_NOT_IMPLEMENTED;
156 gensec_want_feature(auth_ntlmssp_state->gensec_security,
157 GENSEC_FEATURE_DCE_STYLE);
158 gensec_want_feature(auth_ntlmssp_state->gensec_security,
159 GENSEC_FEATURE_ASYNC_REPLIES);
160 if (auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
161 gensec_want_feature(auth_ntlmssp_state->gensec_security,
162 GENSEC_FEATURE_SIGN);
163 } else if (auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
164 gensec_want_feature(auth_ntlmssp_state->gensec_security,
165 GENSEC_FEATURE_SIGN);
166 gensec_want_feature(auth_ntlmssp_state->gensec_security,
167 GENSEC_FEATURE_SEAL);
168 } else if (auth_level == DCERPC_AUTH_LEVEL_CONNECT) {
169 /* Default features */
171 DEBUG(2,("auth_level %d not supported in DCE/RPC authentication\n",
173 return NT_STATUS_INVALID_PARAMETER;
176 status = gensec_start_mech_by_ops(auth_ntlmssp_state->gensec_security,
177 &gensec_ntlmssp3_server_ops);
178 if (!NT_STATUS_IS_OK(status)) {
183 talloc_get_type_abort(auth_ntlmssp_state->gensec_security->private_data,
184 struct gensec_ntlmssp_context);
186 gensec_ntlmssp->auth_context = talloc_move(gensec_ntlmssp, &auth_ntlmssp_state->auth_context);