526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek KCM Server - ccache in-memory storage
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek Copyright (C) Red Hat, 2016
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek This program is free software; you can redistribute it and/or modify
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek it under the terms of the GNU General Public License as published by
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek (at your option) any later version.
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek This program is distributed in the hope that it will be useful,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek GNU General Public License for more details.
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek You should have received a copy of the GNU General Public License
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek * The KCM memory database is just a double-linked list of kcm_ccache structures
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* Both ccaches and the next-id are kept in memory */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek/* In order to provide a consistent interface, we need to let the caller
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * of getbyXXX own the ccache, therefore the memory back end returns a shallow
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * copy of the ccache
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozekstatic struct kcm_ccache *kcm_ccache_dup(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic struct ccache_mem_wrap *memdb_get_by_uuid(struct ccdb_mem *memdb,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek /* since KCM stores ccaches, better not crash.. */
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "BUG: ccwrap contains NULL cc\n");
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek if (uuid_compare(uuid, ccwrap->cc->uuid) == 0) {
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozekstatic struct ccache_mem_wrap *memdb_get_by_name(struct ccdb_mem *memdb,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek const char *name)
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek /* since KCM stores ccaches, better not crash.. */
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "BUG: ccwrap contains NULL cc\n");
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek/* Since with the in-memory database, the database operations are just
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek * fake-async wrappers around otherwise sync operations, we don't often
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose * need any state, so we use this empty structure instead
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek struct ccache_mem_wrap *ccwrap = talloc_get_type(ptr, struct ccache_mem_wrap);
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek safezero(sss_iobuf_get_data(ccwrap->cc->creds->cred_blob),
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek sss_iobuf_get_size(ccwrap->cc->creds->cred_blob));
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozekstatic errno_t ccdb_mem_init(struct kcm_ccdb *db)
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozekstatic struct tevent_req *ccdb_mem_nextid_send(TALLOC_CTX *mem_ctx,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_nextid_state);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_nextid_recv(struct tevent_req *req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek unsigned int *_nextid)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_nextid_state *state = tevent_req_data(req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic struct tevent_req *ccdb_mem_list_send(TALLOC_CTX *mem_ctx,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_list_state);
06d4c022874d4f12d70e79c3c749d52fe020dad6Lukas Slebodnik state->uuid_list = talloc_zero_array(state, uuid_t, num_ccaches+1);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek uuid_copy(state->uuid_list[cc_index], ccwrap->cc->uuid);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_list_recv(struct tevent_req *req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_list_state *state = tevent_req_data(req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek *_uuid_list = talloc_steal(mem_ctx, state->uuid_list);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic struct tevent_req *ccdb_mem_set_default_send(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_dummy_state);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* Reset all ccache defaults first */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* since KCM stores ccaches, better not crash.. */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "BUG: ccwrap contains NULL cc\n");
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose /* Then set the default for the right ccache. This also allows to
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * pass a null uuid to just reset the old ccache (for example after
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * deleting the default
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ccwrap = memdb_get_by_uuid(memdb, client, uuid);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_set_default_recv(struct tevent_req *req)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic struct tevent_req *ccdb_mem_get_default_send(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_get_default_state *state = NULL;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_get_default_state);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* Reset all ccache defaults first */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* since KCM stores ccaches, better not crash.. */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "BUG: ccwrap contains NULL cc\n");
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (ccwrap->cc->owner.uid == uid && ccwrap->is_default == true) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek "No ccache marked as default, returning null ccache\n");
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_get_default_recv(struct tevent_req *req,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ccdb_mem_get_default_state *state = tevent_req_data(req,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekstatic struct tevent_req *ccdb_mem_getbyuuid_send(TALLOC_CTX *mem_ctx,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct ccdb_mem_getbyuuid_state *state = NULL;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_getbyuuid_state);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ccwrap = memdb_get_by_uuid(memdb, client, uuid);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_getbyuuid_recv(struct tevent_req *req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_getbyuuid_state *state = tevent_req_data(req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic struct tevent_req *ccdb_mem_getbyname_send(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek const char *name)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_getbyname_state);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek ccwrap = memdb_get_by_name(memdb, client, name);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic errno_t ccdb_mem_getbyname_recv(struct tevent_req *req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_getbyname_state *state = tevent_req_data(req,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstruct tevent_req *ccdb_mem_name_by_uuid_send(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_name_by_uuid_state *state = NULL;
06d4c022874d4f12d70e79c3c749d52fe020dad6Lukas Slebodnik struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_name_by_uuid_state);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ccwrap = memdb_get_by_uuid(memdb, client, uuid);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina state->name = talloc_strdup(state, ccwrap->cc->name);
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozekerrno_t ccdb_mem_name_by_uuid_recv(struct tevent_req *req,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek const char **_name)
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek struct ccdb_mem_name_by_uuid_state *state = tevent_req_data(req,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozekstruct tevent_req *ccdb_mem_uuid_by_name_send(TALLOC_CTX *mem_ctx,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek const char *name)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem_uuid_by_name_state *state = NULL;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct ccdb_mem *memdb = talloc_get_type(db->db_handle, struct ccdb_mem);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ccdb_mem_uuid_by_name_state);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ccwrap = memdb_get_by_name(memdb, client, name);
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozekerrno_t ccdb_mem_uuid_by_name_recv(struct tevent_req *req,
526a15438525417cd701f837d7085b7f8c8a6325Jakub Hrozek struct ccdb_mem_uuid_by_name_state *state = tevent_req_data(req,
return NULL;
goto immediate;
return req;
return EOK;
return NULL;
goto immediate;
return req;
return EOK;
return NULL;
goto immediate;
goto immediate;
return req;
return EOK;
return NULL;
goto immediate;
return req;
return EOK;