Testsuite: avoid total fail on DISABLE_EVENT build
[exim.git] / src / src / exim.c
index 3170bef98cbd5fbed6f6771496f4a6311eecd6e1..8111a44899cd354f99bb8f3943ea5b55d97fa74b 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) The Exim Maintainers 2020 - 2023 */
+/* Copyright (c) The Exim Maintainers 2020 - 2024 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 /* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -237,7 +237,7 @@ va_end(ap);
 static void
 term_handler(int sig)
 {
 static void
 term_handler(int sig)
 {
-exit(1);
+exim_exit(EXIT_FAILURE);
 }
 
 
 }
 
 
@@ -997,32 +997,35 @@ if (s)
 static gstring *
 show_db_version(gstring * g)
 {
 static gstring *
 show_db_version(gstring * g)
 {
+g = string_cat(g, US"Hints DB:\n");
 #ifdef DB_VERSION_STRING
 DEBUG(D_any)
   {
 #ifdef DB_VERSION_STRING
 DEBUG(D_any)
   {
-  g = string_fmt_append(g, "Library version: BDB: Compile: %s\n", DB_VERSION_STRING);
-  g = string_fmt_append(g, "                      Runtime: %s\n",
+  g = string_fmt_append(g, " Library version: BDB: Compile: %s\n", DB_VERSION_STRING);
+  g = string_fmt_append(g, "                       Runtime: %s\n",
     db_version(NULL, NULL, NULL));
   }
 else
     db_version(NULL, NULL, NULL));
   }
 else
-  g = string_fmt_append(g, "Berkeley DB: %s\n", DB_VERSION_STRING);
+  g = string_fmt_append(g, " Berkeley DB: %s\n", DB_VERSION_STRING);
 
 #elif defined(BTREEVERSION) && defined(HASHVERSION)
 # ifdef USE_DB
 
 #elif defined(BTREEVERSION) && defined(HASHVERSION)
 # ifdef USE_DB
-  g = string_cat(g, US"Probably Berkeley DB version 1.8x (native mode)\n");
+  g = string_cat(g, US" Probably Berkeley DB version 1.8x (native mode)\n");
 # else
 # else
-  g = string_cat(g, US"Probably Berkeley DB version 1.8x (compatibility mode)\n");
+  g = string_cat(g, US" Probably Berkeley DB version 1.8x (compatibility mode)\n");
 # endif
 
 #elif defined(_DBM_RDONLY) || defined(dbm_dirfno)
 # endif
 
 #elif defined(_DBM_RDONLY) || defined(dbm_dirfno)
-g = string_cat(g, US"Probably ndbm\n");
+g = string_cat(g, US" Probably ndbm\n");
+#elif defined(USE_SQLITE)
+g = string_cat(g, US" Using sqlite3\n");
 #elif defined(USE_TDB)
 #elif defined(USE_TDB)
-g = string_cat(g, US"Using tdb\n");
+g = string_cat(g, US" Using tdb\n");
 #else
 # ifdef USE_GDBM
 #else
 # ifdef USE_GDBM
-  g = string_cat(g, US"Probably GDBM (native mode)\n");
+g = string_cat(g, US" Probably GDBM (native mode)\n");
 # else
 # else
-  g = string_cat(g, US"Probably GDBM (compatibility mode)\n");
+g = string_cat(g, US" Probably GDBM (compatibility mode)\n");
 # endif
 #endif
 return g;
 # endif
 #endif
 return g;
@@ -1108,6 +1111,9 @@ g = string_cat(g, US"Support for:");
 #ifndef DISABLE_ESMTP_LIMITS
   g = string_cat(g, US" ESMTP_Limits");
 #endif
 #ifndef DISABLE_ESMTP_LIMITS
   g = string_cat(g, US" ESMTP_Limits");
 #endif
+#ifndef DISABLE_WELLKNOWN
+  g = string_cat(g, US" ESMTP_Wellknown");
+#endif
 #ifndef DISABLE_EVENT
   g = string_cat(g, US" Event");
 #endif
 #ifndef DISABLE_EVENT
   g = string_cat(g, US" Event");
 #endif
@@ -2339,9 +2345,9 @@ on the second character (the one after '-'), to save some effort. */
 
        /* -bh: Host checking - an IP address must follow. */
        case 'h':
 
        /* -bh: Host checking - an IP address must follow. */
        case 'h':
