Commit 3a5f8f2112fb77f502fb9cbc58333beb881544ae

Authored by Perry Werneck
1 parent 8e4f26cd

Working on win32 crl download from ldap.

src/include/lib3270/trace.h
@@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
65 LIB3270_EXPORT void lib3270_get_trace_handler(H3270 *hSession, LIB3270_TRACE_HANDLER *handler, void **userdata); 65 LIB3270_EXPORT void lib3270_get_trace_handler(H3270 *hSession, LIB3270_TRACE_HANDLER *handler, void **userdata);
66 66
67 /** 67 /**
68 - * Write on trace file. 68 + * @brief Write on trace file.
69 * 69 *
70 * Write text on trace file, if DStrace is enabled. 70 * Write text on trace file, if DStrace is enabled.
71 * 71 *
@@ -76,7 +76,7 @@ @@ -76,7 +76,7 @@
76 LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3); 76 LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3);
77 77
78 /** 78 /**
79 - * Write on trace file. 79 + * @brief Write on trace file.
80 * 80 *
81 * Write text on trace file, if network trace is enabled. 81 * Write text on trace file, if network trace is enabled.
82 * 82 *
@@ -87,7 +87,7 @@ @@ -87,7 +87,7 @@
87 LIB3270_EXPORT void lib3270_write_nettrace(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3); 87 LIB3270_EXPORT void lib3270_write_nettrace(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3);
88 88
89 /** 89 /**
90 - * Write on trace file. 90 + * @brief Write on trace file.
91 * 91 *
92 * Write text on trace file, if event is enabled. 92 * Write text on trace file, if event is enabled.
93 * 93 *
@@ -97,6 +97,19 @@ @@ -97,6 +97,19 @@
97 */ 97 */
98 LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3); 98 LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...) LIB3270_AS_PRINTF(2,3);
99 99
  100 +
  101 + /**
  102 + * @brief Write datablock on trace file.
  103 + *
  104 + * @param hSession TN3270 Session handle.
  105 + * @param msg Message.
  106 + * @param data Data block in ASCII.
  107 + * @param datalen Length of the data block.
  108 + *
  109 + */
  110 + LIB3270_EXPORT void lib3270_trace_data(H3270 *hSession, const char *msg, const char *data, size_t datalen);
  111 +
  112 +
100 #ifdef __cplusplus 113 #ifdef __cplusplus
101 } 114 }
102 #endif 115 #endif
src/lib3270/ansi.c
@@ -35,7 +35,10 @@ @@ -35,7 +35,10 @@
35 */ 35 */
36 36
37 #pragma GCC diagnostic ignored "-Wsign-compare" 37 #pragma GCC diagnostic ignored "-Wsign-compare"
38 -#pragma GCC diagnostic ignored "-Wstringop-truncation" 38 +
  39 +#ifdef _WIN32
  40 + #pragma GCC diagnostic ignored "-Wstringop-truncation"
  41 +#endif // _WIN32
39 42
40 #include "private.h" 43 #include "private.h"
41 44
src/lib3270/ssl/linux/getcrl.c
@@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
57 #include <trace_dsc.h> 57 #include <trace_dsc.h>
58 #include <errno.h> 58 #include <errno.h>
59 #include <lib3270.h> 59 #include <lib3270.h>
  60 +#include <lib3270/trace.h>
60 61
61 /*--[ Implement ]------------------------------------------------------------------------------------*/ 62 /*--[ Implement ]------------------------------------------------------------------------------------*/
62 63
@@ -113,7 +114,9 @@ static inline void lib3270_autoptr_cleanup_CURL(CURL **ptr) @@ -113,7 +114,9 @@ static inline void lib3270_autoptr_cleanup_CURL(CURL **ptr)
113 typedef struct _curldata 114 typedef struct _curldata
114 { 115 {
115 size_t length; 116 size_t length;
  117 + H3270 * hSession;
116 SSL_ERROR_MESSAGE * message; 118 SSL_ERROR_MESSAGE * message;
  119 + char errbuf[CURL_ERROR_SIZE];
117 unsigned char contents[CRL_DATA_LENGTH]; 120 unsigned char contents[CRL_DATA_LENGTH];
118 } CURLDATA; 121 } CURLDATA;
119 122
@@ -145,7 +148,15 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n @@ -145,7 +148,15 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n
145 return 0; 148 return 0;
146 } 149 }
147 150
148 - debug("Received %u bytes", (unsigned int) realsize); 151 +#ifdef DEBUG
  152 + lib3270_trace_data(
  153 + data->hSession,
  154 + "Received",
  155 + (const char *) contents,
  156 + realsize
  157 + );
  158 +
  159 +#endif // DEBUG
