On 28.1.2014 16:45, Petr Spacek wrote:
Hello,

Move temporary files to /var/named/dyndb-ldap directory.

This should make RPM packaging easier.

This patch should go to master branch before 4.0 release.

This version fixes packaging problems found by Tomas Hozza.

--
Petr^2 Spacek
From a52962e15968ff5cee893d6a9ba1987b0994071c Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Tue, 28 Jan 2014 16:30:09 +0100
Subject: [PATCH] Move temporary files to /var/named/dyndb-ldap directory.

This should make RPM packaging easier.
---
 README                       |  7 ++++---
 contrib/bind-dyndb-ldap.spec |  6 ++++++
 src/fs.c                     | 27 +++++++++++++++++++++++++++
 src/fs.h                     |  2 +-
 src/ldap_helper.c            |  7 ++++---
 src/zone_register.c          |  2 +-
 6 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/README b/README
index 25f516c9bed9aeea0c547666e75aec3afa5112c4..b2c3653ef3ae653e4454ec43e341a220a4968e8f 100644
--- a/README
+++ b/README
@@ -259,7 +259,8 @@ verbose_checks (default no)
 	debugging purposes. It could produce huge amount of log messages
 	on a loaded system!
 
-directory (default is current instance name from dynamic-db directive)
+directory (default is
+           "dyndb-ldap/<current instance name from dynamic-db directive>")
 	Specifies working directory for plug-in. The path has to be writeable
 	by named because plug-in will create sub-directory for each zone.
 	These sub-directories will contain temporary files like zone dump, zone
@@ -288,9 +289,9 @@ base for entries with object class idnsZone, for which the
 idnsZoneActive attribute is set to True. For each entry it will find, it
 will register a new zone with BIND. The LDAP back-end will keep each
 record it gets from LDAP in its memory.
-Working directory for the plug-in will be "/var/named/my_db_name/",
+Working directory for the plug-in will be "/var/named/dyndb-ldap/my_db_name/",
 so hypothetical zone "example.com" will use sub-directory
-"/var/named/my_db_name/example.com/".
+"/var/named/dyndb-ldap/my_db_name/example.com/".
 
 5.3 Configuration in LDAP
 -------------------------
diff --git a/contrib/bind-dyndb-ldap.spec b/contrib/bind-dyndb-ldap.spec
index e28bf5195cd6bb3bed24d71d7c834c93cdf2df41..65a64120e8637ce2eda9c091231cbf5a19391da0 100644
--- a/contrib/bind-dyndb-ldap.spec
+++ b/contrib/bind-dyndb-ldap.spec
@@ -35,6 +35,7 @@ make %{?_smp_mflags}
 %install
 rm -rf %{buildroot}
 make install DESTDIR=%{buildroot}
+mkdir -m 770 -p %{buildroot}/%{_localstatedir}/named/dyndb-ldap
 
 # Remove unwanted files
 rm %{buildroot}%{_libdir}/bind/ldap.la
@@ -48,9 +49,14 @@ rm -rf %{buildroot}
 %files
 %defattr(-,root,root,-)
 %doc NEWS README COPYING doc/{example.ldif,schema}
+%dir %{_localstatedir}/named/dyndb-ldap
+%attr(770, root, named) %{_localstatedir}/named/dyndb-ldap
 %{_libdir}/bind/ldap.so
 
 
 %changelog
+* Tue Jan 28 2014 Petr Spacek <pspacek redhat com>
+- package /var/named/dyndb-ldap directory
+
 * Mon Nov 14 2011 Adam Tkac <atkac redhat com>
 - specfile to build bind-dyndb-ldap
diff --git a/src/fs.c b/src/fs.c
index ba7003ced895e26b134421c055049e8b9f049fb3..44eebc141bb2a881c95c0f729271e6e1450c9cbe 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -28,6 +28,7 @@
 #include <isc/file.h>
 #include <isc/errno2result.h>
 #include <isc/result.h>
+#include <isc/string.h>
 #include <isc/util.h>
 
 #include "log.h"
