bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek/*
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek SSSD
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek KCM Server - the KCM ccache operations
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek Copyright (C) Red Hat, 2016
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek This program is free software; you can redistribute it and/or modify
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek it under the terms of the GNU General Public License as published by
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek the Free Software Foundation; either version 3 of the License, or
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek (at your option) any later version.
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek This program is distributed in the hope that it will be useful,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek GNU General Public License for more details.
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek You should have received a copy of the GNU General Public License
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek*/
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "config.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "util/crypto/sss_crypto.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "util/util.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "util/sss_krb5.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "responder/kcm/kcmsrv_ccache.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "responder/kcm/kcmsrv_ccache_pvt.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek#include "responder/kcm/kcmsrv_ccache_be.h"
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic int kcm_cc_destructor(struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return 0;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek krb5_free_principal(NULL, cc->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return 0;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_cc_new(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek krb5_context k5c,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *owner,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char *name,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek krb5_principal princ,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache **_cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek struct kcm_ccache *cc = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek krb5_error_code kret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc = talloc_zero(mem_ctx, struct kcm_ccache);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = kcm_check_name(name, owner);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Name %s is malformed\n", name);
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek goto done;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->name = talloc_strdup(cc, name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc->name == NULL) {
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek ret = ENOMEM;
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek goto done;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_generate(cc->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek kret = krb5_copy_principal(k5c, princ, &cc->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (kret != 0) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char *err_msg = sss_krb5_get_error_message(k5c, kret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "krb5_copy_principal failed: [%d][%s]\n", kret, err_msg);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek sss_krb5_free_error_message(k5c, err_msg);
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek ret = ERR_INTERNAL;
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek goto done;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->owner.uid = cli_creds_get_uid(owner);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->owner.gid = cli_creds_get_gid(owner);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->kdc_offset = INT32_MAX;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_set_destructor(cc, kcm_cc_destructor);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_cc = cc;
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek ret = EOK;
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozekdone:
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek if (ret != EOK) {
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek talloc_free(cc);
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek }
7f68de6c2e6aaed1929dfbcf1a73606c9b79fd64Jakub Hrozek return ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekconst char *kcm_cc_get_name(struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return cc ? cc->name : NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_cc_get_uuid(struct kcm_ccache *cc, uuid_t _uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(_uuid, cc->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekkrb5_principal kcm_cc_get_client_principal(struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return cc ? cc->client : NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekbool kcm_cc_access(struct kcm_ccache *cc,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek bool ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uid_t uid = cli_creds_get_uid(client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek gid_t gid = cli_creds_get_gid(client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return false;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (uid == 0 && gid == 0) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* root can access any ccache */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return true;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ok = ((cc->owner.uid == uid) && (cc->owner.gid == gid));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!ok) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Client %"SPRIuid":%"SPRIgid" has no access to ccache %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cli_creds_get_uid(client),
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cli_creds_get_gid(client),
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekint32_t kcm_cc_get_offset(struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return cc ? cc->kdc_offset : INT32_MAX;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_cc_store_cred_blob(struct kcm_ccache *cc,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct sss_iobuf *cred_blob)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_cred *kcreds;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL || cred_blob == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_generate(uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek kcreds = kcm_cred_new(cc, uuid, cred_blob);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (kcreds == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = kcm_cc_store_creds(cc, kcreds);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_cred *kcm_cc_get_cred(struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return cc->creds;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_cred *kcm_cc_next_cred(struct kcm_cred *crd)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (crd == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return crd->next;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_cred *kcm_cred_new(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct sss_iobuf *cred_blob)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_cred *kcreds;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek kcreds = talloc_zero(mem_ctx, struct kcm_cred);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (kcreds == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(kcreds->uuid, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek kcreds->cred_blob = talloc_steal(kcreds, cred_blob);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return kcreds;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek/* Add a cred to ccache */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_cc_store_creds(struct kcm_ccache *cc,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_cred *crd)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DLIST_ADD(cc->creds, crd);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_steal(cc, crd);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_cred_get_uuid(struct kcm_cred *crd, uuid_t _uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (crd == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(_uuid, crd->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct sss_iobuf *kcm_cred_get_creds(struct kcm_cred *crd)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return crd ? crd->cred_blob : NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb *kcm_ccdb_init(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek enum kcm_ccdb_be cc_be)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *ccdb = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ccdb = talloc_zero(mem_ctx, struct kcm_ccdb);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ccdb == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ccdb->ev = ev;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek switch (cc_be) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek case CCDB_BE_MEMORY:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "KCM back end: memory\n");
70fe6e2bb398b8669ad1aebeaf0abcbffc307475Jakub Hrozek ccdb->ops = &ccdb_mem_ops;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek break;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek case CCDB_BE_SECRETS:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_FUNC_DATA, "KCM back end: sssd-secrets\n");
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek ccdb->ops = &ccdb_sec_ops;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek break;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek default:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unknown ccache database\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek break;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ccdb->ops == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Ccache database not initialized\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_free(ccdb);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ccdb->ops->init(ccdb);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Cannot initialize ccache database\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_free(ccdb);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ccdb;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_nextid_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek char *next_cc;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_nextid_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_nextid_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_nextid_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_nextid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = state->db->ops->nextid_send(state, ev, state->db, client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_nextid_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_nextid_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_nextid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_nextid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek unsigned int nextid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->nextid_recv(subreq, &nextid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to generate next UID [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->next_cc = talloc_asprintf(state, "%"SPRIuid":%u",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cli_creds_get_uid(state->client),
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek nextid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (state->next_cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ENOMEM);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "generated %s\n", state->next_cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_nextid_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek char **_next_cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_nextid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_nextid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_next_cc = talloc_steal(mem_ctx, state->next_cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_list_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t *uuid_list;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_list_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_list_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_list_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_list_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = state->db->ops->list_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_list_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_list_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_list_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_list_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->list_recv(subreq, state, &state->uuid_list);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to list all ccaches [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_list_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t **_uuid_list)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_list_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_list_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_uuid_list = talloc_steal(mem_ctx, state->uuid_list);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_get_default_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_get_default_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_get_default_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_get_default_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_get_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = db->ops->get_default_send(state, ev, db, client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_get_default_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_get_default_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_get_default_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_get_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->get_default_recv(subreq, state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to get the default ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_get_default_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t *uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_get_default_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_get_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (uuid != NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* The caller might supply a NULL dfl to just check if there is
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek * some default ccache
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(*uuid, state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_set_default_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_set_default_uuid_resolved(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_set_default_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_set_default_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_set_default_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_set_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev = ev;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(state->uuid, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (uuid_is_null(uuid)) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* NULL UUID means to just reset the default to 'no default' */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = state->db->ops->set_default_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_set_default_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek } else {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* Otherwise we need to check if the client can access the UUID
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek * about to be set as default
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = db->ops->getbyuuid_send(state, ev, db, client, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_set_default_uuid_resolved, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_set_default_uuid_resolved(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_set_default_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_set_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek bool ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache *cc;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->getbyuuid_recv(subreq, state, &cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to get cache by UUID [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "No cache found by UUID\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ERR_KCM_CC_END);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ok = kcm_cc_access(cc, state->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!ok) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, EACCES);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = state->db->ops->set_default_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ENOMEM);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_set_default_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_set_default_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_set_default_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_set_default_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->set_default_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to set the default ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_set_default_recv(struct tevent_req *req)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_getbyname_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache *cc;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_getbyname_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_getbyname_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char *name)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyname_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_getbyname_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || name == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = db->ops->getbyname_send(state, ev, db, client, name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_getbyname_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_getbyname_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyname_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyname_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek bool ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->getbyname_recv(subreq, state, &state->cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to get cache by name [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (state->cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "No cache found by name\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ok = kcm_cc_access(state->cc, state->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!ok) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, EACCES);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_getbyname_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache **_cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyname_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyname_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_cc = talloc_steal(mem_ctx, state->cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_getbyuuid_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache *cc;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_getbyuuid_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_getbyuuid_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyuuid_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_getbyuuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = db->ops->getbyuuid_send(state, ev, db, client, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_getbyuuid_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_getbyuuid_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyuuid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyuuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek bool ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->getbyuuid_recv(subreq, state, &state->cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to get cache by UUID [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (state->cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "No cache found by UUID\n");
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ok = kcm_cc_access(state->cc, state->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!ok) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, EACCES);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_getbyuuid_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache **_cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyuuid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_getbyuuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_cc = talloc_steal(mem_ctx, state->cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_name_by_uuid_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char *name;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_name_by_uuid_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_name_by_uuid_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek &state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || uuid_is_null(uuid)) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = db->ops->name_by_uuid_send(state, ev, db, client, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_name_by_uuid_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_name_by_uuid_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->name_by_uuid_recv(subreq, state, &state->name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to resolve cache by UUID [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_name_by_uuid_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char **_name)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_name_by_uuid_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek *_name = talloc_steal(mem_ctx, state->name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_uuid_by_name_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_uuid_by_name_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_uuid_by_name_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek const char *name)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek &state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || name == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = db->ops->uuid_by_name_send(state, ev, db, client, name);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_uuid_by_name_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_uuid_by_name_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->uuid_by_name_recv(subreq, state, state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to resolve cache by UUID [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_uuid_by_name_recv(struct tevent_req *req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t _uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_uuid_by_name_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(_uuid, state->uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_create_cc_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_create_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_create_cc_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccache *cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_create_cc_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek bool ok;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_create_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ok = kcm_cc_access(cc, client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!ok) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EACCES;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = state->db->ops->create_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_create_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_create_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_create_cc_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_create_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->create_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to create ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_create_cc_recv(struct tevent_req *req)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekvoid kcm_mod_ctx_clear(struct kcm_mod_ctx *mod_ctx)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (mod_ctx == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek mod_ctx->kdc_offset = INT32_MAX;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekvoid kcm_mod_cc(struct kcm_ccache *cc, struct kcm_mod_ctx *mod_ctx)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (cc == NULL || mod_ctx == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (mod_ctx->kdc_offset != INT32_MAX) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cc->kdc_offset = mod_ctx->kdc_offset;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_mod_cc_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_mod_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_mod_cc_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_mod_ctx *mod_cc)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_mod_cc_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_mod_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || mod_cc == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = state->db->ops->mod_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek mod_cc);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_mod_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_mod_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_mod_cc_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_mod_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->mod_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to create ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_mod_cc_recv(struct tevent_req *req)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_store_cred_blob_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_store_cred_blob_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_store_cred_blob_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct sss_iobuf *cred_blob)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_store_cred_blob_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_store_cred_blob_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL || cred_blob == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
3e4fe6cc59419ce4c178e9ad31cd1069ab375e9bJakub Hrozek subreq = state->db->ops->store_cred_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek cred_blob);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = ENOMEM;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_store_cred_blob_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_store_cred_blob_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_store_cred_blob_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_store_cred_blob_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->store_cred_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to create ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_store_cred_blob_recv(struct tevent_req *req)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct kcm_ccdb_delete_cc_state {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek};
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_get_default_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_default_reset_done(struct tevent_req *subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstruct tevent_req *kcm_ccdb_delete_cc_send(TALLOC_CTX *mem_ctx,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_context *ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb *db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct cli_creds *client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *subreq = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state *state = NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct kcm_ccdb_delete_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (req == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return NULL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db = db;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev = ev;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client = client;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_copy(state->uuid, uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ev == NULL || db == NULL || client == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = EINVAL;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek goto immediate;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = state->db->ops->delete_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->uuid);
613a832d5bbf4c8174adbc1dcd881c59660cb0f1Jakub Hrozek if (subreq == NULL) {
613a832d5bbf4c8174adbc1dcd881c59660cb0f1Jakub Hrozek ret = ENOMEM;
613a832d5bbf4c8174adbc1dcd881c59660cb0f1Jakub Hrozek goto immediate;
613a832d5bbf4c8174adbc1dcd881c59660cb0f1Jakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_delete_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekimmediate:
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_post(req, ev);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return req;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->delete_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to delete ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* The delete operation must also check if the deleted ccache was
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek * the default and reset the default if it was
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = state->db->ops->get_default_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ENOMEM);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_delete_get_default_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_get_default_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t dfl_uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_t null_uuid;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->get_default_recv(subreq, dfl_uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to get the default ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (uuid_compare(dfl_uuid, state->uuid) != 0) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* The ccache about to be deleted was not the default, quit */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek /* If we deleted the default ccache, reset the default ccache to 'none' */
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_clear(null_uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek subreq = state->db->ops->set_default_send(state,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->ev,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->db,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek state->client,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek null_uuid);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (subreq == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ENOMEM);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_set_callback(subreq, kcm_ccdb_delete_default_reset_done, req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekstatic void kcm_ccdb_delete_default_reset_done(struct tevent_req *subreq)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct tevent_req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state *state = tevent_req_data(req,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek struct kcm_ccdb_delete_cc_state);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek errno_t ret;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret = state->db->ops->set_default_recv(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek talloc_zfree(subreq);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (ret != EOK) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "Failed to NULL the default ccache [%d]: %s\n",
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek ret, sss_strerror(ret));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_error(req, ret);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek tevent_req_done(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_ccdb_delete_cc_recv(struct tevent_req *req)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekvoid kcm_debug_uuid(uuid_t uuid)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek char dbgbuf[UUID_STR_SIZE];
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (!(debug_level & SSSDBG_TRACE_ALL) || uuid == NULL) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek uuid_unparse(uuid, dbgbuf);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek DEBUG(SSSDBG_TRACE_ALL, "UUID: %s\n", dbgbuf);
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozekerrno_t kcm_check_name(const char *name, struct cli_creds *client)
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek{
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek char prefix[64];
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek size_t prefix_len;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek prefix_len = snprintf(prefix, sizeof(prefix),
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek "%"SPRIuid, cli_creds_get_uid(client));
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek if (strncmp(name, prefix, prefix_len) != 0) {
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return ERR_KCM_WRONG_CCNAME_FORMAT;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek }
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek return EOK;
bea0dc79faf609de8603cb42f190adae544bc8fbJakub Hrozek}