- snprintf(tempfile, MAXPATHLEN, "%s.XXXXX", prefsPath);
- mktemp(tempfile);
- changeIdentity(UNPRIV);
- if((fd2 = open(tempfile, O_RDWR | O_CREAT | O_EXCL, 0666)) < 0) {
- retval = -1;
+ changeIdentity(UNPRIV);
+
+ snprintf(tempfile, MAXPATHLEN, "%s.XXXXXX", prefsPath);
+ int fd2 = mkstemp(tempfile);
+ if (fd2 < 0 || ::fchmod(fd2, 0644) != 0) {
+ ::unlink(tempfile);
+ retval = -1;