149 160
150 memcpy(&(data->contents[data->length]),contents,realsize); 161 memcpy(&(data->contents[data->length]),contents,realsize);
151 data->length += realsize; 162 data->length += realsize;
@@ -153,6 +164,54 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n @@ -153,6 +164,54 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n
153 return realsize; 164 return realsize;
154 } 165 }
155 166
  167 +static int internal_curl_trace_callback(CURL *handle unused, curl_infotype type, char *data, size_t size, void *userp)
  168 +{
  169 + const char * text = NULL;
  170 +
  171 + switch (type) {
  172 + case CURLINFO_TEXT:
  173 + lib3270_write_log(((CURLDATA *) userp)->hSession,"curl","%s",data);
  174 + return 0;
  175 +
  176 + case CURLINFO_HEADER_OUT:
  177 + text = "=> Send header";
  178 + break;
  179 +
  180 + case CURLINFO_DATA_OUT:
  181 + text = "=> Send data";
  182 + break;
  183 +
  184 + case CURLINFO_SSL_DATA_OUT:
  185 + text = "=> Send SSL data";
  186 + break;
  187 +
  188 + case CURLINFO_HEADER_IN:
  189 + text = "<= Recv header";
  190 + break;
  191 +
  192 + case CURLINFO_DATA_IN:
  193 + text = "<= Recv data";
  194 + break;
  195 +
  196 + case CURLINFO_SSL_DATA_IN:
  197 + text = "<= Recv SSL data";
  198 + break;
  199 +
  200 + default:
  201 + return 0;
  202 +
  203 + }
  204 +
  205 + lib3270_trace_data(
  206 + ((CURLDATA *) userp)->hSession,
  207 + text,
  208 + data,
  209 + size
  210 + );
  211 +
  212 + return 0;
  213 +}
  214 +
156 #endif // HAVE_LIBCURL 215 #endif // HAVE_LIBCURL
157 216
158 217
@@ -363,10 +422,12 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -363,10 +422,12 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message)
363 422
364 // Use CURL to download the CRL 423 // Use CURL to download the CRL
365 lib3270_autoptr(CURLDATA) crl_data = lib3270_malloc(sizeof(CURLDATA)); 424 lib3270_autoptr(CURLDATA) crl_data = lib3270_malloc(sizeof(CURLDATA));
  425 +
366 lib3270_autoptr(CURL) hCurl = curl_easy_init(); 426 lib3270_autoptr(CURL) hCurl = curl_easy_init();
367 427
368 memset(crl_data,0,sizeof(CURLDATA)); 428 memset(crl_data,0,sizeof(CURLDATA));
369 crl_data->message = message; 429 crl_data->message = message;
  430 + crl_data->hSession = hSession;
370 431
371 if(hCurl) 432 if(hCurl)
372 { 433 {
@@ -375,19 +436,41 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -375,19 +436,41 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message)
375 curl_easy_setopt(hCurl, CURLOPT_URL, consturl); 436 curl_easy_setopt(hCurl, CURLOPT_URL, consturl);
376 curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1L); 437 curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1L);
377 438
  439 + curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, crl_data->errbuf);
  440 +
378 curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, internal_curl_write_callback); 441 curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, internal_curl_write_callback);
379 curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void *) crl_data); 442 curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void *) crl_data);
380 443
  444 + curl_easy_setopt(hCurl, CURLOPT_USERNAME, "");
  445 +
  446 + if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE))
  447 + {
  448 + curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1L);
  449 + curl_easy_setopt(hCurl, CURLOPT_DEBUGFUNCTION, internal_curl_trace_callback);
  450 + curl_easy_setopt(hCurl, CURLOPT_DEBUGDATA, (void *) crl_data);
  451 + }
  452 +
