lib/param: use strwicmp instead of strlower_talloc
[Samba.git] / source3 / libsmb / ntlmssp_wrap.c
blob46f68aede79271e189a883e06f4e411d6fd64cc4
1 /*
2 NLTMSSP wrappers
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Andrew Bartlett 2001-2003,2011
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "auth/ntlmssp/ntlmssp.h"
23 #include "auth/ntlmssp/ntlmssp_private.h"
24 #include "auth_generic.h"
25 #include "auth/gensec/gensec.h"
26 #include "auth/gensec/gensec_internal.h"
27 #include "auth/credentials/credentials.h"
28 #include "librpc/rpc/dcerpc.h"
29 #include "lib/param/param.h"
31 static NTSTATUS gensec_ntlmssp3_client_update(struct gensec_security *gensec_security,
32 TALLOC_CTX *out_mem_ctx,
33 struct tevent_context *ev,
34 const DATA_BLOB request,
35 DATA_BLOB *reply)
37 NTSTATUS status;
38 struct gensec_ntlmssp_context *gensec_ntlmssp =
39 talloc_get_type_abort(gensec_security->private_data,
40 struct gensec_ntlmssp_context);
42 status = ntlmssp_update(gensec_ntlmssp->ntlmssp_state, request, reply);
43 if (NT_STATUS_IS_OK(status) ||
44 NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
45 talloc_steal(out_mem_ctx, reply->data);
48 return status;
51 static NTSTATUS gensec_ntlmssp3_client_start(struct gensec_security *gensec_security)
53 NTSTATUS nt_status;
54 struct gensec_ntlmssp_context *gensec_ntlmssp;
55 const char *user, *domain;
56 const char *password;
58 nt_status = gensec_ntlmssp_start(gensec_security);
59 NT_STATUS_NOT_OK_RETURN(nt_status);
61 gensec_ntlmssp =
62 talloc_get_type_abort(gensec_security->private_data,
63 struct gensec_ntlmssp_context);
65 nt_status = ntlmssp_client_start(gensec_ntlmssp,
66 lp_netbios_name(), lp_workgroup(),
67 lp_client_ntlmv2_auth(), &gensec_ntlmssp->ntlmssp_state);
68 if (!NT_STATUS_IS_OK(nt_status)) {
69 return nt_status;
72 cli_credentials_get_ntlm_username_domain(gensec_security->credentials, gensec_ntlmssp, &user, &domain);
73 if (!user || !domain) {
74 return NT_STATUS_NO_MEMORY;
77 nt_status = ntlmssp_set_username(gensec_ntlmssp->ntlmssp_state, user);
78 if (!NT_STATUS_IS_OK(nt_status)) {
79 return nt_status;
82 nt_status = ntlmssp_set_domain(gensec_ntlmssp->ntlmssp_state, domain);
83 if (!NT_STATUS_IS_OK(nt_status)) {
84 return nt_status;
87 password = cli_credentials_get_password(gensec_security->credentials);
88 if (!password) {
89 return NT_STATUS_NO_MEMORY;
92 nt_status = ntlmssp_set_password(gensec_ntlmssp->ntlmssp_state, password);
93 if (!NT_STATUS_IS_OK(nt_status)) {
94 return nt_status;
97 if (gensec_security->want_features & GENSEC_FEATURE_SESSION_KEY) {
98 gensec_ntlmssp->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
100 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
101 gensec_ntlmssp->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
103 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
104 gensec_ntlmssp->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
105 gensec_ntlmssp->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
108 return NT_STATUS_OK;
111 static const char *gensec_ntlmssp3_client_oids[] = {
112 GENSEC_OID_NTLMSSP,
113 NULL
116 const struct gensec_security_ops gensec_ntlmssp3_client_ops = {
117 .name = "ntlmssp3_client",
118 .sasl_name = GENSEC_SASL_NAME_NTLMSSP, /* "NTLM" */
119 .auth_type = DCERPC_AUTH_TYPE_NTLMSSP,
120 .oid = gensec_ntlmssp3_client_oids,
121 .client_start = gensec_ntlmssp3_client_start,
122 .magic = gensec_ntlmssp_magic,
123 .update = gensec_ntlmssp3_client_update,
124 .sig_size = gensec_ntlmssp_sig_size,
125 .sign_packet = gensec_ntlmssp_sign_packet,
126 .check_packet = gensec_ntlmssp_check_packet,
127 .seal_packet = gensec_ntlmssp_seal_packet,
128 .unseal_packet = gensec_ntlmssp_unseal_packet,
129 .wrap = gensec_ntlmssp_wrap,
130 .unwrap = gensec_ntlmssp_unwrap,
131 .session_key = gensec_ntlmssp_session_key,
132 .have_feature = gensec_ntlmssp_have_feature,
133 .enabled = true,
134 .priority = GENSEC_NTLMSSP