Bugfix: avoid opening CAfile when it's NULL.
[openssl.git] / apps / s_server.c
index 144dfa662fdc73cd264c46337d13f8a7188ef79c..e54593d5514b17f89002715aec6ef03d22a77278 100644 (file)
@@ -85,6 +85,10 @@ typedef unsigned int u_int;
 #include <openssl/ssl.h>
 #include "s_apps.h"
 
 #include <openssl/ssl.h>
 #include "s_apps.h"
 
+#ifdef WINDOWS
+#include <conio.h>
+#endif
+
 #if (defined(VMS) && __VMS_VER < 70000000)
 /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
 #undef FIONBIO
 #if (defined(VMS) && __VMS_VER < 70000000)
 /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
 #undef FIONBIO
@@ -695,7 +699,8 @@ bad:
        SSL_CTX_set_session_id_context(ctx,(void*)&s_server_session_id_context,
                sizeof s_server_session_id_context);
 
        SSL_CTX_set_session_id_context(ctx,(void*)&s_server_session_id_context,
                sizeof s_server_session_id_context);
 
-       SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));
+       if (CAfile != NULL)
+           SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(CAfile));
 
        BIO_printf(bio_s_out,"ACCEPT\n");
        if (www)
 
        BIO_printf(bio_s_out,"ACCEPT\n");
        if (www)
@@ -748,6 +753,9 @@ static int sv_body(char *hostname, int s, unsigned char *context)
        unsigned long l;
        SSL *con=NULL;
        BIO *sbio;
        unsigned long l;
        SSL *con=NULL;
        BIO *sbio;
+#ifdef WINDOWS
+       struct timeval tv;
+#endif
 
        if ((buf=Malloc(bufsize)) == NULL)
                {
 
        if ((buf=Malloc(bufsize)) == NULL)
                {
@@ -807,9 +815,22 @@ static int sv_body(char *hostname, int s, unsigned char *context)
                 * the compiler: if you do have a cast then you can either
                 * go for (int *) or (void *).
                 */
                 * the compiler: if you do have a cast then you can either
                 * go for (int *) or (void *).
                 */
-               i=select(width,(void *)&readfds,NULL,NULL,NULL);
-               if (i <= 0) continue;
-               if (FD_ISSET(fileno(stdin),&readfds))
+#ifdef WINDOWS
+               /* Under Windows we can't select on stdin: only
+                * on sockets. As a workaround we timeout the select every
+                * second and check for any keypress. In a proper Windows
+                * application we wouldn't do this because it is inefficient.
+                */
+               tv.tv_sec = 1;
+               tv.tv_usec = 0;
+               i=select(width,(void *)&readfds,NULL,NULL,&tv);
+               if((i < 0) || (!i && !_kbhit() ) )continue;
+               if(_kbhit())
+#else
+               i=select(width,(void *)&readfds,NULL,NULL,NULL);
+               if (i <= 0) continue;
+               if (FD_ISSET(fileno(stdin),&readfds))
+#endif
                        {
                        if (s_crlf)
                                {
                        {
                        if (s_crlf)
                                {