381 res = curl_easy_perform(hCurl); 453 res = curl_easy_perform(hCurl);
382 454
383 if(res != CURLE_OK) 455 if(res != CURLE_OK)
384 { 456 {
385 message->error = hSession->ssl.error = 0; 457 message->error = hSession->ssl.error = 0;
386 message->title = N_( "Security error" ); 458 message->title = N_( "Security error" );
387 - message->text = N_( "Error loading CRL" );  
388 - message->description = curl_easy_strerror(res); 459 +
  460 + if(crl_data->errbuf[0])
  461 + {
  462 + message->text = curl_easy_strerror(res);
  463 + message->description = crl_data->errbuf;
  464 + }
  465 + else
  466 + {
  467 + message->text = N_( "Error loading CRL" );
  468 + message->description = curl_easy_strerror(res);
  469 + }
  470 +
389 lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); 471 lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description);
390 return NULL; 472 return NULL;
  473 +
391 } 474 }
392 475
393 char *ct = NULL; 476 char *ct = NULL;
src/lib3270/ssl/windows/getcrl.c
@@ -54,6 +54,7 @@ @@ -54,6 +54,7 @@
54 #include <trace_dsc.h> 54 #include <trace_dsc.h>
55 #include <errno.h> 55 #include <errno.h>
56 #include <lib3270.h> 56 #include <lib3270.h>
  57 +#include <lib3270/trace.h>
57 58
58 /*--[ Implement ]------------------------------------------------------------------------------------*/ 59 /*--[ Implement ]------------------------------------------------------------------------------------*/
59 60
@@ -78,6 +79,7 @@ static inline void lib3270_autoptr_cleanup_CURL(CURL **ptr) @@ -78,6 +79,7 @@ static inline void lib3270_autoptr_cleanup_CURL(CURL **ptr)
78 typedef struct _curldata 79 typedef struct _curldata
79 { 80 {
80 size_t length; 81 size_t length;
  82 + H3270 * hSession;
81 SSL_ERROR_MESSAGE * message; 83 SSL_ERROR_MESSAGE * message;
82 char errbuf[CURL_ERROR_SIZE]; 84 char errbuf[CURL_ERROR_SIZE];
83 unsigned char contents[CRL_DATA_LENGTH]; 85 unsigned char contents[CRL_DATA_LENGTH];
@@ -110,7 +112,9 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n @@ -110,7 +112,9 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n
110 112
111 unsigned char *ptr = (unsigned char *) contents; 113 unsigned char *ptr = (unsigned char *) contents;
112 114
113 - debug("\n------------------------------------\n%s\n", ptr); 115 +#ifdef DEBUG
  116 + lib3270_trace_data(data->hSession,"************* Received block",(const char *) contents, realsize);
  117 +#endif
114 118
115 for(ix = 0; ix < realsize; ix++) 119 for(ix = 0; ix < realsize; ix++)
116 { 120 {
@@ -128,6 +132,53 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n @@ -128,6 +132,53 @@ static size_t internal_curl_write_callback(void *contents, size_t size, size_t n
128 return realsize; 132 return realsize;
129 } 133 }
130 134
  135 +static int internal_curl_trace_callback(CURL *handle unused, curl_infotype type, char *data, size_t size, void *userp)
  136 +{
  137 + const char * text = NULL;
  138 +
  139 + switch (type) {
  140 + case CURLINFO_TEXT:
  141 + lib3270_write_log(((CURLDATA *) userp)->hSession,"curl","%s",data);
  142 + return 0;
  143 +
  144 + case CURLINFO_HEADER_OUT:
  145 + text = "=> Send header";
  146 + break;
  147 +
  148 + case CURLINFO_DATA_OUT:
  149 + text = "=> Send data";
  150 + break;
  151 +
  152 + case CURLINFO_SSL_DATA_OUT:
  153 + text = "=> Send SSL data";
  154 + break;
  155 +
  156 + case CURLINFO_HEADER_IN:
  157 + text = "<= Recv header";
  158 + break;
  159 +
  160 + case CURLINFO_DATA_IN:
  161 + text = "<= Recv data";
  162 + break;
  163 +
  164 + case CURLINFO_SSL_DATA_IN:
  165 + text = "<= Recv SSL data";
  166 + break;
  167 +
  168 + default:
  169 + return 0;
  170 +
  171 + }
  172 +
  173 + lib3270_trace_data(
  174 + ((CURLDATA *) userp)->hSession,
  175 + text,
  176 + data,
  177 + size
  178 + );
  179 +
  180 + return 0;
  181 +}
131 #endif // HAVE_LIBCURL 182 #endif // HAVE_LIBCURL
132 183
133 184
@@ -179,6 +230,7 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -179,6 +230,7 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message)
179 230
180 memset(crl_data,0,sizeof(CURLDATA)); 231 memset(crl_data,0,sizeof(CURLDATA));
181 crl_data->message = message; 232 crl_data->message = message;
  233 + crl_data->hSession = hSession;
182 234
183 debug("datablock is %p",crl_data); 235 debug("datablock is %p",crl_data);
184 236
@@ -189,13 +241,21 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message) @@ -189,13 +241,21 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message)
189 curl_easy_setopt(hCurl, CURLOPT_URL, consturl); 241 curl_easy_setopt(hCurl, CURLOPT_URL, consturl);
190 curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1L); 242 curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION, 1L);
191 243
192 - curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, crl_data); 244 + curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, crl_data->errbuf);
193 245
194 curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, internal_curl_write_callback); 246 curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, internal_curl_write_callback);
195 curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void *) crl_data); 247 curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void *) crl_data);
196 248
197 curl_easy_setopt(hCurl, CURLOPT_USERNAME, ""); 249 curl_easy_setopt(hCurl, CURLOPT_USERNAME, "");
198 250
  251 + if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_SSL_TRACE))
  252 + {
  253 + curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1L);
  254 + curl_easy_setopt(hCurl, CURLOPT_DEBUGFUNCTION, internal_curl_trace_callback);
  255 + curl_easy_setopt(hCurl, CURLOPT_DEBUGDATA, (void *) crl_data);
  256 + CURLOPT_DEBUGDATA
  257 + }
  258 +
