Commit 09dddac04690cfea4545656799286aa79a62c146

Authored by Perry Werneck
1 parent 95491ab4

Fixing windows network methods.

src/core/windows/connect.c
@@ -226,22 +226,16 @@ int net_reconnect(H3270 *hSession, int seconds) @@ -226,22 +226,16 @@ int net_reconnect(H3270 *hSession, int seconds)
226 // Have windows message, convert charset. 226 // Have windows message, convert charset.
227 227
228 char msg[4096]; 228 char msg[4096];
229 - strncpy(msg,host.message,4095);  
230 -  
231 - debug("host.message=\"%s\"",host.message); 229 + snprintf(msg,sizeof(msg),"%s (RC=%d)",host.message,host.rc);
232 230
233 if(hEventLog) 231 if(hEventLog)
234 { 232 {
235 // Register on event log 233 // Register on event log
236 lib3270_autoptr(char) username = lib3270_get_user_name(); 234 lib3270_autoptr(char) username = lib3270_get_user_name();
237 235
238 - snprintf(msg,sizeof(msg),"rc=%d",host.rc);  
239 -  
240 const char *outMsg[] = { 236 const char *outMsg[] = {
241 username, 237 username,
242 "networking", 238 "networking",
243 - message,  
244 - host.message,  
245 msg 239 msg
246 }; 240 };
247 241
@@ -270,7 +264,8 @@ int net_reconnect(H3270 *hSession, int seconds) @@ -270,7 +264,8 @@ int net_reconnect(H3270 *hSession, int seconds)
270 iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); 264 iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset());
271 if(iconv( 265 if(iconv(
272 hConv, 266 hConv,
273 - &host.message,&in, 267 + (ICONV_CONST char *) &host.message,
  268 + &in,
274 &ptr,&out 269 &ptr,&out
275 ) == ((size_t) -1)) 270 ) == ((size_t) -1))
276 { 271 {
src/ssl/windows/getcrl.c
@@ -53,10 +53,14 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co @@ -53,10 +53,14 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
53 53
54 if(!(consturl && *consturl)) 54 if(!(consturl && *consturl))
55 { 55 {
56 - message->error = hSession->ssl.error = 0;  
57 - message->title = _( "Security error" );  
58 - message->text = _( "Can't open CRL File" );  
59 - message->description = _("The URL for the CRL is undefined or empty"); 56 + static const LIB3270_POPUP popup = {
  57 + .name = "CantOpenCRL",
  58 + .summary = N_("Can´t open CRL file"),
  59 + .body = N_("The URL for the CRL is undefined or empty")
  60 + };
  61 +
  62 + message->code = hSession->ssl.error = 0;
  63 + message->popup = &popup;
60 errno = ENOENT; 64 errno = ENOENT;
61 return NULL; 65 return NULL;
62 } 66 }
@@ -68,13 +72,15 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co @@ -68,13 +72,15 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
68 if(!hCRL) 72 if(!hCRL)
69 { 73 {
70 // Can't open CRL File. 74 // Can't open CRL File.
71 - int err = errno;  
72 -  
73 - message->error = hSession->ssl.error = 0;  
74 - message->title = _( "Security error" );  
75 - message->text = _( "Can't open CRL File" );  
76 - message->description = strerror(err);  
77 - trace_ssl(hSession,"Can't open %s: %s\n",consturl,message->description); 75 + static const LIB3270_POPUP popup = {
  76 + .summary = N_("Can´t open CRL file"),
  77 + .body = N_("Unable to open the defined CRL file")
  78 + };
  79 +
  80 + message->code = errno;
  81 + message->popup = &popup;
  82 + hSession->ssl.error = 0;
  83 + trace_ssl(hSession,"Can't open %s: %s\n",consturl,strerror(errno));
78 return NULL; 84 return NULL;
79 85
80 } 86 }
@@ -82,10 +88,13 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co @@ -82,10 +88,13 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
82 trace_ssl(hSession,"Loading CRL from %s\n",consturl+7); 88 trace_ssl(hSession,"Loading CRL from %s\n",consturl+7);
83 if(d2i_X509_CRL_fp(hCRL, &x509_crl)) 89 if(d2i_X509_CRL_fp(hCRL, &x509_crl))
84 { 90 {
85 - message->error = hSession->ssl.error = ERR_get_error();  
86 - message->title = _( "Security error" );  
87 - message->text = _( "Can't decode CRL" );  
88 - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); 91 + static const LIB3270_POPUP popup = {
  92 + .summary = N_("Unable to decode CRL")
  93 + };
  94 +
  95 + message->code = hSession->ssl.error = ERR_get_error();
  96 + message->popup = &popup;
  97 + lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary);
89 return NULL; 98 return NULL;
90 } 99 }
91 100
@@ -112,16 +121,14 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co @@ -112,16 +121,14 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
112 #else 121 #else
113 // Can't get CRL. 122 // Can't get CRL.
114 123
115 - message->error = hSession->ssl.error = 0;  
116 -  
117 - if(!(message->text && message->description))  
118 - message->title = _( "Security error" );  
119 -  
120 - if(!message->text)  
121 - message->text = _( "Unexpected or invalid CRL URL" );  
122 -  
123 - if(!message->description)  
124 - message->description = _("The URL scheme is unknown"); 124 + message->code = hSession->ssl.error = 0;
  125 + if(!message->popup) {
  126 + static const LIB3270_POPUP popup = {
  127 + .summary = N_( "Unexpected or invalid CRL URL" ),
  128 + .body = N_("The URL scheme is unknown")
  129 + };
  130 + message->popup = &popup;
  131 + }
