Commit 60fdc19cd1d48f3196982dae533c39e8a5830968

Authored by Perry Werneck
1 parent 5fd336a0

Spliting windows/linux ssl context initialization to separated sources.

Makefile.in
... ... @@ -70,8 +70,12 @@ DEPENDS= \
70 70 Makefile \
71 71 src/include/*.h \
72 72 src/include/lib3270/*.h \
73   - src/lib3270/*.h
74   -
  73 + src/lib3270/*.h \
  74 + $(wildcard src/lib3270/*) \
  75 + $(wildcard src/lib3270/@OSNAME@/*) \
  76 + $(wildcard src/lib3270/ssl/*) \
  77 + $(wildcard src/lib3270/ssl/@OSNAME@/*) \
  78 + $(wildcard src/@OSNAME@/*)
75 79  
76 80 #---[ Debug Rules ]----------------------------------------------------------------------
77 81  
... ...
lib3270.cbp
... ... @@ -65,7 +65,6 @@
65 65 <Unit filename="src/include/lib3270.h" />
66 66 <Unit filename="src/include/lib3270/X11keysym.h" />
67 67 <Unit filename="src/include/lib3270/action_table.h" />
68   - <Unit filename="src/include/lib3270/actions.h" />
69 68 <Unit filename="src/include/lib3270/charset.h" />
70 69 <Unit filename="src/include/lib3270/filetransfer.h" />
71 70 <Unit filename="src/include/lib3270/html.h" />
... ... @@ -215,7 +214,7 @@
215 214 <Unit filename="src/lib3270/sf.c">
216 215 <Option compilerVar="CC" />
217 216 </Unit>
218   - <Unit filename="src/lib3270/ssl/ctx_init.c">
  217 + <Unit filename="src/lib3270/ssl/linux/ctx_init.c">
219 218 <Option compilerVar="CC" />
220 219 </Unit>
221 220 <Unit filename="src/lib3270/ssl/negotiate.c">
... ... @@ -224,6 +223,9 @@
224 223 <Unit filename="src/lib3270/ssl/state.c">
225 224 <Option compilerVar="CC" />
226 225 </Unit>
  226 + <Unit filename="src/lib3270/ssl/windows/ctx_init.c">
  227 + <Option compilerVar="CC" />
  228 + </Unit>
227 229 <Unit filename="src/lib3270/state.c">
228 230 <Option compilerVar="CC" />
229 231 </Unit>
... ...
src/lib3270/Makefile.in
... ... @@ -30,8 +30,9 @@ LIBNAME=lib@LIB3270_NAME@
30 30  
31 31 SOURCES= \
32 32 $(wildcard *.c) \
33   - $(wildcard ssl/*.c) \
34 33 $(wildcard @OSNAME@/*.c) \
  34 + $(wildcard ssl/*.c) \
  35 + $(wildcard ssl/@OSNAME@/*.c) \
35 36 $(wildcard @OSNAME@/*.rc) \
36 37 $(BASEDIR)/.tmp/$(LIBNAME)/fallbacks.c
37 38  
... ...
src/lib3270/ansi.c
... ... @@ -29,11 +29,13 @@
29 29 *
30 30 */
31 31  
32   -/*
33   - * ansi.c
34   - * ANSI terminal emulation.
  32 +
  33 +/**
  34 + * @brief ANSI terminal emulation.
35 35 */
36 36  
  37 +#pragma GCC diagnostic ignored "-Wsign-compare"
  38 +
37 39 #include "private.h"
38 40  
39 41 #if defined(X3270_ANSI) /*[*/
... ...
src/lib3270/ctlr.c
... ... @@ -30,13 +30,12 @@
30 30 */
31 31  
32 32 /**
33   - * @file
34   - * This module handles interpretation of the 3270 data stream and
35   - * maintenance of the 3270 device state. It was split out from
36   - * screen.c, which handles X operations.
  33 + * @brief Handles interpretation of the 3270 data stream and maintenance of the 3270 device state.
37 34 *
38 35 */
39 36  
  37 +#pragma GCC diagnostic ignored "-Wsign-compare"
  38 +
40 39 #include "private.h"
41 40 #include <errno.h>
42 41 #include <stdlib.h>
... ... @@ -2648,7 +2647,7 @@ void ctlr_wrapping_memmove(H3270 *hSession, int baddr_to, int baddr_from, int co
2648 2647 }
2649 2648  
2650 2649 /**
2651   - * Copy a block of characters in the 3270 buffer.
  2650 + * @brief Copy a block of characters in the 3270 buffer.
2652 2651 *
2653 2652 * Copy a block of characters in the 3270 buffer, optionally including all of
2654 2653 * the extended attributes. (The character set, which is actually kept in the
... ... @@ -2656,7 +2655,7 @@ void ctlr_wrapping_memmove(H3270 *hSession, int baddr_to, int baddr_from, int co
2656 2655 *
2657 2656 * @param hSession Session handle
2658 2657 */
2659   -void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int move_ea)
  2658 +void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int move_ea unused)
