sysdb_subdomains.c revision 84c611c1b7c04cc7735ab54d4e5f48284b79e6fb
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer/*
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer SSSD
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer System Database - Sub-domain related calls
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer This program is free software; you can redistribute it and/or modify
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski it under the terms of the GNU General Public License as published by
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski the Free Software Foundation; either version 3 of the License, or
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski (at your option) any later version.
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer This program is distributed in the hope that it will be useful,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer but WITHOUT ANY WARRANTY; without even the implied warranty of
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer GNU General Public License for more details.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer You should have received a copy of the GNU General Public License
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer along with this program. If not, see <http://www.gnu.org/licenses/>.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer*/
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer#include "util/util.h"
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer#include "db/sysdb_private.h"
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer size_t *subdomain_count,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct subdomain_info ***subdomain_list)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer int i;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer errno_t ret;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer TALLOC_CTX *tmp_ctx;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_result *res;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *attrs[] = {"cn",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer SYSDB_SUBDOMAIN_FLAT,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer SYSDB_SUBDOMAIN_ID,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer NULL};
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct subdomain_info **list;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_dn *basedn;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *tmp_str;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_ctx = talloc_new(NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (tmp_ctx == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
0193c86704431f83731015a77cb613d67ae4e3c2Thiemo Wiedemeyer basedn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE);
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer if (basedn == NULL) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = EIO;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer goto done;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = ldb_search(sysdb->ldb, tmp_ctx, &res,
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer basedn, LDB_SCOPE_ONELEVEL,
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = EIO;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list = talloc_zero_array(tmp_ctx, struct subdomain_info *, res->count);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (list == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer for (i = 0; i < res->count; i++) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list[i] = talloc_zero(list, struct subdomain_info);
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder if (list[i] == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (tmp_str == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE, ("The object [%s] doesn't have a name\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ldb_dn_get_linearized(res->msgs[i]->dn)));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = EINVAL;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer list[i]->name = talloc_strdup(list, tmp_str);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (list[i]->name == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_SUBDOMAIN_FLAT, NULL);
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer if (tmp_str != NULL) {
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer list[i]->flat_name = talloc_strdup(list, tmp_str);
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer if (list[i]->flat_name == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_SUBDOMAIN_ID, NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (tmp_str != NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list[i]->id = talloc_strdup(list, tmp_str);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (list[i]->id == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian Maeder }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer *subdomain_count = res->count;
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer *subdomain_list = talloc_steal(mem_ctx, list);
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer ret = EOK;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerdone:
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer talloc_free(tmp_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return ret;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sysdb_ctx *sysdb,
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer struct subdomain_info **_info)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer errno_t ret;
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer TALLOC_CTX *tmp_ctx;
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer const char *tmp_str;
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer struct ldb_dn *basedn;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct subdomain_info *info;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_result *res;
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer const char *attrs[] = {"cn",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer SYSDB_SUBDOMAIN_FLAT,
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer SYSDB_SUBDOMAIN_ID,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer NULL};
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer tmp_ctx = talloc_new(NULL);
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer if (tmp_ctx == NULL) {
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer return ENOMEM;
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer }
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer info = talloc_zero(tmp_ctx, struct subdomain_info);
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer if (info == NULL) {
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer ret = ENOMEM;
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer goto done;
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer }
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer sysdb->domain->name);
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer if (basedn == NULL) {
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer ret = EIO;
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer goto done;
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer }
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs,
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer NULL);
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer if (ret != LDB_SUCCESS) {
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer ret = EIO;
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer goto done;
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer }
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer if (res->count != 1) {
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "expected 1.\n"));
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer ret = EINVAL;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer NULL);
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer if (tmp_str != NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer info->flat_name = talloc_strdup(info, tmp_str);
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer if (info->flat_name == NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer ret = ENOMEM;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer NULL);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (tmp_str != NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer info->flat_name = talloc_strdup(info, tmp_str);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (info->flat_name == NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer ret = ENOMEM;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer *_info = talloc_steal(mem_ctx, info);
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyerdone:
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer talloc_free(tmp_ctx);
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer return ret;
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer}
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb,
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer struct subdomain_info *domain_info)
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer{
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer TALLOC_CTX *tmp_ctx;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer struct ldb_message *msg;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer int ret;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer bool do_update = false;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer struct subdomain_info *current_info;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer tmp_ctx = talloc_new(NULL);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (tmp_ctx == NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return ENOMEM;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer ret = sysdb_master_domain_get_info(tmp_ctx, sysdb, &current_info);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (ret != EOK) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer msg = ldb_msg_new(tmp_ctx);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (msg == NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer ret = ENOMEM;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer msg->dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer sysdb->domain->name);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer if (msg->dn == NULL) {
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer ret = EIO;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer goto done;
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer }
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (domain_info->flat_name != NULL &&
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer (current_info->flat_name == NULL ||
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) {
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_REPLACE,
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer NULL);
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_FLAT, "%s",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer domain_info->flat_name);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer }
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer do_update = true;
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer }
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer if (domain_info->id != NULL &&
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer (current_info->flat_name == NULL ||
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer strcmp(current_info->flat_name, domain_info->id) != 0) ) {
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_REPLACE,
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer NULL);
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer if (ret != LDB_SUCCESS) {
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder goto done;
5107ba7da675778f2fded68493512b60eff8a455Christian Maeder }
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_ID, "%s",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer domain_info->id);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer do_update = true;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (do_update == false) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = EOK;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_modify(sysdb->ldb, msg);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "[%s]: [%d][%s]!\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer domain_info->name, ret,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ldb_errstring(sysdb->ldb)));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = EOK;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerdone:
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer talloc_free(tmp_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return ret;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstatic errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct subdomain_info *domain_info)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer TALLOC_CTX *tmp_ctx;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_message *msg;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer int ret;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_ctx = talloc_new(NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (tmp_ctx == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer msg = ldb_msg_new(tmp_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (msg == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer msg->dn = ldb_dn_new_fmt(msg, sysdb->ldb, SYSDB_DOM_BASE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer domain_info->name);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (msg->dn == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer }
6c59ae2c44a1fe22ef1712a57afe129e9dbd3368Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_OBJECTCLASS, "%s", SYSDB_SUBDOMAIN_CLASS);
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer goto done;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer }
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer if (domain_info->flat_name != NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_ADD,
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
97b8e548427713e0089a30fcc2df84e0f6aa7ffaCui Jian
97b8e548427713e0089a30fcc2df84e0f6aa7ffaCui Jian ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_FLAT, "%s",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer domain_info->flat_name);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
97b8e548427713e0089a30fcc2df84e0f6aa7ffaCui Jian ret = sysdb_error_to_errno(ret);;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
152e9fe73d97a51ab34ea7e6e6118521776a0e22Thiemo Wiedemeyer }
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (domain_info->id != NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_ADD,
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != LDB_SUCCESS) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer goto done;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_ID, "%s",
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer domain_info->id);
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich if (ret != LDB_SUCCESS) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);;
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer goto done;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = ldb_modify(sysdb->ldb, msg);
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich if (ret != LDB_SUCCESS) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer "[%s]: [%d][%s]!\n",
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer domain_info->name, ret,
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer ldb_errstring(sysdb->ldb)));
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer ret = sysdb_error_to_errno(ret);
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer goto done;
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer }
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = EOK;
76ecd8e01387d1edc9197f3464073264fa2c789aThiemo Wiedemeyer
76ecd8e01387d1edc9197f3464073264fa2c789aThiemo Wiedemeyerdone:
76ecd8e01387d1edc9197f3464073264fa2c789aThiemo Wiedemeyer talloc_free(tmp_ctx);
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich
76ecd8e01387d1edc9197f3464073264fa2c789aThiemo Wiedemeyer return ret;
76ecd8e01387d1edc9197f3464073264fa2c789aThiemo Wiedemeyer}
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyererrno_t sysdb_update_subdomains(struct sysdb_ctx *sysdb,
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyer struct subdomain_info **subdomains)
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyer{
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich int ret;
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich int sret;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer size_t c;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer size_t d;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer TALLOC_CTX *tmp_ctx = NULL;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer size_t cur_subdomains_count;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer struct subdomain_info **cur_subdomains;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer struct ldb_dn *dn;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer bool in_transaction = false;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer bool *keep_subdomain;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer tmp_ctx = talloc_new(NULL);
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyer if (tmp_ctx == NULL) {
ba5cdd22d00311dfa1f594bc704d99492dd1dca6Thiemo Wiedemeyer ret = ENOMEM;
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyer goto done;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer }
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer /* Retrieve all subdomains that are currently in sysdb */
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer ret = sysdb_get_subdomains(tmp_ctx, sysdb, &cur_subdomains_count,
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer &cur_subdomains);
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer if (ret != EOK) {
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_subdomains failed.\n"));
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer goto done;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer }
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer keep_subdomain = talloc_zero_array(tmp_ctx, bool, cur_subdomains_count);
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer if (keep_subdomain == NULL) {
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer ret = ENOMEM;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero_array failed.\n"));
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer goto done;
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer }
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_transaction_start(sysdb);
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer if (ret != EOK) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_transaction_start failed.\n"));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer goto done;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer in_transaction = true;
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer /* Go through a list of retrieved subdomains and:
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer * - if a subdomain already exists in sysdb, mark it for preservation
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer * - if the subdomain doesn't exist in sysdb, create its bare structure
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer */
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer for (c = 0; subdomains[c] != NULL; c++) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer for (d = 0; d < cur_subdomains_count; d++) {
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian if (strcasecmp(subdomains[c]->name, cur_subdomains[d]->name) == 0) {
da955132262baab309a50fdffe228c9efe68251dCui Jian keep_subdomain[d] = true;
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian /* sub-domain already in cache, nothing to do */
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian break;
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian }
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer if (d == cur_subdomains_count) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_TRACE_FUNC, ("Adding sub-domain [%s].\n",
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer subdomains[c]->name));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_domain_create(sysdb, subdomains[c]->name);
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder if (ret != EOK) {
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder DEBUG(SSSDBG_OP_FAILURE, ("sysdb_domain_create failed.\n"));
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder goto done;
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich }
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_add_subdomain_attributes(sysdb, subdomains[c]);
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer if (ret != EOK) {
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE,
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ("sysdb_add_subdomain_attributes failed.\n"));
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich goto done;
fe1f344573c570949fa4f255c68bb9026c609832Thiemo Wiedemeyer }
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich }
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder }
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich /* Now delete all subdomains that have been in sysdb prior to
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder * refreshing the list and are not marked for preservation
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer * (i.e. they are not in the new list of subdomains)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer */
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer for (d = 0; d < cur_subdomains_count; d++) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (!keep_subdomain[d]) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_TRACE_FUNC, ("Removing sub-domain [%s].\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer cur_subdomains[d]->name));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer cur_subdomains[d]->name);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (dn == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ENOMEM;
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer ret = sysdb_delete_recursive(sysdb, dn, true);
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer if (ret != EOK) {
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer goto done;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = sysdb_transaction_commit(sysdb);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret == EOK) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer in_transaction = false;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer } else {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE, ("Could not commit transaction\n"));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerdone:
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (in_transaction) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sret = sysdb_transaction_cancel(sysdb);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (sret != EOK) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
5107ba7da675778f2fded68493512b60eff8a455Christian Maeder }
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer talloc_free(tmp_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return ret;
5107ba7da675778f2fded68493512b60eff8a455Christian Maeder}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_get_subdomain_context(TALLOC_CTX *mem_ctx,
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer struct sysdb_ctx *sysdb,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_domain_info *subdomain,
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer struct sysdb_ctx **subdomain_ctx)
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sysdb_ctx *new_ctx;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer new_ctx = talloc_zero(mem_ctx, struct sysdb_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (new_ctx == NULL) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return ENOMEM;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer new_ctx->domain = subdomain;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer new_ctx->mpg = true;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer new_ctx->ldb = sysdb->ldb;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer new_ctx->ldb_file = sysdb->ldb_file;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer *subdomain_ctx = new_ctx;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer return EOK;
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer}
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer
aa07f9c4585a94514dcff2979d853d6e04c12fb9Thiemo Wiedemeyer#define CHECK_DOMAIN_INFO(dom_info) do { \
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (dom_info == NULL || dom_info->sysdb == NULL) { \
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("Invalid domain info.\n")); \
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return EINVAL; \
be688cc3aa83344b0141321d2d20bf6a8d5c5686Christian Maeder } \
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer} while(0)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domuser_by_name(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *name,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer const char **attrs,
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer struct ldb_message **msg)
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer{
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_search_user_by_name(mem_ctx, domain->sysdb, name, attrs, msg);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer}
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_search_domuser_by_uid(TALLOC_CTX *mem_ctx,
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer struct sss_domain_info *domain,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer uid_t uid,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer const char **attrs,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer struct ldb_message **msg)
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer{
308f8e668578eadb8b2eb2af4abd0d63c656505aChristian Maeder CHECK_DOMAIN_INFO(domain);
308f8e668578eadb8b2eb2af4abd0d63c656505aChristian Maeder
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_search_user_by_uid(mem_ctx, domain->sysdb, uid, attrs, msg);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer}
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyererrno_t sysdb_store_domuser(struct sss_domain_info *domain,
a44f1558006c43dda309b3d1e5a1214443f07048Thiemo Wiedemeyer const char *name,
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer const char *pwd,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer uid_t uid, gid_t gid,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer const char *gecos,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer const char *homedir,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer const char *shell,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer struct sysdb_attrs *attrs,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer char **remove_attrs,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer uint64_t cache_timeout,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer time_t now)
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer{
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_store_user(domain->sysdb, name, pwd, uid, gid, gecos, homedir,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer shell, attrs, remove_attrs, cache_timeout, now);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_delete_domuser(struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *name, uid_t uid)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_delete_user(domain->sysdb, name, uid);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domgroup_by_name(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_domain_info *domain,
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer const char *name,
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer const char **attrs,
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer struct ldb_message **msg)
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
da955132262baab309a50fdffe228c9efe68251dCui Jian return sysdb_search_group_by_name(mem_ctx, domain->sysdb, name, attrs, msg);
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domgroup_by_gid(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_domain_info *domain,
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian gid_t gid,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char **attrs,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_message **msg)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_search_group_by_gid(mem_ctx, domain->sysdb, gid, attrs, msg);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_store_domgroup(struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *name,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer gid_t gid,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sysdb_attrs *attrs,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer uint64_t cache_timeout,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer time_t now)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_store_group(domain->sysdb, name, gid, attrs, cache_timeout,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer now);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_delete_domgroup(struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char *name, gid_t gid)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer CHECK_DOMAIN_INFO(domain);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_delete_group(domain->sysdb, name, gid);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer}
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer