-
- if (!IsEmptyStr(argbuf))
- {
- if (CtdlAccessCheck(ac_aide)) return;
- if (strcmp(argbuf, FILE_MAILALIAS))
- {
- cprintf("%d No such file or directory\n",
- ERROR + INTERNAL_ERROR);
- return;
- }
- len = safestrncpy(filename, file_mail_aliases, sizeof(filename));
- memset(MailAliasesFound, 0, sizeof(MailAliasesFound));
- memcpy(tempfilename, filename, len + 1);
- IsMailAlias = 1;
- }
- else
- {
- if ( (CCC->room.QRflags & QR_MAILBOX) && (CCC->user.usernum == atol(CCC->room.QRname)) ) {
- /* users can edit the netconfigs for their own mailbox rooms */
- }
- else if (CtdlAccessCheck(ac_room_aide)) return;
-
- len = assoc_file_name(filename, sizeof filename, &CCC->room, ctdl_netcfg_dir);
- memcpy(tempfilename, filename, len + 1);
- }
- memset(&StatBuf, 0, sizeof(struct stat));
- if ((stat(filename, &StatBuf) == -1) || (StatBuf.st_size == 0))
- StatBuf.st_size = 80; /* Not there or empty? guess 80 chars line. */
-
- sprintf(tempfilename + len, ".%d", CCC->cs_pid);
- errno = 0;
- TmpFD = open(tempfilename, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
-
- if ((TmpFD > 0) && (errno == 0))
- {
- char *tmp = malloc(StatBuf.st_size * 2);
- memset(tmp, ' ', StatBuf.st_size * 2);
- rc = write(TmpFD, tmp, StatBuf.st_size * 2);
- free(tmp);
- if ((rc <= 0) || (rc != StatBuf.st_size * 2))
- {
- close(TmpFD);
- cprintf("%d Unable to allocate the space required for %s: %s\n",
- ERROR + INTERNAL_ERROR,
- tempfilename,
- strerror(errno));
- unlink(tempfilename);
- return;
- }
- lseek(TmpFD, SEEK_SET, 0);
- }
- else {
- cprintf("%d Unable to allocate the space required for %s: %s\n",
- ERROR + INTERNAL_ERROR,
- tempfilename,
- strerror(errno));
- unlink(tempfilename);
- return;
- }