2660 2659 {
2661 2660 /* Move the characters. */
2662 2661 if (memcmp((char *) &hSession->ea_buf[baddr_from],(char *) &hSession->ea_buf[baddr_to],count * sizeof(struct lib3270_ea)))
... ... @@ -2669,12 +2668,12 @@ void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int mo
2669 2668  
2670 2669 #if defined(X3270_ANSI) /*[*/
2671 2670 /**
2672   - * Erase a region of the 3270 buffer, optionally clearing extended attributes as well.
  2671 + * @brief Erase a region of the 3270 buffer, optionally clearing extended attributes as well.
2673 2672 *
2674 2673 * @param hSession Session handle
2675 2674 *
2676 2675 */
2677   -void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea)
  2676 +void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea unused)
2678 2677 {
2679 2678 if (memcmp((char *) &hSession->ea_buf[baddr], (char *) hSession->zero_buf,
2680 2679 count * sizeof(struct lib3270_ea))) {
... ...
src/lib3270/ft.c
... ... @@ -29,6 +29,8 @@
29 29 *
30 30 */
31 31  
  32 +#pragma GCC diagnostic ignored "-Wsign-compare"
  33 +
32 34 #ifdef WIN32
33 35 #include <winsock2.h>
34 36 #include <windows.h>
... ...
src/lib3270/host.c
... ... @@ -31,13 +31,12 @@
31 31 */
32 32  
33 33  
34   -/*
35   - * host.c
36   - * This module handles the ibm_hosts file, connecting to and
37   - * disconnecting from hosts, and state changes on the host
38   - * connection.
  34 +/**
  35 + * @brief Handle connect and disconnect from hosts, and state changes on the host connection.
39 36 */
40 37  
  38 +#pragma GCC diagnostic ignored "-Wsign-compare"
  39 +
41 40 #include <malloc.h>
42 41 #include "private.h"
43 42 // #include "appres.h"
... ...
src/lib3270/html.c
... ... @@ -124,9 +124,9 @@
124 124  
125 125 static void append_string(struct html_info *info, const char *text)
126 126 {
127   - int sz = strlen(info->text)+strlen(text);
  127 + size_t sz = strlen(info->text)+strlen(text);
128 128  
129   - if(strlen(info->text)+sz <= info->szText)
  129 + if(strlen(info->text)+sz <= ((size_t)info->szText) )
130 130 {
131 131 info->szText += (100+sz);
132 132 info->text = lib3270_realloc(info->text,info->szText);
... ...
src/lib3270/iocalls.c
... ... @@ -228,7 +228,7 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo
228 228 ip->userdata = userdata;
229 229 ip->call = call;
230 230  
231   - ip->next = session->inputs;
  231 + ip->next = (input_t *) session->inputs;
232 232  
233 233 session->inputs = ip;
234 234 session->inputs_changed = 1;
... ... @@ -267,17 +267,16 @@ static void internal_remove_poll(H3270 *session, void *id)
267 267 static void internal_set_poll_state(H3270 *session, void *id, int enabled)
268 268 {
269 269 input_t *ip;
270   - input_t *prev = (input_t *)NULL;
271 270  
272 271 for (ip = session->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next)
273 272 {
274 273 if (ip == (input_t *)id)
275 274 {
276 275 ip->enabled = enabled ? 1 : 0;
  276 + session->inputs_changed = 1;
277 277 break;
278 278 }
279 279  
280   - prev = ip;
281 280 }
282 281  
283 282 }
... ... @@ -318,7 +317,7 @@ LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_F
318 317  
319 318 input_t *ip;
320 319  
321   - for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next)
  320 + for (ip = session->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next)
322 321 {
323 322 if(ip->fd == fd)
324 323 {
... ...
src/lib3270/kybd.c
... ... @@ -33,6 +33,9 @@
33 33 * @brief This module handles the keyboard for the 3270 emulator.
34 34 */
35 35  
  36 +#pragma GCC diagnostic ignored "-Wsign-compare"
  37 +
  38 +
36 39 struct ta;
37 40  
38 41 #define LIB3270_TA struct ta
... ...
src/lib3270/linux/connect.c
... ... @@ -252,7 +252,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
252 252 lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);
253 253  
254 254 // s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
255   - if(lib3270_run_task(hSession, background_connect, &host))
  255 + if(lib3270_run_task(hSession, background_connect, &host) || hSession->sock < 0)
256 256 {
257 257 char buffer[4096];
258 258 snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
... ... @@ -265,7 +265,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
265 265 host.message);
266 266  
267 267 lib3270_set_disconnected(hSession);
268   - return errno = ENOENT;
  268 + return errno = ENOTCONN;
269 269 }
270 270  
271 271 /* don't share the socket with our children */
... ... @@ -291,26 +291,6 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
291 291 #endif // HAVE_LIBSSL
292 292 }
293 293  
294   - /* connect */
295   - if(hSession->sock < 0)
296   - {
297   - lib3270_set_disconnected(hSession);
298   -
299   - char buffer[4096];
300   - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
301   -
302   - lib3270_popup_dialog(
303   - hSession,
304   - LIB3270_NOTIFY_ERROR,
305   - _( "Connection error" ),
306   - buffer,
307   - "%s",
308   - host.message
309   - );
310   -
311   - return errno = ENOTCONN;
312   - }
313   -
314 294 // set options for inline out-of-band data and keepalives
315 295 optval = 1;
316 296 if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0)
... ... @@ -322,6 +302,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
322 302 "%s",
323 303 strerror(errno));
324 304 SOCK_CLOSE(hSession);
  305 + return errno = ENOTCONN;
