Testsuite: permit "client" utility to pass trailing spaces from script input lines
[exim.git] / test / src / client.c
index 7b7d9de9d7055665c7eb362c3990622da224361f..ac9a965e0d3569660453357b9a46dceede770756 100644 (file)
@@ -58,7 +58,6 @@ static int sigalrm_seen = 0;
 
 /* TLS support can be optionally included, either for OpenSSL or GnuTLS. The
 latter needs a whole pile of tables. */
-
 #ifdef HAVE_OPENSSL
 # define HAVE_TLS
 # include <openssl/crypto.h>
@@ -67,7 +66,14 @@ latter needs a whole pile of tables. */
 # include <openssl/ssl.h>
 # include <openssl/err.h>
 # include <openssl/rand.h>
-# include <openssl/ocsp.h>
+
+# if OPENSSL_VERSION_NUMBER < 0x0090806fL && !defined(DISABLE_OCSP) && !defined(OPENSSL_NO_TLSEXT)
+#  warning "OpenSSL library version too old; define DISABLE_OCSP in Makefile"
+#  define DISABLE_OCSP
+# endif
+# ifndef DISABLE_OCSP
+#  include <openssl/ocsp.h>
+# endif
 #endif
 
 
@@ -79,6 +85,9 @@ latter needs a whole pile of tables. */
 #  define HAVE_OCSP
 #  include <gnutls/ocsp.h>
 # endif
+# ifndef GNUTLS_NO_EXTENSIONS
+#  define GNUTLS_NO_EXTENSIONS 0
+# endif
 
 # define DH_BITS      768
 
@@ -188,6 +197,7 @@ setup_verify(BIO *bp, char *CAfile, char *CApath)
 }
 
 
+#ifndef DISABLE_OCSP
 static int
 tls_client_stapling_cb(SSL *s, void *arg)
 {
@@ -238,6 +248,7 @@ else
 X509_STORE_free(store);
 return ret;
 }
+#endif
 
 
 /*************************************************
@@ -248,21 +259,23 @@ int
 tls_start(int sock, SSL **ssl, SSL_CTX *ctx)
 {
 int rc;
-static const char *sid_ctx = "exim";
+static const unsigned char *sid_ctx = US"exim";
 
 RAND_load_file("client.c", -1);   /* Not *very* random! */
 
 *ssl = SSL_new (ctx);
-SSL_set_session_id_context(*ssl, sid_ctx, strlen(sid_ctx));
+SSL_set_session_id_context(*ssl, sid_ctx, strlen(CS sid_ctx));
 SSL_set_fd (*ssl, sock);
 SSL_set_connect_state(*ssl);
 
+#ifndef DISABLE_OCSP
 if (ocsp_stapling)
   {
   SSL_CTX_set_tlsext_status_cb(ctx, tls_client_stapling_cb);
   SSL_CTX_set_tlsext_status_arg(ctx, BIO_new_fp(stdout, BIO_NOCLOSE));
   SSL_set_tlsext_status_type(*ssl, TLSEXT_STATUSTYPE_ocsp);
   }
+#endif
 
 signal(SIGALRM, sigalrm_handler_flag);
 sigalrm_seen = 0;
@@ -441,7 +454,7 @@ tls_session_init(void)
 {
 gnutls_session session;
 
-gnutls_init(&session, GNUTLS_CLIENT);
+gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_NO_EXTENSIONS);
 
 gnutls_cipher_set_priority(session, default_cipher_priority);
 gnutls_compression_set_priority(session, comp_priority);
@@ -470,7 +483,14 @@ return session;
 *************************************************/
 
 const char * const HELP_MESSAGE = "\n\
-Usage: client\n\
+Usage: client\n"
+#ifdef HAVE_TLS
+"\
+          [-tls-on-connect]\n\
+          [-ocsp]\n"
+#endif
+"\
+          [-tn] n seconds timeout\n\
           <IP address>\n\
           <port>\n\
           [<outgoing interface>]\n\
@@ -821,8 +841,9 @@ if (tls_on_connect)
 while (fgets(CS outbuffer, sizeof(outbuffer), stdin) != NULL)
   {
   int n = (int)strlen(CS outbuffer);
-  while (n > 0 && isspace(outbuffer[n-1])) n--;
-  outbuffer[n] = 0;
+
+  /* Strip trailing newline */
+  if (outbuffer[n-1] == '\n') outbuffer[--n] = 0;
 
   /* Expect incoming */
 
@@ -981,8 +1002,8 @@ int rc;
 
     /* Shutdown TLS */
 
-    if (strcmp(outbuffer, "stoptls") == 0 ||
-        strcmp(outbuffer, "STOPTLS") == 0)
+    if (strcmp(CS outbuffer, "stoptls") == 0 ||
+        strcmp(CS outbuffer, "STOPTLS") == 0)
       {
       if (!tls_active)
         {
@@ -1009,14 +1030,14 @@ int rc;
 
     /* Remember that we sent STARTTLS */
 
-    sent_starttls = (strcmp(outbuffer, "starttls") == 0 ||
-                     strcmp(outbuffer, "STARTTLS") == 0);
+    sent_starttls = (strcmp(CS outbuffer, "starttls") == 0 ||
+                     strcmp(CS outbuffer, "STARTTLS") == 0);
 
     /* Fudge: if the command is "starttls_wait", we send the starttls bit,
     but we haven't set the flag, so that there is no negotiation. This is for
     testing the server's timeout. */
 
-    if (strcmp(outbuffer, "starttls_wait") == 0)
+    if (strcmp(CS outbuffer, "starttls_wait") == 0)
       {
       outbuffer[8] = 0;
       n = 8;
@@ -1035,7 +1056,7 @@ int rc;
       n--;
       }
 
-    while ((escape = strstr(outbuffer, "\\n")) != NULL)
+    while ((escape = US strstr(CS outbuffer, "\\n")) != NULL)
       {
       *escape = '\n';
       memmove(escape + 1, escape + 2,  (n + 2) - (escape - outbuffer) - 2);