s3-shadow-copy2: Add more debugs
[Samba.git] / source4 / auth / samba_server_gensec.c
blob7b09aa78d7e00d5443aa405783fde5fbb6a22aa3
1 /*
2 Unix SMB/CIFS implementation.
4 Generic Authentication Interface for Samba Servers
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /* This code sets up GENSEC in the way that all Samba servers want
23 * (becaue they have presumed access to the sam.ldb etc */
25 #include "includes.h"
26 #include "auth/auth.h"
27 #include "auth/gensec/gensec.h"
28 #include "param/param.h"
30 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
31 struct tevent_context *event_ctx,
32 struct imessaging_context *msg_ctx,
33 struct loadparm_context *lp_ctx,
34 struct cli_credentials *server_credentials,
35 const char *target_service,
36 struct gensec_security **gensec_context)
38 NTSTATUS nt_status;
39 struct gensec_security *gensec_ctx;
40 struct auth4_context *auth_context;
42 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
43 if (!tmp_ctx) {
44 return NT_STATUS_NO_MEMORY;
47 nt_status = auth_context_create(tmp_ctx,
48 event_ctx,
49 msg_ctx,
50 lp_ctx,
51 &auth_context);
53 if (!NT_STATUS_IS_OK(nt_status)) {
54 DEBUG(1, ("Failed to start auth server code: %s\n", nt_errstr(nt_status)));
55 talloc_free(tmp_ctx);
56 return nt_status;
59 nt_status = gensec_server_start(tmp_ctx,
60 lpcfg_gensec_settings(mem_ctx, lp_ctx),
61 auth_context,
62 &gensec_ctx);
63 if (!NT_STATUS_IS_OK(nt_status)) {
64 talloc_free(tmp_ctx);
65 DEBUG(1, ("Failed to start GENSEC server code: %s\n", nt_errstr(nt_status)));
66 return nt_status;
69 gensec_set_credentials(gensec_ctx, server_credentials);
71 if (target_service) {
72 gensec_set_target_service(gensec_ctx, target_service);
74 *gensec_context = talloc_steal(mem_ctx, gensec_ctx);
75 talloc_free(tmp_ctx);
76 return nt_status;