diff --git a/Makefile.in b/Makefile.in index f710f8e..4b14d78 100644 --- a/Makefile.in +++ b/Makefile.in @@ -70,8 +70,12 @@ DEPENDS= \ Makefile \ src/include/*.h \ src/include/lib3270/*.h \ - src/lib3270/*.h - + src/lib3270/*.h \ + $(wildcard src/lib3270/*) \ + $(wildcard src/lib3270/@OSNAME@/*) \ + $(wildcard src/lib3270/ssl/*) \ + $(wildcard src/lib3270/ssl/@OSNAME@/*) \ + $(wildcard src/@OSNAME@/*) #---[ Debug Rules ]---------------------------------------------------------------------- diff --git a/lib3270.cbp b/lib3270.cbp index 50ee724..f995b31 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -65,7 +65,6 @@ - @@ -215,7 +214,7 @@ - + @@ -224,6 +223,9 @@ + + diff --git a/src/lib3270/Makefile.in b/src/lib3270/Makefile.in index 5f47558..e5ede28 100644 --- a/src/lib3270/Makefile.in +++ b/src/lib3270/Makefile.in @@ -30,8 +30,9 @@ LIBNAME=lib@LIB3270_NAME@ SOURCES= \ $(wildcard *.c) \ - $(wildcard ssl/*.c) \ $(wildcard @OSNAME@/*.c) \ + $(wildcard ssl/*.c) \ + $(wildcard ssl/@OSNAME@/*.c) \ $(wildcard @OSNAME@/*.rc) \ $(BASEDIR)/.tmp/$(LIBNAME)/fallbacks.c diff --git a/src/lib3270/ansi.c b/src/lib3270/ansi.c index 479e8b1..901389d 100644 --- a/src/lib3270/ansi.c +++ b/src/lib3270/ansi.c @@ -29,11 +29,13 @@ * */ -/* - * ansi.c - * ANSI terminal emulation. + +/** + * @brief ANSI terminal emulation. */ +#pragma GCC diagnostic ignored "-Wsign-compare" + #include "private.h" #if defined(X3270_ANSI) /*[*/ diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 8d91aab..4542371 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -30,13 +30,12 @@ */ /** - * @file - * This module handles interpretation of the 3270 data stream and - * maintenance of the 3270 device state. It was split out from - * screen.c, which handles X operations. + * @brief Handles interpretation of the 3270 data stream and maintenance of the 3270 device state. * */ +#pragma GCC diagnostic ignored "-Wsign-compare" + #include "private.h" #include #include @@ -2648,7 +2647,7 @@ void ctlr_wrapping_memmove(H3270 *hSession, int baddr_to, int baddr_from, int co } /** - * Copy a block of characters in the 3270 buffer. + * @brief Copy a block of characters in the 3270 buffer. * * Copy a block of characters in the 3270 buffer, optionally including all of * 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 * * @param hSession Session handle */ -void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int move_ea) +void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int move_ea unused) { /* Move the characters. */ 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 #if defined(X3270_ANSI) /*[*/ /** - * Erase a region of the 3270 buffer, optionally clearing extended attributes as well. + * @brief Erase a region of the 3270 buffer, optionally clearing extended attributes as well. * * @param hSession Session handle * */ -void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea) +void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea unused) { if (memcmp((char *) &hSession->ea_buf[baddr], (char *) hSession->zero_buf, count * sizeof(struct lib3270_ea))) { diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index 6e22a03..608d632 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -29,6 +29,8 @@ * */ +#pragma GCC diagnostic ignored "-Wsign-compare" + #ifdef WIN32 #include #include diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 78fb0b7..20faf9c 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -31,13 +31,12 @@ */ -/* - * host.c - * This module handles the ibm_hosts file, connecting to and - * disconnecting from hosts, and state changes on the host - * connection. +/** + * @brief Handle connect and disconnect from hosts, and state changes on the host connection. */ +#pragma GCC diagnostic ignored "-Wsign-compare" + #include #include "private.h" // #include "appres.h" diff --git a/src/lib3270/html.c b/src/lib3270/html.c index 9d7e7d7..ef9fe2b 100644 --- a/src/lib3270/html.c +++ b/src/lib3270/html.c @@ -124,9 +124,9 @@ static void append_string(struct html_info *info, const char *text) { - int sz = strlen(info->text)+strlen(text); + size_t sz = strlen(info->text)+strlen(text); - if(strlen(info->text)+sz <= info->szText) + if(strlen(info->text)+sz <= ((size_t)info->szText) ) { info->szText += (100+sz); info->text = lib3270_realloc(info->text,info->szText); diff --git a/src/lib3270/iocalls.c b/src/lib3270/iocalls.c index 288c501..d9018bb 100644 --- a/src/lib3270/iocalls.c +++ b/src/lib3270/iocalls.c @@ -228,7 +228,7 @@ static void * internal_add_poll(H3270 *session, int fd, LIB3270_IO_FLAG flag, vo ip->userdata = userdata; ip->call = call; - ip->next = session->inputs; + ip->next = (input_t *) session->inputs; session->inputs = ip; session->inputs_changed = 1; @@ -267,17 +267,16 @@ static void internal_remove_poll(H3270 *session, void *id) static void internal_set_poll_state(H3270 *session, void *id, int enabled) { input_t *ip; - input_t *prev = (input_t *)NULL; for (ip = session->inputs; ip != (input_t *) NULL; ip = (input_t *) ip->next) { if (ip == (input_t *)id) { ip->enabled = enabled ? 1 : 0; + session->inputs_changed = 1; break; } - prev = ip; } } @@ -318,7 +317,7 @@ LIB3270_EXPORT void lib3270_update_poll_fd(H3270 *session, int fd, LIB3270_IO_F input_t *ip; - for (ip = session->inputs; ip != (input_t *)NULL; ip = ip->next) + for (ip = session->inputs; ip != (input_t *)NULL; ip = (input_t *) ip->next) { if(ip->fd == fd) { diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 9acc575..2aabbea 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -33,6 +33,9 @@ * @brief This module handles the keyboard for the 3270 emulator. */ +#pragma GCC diagnostic ignored "-Wsign-compare" + + struct ta; #define LIB3270_TA struct ta diff --git a/src/lib3270/linux/connect.c b/src/lib3270/linux/connect.c index ce5beb5..dbea3a1 100644 --- a/src/lib3270/linux/connect.c +++ b/src/lib3270/linux/connect.c @@ -252,7 +252,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True); // s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result); - if(lib3270_run_task(hSession, background_connect, &host)) + if(lib3270_run_task(hSession, background_connect, &host) || hSession->sock < 0) { char buffer[4096]; 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 host.message); lib3270_set_disconnected(hSession); - return errno = ENOENT; + return errno = ENOTCONN; } /* 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 #endif // HAVE_LIBSSL } - /* connect */ - if(hSession->sock < 0) - { - lib3270_set_disconnected(hSession); - - char buffer[4096]; - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc); - - lib3270_popup_dialog( - hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", - host.message - ); - - return errno = ENOTCONN; - } - // set options for inline out-of-band data and keepalives optval = 1; 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 "%s", strerror(errno)); SOCK_CLOSE(hSession); + return errno = ENOTCONN; } 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 "%s", strerror(errno)); SOCK_CLOSE(hSession); + return errno = ENOTCONN; } else { diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 1aee4a0..2cf7ba9 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -282,7 +282,7 @@ typedef struct timeout typedef struct _input_t { unsigned char enabled; - struct input * next; + struct _input_t * next; H3270 * session; int fd; LIB3270_IO_FLAG flag; diff --git a/src/lib3270/rpq.c b/src/lib3270/rpq.c index b936836..9fc3da2 100644 --- a/src/lib3270/rpq.c +++ b/src/lib3270/rpq.c @@ -30,9 +30,10 @@ * */ -/* - * rpq.c - * RPQNAMES structured field support. + #pragma GCC diagnostic ignored "-Wsign-compare" + +/** + * @brief RPQNAMES structured field support. * */ diff --git a/src/lib3270/ssl/ctx_init.c b/src/lib3270/ssl/ctx_init.c deleted file mode 100644 index dcda334..0000000 --- a/src/lib3270/ssl/ctx_init.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como ssl.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - * - * References: - * - * http://www.openssl.org/docs/ssl/ - * - */ - -/** - * @brief OpenSSL initialization. - * - */ - -#include -#if defined(HAVE_LIBSSL) - -#include -#include -#include - -#ifndef SSL_ST_OK - #define SSL_ST_OK 3 -#endif // !SSL_ST_OK - -#include "../private.h" -#include -#include -#include -#include -#include "trace_dsc.h" - -/*--[ Implement ]------------------------------------------------------------------------------------*/ - -/** - * @brief Initialize openssl library. - * - * @return 0 if ok, non zero if fails. - * - */ -int ssl_ctx_init(H3270 *hSession) -{ - debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx); - - if(!ssl_ctx) - { - trace_dsn(hSession,"Initializing SSL context.\n"); - - SSL_load_error_strings(); - SSL_library_init(); - - ssl_ctx = SSL_CTX_new(SSLv23_method()); - if(ssl_ctx == NULL) - return -1; - - SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); - SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); - SSL_CTX_set_default_verify_paths(ssl_ctx); - -#if defined(_WIN32) - { - HKEY hKey = 0; - - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\" PACKAGE_NAME,0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) - { - char data[4096]; - unsigned long datalen = sizeof(data); // data field length(in), data returned length(out) - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - - if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS) - { - strncat(data,"\\certs",4095); - - if(!SSL_CTX_load_verify_locations(ssl_ctx,NULL,data)) - { - hSession->ssl.error = ERR_get_error(); - - trace_dsn( - hSession, - "Cant set default locations for trusted CA certificates to %s\n%s\m" - data, - ERR_lib_error_string(hSession->ssl.error) - ); - - lib3270_write_log( - hSession, - "ssl", - "Cant set default locations for trusted CA certificates to %s\n%s", - data, - ERR_lib_error_string(hSession->ssl.error) - ); - - } - } - RegCloseKey(hKey); - } - - - } -#else - - static const char * ssldir[] = - { -#ifdef DATAROOTDIR - DATAROOTDIR "/" PACKAGE_NAME "/certs", -#endif // DATAROOTDIR -#ifdef SYSCONFDIR - SYSCONFDIR "/ssl/certs", - SYSCONFDIR "/certs", -#endif - "/etc/ssl/certs" - }; - - size_t f; - - for(f = 0;f < sizeof(ssldir) / sizeof(ssldir[0]);f++) - { - SSL_CTX_load_verify_locations(ssl_ctx,NULL,ssldir[f]); - } - - #endif // _WIN32 - - // - // Initialize CUSTOM CRL CHECK - // - - } - - - -/* -#if defined(SSL_ENABLE_CRL_CHECK) - // Set up CRL validation - // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now - X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); - - // Enable CRL checking - X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); - X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); - X509_STORE_set1_param(store, param); - X509_VERIFY_PARAM_free(param); - - // X509_STORE_free(store); - - trace_dsn(hSession,"CRL CHECK is enabled.\n"); - -#else - - trace_dsn(hSession,"CRL CHECK is disabled.\n"); - -#endif // SSL_ENABLE_CRL_CHECK -*/ - - ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL); - - return 0; -} - -#endif // HAVE_LIBSSL diff --git a/src/lib3270/ssl/linux/ctx_init.c b/src/lib3270/ssl/linux/ctx_init.c new file mode 100644 index 0000000..9bbf9e1 --- /dev/null +++ b/src/lib3270/ssl/linux/ctx_init.c @@ -0,0 +1,162 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * + * References: + * + * http://www.openssl.org/docs/ssl/ + * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now + * + */ + +/** + * @brief OpenSSL initialization for linux. + * + */ + +#include +#if defined(HAVE_LIBSSL) + +#include +#include +#include + +#ifndef SSL_ST_OK + #define SSL_ST_OK 3 +#endif // !SSL_ST_OK + +#include "../../private.h" +#include +#include +#include +#include +#include "trace_dsc.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +/** + * @brief Initialize openssl library. + * + * @return 0 if ok, non zero if fails. + * + */ +int ssl_ctx_init(H3270 *hSession) +{ + debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx); + + if(ssl_ctx) + return 0; + + trace_dsn(hSession,"Initializing SSL context.\n"); + + SSL_load_error_strings(); + SSL_library_init(); + + ssl_ctx = SSL_CTX_new(SSLv23_method()); + if(ssl_ctx == NULL) + return -1; + + SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); + SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); + + SSL_CTX_set_default_verify_paths(ssl_ctx); + + /* + static const char * ssldir[] = + { +#ifdef DATAROOTDIR + DATAROOTDIR "/" PACKAGE_NAME "/certs", +#endif // DATAROOTDIR +#ifdef SYSCONFDIR + SYSCONFDIR "/ssl/certs", + SYSCONFDIR "/certs", +#endif + "/etc/ssl/certs" + }; + + size_t f; + + for(f = 0;f < sizeof(ssldir) / sizeof(ssldir[0]);f++) + { + SSL_CTX_load_verify_locations(ssl_ctx,NULL,ssldir[f]); + } + */ + + ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL); + + // + // Initialize CUSTOM CRL CHECK + // + + + return 0; +} + +#endif // HAVE_LIBSSL + +/* +// Load CRLs into the `X509_STORE` + +X509_STORE *x509_store = SSL_CTX_get_cert_store(ctx); +X509_STORE_add_crl(x509_store, crl); + +// Enable CRL checking +X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); +X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); +SSL_CTX_set1_param(ctx, param); +X509_VERIFY_PARAM_free(param); + + + + } + + + + +#if defined(SSL_ENABLE_CRL_CHECK) + // Set up CRL validation + // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now + X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); + + // Enable CRL checking + X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); + X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); + X509_STORE_set1_param(store, param); + X509_VERIFY_PARAM_free(param); + + // X509_STORE_free(store); + + trace_dsn(hSession,"CRL CHECK is enabled.\n"); + +#else + + trace_dsn(hSession,"CRL CHECK is disabled.\n"); + +#endif // SSL_ENABLE_CRL_CHECK + +*/ + diff --git a/src/lib3270/ssl/windows/ctx_init.c b/src/lib3270/ssl/windows/ctx_init.c new file mode 100644 index 0000000..7cc644e --- /dev/null +++ b/src/lib3270/ssl/windows/ctx_init.c @@ -0,0 +1,176 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * + * References: + * + * http://www.openssl.org/docs/ssl/ + * https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now + * + */ + +/** + * @brief OpenSSL initialization for windows. + * + */ + +#include +#if defined(HAVE_LIBSSL) +#include +#include +#include + +#ifndef SSL_ST_OK + #define SSL_ST_OK 3 +#endif // !SSL_ST_OK + +#include "../../private.h" +#include +#include +#include +#include +#include "trace_dsc.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + +/** + * @brief Initialize openssl library. + * + * @return 0 if ok, non zero if fails. + * + */ +int ssl_ctx_init(H3270 *hSession) +{ + debug("%s ssl_ctx=%p",__FUNCTION__,ssl_ctx); + + if(ssl_ctx) + return 0; + + trace_dsn(hSession,"Initializing SSL context.\n"); + + SSL_load_error_strings(); + SSL_library_init(); + + ssl_ctx = SSL_CTX_new(SSLv23_method()); + if(ssl_ctx == NULL) + return -1; + + SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); + SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); + SSL_CTX_set_default_verify_paths(ssl_ctx); + + // + // Get path from windows registry. + // + HKEY hKey = 0; + + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\" PACKAGE_NAME,0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) + { + char data[4096]; + unsigned long datalen = sizeof(data); // data field length(in), data returned length(out) + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) + + if(RegQueryValueExA(hKey,"datadir",NULL,&datatype,(LPBYTE) data,&datalen) == ERROR_SUCCESS) + { + strncat(data,"\\certs",4095); + + if(!SSL_CTX_load_verify_locations(ssl_ctx,NULL,data)) + { + hSession->ssl.error = ERR_get_error(); + + trace_dsn( + hSession, + "Cant set default locations for trusted CA certificates to %s\n%s\m" + data, + ERR_lib_error_string(hSession->ssl.error) + ); + + lib3270_write_log( + hSession, + "ssl", + "Cant set default locations for trusted CA certificates to %s\n%s", + data, + ERR_lib_error_string(hSession->ssl.error) + ); + + } + } + RegCloseKey(hKey); + } + + ssl_3270_ex_index = SSL_get_ex_new_index(0,NULL,NULL,NULL,NULL); + + // + // Initialize CUSTOM CRL CHECK + // + + return 0; +} + +#endif // HAVE_LIBSSL + +/* +// Load CRLs into the `X509_STORE` + +X509_STORE *x509_store = SSL_CTX_get_cert_store(ctx); +X509_STORE_add_crl(x509_store, crl); + +// Enable CRL checking +X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); +X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); +SSL_CTX_set1_param(ctx, param); +X509_VERIFY_PARAM_free(param); + + + + } + + + +/* +#if defined(SSL_ENABLE_CRL_CHECK) + // Set up CRL validation + // https://stackoverflow.com/questions/4389954/does-openssl-automatically-handle-crls-certificate-revocation-lists-now + X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); + + // Enable CRL checking + X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); + X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK); + X509_STORE_set1_param(store, param); + X509_VERIFY_PARAM_free(param); + + // X509_STORE_free(store); + + trace_dsn(hSession,"CRL CHECK is enabled.\n"); + +#else + + trace_dsn(hSession,"CRL CHECK is disabled.\n"); + +#endif // SSL_ENABLE_CRL_CHECK +*/ + diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index 6aff19b..37fafe6 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -29,11 +29,11 @@ * */ + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -/* - * telnet.c - * This module initializes and manages a telnet socket to - * the given IBM host. + +/** + * @brief Initializes and manages a telnet socket to the given IBM host. */ #if defined(_WIN32) @@ -340,16 +340,25 @@ void popup_a_sockerr(H3270 *hSession, char *fmt, ...) text = lib3270_vsprintf(fmt, args); va_end(args); - lib3270_write_log(hSession, "3270", "Network error:\n%s\n%s",text,msg); - - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Network error" ), - text, - "%s", msg); - + lib3270_write_log( + hSession, + "3270", + "Network error:\n%s\n%s", + text, + msg + ); + + lib3270_popup_dialog( + hSession, + LIB3270_NOTIFY_ERROR, + _( "Network error" ), + text, + "%s", + msg + ); lib3270_free(text); + } /* diff --git a/src/lib3270/windows/connect.c b/src/lib3270/windows/connect.c index c76fef4..a67142d 100644 --- a/src/lib3270/windows/connect.c +++ b/src/lib3270/windows/connect.c @@ -29,50 +29,32 @@ #include -#if defined(_WIN32) +// Compiling for WinXP or later: Expose getaddrinfo()/freeaddrinfo(). +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 - // Compiling for WinXP or later: Expose getaddrinfo()/freeaddrinfo(). - #undef _WIN32_WINNT - #define _WIN32_WINNT 0x0501 - - #include - #include - #include - -#endif +#include +#include +#include #include "private.h" #include -#if defined(_WIN32) - #include -#else - #include - #include - #include - #include - #include - #include - #include -#endif +#include #ifdef HAVE_ICONV #include #endif // HAVE_ICONV -#if defined(_WIN32) /*[*/ - #define SOCK_CLOSE(s) closesocket(s->sock); s->sock = -1; -#else /*][*/ - #define SOCK_CLOSE(s) close(s->sock); s->sock = -1; -#endif /*]*/ +#define SOCK_CLOSE(s) closesocket(s->sock); s->sock = -1; -#include -#include "statusc.h" +//#include "statusc.h" #include "hostc.h" #include "trace_dsc.h" -#include "utilc.h" +//#include "utilc.h" #include "telnetc.h" #include "screen.h" + #include /*---[ Implement ]-------------------------------------------------------------------------------*/ @@ -97,11 +79,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u LIB3270_NOTIFY_ERROR, _( "Network error" ), _( "Unable to get connection state." ), -#ifdef _WIN32 "%s", lib3270_win32_strerror(WSAGetLastError()) -#else - _( "%s" ), strerror(errno) -#endif // _WIN32 ); return; } @@ -115,11 +93,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u LIB3270_NOTIFY_ERROR, _( "Connection failed" ), buffer, -#ifdef _WIN32 _( "%s"), lib3270_win32_strerror(err) -#else - _( "%s" ), strerror(err) -#endif // _WIN32 ); trace("%s",__FUNCTION__); return; @@ -141,11 +115,8 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u } - -#if defined(_WIN32) - - static void sockstart(H3270 *session) - { +static void sockstart(H3270 *session) +{ static int initted = 0; WORD wVersionRequested; WSADATA wsaData; @@ -177,11 +148,10 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u N_( "Can't use winsock version %d.%d" ), LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); _exit(1); } - } -#endif // WIN32 +} - LIB3270_EXPORT int lib3270_connect_url(H3270 *hSession, const char *url, int wait) - { +LIB3270_EXPORT int lib3270_connect_url(H3270 *hSession, const char *url, int wait) +{ CHECK_SESSION_HANDLE(hSession); if(url && *url) @@ -191,10 +161,10 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u return lib3270_connect(hSession, wait); - } +} - LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt) - { +LIB3270_EXPORT int lib3270_connect_host(H3270 *hSession, const char *hostname, const char *srvc, LIB3270_OPTION opt) +{ CHECK_SESSION_HANDLE(hSession); if(!hostname) @@ -235,10 +205,63 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u return lib3270_connect(hSession,opt & LIB3270_OPTION_WAIT); - } +} + + struct resolver + { + int convert; + const char * message; + }; - int lib3270_connect(H3270 *hSession, int seconds) + static int background_connect(H3270 *hSession, void *host) { + struct addrinfo hints; + struct addrinfo * result = NULL; + struct addrinfo * rp = NULL; + + memset(&hints,0,sizeof(hints)); + hints.ai_family = AF_UNSPEC; // Allow IPv4 or IPv6 + hints.ai_socktype = SOCK_STREAM; // Stream socket + hints.ai_flags = AI_PASSIVE; // For wildcard IP address + hints.ai_protocol = 0; // Any protocol + + int rc = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result); + if(rc != 0) + { + ((struct resolver *) host)->message = gai_strerror(rc); + ((struct resolver *) host)->convert = 1; + return -1; + } + + status_connecting(hSession,1); + + for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next) + { + hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if(hSession->sock < 0) + { + ((struct resolver *) host)->message = strerror(errno); + continue; + } + + // Connected! + if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen)) + { + SOCK_CLOSE(hSession); + ((struct resolver *) host)->message = strerror(errno); + continue; + } + + } + + freeaddrinfo(result); + + return 0; + +} + +int lib3270_connect(H3270 *hSession, int seconds) +{ int s; int optval; struct addrinfo hints; @@ -255,9 +278,7 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u if(hSession->sock > 0) return errno = EBUSY; -#if defined(_WIN32) sockstart(hSession); -#endif #if defined(HAVE_LIBSSL) 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 snprintf(hSession->full_model_name,LIB3270_FULL_MODEL_NAME_LENGTH,"IBM-327%c-%d",hSession->m3279 ? '9' : '8', hSession->model_num); hSession->ever_3270 = False; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ - hints.ai_socktype = SOCK_STREAM; /* Stream socket */ - hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */ - hints.ai_protocol = 0; /* Any protocol */ - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; - hSession->cstate = LIB3270_RESOLVING; - lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True); - s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result); + lib3270_st_changed(hSession, LIB3270_STATE_RESOLVING, True); - if(s != 0) + // s = getaddrinfo(hSession->host.current, hSession->host.srvc, &hints, &result); + if(lib3270_run_task(hSession, background_connect, &host) || hSession->sock < 0) { char buffer[4096]; + char msg[4096]; snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc); -#if defined(WIN32) && defined(HAVE_ICONV) + strncpy(msg,host.message,4095); + +#ifdef HAVE_ICONV + if(host.convert) { - char tmpbuffer[4096]; - const char * msg = gai_strerror(s); - size_t in = strlen(msg); - size_t out = 4096; - char * ptr = tmpbuffer; + char * ptr = msg; + size_t out = 4096; iconv_t hConv = iconv_open(lib3270_win32_local_charset(),"UTF-8"); - - trace("Antes: [%s]",msg); - if(iconv(hConv,&msg,&in,&ptr,&out) != ((size_t) -1)) - msg = tmpbuffer; - trace("Depois: [%s]",msg); - + if(iconv(hConv,&host.message,&in,&ptr,&out) == ((size_t) -1)) + { + strncpy(msg,host.message,4095); + } iconv_close(hConv); - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", - msg); } +#endif // HAVE_ICONV -#else lib3270_popup_dialog( hSession, LIB3270_NOTIFY_ERROR, _( "Connection error" ), buffer, "%s", - gai_strerror(s)); -#endif // WIN32 - + msg); lib3270_set_disconnected(hSession); - return errno = ENOENT; + return errno = ENOTCONN; } - -#if !defined(_WIN32) - /* don't share the socket with our children */ - (void) fcntl(hSession->sock, F_SETFD, 1); -#endif - hSession->ever_3270 = False; hSession->ssl.host = 0; @@ -353,141 +349,40 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u } /* connect */ - status_connecting(hSession,1); - - for(rp = result; hSession->sock < 0 && rp != NULL; rp = rp->ai_next) - { - hSession->sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if(hSession->sock < 0) - continue; - - trace("sock=%d",hSession->sock); - -#ifdef WIN32 - WSASetLastError(0); - u_long iMode=1; - trace("sock=%d",hSession->sock); + WSASetLastError(0); + u_long iMode=1; - optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) - { - char buffer[4096]; - snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); - - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", lib3270_win32_strerror(WSAGetLastError())); - SOCK_CLOSE(hSession); - continue; - } - else - { - trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); - } - - if(ioctlsocket(hSession->sock,FIONBIO,&iMode)) - { - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - _( "ioctlsocket(FIONBIO) failed." ), - "%s", lib3270_win32_strerror(WSAGetLastError())); - SOCK_CLOSE(hSession); - continue; - } - else if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen)) - { - int err = WSAGetLastError(); - if(err != WSAEWOULDBLOCK) - { - char buffer[4096]; - snprintf(buffer,4095,_( "Can't connect to %s"), lib3270_get_host(hSession)); - - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", lib3270_win32_strerror(err)); - SOCK_CLOSE(hSession); - continue; - - } - } - - optval = 1; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) - { - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - _( "setsockopt(SO_OOBINLINE) has failed" ), - "%s", lib3270_win32_strerror(WSAGetLastError())); - SOCK_CLOSE(hSession); - continue; - } - -#else - fcntl(hSession->sock, F_SETFL,fcntl(hSession->sock,F_GETFL,0)|O_NONBLOCK); - - errno = 0; - if(connect(hSession->sock, rp->ai_addr, rp->ai_addrlen)) - { - if( errno != EINPROGRESS ) - { - char buffer[4096]; - snprintf(buffer,4095,_( "Can't connect to %s:%s"), hSession->host.current, hSession->host.srvc); - - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", - strerror(errno)); - SOCK_CLOSE(hSession); - continue; - } - } - - optval = 1; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) - { - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - _( "setsockopt(SO_OOBINLINE) has failed" ), - "%s", - strerror(errno)); - SOCK_CLOSE(hSession); - continue; - } - - optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; - if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) - { - char buffer[4096]; - snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); - - lib3270_popup_dialog( hSession, - LIB3270_NOTIFY_ERROR, - _( "Connection error" ), - buffer, - "%s", - strerror(errno)); - SOCK_CLOSE(hSession); - continue; - } - else - { - trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); - } + optval = lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; + if (setsockopt(hSession->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) + { + char buffer[4096]; + snprintf(buffer,4095,N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); -#endif // WIN32 + lib3270_popup_dialog( hSession, + LIB3270_NOTIFY_ERROR, + _( "Connection error" ), + buffer, + "%s", lib3270_win32_strerror(WSAGetLastError())); + SOCK_CLOSE(hSession); + return errno = ENOTCONN; + } + else + { + trace_dsn(hSession,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); } - freeaddrinfo(result); + optval = 1; + if (setsockopt(hSession->sock, SOL_SOCKET, SO_OOBINLINE, (char *)&optval,sizeof(optval)) < 0) + { + lib3270_popup_dialog( hSession, + LIB3270_NOTIFY_ERROR, + _( "Connection error" ), + _( "setsockopt(SO_OOBINLINE) has failed" ), + "%s", lib3270_win32_strerror(WSAGetLastError())); + SOCK_CLOSE(hSession); + return errno = ENOTCONN; + } // set options for inline out-of-band data and keepalives @@ -502,12 +397,6 @@ static void net_connected(H3270 *hSession, int fd unused, LIB3270_IO_FLAG flag u */ - if(hSession->sock < 0) - { - lib3270_set_disconnected(hSession); - return errno = ENOTCONN; - } - // Connecting, set callbacks, wait for connection hSession->cstate = LIB3270_PENDING; lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True); -- libgit2 0.21.2