@@ -70,6 +71,32 @@ fs_dir_create(const char *dir_name)
 	return result;
 }
 
+/**
+ * Create directories specified by path (including all parents).
+ */
+isc_result_t
+fs_dirs_create(const char *path) {
+	isc_result_t result = ISC_R_SUCCESS;
+	char curr_path[PATH_MAX + 1];
+	char *end = NULL;
+
+	CHECK(isc_string_copy(curr_path, PATH_MAX, path));
+
+	for (end = strchr(curr_path, '/');
+	     end != NULL;
+	     end = strchr(end + 1, '/')) {
+		*end = '\0';
+		if (strcmp(curr_path, "") != 0)
+			/* Absolute paths would have first component empty. */
+			CHECK(fs_dir_create(curr_path));
+		*end = '/';
+	}
+
+
+cleanup:
+	return result;
+}
+
 isc_result_t
 fs_file_remove(const char *file_name) {
 	isc_result_t result;
diff --git a/src/fs.h b/src/fs.h
index b583d3be57b7e1582b61b2bf3554c5d5be805e18..341222dac1ce08e4d37bd10edb9a3838632a8c58 100644
--- a/src/fs.h
+++ b/src/fs.h
@@ -24,7 +24,7 @@
 #include "util.h"
 
 isc_result_t ATTR_NONNULLS
-fs_dir_create(const char *dir_name);
+fs_dirs_create(const char *path);
 
 isc_result_t ATTR_NONNULLS
 fs_file_remove(const char *file_name);
diff --git a/src/ldap_helper.c b/src/ldap_helper.c
index 8e8bf4bdb4072e414f5212c6b5df429203e582de..b0dd3391f4dca88992ac7869b34d943a381d51be 100644
--- a/src/ldap_helper.c
+++ b/src/ldap_helper.c
@@ -372,9 +372,10 @@ validate_local_instance_settings(ldap_instance_t *inst, settings_set_t *set) {
 	CHECK(str_new(inst->mctx, &buff));
 	CHECK(setting_get_str("directory", inst->local_settings, &dir_name));
 	dir_default = (strcmp(dir_name, "") == 0);
-	if (dir_default == ISC_TRUE)
+	if (dir_default == ISC_TRUE) {
+		CHECK(str_cat_char(buff, "dyndb-ldap/"));
 		CHECK(str_cat_char(buff, inst->db_name));
-	else
+	} else
 		CHECK(str_cat_char(buff, dir_name));
 
 	if (str_buf(buff)[str_len(buff) - 1] != '/')
@@ -388,7 +389,7 @@ validate_local_instance_settings(ldap_instance_t *inst, settings_set_t *set) {
 	CHECK(setting_get_str("directory", inst->local_settings, &dir_name));
 
 	/* Make sure that working directory exists */
-	CHECK(fs_dir_create(dir_name));
+	CHECK(fs_dirs_create(dir_name));
 
 	/* Set timer for deadlock detection inside semaphore_wait_timed . */
 	CHECK(setting_get_uint("timeout", set, &uint));
diff --git a/src/zone_register.c b/src/zone_register.c
index 6a5bade031660b7fc567a36a074aff1c5fda2689..d58159c3104f2624bfaa05de4515db5b2598d51f 100644
--- a/src/zone_register.c
+++ b/src/zone_register.c
@@ -260,7 +260,7 @@ create_zone_info(isc_mem_t *mctx, dns_zone_t *zone, const char *dn,
 	/* Prepate a directory for this zone */
 	CHECK(zr_get_zone_path(mctx, global_settings, dns_zone_getorigin(zone),
 			       NULL, &zone_dir));
-	CHECK(fs_dir_create(str_buf(zone_dir)));
+	CHECK(fs_dirs_create(str_buf(zone_dir)));
 
 	DE_CONST(db_name, argv[0]);
 	CHECK(ldapdb_create(mctx, dns_zone_getorigin(zone), LDAP_DB_TYPE,
-- 
1.8.5.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to