* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) University of Cambridge 1995 - 2017 */
+/* Copyright (c) University of Cambridge 1995 - 2018 */
/* See the file NOTICE for conditions of use and distribution. */
(appendfile_transport_options_block *)(tblock->options_block);
uschar *q = ob->quota;
double default_value = 0.0;
-int i;
addrlist = addrlist; /* Keep picky compilers happy */
dummy = dummy;
/* Loop for quota, quota_filecount, quota_warn_threshold, mailbox_size,
mailbox_filecount */
-for (i = 0; i < 5; i++)
+for (int i = 0; i < 5; i++)
{
double d;
int no_check = 0;
{
*errmsg = string_sprintf("Expansion of \"%s\" in %s transport failed: "
"%s", q, tblock->name, expand_string_message);
- return search_find_defer ? DEFER : FAIL;
+ return f.search_find_defer ? DEFER : FAIL;
}
d = Ustrtod(s, &rest);
{
struct servent *sp;
host_item host;
-host_item *h;
-uschar buffer[256];
+uschar * s;
DEBUG(D_transport) debug_printf("notify_comsat called\n");
-sprintf(CS buffer, "%.200s@" OFF_T_FMT "\n", user, offset);
+s = string_sprintf("%.200s@" OFF_T_FMT "\n", user, offset);
if ((sp = getservbyname("biff", "udp")) == NULL)
{
host.address = US"127.0.0.1";
-for (h = &host; h; h = h->next)
+for (host_item * h = &host; h; h = h->next)
{
int sock, rc;
int host_af = Ustrchr(h->address, ':') != NULL ? AF_INET6 : AF_INET;
/* Connect never fails for a UDP socket, so don't set a timeout. */
(void)ip_connect(sock, host_af, h->address, ntohs(sp->s_port), 0, NULL);
- rc = send(sock, buffer, Ustrlen(buffer) + 1, 0);
+ rc = send(sock, s, Ustrlen(s) + 1, 0);
(void)close(sock);
if (rc >= 0) break;
if (match && tp)
{
- transport_instance *tt;
- for (tt = transports; tt; tt = tt->next)
+ for (transport_instance * tt = transports; tt; tt = tt->next)
if (Ustrcmp(tp, tt->name) == 0)
{
DEBUG(D_transport)
*/
off_t
-check_dir_size(uschar *dirname, int *countptr, const pcre *regex)
+check_dir_size(const uschar * dirname, int *countptr, const pcre *regex)
{
DIR *dir;
off_t sum = 0;
struct dirent *ent;
struct stat statbuf;
-dir = opendir(CS dirname);
-if (dir == NULL) return 0;
+if (!(dir = opendir(CS dirname))) return 0;
-while ((ent = readdir(dir)) != NULL)
+while ((ent = readdir(dir)))
{
- uschar *name = US ent->d_name;
- uschar buffer[1024];
+ uschar * path, * name = US ent->d_name;
if (Ustrcmp(name, ".") == 0 || Ustrcmp(name, "..") == 0) continue;
/* If there's a regex, try to find the size using it */
- if (regex != NULL)
+ if (regex)
{
int ovector[6];
if (pcre_exec(regex, NULL, CS name, Ustrlen(name), 0, 0, ovector,6) >= 2)
/* No regex or no match for the regex, or captured non-digits */
- if (!string_format(buffer, sizeof(buffer), "%s/%s", dirname, name))
- {
- DEBUG(D_transport)
- debug_printf("check_dir_size: name too long: dir=%s name=%s\n", dirname,
- name);
- continue;
- }
+ path = string_sprintf("%s/%s", dirname, name);
- if (Ustat(buffer, &statbuf) < 0)
+ if (Ustat(path, &statbuf) < 0)
{
DEBUG(D_transport)
- debug_printf("check_dir_size: stat error %d for %s: %s\n", errno, buffer,
+ debug_printf("check_dir_size: stat error %d for %s: %s\n", errno, path,
strerror(errno));
- continue;
}
-
- if ((statbuf.st_mode & S_IFMT) == S_IFREG)
- sum += statbuf.st_size;
- else if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
- sum += check_dir_size(buffer, &count, regex);
+ else
+ if ((statbuf.st_mode & S_IFMT) == S_IFREG)
+ sum += statbuf.st_size / statbuf.st_nlink;
+ else if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
+ sum += check_dir_size(path, &count, regex);
}
closedir(dir);
{
if (fcntltime > 0)
{
- alarm(fcntltime);
+ ALARM(fcntltime);
yield = fcntl(fd, F_SETLKW, &lock_data);
save_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
errno = save_errno;
}
else yield = fcntl(fd, F_SETLK, &lock_data);
int flocktype = (fcntltype == F_WRLCK) ? LOCK_EX : LOCK_SH;
if (flocktime > 0)
{
- alarm(flocktime);
+ ALARM(flocktime);
yield = flock(fd, flocktype);
save_errno = errno;
- alarm(0);
+ ALARM_CLR(0);
errno = save_errno;
}
else yield = flock(fd, flocktype | LOCK_NB);
int used;
off_t size;
struct stat statbuf;
-transport_ctx tctx = {{0}};
-
-tctx.u.fd = to_fd;
+transport_ctx tctx = { .u={.fd = to_fd}, .options = topt_not_socket };
/* If the current mailbox size is zero, write a header block */
if (saved_size == 0)
{
- int i;
uschar *s;
memset (deliver_out_buffer, '\0', MBX_HDRSIZE);
sprintf(CS(s = deliver_out_buffer), "*mbx*\015\012%08lx00000000\015\012",
(long int)time(NULL));
- for (i = 0; i < MBX_NUSERFLAGS; i++)
+ for (int i = 0; i < MBX_NUSERFLAGS; i++)
sprintf (CS(s += Ustrlen(s)), "\015\012");
if (!transport_write_block (&tctx, deliver_out_buffer, MBX_HDRSIZE, FALSE))
return DEFER;
#ifndef NO_REALPATH
if (yield && create_file == create_belowhome)
{
- uschar *slash, *next;
+ uschar *next;
uschar *rp = NULL;
- for (slash = Ustrrchr(file, '/'); /* There is known to be one */
- rp == NULL && slash > file; /* Stop if reached beginning */
+ for (uschar * slash = Ustrrchr(file, '/'); /* There is known to be one */
+ rp == NULL && slash > file; /* Stop if reached beginning */
slash = next)
{
*slash = 0;
to the true local part. */
if (testflag(addr, af_file))
- {
- address_item *addr2;
- for (addr2 = addr; addr2 != NULL; addr2 = addr2->next)
+ for (address_item * addr2 = addr; addr2 != NULL; addr2 = addr2->next)
addr2->local_part = string_copy(path);
- }
/* The available mailbox formats depend on whether it is a directory or a file
delivery. */
/* If the -N option is set, can't do any more. */
-if (dont_deliver)
+if (f.dont_deliver)
{
DEBUG(D_transport)
debug_printf("*** delivery by %s transport bypassed by -N option\n",
/* We have successfully created and opened the file. Ensure that the group
and the mode are correct. */
- if(Uchown(filename, uid, gid) || Uchmod(filename, mode))
+ if(exim_chown(filename, uid, gid) || Uchmod(filename, mode))
{
addr->basic_errno = errno;
addr->message = string_sprintf("while setting perms on mailbox %s",
$message_size is accurately known. */
if (nametag != NULL && expand_string(nametag) == NULL &&
- !expand_string_forcedfail)
+ !f.expand_string_forcedfail)
{
addr->transport_return = PANIC;
addr->message = string_sprintf("Expansion of \"%s\" (maildir_tag "
checked at the end, to make sure we don't release this process until the
clock has ticked. */
- for (i = 1;; i++)
+ for (int i = 1;; i++)
{
uschar *basename;
/* Why are these here? Put in because they are present in the non-maildir
directory case above. */
- if(Uchown(filename, uid, gid) || Uchmod(filename, mode))
+ if(exim_chown(filename, uid, gid) || Uchmod(filename, mode))
{
addr->basic_errno = errno;
addr->message = string_sprintf("while setting perms on maildir %s",
else
{
FILE *env_file;
- address_item *taddr;
mailstore_basename = string_sprintf("%s/%s-%s", path, message_id,
string_base62((long int)getpid()));
/* Why are these here? Put in because they are present in the non-maildir
directory case above. */
- if(Uchown(filename, uid, gid) || Uchmod(filename, mode))
+ if(exim_chown(filename, uid, gid) || Uchmod(filename, mode))
{
addr->basic_errno = errno;
addr->message = string_sprintf("while setting perms on file %s",
uschar *s = expand_string(ob->mailstore_prefix);
if (s == NULL)
{
- if (!expand_string_forcedfail)
+ if (!f.expand_string_forcedfail)
{
addr->transport_return = PANIC;
addr->message = string_sprintf("Expansion of \"%s\" (mailstore "
fprintf(env_file, "%s\n", sender_address);
- for (taddr = addr; taddr!= NULL; taddr = taddr->next)
+ for (address_item * taddr = addr; taddr; taddr = taddr->next)
fprintf(env_file, "%s@%s\n", taddr->local_part, taddr->domain);
if (ob->mailstore_suffix != NULL)
uschar *s = expand_string(ob->mailstore_suffix);
if (s == NULL)
{
- if (!expand_string_forcedfail)
+ if (!f.expand_string_forcedfail)
{
addr->transport_return = PANIC;
addr->message = string_sprintf("Expansion of \"%s\" (mailstore "
Uunlink(filename);
return FALSE;
}
- if(Uchown(dataname, uid, gid) || Uchmod(dataname, mode))
+ if(exim_chown(dataname, uid, gid) || Uchmod(dataname, mode))
{
addr->basic_errno = errno;
addr->message = string_sprintf("while setting perms on file %s",
/* In all cases of writing to a new file, ensure that the file which is
going to be renamed has the correct ownership and mode. */
- if(Uchown(filename, uid, gid) || Uchmod(filename, mode))
+ if(exim_chown(filename, uid, gid) || Uchmod(filename, mode))
{
addr->basic_errno = errno;
addr->message = string_sprintf("while setting perms on file %s",
yield = DEFER;
else
{
- address_item *a;
transport_newlines++;
- for (a = addr; a != NULL; a = a->next)
+ for (address_item * a = addr; a != NULL; a = a->next)
{
address_item *b = testflag(a, af_pfr) ? a->parent: a;
if (!transport_write_string(fd, "RCPT TO:<%s>%s\n",
if (yield == OK)
{
transport_ctx tctx = {
- {fd},
- tblock,
- addr,
- ob->check_string,
- ob->escape_string,
- ob->options
+ .u = {.fd=fd},
+ .tblock = tblock,
+ .addr = addr,
+ .check_string = ob->check_string,
+ .escape_string = ob->escape_string,
+ .options = ob->options | topt_not_socket
};
if (!transport_write_message(&tctx, 0))
yield = DEFER;
}
else /* Want a repeatable time when in test harness */
{
- addr->more_errno = running_in_test_harness ? 10 :
+ addr->more_errno = f.running_in_test_harness ? 10 :
(int)time(NULL) - statbuf.st_mtime;
}
DEBUG(D_transport)
addr->message = string_sprintf("mailbox is full "
"(quota exceeded while writing to file %s)", filename);
#else
- addr->message = string_sprintf("mailbox is full");
+ addr->message = US"mailbox is full";
#endif /* EDQUOT */
addr->user_message = US"mailbox is full";
DEBUG(D_transport) debug_printf("System quota exceeded for %s%s%s\n",
if (newname == NULL)
{
- int i;
uschar *renameleaf;
uschar *old_renameleaf = US"";
- for (i = 0; ; sleep(1), i++)
+ for (int i = 0; ; sleep(1), i++)
{
deliver_inode = statbuf.st_ino;
renameleaf = expand_string(ob->dirfilename);
uschar *iptr = expand_string(nametag);
if (iptr != NULL)
{
- uschar *etag = store_get(Ustrlen(iptr) + 2);
+ uschar *etag = store_get(Ustrlen(iptr) + 2, is_tainted(iptr));
uschar *optr = etag;
while (*iptr != 0)
{