3 * DCERPC Server functions
4 * Copyright (C) Simo Sorce 2010.
5 * Copyright (C) Andrew Bartlett 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/>.
23 #include "rpc_server/dcesrv_auth_generic.h"
24 #include "ntlmssp_wrap.h"
26 #include "auth/gensec/gensec.h"
28 NTSTATUS auth_generic_server_start(TALLOC_CTX *mem_ctx,
35 const struct tsocket_address *remote_address,
36 struct gensec_security **ctx)
38 struct auth_generic_state *a = NULL;
41 status = auth_generic_prepare(remote_address, &a);
42 if (!NT_STATUS_IS_OK(status)) {
43 DEBUG(0, (__location__ ": auth_generic_prepare failed: %s\n",
49 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SIGN);
52 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SIGN);
53 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SEAL);
57 gensec_want_feature(a->gensec_security, GENSEC_FEATURE_DCE_STYLE);
60 status = auth_generic_start(a, oid);
61 if (!NT_STATUS_IS_OK(status)) {
62 DEBUG(0, (__location__ ": auth_generic_start failed: %s\n",
67 status = gensec_update(a->gensec_security, mem_ctx, NULL, *token_in, token_out);
68 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
69 DEBUG(2, (__location__ ": gensec_update failed: %s\n",
74 /* steal gensec context too */
75 *ctx = talloc_move(mem_ctx, &a->gensec_security);
77 status = NT_STATUS_OK;
85 NTSTATUS auth_generic_server_authtype_start(TALLOC_CTX *mem_ctx,
86 uint8_t auth_type, uint8_t auth_level,
89 const struct tsocket_address *remote_address,
90 struct gensec_security **ctx)
92 struct auth_generic_state *a = NULL;
95 status = auth_generic_prepare(remote_address, &a);
96 if (!NT_STATUS_IS_OK(status)) {
97 DEBUG(0, (__location__ ": auth_generic_prepare failed: %s\n",
102 status = auth_generic_authtype_start(a, auth_type, auth_level);
103 if (!NT_STATUS_IS_OK(status)) {
104 DEBUG(0, (__location__ ": auth_generic_start failed: %s\n",
109 status = gensec_update(a->gensec_security, mem_ctx, NULL, *token_in, token_out);
110 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
111 DEBUG(2, (__location__ ": gensec_update failed: %s\n",
116 /* steal gensec context too */
117 *ctx = talloc_move(mem_ctx, &a->gensec_security);
119 status = NT_STATUS_OK;
127 NTSTATUS auth_generic_server_step(struct gensec_security *gensec_security,
130 DATA_BLOB *token_out)
134 /* this has to be done as root in order to verify the password */
136 status = gensec_update(gensec_security, mem_ctx, NULL, *token_in, token_out);
142 NTSTATUS auth_generic_server_check_flags(struct gensec_security *gensec_security,
143 bool do_sign, bool do_seal)
145 if (do_sign && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SIGN)) {
146 DEBUG(1, (__location__ "Integrity was requested but client "
147 "failed to negotiate signing.\n"));
148 return NT_STATUS_ACCESS_DENIED;
151 if (do_seal && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SEAL)) {
152 DEBUG(1, (__location__ "Privacy was requested but client "
153 "failed to negotiate sealing.\n"));
154 return NT_STATUS_ACCESS_DENIED;
160 NTSTATUS auth_generic_server_get_user_info(struct gensec_security *gensec_security,
162 struct auth_session_info **session_info)
166 status = gensec_session_info(gensec_security, mem_ctx, session_info);
167 if (!NT_STATUS_IS_OK(status)) {
168 DEBUG(1, (__location__ ": Failed to get authenticated user "
169 "info: %s\n", nt_errstr(status)));
173 DEBUG(5, (__location__ "OK: user: %s domain: %s\n",
174 (*session_info)->info->account_name,
175 (*session_info)->info->domain_name));