325 306 }
326 307  
327 308 optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0;
... ... @@ -337,6 +318,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
337 318 "%s",
338 319 strerror(errno));
339 320 SOCK_CLOSE(hSession);
  321 + return errno = ENOTCONN;
340 322 }
341 323 else
342 324 {
... ...
src/lib3270/private.h
... ... @@ -282,7 +282,7 @@ typedef struct timeout
282 282 typedef struct _input_t
283 283 {
284 284 unsigned char enabled;
285   - struct input * next;
  285 + struct _input_t * next;
286 286 H3270 * session;
287 287 int fd;
288 288 LIB3270_IO_FLAG flag;
... ...
src/lib3270/rpq.c
... ... @@ -30,9 +30,10 @@
30 30 *
31 31 */
32 32  
33   -/*
34   - * rpq.c
35   - * RPQNAMES structured field support.
  33 + #pragma GCC diagnostic ignored "-Wsign-compare"
  34 +
  35 +/**
  36 + * @brief RPQNAMES structured field support.
36 37 *
37 38 */
38 39  
... ...
src/lib3270/ssl/ctx_init.c
... ... @@ -1,186 +0,0 @@
1   -/*
2   - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270.
5   - *
6   - * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
8   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10   - * Free Software Foundation.
11   - *
12   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15   - * obter mais detalhes.
16   - *
17   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como ssl.c e possui - linhas de código.
22   - *
23   - * Contatos:
24   - *
25   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26   - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27   - * licinio@bb.com.br (Licínio Luis Branco)
28   - * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29   - *
30   - *
31   - * References:
32   - *
33   - * http://www.openssl.org/docs/ssl/
34   - *
35   - */
36   -
37   -/**
38   - * @brief OpenSSL initialization.
39   - *
40   - */
41   -
42   -#include <config.h>
43   -#if defined(HAVE_LIBSSL)
44   -
45   -#include <openssl/ssl.h>
46   -#include <openssl/err.h>
47   -#include <openssl/x509_vfy.h>
48   -
49   -#ifndef SSL_ST_OK
50   - #define SSL_ST_OK 3
51   -#endif // !SSL_ST_OK
52   -
53   -#include "../private.h"
54   -#include <errno.h>
55   -#include <lib3270.h>
56   -#include <lib3270/internals.h>
57   -#include <lib3270/trace.h>
58   -#include "trace_dsc.h"
59   -
60   -/*--[ Implement ]------------------------------------------------------------------------------------*/
61   -
62   -/**
63   - * @brief Initialize openssl library.
64   - *
65   - * @return 0 if ok, non zero if fails.
66   - *
67   - */
68   -int ssl_ctx_init(H3270 *hSession)
69   -{
70   - debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx);
71   -
72   - if(!ssl_ctx)
73   - {
74   - trace_dsn(hSession,"Initializing SSL context.\n");
75   -
76   - SSL_load_error_strings();
77   - SSL_library_init();
78   -
79   - ssl_ctx = SSL_CTX_new(SSLv23_method());
80   - if(ssl_ctx == NULL)
81   - return -1;
82   -
83   - SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
84   - SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback);
85   - SSL_CTX_set_default_verify_paths(ssl_ctx);
86   -
87   -#if defined(_WIN32)
88   - {
89   - HKEY hKey = 0;
90   -
91   - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\" PACKAGE_NAME,0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
92   - {
93   - char data[4096];
94   - unsigned long datalen = sizeof(data); // data field length(in), data returned length(out)
95   - unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
96   -
97   - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS)
98   - {
99   - strncat(data,"\\certs",4095);
100   -
101   - if(!SSL_CTX_load_verify_locations(ssl_ctx,NULL,data))
102   - {
103   - hSession->ssl.error = ERR_get_error();
104   -
105   - trace_dsn(
106   - hSession,
107   - "Cant set default locations for trusted CA certificates to %s\n%s\m"
108   - data,
109   - ERR_lib_error_string(hSession->ssl.error)
110   - );
111   -
112   - lib3270_write_log(
113   - hSession,
114   - "ssl",
115   - "Cant set default locations for trusted CA certificates to %s\n%s",
116   - data,
117   - ERR_lib_error_string(hSession->ssl.error)
118   - );
119   -
120   - }
121   - }
122   - RegCloseKey(hKey);
123   - }
124   -
125   -
126   - }
127   -#else
128   -
129   - static const char * ssldir[] =
130   - {
131   -#ifdef DATAROOTDIR
132   - DATAROOTDIR "/" PACKAGE_NAME "/certs",
133   -#endif // DATAROOTDIR
134   -#ifdef SYSCONFDIR
135   - SYSCONFDIR "/ssl/certs",
136   - SYSCONFDIR "/certs",
137   -#endif
138   - "/etc/ssl/certs"
139   - };
140   -
141   - size_t f;
142   -
143   - for(f = 0;f < sizeof(ssldir) / sizeof(ssldir[0]);f++)
144   - {
145   - SSL_CTX_load_verify_locations(ssl_ctx,NULL,ssldir[f]);
146   - }
147   -
148   - #endif // _WIN32
149   -
150   - //
151   - // Initialize CUSTOM CRL CHECK
152   - //
153   -
154   - }
155   -
156   -
157   -
158   -/*
159   -#if defined(SSL_ENABLE_CRL_CHECK)
160   - // Set up CRL validation
161   - // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now
162   - X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
163   -
164   - // Enable CRL checking
165   - X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
166   - X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
167   - X509_STORE_set1_param(store, param);
168   - X509_VERIFY_PARAM_free(param);
169   -
170   - // X509_STORE_free(store);
171   -
172   - trace_dsn(hSession,"CRL CHECK is enabled.\n");
173   -
174   -#else
175   -
176   - trace_dsn(hSession,"CRL CHECK is disabled.\n");
177   -
178   -#endif // SSL_ENABLE_CRL_CHECK
179   -*/
180   -
181   - ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL);
182   -
183   - return 0;
184   -}
185   -
186   -#endif // HAVE_LIBSSL
src/lib3270/ssl/linux/ctx_init.c 0 → 100644
... ... @@ -0,0 +1,162 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + *
  29 + * References:
  30 + *
  31 + * http://www.openssl.org/docs/ssl/
  32 + * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now
  33 + *
  34 + */
  35 +
  36 +/**
  37 + * @brief OpenSSL initialization for linux.
  38 + *
  39 + */
  40 +
  41 +#include <config.h>
  42 +#if defined(HAVE_LIBSSL)
  43 +
  44 +#include <openssl/ssl.h>
  45 +#include <openssl/err.h>
  46 +#include <openssl/x509_vfy.h>
  47 +
  48 +#ifndef SSL_ST_OK
  49 + #define SSL_ST_OK 3
  50 +#endif // !SSL_ST_OK
  51 +
  52 +#include "../../private.h"
  53 +#include <errno.h>
  54 +#include <lib3270.h>
  55 +#include <lib3270/internals.h>
  56 +#include <lib3270/trace.h>
  57 +#include "trace_dsc.h"
  58 +
  59 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  60 +
  61 +/**
  62 + * @brief Initialize openssl library.
  63 + *
  64 + * @return 0 if ok, non zero if fails.
  65 + *
  66 + */
  67 +int ssl_ctx_init(H3270 *hSession)
  68 +{
  69 + debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx);
  70 +
  71 + if(ssl_ctx)
  72 + return 0;
  73 +
  74 + trace_dsn(hSession,"Initializing SSL context.\n");
  75 +
  76 + SSL_load_error_strings();
  77 + SSL_library_init();
  78 +
  79 + ssl_ctx = SSL_CTX_new(SSLv23_method());
  80 + if(ssl_ctx == NULL)
  81 + return -1;
  82 +
  83 + SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
  84 + SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback);
  85 +
  86 + SSL_CTX_set_default_verify_paths(ssl_ctx);
  87 +
  88 + /*
  89 + static const char * ssldir[] =
  90 + {
  91 +#ifdef DATAROOTDIR
  92 + DATAROOTDIR "/" PACKAGE_NAME "/certs",
  93 +#endif // DATAROOTDIR
  94 +#ifdef SYSCONFDIR
  95 + SYSCONFDIR "/ssl/certs",
  96 + SYSCONFDIR "/certs",
  97 +#endif
  98 + "/etc/ssl/certs"
  99 + };
  100 +
  101 + size_t f;
  102 +
  103 + for(f = 0;f < sizeof(ssldir) / sizeof(ssldir[0]);f++)
  104 + {
  105 + SSL_CTX_load_verify_locations(ssl_ctx,NULL,ssldir[f]);
  106 + }
  107 + */
  108 +
  109 + ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL);
  110 +
  111 + //
  112 + // Initialize CUSTOM CRL CHECK
  113 + //
  114 +
  115 +
  116 + return 0;
  117 +}
  118 +
  119 +#endif // HAVE_LIBSSL
  120 +
  121 +/*
  122 +// Load CRLs into the `X509_STORE`
  123 +
  124 +X509_STORE *x509_store = SSL_CTX_get_cert_store(ctx);
  125 +X509_STORE_add_crl(x509_store, crl);
  126 +
  127 +// Enable CRL checking
  128 +X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
  129 +X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
  130 +SSL_CTX_set1_param(ctx, param);
  131 +X509_VERIFY_PARAM_free(param);
  132 +
  133 +
  134 +
  135 + }
  136 +
  137 +
  138 +
  139 +
  140 +#if defined(SSL_ENABLE_CRL_CHECK)
  141 + // Set up CRL validation
  142 + // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now
  143 + X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
  144 +
  145 + // Enable CRL checking
  146 + X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
  147 + X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
  148 + X509_STORE_set1_param(store, param);
  149 + X509_VERIFY_PARAM_free(param);
  150 +
  151 + // X509_STORE_free(store);
  152 +
  153 + trace_dsn(hSession,"CRL CHECK is enabled.\n");
  154 +
  155 +#else
  156 +
  157 + trace_dsn(hSession,"CRL CHECK is disabled.\n");
  158 +
  159 +#endif // SSL_ENABLE_CRL_CHECK
  160 +
  161 +*/
  162 +
