int ovector[3*(EXPAND_MAXN+1)];
uschar * s = string_copy(subject); /* de-constifying */
int n = pcre_exec(re, NULL, CS s, Ustrlen(s), 0,
- PCRE_EOPT | options, ovector, sizeof(ovector)/sizeof(int));
+ PCRE_EOPT | options, ovector, nelem(ovector));
BOOL yield = n >= 0;
if (n == 0) n = EXPAND_MAXN + 1;
if (yield)
{
- int nn;
- expand_nmax = (setup < 0)? 0 : setup + 1;
- for (nn = (setup < 0)? 0 : 2; nn < n*2; nn += 2)
+ expand_nmax = setup < 0 ? 0 : setup + 1;
+ for (int nn = setup < 0 ? 0 : 2; nn < n*2; nn += 2)
{
expand_nstring[expand_nmax] = s + ovector[nn];
expand_nlength[expand_nmax++] = ovector[nn+1] - ovector[nn];
void
set_process_info(const char *format, ...)
{
-int len = sprintf(CS process_info, "%5d ", (int)getpid());
+gstring gs = { .size = PROCESS_INFO_SIZE - 2, .ptr = 0, .s = process_info };
+gstring * g;
+int len;
va_list ap;
+
+g = string_fmt_append(&gs, "%5d ", (int)getpid());
+len = g->ptr;
va_start(ap, format);
-if (!string_vformat(process_info + len, PROCESS_INFO_SIZE - len - 2, format, ap))
- Ustrcpy(process_info + len, "**** string overflowed buffer ****");
-len = Ustrlen(process_info);
-process_info[len+0] = '\n';
-process_info[len+1] = '\0';
-process_info_len = len + 1;
+if (!string_vformat(g, FALSE, format, ap))
+ {
+ gs.ptr = len;
+ g = string_cat(&gs, US"**** string overflowed buffer ****");
+ }
+g = string_catn(g, US"\n", 1);
+string_from_gstring(g);
+process_info_len = g->ptr;
DEBUG(D_process_info) debug_printf("set_process_info: %s", process_info);
va_end(ap);
}
void
exim_nullstd(void)
{
-int i;
int devnull = -1;
struct stat statbuf;
-for (i = 0; i <= 2; i++)
+for (int i = 0; i <= 2; i++)
{
if (fstat(i, &statbuf) < 0 && errno == EBADF)
{
if (igflag)
{
struct passwd *pw = getpwuid(uid);
- if (pw != NULL)
- {
- if (initgroups(pw->pw_name, gid) != 0)
- log_write(0,LOG_MAIN|LOG_PANIC_DIE,"initgroups failed for uid=%ld: %s",
- (long int)uid, strerror(errno));
- }
- else log_write(0, LOG_MAIN|LOG_PANIC_DIE, "cannot run initgroups(): "
- "no passwd entry for uid=%ld", (long int)uid);
+ if (!pw)
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE, "cannot run initgroups(): "
+ "no passwd entry for uid=%ld", (long int)uid);
+
+ if (initgroups(pw->pw_name, gid) != 0)
+ log_write(0,LOG_MAIN|LOG_PANIC_DIE,"initgroups failed for uid=%ld: %s",
+ (long int)uid, strerror(errno));
}
if (setgid(gid) < 0 || setuid(uid) < 0)
- {
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "unable to set gid=%ld or uid=%ld "
"(euid=%ld): %s", (long int)gid, (long int)uid, (long int)euid, msg);
- }
}
/* Debugging output included uid/gid and all groups */
DEBUG(D_uid)
{
int group_count, save_errno;
- gid_t group_list[NGROUPS_MAX];
+ gid_t group_list[EXIM_GROUPLIST_SIZE];
debug_printf("changed uid/gid: %s\n uid=%ld gid=%ld pid=%ld\n", msg,
(long int)geteuid(), (long int)getegid(), (long int)getpid());
- group_count = getgroups(NGROUPS_MAX, group_list);
+ group_count = getgroups(nelem(group_list), group_list);
save_errno = errno;
debug_printf(" auxiliary group list:");
if (group_count > 0)
- {
- int i;
- for (i = 0; i < group_count; i++) debug_printf(" %d", (int)group_list[i]);
- }
+ for (int i = 0; i < group_count; i++) debug_printf(" %d", (int)group_list[i]);
else if (group_count < 0)
debug_printf(" <error: %s>", strerror(save_errno));
else debug_printf(" <none>");
+/* Print error string, then die */
+static void
+exim_fail(const char * fmt, ...)
+{
+va_list ap;
+va_start(ap, fmt);
+vfprintf(stderr, fmt, ap);
+exit(EXIT_FAILURE);
+}
+
+
/*************************************************
* Extract port from host address *
{
int port = host_address_extract_port(address);
if (string_is_ip_address(address, NULL) == 0)
- {
- fprintf(stderr, "exim abandoned: \"%s\" is not an IP address\n", address);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim abandoned: \"%s\" is not an IP address\n", address);
return port;
}
static void
show_whats_supported(FILE * fp)
{
-auth_info * authi;
-
DEBUG(D_any) {} else show_db_version(fp);
fprintf(fp, "Support for:");
#ifdef EXPERIMENTAL_REQUIRETLS
fprintf(fp, " Experimental_REQUIRETLS");
#endif
+#ifdef EXPERIMENTAL_PIPE_CONNECT
+ fprintf(fp, " Experimental_PIPE_CONNECT");
+#endif
fprintf(fp, "\n");
fprintf(fp, "Lookups (built-in):");
#if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
fprintf(fp, " ibase");
#endif
+#if defined(LOOKUP_JSON) && LOOKUP_JSON!=2
+ fprintf(fp, " json");
+#endif
#if defined(LOOKUP_LDAP) && LOOKUP_LDAP!=2
fprintf(fp, " ldap ldapdn ldapm");
#endif
Perhaps the tls_version_report should move into this too. */
DEBUG(D_any) do {
- int i;
-
/* clang defines __GNUC__ (at least, for me) so test for it first */
#if defined(__clang__)
fprintf(fp, "Compiler: CLang [%s]\n", __clang_version__);
utf8_version_report(fp);
#endif
- for (authi = auths_available; *authi->driver_name != '\0'; ++authi)
+ for (auth_info * authi = auths_available; *authi->driver_name != '\0'; ++authi)
if (authi->version_report)
(*authi->version_report)(fp);
#undef EXPAND_AND_QUOTE
init_lookup_list();
- for (i = 0; i < lookup_list_count; i++)
+ for (int i = 0; i < lookup_list_count; i++)
if (lookup_list[i]->version_report)
lookup_list[i]->version_report(fp);
static void
show_exim_information(enum commandline_info request, FILE *stream)
{
-const uschar **pp;
-
switch(request)
{
case CMDINFO_NONE:
);
return;
case CMDINFO_SIEVE:
- for (pp = exim_sieve_extension_list; *pp; ++pp)
+ for (const uschar ** pp = exim_sieve_extension_list; *pp; ++pp)
fprintf(stream, "%s\n", *pp);
return;
case CMDINFO_DSCP:
{
BOOL needs_quote = FALSE;
gstring * g;
-uschar *t;
-for (t = lpart; !needs_quote && *t != 0; t++)
+for (uschar * t = lpart; !needs_quote && *t != 0; t++)
{
needs_quote = !isalnum(*t) && strchr("!#$%&'*+-/=?^_`{|}~", *t) == NULL &&
(*t != '.' || t == lpart || t[1] == 0);
static uschar *
get_stdinput(char *(*fn_readline)(const char *), void(*fn_addhist)(const char *))
{
-int i;
gstring * g = NULL;
if (!fn_readline) { printf("> "); fflush(stdout); }
-for (i = 0;; i++)
+for (int i = 0;; i++)
{
uschar buffer[1024];
uschar *p, *ss;
/* Handle specific program invocation variants */
if (Ustrcmp(progname, US"-mailq") == 0)
- {
- fprintf(stderr,
+ exim_fail(
"mailq - list the contents of the mail queue\n\n"
"For a list of options, see the Exim documentation.\n");
- exit(EXIT_FAILURE);
- }
/* Generic usage - we output this whatever happens */
-fprintf(stderr,
+exim_fail(
"Exim is a Mail Transfer Agent. It is normally called by Mail User Agents,\n"
"not directly from a shell command line. Options and/or arguments control\n"
"what it does when called. For a list of options, see the Exim documentation.\n");
-
-exit(EXIT_FAILURE);
}
macros_trusted(BOOL opt_D_used)
{
#ifdef WHITELIST_D_MACROS
-macro_item *m;
-uschar *whitelisted, *end, *p, **whites, **w;
+uschar *whitelisted, *end, *p, **whites;
int white_count, i, n;
size_t len;
BOOL prev_char_item, found;
/* The list of commandline macros should be very short.
Accept the N*M complexity. */
-for (m = macros_user; m; m = m->next) if (m->command_line)
+for (macro_item * m = macros_user; m; m = m->next) if (m->command_line)
{
found = FALSE;
- for (w = whites; *w; ++w)
+ for (uschar ** w = whites; *w; ++w)
if (Ustrcmp(*w, m->name) == 0)
{
found = TRUE;
}
+
/*************************************************
* Entry point and high-level code *
*************************************************/
int sender_address_domain = 0;
int test_retry_arg = -1;
int test_rewrite_arg = -1;
+gid_t original_egid;
BOOL arg_queue_only = FALSE;
BOOL bi_option = FALSE;
BOOL checking = FALSE;
struct stat statbuf;
pid_t passed_qr_pid = (pid_t)0;
int passed_qr_pipe = -1;
-gid_t group_list[NGROUPS_MAX];
+gid_t group_list[EXIM_GROUPLIST_SIZE];
/* For the -bI: flag */
enum commandline_info info_flag = CMDINFO_NONE;
if (route_finduser(US EXIM_USERNAME, &pw, &exim_uid))
{
if (exim_uid == 0)
- {
- fprintf(stderr, "exim: refusing to run with uid 0 for \"%s\"\n",
- EXIM_USERNAME);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: refusing to run with uid 0 for \"%s\"\n", EXIM_USERNAME);
+
/* If ref:name uses a number as the name, route_finduser() returns
TRUE with exim_uid set and pw coerced to NULL. */
if (pw)
exim_gid = pw->pw_gid;
#ifndef EXIM_GROUPNAME
else
- {
- fprintf(stderr,
+ exim_fail(
"exim: ref:name should specify a usercode, not a group.\n"
"exim: can't let you get away with it unless you also specify a group.\n");
- exit(EXIT_FAILURE);
- }
#endif
}
else
- {
- fprintf(stderr, "exim: failed to find uid for user name \"%s\"\n",
- EXIM_USERNAME);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: failed to find uid for user name \"%s\"\n", EXIM_USERNAME);
#endif
#ifdef EXIM_GROUPNAME
if (!route_findgroup(US EXIM_GROUPNAME, &exim_gid))
- {
- fprintf(stderr, "exim: failed to find gid for group name \"%s\"\n",
- EXIM_GROUPNAME);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: failed to find gid for group name \"%s\"\n", EXIM_GROUPNAME);
#endif
#ifdef CONFIGURE_OWNERNAME
if (!route_finduser(US CONFIGURE_OWNERNAME, NULL, &config_uid))
- {
- fprintf(stderr, "exim: failed to find uid for user name \"%s\"\n",
+ exim_fail("exim: failed to find uid for user name \"%s\"\n",
CONFIGURE_OWNERNAME);
- exit(EXIT_FAILURE);
- }
#endif
/* We default the system_filter_user to be the Exim run-time user, as a
#ifdef CONFIGURE_GROUPNAME
if (!route_findgroup(US CONFIGURE_GROUPNAME, &config_gid))
- {
- fprintf(stderr, "exim: failed to find gid for group name \"%s\"\n",
+ exim_fail("exim: failed to find gid for group name \"%s\"\n",
CONFIGURE_GROUPNAME);
- exit(EXIT_FAILURE);
- }
#endif
/* In the Cygwin environment, some initialization used to need doing.
because store_malloc writes a log entry on failure. */
if (!(log_buffer = US malloc(LOG_BUFFER_SIZE)))
- {
- fprintf(stderr, "exim: failed to get store for log buffer\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: failed to get store for log buffer\n");
/* Initialize the default log options. */
normally be root, but in some esoteric environments it may not be. */
original_euid = geteuid();
+original_egid = getegid();
/* Get the real uid and gid. If the caller is root, force the effective uid/gid
to be the same as the real ones. This makes a difference only if Exim is setuid
if (real_uid == root_uid)
{
- rv = setgid(real_gid);
- if (rv)
- {
- fprintf(stderr, "exim: setgid(%ld) failed: %s\n",
+ if ((rv = setgid(real_gid)))
+ exim_fail("exim: setgid(%ld) failed: %s\n",
(long int)real_gid, strerror(errno));
- exit(EXIT_FAILURE);
- }
- rv = setuid(real_uid);
- if (rv)
- {
- fprintf(stderr, "exim: setuid(%ld) failed: %s\n",
+ if ((rv = setuid(real_uid)))
+ exim_fail("exim: setuid(%ld) failed: %s\n",
(long int)real_uid, strerror(errno));
- exit(EXIT_FAILURE);
- }
}
/* If neither the original real uid nor the original euid was root, Exim is
filter_test |= checking = FTEST_SYSTEM;
if (*(++argrest) != 0) { badarg = TRUE; break; }
if (++i < argc) filter_test_sfile = argv[i]; else
- {
- fprintf(stderr, "exim: file name expected after %s\n", argv[i-1]);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: file name expected after %s\n", argv[i-1]);
}
/* -bf: Run user filter test
{
filter_test |= checking = FTEST_USER;
if (++i < argc) filter_test_ufile = argv[i]; else
- {
- fprintf(stderr, "exim: file name expected after %s\n", argv[i-1]);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: file name expected after %s\n", argv[i-1]);
}
else
{
if (++i >= argc)
- {
- fprintf(stderr, "exim: string expected after %s\n", arg);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after %s\n", arg);
if (Ustrcmp(argrest, "d") == 0) ftest_domain = argv[i];
else if (Ustrcmp(argrest, "l") == 0) ftest_localpart = argv[i];
else if (Ustrcmp(argrest, "p") == 0) ftest_prefix = argv[i];
f.background_daemon = FALSE;
f.daemon_listen = TRUE;
if (*(++argrest) != '\0')
- {
- inetd_wait_timeout = readconf_readtime(argrest, 0, FALSE);
- if (inetd_wait_timeout <= 0)
- {
- fprintf(stderr, "exim: bad time value %s: abandoned\n", argv[i]);
- exit(EXIT_FAILURE);
- }
- }
+ if ((inetd_wait_timeout = readconf_readtime(argrest, 0, FALSE)) <= 0)
+ exim_fail("exim: bad time value %s: abandoned\n", argv[i]);
}
else badarg = TRUE;
Ustrncmp(filename, ALT_CONFIG_PREFIX, len) != 0 ||
Ustrstr(filename, "/../") != NULL) &&
(Ustrcmp(filename, "/dev/null") != 0 || real_uid != root_uid))
- {
- fprintf(stderr, "-C Permission denied\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("-C Permission denied\n");
}
#endif
if (real_uid != root_uid)
/* -D: set up a macro definition */
case 'D':
- #ifdef DISABLE_D_OPTION
- fprintf(stderr, "exim: -D is not available in this Exim binary\n");
- exit(EXIT_FAILURE);
- #else
+#ifdef DISABLE_D_OPTION
+ exim_fail("exim: -D is not available in this Exim binary\n");
+#else
{
int ptr = 0;
macro_item *m;
while (isspace(*s)) s++;
if (*s < 'A' || *s > 'Z')
- {
- fprintf(stderr, "exim: macro name set by -D must start with "
+ exim_fail("exim: macro name set by -D must start with "
"an upper case letter\n");
- exit(EXIT_FAILURE);
- }
while (isalnum(*s) || *s == '_')
{
for (m = macros_user; m; m = m->next)
if (Ustrcmp(m->name, name) == 0)
- {
- fprintf(stderr, "exim: duplicated -D in command line\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: duplicated -D in command line\n");
m = macro_create(name, s, TRUE);
if (clmacro_count >= MAX_CLMACROS)
- {
- fprintf(stderr, "exim: too many -D options on command line\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: too many -D options on command line\n");
clmacros[clmacro_count++] = string_sprintf("-D%s=%s", m->name,
m->replacement);
}
#endif
allow_domain_literals = FALSE;
strip_trailing_dot = FALSE;
- if (sender_address == NULL)
- {
- fprintf(stderr, "exim: bad -f address \"%s\": %s\n", argrest, errmess);
- return EXIT_FAILURE;
- }
+ if (!sender_address)
+ exim_fail("exim: bad -f address \"%s\": %s\n", argrest, errmess);
}
f.sender_address_forced = TRUE;
}
if(++i < argc) argrest = argv[i]; else
{ badarg = TRUE; break; }
}
- sz = Ustrlen(argrest);
- if (sz > 32)
- {
- fprintf(stderr, "exim: the -L syslog name is too long: \"%s\"\n", argrest);
- return EXIT_FAILURE;
- }
+ if ((sz = Ustrlen(argrest)) > 32)
+ exim_fail("exim: the -L syslog name is too long: \"%s\"\n", argrest);
if (sz < 1)
- {
- fprintf(stderr, "exim: the -L syslog name is too short\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: the -L syslog name is too short\n");
cmdline_syslog_name = argrest;
break;
EXIM_SOCKLEN_T size = sizeof(interface_sock);
if (argc != i + 6)
- {
- fprintf(stderr, "exim: too many or too few arguments after -MC\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: too many or too few arguments after -MC\n");
if (msg_action_arg >= 0)
- {
- fprintf(stderr, "exim: incompatible arguments\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: incompatible arguments\n");
continue_transport = argv[++i];
continue_hostname = argv[++i];
queue_run_pipe = passed_qr_pipe;
if (!mac_ismsgid(argv[i]))
- {
- fprintf(stderr, "exim: malformed message id %s after -MC option\n",
+ exim_fail("exim: malformed message id %s after -MC option\n",
argv[i]);
- return EXIT_FAILURE;
- }
/* Set up $sending_ip_address and $sending_port, unless proxied */
sending_ip_address = host_ntoa(-1, &interface_sock, NULL,
&sending_port);
else
- {
- fprintf(stderr, "exim: getsockname() failed after -MC option: %s\n",
+ exim_fail("exim: getsockname() failed after -MC option: %s\n",
strerror(errno));
- return EXIT_FAILURE;
- }
if (f.running_in_test_harness) millisleep(500);
break;
msg_action_arg = i + 1;
if (msg_action_arg >= argc)
- {
- fprintf(stderr, "exim: no message ids given after %s option\n", arg);
- return EXIT_FAILURE;
- }
+ exim_fail("exim: no message ids given after %s option\n", arg);
/* Some require only message ids to follow */
if (!one_msg_action)
{
- int j;
- for (j = msg_action_arg; j < argc; j++) if (!mac_ismsgid(argv[j]))
- {
- fprintf(stderr, "exim: malformed message id %s after %s option\n",
+ for (int j = msg_action_arg; j < argc; j++) if (!mac_ismsgid(argv[j]))
+ exim_fail("exim: malformed message id %s after %s option\n",
argv[j], arg);
- return EXIT_FAILURE;
- }
goto END_ARG; /* Remaining args are ids */
}
else
{
if (!mac_ismsgid(argv[msg_action_arg]))
- {
- fprintf(stderr, "exim: malformed message id %s after %s option\n",
+ exim_fail("exim: malformed message id %s after %s option\n",
argv[msg_action_arg], arg);
- return EXIT_FAILURE;
- }
i++;
}
break;
if (*argrest == 0)
{
if (++i >= argc)
- {
- fprintf(stderr, "exim: string expected after -O\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after -O\n");
}
break;
if (alias_arg[0] == 0)
{
if (i+1 < argc) alias_arg = argv[++i]; else
- {
- fprintf(stderr, "exim: string expected after -oA\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after -oA\n");
}
}
if (p != NULL)
{
if (!isdigit(*p))
- {
- fprintf(stderr, "exim: number expected after -oB\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: number expected after -oB\n");
connection_max_messages = Uatoi(p);
}
}
else if (*argrest == 'M')
{
if (i+1 >= argc)
- {
- fprintf(stderr, "exim: data expected after -o%s\n", argrest);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: data expected after -o%s\n", argrest);
/* -oMa: Set sender host address */
else if (Ustrcmp(argrest, "Mm") == 0)
{
if (!mac_ismsgid(argv[i+1]))
- {
- fprintf(stderr,"-oMm must be a valid message ID\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("-oMm must be a valid message ID\n");
if (!f.trusted_config)
- {
- fprintf(stderr,"-oMm must be called by a trusted user/config\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("-oMm must be called by a trusted user/config\n");
message_reference = argv[++i];
}
else if (Ustrcmp(argrest, "Mr") == 0)
if (received_protocol)
- {
- fprintf(stderr, "received_protocol is set already\n");
- exit(EXIT_FAILURE);
- }
- else received_protocol = argv[++i];
+ exim_fail("received_protocol is set already\n");
+ else
+ received_protocol = argv[++i];
/* -oMs: Set sender host name */
}
else *tp = readconf_readtime(argrest + 1, 0, FALSE);
if (*tp < 0)
- {
- fprintf(stderr, "exim: bad time value %s: abandoned\n", argv[i]);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: bad time value %s: abandoned\n", argv[i]);
}
/* -oX <list>: Override local_interfaces and/or default daemon ports */
uschar *hn;
if (received_protocol)
- {
- fprintf(stderr, "received_protocol is set already\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("received_protocol is set already\n");
hn = Ustrchr(argrest, ':');
if (hn == NULL)
case 'q':
receiving_message = FALSE;
if (queue_interval >= 0)
- {
- fprintf(stderr, "exim: -q specified more than once\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: -q specified more than once\n");
/* -qq...: Do queue runs in a 2-stage manner */
else if ((queue_interval = readconf_readtime(*argrest ? argrest : argv[++i],
0, FALSE)) <= 0)
- {
- fprintf(stderr, "exim: bad time value %s: abandoned\n", argv[i]);
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: bad time value %s: abandoned\n", argv[i]);
break;
argument. */
if (*argrest != 0)
- {
- int i;
- for (i = 0; i < nelem(rsopts); i++)
+ for (int i = 0; i < nelem(rsopts); i++)
if (Ustrcmp(argrest, rsopts[i]) == 0)
{
if (i != 2) f.queue_run_force = TRUE;
if (i == 1 || i == 4) f.deliver_force_thaw = TRUE;
argrest += Ustrlen(rsopts[i]);
}
- }
/* -R: Set string to match in addresses for forced queue run to
pick out particular messages. */
else if (i+1 < argc)
deliver_selectstring = argv[++i];
else
- {
- fprintf(stderr, "exim: string expected after -R\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after -R\n");
break;
argument. */
if (*argrest)
- {
- int i;
- for (i = 0; i < nelem(rsopts); i++)
+ for (int i = 0; i < nelem(rsopts); i++)
if (Ustrcmp(argrest, rsopts[i]) == 0)
{
if (i != 2) f.queue_run_force = TRUE;
if (i == 1 || i == 4) f.deliver_force_thaw = TRUE;
argrest += Ustrlen(rsopts[i]);
}
- }
/* -S: Set string to match in addresses for forced queue run to
pick out particular messages. */
else if (i+1 < argc)
deliver_selectstring_sender = argv[++i];
else
- {
- fprintf(stderr, "exim: string expected after -S\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after -S\n");
break;
/* -Tqt is an option that is exclusively for use by the testing suite.
case 'X':
if (*argrest == '\0')
if (++i >= argc)
- {
- fprintf(stderr, "exim: string expected after -X\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: string expected after -X\n");
break;
case 'z':
if (*argrest == '\0')
- if (++i < argc) log_oneline = argv[i]; else
- {
- fprintf(stderr, "exim: file name expected after %s\n", argv[i-1]);
- exit(EXIT_FAILURE);
- }
+ if (++i < argc)
+ log_oneline = argv[i];
+ else
+ exim_fail("exim: file name expected after %s\n", argv[i-1]);
break;
/* All other initial characters are errors */
/* Failed to recognize the option, or syntax error */
if (badarg)
- {
- fprintf(stderr, "exim abandoned: unknown, malformed, or incomplete "
+ exim_fail("exim abandoned: unknown, malformed, or incomplete "
"option %s\n", arg);
- exit(EXIT_FAILURE);
- }
}
(!expansion_test || expansion_test_message != NULL)
)
)
- {
- fprintf(stderr, "exim: incompatible command-line options or arguments\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: incompatible command-line options or arguments\n");
/* If debugging is set up, set the file and the file descriptor to pass on to
child processes. It should, of course, be 2 for stderr. Also, force the daemon
till after reading the config, which might specify the exim gid. Therefore,
save the group list here first. */
-group_count = getgroups(NGROUPS_MAX, group_list);
-if (group_count < 0)
- {
- fprintf(stderr, "exim: getgroups() failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+if ((group_count = getgroups(nelem(group_list), group_list)) < 0)
+ exim_fail("exim: getgroups() failed: %s\n", strerror(errno));
/* There is a fundamental difference in some BSD systems in the matter of
groups. FreeBSD and BSDI are known to be different; NetBSD and OpenBSD are
list. Calling setgroups() with zero groups on a "different" system results in
an error return. The following code should cope with both types of system.
+ Unfortunately, recent MacOS, which should be a FreeBSD, "helpfully" succeeds
+ the "setgroups() with zero groups" - and changes the egid.
+ Thanks to that we had to stash the original_egid above, for use below
+ in the call to exim_setugid().
+
However, if this process isn't running as root, setgroups() can't be used
since you have to be root to run it, even if throwing away groups. Not being
root here happens only in some unusual configurations. We just ignore the
error. */
-if (setgroups(0, NULL) != 0)
- {
- if (setgroups(1, group_list) != 0 && !unprivileged)
- {
- fprintf(stderr, "exim: setgroups() failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- }
+if (setgroups(0, NULL) != 0 && setgroups(1, group_list) != 0 && !unprivileged)
+ exim_fail("exim: setgroups() failed: %s\n", strerror(errno));
/* If the configuration file name has been altered by an argument on the
command line (either a new file name or a macro definition) and the caller is
Note that if the invoker is Exim, the logs remain available. Messing with
this causes unlogged successful deliveries. */
- if ((log_stderr != NULL) && (real_uid != exim_uid))
+ if (log_stderr && real_uid != exim_uid)
f.really_exim = FALSE;
}
the real uid to the effective so that subsequent re-execs of Exim are done by a
privileged user. */
-else exim_setugid(geteuid(), getegid(), FALSE, US"forcing real = effective");
+else
+ exim_setugid(geteuid(), original_egid, FALSE, US"forcing real = effective");
/* If testing a filter, open the file(s) now, before wasting time doing other
setups and reading the message. */
-if ((filter_test & FTEST_SYSTEM) != 0)
- {
- filter_sfd = Uopen(filter_test_sfile, O_RDONLY, 0);
- if (filter_sfd < 0)
- {
- fprintf(stderr, "exim: failed to open %s: %s\n", filter_test_sfile,
+if (filter_test & FTEST_SYSTEM)
+ if ((filter_sfd = Uopen(filter_test_sfile, O_RDONLY, 0)) < 0)
+ exim_fail("exim: failed to open %s: %s\n", filter_test_sfile,
strerror(errno));
- return EXIT_FAILURE;
- }
- }
-if ((filter_test & FTEST_USER) != 0)
- {
- filter_ufd = Uopen(filter_test_ufile, O_RDONLY, 0);
- if (filter_ufd < 0)
- {
- fprintf(stderr, "exim: failed to open %s: %s\n", filter_test_ufile,
+if (filter_test & FTEST_USER)
+ if ((filter_ufd = Uopen(filter_test_ufile, O_RDONLY, 0)) < 0)
+ exim_fail("exim: failed to open %s: %s\n", filter_test_ufile,
strerror(errno));
- return EXIT_FAILURE;
- }
- }
/* Initialise lookup_list
If debugging, already called above via version reporting.
if (real_uid == root_uid || real_uid == exim_uid || real_gid == exim_gid)
f.admin_user = TRUE;
else
- {
- int i, j;
- for (i = 0; i < group_count && !f.admin_user; i++)
+ for (int i = 0; i < group_count && !f.admin_user; i++)
if (group_list[i] == exim_gid)
f.admin_user = TRUE;
else if (admin_groups)
- for (j = 1; j <= (int)admin_groups[0] && !f.admin_user; j++)
+ for (int j = 1; j <= (int)admin_groups[0] && !f.admin_user; j++)
if (admin_groups[j] == group_list[i])
f.admin_user = TRUE;
- }
/* Another group of privileged users are the trusted users. These are root,
exim, and any caller matching trusted_users or trusted_groups. Trusted callers
f.trusted_caller = TRUE;
else
{
- int i, j;
-
if (trusted_users)
- for (i = 1; i <= (int)trusted_users[0] && !f.trusted_caller; i++)
+ for (int i = 1; i <= (int)trusted_users[0] && !f.trusted_caller; i++)
if (trusted_users[i] == real_uid)
f.trusted_caller = TRUE;
if (trusted_groups)
- for (i = 1; i <= (int)trusted_groups[0] && !f.trusted_caller; i++)
+ for (int i = 1; i <= (int)trusted_groups[0] && !f.trusted_caller; i++)
if (trusted_groups[i] == real_gid)
f.trusted_caller = TRUE;
- else for (j = 0; j < group_count && !f.trusted_caller; j++)
+ else for (int j = 0; j < group_count && !f.trusted_caller; j++)
if (trusted_groups[i] == group_list[j])
f.trusted_caller = TRUE;
}
/* At this point, we know if the user is privileged and some command-line
options become possibly impermissible, depending upon the configuration file. */
-if (checking && commandline_checks_require_admin && !f.admin_user) {
- fprintf(stderr, "exim: those command-line flags are set to require admin\n");
- exit(EXIT_FAILURE);
-}
+if (checking && commandline_checks_require_admin && !f.admin_user)
+ exim_fail("exim: those command-line flags are set to require admin\n");
/* Handle the decoding of logging options. */
DEBUG(D_any)
{
- int i;
debug_printf("configuration file is %s\n", config_main_filename);
debug_printf("log selectors =");
- for (i = 0; i < log_selector_size; i++)
+ for (int i = 0; i < log_selector_size; i++)
debug_printf(" %08x", log_selector[i]);
debug_printf("\n");
}
/* If domain literals are not allowed, check the sender address that was
supplied with -f. Ditto for a stripped trailing dot. */
-if (sender_address != NULL)
+if (sender_address)
{
if (sender_address[sender_address_domain] == '[' && !allow_domain_literals)
- {
- fprintf(stderr, "exim: bad -f address \"%s\": domain literals not "
+ exim_fail("exim: bad -f address \"%s\": domain literals not "
"allowed\n", sender_address);
- return EXIT_FAILURE;
- }
if (f_end_dot && !strip_trailing_dot)
- {
- fprintf(stderr, "exim: bad -f address \"%s.\": domain is malformed "
+ exim_fail("exim: bad -f address \"%s.\": domain is malformed "
"(trailing dot not allowed)\n", sender_address);
- return EXIT_FAILURE;
- }
}
/* See if an admin user overrode our logging. */
-if (cmdline_syslog_name != NULL)
- {
+if (cmdline_syslog_name)
if (f.admin_user)
{
syslog_processname = cmdline_syslog_name;
log_file_path = string_copy(CUS"syslog");
}
else
- {
/* not a panic, non-privileged users should not be able to spam paniclog */
- fprintf(stderr,
+ exim_fail(
"exim: you lack sufficient privilege to specify syslog process name\n");
- return EXIT_FAILURE;
- }
- }
/* Paranoia check of maximum lengths of certain strings. There is a check
on the length of the log file path in log.c, which will come into effect
*/
#ifdef EXIM_TMPDIR
- {
- uschar **p;
- if (environ) for (p = USS environ; *p; p++)
+ if (environ) for (uschar ** p = USS environ; *p; p++)
if (Ustrncmp(*p, "TMPDIR=", 7) == 0 && Ustrcmp(*p+7, EXIM_TMPDIR) != 0)
{
uschar * newp = store_malloc(Ustrlen(EXIM_TMPDIR) + 8);
*p = newp;
DEBUG(D_any) debug_printf("reset TMPDIR=%s in environment\n", EXIM_TMPDIR);
}
- }
#endif
/* Timezone handling. If timezone_string is "utc", set a flag to cause all
{
uschar *errstr;
DEBUG(D_any) debug_printf("Starting Perl interpreter\n");
- errstr = init_perl(opt_perl_startup);
- if (errstr != NULL)
- {
- fprintf(stderr, "exim: error in perl_startup code: %s\n", errstr);
- return EXIT_FAILURE;
- }
+ if ((errstr = init_perl(opt_perl_startup)))
+ exim_fail("exim: error in perl_startup code: %s\n", errstr);
opt_perl_started = TRUE;
}
#endif /* EXIM_PERL */
if ( (debug_selector & D_any || LOGGING(arguments))
&& f.really_exim && !list_options && !checking)
{
- int i;
uschar *p = big_buffer;
Ustrcpy(p, "cwd= (failed)");
(void)string_format(p, big_buffer_size - (p - big_buffer), " %d args:", argc);
while (*p) p++;
- for (i = 0; i < argc; i++)
+ for (int i = 0; i < argc; i++)
{
int len = Ustrlen(argv[i]);
const uschar *printing;
(argv[1] == NULL)? US"" : argv[1]);
execv(CS argv[0], (char *const *)argv);
- fprintf(stderr, "exim: exec failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
+ exim_fail("exim: exec failed: %s\n", strerror(errno));
}
else
{
(list_queue && queue_list_requires_admin) ||
(queue_interval >= 0 && prod_requires_admin) ||
(debugset && !f.running_in_test_harness))
- {
- fprintf(stderr, "exim:%s permission denied\n", debugset? " debugging" : "");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim:%s permission denied\n", debugset? " debugging" : "");
}
/* If the real user is not root or the exim uid, the argument for passing
(f.dont_deliver &&
(queue_interval >= 0 || f.daemon_listen || msg_action_arg > 0)
)) && !f.running_in_test_harness)
- {
- fprintf(stderr, "exim: Permission denied\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: Permission denied\n");
/* If the caller is not trusted, certain arguments are ignored when running for
real, but are permitted when checking things (-be, -bv, -bt, -bh, -bf, -bF).
DEBUG(D_acl) debug_printf("suppress_local_fixups forced on by -G\n");
}
else
- {
- fprintf(stderr, "exim: permission denied (-G requires a trusted user)\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: permission denied (-G requires a trusted user)\n");
}
/* If an SMTP message is being received check to see if the standard input is a
"inetd is not supported when mua_wrapper is set");
}
else
- {
- fprintf(stderr,
+ exim_fail(
"exim: Permission denied (unprivileged user, unprivileged port)\n");
- return EXIT_FAILURE;
- }
}
}
}
no need to complain then. */
if (rv == -1)
if (!(unprivileged || removed_privilege))
- {
- fprintf(stderr,
- "exim: changing group failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: changing group failed: %s\n", strerror(errno));
else
DEBUG(D_any) debug_printf("changing group to %ld failed: %s\n",
(long int)exim_gid, strerror(errno));
int yield = EXIT_SUCCESS;
set_process_info("acting on specified messages");
+ /* ACL definitions may be needed when removing a message (-Mrm) because
+ event_action gets expanded */
+
+ if (msg_action == MSG_REMOVE)
+ readconf_rest();
+
if (!one_msg_action)
{
for (i = msg_action_arg; i < argc; i++)
printf("No retry information found\n");
else
{
- retry_rule *r;
more_errno = yield->more_errno;
printf("Retry rule: %s ", yield->pattern);
printf("auth_failed ");
else printf("* ");
- for (r = yield->rules; r; r = r->next)
+ for (retry_rule * r = yield->rules; r; r = r->next)
{
printf("%c,%s", r->rule, readconf_printtime(r->timeout)); /* Do not */
printf(",%s", readconf_printtime(r->p1)); /* amalgamate */
{
uschar spoolname[256]; /* Not big_buffer; used in spool_read_header() */
if (!f.admin_user)
- {
- fprintf(stderr, "exim: permission denied\n");
- exit(EXIT_FAILURE);
- }
+ exim_fail("exim: permission denied\n");
message_id = argv[msg_action_arg];
(void)string_format(spoolname, sizeof(spoolname), "%s-H", message_id);
if ((deliver_datafile = spool_open_datafile(message_id)) < 0)
int save_stdin = dup(0);
int fd = Uopen(expansion_test_message, O_RDONLY, 0);
if (fd < 0)
- {
- fprintf(stderr, "exim: failed to open %s: %s\n", expansion_test_message,
+ exim_fail("exim: failed to open %s: %s\n", expansion_test_message,
strerror(errno));
- return EXIT_FAILURE;
- }
(void) dup2(fd, 0);
filter_test = FTEST_USER; /* Fudge to make it look like filter test */
message_ended = END_NOTENDED;
error code is given.) */
if ((!smtp_input || smtp_batched_input) && !receive_check_fs(0))
- {
- fprintf(stderr, "exim: insufficient disk space\n");
- return EXIT_FAILURE;
- }
+ exim_fail("exim: insufficient disk space\n");
/* If this is smtp input of any kind, real or batched, handle the start of the
SMTP session.
else
{
- int i;
int rcount = 0;
int count = argc - recipients_arg;
uschar **list = argv + recipients_arg;
/* Loop for each argument */
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
int start, end, domain;
uschar *errmess;
DEBUG(D_receive)
{
- int i;
if (sender_address != NULL) debug_printf("Sender: %s\n", sender_address);
if (recipients_list != NULL)
{
debug_printf("Recipients:\n");
- for (i = 0; i < recipients_count; i++)
+ for (int i = 0; i < recipients_count; i++)
debug_printf(" %s\n", recipients_list[i].address);
}
}
callout_address = NULL;
sending_ip_address = NULL;
acl_var_m = NULL;
- { int i; for(i=0; i<REGEX_VARS; i++) regex_vars[i] = NULL; }
+ for(int i = 0; i < REGEX_VARS; i++) regex_vars[i] = NULL;
store_reset(reset_point);
}