49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose System Database - certificate mapping rules related calls
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose Copyright (C) 2017 Sumit Bose <sbose@redhat.com>
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose This program is free software; you can redistribute it and/or modify
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose it under the terms of the GNU General Public License as published by
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose the Free Software Foundation; either version 3 of the License, or
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose (at your option) any later version.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose This program is distributed in the hope that it will be useful,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose GNU General Public License for more details.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose You should have received a copy of the GNU General Public License
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic errno_t sysdb_create_certmap_container(struct sysdb_ctx *sysdb,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose msg->dn = ldb_dn_new(msg, sysdb->ldb, SYSDB_TMPL_CERTMAP_BASE);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = ldb_msg_add_string(msg, SYSDB_CERTMAP_USER_NAME_HINT,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose /* do a synchronous add */
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose "Failed to add certmap container (%d, [%s])!\n",
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bosestatic errno_t sysdb_certmap_add(struct sysdb_ctx *sysdb,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_new failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_CERTMAP_CLASS);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_string failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_add_string(msg, SYSDB_NAME, certmap->name);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_string failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_add_string(msg, SYSDB_CERTMAP_MAPPING_RULE,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_string failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_add_string(msg, SYSDB_CERTMAP_MATCHING_RULE,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_string failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose el = talloc_zero(tmp_ctx, struct ldb_message_element);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose el->name = talloc_strdup(el, SYSDB_CERTMAP_DOMAINS);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose el->values = talloc_zero_array(el, struct ldb_val, c + 1);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose el->values[c].data = (uint8_t *) talloc_strdup(el->values,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose el->values[c].length = strlen(certmap->domains[c]);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_add_ulong(msg, SYSDB_CERTMAP_PRIORITY,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_ulong failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Error: %d (%s)\n", ret, sss_strerror(ret));
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Boseerrno_t sysdb_update_certmap(struct sysdb_ctx *sysdb,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose container_dn = ldb_dn_new(sysdb, sysdb->ldb, SYSDB_TMPL_CERTMAP_BASE);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_start failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_delete_recursive(sysdb, container_dn, true);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_recursive failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = sysdb_create_certmap_container(sysdb, user_name_hint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_create_certmap_container failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_certmap_add failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_transaction_commit failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Boseerrno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose struct certmap_info ***certmaps, bool *user_name_hint)
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose const char *config_attrs[] = {SYSDB_CERTMAP_USER_NAME_HINT,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose container_dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_TMPL_CERTMAP_BASE);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose ret = ldb_search(sysdb->ldb, tmp_ctx, &res, container_dn, LDB_SCOPE_BASE,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose "Failed to read certmap config, skipping.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_search failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_TRACE_FUNC, "No certificate maps found.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps = talloc_zero_array(tmp_ctx, struct certmap_info *, res->count + 1);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps[c] = talloc_zero(maps, struct certmap_info);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_NAME, NULL);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "The object [%s] doesn't have a name.\n",
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c],
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps[c]->map_rule = talloc_strdup(maps, tmp_str);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c],
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps[c]->match_rule = talloc_strdup(maps, tmp_str);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tmp_uint = ldb_msg_find_attr_as_uint64(res->msgs[c],
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Priority value [%lu] too large.\n",
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose (unsigned long) tmp_uint);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose tmp_el = ldb_msg_find_element(res->msgs[c], SYSDB_CERTMAP_DOMAINS);
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps[c]->domains = talloc_zero_array(maps[c], const char *,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose for (d = 0; d < num_values; d++) {
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose maps[c]->domains[d] = talloc_strndup(maps[c]->domains,
49f8ec8e0a3723a748bdb043d6dc1fb2a3977a8aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strndup failed.\n");