817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher Copyright (C) 2012 Red Hat
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher This program is free software; you can redistribute it and/or modify
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher it under the terms of the GNU General Public License as published by
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher the Free Software Foundation; either version 3 of the License, or
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher (at your option) any later version.
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher This program is distributed in the hope that it will be useful,
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher GNU General Public License for more details.
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher You should have received a copy of the GNU General Public License
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
9a7b6d3248c5aac460e164f2246b26131cfbc055Simo Sorcestatic struct ldb_dn *
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozeksysdb_idmap_dn(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain,
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher ret = sysdb_dn_sanitize(NULL, object_sid, &clean_sid);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, SYSDB_TMPL_IDMAP"\n", clean_sid, domain->name);
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek dn = ldb_dn_new_fmt(mem_ctx, domain->sysdb->ldb, SYSDB_TMPL_IDMAP,
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozeksysdb_idmap_store_mapping(struct sss_domain_info *domain,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek static const char *attrs[] = SYSDB_IDMAP_ATTRS;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Check for an existing mapping */
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek ret = sysdb_search_entry(tmp_ctx, domain->sysdb, dn, LDB_SCOPE_BASE,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* More than one reply for a base search? */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Create a new mapping */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding new ID mapping [%s][%s][%lu]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov dom_name, dom_sid, (unsigned long)slice_num);
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Add the objectClass */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_empty(update_msg, SYSDB_OBJECTCLASS,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_string(update_msg, SYSDB_OBJECTCLASS,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Add the domain objectSID */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_empty(update_msg, SYSDB_IDMAP_SID_ATTR,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_string(update_msg, SYSDB_IDMAP_SID_ATTR, dom_sid);
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Add the domain name */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_empty(update_msg, SYSDB_NAME,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_string(update_msg, SYSDB_NAME, dom_name);
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Add the slice number */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_empty(update_msg, SYSDB_IDMAP_SLICE_ATTR,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_fmt(update_msg, SYSDB_IDMAP_SLICE_ATTR,
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek lret = ldb_add(domain->sysdb->ldb, update_msg);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add mapping: [%s]\n",
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Update the existing mapping */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Check whether the slice has changed
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek * This should never happen, and it's a recipe for
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek * disaster. We'll throw an error if it does.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not identify original slice for SID [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Detected attempt to change slice value for sid [%s] "
7486dea9f5f7b2a6fbbacc6db740a82140b6377cLukas Slebodnik "This will break existing users. Refusing to perform.\n",
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Check whether the name has changed. This may happen
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek * if we're told the real name of a domain and want to
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek * replace the SID as placeholder.
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek old_name = ldb_msg_find_attr_as_string(msgs[0], SYSDB_NAME, NULL);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not identify original domain name of SID [%s]\n",
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* There's nothing to be done. We don't need to
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek * make any changes here. Just return success.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "No changes needed, canceling transaction\n");
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* The name has changed. Replace it */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Changing domain name of SID [%s] from [%s] to [%s]\n",
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek /* Set the new name */
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_empty(update_msg, SYSDB_NAME,
3a59cbd0b7b9c5dd3c62ac1679876070c264d80fMichal Zidek lret = ldb_msg_add_string(update_msg, SYSDB_NAME, dom_name);
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek lret = ldb_modify(domain->sysdb->ldb, update_msg);
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik "Failed to update mapping: [%s](%d)[%s]\n",
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik ldb_strerror(lret), lret, ldb_errstring(domain->sysdb->ldb));
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not commit transaction: [%s]\n", strerror(ret));
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek sret = sysdb_transaction_cancel(domain->sysdb);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not cancel transaction\n");
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallaghersysdb_idmap_get_mappings(TALLOC_CTX *mem_ctx,
817b1bcafff27cc67630dd0cbd36df708c05fcccStephen Gallagher static const char *attrs[] = SYSDB_IDMAP_ATTRS;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, SYSDB_TMPL_IDMAP_BASE"\n", domain->name);
7d056853e4a5fe6daa5743e38d21b4493f4fca27Jakub Hrozek base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
a5b55bdfcda8bfce8cb2ced981773998093d7857Pavel Reichl SSS_LDB_SEARCH(ret, domain->sysdb->ldb, tmp_ctx, &res, base_dn,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not locate ID mappings: [%s]\n",