-         if (!*argrest || Ustrcmp(argrest, "c") == 0)
+         if (  (!*argrest || Ustrcmp(argrest, "c") == 0)
+            && ++i < argc)
            {
            {
-           if (++i >= argc) { badarg = TRUE; break; }
            sender_host_address = string_copy_taint(
                  exim_str_fail_toolong(argv[i], EXIM_IPADDR_MAX, "-bh"),
                  GET_TAINTED);
            sender_host_address = string_copy_taint(
                  exim_str_fail_toolong(argv[i], EXIM_IPADDR_MAX, "-bh"),
                  GET_TAINTED);
@@ -2349,7 +2355,8 @@ on the second character (the one after '-'), to save some effort. */
            f.host_checking_callout = *argrest == 'c';
            message_logs = FALSE;
            }
            f.host_checking_callout = *argrest == 'c';
            message_logs = FALSE;
            }
-         else badarg = TRUE;
+         else
+           badarg = TRUE;
          break;
 
        /* -bi: This option is used by sendmail to initialize *the* alias file,
          break;
 
        /* -bi: This option is used by sendmail to initialize *the* alias file,
@@ -2632,14 +2639,11 @@ on the second character (the one after '-'), to save some effort. */
               reset_point = store_mark();
               while (Ufgets(big_buffer, big_buffer_size, trust_list))
                 {
               reset_point = store_mark();
               while (Ufgets(big_buffer, big_buffer_size, trust_list))
                 {
-                uschar *start = big_buffer, *nl;
-                while (*start && isspace(*start))
-                start++;
-                if (*start != '/')
+                uschar * start = big_buffer, * nl;
+                if (Uskip_whitespace(&start) != '/')
                   continue;
                   continue;
-                nl = Ustrchr(start, '\n');
-                if (nl)
-                  *nl = 0;
+                if ((nl = Ustrchr(start, '\n')))
+                  *nl = '\0';
                 trusted_configs[nr_configs++] = string_copy(start);
                 if (nr_configs == nelem(trusted_configs))
                   break;
                 trusted_configs[nr_configs++] = string_copy(start);
                 if (nr_configs == nelem(trusted_configs))
                   break;
@@ -2698,7 +2702,7 @@ on the second character (the one after '-'), to save some effort. */
       const uschar * s = argrest;
 
       opt_D_used = TRUE;
       const uschar * s = argrest;
 
       opt_D_used = TRUE;
-      while (isspace(*s)) s++;
+      Uskip_whitespace(&s);
 
       if (*s < 'A' || *s > 'Z')
         exim_fail("exim: macro name set by -D must start with "
 
       if (*s < 'A' || *s > 'Z')
         exim_fail("exim: macro name set by -D must start with "
@@ -2711,11 +2715,10 @@ on the second character (the one after '-'), to save some effort. */
         }
       name[ptr] = 0;
       if (ptr == 0) { badarg = TRUE; break; }
         }
       name[ptr] = 0;
       if (ptr == 0) { badarg = TRUE; break; }
-      while (isspace(*s)) s++;
-      if (*s != 0)
+      if (Uskip_whitespace(&s))
         {
         if (*s++ != '=') { badarg = TRUE; break; }
         {
         if (*s++ != '=') { badarg = TRUE; break; }
-        while (isspace(*s)) s++;
+        Uskip_whitespace(&s);
         }
 
       for (m = macros_user; m; m = m->next)
         }
 
       for (m = macros_user; m; m = m->next)
@@ -4689,12 +4692,12 @@ if (malware_test_file)
   if ((result = malware_in_file(malware_test_file)) == FAIL)
     {
     printf("No malware found.\n");
   if ((result = malware_in_file(malware_test_file)) == FAIL)
     {
     printf("No malware found.\n");
-    exit(EXIT_SUCCESS);
+    exim_exit(EXIT_SUCCESS);
     }
   if (result != OK)
     {
     printf("Malware lookup returned non-okay/fail: %d\n", result);
     }
   if (result != OK)
     {
     printf("Malware lookup returned non-okay/fail: %d\n", result);
-    exit(EXIT_FAILURE);
+    exim_exit(EXIT_FAILURE);
     }
   if (malware_name)
     printf("Malware found: %s\n", malware_name);
     }
   if (malware_name)
     printf("Malware found: %s\n", malware_name);
@@ -4703,7 +4706,7 @@ if (malware_test_file)
 #else
   printf("Malware scanning not enabled at compile time.\n");
 #endif
 #else
   printf("Malware scanning not enabled at compile time.\n");
 #endif
-  exit(EXIT_FAILURE);
+  exim_exit(EXIT_FAILURE);
   }
 
 /* Handle a request to list the delivery queue */
   }
 
 /* Handle a request to list the delivery queue */
