]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
safe_mkdir(): uid/gid can now be -1 to mean "don't change it".
authorTimo Sirainen <tss@iki.fi>
Tue, 16 Mar 2010 12:29:25 +0000 (14:29 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 16 Mar 2010 12:29:25 +0000 (14:29 +0200)
--HG--
branch : HEAD

src/lib/safe-mkdir.c

index 3fadebef2698eb05b27bda88286dca852b75b3e2..7f8185be53fc94e631e16e9846c5b7c8080279d3 100644 (file)
@@ -39,7 +39,8 @@ int safe_mkdir(const char *dir, mode_t mode, uid_t uid, gid_t gid)
 
        /* change the file owner first, since it's the only user one who
           can mess up with the file mode. */
-       if (st.st_uid != uid || st.st_gid != gid) {
+       if ((st.st_uid != uid && uid != (uid_t)-1) ||
+           (st.st_gid != gid && gid != (gid_t)-1)) {
                if (fchown(fd, uid, gid) < 0)
                        i_fatal("fchown() failed for %s: %m", dir);
                ret = changed_ret;
@@ -65,7 +66,8 @@ int safe_mkdir(const char *dir, mode_t mode, uid_t uid, gid_t gid)
                i_fatal("safe_mkdir() failed: %s (%o) is still not mode %o",
                        dir, (int)st.st_mode, (int)mode);
        }
-       if (st.st_uid != uid || st.st_gid != gid) {
+       if ((st.st_uid != uid && uid != (uid_t)-1) ||
+           (st.st_gid != gid && gid != (gid_t)-1)) {
                i_fatal("safe_mkdir() failed: %s (%s, %s) "
                        "is still not owned by %s.%s",
                        dir, dec2str(st.st_uid), dec2str(st.st_gid),