• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision6905 (tree)
Time2017-08-25 23:48:06
Authordoda

Log Message

ssh 転送関連を修正。

・使用しなくなった RtoL 転送をキャンセルするようにした。(除くX11 Forwarding)
・server_listening_specs を更新するようにした。

Change Summary

Incremental Difference

--- trunk/ttssh2/ttxssh/fwd.c (revision 6904)
+++ trunk/ttssh2/ttxssh/fwd.c (revision 6905)
@@ -1163,7 +1163,9 @@
11631163 {
11641164 FWDRequestSpec *new_specs =
11651165 (FWDRequestSpec *) malloc(sizeof(FWDRequestSpec) * num_specs);
1166+ FWDRequestSpec *server_listening_specs = pvar->fwd_state.server_listening_specs;
11661167 char *specs_accounted_for;
1168+ char *listening_specs_remain_for = NULL;
11671169 typedef struct _saved_sockets {
11681170 SOCKET *listening_sockets;
11691171 int num_listening_sockets;
@@ -1173,6 +1175,9 @@
11731175 int num_new_requests = num_specs;
11741176 int num_free_requests = 0;
11751177 int free_request = 0;
1178+ int num_new_listening = 0;
1179+ int num_cur_listening = pvar->fwd_state.num_server_listening_specs;
1180+ int x11_listening = -1;
11761181 BOOL report_err = TRUE;
11771182
11781183 memcpy(new_specs, specs, sizeof(FWDRequestSpec) * num_specs);
@@ -1216,10 +1221,10 @@
12161221 logprintf(150, __FUNCTION__ ": #%d: %s", i, dump_fwdspec(new_specs+i, 0));
12171222 }
12181223
1219- logprintf(150, __FUNCTION__ ": listening specs: %d", pvar->fwd_state.num_server_listening_specs);
1220- for (i=0; i < pvar->fwd_state.num_server_listening_specs; i++) {
1224+ logprintf(150, __FUNCTION__ ": listening specs: %d", num_cur_listening);
1225+ for (i=0; i < num_cur_listening; i++) {
12211226 logprintf(150, __FUNCTION__ ": #%d: %s", i,
1222- dump_fwdspec(&pvar->fwd_state.server_listening_specs[i], 0));
1227+ dump_fwdspec(&server_listening_specs[i], 0));
12231228 }
12241229 }
12251230
@@ -1278,6 +1283,11 @@
12781283 pvar->fwd_state.num_requests = total_requests;
12791284 }
12801285
1286+ if (num_cur_listening > 0) {
1287+ listening_specs_remain_for = (char *) malloc(sizeof(char) * num_cur_listening);
1288+ memset(listening_specs_remain_for, 0, num_cur_listening);
1289+ }
1290+
12811291 for (i = 0; i < num_specs; i++) {
12821292 if (!specs_accounted_for[i]) {
12831293 while ((pvar->fwd_state.requests[free_request].status & FWD_DELETED) == 0
@@ -1296,8 +1306,64 @@
12961306
12971307 free_request++;
12981308 }
1309+
1310+ // 更新後もサーバ側で listen し続けるかのマーク付け
1311+ if (new_specs[i].type == FWD_REMOTE_TO_LOCAL) {
1312+ if (num_cur_listening > 0) {
1313+ FWDRequestSpec *listening_spec =
1314+ bsearch(&new_specs[i], server_listening_specs, num_specs, sizeof(FWDRequestSpec), FWD_compare_specs);
1315+ if (listening_spec != NULL) {
1316+ listening_specs_remain_for[listening_spec - server_listening_specs] = 1;
1317+ }
1318+ }
1319+ num_new_listening++;
1320+ }
12991321 }
13001322
1323+ for (i = 0; i < num_cur_listening; i++) {
1324+ FWDRequestSpec *lspec = &server_listening_specs[i];
1325+ if (lspec->type == FWD_REMOTE_X11_TO_LOCAL) {
1326+ // X11 転送はキャンセルできないので、そのまま引き継ぐ
1327+ // 引き継ぐ為に場所を覚えておく
1328+ x11_listening = i;
1329+ num_new_listening++;
1330+ }
1331+ else if (!listening_specs_remain_for[i]) {
1332+ SSH_cancel_request_forwarding(pvar, lspec->bind_address, lspec->from_port, 0);
1333+ }
1334+ }
1335+
1336+ if (x11_listening > 0) {
1337+ // X11 転送が有った場合は先頭に移動する (reallocで消されないようにする為)
1338+ server_listening_specs[0] = server_listening_specs[x11_listening];
1339+ }
1340+
1341+ if (num_new_listening > 0) {
1342+ if (num_cur_listening >= 0) {
1343+ server_listening_specs = realloc(server_listening_specs, sizeof(FWDRequestSpec) * num_new_listening);
1344+ if (server_listening_specs) {
1345+ FWDRequestSpec *dst = server_listening_specs;
1346+ if (x11_listening >= 0) {
1347+ dst++;
1348+ }
1349+ for (i=0; i < num_specs; i++) {
1350+ if (new_specs[i].type == FWD_REMOTE_TO_LOCAL) {
1351+ *dst = new_specs[i];
1352+ dst++;
1353+ }
1354+ }
1355+ qsort(server_listening_specs, num_new_listening, sizeof(FWDRequestSpec), FWD_compare_specs);
1356+ pvar->fwd_state.server_listening_specs = server_listening_specs;
1357+ pvar->fwd_state.num_server_listening_specs = num_new_listening;
1358+ }
1359+ }
1360+ }
1361+ else if (num_cur_listening > 0) {
1362+ free(server_listening_specs);
1363+ pvar->fwd_state.server_listening_specs = NULL;
1364+ pvar->fwd_state.num_server_listening_specs = 0;
1365+ }
1366+
13011367 if (LogLevel(pvar, 150)) {
13021368 logprintf(150, __FUNCTION__ ": updated specs: %d", pvar->fwd_state.num_requests);
13031369 for (i=0; i < pvar->fwd_state.num_requests; i++) {
@@ -1304,10 +1370,15 @@
13041370 logprintf(150, __FUNCTION__ ": #%d: %s", i,
13051371 dump_fwdspec(&pvar->fwd_state.requests[i].spec, pvar->fwd_state.requests[i].status));
13061372 }
1373+ logprintf(150, __FUNCTION__ ": new listening specs: %d", pvar->fwd_state.num_server_listening_specs);
1374+ for (i=0; i < pvar->fwd_state.num_server_listening_specs; i++) {
1375+ logprintf(150, __FUNCTION__ ": #%d: %s", i,
1376+ dump_fwdspec(&pvar->fwd_state.server_listening_specs[i], 0));
1377+ }
13071378 }
13081379
1309-
13101380 free(ptr_to_saved_sockets);
1381+ free(listening_specs_remain_for);
13111382 free(specs_accounted_for);
13121383 free(new_specs);
13131384 }
Show on old repository browser