dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0031-SYSDB-Allow-calling-chown-on-the-sysdb-file-from-mon.patch

905b4d
From 3c97e3ab74309934687e65a768fb843d8b4608fa Mon Sep 17 00:00:00 2001
905b4d
From: Michal Zidek <mzidek@redhat.com>
905b4d
Date: Thu, 9 Oct 2014 17:21:30 +0200
905b4d
Subject: [PATCH 31/46] SYSDB: Allow calling chown on the sysdb file from
905b4d
 monitor
905b4d
905b4d
Sysdb must be accessible for the nonroot sssd
905b4d
processes.
905b4d
905b4d
Reviewed-by: Pavel Reichl <preichl@redhat.com>
905b4d
Reviewed-by: Simo Sorce <simo@redhat.com>
905b4d
(cherry picked from commit 0887c35bdb85adf0a4376dc8963294ea5a9d6da6)
905b4d
---
905b4d
 src/db/sysdb.c        | 21 +++++++++++++++++++++
905b4d
 src/db/sysdb.h        |  9 +++++++++
905b4d
 src/monitor/monitor.c |  3 ++-
905b4d
 3 files changed, 32 insertions(+), 1 deletion(-)
905b4d
905b4d
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
905b4d
index 8d6f00b52976228bfc9dfdc93503148837677346..1f02585e747dda6aadde772f76f30d3d69c4cfc0 100644
905b4d
--- a/src/db/sysdb.c
905b4d
+++ b/src/db/sysdb.c
905b4d
@@ -1322,6 +1322,16 @@ int sysdb_init(TALLOC_CTX *mem_ctx,
905b4d
                struct sss_domain_info *domains,
905b4d
                bool allow_upgrade)
905b4d
 {
905b4d
+    return sysdb_init_ext(mem_ctx, domains, allow_upgrade, false, 0, 0);
905b4d
+}
905b4d
+
905b4d
+int sysdb_init_ext(TALLOC_CTX *mem_ctx,
905b4d
+                   struct sss_domain_info *domains,
905b4d
+                   bool allow_upgrade,
905b4d
+                   bool chown_dbfile,
905b4d
+                   uid_t uid,
905b4d
+                   gid_t gid)
905b4d
+{
905b4d
     struct sss_domain_info *dom;
905b4d
     struct sysdb_ctx *sysdb;
905b4d
     int ret;
905b4d
@@ -1343,6 +1353,17 @@ int sysdb_init(TALLOC_CTX *mem_ctx,
905b4d
             return ret;
905b4d
         }
905b4d
 
905b4d
+        if (chown_dbfile) {
905b4d
+            ret = chown(sysdb->ldb_file, uid, gid);
905b4d
+            if (ret != 0) {
905b4d
+                ret = errno;
905b4d
+                DEBUG(SSSDBG_CRIT_FAILURE,
905b4d
+                      "Cannot set sysdb ownership to %"SPRIuid":%"SPRIgid"\n",
905b4d
+                      uid, gid);
905b4d
+                return ret;
905b4d
+            }
905b4d
+        }
905b4d
+
905b4d
         dom->sysdb = talloc_move(dom, &sysdb);
905b4d
     }
905b4d
 
905b4d
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
905b4d
index 0d0971d98dd684e47ae8ec067447169f41ebba67..ebb1bbedaf2df3030a012f1f0be8c5a069399cc3 100644
905b4d
--- a/src/db/sysdb.h
905b4d
+++ b/src/db/sysdb.h
905b4d
@@ -533,6 +533,15 @@ uint64_t sss_view_ldb_msg_find_attr_as_uint64(struct sss_domain_info *dom,
905b4d
 int sysdb_init(TALLOC_CTX *mem_ctx,
905b4d
                struct sss_domain_info *domains,
905b4d
                bool allow_upgrade);
905b4d
+
905b4d
+/* Same as sysdb_init, but additionally allows to change
905b4d
+ * file ownership of the sysdb databases. */
905b4d
+int sysdb_init_ext(TALLOC_CTX *mem_ctx,
905b4d
+                   struct sss_domain_info *domains,
905b4d
+                   bool allow_upgrade,
905b4d
+                   bool chown_dbfile,
905b4d
+                   uid_t uid, gid_t gid);
905b4d
+
905b4d
 /* used to initialize only one domain database.
905b4d
  * Do NOT use if sysdb_init has already been called */
905b4d
 int sysdb_domain_init(TALLOC_CTX *mem_ctx,
905b4d
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
905b4d
index 37f6e928be3508762e1c3afadbb67762f5cc1d38..04702428c4ed7fd1d77c6f18e491fa69b3700f4f 100644
905b4d
--- a/src/monitor/monitor.c
905b4d
+++ b/src/monitor/monitor.c
905b4d
@@ -2312,7 +2312,8 @@ static int monitor_process_init(struct mt_ctx *ctx,
905b4d
     if (!tmp_ctx) {
905b4d
         return ENOMEM;
905b4d
     }
905b4d
-    ret = sysdb_init(tmp_ctx, ctx->domains, true);
905b4d
+    ret = sysdb_init_ext(tmp_ctx, ctx->domains, true,
905b4d
+                         true, ctx->uid, ctx->gid);
905b4d
     if (ret != EOK) {
905b4d
         SYSDB_VERSION_ERROR_DAEMON(ret);
905b4d
         return ret;
905b4d
-- 
905b4d
1.9.3
905b4d