... ...
src/lib3270/ssl/windows/ctx_init.c 0 → 100644
... ... @@ -0,0 +1,176 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + *
  29 + * References:
  30 + *
  31 + * http://www.openssl.org/docs/ssl/
  32 + * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now
  33 + *
  34 + */
  35 +
  36 +/**
  37 + * @brief OpenSSL initialization for windows.
  38 + *
  39 + */
  40 +
  41 +#include <config.h>
  42 +#if defined(HAVE_LIBSSL)
  43 +#include <openssl/ssl.h>
  44 +#include <openssl/err.h>
  45 +#include <openssl/x509_vfy.h>
  46 +
  47 +#ifndef SSL_ST_OK
  48 + #define SSL_ST_OK 3
  49 +#endif // !SSL_ST_OK
  50 +
  51 +#include "../../private.h"
  52 +#include <errno.h>
  53 +#include <lib3270.h>
  54 +#include <lib3270/internals.h>
  55 +#include <lib3270/trace.h>
  56 +#include "trace_dsc.h"
  57 +
  58 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  59 +
  60 +/**
  61 + * @brief Initialize openssl library.
  62 + *
  63 + * @return 0 if ok, non zero if fails.
  64 + *
  65 + */
  66 +int ssl_ctx_init(H3270 *hSession)
  67 +{
  68 + debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx);
  69 +
  70 + if(ssl_ctx)
  71 + return 0;
  72 +
  73 + trace_dsn(hSession,"Initializing SSL context.\n");
  74 +
  75 + SSL_load_error_strings();
  76 + SSL_library_init();
  77 +
  78 + ssl_ctx = SSL_CTX_new(SSLv23_method());
  79 + if(ssl_ctx == NULL)
  80 + return -1;
  81 +
  82 + SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
  83 + SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback);
  84 + SSL_CTX_set_default_verify_paths(ssl_ctx);
  85 +
  86 + //
  87 + // Get path from windows registry.
  88 + //
  89 + HKEY hKey = 0;
  90 +
  91 + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\" PACKAGE_NAME,0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS)
  92 + {
  93 + char data[4096];
  94 + unsigned long datalen = sizeof(data); // data field length(in), data returned length(out)
  95 + unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
  96 +
  97 + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS)
  98 + {
  99 + strncat(data,"\\certs",4095);
  100 +
  101 + if(!SSL_CTX_load_verify_locations(ssl_ctx,NULL,data))
  102 + {
  103 + hSession->ssl.error = ERR_get_error();
  104 +
  105 + trace_dsn(
  106 + hSession,
  107 + "Cant set default locations for trusted CA certificates to %s\n%s\m"
  108 + data,
  109 + ERR_lib_error_string(hSession->ssl.error)
  110 + );
  111 +
  112 + lib3270_write_log(
  113 + hSession,
  114 + "ssl",
  115 + "Cant set default locations for trusted CA certificates to %s\n%s",
  116 + data,
  117 + ERR_lib_error_string(hSession->ssl.error)
  118 + );
  119 +
  120 + }
  121 + }
  122 + RegCloseKey(hKey);
  123 + }
  124 +
  125 + ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL);
  126 +
  127 + //
  128 + // Initialize CUSTOM CRL CHECK
  129 + //
  130 +
  131 + return 0;
  132 +}
  133 +
  134 +#endif // HAVE_LIBSSL
  135 +
  136 +/*
  137 +// Load CRLs into the `X509_STORE`
  138 +
  139 +X509_STORE *x509_store = SSL_CTX_get_cert_store(ctx);
  140 +X509_STORE_add_crl(x509_store, crl);
  141 +
  142 +// Enable CRL checking
  143 +X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
  144 +X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
  145 +SSL_CTX_set1_param(ctx, param);
  146 +X509_VERIFY_PARAM_free(param);
  147 +
  148 +
  149 +
  150 + }
  151 +
  152 +
  153 +
  154 +/*
  155 +#if defined(SSL_ENABLE_CRL_CHECK)
  156 + // Set up CRL validation
  157 + // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now
  158 + X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
  159 +
  160 + // Enable CRL checking
  161 + X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
  162 + X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
  163 + X509_STORE_set1_param(store, param);
  164 + X509_VERIFY_PARAM_free(param);
  165 +
  166 + // X509_STORE_free(store);
  167 +
  168 + trace_dsn(hSession,"CRL CHECK is enabled.\n");
  169 +
  170 +#else
  171 +
  172 + trace_dsn(hSession,"CRL CHECK is disabled.\n");
  173 +
  174 +#endif // SSL_ENABLE_CRL_CHECK
  175 +*/
  176 +