199 res = curl_easy_perform(hCurl); 259 res = curl_easy_perform(hCurl);
200 260
201 if(res != CURLE_OK) 261 if(res != CURLE_OK)
src/lib3270/trace_ds.c
@@ -302,5 +302,43 @@ void trace_ansi_disc(H3270 *hSession) @@ -302,5 +302,43 @@ void trace_ansi_disc(H3270 *hSession)
302 hSession->trace_skipping = 1; 302 hSession->trace_skipping = 1;
303 } 303 }
304 304
  305 +void lib3270_trace_data(H3270 *hSession, const char *msg, const char *data, size_t datalen)
  306 +{
  307 + // 00000000001111111111222222222233333333334444444444555555555566666666667777777777
  308 + // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  309 + // xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx . . . . . . . . . . . . . . . .
  310 +
  311 + size_t ix;
  312 + char buffer[80];
  313 + char hexvalue[3];
  314 +
  315 + memset(buffer,0,sizeof(buffer));
  316 +
  317 + wtrace(hSession, "%s (%u bytes)\n", msg, (unsigned int) datalen);
  318 +
  319 + for(ix = 0; ix < datalen; ix++)
  320 + {
  321 + size_t col = (ix%15);
  322 +
  323 + if(col == 0)
  324 + {
  325 + if(ix)
  326 + wtrace(hSession," %s\n",buffer);
  327 +
  328 + memset(buffer,' ',79);
  329 + buffer[79] = 0;
  330 + }
  331 +
  332 + snprintf(hexvalue,3,"%02x",data[ix]);
  333 + memcpy(buffer+(col*3),hexvalue,2);
  334 +
  335 + if(data[ix] > ' ')
  336 + buffer[48 + (col*2)] = data[ix];
  337 +
  338 + }
  339 +
  340 + wtrace(hSession," %s\n",buffer);
  341 +
  342 +}
305 343
306 #endif 344 #endif