[dovecot-cvs] dovecot/src/lib safe-mkdir.c,1.5,1.6

cras at dovecot.org cras at dovecot.org
Fri Jun 30 17:49:06 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv7265

Modified Files:
	safe-mkdir.c 
Log Message:
safe_mkdir() should return 1 always when it creates a new directory, even if  
it changes the group/permissions when doing it. 



Index: safe-mkdir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/safe-mkdir.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- safe-mkdir.c	26 Aug 2003 22:15:36 -0000	1.5
+++ safe-mkdir.c	30 Jun 2006 14:49:03 -0000	1.6
@@ -10,17 +10,19 @@
 int safe_mkdir(const char *dir, mode_t mode, uid_t uid, gid_t gid)
 {
 	struct stat st;
-	int fd, ret = 1;
+	int fd, ret = 2, changed_ret = 0;
 
 	if (lstat(dir, &st) < 0) {
 		if (errno != ENOENT)
 			i_fatal("lstat() failed for %s: %m", dir);
 
-		if (mkdir(dir, mode) < 0)
-			i_fatal("Can't create directory %s: %m", dir);
-	} else {
-		/* already exists. */
-		ret = 2;
+		if (mkdir(dir, mode) < 0) {
+			if (errno != EEXIST)
+				i_fatal("Can't create directory %s: %m", dir);
+		} else {
+			/* created it */
+			ret = changed_ret = 1;
+		}
 	}
 
 	/* use fchown() and fchmod() just to make sure we aren't following
@@ -40,13 +42,13 @@
 	if (st.st_uid != uid || st.st_gid != gid) {
 		if (fchown(fd, uid, gid) < 0)
 			i_fatal("fchown() failed for %s: %m", dir);
-		ret = 0;
+		ret = changed_ret;
 	}
 
 	if ((st.st_mode & 07777) != mode) {
 		if (fchmod(fd, mode) < 0)
 			i_fatal("chmod() failed for %s: %m", dir);
-		ret = 0;
+		ret = changed_ret;
 	}
 
 	if (close(fd) < 0)



More information about the dovecot-cvs mailing list