... ...
src/lib3270/telnet.c
... ... @@ -29,11 +29,11 @@
29 29 *
30 30 */
31 31  
  32 + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
32 33  
33   -/*
34   - * telnet.c
35   - * This module initializes and manages a telnet socket to
36   - * the given IBM host.
  34 +
  35 +/**
  36 + * @brief Initializes and manages a telnet socket to the given IBM host.
37 37 */
38 38  
39 39 #if defined(_WIN32)
... ... @@ -340,16 +340,25 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...)
340 340 text = lib3270_vsprintf(fmt, args);
341 341 va_end(args);
342 342  
343   - lib3270_write_log(hSession, "3270", "Network error:\n%s\n%s",text,msg);
344   -
345   - lib3270_popup_dialog( hSession,
346   - LIB3270_NOTIFY_ERROR,
347   - _( "Network error" ),
348   - text,
349   - "%s", msg);
350   -
  343 + lib3270_write_log(
  344 + hSession,
  345 + "3270",
  346 + "Network error:\n%s\n%s",
  347 + text,
  348 + msg
  349 + );
  350 +
  351 + lib3270_popup_dialog(
  352 + hSession,
  353 + LIB3270_NOTIFY_ERROR,
  354 + _( "Network error" ),
  355 + text,
  356 + "%s",
  357 + msg
  358 + );
