| 84 |
|
|
| 85 |
static char ssh_ttymodes[] = "\x01\x03\x02\x1c\x03\x08\x04\x15\x05\x04"; |
static char ssh_ttymodes[] = "\x01\x03\x02\x1c\x03\x08\x04\x15\x05\x04"; |
| 86 |
|
|
| 87 |
|
static CRITICAL_SECTION g_ssh_scp_lock; /* SCP受信用ロック */ |
| 88 |
|
|
| 89 |
static void try_send_credentials(PTInstVar pvar); |
static void try_send_credentials(PTInstVar pvar); |
| 90 |
static void prep_compression(PTInstVar pvar); |
static void prep_compression(PTInstVar pvar); |
| 91 |
|
|
| 124 |
static void start_ssh_heartbeat_thread(PTInstVar pvar); |
static void start_ssh_heartbeat_thread(PTInstVar pvar); |
| 125 |
void ssh2_channel_send_close(PTInstVar pvar, Channel_t *c); |
void ssh2_channel_send_close(PTInstVar pvar, Channel_t *c); |
| 126 |
static BOOL SSH_agent_response(PTInstVar pvar, Channel_t *c, int local_channel_num, unsigned char *data, unsigned int buflen); |
static BOOL SSH_agent_response(PTInstVar pvar, Channel_t *c, int local_channel_num, unsigned char *data, unsigned int buflen); |
| 127 |
|
static void ssh2_scp_get_packetlist(Channel_t *c, unsigned char **buf, unsigned int *buflen); |
| 128 |
|
static void ssh2_scp_free_packetlist(Channel_t *c); |
| 129 |
|
|
| 130 |
|
|
| 131 |
// |
// |
| 132 |
// Global request confirm |
// Global request confirm |
| 305 |
CloseHandle(c->scp.thread); |
CloseHandle(c->scp.thread); |
| 306 |
c->scp.thread = (HANDLE)-1L; |
c->scp.thread = (HANDLE)-1L; |
| 307 |
} |
} |
| 308 |
|
|
| 309 |
|
ssh2_scp_free_packetlist(c); |
| 310 |
} |
} |
| 311 |
if (c->type == TYPE_AGENT) { |
if (c->type == TYPE_AGENT) { |
| 312 |
buffer_free(c->agent_msg); |
buffer_free(c->agent_msg); |
| 8189 |
if (is_canceled_window(hWnd)) |
if (is_canceled_window(hWnd)) |
| 8190 |
goto cancel_abort; |
goto cancel_abort; |
| 8191 |
|
|
| 8192 |
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) { |
ssh2_scp_get_packetlist(c, &data, &buflen); |
| 8193 |
|
if (data && buflen) { |
| 8194 |
|
msg.message = WM_RECEIVING_FILE; |
| 8195 |
|
|
| 8196 |
switch (msg.message) { |
switch (msg.message) { |
| 8197 |
case WM_RECEIVING_FILE: |
case WM_RECEIVING_FILE: |
| 8198 |
data = (unsigned char *)msg.wParam; |
//data = (unsigned char *)msg.wParam; |
| 8199 |
buflen = (unsigned int)msg.lParam; |
//buflen = (unsigned int)msg.lParam; |
| 8200 |
eof = 0; |
eof = 0; |
| 8201 |
|
|
| 8202 |
if (c->scp.filercvsize >= c->scp.filetotalsize) { // EOF |
if (c->scp.filercvsize >= c->scp.filetotalsize) { // EOF |
| 8271 |
return 0; |
return 0; |
| 8272 |
} |
} |
| 8273 |
|
|
| 8274 |
|
static void ssh2_scp_add_packetlist(Channel_t *c, unsigned char *buf, unsigned int buflen) |
| 8275 |
|
{ |
| 8276 |
|
PacketList_t *p, *old; |
| 8277 |
|
|
| 8278 |
|
EnterCriticalSection(&g_ssh_scp_lock); |
| 8279 |
|
|
| 8280 |
|
// allocate new buffer |
| 8281 |
|
p = malloc(sizeof(PacketList_t)); |
| 8282 |
|
if (p == NULL) |
| 8283 |
|
goto error; |
| 8284 |
|
p->buf = buf; |
| 8285 |
|
p->buflen = buflen; |
| 8286 |
|
p->next = NULL; |
| 8287 |
|
|
| 8288 |
|
if (c->scp.pktlist_head == NULL) { |
| 8289 |
|
c->scp.pktlist_head = p; |
| 8290 |
|
c->scp.pktlist_tail = p; |
| 8291 |
|
} |
| 8292 |
|
else { |
| 8293 |
|
old = c->scp.pktlist_tail; |
| 8294 |
|
old->next = p; |
| 8295 |
|
c->scp.pktlist_tail = p; |
| 8296 |
|
} |
| 8297 |
|
|
| 8298 |
|
error:; |
| 8299 |
|
LeaveCriticalSection(&g_ssh_scp_lock); |
| 8300 |
|
} |
| 8301 |
|
|
| 8302 |
|
static void ssh2_scp_get_packetlist(Channel_t *c, unsigned char **buf, unsigned int *buflen) |
| 8303 |
|
{ |
| 8304 |
|
PacketList_t *p; |
| 8305 |
|
|
| 8306 |
|
EnterCriticalSection(&g_ssh_scp_lock); |
| 8307 |
|
|
| 8308 |
|
if (c->scp.pktlist_head == NULL) { |
| 8309 |
|
*buf = NULL; |
| 8310 |
|
*buflen = 0; |
| 8311 |
|
goto end; |
| 8312 |
|
} |
| 8313 |
|
|
| 8314 |
|
p = c->scp.pktlist_head; |
| 8315 |
|
*buf = p->buf; |
| 8316 |
|
*buflen = p->buflen; |
| 8317 |
|
|
| 8318 |
|
c->scp.pktlist_head = p->next; |
| 8319 |
|
|
| 8320 |
|
if (c->scp.pktlist_head == NULL) |
| 8321 |
|
c->scp.pktlist_tail = NULL; |
| 8322 |
|
|
| 8323 |
|
free(p); |
| 8324 |
|
|
| 8325 |
|
end:; |
| 8326 |
|
LeaveCriticalSection(&g_ssh_scp_lock); |
| 8327 |
|
} |
| 8328 |
|
|
| 8329 |
|
static void ssh2_scp_alloc_packetlist(Channel_t *c) |
| 8330 |
|
{ |
| 8331 |
|
c->scp.pktlist_head = NULL; |
| 8332 |
|
c->scp.pktlist_tail = NULL; |
| 8333 |
|
InitializeCriticalSection(&g_ssh_scp_lock); |
| 8334 |
|
} |
| 8335 |
|
|
| 8336 |
|
static void ssh2_scp_free_packetlist(Channel_t *c) |
| 8337 |
|
{ |
| 8338 |
|
PacketList_t *p, *old; |
| 8339 |
|
|
| 8340 |
|
p = c->scp.pktlist_head; |
| 8341 |
|
while (p) { |
| 8342 |
|
old = p; |
| 8343 |
|
p = p->next; |
| 8344 |
|
|
| 8345 |
|
free(old->buf); |
| 8346 |
|
free(old); |
| 8347 |
|
} |
| 8348 |
|
|
| 8349 |
|
c->scp.pktlist_head = NULL; |
| 8350 |
|
c->scp.pktlist_tail = NULL; |
| 8351 |
|
DeleteCriticalSection(&g_ssh_scp_lock); |
| 8352 |
|
} |
| 8353 |
|
|
| 8354 |
static BOOL SSH2_scp_fromremote(PTInstVar pvar, Channel_t *c, unsigned char *data, unsigned int buflen) |
static BOOL SSH2_scp_fromremote(PTInstVar pvar, Channel_t *c, unsigned char *data, unsigned int buflen) |
| 8355 |
{ |
{ |
| 8356 |
int permission; |
int permission; |
| 8404 |
ShowWindow(hDlgWnd, SW_SHOW); |
ShowWindow(hDlgWnd, SW_SHOW); |
| 8405 |
} |
} |
| 8406 |
|
|
| 8407 |
|
ssh2_scp_alloc_packetlist(c); |
| 8408 |
thread = (HANDLE)_beginthreadex(NULL, 0, ssh_scp_receive_thread, c, 0, &tid); |
thread = (HANDLE)_beginthreadex(NULL, 0, ssh_scp_receive_thread, c, 0, &tid); |
| 8409 |
if (thread == (HANDLE)-1) { |
if (thread == (HANDLE)-1) { |
| 8410 |
// TODO: |
// TODO: |
| 8426 |
|
|
| 8427 |
} else if (c->scp.state == SCP_DATA) { // payloadの受信 |
} else if (c->scp.state == SCP_DATA) { // payloadの受信 |
| 8428 |
unsigned char *newdata = malloc(buflen); |
unsigned char *newdata = malloc(buflen); |
|
BOOL ret; |
|
|
DWORD texit; |
|
| 8429 |
if (newdata != NULL) { |
if (newdata != NULL) { |
| 8430 |
memcpy(newdata, data, buflen); |
memcpy(newdata, data, buflen); |
|
do { |
|
|
// SCPファイル受信中に、ファイル受信を中断すると、無限ループに陥ることがあるため、 |
|
|
// スレッドが終了しているかどうかを判別する。 |
|
|
// (2014.7.6 yutaka) |
|
|
texit = STILL_ACTIVE; |
|
|
GetExitCodeThread(c->scp.thread, &texit); |
|
|
if (texit != STILL_ACTIVE) { |
|
|
texit = texit; |
|
|
break; |
|
|
} |
|
| 8431 |
|
|
| 8432 |
// スレッドがキューを作っていない場合、メッセージポストが失敗することがあるので、 |
// SCP受信処理のスピードが速い場合、スレッドのメッセージキューがフル(10000個)に |
| 8433 |
// 無限リトライする。MSDNにそうしろと書いてある。 |
// なり、かつスレッド上での SendMessage がブロックすることにより、Tera Term(TTSSH) |
| 8434 |
// (2011.6.15 yutaka) |
// 自体がストールしてしまう。この問題を回避するため、スレッドのメッセージキューを |
| 8435 |
ret = PostThreadMessage(c->scp.thread_id, WM_RECEIVING_FILE, (WPARAM)newdata, (LPARAM)buflen); |
// 使うのをやめて、リンクドリスト方式に切り替える。 |
| 8436 |
} while (ret == FALSE); |
// (2016.11.3 yutaka) |
| 8437 |
|
ssh2_scp_add_packetlist(c, newdata, buflen); |
| 8438 |
} |
} |
| 8439 |
|
|
| 8440 |
} else if (c->scp.state == SCP_CLOSING) { // EOFの受信 |
} else if (c->scp.state == SCP_CLOSING) { // EOFの受信 |