From: Timo Sirainen Date: Tue, 26 Aug 2003 22:15:36 +0000 (+0300) Subject: comment updates. it's not possible to change the file mode if you're not the X-Git-Tag: 1.1.alpha1~4364 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcb2135a601e0c16ed5922f04d314b2e6cc563ca;p=thirdparty%2Fdovecot%2Fcore.git comment updates. it's not possible to change the file mode if you're not the owner.. --HG-- branch : HEAD --- diff --git a/src/lib/safe-mkdir.c b/src/lib/safe-mkdir.c index 0cb8802e27..a582d2ea16 100644 --- a/src/lib/safe-mkdir.c +++ b/src/lib/safe-mkdir.c @@ -35,6 +35,8 @@ int safe_mkdir(const char *dir, mode_t mode, uid_t uid, gid_t gid) if (!S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)) i_fatal("Not a directory %s", dir); + /* 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 (fchown(fd, uid, gid) < 0) i_fatal("fchown() failed for %s: %m", dir); @@ -50,9 +52,7 @@ int safe_mkdir(const char *dir, mode_t mode, uid_t uid, gid_t gid) if (close(fd) < 0) i_fatal("close() failed for %s: %m", dir); - /* make sure we succeeded in everything. chown() and chmod() - are racy: user owned 0777 file - change either and the user - can still change it back. */ + /* paranoia: make sure we succeeded in everything. */ if (lstat(dir, &st) < 0) i_fatal("lstat() check failed for %s: %m", dir);