- */
- if (use_default_mailbox){
- /* get our preciousss out of pocket */
- gid_t ruid, euid, suid;
- getresgid(&ruid, &euid, &suid);
- setresgid(ruid, suid, suid);
-
- /* we are not going to create default mailbox */
- fd = open(path, O_RDWR);
- if (fd < 0){
- dot_unlock(path);
- return -1;
- }
-
- /* hide it again */
- setresgid(ruid, ruid, suid);
- } else {
- fd = open(path, O_RDWR);
- if (fd < 0 && errno == ENOENT){
- fd = open(path, O_RDWR | O_CREAT | O_EXCL,
- S_IRUSR | S_IWUSR);
- if (fd < 0){
- dot_unlock(path);
- return -1;
- }
-
- } else if (fd < 0){
- dot_unlock(path);
- return -1;
- }
+ */
+ int perms = S_IRUSR | S_IWUSR;
+ if (is_default_mailbox)
+ perms |= (S_IRGRP | S_IWGRP);
+
+ mode_t oldmask = umask(0);
+ fd = open(path, O_RDWR | O_CREAT, perms);
+ umask(oldmask);
+ if (fd < 0){
+ dot_unlock(path);
+ return -1;