351 359  
352 360 lib3270_free(text);
  361 +
353 362 }
354 363  
355 364 /*
... ...
src/lib3270/windows/connect.c
... ... @@ -29,50 +29,32 @@
29 29  
30 30 #include <config.h>
31 31  
32   -#if defined(_WIN32)
  32 +// Compiling for WinXP or later: Expose getaddrinfo()/freeaddrinfo().
  33 +#undef _WIN32_WINNT
  34 +#define _WIN32_WINNT 0x0501
33 35  
34   - // Compiling for WinXP or later: Expose getaddrinfo()/freeaddrinfo().
35   - #undef _WIN32_WINNT
36   - #define _WIN32_WINNT 0x0501
37   -
38   - #include <winsock2.h>
39   - #include <windows.h>
40   - #include <ws2tcpip.h>
41   -
42   -#endif
  36 +#include <winsock2.h>
  37 +#include <windows.h>
  38 +#include <ws2tcpip.h>
43 39  
44 40 #include "private.h"
45 41 #include <errno.h>
46 42  
47   -#if defined(_WIN32)
48   - #include <ws2tcpip.h>
49   -#else
50   - #include <sys/types.h>
51   - #include <sys/socket.h>
52   - #include <sys/ioctl.h>
53   - #include <netinet/in.h>
54   - #include <netdb.h>
55   - #include <unistd.h>
56   - #include <fcntl.h>
57   -#endif
  43 +#include <ws2tcpip.h>
58 44  
59 45 #ifdef HAVE_ICONV
60 46 #include <iconv.h>
61 47 #endif // HAVE_ICONV
62 48  
63   -#if defined(_WIN32) /*[*/
64   - #define SOCK_CLOSE(s) closesocket(s->sock); s->sock = -1;
65   -#else /*][*/
66   - #define SOCK_CLOSE(s) close(s->sock); s->sock = -1;
67   -#endif /*]*/
  49 +#define SOCK_CLOSE(s) closesocket(s->sock); s->sock = -1;
68 50  
69   -#include <stdlib.h>
70   -#include "statusc.h"
  51 +//#include "statusc.h"
71 52 #include "hostc.h"
72 53 #include "trace_dsc.h"
73   -#include "utilc.h"
  54 +//#include "utilc.h"
74 55 #include "telnetc.h"
75 56 #include "screen.h"
  57 +
76 58 #include <lib3270/internals.h>
77 59  
78 60 /*---[ Implement ]-------------------------------------------------------------------------------*/
... ... @@ -97,11 +79,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
97 79 LIB3270_NOTIFY_ERROR,
98 80 _( "Network error" ),
99 81 _( "Unable to get connection state." ),
100   -#ifdef _WIN32
101 82 "%s", lib3270_win32_strerror(WSAGetLastError())
102   -#else
103   - _( "%s" ), strerror(errno)
104   -#endif // _WIN32
105 83 );
106 84 return;
107 85 }
... ... @@ -115,11 +93,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
115 93 LIB3270_NOTIFY_ERROR,
116 94 _( "Connection failed" ),
117 95 buffer,
118   -#ifdef _WIN32
119 96 _( "%s"), lib3270_win32_strerror(err)
120   -#else
121   - _( "%s" ), strerror(err)
122   -#endif // _WIN32
123 97 );
124 98 trace("%s",__FUNCTION__);
125 99 return;
... ... @@ -141,11 +115,8 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
141 115  
142 116 }
143 117  
144   -
145   -#if defined(_WIN32)
146   -
147   - static void sockstart(H3270 *session)
148   - {
  118 +static void sockstart(H3270 *session)
  119 +{
149 120 static int initted = 0;
150 121 WORD wVersionRequested;
151 122 WSADATA wsaData;
... ... @@ -177,11 +148,10 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
177 148 N_( "Can't use winsock version %d.%d" ), LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
178 149 _exit(1);
179 150 }
180   - }
181   -#endif // WIN32
  151 +}
182 152  
183   - LIB3270_EXPORT int lib3270_connect_url(H3270 *hSession, const char *url, int wait)
184   - {
  153 +LIB3270_EXPORT int lib3270_connect_url(H3270 *hSession, const char *url, int wait)
  154 +{
185 155 CHECK_SESSION_HANDLE(hSession);
186 156  
187 157 if(url && *url)
... ... @@ -191,10 +161,10 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
191 161  
192 162 return lib3270_connect(hSession, wait);
193 163  
194   - }
  164 +}
195 165  
196   - LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt)
197   - {
  166 +LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt)
  167 +{
198 168 CHECK_SESSION_HANDLE(hSession);
199 169  
200 170 if(!hostname)
... ... @@ -235,10 +205,63 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
235 205  
236 206 return lib3270_connect(hSession,opt & LIB3270_OPTION_WAIT);
237 207  
238   - }
  208 +}
  209 +
  210 + struct resolver
  211 + {
  212 + int convert;
  213 + const char * message;
  214 + };
239 215  
240   - int lib3270_connect(H3270 *hSession, int seconds)
  216 + static int background_connect(H3270 *hSession, void *host)
