s3: Fix wbinfo socket dir path.
[Samba/gebeck_regimport.git] / source3 / rpc_server / dcesrv_ntlmssp.c
blobe03b3357f325523d851a15ec5118dbe72e41cdc7
1 /*
2 * NTLMSSP Acceptor
3 * DCERPC Server functions
4 * Copyright (C) Simo Sorce 2010.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "rpc_server/dcesrv_ntlmssp.h"
23 #include "../auth/ntlmssp/ntlmssp.h"
24 #include "ntlmssp_wrap.h"
25 #include "auth.h"
26 #include "auth/gensec/gensec.h"
28 NTSTATUS ntlmssp_server_auth_start(TALLOC_CTX *mem_ctx,
29 bool do_sign,
30 bool do_seal,
31 bool is_dcerpc,
32 DATA_BLOB *token_in,
33 DATA_BLOB *token_out,
34 const struct tsocket_address *remote_address,
35 struct gensec_security **ctx)
37 struct auth_ntlmssp_state *a = NULL;
38 NTSTATUS status;
40 status = auth_ntlmssp_prepare(remote_address, &a);
41 if (!NT_STATUS_IS_OK(status)) {
42 DEBUG(0, (__location__ ": auth_ntlmssp_prepare failed: %s\n",
43 nt_errstr(status)));
44 return status;
47 if (do_sign) {
48 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SIGN);
50 if (do_seal) {
51 /* Always implies both sign and seal for ntlmssp */
52 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SEAL);
55 status = auth_ntlmssp_start(a);
56 if (!NT_STATUS_IS_OK(status)) {
57 DEBUG(0, (__location__ ": auth_ntlmssp_start failed: %s\n",
58 nt_errstr(status)));
59 return status;
62 status = gensec_update(a->gensec_security, mem_ctx, NULL, *token_in, token_out);
63 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
64 DEBUG(0, (__location__ ": auth_ntlmssp_update failed: %s\n",
65 nt_errstr(status)));
66 goto done;
69 /* steal ntlmssp context too */
70 *ctx = talloc_move(mem_ctx, &a->gensec_security);
72 status = NT_STATUS_OK;
74 done:
75 TALLOC_FREE(a);
77 return status;
80 NTSTATUS ntlmssp_server_step(struct gensec_security *gensec_security,
81 TALLOC_CTX *mem_ctx,
82 DATA_BLOB *token_in,
83 DATA_BLOB *token_out)
85 NTSTATUS status;
87 /* this has to be done as root in order to verify the password */
88 become_root();
89 status = gensec_update(gensec_security, mem_ctx, NULL, *token_in, token_out);
90 unbecome_root();
92 return status;
95 NTSTATUS ntlmssp_server_check_flags(struct gensec_security *gensec_security,
96 bool do_sign, bool do_seal)
98 if (do_sign && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SIGN)) {
99 DEBUG(1, (__location__ "Integrity was requested but client "
100 "failed to negotiate signing.\n"));
101 return NT_STATUS_ACCESS_DENIED;
104 if (do_seal && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SEAL)) {
105 DEBUG(1, (__location__ "Privacy was requested but client "
106 "failed to negotiate sealing.\n"));
107 return NT_STATUS_ACCESS_DENIED;
110 return NT_STATUS_OK;
113 NTSTATUS ntlmssp_server_get_user_info(struct gensec_security *gensec_security,
114 TALLOC_CTX *mem_ctx,
115 struct auth_session_info **session_info)
117 NTSTATUS status;
119 status = gensec_session_info(gensec_security, mem_ctx, session_info);
120 if (!NT_STATUS_IS_OK(status)) {
121 DEBUG(1, (__location__ ": Failed to get authenticated user "
122 "info: %s\n", nt_errstr(status)));
123 return status;
126 DEBUG(5, (__location__ "OK: user: %s domain: %s\n",
127 (*session_info)->info->account_name,
128 (*session_info)->info->domain_name));
130 return NT_STATUS_OK;