netlogon_creds_cli: Simplify netlogon_creds_cli_delete
[Samba.git] / auth / gensec / external.c
blob01580456794175722ddfe5fe38646e67e6afbdea
1 /*
2 Unix SMB/CIFS implementation.
4 SASL/EXTERNAL authentication.
6 Copyright (C) Howard Chu <hyc@symas.com> 2013
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 #include "includes.h"
23 #include <tevent.h>
24 #include "lib/util/tevent_ntstatus.h"
25 #include "auth/credentials/credentials.h"
26 #include "auth/gensec/gensec.h"
27 #include "auth/gensec/gensec_internal.h"
28 #include "auth/gensec/gensec_proto.h"
29 #include "auth/gensec/gensec_toplevel_proto.h"
31 /* SASL/EXTERNAL is essentially a no-op; it is only usable when the transport
32 * layer is already mutually authenticated.
35 NTSTATUS gensec_external_init(TALLOC_CTX *ctx);
37 static NTSTATUS gensec_external_start(struct gensec_security *gensec_security)
39 if (gensec_security->want_features & GENSEC_FEATURE_SIGN)
40 return NT_STATUS_INVALID_PARAMETER;
41 if (gensec_security->want_features & GENSEC_FEATURE_SEAL)
42 return NT_STATUS_INVALID_PARAMETER;
44 return NT_STATUS_OK;
47 struct gensec_external_update_state {
48 DATA_BLOB out;
51 static struct tevent_req *gensec_external_update_send(TALLOC_CTX *mem_ctx,
52 struct tevent_context *ev,
53 struct gensec_security *gensec_security,
54 const DATA_BLOB in)
56 struct tevent_req *req;
57 struct gensec_external_update_state *state = NULL;
59 req = tevent_req_create(mem_ctx, &state,
60 struct gensec_external_update_state);
61 if (req == NULL) {
62 return NULL;
65 state->out = data_blob_talloc(state, "", 0);
66 if (tevent_req_nomem(state->out.data, req)) {
67 return tevent_req_post(req, ev);
70 tevent_req_done(req);
71 return tevent_req_post(req, ev);
74 static NTSTATUS gensec_external_update_recv(struct tevent_req *req,
75 TALLOC_CTX *out_mem_ctx,
76 DATA_BLOB *out)
78 struct gensec_external_update_state *state =
79 tevent_req_data(req,
80 struct gensec_external_update_state);
81 NTSTATUS status;
83 *out = data_blob_null;
85 if (tevent_req_is_nterror(req, &status)) {
86 tevent_req_received(req);
87 return status;
90 *out = state->out;
91 tevent_req_received(req);
92 return NT_STATUS_OK;
95 /* We have no features */
96 static bool gensec_external_have_feature(struct gensec_security *gensec_security,
97 uint32_t feature)
99 return false;
102 static const struct gensec_security_ops gensec_external_ops = {
103 .name = "sasl-EXTERNAL",
104 .sasl_name = "EXTERNAL",
105 .client_start = gensec_external_start,
106 .update_send = gensec_external_update_send,
107 .update_recv = gensec_external_update_recv,
108 .have_feature = gensec_external_have_feature,
109 .enabled = true,
110 .priority = GENSEC_EXTERNAL
114 NTSTATUS gensec_external_init(TALLOC_CTX *ctx)
116 NTSTATUS ret;
118 ret = gensec_register(ctx, &gensec_external_ops);
119 if (!NT_STATUS_IS_OK(ret)) {
120 DEBUG(0,("Failed to register '%s' gensec backend!\n",
121 gensec_external_ops.name));
123 return ret;