2 Unix SMB/CIFS implementation.
4 Authenticate a user to a domain controller
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
7 Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "librpc/gen_ndr/ndr_netlogon.h"
26 #include "include/secrets.h"
27 #include "lib/ldb/include/ldb.h"
28 #include "auth/auth.h"
30 /* Authenticate a user with a challenge/response */
31 static NTSTATUS domain_check_password(struct auth_method_context *ctx,
33 const struct auth_usersupplied_info *user_info,
34 struct auth_serversupplied_info **server_info)
38 struct dcerpc_pipe *p;
39 struct dcerpc_binding *b;
40 struct netr_LogonSamLogon r;
41 struct netr_Authenticator auth, auth2;
42 struct netr_NetworkInfo ninfo;
44 struct creds_CredentialState *creds;
45 struct cli_credentials *credentials;
47 const char **bindings = lp_passwordserver();
50 if (bindings && bindings[0]) {
51 binding = bindings[0];
54 if (!user_info->account_name) {
55 return NT_STATUS_INVALID_PARAMETER;
57 if (!user_info->workstation_name) {
58 return NT_STATUS_INVALID_PARAMETER;
61 credentials = cli_credentials_init(mem_ctx);
62 cli_credentials_set_conf(credentials);
63 status = cli_credentials_set_machine_account(credentials);
65 if (!NT_STATUS_IS_OK(status)) {
69 /* Connect to DC (take a binding string for now) */
71 status = dcerpc_parse_binding(mem_ctx, binding, &b);
72 if (!NT_STATUS_IS_OK(status)) {
73 printf("Bad binding string %s\n", binding);
74 return NT_STATUS_INVALID_PARAMETER;
77 /* We like schannel */
78 b->flags &= ~DCERPC_AUTH_OPTIONS;
79 b->flags |= DCERPC_SCHANNEL_WORKSTATION | DCERPC_SEAL | DCERPC_SCHANNEL_128;
82 status = dcerpc_pipe_connect_b(mem_ctx, &p, b,
84 DCERPC_NETLOGON_VERSION,
87 if (!NT_STATUS_IS_OK(status)) {
91 /* call domain logon */
93 status = dcerpc_schannel_creds(p->conn->security_state.generic_state, mem_ctx, &creds);
94 if (!NT_STATUS_IS_OK(status)) {
98 ninfo.identity_info.domain_name.string = user_info->domain_name;
99 ninfo.identity_info.parameter_control = 0;
100 ninfo.identity_info.logon_id_low = 0;
101 ninfo.identity_info.logon_id_high = 0;
102 ninfo.identity_info.account_name.string = user_info->account_name;
103 ninfo.identity_info.workstation.string = user_info->workstation_name;
104 memcpy(ninfo.challenge, ctx->auth_ctx->challenge.data.data, sizeof(ninfo.challenge));
106 ninfo.nt.length = user_info->nt_resp.length;
107 ninfo.nt.data = user_info->nt_resp.data;
108 ninfo.lm.length = user_info->lm_resp.length;
109 ninfo.lm.data = user_info->lm_resp.data;
111 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
112 r.in.workstation = cli_credentials_get_workstation(credentials);
113 r.in.credential = &auth;
114 r.in.return_authenticator = &auth2;
115 r.in.logon_level = 2;
116 r.in.logon.network = &ninfo;
117 r.in.validation_level = 3;
120 creds_client_authenticator(creds, &auth);
122 status = dcerpc_netr_LogonSamLogon(p, mem_ctx, &r);
124 if (!creds_client_check(creds, &r.out.return_authenticator->cred)) {
125 DEBUG(1, ("Credential chaining failed\n"));
126 return NT_STATUS_ACCESS_DENIED;
129 /* make server info */
131 if (!NT_STATUS_IS_OK(status)) {
135 status = make_server_info_netlogon_validation(mem_ctx,
136 user_info->account_name,
137 r.in.validation_level, &r.out.validation,
142 static const struct auth_operations domain_ops = {
144 .get_challenge = auth_get_challenge_not_implemented,
145 .check_password = domain_check_password
148 NTSTATUS auth_domain_init(void)
152 ret = auth_register(&domain_ops);
153 if (!NT_STATUS_IS_OK(ret)) {
154 DEBUG(0,("Failed to register 'domain' auth backend!\n"));