285127
From 562a8089369f78cd9a07b41c44a149abf72b02a8 Mon Sep 17 00:00:00 2001
285127
From: Bertrand Jacquin <bertrand@jacquin.bzh>
285127
Date: Mon, 19 Sep 2016 02:25:33 +0100
285127
Subject: [PATCH 1/2] config.c: drop comparison of uid/gid with undetermined
285127
 values
285127
285127
... loaded from uninitialized stat buffer on the stack of do_mkdir()
285127
285127
If a directory is created (ie createolddir), struct sb must be updated
285127
in order to get appropriate st_uid and st_gid. Test made later to known
285127
if chown() should be performed is inadequate since sb is never updated.
285127
285127
As per discussion in https://github.com/logrotate/logrotate/pull/59,
285127
removing the comparison to unsure newly created directory always get
285127
owner and group changed.
285127
285127
Before:
285127
  ./logrotate  -f /etc/logrotate.conf
285127
  uid: 250, sb.st_uid: 250
285127
  gid: 250, sb.st_gid: 250
285127
285127
After:
285127
  ./logrotate  -f /etc/logrotate.conf
285127
  uid: 250, sb.st_uid: 0
285127
  gid: 250, sb.st_gid: 250
285127
285127
Closes #59
285127
285127
Upstream-commit: ae040a55d3a8f2bbce7860415b4ee479a024a334
285127
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
285127
---
285127
 config.c | 3 +--
285127
 1 file changed, 1 insertion(+), 2 deletions(-)
285127
285127
diff --git a/config.c b/config.c
285127
index 493f3f7..e692ac9 100644
285127
--- a/config.c
285127
+++ b/config.c
285127
@@ -313,8 +313,7 @@ static int do_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
285127
 				path, strerror(errno));
285127
 			return -1;
285127
 		}
285127
-		if ((uid != sb.st_uid || gid != sb.st_gid) && 
285127
-			chown(path, uid, gid)) {
285127
+		if (chown(path, uid, gid) != 0) {
285127
 			message(MESS_ERROR, "error setting owner of %s to uid %d and gid %d: %s\n",
285127
 				path, uid, gid, strerror(errno));
285127
 			return -1;
285127
-- 
285127
2.7.4
285127
285127
285127
From d6962e20c9043152b63df6c1ca1de14161caa725 Mon Sep 17 00:00:00 2001
285127
From: Kamil Dudka <kdudka@redhat.com>
285127
Date: Tue, 20 Sep 2016 18:56:24 +0200
285127
Subject: [PATCH 2/2] config.c: make 'createolddir' preserve sticky bit
285127
285127
After calling chown() to set uid/gid on the created directory, re-apply
285127
permission bits once again by chmod() because the sticky bit might have
285127
been cleared by chown().
285127
285127
Upstream-commit: 3c76f48efa0d9d448528af3e40f757654458978c
285127
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
285127
---
285127
 config.c | 7 ++++++-
285127
 1 file changed, 6 insertions(+), 1 deletion(-)
285127
285127
diff --git a/config.c b/config.c
285127
index e692ac9..64bb935 100644
285127
--- a/config.c
285127
+++ b/config.c
285127
@@ -318,7 +318,12 @@ static int do_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) {
285127
 				path, uid, gid, strerror(errno));
285127
 			return -1;
285127
 		}
285127
-    }
285127
+		if (chmod(path, mode) != 0) {
285127
+			message(MESS_ERROR, "error setting permissions of %s to 0%o: %s\n",
285127
+				path, mode, strerror(errno));
285127
+			return -1;
285127
+		}
285127
+	}
285127
 	else if (!S_ISDIR(sb.st_mode)) {
285127
 		message(MESS_ERROR, "path %s already exists, but it is not a directory\n",
285127
 			path);
285127
-- 
285127
2.7.4
285127