1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek KCM Server - the KCM server operations
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek Copyright (C) Red Hat, 2016
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek This program is free software; you can redistribute it and/or modify
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek it under the terms of the GNU General Public License as published by
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek the Free Software Foundation; either version 3 of the License, or
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek (at your option) any later version.
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek This program is distributed in the hope that it will be useful,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek GNU General Public License for more details.
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek You should have received a copy of the GNU General Public License
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
b09cd3072153663bfcce902633b5e6f9134e72e0Fabiano Fidêncio/* This limit comes from:
b09cd3072153663bfcce902633b5e6f9134e72e0Fabiano Fidêncio * https://github.com/krb5/krb5/blob/master/src/lib/krb5/ccache/cc_kcm.c#L53
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* Each operation follows the same pattern and is implemented using
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * functions with this prototype. The operation receives an op_ctx
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * that serves as a state of the operation and can be used to keep
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * track of any temporary data. The operation writes its output data
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * into the op_ctx reply IO buffer and returns the op_ret status code
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * separately.
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * The operation always returns EOK unless an internal error occurs,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * the result of the operation is stored in the op_ret variable
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozektypedef struct tevent_req*
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozekstatic void kcm_cmd_queue_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_cmd_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstruct tevent_req *kcm_cmd_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_cmd_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "KCM operation %s\n", op->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "%zu bytes on KCM input\n", input->length);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "KCM op %s has no handler\n", kcm_opt_name(op));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Allocating op_ctx on the heap makes it possible for operations to use
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * op_ctx as their temporary context and avoid tmp_ctx altogether
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek state->op_ctx = talloc_zero(state, struct kcm_op_ctx);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek state->op_ctx->input = sss_iobuf_init_readonly(state->op_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * The internal operation returns the opcode and the buffer separately.
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * The KCM server reply to the client also always contains zero if the
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * operation ran to completion, both are uint32_t.
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * Alternatively, we could extend iobuf API so that we can just pass
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * the reply's buffer+sizeof(2*uint32_t) and avoid the useless allocations
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek subreq = kcm_op_queue_send(state, ev, qctx, client);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek tevent_req_set_callback(subreq, kcm_cmd_queue_done, req);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozekstatic void kcm_cmd_queue_done(struct tevent_req *subreq)
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek struct kcm_cmd_state *state = tevent_req_data(req, struct kcm_cmd_state);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek /* When this request finishes, it frees the queue_entry which unblocks
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek * other requests by the same UID
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek ret = kcm_op_queue_recv(subreq, state, &state->queue_entry);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Cannot acquire queue slot\n");
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek subreq = state->op->fn_send(state, state->ev, state->op_ctx);
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek tevent_req_set_callback(subreq, kcm_cmd_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_cmd_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_cmd_state *state = tevent_req_data(req, struct kcm_cmd_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = state->op->fn_recv(subreq, &state->op_ret);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "op receive function failed [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "KCM operation %s returned [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek kcm_opt_name(state->op), state->op_ret, sss_strerror(state->op_ret));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* The first four bytes of the reply is the operation status code */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_uint32(state->reply, htobe32(kerr));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek state = tevent_req_data(req, struct kcm_cmd_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* ======= KCM operations ======= */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* Operations that don't return any extra information except for the op_ret
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * can use this macro in the _recv function to avoid code duplication
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek#define KCM_OP_RET_FROM_TYPE(req, state_type, _op_ret_out) do { \
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic errno_t kcm_op_common_recv(struct tevent_req *req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* () -> (name) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_gen_new_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *kcm_op_gen_new_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_gen_new_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_gen_new_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_nextid_recv(subreq, state, &newid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot generate a new ID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Generated a new ID %s\n", newid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_stringz(state->op_ctx->reply, newid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot write generated ID %d: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (princ) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_got_byname(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_cc_create_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_cc_delete_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_create_step(struct tevent_req *req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_got_default(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_set_default_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *kcm_op_initialize_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_initialize_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &state->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Initializing ccache %s\n", state->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_check_name(state->name, op_ctx->client);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Name %s is malformed [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_krb5_unmarshal_princ(op_ctx, op_ctx->input, &state->princ);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot unmarshal principal [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_initialize_got_byname, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_got_byname(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_initialize_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyname_recv(subreq, state, &state->new_cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ok = kcm_cc_access(state->new_cc, state->op_ctx->client);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get new ccache UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Nuke any previous cache and its contents during initialization */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_initialize_cc_delete_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_cc_delete_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot delete ccache from the db %d: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_create_step(struct tevent_req *req)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_initialize_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot create new ccache %d: %s\n", ret, sss_strerror(ret));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_initialize_cc_create_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_cc_create_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_initialize_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot add ccache to db %d: %s\n", ret, sss_strerror(ret));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* If there was no previous default ccache, set this one as default */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek subreq = kcm_ccdb_get_default_send(state, state->ev,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_initialize_got_default, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_got_default(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_initialize_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_get_default_recv(subreq, &old_dfl_uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get default ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* If there was a previous default ccache, switch to the initialized
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * one by default
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_cc_get_uuid(state->new_cc, dfl_uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get new ccache UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_initialize_set_default_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* ENOENT, done */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_initialize_set_default_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_initialize_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot set default ccache %d: %s\n", ret, sss_strerror(ret));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic errno_t kcm_op_initialize_recv(struct tevent_req *req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek KCM_OP_RET_FROM_TYPE(req, struct kcm_op_initialize_state, _op_ret);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_destroy_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_destroy_delete_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *kcm_op_destroy_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot unmarshall input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Destroying credentials of %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_destroy_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_destroy_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_uuid_by_name_recv(subreq, state, uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get matching ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_destroy_delete_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_destroy_delete_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot delete ccache from the db [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name, cred) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_store_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_store_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *kcm_op_store_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_store_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot unmarshall input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Storing credentials for %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek creds_len = sss_iobuf_get_size(op_ctx->input) - strlen(name) -1;
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Protects against underflows and in general adds sanity */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot unmarshall input cred blob [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_store_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_store_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_store_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_uuid_by_name_recv(subreq, state, uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek subreq = kcm_ccdb_store_cred_blob_send(state, state->ev,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_store_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_store_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_store_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot store credentials [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic errno_t kcm_op_store_recv(struct tevent_req *req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek KCM_OP_RET_FROM_TYPE(req, struct kcm_op_store_state, _op_ret);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name) -> (princ) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_principal_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *kcm_op_get_principal_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Requested principal %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_principal_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_principal_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyname_recv(subreq, state, &cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "No credentials by that name\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Marshall the principal to the reply */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Credentials with no principal?\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_krb5_marshal_princ(princ, state->op_ctx->reply);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot marshall principal [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name) -> (uuid, ...) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cred_uuid_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_cred_uuid_list_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Returning UUID list for %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_cred_uuid_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cred_uuid_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyname_recv(subreq, state, &cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "No credentials by that UUID\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "Credential has no UUID, skipping\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_len(state->op_ctx->reply,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot marshall UUID %s [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name, uuid) -> (cred) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cred_by_uuid_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_cred_by_uuid_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Returning creds by UUID for %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_cred_by_uuid_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cred_by_uuid_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyname_recv(subreq, state, &cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "No credentials by that name\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get UUID from creds, skipping\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "No credentials by that UUID\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Credentials lack the creds blob\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_len(state->op_ctx->reply,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot write ccache blob [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name, flags, credtag) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* () -> (uuid, ...) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cache_uuid_list_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_cache_uuid_list_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Returning full UUID list\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_cache_uuid_list_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cache_uuid_list_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_list_recv(subreq, state, &uuid_list);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot list the ccache DB [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek if (uuid_list == NULL || uuid_list[0] == NULL) {
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "Nothing to list\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek for (int i = 0;
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_len(state->op_ctx->reply,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot marshall UUID %s [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (uuid) -> (name) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cache_by_uuid_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_cache_by_uuid_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Retrieving cache by UUID\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_cache_by_uuid_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_cache_by_uuid_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyuuid_recv(subreq, state, &cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccahe by UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, "Found %s by UUID\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_stringz(state->op_ctx->reply,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot write output name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* () -> (name) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_get_default_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_default_ccache_byuuid_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_default_ccache_list_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_default_ccache_reply_step(struct kcm_op_get_default_ccache_state *state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_default_ccache_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_get_default_ccache_state *state = NULL;
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Getting client's default ccache\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_get_default_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_get_default_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_get_default_ccache_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_get_default_recv(subreq, &dfl_uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get default ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* No cache marked as default -- get an existing ccache for ID
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek * and treat the default as simply the first one
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_default_ccache_list_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Existing default */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_default_ccache_byuuid_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_default_ccache_byuuid_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_get_default_ccache_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_name_by_uuid_recv(subreq, state, &state->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccahe by UUID [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_op_get_default_ccache_reply_step(state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_default_ccache_list_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_get_default_ccache_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_list_recv(subreq, state, &uuid_list);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot list ccaches [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek if (uuid_list == NULL || uuid_is_null(uuid_list[0])) {
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* No cache at all, just send back a reply */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_op_get_default_ccache_reply_step(state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek /* Otherwise resolve the first cache and use it as a default */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_default_ccache_byuuid_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_get_default_ccache_reply_step(struct kcm_op_get_default_ccache_state *state)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, "The default ccache is %s\n", state->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_stringz(state->op_ctx->reply, state->name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot write output name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic errno_t kcm_op_get_default_ccache_recv(struct tevent_req *req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek KCM_OP_RET_FROM_TYPE(req, struct kcm_op_get_default_ccache_state, _op_ret);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_default_ccache_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_default_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekkcm_op_set_default_ccache_send(TALLOC_CTX *mem_ctx,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Setting default ccache %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_set_default_ccache_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_default_ccache_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_uuid_by_name_recv(subreq, state, dfl_uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get ccache by name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_set_default_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_default_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot set default ccache %d: %s\n", ret, sss_strerror(ret));
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name) -> (offset) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_kdc_offset_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_common_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Requested offset for principal %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_get_kdc_offset_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_get_kdc_offset_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_common_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_getbyname_recv(subreq, state, &cc);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get matching ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "No matching credentials\n");
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "KDC offset: %"PRIu32"\n", offset);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_write_int32(state->op_ctx->reply, offset_be);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot write KDC offset [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* (name, offset) -> () */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek/* () -> (name) */
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_kdc_offset_getbyname_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_kdc_offset_mod_done(struct tevent_req *subreq);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic struct tevent_req *
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_set_kdc_offset_state *state = NULL;
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_op_set_kdc_offset_state);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_stringz(op_ctx->input, &name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read input name [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Setting offset for principal %s\n", name);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_set_kdc_offset_getbyname_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_kdc_offset_getbyname_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_set_kdc_offset_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = kcm_ccdb_uuid_by_name_recv(subreq, state, uuid);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot get matching ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek ret = sss_iobuf_read_int32(state->op_ctx->input, &offset_be);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot read KDC offset [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek tevent_req_set_callback(subreq, kcm_op_set_kdc_offset_mod_done, req);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic void kcm_op_set_kdc_offset_mod_done(struct tevent_req *subreq)
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek struct kcm_op_set_kdc_offset_state *state = tevent_req_data(req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "Cannot modify ccache [%d]: %s\n",
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozekstatic errno_t kcm_op_set_kdc_offset_recv(struct tevent_req *req,
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek KCM_OP_RET_FROM_TYPE(req, struct kcm_op_set_kdc_offset_state, _op_ret);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "INITIALIZE", kcm_op_initialize_send, kcm_op_initialize_recv },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "STORE", kcm_op_store_send, kcm_op_store_recv },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_PRINCIPAL", kcm_op_get_principal_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_CRED_UUID_LIST", kcm_op_get_cred_uuid_list_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_CRED_BY_UUID", kcm_op_get_cred_by_uuid_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "REMOVE_CRED", kcm_op_remove_cred_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_CACHE_UUID_LIST", kcm_op_get_cache_uuid_list_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_CACHE_BY_UUID", kcm_op_get_cache_by_uuid_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_DEFAULT_CACHE", kcm_op_get_default_ccache_send, kcm_op_get_default_ccache_recv },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "SET_DEFAULT_CACHE", kcm_op_set_default_ccache_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "GET_KDC_OFFSET", kcm_op_get_kdc_offset_send, NULL },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek { "SET_KDC_OFFSET", kcm_op_set_kdc_offset_send, kcm_op_set_kdc_offset_recv },
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek "The client requested operation %"PRIu16"\n", opcode);
1ec4198f38d34a1f82a2db55d8c9782a434fb55fJakub Hrozek return "Unknown operation";