@@ -4712,7 +4715,7 @@ if (list_queue)
   {
   set_process_info("listing the queue");
   queue_list(list_queue_option, argv + recipients_arg, argc - recipients_arg);
   {
   set_process_info("listing the queue");
   queue_list(list_queue_option, argv + recipients_arg, argc - recipients_arg);
-  exit(EXIT_SUCCESS);
+  exim_exit(EXIT_SUCCESS);
   }
 
 /* Handle a request to count the delivery queue */
   }
 
 /* Handle a request to count the delivery queue */
@@ -4721,7 +4724,7 @@ if (count_queue)
   {
   set_process_info("counting the queue");
   fprintf(stdout, "%u\n", queue_count());
   {
   set_process_info("counting the queue");
   fprintf(stdout, "%u\n", queue_count());
-  exit(EXIT_SUCCESS);
+  exim_exit(EXIT_SUCCESS);
   }
 
 /* Handle actions on specific messages, except for the force delivery and
   }
 
 /* Handle actions on specific messages, except for the force delivery and
@@ -4760,7 +4763,7 @@ if (msg_action_arg > 0 && msg_action != MSG_DELIVER && msg_action != MSG_LOAD)
 
   else if (!queue_action(argv[msg_action_arg], msg_action, argv, argc,
     recipients_arg)) yield = EXIT_FAILURE;
 
   else if (!queue_action(argv[msg_action_arg], msg_action, argv, argc,
     recipients_arg)) yield = EXIT_FAILURE;
-  exit(yield);
+  exim_exit(yield);
   }
 
 /* We used to set up here to skip reading the ACL section, on
   }
 
 /* We used to set up here to skip reading the ACL section, on
@@ -5163,7 +5166,7 @@ if (f.daemon_listen || f.inetd_wait_mode || is_multiple_qrun())
     (void)gettimeofday(&t0, NULL);
 # endif
     if (!tls_dropprivs_validate_require_cipher(FALSE))
     (void)gettimeofday(&t0, NULL);
 # endif
     if (!tls_dropprivs_validate_require_cipher(FALSE))
-      exit(1);
+      exim_exit(EXIT_FAILURE);
 # ifdef MEASURE_TIMING
     report_time_since(&t0, US"validate_ciphers (delta)");
 # endif
 # ifdef MEASURE_TIMING
     report_time_since(&t0, US"validate_ciphers (delta)");
 # endif
@@ -5447,11 +5450,14 @@ if (host_checking)
     }
 
   /* In case the given address is a non-canonical IPv6 address, canonicalize
     }
 
   /* In case the given address is a non-canonical IPv6 address, canonicalize
-  it. The code works for both IPv4 and IPv6, as it happens. */
+  it. Use the compressed form for IPv6. */
 
   size = host_aton(sender_host_address, x);
   sender_host_address = store_get(48, GET_UNTAINTED);  /* large enough for full IPv6 */
 
   size = host_aton(sender_host_address, x);
   sender_host_address = store_get(48, GET_UNTAINTED);  /* large enough for full IPv6 */
-  (void)host_nmtoa(size, x, -1, sender_host_address, ':');
+  if (size == 1)
+    (void) host_nmtoa(size, x, -1, sender_host_address, ':');
+  else
+    (void) ipv6_nmtoa(x, sender_host_address);
 
   /* Now set up for testing */
 
 
   /* Now set up for testing */
 
@@ -5918,7 +5924,7 @@ for (BOOL more = TRUE; more; )
         receive_add_recipient(string_copy_taint(recipient, GET_TAINTED), -1);
         s = ss;
         if (!finished)
         receive_add_recipient(string_copy_taint(recipient, GET_TAINTED), -1);
         s = ss;
         if (!finished)
-          while (*(++s) != 0 && (*s == ',' || isspace(*s)));
+          while (*++s && (*s == ',' || isspace(*s)));
         }
       }
 
         }
       }
 
@@ -6193,3 +6199,5 @@ return 0;                  /* To stop compiler warning */
 
 
 /* End of exim.c */
 
 
 /* End of exim.c */
+/* vi: aw ai sw=2
+*/