125 132
126 trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); 133 trace_ssl(hSession,"%s: The URL scheme is unknown",consturl);
127 134
src/ssl/windows/http.c
@@ -49,16 +49,22 @@ @@ -49,16 +49,22 @@
49 X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl) 49 X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, const char *consturl)
50 { 50 {
51 size_t szResponse = 0; 51 size_t szResponse = 0;
52 - lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szResponse, &message->text); 52 + const char * error_message = NULL;
  53 + lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szResponse, &error_message);
53 54
54 if(!httpText) 55 if(!httpText)
55 { 56 {
56 - message->error = hSession->ssl.error = 0;  
57 - message->title = _( "Security error" ); 57 + static LIB3270_POPUP popup = {
  58 + .summary = N_("Can´t get CRL"),
  59 + };
  60 +
  61 + popup.body = error_message;
  62 + message->popup = error_message;
  63 + message->code = hSession->ssl.error = 0;
58 trace_ssl( 64 trace_ssl(
59 hSession,"Can't get %s: %s\n", 65 hSession,"Can't get %s: %s\n",
60 consturl, 66 consturl,
61 - message->description ? message->description : "Undefined message" 67 + popup.body ? popup.body : "Undefined message"
62 ); 68 );
63 return NULL; 69 return NULL;
64 } 70 }
@@ -67,17 +73,20 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons @@ -67,17 +73,20 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons
67 const unsigned char *crl_data = (const unsigned char *) httpText; 73 const unsigned char *crl_data = (const unsigned char *) httpText;
68 74
69 X509_CRL * x509_crl = NULL; 75 X509_CRL * x509_crl = NULL;
  76 +
70 if(!d2i_X509_CRL(&x509_crl,&crl_data, (DWORD) szResponse)) 77 if(!d2i_X509_CRL(&x509_crl,&crl_data, (DWORD) szResponse))
71 { 78 {
72 - message->error = hSession->ssl.error = ERR_get_error();  
73 - message->title = _( "Security error" );  
74 - message->text = _( "Can't decode certificate revocation list" );  
75 - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); 79 + static const LIB3270_POPUP popup = {
  80 + .summary = N_( "Can't decode certificate revocation list" )
  81 + };
  82 + message->code = hSession->ssl.error = ERR_get_error();
  83 + message->popup = &popup;
  84 + lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary);
76 85
77 trace_ssl( 86 trace_ssl(
78 hSession,"%s: %s\n", 87 hSession,"%s: %s\n",
79 consturl, 88 consturl,
80 - message->text 89 + popup.summary
81 ); 90 );
82 91
83 return NULL; 92 return NULL;
src/ssl/windows/init.c
@@ -87,9 +87,12 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -87,9 +87,12 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
87 ssl_ctx = SSL_CTX_new(SSLv23_method()); 87 ssl_ctx = SSL_CTX_new(SSLv23_method());
88 if(ssl_ctx == NULL) 88 if(ssl_ctx == NULL)
89 { 89 {
90 - message->error = hSession->ssl.error = ERR_get_error();  
91 - message->title = _( "Security error" );  
92 - message->text = _( "Cant initialize the SSL context." ); 90 + static const LIB3270_POPUP popup = {
  91 + .summary = N_( "Cant initialize the SSL context." )
  92 + };
  93 +
  94 + message->code = hSession->ssl.error = ERR_get_error();
  95 + message->popup = &popup;
93 return -1; 96 return -1;
94 } 97 }
95 98
@@ -109,8 +112,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -109,8 +112,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
109 112
110 if(hFind == INVALID_HANDLE_VALUE) 113 if(hFind == INVALID_HANDLE_VALUE)
111 { 114 {
112 - message->title = _( "Security error" );  
113 - message->text = _( "Cant open custom certificate directory." ); 115 + static const LIB3270_POPUP popup = {
  116 + .summary = N_( "Cant open custom certificate directory." )
  117 + };
  118 +
  119 + message->popup = &popup;
114 120
115 trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)\n" ), certpath, (long) GetLastError()); 121 trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)\n" ), certpath, (long) GetLastError());
116 } 122 }
@@ -134,9 +140,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -134,9 +140,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
134 140
135 if(!cert) 141 if(!cert)
136 { 142 {
137 - message->error = hSession->ssl.error = ERR_get_error();  
138 - message->title = _( "Security error" );  
139 - message->text = _( "Cant read custom certificate file." ); 143 + static const LIB3270_POPUP popup = {
  144 + .summary = N_( "Cant read custom certificate file." )
  145 + };
  146 + message->code = hSession->ssl.error = ERR_get_error();
  147 + message->popup = &popup;
140 148
141 trace_ssl(hSession, _( "Can't read \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error)); 149 trace_ssl(hSession, _( "Can't read \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error));
142 } 150 }
@@ -145,9 +153,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -145,9 +153,11 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
145 153
146 if(X509_STORE_add_cert(store, cert) != 1) 154 if(X509_STORE_add_cert(store, cert) != 1)
147 { 155 {
148 - message->error = hSession->ssl.error = ERR_get_error();  
149 - message->title = _( "Security error" );  
150 - message->text = _( "Cant load custom certificate file." ); 156 + static const LIB3270_POPUP popup = {
  157 + .summary = N_( "Cant load custom certificate file." )
  158 + };
  159 + message->code = hSession->ssl.error = ERR_get_error();
  160 + message->popup = &popup;
151 161
152 trace_ssl(hSession, _( "Can't load \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error)); 162 trace_ssl(hSession, _( "Can't load \"%s\": %s" ), filename, ERR_lib_error_string(hSession->ssl.error));
153 } 163 }