[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for sqlcreatehomedir.c mkdir permissions bug



If you're using sqlcreatehomedir and your directory structure is more than one
dir deep, sqlcreatehomedir will create all nonexisting dirs along the path. For
example, if mail arrives for a user whose inbox is
/home/domain.tld/user/Maildir, and /home/domain.tld does not exist,
sqlcreatehomedir will do:

mkdir /home/domain.tld
mkdir /home/domain.tld/user
mkdir /home/domain.tld/user/Maildir

However, it only applies the proper chmod and chown to the very last dir. As a
result, qmail-local will not be able to deliver the mail because the inbox's
parent directory will be owned by root with 0700 permissions. This patch fixes
that behavior, so that all directories have the correct ownership and
permissions.

--- sqlcreatehomedir.c.orig     2004-07-02 18:26:46.000000000 -0500
+++ sqlcreatehomedir.c  2004-07-02 18:26:59.000000000 -0500
@@ -36,6 +36,9 @@
          if (stat(p,&statinfo) != 0) {
             if (errno == ENOENT) {
              mkdir(p,00700);
+          chown(p,pw->pw_uid,pw->pw_gid);
+          setregid(pw->pw_gid,pw->pw_gid);
+          setreuid(pw->pw_uid,pw->pw_uid);
            }
          }
          if (chdir(p)) {

The standard "it works for me" disclaimer applies... :)

-- 
Alex Howansky
Wankwood Associates
http://www.wankwood.com/