Commit 114af134f6b15284f18b889da9b97c1a9dd8003a
1 parent
a6f24e75
Exists in
master
and in
3 other branches
Mais ajustes para multi-sessão
Showing
1 changed file
with
31 additions
and
65 deletions
Show diff stats
telnet.c
@@ -275,7 +275,7 @@ static unsigned char will_opt[] = { IAC, WILL, '_' }; | @@ -275,7 +275,7 @@ static unsigned char will_opt[] = { IAC, WILL, '_' }; | ||
275 | static unsigned char wont_opt[] = { IAC, WONT, '_' }; | 275 | static unsigned char wont_opt[] = { IAC, WONT, '_' }; |
276 | 276 | ||
277 | #if defined(X3270_TN3270E) /*[*/ | 277 | #if defined(X3270_TN3270E) /*[*/ |
278 | -static unsigned char functions_req[] = { IAC, SB, TELOPT_TN3270E, TN3270E_OP_FUNCTIONS }; | 278 | +static const unsigned char functions_req[] = { IAC, SB, TELOPT_TN3270E, TN3270E_OP_FUNCTIONS }; |
279 | #endif /*]*/ | 279 | #endif /*]*/ |
280 | 280 | ||
281 | #if defined(X3270_TRACE) /*[*/ | 281 | #if defined(X3270_TRACE) /*[*/ |
@@ -327,7 +327,7 @@ static const char *trsp_flag[2] = { "POSITIVE-RESPONSE", "NEGATIVE-RESPONSE" }; | @@ -327,7 +327,7 @@ static const char *trsp_flag[2] = { "POSITIVE-RESPONSE", "NEGATIVE-RESPONSE" }; | ||
327 | // #endif | 327 | // #endif |
328 | 328 | ||
329 | #if defined(HAVE_LIBSSL) /*[*/ | 329 | #if defined(HAVE_LIBSSL) /*[*/ |
330 | -static Boolean need_tls_follows = False; | 330 | +// static Boolean need_tls_follows = False; |
331 | static void ssl_init(H3270 *session); | 331 | static void ssl_init(H3270 *session); |
332 | #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ | 332 | #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ |
333 | #define INFO_CONST const | 333 | #define INFO_CONST const |
@@ -335,7 +335,7 @@ static void ssl_init(H3270 *session); | @@ -335,7 +335,7 @@ static void ssl_init(H3270 *session); | ||
335 | #define INFO_CONST | 335 | #define INFO_CONST |
336 | #endif /*]*/ | 336 | #endif /*]*/ |
337 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret); | 337 | static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret); |
338 | -static void continue_tls(unsigned char *sbbuf, int len); | 338 | +static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len); |
339 | #endif /*]*/ | 339 | #endif /*]*/ |
340 | 340 | ||
341 | // #if !defined(_WIN32) /*[*/ | 341 | // #if !defined(_WIN32) /*[*/ |
@@ -897,7 +897,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) | @@ -897,7 +897,7 @@ LIB3270_EXPORT void lib3270_setup_session(H3270 *hSession) | ||
897 | #endif /*]*/ | 897 | #endif /*]*/ |
898 | 898 | ||
899 | #if defined(HAVE_LIBSSL) /*[*/ | 899 | #if defined(HAVE_LIBSSL) /*[*/ |
900 | - need_tls_follows = False; | 900 | + hSession->need_tls_follows = 0; |
901 | #endif /*]*/ | 901 | #endif /*]*/ |
902 | hSession->telnet_state = TNS_DATA; | 902 | hSession->telnet_state = TNS_DATA; |
903 | hSession->ibptr = hSession->ibuf; | 903 | hSession->ibptr = hSession->ibuf; |
@@ -1471,7 +1471,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) | @@ -1471,7 +1471,7 @@ static int telnet_fsm(H3270 *session, unsigned char c) | ||
1471 | cmd(SB), | 1471 | cmd(SB), |
1472 | opt(TELOPT_STARTTLS), | 1472 | opt(TELOPT_STARTTLS), |
1473 | cmd(SE)); | 1473 | cmd(SE)); |
1474 | - need_tls_follows = True; | 1474 | + session->need_tls_follows = 1; |
1475 | } | 1475 | } |
1476 | #endif /*]*/ | 1476 | #endif /*]*/ |
1477 | break; | 1477 | break; |
@@ -1559,9 +1559,9 @@ static int telnet_fsm(H3270 *session, unsigned char c) | @@ -1559,9 +1559,9 @@ static int telnet_fsm(H3270 *session, unsigned char c) | ||
1559 | } | 1559 | } |
1560 | #endif /*]*/ | 1560 | #endif /*]*/ |
1561 | #if defined(HAVE_LIBSSL) /*[*/ | 1561 | #if defined(HAVE_LIBSSL) /*[*/ |
1562 | - else if (need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) | 1562 | + else if (session->need_tls_follows && session->myopts[TELOPT_STARTTLS] && session->sbbuf[0] == TELOPT_STARTTLS) |
1563 | { | 1563 | { |
1564 | - continue_tls(session->sbbuf, session->sbptr - session->sbbuf); | 1564 | + continue_tls(session,session->sbbuf, session->sbptr - session->sbbuf); |
1565 | } | 1565 | } |
1566 | #endif /*]*/ | 1566 | #endif /*]*/ |
1567 | 1567 | ||
@@ -2851,43 +2851,6 @@ static void tn3270e_nak(H3270 *hSession, enum pds rv) | @@ -2851,43 +2851,6 @@ static void tn3270e_nak(H3270 *hSession, enum pds rv) | ||
2851 | trace_dsn(hSession,"SENT TN3270E(RESPONSE NEGATIVE-RESPONSE %u) %s\n",h_in->seq_number[0] << 8 | h_in->seq_number[1], neg); | 2851 | trace_dsn(hSession,"SENT TN3270E(RESPONSE NEGATIVE-RESPONSE %u) %s\n",h_in->seq_number[0] << 8 | h_in->seq_number[1], neg); |
2852 | net_rawout(hSession, rsp_buf, rsp_len); | 2852 | net_rawout(hSession, rsp_buf, rsp_len); |
2853 | } | 2853 | } |
2854 | - | ||
2855 | -/* | ||
2856 | -#if defined(X3270_TRACE) | ||
2857 | -// Add a dummy TN3270E header to the output buffer. | ||
2858 | -Boolean | ||
2859 | -net_add_dummy_tn3270e(void) | ||
2860 | -{ | ||
2861 | - tn3270e_header *h; | ||
2862 | - | ||
2863 | - if (!IN_E || h3270.tn3270e_submode == E_NONE) | ||
2864 | - return False; | ||
2865 | - | ||
2866 | - space3270out(&h3270,EH_SIZE); | ||
2867 | - h = (tn3270e_header *)h3270.obptr; | ||
2868 | - | ||
2869 | - switch (h3270.tn3270e_submode) { | ||
2870 | - case E_NONE: | ||
2871 | - break; | ||
2872 | - case E_NVT: | ||
2873 | - h->data_type = TN3270E_DT_NVT_DATA; | ||
2874 | - break; | ||
2875 | - case E_SSCP: | ||
2876 | - h->data_type = TN3270E_DT_SSCP_LU_DATA; | ||
2877 | - break; | ||
2878 | - case E_3270: | ||
2879 | - h->data_type = TN3270E_DT_3270_DATA; | ||
2880 | - break; | ||
2881 | - } | ||
2882 | - h->request_flag = 0; | ||
2883 | - h->response_flag = TN3270E_RSF_NO_RESPONSE; | ||
2884 | - h->seq_number[0] = 0; | ||
2885 | - h->seq_number[1] = 0; | ||
2886 | - h3270.obptr += EH_SIZE; | ||
2887 | - return True; | ||
2888 | -} | ||
2889 | -#endif | ||
2890 | -*/ | ||
2891 | #endif /*]*/ | 2854 | #endif /*]*/ |
2892 | 2855 | ||
2893 | #if defined(X3270_TRACE) /*[*/ | 2856 | #if defined(X3270_TRACE) /*[*/ |
@@ -3276,68 +3239,71 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) | @@ -3276,68 +3239,71 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) | ||
3276 | } | 3239 | } |
3277 | } | 3240 | } |
3278 | 3241 | ||
3279 | -/* Process a STARTTLS subnegotiation. */ | ||
3280 | -static void continue_tls(unsigned char *sbbuf, int len) | 3242 | +/** |
3243 | + * Process a STARTTLS subnegotiation. | ||
3244 | + */ | ||
3245 | +static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len) | ||
3281 | { | 3246 | { |
3282 | int rv; | 3247 | int rv; |
3283 | 3248 | ||
3284 | /* Whatever happens, we're not expecting another SB STARTTLS. */ | 3249 | /* Whatever happens, we're not expecting another SB STARTTLS. */ |
3285 | - need_tls_follows = False; | 3250 | + hSession->need_tls_follows = 0; |
3286 | 3251 | ||
3287 | /* Make sure the option is FOLLOWS. */ | 3252 | /* Make sure the option is FOLLOWS. */ |
3288 | - if (len < 2 || sbbuf[1] != TLS_FOLLOWS) { | 3253 | + if (len < 2 || sbbuf[1] != TLS_FOLLOWS) |
3254 | + { | ||
3289 | /* Trace the junk. */ | 3255 | /* Trace the junk. */ |
3290 | - trace_dsn(&h3270,"%s ? %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | ||
3291 | - popup_an_error(NULL,"TLS negotiation failure"); | ||
3292 | - net_disconnect(&h3270); | 3256 | + trace_dsn(hSession,"%s ? %s\n", opt(TELOPT_STARTTLS), cmd(SE)); |
3257 | + popup_an_error(hSession,_( "TLS negotiation failure")); | ||
3258 | + net_disconnect(hSession); | ||
3293 | return; | 3259 | return; |
3294 | } | 3260 | } |
3295 | 3261 | ||
3296 | /* Trace what we got. */ | 3262 | /* Trace what we got. */ |
3297 | - trace_dsn(&h3270,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); | 3263 | + trace_dsn(hSession,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); |
3298 | 3264 | ||
3299 | /* Initialize the SSL library. */ | 3265 | /* Initialize the SSL library. */ |
3300 | - ssl_init(&h3270); | ||
3301 | - if(h3270.ssl_con == NULL) | 3266 | + ssl_init(hSession); |
3267 | + if(hSession->ssl_con == NULL) | ||
3302 | { | 3268 | { |
3303 | /* Failed. */ | 3269 | /* Failed. */ |
3304 | - net_disconnect(&h3270); | 3270 | + net_disconnect(hSession); |
3305 | return; | 3271 | return; |
3306 | } | 3272 | } |
3307 | 3273 | ||
3308 | /* Set up the TLS/SSL connection. */ | 3274 | /* Set up the TLS/SSL connection. */ |
3309 | - if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1) | 3275 | + if(SSL_set_fd(hSession->ssl_con, hSession->sock) != 1) |
3310 | { | 3276 | { |
3311 | - trace_dsn(&h3270,"SSL_set_fd failed!\n"); | 3277 | + trace_dsn(hSession,"SSL_set_fd failed!\n"); |
3312 | } | 3278 | } |
3313 | 3279 | ||
3314 | //#if defined(_WIN32) | 3280 | //#if defined(_WIN32) |
3315 | // /* Make the socket blocking for SSL. */ | 3281 | // /* Make the socket blocking for SSL. */ |
3316 | -// (void) WSAEventSelect(h3270.sock, h3270.sock_handle, 0); | 3282 | +// (void) WSAEventSelect(hSession->sock, hSession->sock_handle, 0); |
3317 | // (void) non_blocking(False); | 3283 | // (void) non_blocking(False); |
3318 | //#endif | 3284 | //#endif |
3319 | 3285 | ||
3320 | - rv = SSL_connect(h3270.ssl_con); | 3286 | + rv = SSL_connect(hSession->ssl_con); |
3321 | 3287 | ||
3322 | //#if defined(_WIN32) | 3288 | //#if defined(_WIN32) |
3323 | // // Make the socket non-blocking again for event processing | 3289 | // // Make the socket non-blocking again for event processing |
3324 | -// (void) WSAEventSelect(h3270.sock, h3270.sock_handle, FD_READ | FD_CONNECT | FD_CLOSE); | 3290 | +// (void) WSAEventSelect(hSession->sock, hSession->sock_handle, FD_READ | FD_CONNECT | FD_CLOSE); |
3325 | //#endif | 3291 | //#endif |
3326 | 3292 | ||
3327 | if (rv != 1) | 3293 | if (rv != 1) |
3328 | { | 3294 | { |
3329 | - trace_dsn(&h3270,"continue_tls: SSL_connect failed\n"); | ||
3330 | - net_disconnect(&h3270); | 3295 | + trace_dsn(hSession,"continue_tls: SSL_connect failed\n"); |
3296 | + net_disconnect(hSession); | ||
3331 | return; | 3297 | return; |
3332 | } | 3298 | } |
3333 | 3299 | ||
3334 | -// h3270.secure_connection = True; | 3300 | +// hSession->secure_connection = True; |
3335 | 3301 | ||
3336 | /* Success. */ | 3302 | /* Success. */ |
3337 | -// trace_dsn(&h3270,"TLS/SSL negotiated connection complete. Connection is now secure.\n"); | 3303 | +// trace_dsn(hSession,"TLS/SSL negotiated connection complete. Connection is now secure.\n"); |
3338 | 3304 | ||
3339 | /* Tell the world that we are (still) connected, now in secure mode. */ | 3305 | /* Tell the world that we are (still) connected, now in secure mode. */ |
3340 | - lib3270_set_connected(&h3270); | 3306 | + lib3270_set_connected(hSession); |
3341 | } | 3307 | } |
3342 | 3308 | ||
3343 | #endif /*]*/ | 3309 | #endif /*]*/ |