241 217 {
  218 + struct addrinfo hints;
  219 + struct addrinfo * result = NULL;
  220 + struct addrinfo * rp = NULL;
  221 +
  222 + memset(&hints,0,sizeof(hints));
  223 + hints.ai_family = AF_UNSPEC; // Allow IPv4 or IPv6
  224 + hints.ai_socktype = SOCK_STREAM; // Stream socket
  225 + hints.ai_flags = AI_PASSIVE; // For wildcard IP address
  226 + hints.ai_protocol = 0; // Any protocol
  227 +
  228 + int rc = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
  229 + if(rc != 0)
  230 + {
  231 + ((struct resolver *) host)->message = gai_strerror(rc);
  232 + ((struct resolver *) host)->convert = 1;
  233 + return -1;
  234 + }
  235 +
  236 + status_connecting(hSession,1);
  237 +
  238 + for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next)
  239 + {
  240 + hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  241 + if(hSession->sock < 0)
  242 + {
  243 + ((struct resolver *) host)->message = strerror(errno);
  244 + continue;
  245 + }
  246 +
  247 + // Connected!
  248 + if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen))
  249 + {
  250 + SOCK_CLOSE(hSession);
  251 + ((struct resolver *) host)->message = strerror(errno);
  252 + continue;
  253 + }
  254 +
  255 + }
  256 +
  257 + freeaddrinfo(result);
  258 +
  259 + return 0;
  260 +
  261 +}
  262 +
  263 +int lib3270_connect(H3270 *hSession, int seconds)
  264 +{
242 265 int s;
243 266 int optval;
244 267 struct addrinfo hints;
... ... @@ -255,9 +278,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
255 278 if(hSession->sock > 0)
256 279 return errno = EBUSY;
257 280  
258   -#if defined(_WIN32)
259 281 sockstart(hSession);
260   -#endif
261 282  
262 283 #if defined(HAVE_LIBSSL)
263 284 set_ssl_state(hSession,LIB3270_SSL_UNSECURE);
... ... @@ -266,72 +287,47 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
266 287 snprintf(hSession->full_model_name,LIB3270_FULL_MODEL_NAME_LENGTH,"IBM-327%c-%d",hSession->m3279 ? '9' : '8', hSession->model_num);
267 288  
268 289 hSession->ever_3270 = False;
269   -
270   - memset(&hints, 0, sizeof(struct addrinfo));
271   - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
272   - hints.ai_socktype = SOCK_STREAM; /* Stream socket */
273   - hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
274   - hints.ai_protocol = 0; /* Any protocol */
275   - hints.ai_canonname = NULL;
276   - hints.ai_addr = NULL;
277   - hints.ai_next = NULL;
278   -
279 290 hSession->cstate = LIB3270_RESOLVING;
280   - lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);
281 291  
282   - s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
  292 + lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True);
283 293  
284   - if(s != 0)
  294 + // s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result);
  295 + if(lib3270_run_task(hSession, background_connect, &host) || hSession->sock < 0)
285 296 {
286 297 char buffer[4096];
  298 + char msg[4096];
287 299  
288 300 snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
289 301  
290   -#if defined(WIN32) && defined(HAVE_ICONV)
  302 + strncpy(msg,host.message,4095);
  303 +
  304 +#ifdef HAVE_ICONV
  305 + if(host.convert)
291 306 {
292   - char tmpbuffer[4096];
293   - const char * msg = gai_strerror(s);
294   - size_t in = strlen(msg);
295   - size_t out = 4096;
296   - char * ptr = tmpbuffer;
  307 + char * ptr = msg;
  308 + size_t out = 4096;
297 309  
298 310 iconv_t hConv = iconv_open(lib3270_win32_local_charset(),"UTF-8");
299   -
300   - trace("Antes: [%s]",msg);
301   - if(iconv(hConv,&msg,&in,&ptr,&out) != ((size_t) -1))
302   - msg = tmpbuffer;
303   - trace("Depois: [%s]",msg);
304   -
  311 + if(iconv(hConv,&host.message,&in,&ptr,&out) == ((size_t) -1))
  312 + {
  313 + strncpy(msg,host.message,4095);
  314 + }
305 315 iconv_close(hConv);
306 316  
307   - lib3270_popup_dialog( hSession,
308   - LIB3270_NOTIFY_ERROR,
309   - _( "Connection error" ),
310   - buffer,
311   - "%s",
312   - msg);
313 317 }
  318 +#endif // HAVE_ICONV
314 319  
315   -#else
316 320 lib3270_popup_dialog( hSession,
317 321 LIB3270_NOTIFY_ERROR,
318 322 _( "Connection error" ),
319 323 buffer,
320 324 "%s",
321   - gai_strerror(s));
322   -#endif // WIN32
323   -
  325 + msg);
324 326  
325 327 lib3270_set_disconnected(hSession);
326   - return errno = ENOENT;
  328 + return errno = ENOTCONN;
