-crlf option.
[openssl.git] / apps / s_server.c
index 4b932baac24911c80d598b4eff687e68348fd484..afe418211b171e36793e4305e3165b45d39e2c69 100644 (file)
  * [including the GNU Public Licence.]
  */
 
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef NO_STDIO
+#define APPS_WIN16
+#endif
+
 /* With IPv6, it looks like Digital has mixed up the proper order of
    recursive header file inclusion, resulting in the compiler complaining
    that u_int isn't defined, but only if _POSIX_C_SOURCE is defined, which
 typedef unsigned int u_int;
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef NO_STDIO
-#define APPS_WIN16
-#endif
 #include <openssl/lhash.h>
 #include <openssl/bn.h>
 #define USE_SOCKETS
@@ -165,6 +167,7 @@ static char *s_dcert_file=NULL,*s_dkey_file=NULL;
 static int s_nbio=0;
 #endif
 static int s_nbio_test=0;
+int s_crlf=0;
 static SSL_CTX *ctx=NULL;
 static int www=0;
 
@@ -212,6 +215,7 @@ static void sv_usage(void)
        BIO_printf(bio_err," -nbio         - Run with non-blocking IO\n");
 #endif
        BIO_printf(bio_err," -nbio_test    - test with the non-blocking test bio\n");
+       BIO_printf(bio_err," -crlf         - convert LF from terminal into CRLF\n");
        BIO_printf(bio_err," -debug        - Print more output\n");
        BIO_printf(bio_err," -state        - Print the SSL states\n");
        BIO_printf(bio_err," -CApath arg   - PEM format directory of CA's\n");
@@ -515,6 +519,8 @@ int MAIN(int argc, char *argv[])
                        { hack=1; }
                else if (strcmp(*argv,"-state") == 0)
                        { state=1; }
+               else if (strcmp(*argv,"-crlf") == 0)
+                       { s_crlf=1; }
                else if (strcmp(*argv,"-quiet") == 0)
                        { s_quiet=1; }
                else if (strcmp(*argv,"-bugs") == 0)
@@ -799,7 +805,30 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                if (i <= 0) continue;
                if (FD_ISSET(fileno(stdin),&readfds))
                        {
-                       i=read(fileno(stdin),buf,bufsize);
+                       if (s_crlf)
+                               {
+                               int j, lf_num;
+
+                               i=read(fileno(stdin), buf, bufsize/2);
+                               lf_num = 0;
+                               /* both loops are skipped when i <= 0 */
+                               for (j = 0; j < i; j++)
+                                       if (buf[j] == '\n')
+                                               lf_num++;
+                               for (j = i-1; j >= 0; j--)
+                                       {
+                                       buf[j+lf_num] = buf[j];
+                                       if (buf[j] == '\n')
+                                               {
+                                               lf_num--;
+                                               i++;
+                                               buf[j+lf_num] = '\r';
+                                               }
+                                       }
+                               assert(lf_num == 0);
+                               }
+                       else
+                               i=read(fileno(stdin),buf,bufsize);
                        if (!s_quiet)
                                {
                                if ((i <= 0) || (buf[0] == 'Q'))
@@ -1027,7 +1056,7 @@ static DH *load_dh_param(void)
 
        if ((bio=BIO_new_file(DH_PARAM,"r")) == NULL)
                goto err;
-       ret=PEM_read_bio_DHparams(bio,NULL,NULL);
+       ret=PEM_read_bio_DHparams(bio,NULL,NULL,NULL);
 err:
        if (bio != NULL) BIO_free(bio);
        return(ret);