svnno****@sourc*****
svnno****@sourc*****
2017年 8月 25日 (金) 23:48:06 JST
Revision: 6905 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6905 Author: doda Date: 2017-08-25 23:48:06 +0900 (Fri, 25 Aug 2017) Log Message: ----------- ssh 転送関連を修正。 ・使用しなくなった RtoL 転送をキャンセルするようにした。(除くX11 Forwarding) ・server_listening_specs を更新するようにした。 Modified Paths: -------------- trunk/ttssh2/ttxssh/fwd.c -------------- next part -------------- Modified: trunk/ttssh2/ttxssh/fwd.c =================================================================== --- trunk/ttssh2/ttxssh/fwd.c 2017-08-25 14:48:03 UTC (rev 6904) +++ trunk/ttssh2/ttxssh/fwd.c 2017-08-25 14:48:06 UTC (rev 6905) @@ -1163,7 +1163,9 @@ { FWDRequestSpec *new_specs = (FWDRequestSpec *) malloc(sizeof(FWDRequestSpec) * num_specs); + FWDRequestSpec *server_listening_specs = pvar->fwd_state.server_listening_specs; char *specs_accounted_for; + char *listening_specs_remain_for = NULL; typedef struct _saved_sockets { SOCKET *listening_sockets; int num_listening_sockets; @@ -1173,6 +1175,9 @@ int num_new_requests = num_specs; int num_free_requests = 0; int free_request = 0; + int num_new_listening = 0; + int num_cur_listening = pvar->fwd_state.num_server_listening_specs; + int x11_listening = -1; BOOL report_err = TRUE; memcpy(new_specs, specs, sizeof(FWDRequestSpec) * num_specs); @@ -1216,10 +1221,10 @@ logprintf(150, __FUNCTION__ ": #%d: %s", i, dump_fwdspec(new_specs+i, 0)); } - logprintf(150, __FUNCTION__ ": listening specs: %d", pvar->fwd_state.num_server_listening_specs); - for (i=0; i < pvar->fwd_state.num_server_listening_specs; i++) { + logprintf(150, __FUNCTION__ ": listening specs: %d", num_cur_listening); + for (i=0; i < num_cur_listening; i++) { logprintf(150, __FUNCTION__ ": #%d: %s", i, - dump_fwdspec(&pvar->fwd_state.server_listening_specs[i], 0)); + dump_fwdspec(&server_listening_specs[i], 0)); } } @@ -1278,6 +1283,11 @@ pvar->fwd_state.num_requests = total_requests; } + if (num_cur_listening > 0) { + listening_specs_remain_for = (char *) malloc(sizeof(char) * num_cur_listening); + memset(listening_specs_remain_for, 0, num_cur_listening); + } + for (i = 0; i < num_specs; i++) { if (!specs_accounted_for[i]) { while ((pvar->fwd_state.requests[free_request].status & FWD_DELETED) == 0 @@ -1296,8 +1306,64 @@ free_request++; } + + // \x8DX\x90V\x8C\xE3\x82\xE0\x83T\x81[\x83o\x91\xA4\x82\xC5 listen \x82\xB5\x91\xB1\x82\xAF\x82邩\x82̃}\x81[\x83N\x95t\x82\xAF + if (new_specs[i].type == FWD_REMOTE_TO_LOCAL) { + if (num_cur_listening > 0) { + FWDRequestSpec *listening_spec = + bsearch(&new_specs[i], server_listening_specs, num_specs, sizeof(FWDRequestSpec), FWD_compare_specs); + if (listening_spec != NULL) { + listening_specs_remain_for[listening_spec - server_listening_specs] = 1; + } + } + num_new_listening++; + } } + for (i = 0; i < num_cur_listening; i++) { + FWDRequestSpec *lspec = &server_listening_specs[i]; + if (lspec->type == FWD_REMOTE_X11_TO_LOCAL) { + // X11 \x93]\x91\x97\x82̓L\x83\x83\x83\x93\x83Z\x83\x8B\x82ł\xAB\x82Ȃ\xA2\x82̂ŁA\x82\xBB\x82̂܂܈\xF8\x82\xAB\x8Cp\x82\xAE + // \x88\xF8\x82\xAB\x8Cp\x82\xAE\x88ׂɏꏊ\x82\xF0\x8Ao\x82\xA6\x82Ă\xA8\x82\xAD + x11_listening = i; + num_new_listening++; + } + else if (!listening_specs_remain_for[i]) { + SSH_cancel_request_forwarding(pvar, lspec->bind_address, lspec->from_port, 0); + } + } + + if (x11_listening > 0) { + // X11 \x93]\x91\x97\x82\xAA\x97L\x82\xC1\x82\xBD\x8Fꍇ\x82͐擪\x82Ɉړ\xAE\x82\xB7\x82\xE9 (realloc\x82ŏ\xC1\x82\xB3\x82\xEA\x82Ȃ\xA2\x82悤\x82ɂ\xB7\x82\xE9\x88\xD7) + server_listening_specs[0] = server_listening_specs[x11_listening]; + } + + if (num_new_listening > 0) { + if (num_cur_listening >= 0) { + server_listening_specs = realloc(server_listening_specs, sizeof(FWDRequestSpec) * num_new_listening); + if (server_listening_specs) { + FWDRequestSpec *dst = server_listening_specs; + if (x11_listening >= 0) { + dst++; + } + for (i=0; i < num_specs; i++) { + if (new_specs[i].type == FWD_REMOTE_TO_LOCAL) { + *dst = new_specs[i]; + dst++; + } + } + qsort(server_listening_specs, num_new_listening, sizeof(FWDRequestSpec), FWD_compare_specs); + pvar->fwd_state.server_listening_specs = server_listening_specs; + pvar->fwd_state.num_server_listening_specs = num_new_listening; + } + } + } + else if (num_cur_listening > 0) { + free(server_listening_specs); + pvar->fwd_state.server_listening_specs = NULL; + pvar->fwd_state.num_server_listening_specs = 0; + } + if (LogLevel(pvar, 150)) { logprintf(150, __FUNCTION__ ": updated specs: %d", pvar->fwd_state.num_requests); for (i=0; i < pvar->fwd_state.num_requests; i++) { @@ -1304,10 +1370,15 @@ logprintf(150, __FUNCTION__ ": #%d: %s", i, dump_fwdspec(&pvar->fwd_state.requests[i].spec, pvar->fwd_state.requests[i].status)); } + logprintf(150, __FUNCTION__ ": new listening specs: %d", pvar->fwd_state.num_server_listening_specs); + for (i=0; i < pvar->fwd_state.num_server_listening_specs; i++) { + logprintf(150, __FUNCTION__ ": #%d: %s", i, + dump_fwdspec(&pvar->fwd_state.server_listening_specs[i], 0)); + } } - free(ptr_to_saved_sockets); + free(listening_specs_remain_for); free(specs_accounted_for); free(new_specs); }