| 47 |
#include "ssh.h" |
#include "ssh.h" |
| 48 |
#include "crypt.h" |
#include "crypt.h" |
| 49 |
#include "fwd.h" |
#include "fwd.h" |
| 50 |
|
#include "sftp.h" |
| 51 |
|
|
| 52 |
#include <sys/types.h> |
#include <sys/types.h> |
| 53 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 72 |
#define CHANNEL_MAX 100 |
#define CHANNEL_MAX 100 |
| 73 |
|
|
| 74 |
enum channel_type { |
enum channel_type { |
| 75 |
TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, |
TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, |
| 76 |
}; |
}; |
| 77 |
|
|
| 78 |
enum scp_state { |
enum scp_state { |
| 3494 |
} |
} |
| 3495 |
|
|
| 3496 |
|
|
| 3497 |
|
int SSH_sftp_transaction(PTInstVar pvar) |
| 3498 |
|
{ |
| 3499 |
|
buffer_t *msg; |
| 3500 |
|
char *s; |
| 3501 |
|
unsigned char *outmsg; |
| 3502 |
|
int len; |
| 3503 |
|
Channel_t *c = NULL; |
| 3504 |
|
// FILE *fp = NULL; |
| 3505 |
|
// struct _stat st; |
| 3506 |
|
|
| 3507 |
|
// ソケットがクローズされている場合は何もしない。 |
| 3508 |
|
if (pvar->socket == INVALID_SOCKET) |
| 3509 |
|
goto error; |
| 3510 |
|
|
| 3511 |
|
if (SSHv1(pvar)) // SSH1サポートはTBD |
| 3512 |
|
goto error; |
| 3513 |
|
|
| 3514 |
|
// チャネル設定 |
| 3515 |
|
c = ssh2_channel_new(CHAN_SES_WINDOW_DEFAULT, CHAN_SES_PACKET_DEFAULT, TYPE_SFTP, -1); |
| 3516 |
|
if (c == NULL) { |
| 3517 |
|
UTIL_get_lang_msg("MSG_SSH_NO_FREE_CHANNEL", pvar, |
| 3518 |
|
"Could not open new channel. TTSSH is already opening too many channels."); |
| 3519 |
|
notify_fatal_error(pvar, pvar->ts->UIMsg); |
| 3520 |
|
goto error; |
| 3521 |
|
} |
| 3522 |
|
|
| 3523 |
|
// session open |
| 3524 |
|
msg = buffer_init(); |
| 3525 |
|
if (msg == NULL) { |
| 3526 |
|
goto error; |
| 3527 |
|
} |
| 3528 |
|
s = "session"; |
| 3529 |
|
buffer_put_string(msg, s, strlen(s)); // ctype |
| 3530 |
|
buffer_put_int(msg, c->self_id); // self(channel number) |
| 3531 |
|
buffer_put_int(msg, c->local_window); // local_window |
| 3532 |
|
buffer_put_int(msg, c->local_maxpacket); // local_maxpacket |
| 3533 |
|
len = buffer_len(msg); |
| 3534 |
|
outmsg = begin_send_packet(pvar, SSH2_MSG_CHANNEL_OPEN, len); |
| 3535 |
|
memcpy(outmsg, buffer_ptr (msg), len); |
| 3536 |
|
finish_send_packet(pvar); |
| 3537 |
|
buffer_free(msg); |
| 3538 |
|
|
| 3539 |
|
return TRUE; |
| 3540 |
|
|
| 3541 |
|
error: |
| 3542 |
|
if (c != NULL) |
| 3543 |
|
ssh2_channel_delete(c); |
| 3544 |
|
|
| 3545 |
|
return FALSE; |
| 3546 |
|
} |
| 3547 |
|
|
| 3548 |
|
|
| 3549 |
///////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////// |
| 3550 |
// |
// |
| 3551 |
// SSH2 protocol procedure in the following code: |
// SSH2 protocol procedure in the following code: |
| 6945 |
buffer_put_int(msg, remote_id); |
buffer_put_int(msg, remote_id); |
| 6946 |
if (c->type == TYPE_SCP) { |
if (c->type == TYPE_SCP) { |
| 6947 |
s = "exec"; |
s = "exec"; |
| 6948 |
} else { |
} else if (c->type == TYPE_SFTP) { |
| 6949 |
|
s = "subsystem"; |
| 6950 |
|
} else if (c->type == TYPE_SHELL) { |
| 6951 |
s = "pty-req"; // pseudo terminalのリクエスト |
s = "pty-req"; // pseudo terminalのリクエスト |
| 6952 |
|
} else { |
| 6953 |
|
s = ""; // NOT REACHED |
| 6954 |
} |
} |
| 6955 |
buffer_put_string(msg, s, strlen(s)); |
buffer_put_string(msg, s, strlen(s)); |
| 6956 |
buffer_put_char(msg, wantconfirm); // wantconfirm (disableに変更 2005/3/28 yutaka) |
buffer_put_char(msg, wantconfirm); // wantconfirm (disableに変更 2005/3/28 yutaka) |
| 6968 |
goto done; |
goto done; |
| 6969 |
} |
} |
| 6970 |
|
|
| 6971 |
|
if (c->type == TYPE_SFTP) { |
| 6972 |
|
char *sbuf = "sftp"; |
| 6973 |
|
buffer_put_string(msg, sbuf, strlen(sbuf)); |
| 6974 |
|
goto done; |
| 6975 |
|
} |
| 6976 |
|
|
| 6977 |
s = pvar->ts->TermType; // TERM |
s = pvar->ts->TermType; // TERM |
| 6978 |
buffer_put_string(msg, s, strlen(s)); |
buffer_put_string(msg, s, strlen(s)); |
| 6979 |
buffer_put_int(msg, pvar->ssh_state.win_cols); // columns |
buffer_put_int(msg, pvar->ssh_state.win_cols); // columns |
| 7649 |
|
|
| 7650 |
} else if (c->type == TYPE_SCP) { // SCP |
} else if (c->type == TYPE_SCP) { // SCP |
| 7651 |
SSH2_scp_response(pvar, c, data, str_len); |
SSH2_scp_response(pvar, c, data, str_len); |
| 7652 |
|
|
| 7653 |
|
} else if (c->type == TYPE_SFTP) { // SFTP |
| 7654 |
|
|
| 7655 |
|
|
| 7656 |
} |
} |
| 7657 |
|
|
| 7658 |
//debug_print(200, data, strlen); |
//debug_print(200, data, strlen); |