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/>.
22
#include "rpc_server/dcesrv_gssapi.h"
23
#include "../librpc/gen_ndr/ndr_krb5pac.h"
24
#include "librpc/crypto/gse.h"
27
NTSTATUS gssapi_server_auth_start(TALLOC_CTX *mem_ctx,
33
struct gse_context **ctx)
35
struct gse_context *gse_ctx = NULL;
36
uint32_t add_flags = 0;
40
add_flags = GSS_C_DCE_STYLE;
43
/* Let's init the gssapi machinery for this connection */
44
/* passing a NULL server name means the server will try
45
* to accept any connection regardless of the name used as
46
* long as it can find a decryption key */
47
/* by passing NULL, the code will attempt to set a default
48
* keytab based on configuration options */
49
status = gse_init_server(mem_ctx, do_sign, do_seal,
50
add_flags, NULL, &gse_ctx);
51
if (!NT_STATUS_IS_OK(status)) {
52
DEBUG(0, ("Failed to init dcerpc gssapi server (%s)\n",
57
status = gse_get_server_auth_token(mem_ctx, gse_ctx,
59
if (!NT_STATUS_IS_OK(status)) {
60
DEBUG(0, ("Failed to parse initial client token (%s)\n",
66
status = NT_STATUS_OK;
69
if (!NT_STATUS_IS_OK(status)) {
76
NTSTATUS gssapi_server_step(struct gse_context *gse_ctx,
83
status = gse_get_server_auth_token(mem_ctx, gse_ctx,
85
if (!NT_STATUS_IS_OK(status)) {
89
if (gse_require_more_processing(gse_ctx)) {
90
/* ask for next leg */
91
return NT_STATUS_MORE_PROCESSING_REQUIRED;
97
NTSTATUS gssapi_server_check_flags(struct gse_context *gse_ctx)
99
return gse_verify_server_auth_flags(gse_ctx);
102
NTSTATUS gssapi_server_get_user_info(struct gse_context *gse_ctx,
104
struct client_address *client_id,
105
struct auth_serversupplied_info **server_info)
109
struct PAC_DATA *pac_data;
110
struct PAC_LOGON_INFO *logon_info = NULL;
111
enum ndr_err_code ndr_err;
122
tmp_ctx = talloc_new(mem_ctx);
124
return NT_STATUS_NO_MEMORY;
127
status = gse_get_pac_blob(gse_ctx, tmp_ctx, &pac);
128
if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
129
/* TODO: Fetch user by principal name ? */
130
status = NT_STATUS_ACCESS_DENIED;
133
if (!NT_STATUS_IS_OK(status)) {
137
status = gse_get_client_name(gse_ctx, tmp_ctx, &princ_name);
138
if (!NT_STATUS_IS_OK(status)) {
142
pac_data = talloc_zero(tmp_ctx, struct PAC_DATA);
144
status = NT_STATUS_NO_MEMORY;
148
ndr_err = ndr_pull_struct_blob(&pac, pac_data, pac_data,
149
(ndr_pull_flags_fn_t)ndr_pull_PAC_DATA);
150
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
151
DEBUG(1, ("Failed to parse the PAC for %s\n", princ_name));
152
status = ndr_map_error2ntstatus(ndr_err);
156
/* get logon name and logon info */
157
for (i = 0; i < pac_data->num_buffers; i++) {
158
struct PAC_BUFFER *data_buf = &pac_data->buffers[i];
160
switch (data_buf->type) {
161
case PAC_TYPE_LOGON_INFO:
162
if (!data_buf->info) {
165
logon_info = data_buf->info->logon_info.info;
172
DEBUG(1, ("Invalid PAC data, missing logon info!\n"));
173
status = NT_STATUS_NOT_FOUND;
177
/* TODO: Should we check princ_name against account_name in
178
* logon_name ? Are they supposed to be identical, or can an
179
* account_name be different from the UPN ? */
181
status = get_user_from_kerberos_info(tmp_ctx, client_id->name,
182
princ_name, logon_info,
183
&is_mapped, &is_guest,
186
if (!NT_STATUS_IS_OK(status)) {
187
DEBUG(1, ("Failed to map kerberos principal to system user "
188
"(%s)\n", nt_errstr(status)));
189
status = NT_STATUS_ACCESS_DENIED;
193
/* TODO: save PAC data in netsamlogon cache ? */
195
status = make_server_info_krb5(mem_ctx,
196
ntuser, ntdomain, username, pw,
197
logon_info, is_guest, server_info);
198
if (!NT_STATUS_IS_OK(status)) {
199
DEBUG(1, ("Failed to map kerberos pac to server info (%s)\n",
201
status = NT_STATUS_ACCESS_DENIED;
205
DEBUG(5, (__location__ "OK: user: %s domain: %s client: %s\n",
206
ntuser, ntdomain, client_id->name));
208
status = NT_STATUS_OK;
211
TALLOC_FREE(tmp_ctx);