reply(553, "Bad filename; includes invalid character.");
return;
}
- mode_t omask = umask(007);
+ mode_t omask = umask(027);
FILE* fout = fopen(name, restart_point ? "r+w" : mode);
if (fout != NULL) {
setFileOwner(name);
FILE* fout = fopen(filename, "w");
if (fout != NULL) {
setFileOwner(filename);
- FileCache::chmod(filename, 0660); // sync cache
+ FileCache::chmod(filename, 0640); // sync cache
if (isTemp)
tempFiles.append(filename);
time_t start_time = Sys::now();
u_int
HylaFAXServer::getSequenceNumber(const char* filename, u_int count, fxStr& emsg)
{
- int fd = Sys::open(filename, O_CREAT|O_RDWR, 0644);
+ int fd = Sys::open(filename, O_CREAT|O_RDWR|O_EXCL, 0600);
if (fd < 0) {
- emsg = fxStr::format("Unable to open sequence number file %s; %s.",
- filename, strerror(errno));
- logError("%s: open: %s", filename, strerror(errno));
- return ((u_int) -1);
+ emsg = fxStr::format("Unable to open sequence number file %s; %s.",
+ filename, strerror(errno));
+ logError("%s: open: %s", filename, strerror(errno));
+ return ((u_int) -1);
}
flock(fd, LOCK_EX);
u_int seqnum = 1;
char line[1024];
int n = read(fd, line, sizeof (line));
line[n < 0 ? 0 : n] = '\0';
- if (n > 0)
- seqnum = atoi(line);
+ if (n > 0) {
+ seqnum = atoi(line);
+ }
if (seqnum < 1 || seqnum >= MAXSEQNUM) {
- logWarning("%s: Invalid sequence number \"%s\", resetting to 1",
- filename, line);
- seqnum = 1;
+ logWarning("%s: Invalid sequence number \"%s\", resetting to 1",
+ filename, line);
+ seqnum = 1;
}
sprintf(line, "%u", NEXTSEQNUM(seqnum+count));
lseek(fd, 0, SEEK_SET);
Sys::close(fd); // NB: implicit unlock
return (seqnum);
}
+
u_int HylaFAXServer::getJobNumber(fxStr& emsg)
{ return (getSequenceNumber(FAX_SENDDIR "/" FAX_SEQF, 1, emsg)); }
u_int HylaFAXServer::getDocumentNumbers(u_int count, fxStr& emsg)
{ return ::gethostname(name, namelen); }
static char* mktemp(char* templ) { return ::mktemp(templ); }
- static int mkstemp(char* templ) { return ::mkstemp(templ); }
+
+ static int mkstemp(char* templ) {
+ int fd = mkstemp(templ);
+#if defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ <= 0
+ // Hack for older versions of glibc which do not set the file
+ // permissions correctly
+ if (fchmod(fd, S_IRUSR | S_IWUSR) == -1) return -1;
+#endif
+ return fd;
+ }
+
static FILE* tmpfile() { return ::tmpfile(); }
static FILE* fopen(const char* filename, const char* mode)
{ return ::fopen(filename, mode); }