|
|
bb7cd1 |
From b601cae66c441163a00f73c64d00a29e0840d44e Mon Sep 17 00:00:00 2001
|
|
|
bb7cd1 |
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
|
bb7cd1 |
Date: Fri, 24 Mar 2017 15:29:23 +0100
|
|
|
bb7cd1 |
Subject: [PATCH 46/54] SYSDB: Add methods to deal with the domain's resolution
|
|
|
bb7cd1 |
order
|
|
|
bb7cd1 |
MIME-Version: 1.0
|
|
|
bb7cd1 |
Content-Type: text/plain; charset=UTF-8
|
|
|
bb7cd1 |
Content-Transfer-Encoding: 8bit
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
In the following-up patches those newly introduced methods will be used
|
|
|
bb7cd1 |
to deal with the domainResolutionOrder attribute.
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
The sysdb_update_domain_resolution_order() method is purposely not
|
|
|
bb7cd1 |
checking whether a value has changed or not before writing to sysdb and
|
|
|
bb7cd1 |
while may not be optimal, the readability of the code has increased a
|
|
|
bb7cd1 |
lot by keeping it as simple as possible.
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
Tests for these new methods are part of the next commit.
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
Related:
|
|
|
bb7cd1 |
https://pagure.io/SSSD/sssd/issue/3001
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
bb7cd1 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
bb7cd1 |
---
|
|
|
bb7cd1 |
Makefile.am | 2 +
|
|
|
bb7cd1 |
src/db/sysdb.h | 2 +
|
|
|
bb7cd1 |
src/db/sysdb_domain_resolution_order.c | 169 +++++++++++++++++++++++++++++++++
|
|
|
bb7cd1 |
src/db/sysdb_domain_resolution_order.h | 37 ++++++++
|
|
|
bb7cd1 |
4 files changed, 210 insertions(+)
|
|
|
bb7cd1 |
create mode 100644 src/db/sysdb_domain_resolution_order.c
|
|
|
bb7cd1 |
create mode 100644 src/db/sysdb_domain_resolution_order.h
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
bb7cd1 |
index 359feddef298b0013c726409b7ba8b86504abf09..8052150be32d89813764e9bc436dfcb211a738d6 100644
|
|
|
bb7cd1 |
--- a/Makefile.am
|
|
|
bb7cd1 |
+++ b/Makefile.am
|
|
|
bb7cd1 |
@@ -736,6 +736,7 @@ dist_noinst_HEADERS = \
|
|
|
bb7cd1 |
src/db/sysdb_private.h \
|
|
|
bb7cd1 |
src/db/sysdb_services.h \
|
|
|
bb7cd1 |
src/db/sysdb_ssh.h \
|
|
|
bb7cd1 |
+ src/db/sysdb_domain_resolution_order.h \
|
|
|
bb7cd1 |
src/confdb/confdb.h \
|
|
|
bb7cd1 |
src/confdb/confdb_private.h \
|
|
|
bb7cd1 |
src/confdb/confdb_setup.h \
|
|
|
bb7cd1 |
@@ -995,6 +996,7 @@ libsss_util_la_SOURCES = \
|
|
|
bb7cd1 |
src/db/sysdb_idmap.c \
|
|
|
bb7cd1 |
src/db/sysdb_gpo.c \
|
|
|
bb7cd1 |
src/db/sysdb_certmap.c \
|
|
|
bb7cd1 |
+ src/db/sysdb_domain_resolution_order.c \
|
|
|
bb7cd1 |
src/monitor/monitor_sbus.c \
|
|
|
bb7cd1 |
src/providers/dp_auth_util.c \
|
|
|
bb7cd1 |
src/providers/dp_pam_data_util.c \
|
|
|
bb7cd1 |
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
|
|
|
bb7cd1 |
index 6762b51bee02911fb97d5d393fad2495504ee5ad..42d2857ed7765c17e7d84b0da93ed07758fbe012 100644
|
|
|
bb7cd1 |
--- a/src/db/sysdb.h
|
|
|
bb7cd1 |
+++ b/src/db/sysdb.h
|
|
|
bb7cd1 |
@@ -184,6 +184,8 @@
|
|
|
bb7cd1 |
#define SYSDB_OVERRIDE_GROUP_CLASS "groupOverride"
|
|
|
bb7cd1 |
#define SYSDB_OVERRIDE_DN "overrideDN"
|
|
|
bb7cd1 |
#define SYSDB_OVERRIDE_OBJECT_DN "overrideObjectDN"
|
|
|
bb7cd1 |
+#define SYSDB_USE_DOMAIN_RESOLUTION_ORDER "useDomainResolutionOrder"
|
|
|
bb7cd1 |
+#define SYSDB_DOMAIN_RESOLUTION_ORDER "domainResolutionOrder"
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
#define SYSDB_NEXTID_FILTER "("SYSDB_NEXTID"=*)"
|
|
|
bb7cd1 |
|
|
|
bb7cd1 |
diff --git a/src/db/sysdb_domain_resolution_order.c b/src/db/sysdb_domain_resolution_order.c
|
|
|
bb7cd1 |
new file mode 100644
|
|
|
bb7cd1 |
index 0000000000000000000000000000000000000000..63774461a1e9f3dc863220d418e29e06d6e6e6df
|
|
|
bb7cd1 |
--- /dev/null
|
|
|
bb7cd1 |
+++ b/src/db/sysdb_domain_resolution_order.c
|
|
|
bb7cd1 |
@@ -0,0 +1,169 @@
|
|
|
bb7cd1 |
+/*
|
|
|
bb7cd1 |
+ Authors:
|
|
|
bb7cd1 |
+ Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ Copyright (C) 2017 Red Hat
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
bb7cd1 |
+ it under the terms of the GNU General Public License as published by
|
|
|
bb7cd1 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
bb7cd1 |
+ (at your option) any later version.
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ This program is distributed in the hope that it will be useful,
|
|
|
bb7cd1 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
bb7cd1 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
bb7cd1 |
+ GNU General Public License for more details.
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ You should have received a copy of the GNU General Public License
|
|
|
bb7cd1 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
bb7cd1 |
+*/
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+#include <ldb.h>
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+#include "db/sysdb.h"
|
|
|
bb7cd1 |
+#include "db/sysdb_private.h"
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+static errno_t
|
|
|
bb7cd1 |
+sysdb_get_domain_resolution_order_string_attr(TALLOC_CTX *mem_ctx,
|
|
|
bb7cd1 |
+ struct sysdb_ctx *sysdb,
|
|
|
bb7cd1 |
+ struct ldb_dn *dn,
|
|
|
bb7cd1 |
+ const char *const *attrs,
|
|
|
bb7cd1 |
+ const char **_attr)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
bb7cd1 |
+ struct ldb_result *res;
|
|
|
bb7cd1 |
+ const char *attr;
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
bb7cd1 |
+ if (tmp_ctx == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = ldb_search(sysdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs,
|
|
|
bb7cd1 |
+ NULL);
|
|
|
bb7cd1 |
+ if (ret != LDB_SUCCESS) {
|
|
|
bb7cd1 |
+ ret = EIO;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ if (res->count > 1) {
|
|
|
bb7cd1 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
bb7cd1 |
+ "Base search returned [%d] results, expected 1.\n", res->count);
|
|
|
bb7cd1 |
+ ret = EINVAL;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ } else if (res->count == 0) {
|
|
|
bb7cd1 |
+ ret = ENOENT;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ } else {
|
|
|
bb7cd1 |
+ /* res->count == 1 */
|
|
|
bb7cd1 |
+ attr = ldb_msg_find_attr_as_string(res->msgs[0], attrs[0], NULL);
|
|
|
bb7cd1 |
+ if (attr == NULL) {
|
|
|
bb7cd1 |
+ ret = ENOENT;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ *_attr = talloc_steal(mem_ctx, attr);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = EOK;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+done:
|
|
|
bb7cd1 |
+ talloc_free(tmp_ctx);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+errno_t
|
|
|
bb7cd1 |
+sysdb_get_domain_resolution_order(TALLOC_CTX *mem_ctx,
|
|
|
bb7cd1 |
+ struct sysdb_ctx *sysdb,
|
|
|
bb7cd1 |
+ struct ldb_dn *dn,
|
|
|
bb7cd1 |
+ const char **_domain_resolution_order)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
bb7cd1 |
+ const char *domain_resolution_order = NULL;
|
|
|
bb7cd1 |
+ const char *attrs[] = { SYSDB_DOMAIN_RESOLUTION_ORDER, NULL };
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
bb7cd1 |
+ if (tmp_ctx == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = sysdb_get_domain_resolution_order_string_attr(
|
|
|
bb7cd1 |
+ tmp_ctx, sysdb, dn, attrs, &domain_resolution_order);
|
|
|
bb7cd1 |
+ if (ret != EOK && ret != ENOENT) {
|
|
|
bb7cd1 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
bb7cd1 |
+ "sysdb_get_domain_resolution_order_string_attr() failed "
|
|
|
bb7cd1 |
+ "[%d]: [%s]",
|
|
|
bb7cd1 |
+ ret, sss_strerror(ret));
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ } else if (ret == ENOENT) {
|
|
|
bb7cd1 |
+ *_domain_resolution_order = NULL;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ } else {
|
|
|
bb7cd1 |
+ /* ret == EOK */
|
|
|
bb7cd1 |
+ *_domain_resolution_order = talloc_steal(mem_ctx,
|
|
|
bb7cd1 |
+ domain_resolution_order);
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = EOK;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+done:
|
|
|
bb7cd1 |
+ talloc_free(tmp_ctx);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+errno_t
|
|
|
bb7cd1 |
+sysdb_update_domain_resolution_order(struct sysdb_ctx *sysdb,
|
|
|
bb7cd1 |
+ struct ldb_dn *dn,
|
|
|
bb7cd1 |
+ const char *domain_resolution_order)
|
|
|
bb7cd1 |
+{
|
|
|
bb7cd1 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
bb7cd1 |
+ struct ldb_message *msg;
|
|
|
bb7cd1 |
+ errno_t ret;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
bb7cd1 |
+ if (tmp_ctx == NULL) {
|
|
|
bb7cd1 |
+ return ENOMEM;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ msg = ldb_msg_new(tmp_ctx);
|
|
|
bb7cd1 |
+ if (msg == NULL) {
|
|
|
bb7cd1 |
+ ret = ENOMEM;
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ msg->dn = dn;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = ldb_msg_add_empty(msg, SYSDB_DOMAIN_RESOLUTION_ORDER,
|
|
|
bb7cd1 |
+ LDB_FLAG_MOD_REPLACE, NULL);
|
|
|
bb7cd1 |
+ if (ret != LDB_SUCCESS) {
|
|
|
bb7cd1 |
+ ret = sysdb_error_to_errno(ret);
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ if (domain_resolution_order != NULL) {
|
|
|
bb7cd1 |
+ ret = ldb_msg_add_string(msg, SYSDB_DOMAIN_RESOLUTION_ORDER,
|
|
|
bb7cd1 |
+ domain_resolution_order);
|
|
|
bb7cd1 |
+ if (ret != LDB_SUCCESS) {
|
|
|
bb7cd1 |
+ ret = sysdb_error_to_errno(ret);
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = ldb_modify(sysdb->ldb, msg);
|
|
|
bb7cd1 |
+ if (ret != LDB_SUCCESS) {
|
|
|
bb7cd1 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
bb7cd1 |
+ "ldb_modify()_failed: [%s][%d][%s]\n",
|
|
|
bb7cd1 |
+ ldb_strerror(ret), ret, ldb_errstring(sysdb->ldb));
|
|
|
bb7cd1 |
+ ret = sysdb_error_to_errno(ret);
|
|
|
bb7cd1 |
+ goto done;
|
|
|
bb7cd1 |
+ }
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ ret = EOK;
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+done:
|
|
|
bb7cd1 |
+ talloc_free(tmp_ctx);
|
|
|
bb7cd1 |
+ return ret;
|
|
|
bb7cd1 |
+}
|
|
|
bb7cd1 |
diff --git a/src/db/sysdb_domain_resolution_order.h b/src/db/sysdb_domain_resolution_order.h
|
|
|
bb7cd1 |
new file mode 100644
|
|
|
bb7cd1 |
index 0000000000000000000000000000000000000000..45d2ea63f6bc14cd3184994530846ee6f762d4d0
|
|
|
bb7cd1 |
--- /dev/null
|
|
|
bb7cd1 |
+++ b/src/db/sysdb_domain_resolution_order.h
|
|
|
bb7cd1 |
@@ -0,0 +1,37 @@
|
|
|
bb7cd1 |
+/*
|
|
|
bb7cd1 |
+ Authors:
|
|
|
bb7cd1 |
+ Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ Copyright (C) 2017 Red Hat
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
bb7cd1 |
+ it under the terms of the GNU General Public License as published by
|
|
|
bb7cd1 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
bb7cd1 |
+ (at your option) any later version.
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ This program is distributed in the hope that it will be useful,
|
|
|
bb7cd1 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
bb7cd1 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
bb7cd1 |
+ GNU General Public License for more details.
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+ You should have received a copy of the GNU General Public License
|
|
|
bb7cd1 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
bb7cd1 |
+*/
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+#ifndef _SYSDB_DOMAIN_RESOLUTION_ORDER_H_
|
|
|
bb7cd1 |
+#define _SYSDB_DOMAIN_RESOLUTION_ORDER_H_
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+#include "db/sysdb.h"
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+errno_t
|
|
|
bb7cd1 |
+sysdb_get_domain_resolution_order(TALLOC_CTX *mem_ctx,
|
|
|
bb7cd1 |
+ struct sysdb_ctx *sysdb,
|
|
|
bb7cd1 |
+ struct ldb_dn *dn,
|
|
|
bb7cd1 |
+ const char **_domain_resolution_order);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+errno_t
|
|
|
bb7cd1 |
+sysdb_update_domain_resolution_order(struct sysdb_ctx *sysdb,
|
|
|
bb7cd1 |
+ struct ldb_dn *dn,
|
|
|
bb7cd1 |
+ const char *domain_resolution_order);
|
|
|
bb7cd1 |
+
|
|
|
bb7cd1 |
+#endif /* _SYSDB_DOMAIN_RESOLUTION_ORDER_H_ */
|
|
|
bb7cd1 |
--
|
|
|
bb7cd1 |
2.9.3
|
|
|
bb7cd1 |
|