327 329 }
328 330  
329   -
330   -#if !defined(_WIN32)
331   - /* don't share the socket with our children */
332   - (void) fcntl(hSession->sock, F_SETFD, 1);
333   -#endif
334   -
335 331 hSession->ever_3270 = False;
336 332 hSession->ssl.host = 0;
337 333  
... ... @@ -353,141 +349,40 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
353 349 }
354 350  
355 351 /* connect */
356   - status_connecting(hSession,1);
357   -
358   - for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next)
359   - {
360   - hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
361   - if(hSession->sock < 0)
362   - continue;
363   -
364   - trace("sock=%d",hSession->sock);
365   -
366   -#ifdef WIN32
367 352  
368   - WSASetLastError(0);
369   - u_long iMode=1;
370   - trace("sock=%d",hSession->sock);
  353 + WSASetLastError(0);
  354 + u_long iMode=1;
371 355  
372   - optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0;
373   - if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
374   - {
375   - char buffer[4096];
376   - snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
377   -
378   - lib3270_popup_dialog( hSession,
379   - LIB3270_NOTIFY_ERROR,
380   - _( "Connection error" ),
381   - buffer,
382   - "%s", lib3270_win32_strerror(WSAGetLastError()));
383   - SOCK_CLOSE(hSession);
384   - continue;
385   - }
386   - else
387   - {
388   - trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" );
389   - }
390   -
391   - if(ioctlsocket(hSession->sock,FIONBIO,&iMode))
392   - {
393   - lib3270_popup_dialog( hSession,
394   - LIB3270_NOTIFY_ERROR,
395   - _( "Connection error" ),
396   - _( "ioctlsocket(FIONBIO) failed." ),
397   - "%s", lib3270_win32_strerror(WSAGetLastError()));
398   - SOCK_CLOSE(hSession);
399   - continue;
400   - }
401   - else if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen))
402   - {
403   - int err = WSAGetLastError();
404   - if(err != WSAEWOULDBLOCK)
405   - {
406   - char buffer[4096];
407   - snprintf(buffer,4095,_( "Can't connect to %s"), lib3270_get_host(hSession));
408   -
409   - lib3270_popup_dialog( hSession,
410   - LIB3270_NOTIFY_ERROR,
411   - _( "Connection error" ),
412   - buffer,
413   - "%s", lib3270_win32_strerror(err));
414   - SOCK_CLOSE(hSession);
415   - continue;
416   -
417   - }
418   - }
419   -
420   - optval = 1;
421   - if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0)
422   - {
423   - lib3270_popup_dialog( hSession,
424   - LIB3270_NOTIFY_ERROR,
425   - _( "Connection error" ),
426   - _( "setsockopt(SO_OOBINLINE) has failed" ),
427   - "%s", lib3270_win32_strerror(WSAGetLastError()));
428   - SOCK_CLOSE(hSession);
429   - continue;
430   - }
431   -
432   -#else
433   - fcntl(hSession->sock, F_SETFL,fcntl(hSession->sock,F_GETFL,0)|O_NONBLOCK);
434   -
435   - errno = 0;
436   - if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen))
437   - {
438   - if( errno != EINPROGRESS )
439   - {
440   - char buffer[4096];
441   - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc);
442   -
443   - lib3270_popup_dialog( hSession,
444   - LIB3270_NOTIFY_ERROR,
445   - _( "Connection error" ),
446   - buffer,
447   - "%s",
448   - strerror(errno));
449   - SOCK_CLOSE(hSession);
450   - continue;
451   - }
452   - }
453   -
454   - optval = 1;
455   - if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0)
456   - {
457   - lib3270_popup_dialog( hSession,
458   - LIB3270_NOTIFY_ERROR,
459   - _( "Connection error" ),
460   - _( "setsockopt(SO_OOBINLINE) has failed" ),
461   - "%s",
462   - strerror(errno));
463   - SOCK_CLOSE(hSession);
464   - continue;
465   - }
466   -
467   - optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0;
468   - if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
469   - {
470   - char buffer[4096];
471   - snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
472   -
473   - lib3270_popup_dialog( hSession,
474   - LIB3270_NOTIFY_ERROR,
475   - _( "Connection error" ),
476   - buffer,
477   - "%s",
478   - strerror(errno));
479   - SOCK_CLOSE(hSession);
480   - continue;
481   - }
482   - else
483   - {
484   - trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" );
485   - }
  356 + optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0;
  357 + if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
  358 + {
  359 + char buffer[4096];
  360 + snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
486 361  
487   -#endif // WIN32
  362 + lib3270_popup_dialog( hSession,
  363 + LIB3270_NOTIFY_ERROR,
  364 + _( "Connection error" ),
  365 + buffer,
  366 + "%s", lib3270_win32_strerror(WSAGetLastError()));
  367 + SOCK_CLOSE(hSession);
  368 + return errno = ENOTCONN;
  369 + }
  370 + else
  371 + {
  372 + trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" );
488 373 }
489 374  
490   - freeaddrinfo(result);
  375 + optval = 1;
  376 + if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0)
  377 + {
  378 + lib3270_popup_dialog( hSession,
  379 + LIB3270_NOTIFY_ERROR,
  380 + _( "Connection error" ),
  381 + _( "setsockopt(SO_OOBINLINE) has failed" ),
  382 + "%s", lib3270_win32_strerror(WSAGetLastError()));
  383 + SOCK_CLOSE(hSession);
  384 + return errno = ENOTCONN;
  385 + }
491 386  
492 387 // set options for inline out-of-band data and keepalives
493 388  
... ... @@ -502,12 +397,6 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u
502 397  
503 398 */
504 399  
505   - if(hSession->sock < 0)
506   - {
507   - lib3270_set_disconnected(hSession);
508   - return errno = ENOTCONN;
509   - }
510   -
511 400 // Connecting, set callbacks, wait for connection
512 401 hSession->cstate = LIB3270_PENDING;
513 402 lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True);
... ...