sssd/0051-UTIL-move-files-selinu...

345 lines
12 KiB
Diff

From 5b93634c7f0e34f69b4cf8fb9b2e77b9179024a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Wed, 2 Aug 2017 12:10:10 +0200
Subject: [PATCH 51/93] UTIL: move {files,selinux}.c under util directory
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
files.c has at least one function that will be re-used for the new
session provider that's about to be added. Also, a few other functions
may be added and files.c seems the right place for those.
selinux.c has been moved together with files.c as the latter takes
advantage of some functions from the former and we do not want to always
link agains the tools code.
The public functions from files.c got a "sss_" prefix and it has been
changed whenever they're used.
Last but not least, all the places that included "tools/tools_util.h"
due to the functions on files.c had this include removed (as they were
already including "util/util.h".
Related:
https://pagure.io/SSSD/sssd/issue/2995
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
Makefile.am | 8 ++++----
src/tests/files-tests.c | 13 ++++++-------
src/tools/sssctl/sssctl_data.c | 3 +--
src/tools/sssctl/sssctl_logs.c | 3 +--
src/tools/tools_util.c | 5 ++---
src/tools/tools_util.h | 17 -----------------
src/{tools => util}/files.c | 22 +++++++++++-----------
src/{tools => util}/selinux.c | 0
src/util/util.h | 19 +++++++++++++++++++
9 files changed, 44 insertions(+), 46 deletions(-)
rename src/{tools => util}/files.c (98%)
rename src/{tools => util}/selinux.c (100%)
diff --git a/Makefile.am b/Makefile.am
index 161db198061f1a636b77721b42997158543be68d..c292c1317ae45ae73cc3e86eb464d72e77eaf1fe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -583,8 +583,6 @@ SSSD_RESPONDER_OBJ = \
SSSD_TOOLS_OBJ = \
src/tools/sss_sync_ops.c \
src/tools/tools_util.c \
- src/tools/files.c \
- src/tools/selinux.c \
src/tools/common/sss_tools.c \
src/tools/common/sss_process.c \
src/confdb/confdb_setup.c \
@@ -1052,6 +1050,8 @@ libsss_util_la_SOURCES = \
src/util/become_user.c \
src/util/util_watchdog.c \
src/util/sss_ptr_hash.c \
+ src/util/files.c \
+ src/util/selinux.c \
$(NULL)
libsss_util_la_CFLAGS = \
$(AM_CFLAGS) \
@@ -2016,8 +2016,8 @@ files_tests_SOURCES = \
src/tests/files-tests.c \
src/util/check_and_open.c \
src/util/atomic_io.c \
- src/tools/selinux.c \
- src/tools/files.c
+ src/util/selinux.c \
+ src/util/files.c
files_tests_CFLAGS = \
$(AM_CFLAGS) \
$(CHECK_CFLAGS)
diff --git a/src/tests/files-tests.c b/src/tests/files-tests.c
index e96a60af1817b5f7a2e99d8b09ebc91c1a52667b..9feb9274ace02dd977950b8de220ee1f1aa18e65 100644
--- a/src/tests/files-tests.c
+++ b/src/tests/files-tests.c
@@ -32,7 +32,6 @@
#include <popt.h>
#include "config.h"
-#include "tools/tools_util.h"
#include "util/util.h"
#include "tests/common.h"
@@ -144,7 +143,7 @@ START_TEST(test_remove_tree)
fail_if(ret == -1, "Cannot chdir\n");
/* and finally wipe it out.. */
- ret = remove_tree(dir_path);
+ ret = sss_remove_tree(dir_path);
fail_unless(ret == EOK, "remove_tree failed\n");
/* check if really gone */
@@ -193,7 +192,7 @@ START_TEST(test_remove_subtree)
fail_if(ret == -1, "Cannot chdir\n");
/* and finally wipe it out.. */
- ret = remove_subtree(dir_path);
+ ret = sss_remove_subtree(dir_path);
fail_unless(ret == EOK, "remove_subtree failed\n");
/* check if really gone */
@@ -240,7 +239,7 @@ START_TEST(test_simple_copy)
/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
- ret = copy_tree(dir_path, dst_path, 0700, uid, gid);
+ ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
fail_unless(ret == EOK, "copy_tree failed\n");
/* check if really copied */
@@ -284,7 +283,7 @@ START_TEST(test_copy_file)
/* Copy this file to a new file */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from 'foo' to 'bar'\n");
- ret = copy_file_secure(foo_path, bar_path, 0700, uid, gid, 0);
+ ret = sss_copy_file_secure(foo_path, bar_path, 0700, uid, gid, 0);
fail_unless(ret == EOK, "copy_file_secure failed\n");
/* check if really copied */
@@ -326,7 +325,7 @@ START_TEST(test_copy_symlink)
/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
- ret = copy_tree(dir_path, dst_path, 0700, uid, gid);
+ ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
fail_unless(ret == EOK, "copy_tree failed\n");
/* check if really copied */
@@ -365,7 +364,7 @@ START_TEST(test_copy_node)
/* and finally copy.. */
DEBUG(SSSDBG_FUNC_DATA,
"Will copy from '%s' to '%s'\n", dir_path, dst_path);
- ret = copy_tree(dir_path, dst_path, 0700, uid, gid);
+ ret = sss_copy_tree(dir_path, dst_path, 0700, uid, gid);
fail_unless(ret == EOK, "copy_tree failed\n");
/* check if really copied and without special files */
diff --git a/src/tools/sssctl/sssctl_data.c b/src/tools/sssctl/sssctl_data.c
index 29c5e676056ce4bd4abf579e14963680731e10a9..860c5df55094a44e23da683b6a6b3c92902f985b 100644
--- a/src/tools/sssctl/sssctl_data.c
+++ b/src/tools/sssctl/sssctl_data.c
@@ -23,7 +23,6 @@
#include "util/util.h"
#include "db/sysdb.h"
-#include "tools/common/sss_tools.h"
#include "tools/common/sss_process.h"
#include "tools/sssctl/sssctl.h"
#include "tools/tools_util.h"
@@ -241,7 +240,7 @@ errno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
}
printf(_("Removing cache files...\n"));
- ret = remove_subtree(DB_PATH);
+ ret = sss_remove_subtree(DB_PATH);
if (ret != EOK) {
fprintf(stderr, _("Unable to remove cache files\n"));
return ret;
diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c
index 1aea54e36a8b566f20f352871c0950de1c038960..472a553d1700f097f856d64c036c6b4f646ede59 100644
--- a/src/tools/sssctl/sssctl_logs.c
+++ b/src/tools/sssctl/sssctl_logs.c
@@ -23,7 +23,6 @@
#include <signal.h>
#include "util/util.h"
-#include "tools/common/sss_tools.h"
#include "tools/common/sss_process.h"
#include "tools/sssctl/sssctl.h"
#include "tools/tools_util.h"
@@ -57,7 +56,7 @@ errno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
if (opts.delete) {
printf(_("Deleting log files...\n"));
- ret = remove_subtree(LOG_PATH);
+ ret = sss_remove_subtree(LOG_PATH);
if (ret != EOK) {
fprintf(stderr, _("Unable to remove log files\n"));
return ret;
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 5e51a4089e48d44347d87ba1beec6fff9ca30748..87a17491d52649da8ec48d6147e161e59298beaa 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -33,7 +33,6 @@
#include "util/util.h"
#include "confdb/confdb.h"
#include "db/sysdb.h"
-#include "tools/tools_util.h"
#include "tools/sss_sync_ops.h"
static int setup_db(struct tools_ctx *ctx)
@@ -414,7 +413,7 @@ int remove_homedir(TALLOC_CTX *mem_ctx,
}
/* Remove the tree */
- ret = remove_tree(homedir);
+ ret = sss_remove_tree(homedir);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot remove homedir %s: %d\n",
homedir, ret);
@@ -502,7 +501,7 @@ int create_homedir(const char *skeldir,
selinux_file_context(homedir);
- ret = copy_tree(skeldir, homedir, 0777 & ~default_umask, uid, gid);
+ ret = sss_copy_tree(skeldir, homedir, 0777 & ~default_umask, uid, gid);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Cannot populate user's home directory: [%d][%s].\n",
diff --git a/src/tools/tools_util.h b/src/tools/tools_util.h
index 389c7b5c4563118ccb7fdc9448a0879638a35a0b..fcfd8a659c1c0c61d9afda72c7bbacb9c97dddfd 100644
--- a/src/tools/tools_util.h
+++ b/src/tools/tools_util.h
@@ -111,21 +111,4 @@ errno_t sss_mc_refresh_group(const char *groupname);
errno_t sss_mc_refresh_grouplist(struct tools_ctx *tctx,
char **groupnames);
-/* from files.c */
-int remove_tree(const char *root);
-int remove_subtree(const char *root);
-
-int copy_tree(const char *src_root, const char *dst_root,
- mode_t mode_root, uid_t uid, gid_t gid);
-int
-copy_file_secure(const char *src,
- const char *dest,
- mode_t mode,
- uid_t uid, gid_t gid,
- bool force);
-
-/* from selinux.c */
-int selinux_file_context(const char *dst_name);
-int reset_selinux_file_context(void);
-
#endif /* __TOOLS_UTIL_H__ */
diff --git a/src/tools/files.c b/src/util/files.c
similarity index 98%
rename from src/tools/files.c
rename to src/util/files.c
index 9f4e7caa7257144702c417c39bc1643f0be8661a..5827b29d8b5cf13248514f693e859d42335069d9 100644
--- a/src/tools/files.c
+++ b/src/util/files.c
@@ -65,7 +65,6 @@
#include <talloc.h>
#include "util/util.h"
-#include "tools/tools_util.h"
struct copy_ctx {
const char *src_orig;
@@ -140,7 +139,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
dev_t parent_dev,
bool keep_root_dir);
-int remove_tree(const char *root)
+int sss_remove_tree(const char *root)
{
TALLOC_CTX *tmp_ctx = NULL;
int ret;
@@ -155,7 +154,7 @@ int remove_tree(const char *root)
return ret;
}
-int remove_subtree(const char *root)
+int sss_remove_subtree(const char *root)
{
TALLOC_CTX *tmp_ctx = NULL;
int ret;
@@ -489,11 +488,11 @@ done:
}
int
-copy_file_secure(const char *src,
- const char *dest,
- mode_t mode,
- uid_t uid, gid_t gid,
- bool force)
+sss_copy_file_secure(const char *src,
+ const char *dest,
+ mode_t mode,
+ uid_t uid, gid_t gid,
+ bool force)
{
int ifd = -1;
int ofd = -1;
@@ -761,8 +760,10 @@ done:
* For several reasons, including the fact that we copy even special files
* (pipes, etc) from the skeleton directory, the skeldir needs to be trusted
*/
-int copy_tree(const char *src_root, const char *dst_root,
- mode_t mode_root, uid_t uid, gid_t gid)
+int sss_copy_tree(const char *src_root,
+ const char *dst_root,
+ mode_t mode_root,
+ uid_t uid, gid_t gid)
{
int ret = EOK;
struct copy_ctx *cctx = NULL;
@@ -806,4 +807,3 @@ fail:
talloc_free(cctx);
return ret;
}
-
diff --git a/src/tools/selinux.c b/src/util/selinux.c
similarity index 100%
rename from src/tools/selinux.c
rename to src/util/selinux.c
diff --git a/src/util/util.h b/src/util/util.h
index 9b64dead88f05f16b00e73d59b2af06dcd485ff7..80411ec91046b7dc7993b8d175fedebd2b70a79a 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -681,4 +681,23 @@ int sss_unique_filename(TALLOC_CTX *owner, char *path_tmpl);
int setup_watchdog(struct tevent_context *ev, int interval);
void teardown_watchdog(void);
+/* from files.c */
+int sss_remove_tree(const char *root);
+int sss_remove_subtree(const char *root);
+
+int sss_copy_tree(const char *src_root,
+ const char *dst_root,
+ mode_t mode_root,
+ uid_t uid, gid_t gid);
+
+int sss_copy_file_secure(const char *src,
+ const char *dest,
+ mode_t mode,
+ uid_t uid, gid_t gid,
+ bool force);
+
+/* from selinux.c */
+int selinux_file_context(const char *dst_name);
+int reset_selinux_file_context(void);
+
#endif /* __SSSD_UTIL_H__ */
--
2.14.1