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 */
26 #include "auth/auth.h"
27 #include "auth/gensec/gensec.h"
28 #include "param/param.h"
30 static NTSTATUS
samba_server_gensec_start_settings(TALLOC_CTX
*mem_ctx
,
31 struct tevent_context
*event_ctx
,
32 struct imessaging_context
*msg_ctx
,
33 struct loadparm_context
*lp_ctx
,
34 struct gensec_settings
*settings
,
35 struct cli_credentials
*server_credentials
,
36 const char *target_service
,
37 struct gensec_security
**gensec_context
)
40 struct gensec_security
*gensec_ctx
;
41 struct auth4_context
*auth_context
;
43 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
45 return NT_STATUS_NO_MEMORY
;
48 nt_status
= auth_context_create(tmp_ctx
,
54 if (!NT_STATUS_IS_OK(nt_status
)) {
55 DEBUG(1, ("Failed to start auth server code: %s\n", nt_errstr(nt_status
)));
60 nt_status
= gensec_server_start(tmp_ctx
,
64 if (!NT_STATUS_IS_OK(nt_status
)) {
66 DEBUG(1, ("Failed to start GENSEC server code: %s\n", nt_errstr(nt_status
)));
70 gensec_set_credentials(gensec_ctx
, server_credentials
);
73 gensec_set_target_service(gensec_ctx
, target_service
);
75 *gensec_context
= talloc_steal(mem_ctx
, gensec_ctx
);
80 NTSTATUS
samba_server_gensec_start(TALLOC_CTX
*mem_ctx
,
81 struct tevent_context
*event_ctx
,
82 struct imessaging_context
*msg_ctx
,
83 struct loadparm_context
*lp_ctx
,
84 struct cli_credentials
*server_credentials
,
85 const char *target_service
,
86 struct gensec_security
**gensec_context
)
88 struct gensec_settings
*settings
= NULL
;
91 settings
= lpcfg_gensec_settings(mem_ctx
, lp_ctx
);
92 if (settings
== NULL
) {
93 return NT_STATUS_NO_MEMORY
;
95 status
= samba_server_gensec_start_settings(mem_ctx
, event_ctx
,
97 settings
, server_credentials
,
100 if (!NT_STATUS_IS_OK(status
)) {
101 TALLOC_FREE(settings
);
105 talloc_reparent(mem_ctx
, *gensec_context
, settings
);
109 NTSTATUS
samba_server_gensec_krb5_start(TALLOC_CTX
*mem_ctx
,
110 struct tevent_context
*event_ctx
,
111 struct imessaging_context
*msg_ctx
,
112 struct loadparm_context
*lp_ctx
,
113 struct cli_credentials
*server_credentials
,
114 const char *target_service
,
115 struct gensec_security
**gensec_context
)
117 struct gensec_settings
*settings
= NULL
;
118 const struct gensec_security_ops
**backends
= NULL
;
122 settings
= lpcfg_gensec_settings(mem_ctx
, lp_ctx
);
123 if (settings
== NULL
) {
124 return NT_STATUS_NO_MEMORY
;
126 backends
= talloc_zero_array(settings
,
127 const struct gensec_security_ops
*, 3);
128 if (backends
== NULL
) {
129 TALLOC_FREE(settings
);
130 return NT_STATUS_NO_MEMORY
;
132 settings
->backends
= backends
;
136 backends
[idx
++] = gensec_security_by_oid(NULL
, GENSEC_OID_KERBEROS5
);
138 backends
[idx
++] = gensec_security_by_oid(NULL
, GENSEC_OID_SPNEGO
);
140 status
= samba_server_gensec_start_settings(mem_ctx
, event_ctx
,
142 settings
, server_credentials
,
145 if (!NT_STATUS_IS_OK(status
)) {
146 TALLOC_FREE(settings
);
150 talloc_reparent(mem_ctx
, *gensec_context
, settings
);