Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 7641 by zmatsuo, Wed May 1 14:51:20 2019 UTC revision 7649 by zmatsuo, Mon May 6 13:42:01 2019 UTC
# Line 84  Line 84 
84  //  //
85  #define NonNull(msg) ((msg)?(msg):"(null)")  #define NonNull(msg) ((msg)?(msg):"(null)")
86    
 #if defined(__MINGW32__)  
 #define __FUNCTION__  
 #endif  
   
87  typedef enum {  typedef enum {
88          GetPayloadError = 0,          GetPayloadError = 0,
89          GetPayloadOK = 1,          GetPayloadOK = 1,
# Line 360  static Channel_t *ssh2_channel_lookup(in Line 356  static Channel_t *ssh2_channel_lookup(in
356          Channel_t *c;          Channel_t *c;
357    
358          if (id < 0 || id >= CHANNEL_MAX) {          if (id < 0 || id >= CHANNEL_MAX) {
359                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": invalid channel id. (%d)", id);                  logprintf(LOG_LEVEL_VERBOSE, "%s: invalid channel id. (%d)", __FUNCTION__, id);
360                  return (NULL);                  return (NULL);
361          }          }
362          c = &channels[id];          c = &channels[id];
363          if (c->used == 0) { // already freed          if (c->used == 0) { // already freed
364                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": channel was already freed. id:%d", id);                  logprintf(LOG_LEVEL_VERBOSE, "%s: channel was already freed. id:%d", __FUNCTION__, id);
365                  return (NULL);                  return (NULL);
366          }          }
367          return (c);          return (c);
# Line 1180  void finish_send_packet_special(PTInstVa Line 1176  void finish_send_packet_special(PTInstVa
1176                          msg = buffer_init();                          msg = buffer_init();
1177                          if (msg == NULL) {                          if (msg == NULL) {
1178                                  // TODO: error check                                  // TODO: error check
1179                                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
1180                                  return;                                  return;
1181                          }                          }
1182    
# Line 1260  void finish_send_packet_special(PTInstVa Line 1256  void finish_send_packet_special(PTInstVa
1256    
1257                  data_length = encryption_size + aadlen + maclen;                  data_length = encryption_size + aadlen + maclen;
1258    
1259                  logprintf(150, __FUNCTION__                  logprintf(150,
1260                          ": built packet info: aadlen:%d, enclen:%d, padlen:%d, datalen:%d, maclen:%d, mode:%s",                                    "%s: built packet info: aadlen:%d, enclen:%d, padlen:%d, datalen:%d, maclen:%d, mode:%s",
1261                          aadlen, encryption_size, padding, data_length, maclen, aadlen ? "EtM" : "E&M");                                    __FUNCTION__,
1262                                      aadlen, encryption_size, padding, data_length, maclen, aadlen ? "EtM" : "E&M");
1263          }          }
1264    
1265          send_packet_blocking(pvar, data, data_length);          send_packet_blocking(pvar, data, data_length);
# Line 2209  void SSH2_dispatch_add_message(unsigned Line 2206  void SSH2_dispatch_add_message(unsigned
2206    
2207          if (handle_message_count >= HANDLE_MESSAGE_MAX) {          if (handle_message_count >= HANDLE_MESSAGE_MAX) {
2208                  // TODO: error check                  // TODO: error check
2209                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": too many handlers. handlers:%d, max:%d",                  logprintf(LOG_LEVEL_ERROR, "%s: too many handlers. handlers:%d, max:%d", __FUNCTION__,
2210                          handle_message_count, HANDLE_MESSAGE_MAX);                          handle_message_count, HANDLE_MESSAGE_MAX);
2211                  return;                  return;
2212          }          }
# Line 2281  void SSH2_handle_packet(PTInstVar pvar, Line 2278  void SSH2_handle_packet(PTInstVar pvar,
2278                          set_uint32(outmsg, pvar->ssh_state.receiver_sequence_number - 1);                          set_uint32(outmsg, pvar->ssh_state.receiver_sequence_number - 1);
2279                          finish_send_packet(pvar);                          finish_send_packet(pvar);
2280    
2281                          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_UNIMPLEMENTED was sent.");                          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_UNIMPLEMENTED was sent.", __FUNCTION__);
2282                          /* XXX need to decompress incoming packet, but how? */                          /* XXX need to decompress incoming packet, but how? */
2283                  } else {                  } else {
2284                          if (!handler(pvar)) {                          if (!handler(pvar)) {
# Line 2888  void SSH_notify_disconnecting(PTInstVar Line 2885  void SSH_notify_disconnecting(PTInstVar
2885                  msg = buffer_init();                  msg = buffer_init();
2886                  if (msg == NULL) {                  if (msg == NULL) {
2887                          // TODO: error check                          // TODO: error check
2888                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
2889                          return;                          return;
2890                  }                  }
2891                  buffer_put_int(msg, SSH2_DISCONNECT_BY_APPLICATION);                  buffer_put_int(msg, SSH2_DISCONNECT_BY_APPLICATION);
# Line 2949  void SSH_notify_win_size(PTInstVar pvar, Line 2946  void SSH_notify_win_size(PTInstVar pvar,
2946                          set_uint32(outmsg + 8, x);    // window width  (pixels)                          set_uint32(outmsg + 8, x);    // window width  (pixels)
2947                          set_uint32(outmsg + 12, y);   // window height (pixels)                          set_uint32(outmsg + 12, y);   // window height (pixels)
2948                          finish_send_packet(pvar);                          finish_send_packet(pvar);
2949                          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH_CMSG_WINDOW_SIZE. "                          logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH_CMSG_WINDOW_SIZE. "
2950                                    "cols: %d, rows: %d, x: %d, y: %d", cols, rows, x, y);                                    "cols: %d, rows: %d, x: %d, y: %d", __FUNCTION__, cols, rows, x, y);
2951                  }                  }
2952    
2953          } else if (SSHv2(pvar)) {          } else if (SSHv2(pvar)) {
# Line 2964  void SSH_notify_win_size(PTInstVar pvar, Line 2961  void SSH_notify_win_size(PTInstVar pvar,
2961    
2962                  c = ssh2_channel_lookup(pvar->shell_id);                  c = ssh2_channel_lookup(pvar->shell_id);
2963                  if (c == NULL) {                  if (c == NULL) {
2964                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
2965                          return;                          return;
2966                  }                  }
2967    
# Line 2972  void SSH_notify_win_size(PTInstVar pvar, Line 2969  void SSH_notify_win_size(PTInstVar pvar,
2969                  msg = buffer_init();                  msg = buffer_init();
2970                  if (msg == NULL) {                  if (msg == NULL) {
2971                          // TODO: error check                          // TODO: error check
2972                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
2973                          return;                          return;
2974                  }                  }
2975                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 2988  void SSH_notify_win_size(PTInstVar pvar, Line 2985  void SSH_notify_win_size(PTInstVar pvar,
2985                  finish_send_packet(pvar);                  finish_send_packet(pvar);
2986                  buffer_free(msg);                  buffer_free(msg);
2987    
2988                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_REQUEST. "                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_CHANNEL_REQUEST. "
2989                            "local: %d, remote: %d, request-type: %s, cols: %d, rows: %d, x: %d, y: %d",                            "local: %d, remote: %d, request-type: %s, cols: %d, rows: %d, x: %d, y: %d", __FUNCTION__,
2990                            c->self_id, c->remote_id, req_type, cols, rows, x, y);                            c->self_id, c->remote_id, req_type, cols, rows, x, y);
2991    
2992          } else {          } else {
# Line 3013  int SSH_notify_break_signal(PTInstVar pv Line 3010  int SSH_notify_break_signal(PTInstVar pv
3010    
3011                  c = ssh2_channel_lookup(pvar->shell_id);                  c = ssh2_channel_lookup(pvar->shell_id);
3012                  if (c == NULL) {                  if (c == NULL) {
3013                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
3014                          goto error;                          goto error;
3015                  }                  }
3016    
3017                  msg = buffer_init();                  msg = buffer_init();
3018                  if (msg == NULL) {                  if (msg == NULL) {
3019                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3020                          goto error;                          goto error;
3021                  }                  }
3022                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 3032  int SSH_notify_break_signal(PTInstVar pv Line 3029  int SSH_notify_break_signal(PTInstVar pv
3029                  finish_send_packet(pvar);                  finish_send_packet(pvar);
3030                  buffer_free(msg);                  buffer_free(msg);
3031    
3032                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_REQUEST. "                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_CHANNEL_REQUEST. "
3033                            "local: %d, remote: %d, request-type: %s, break-length: %d",                            "local: %d, remote: %d, request-type: %s, break-length: %d", __FUNCTION__,
3034                            c->self_id, c->remote_id, req_type, 1000);                            c->self_id, c->remote_id, req_type, 1000);
3035    
3036                  ret = 1;                  ret = 1;
# Line 3166  void SSH_send(PTInstVar pvar, unsigned c Line 3163  void SSH_send(PTInstVar pvar, unsigned c
3163          } else { // for SSH2(yutaka)          } else { // for SSH2(yutaka)
3164                  Channel_t *c = ssh2_channel_lookup(pvar->shell_id);                  Channel_t *c = ssh2_channel_lookup(pvar->shell_id);
3165                  if (c == NULL) {                  if (c == NULL) {
3166                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
3167                  }                  }
3168                  else {                  else {
3169                          SSH2_send_channel_data(pvar, c, (unsigned char *)buf, buflen, 0);                          SSH2_send_channel_data(pvar, c, (unsigned char *)buf, buflen, 0);
# Line 3429  void SSH2_send_channel_data(PTInstVar pv Line 3426  void SSH2_send_channel_data(PTInstVar pv
3426          if (pvar->rekeying) {          if (pvar->rekeying) {
3427                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、
3428                  // 将来直すことにする。                  // 将来直すことにする。
3429                  logputs(LOG_LEVEL_INFO, __FUNCTION__ ": now rekeying. data is not sent.");                  logprintf(LOG_LEVEL_INFO, "%s: now rekeying. data is not sent.", __FUNCTION__);
3430    
3431                  c = NULL;                  c = NULL;
3432    
# Line 3459  void SSH2_send_channel_data(PTInstVar pv Line 3456  void SSH2_send_channel_data(PTInstVar pv
3456                  msg = buffer_init();                  msg = buffer_init();
3457                  if (msg == NULL) {                  if (msg == NULL) {
3458                          // TODO: error check                          // TODO: error check
3459                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3460                          return;                          return;
3461                  }                  }
3462                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 3472  void SSH2_send_channel_data(PTInstVar pv Line 3469  void SSH2_send_channel_data(PTInstVar pv
3469                  finish_send_packet(pvar);                  finish_send_packet(pvar);
3470                  buffer_free(msg);                  buffer_free(msg);
3471    
3472                  logprintf(LOG_LEVEL_SSHDUMP, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_DATA. "                  logprintf(LOG_LEVEL_SSHDUMP, "%s: sending SSH2_MSG_CHANNEL_DATA. "
3473                          "local:%d remote:%d len:%d", c->self_id, c->remote_id, buflen);                                    "local:%d remote:%d len:%d", __FUNCTION__, c->self_id, c->remote_id, buflen);
3474    
3475                  // remote window sizeの調整                  // remote window sizeの調整
3476                  if (buflen <= c->remote_window) {                  if (buflen <= c->remote_window) {
# Line 3558  void SSH_fail_channel_open(PTInstVar pva Line 3555  void SSH_fail_channel_open(PTInstVar pva
3555                  msg = buffer_init();                  msg = buffer_init();
3556                  if (msg == NULL) {                  if (msg == NULL) {
3557                          // TODO: error check                          // TODO: error check
3558                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3559                          return;                          return;
3560                  }                  }
3561                  buffer_put_int(msg, remote_channel_num);                  buffer_put_int(msg, remote_channel_num);
# Line 3588  void SSH2_confirm_channel_open(PTInstVar Line 3585  void SSH2_confirm_channel_open(PTInstVar
3585          msg = buffer_init();          msg = buffer_init();
3586          if (msg == NULL) {          if (msg == NULL) {
3587                  // TODO: error check                  // TODO: error check
3588                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3589                  return;                  return;
3590          }          }
3591          buffer_put_int(msg, c->remote_id);          buffer_put_int(msg, c->remote_id);
# Line 3657  void SSH2_channel_input_eof(PTInstVar pv Line 3654  void SSH2_channel_input_eof(PTInstVar pv
3654          if (pvar->rekeying) {          if (pvar->rekeying) {
3655                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、
3656                  // 将来直すことにする。                  // 将来直すことにする。
3657                  logputs(LOG_LEVEL_INFO, __FUNCTION__ ": now rekeying. data is not sent.");                  logprintf(LOG_LEVEL_INFO, "%s: now rekeying. data is not sent.", __FUNCTION__);
3658    
3659                  c = NULL;                  c = NULL;
3660    
# Line 3667  void SSH2_channel_input_eof(PTInstVar pv Line 3664  void SSH2_channel_input_eof(PTInstVar pv
3664          msg = buffer_init();          msg = buffer_init();
3665          if (msg == NULL) {          if (msg == NULL) {
3666                  // TODO: error check                  // TODO: error check
3667                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3668                  return;                  return;
3669          }          }
3670          buffer_put_int(msg, c->remote_id);  // remote ID          buffer_put_int(msg, c->remote_id);  // remote ID
# Line 3710  void SSH_request_forwarding(PTInstVar pv Line 3707  void SSH_request_forwarding(PTInstVar pv
3707                  unsigned char *outmsg =                  unsigned char *outmsg =
3708                          begin_send_packet(pvar, SSH_CMSG_PORT_FORWARD_REQUEST, 12 + host_len);                          begin_send_packet(pvar, SSH_CMSG_PORT_FORWARD_REQUEST, 12 + host_len);
3709    
3710                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": Forwarding request (SSH1 RtoL): "                  logprintf(LOG_LEVEL_VERBOSE, "%s: Forwarding request (SSH1 RtoL): "
3711                          "remote_port=%d, to_host=%s, to_port=%d",                                    "remote_port=%d, to_host=%s, to_port=%d", __FUNCTION__,
3712                          from_server_port, to_local_host, to_local_port);                          from_server_port, to_local_host, to_local_port);
3713    
3714                  set_uint32(outmsg, from_server_port);                  set_uint32(outmsg, from_server_port);
# Line 3722  void SSH_request_forwarding(PTInstVar pv Line 3719  void SSH_request_forwarding(PTInstVar pv
3719    
3720                  enque_forwarding_request_handlers(pvar);                  enque_forwarding_request_handlers(pvar);
3721    
3722                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH_CMSG_PORT_FORWARD_REQUEST."                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH_CMSG_PORT_FORWARD_REQUEST."
3723                          "remote_port=%d, to_host=%s, to_port=%d",                                    "remote_port=%d, to_host=%s, to_port=%d", __FUNCTION__,
3724                          from_server_port, to_local_host, to_local_port);                          from_server_port, to_local_host, to_local_port);
3725    
3726          } else {          } else {
# Line 3733  void SSH_request_forwarding(PTInstVar pv Line 3730  void SSH_request_forwarding(PTInstVar pv
3730                  unsigned char *outmsg;                  unsigned char *outmsg;
3731                  int len;                  int len;
3732    
3733                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": Forwarding request (SSH2 RtoL): "                  logprintf(LOG_LEVEL_VERBOSE, "%s: Forwarding request (SSH2 RtoL): "
3734                          "bind_addr=%s, remote_port=%d, to_host=%s, to_port=%d",                                    "bind_addr=%s, remote_port=%d, to_host=%s, to_port=%d", __FUNCTION__,
3735                          bind_address, from_server_port, to_local_host, to_local_port);                          bind_address, from_server_port, to_local_host, to_local_port);
3736    
3737                  msg = buffer_init();                  msg = buffer_init();
3738                  if (msg == NULL) {                  if (msg == NULL) {
3739                          // TODO: error check                          // TODO: error check
3740                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3741                          return;                          return;
3742                  }                  }
3743                  req = "tcpip-forward";                  req = "tcpip-forward";
# Line 3756  void SSH_request_forwarding(PTInstVar pv Line 3753  void SSH_request_forwarding(PTInstVar pv
3753                  finish_send_packet(pvar);                  finish_send_packet(pvar);
3754                  buffer_free(msg);                  buffer_free(msg);
3755    
3756                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_GLOBAL_REQUEST. "                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_GLOBAL_REQUEST. "
3757                          "request=%s, want_reply=%d, bind_address=%s, remote_port=%d",                                    "request=%s, want_reply=%d, bind_address=%s, remote_port=%d", __FUNCTION__,
3758                          req, 1, bind_address, from_server_port);                          req, 1, bind_address, from_server_port);
3759          }          }
3760  }  }
# Line 3773  void SSH_cancel_request_forwarding(PTIns Line 3770  void SSH_cancel_request_forwarding(PTIns
3770                  msg = buffer_init();                  msg = buffer_init();
3771                  if (msg == NULL) {                  if (msg == NULL) {
3772                          // TODO: error check                          // TODO: error check
3773                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3774                          return;                          return;
3775                  }                  }
3776                  s = "cancel-tcpip-forward";                  s = "cancel-tcpip-forward";
# Line 3836  void SSH_request_X11_forwarding(PTInstVa Line 3833  void SSH_request_X11_forwarding(PTInstVa
3833                  msg = buffer_init();                  msg = buffer_init();
3834                  if (msg == NULL) {                  if (msg == NULL) {
3835                          // TODO: error check                          // TODO: error check
3836                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3837                          return;                          return;
3838                  }                  }
3839    
3840                  c = ssh2_channel_lookup(pvar->shell_id);                  c = ssh2_channel_lookup(pvar->shell_id);
3841                  if (c == NULL) {                  if (c == NULL) {
3842                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
3843                          return;                          return;
3844                  }                  }
3845    
# Line 3872  void SSH_request_X11_forwarding(PTInstVa Line 3869  void SSH_request_X11_forwarding(PTInstVa
3869                  finish_send_packet(pvar);                  finish_send_packet(pvar);
3870                  buffer_free(msg);                  buffer_free(msg);
3871    
3872                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_REQUEST. "                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_CHANNEL_REQUEST. "
3873                            "local: %d, remote: %d, request-type: %s, proto: %s, cookie: %s, screen: %d",                            "local: %d, remote: %d, request-type: %s, proto: %s, cookie: %s, screen: %d", __FUNCTION__,
3874                            c->self_id, c->remote_id, req_type, auth_protocol, newdata, screen_num);                            c->self_id, c->remote_id, req_type, auth_protocol, newdata, screen_num);
3875    
3876                  free(newdata);                  free(newdata);
# Line 3929  void SSH_open_channel(PTInstVar pvar, ui Line 3926  void SSH_open_channel(PTInstVar pvar, ui
3926                          if (pvar->rekeying) {                          if (pvar->rekeying) {
3927                                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、                                  // TODO: 理想としてはパケット破棄ではなく、パケット読み取り遅延にしたいところだが、
3928                                  // 将来直すことにする。                                  // 将来直すことにする。
3929                                  logputs(LOG_LEVEL_INFO, __FUNCTION__ ": now rekeying. channel open request is not sent.");                                  logprintf(LOG_LEVEL_INFO, "%s: now rekeying. channel open request is not sent.", __FUNCTION__);
3930    
3931                                  c = NULL;                                  c = NULL;
3932    
# Line 3951  void SSH_open_channel(PTInstVar pvar, ui Line 3948  void SSH_open_channel(PTInstVar pvar, ui
3948                          msg = buffer_init();                          msg = buffer_init();
3949                          if (msg == NULL) {                          if (msg == NULL) {
3950                                  // TODO: error check                                  // TODO: error check
3951                                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
3952                                  return;                                  return;
3953                          }                          }
3954                          s = "direct-tcpip";                          s = "direct-tcpip";
# Line 4733  void SSH2_send_kexinit(PTInstVar pvar) Line 4730  void SSH2_send_kexinit(PTInstVar pvar)
4730          msg = buffer_init();          msg = buffer_init();
4731          if (msg == NULL) {          if (msg == NULL) {
4732                  // TODO: error check                  // TODO: error check
4733                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
4734                  return;                  return;
4735          }          }
4736          if (pvar->my_kex != NULL)          if (pvar->my_kex != NULL)
# Line 5003  static BOOL handle_SSH2_kexinit(PTInstVa Line 5000  static BOOL handle_SSH2_kexinit(PTInstVa
5000          else {          else {
5001                  pvar->peer_kex = buffer_init();                  pvar->peer_kex = buffer_init();
5002                  if (pvar->peer_kex == NULL) {                  if (pvar->peer_kex == NULL) {
5003                          msg = __FUNCTION__ ": Out of memory";                          _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5004                                                    "%s: Out of memory", __FUNCTION__);
5005                            msg = tmp;
5006                          goto error;                          goto error;
5007                  }                  }
5008          }          }
# Line 5013  static BOOL handle_SSH2_kexinit(PTInstVa Line 5012  static BOOL handle_SSH2_kexinit(PTInstVa
5012    
5013          // cookie; ここでは使わないので読み飛ばす          // cookie; ここでは使わないので読み飛ばす
5014          if (! grab_payload(pvar, SSH2_COOKIE_LENGTH)) {          if (! grab_payload(pvar, SSH2_COOKIE_LENGTH)) {
5015                  msg = __FUNCTION__ ": truncated packet (cookie)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5016                                            "%s: truncated packet (cookie)", __FUNCTION__);
5017                    msg = tmp;
5018                  goto error;                  goto error;
5019          }          }
5020    
# Line 5025  static BOOL handle_SSH2_kexinit(PTInstVa Line 5026  static BOOL handle_SSH2_kexinit(PTInstVa
5026          // 鍵交換アルゴリズム          // 鍵交換アルゴリズム
5027          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5028          case GetPayloadError:          case GetPayloadError:
5029                  msg = __FUNCTION__ ": truncated packet (kex algorithms)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5030                                            "%s: truncated packet (kex algorithms)", __FUNCTION__);
5031                    msg = tmp;
5032                  goto error;                  goto error;
5033          case GetPayloadTruncate:          case GetPayloadTruncate:
5034                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed kex algorithms is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed kex algorithms is too long.", __FUNCTION__);
5035                  break;                  break;
5036          }          }
5037    
# Line 5045  static BOOL handle_SSH2_kexinit(PTInstVa Line 5048  static BOOL handle_SSH2_kexinit(PTInstVa
5048          // ホスト鍵アルゴリズム          // ホスト鍵アルゴリズム
5049          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5050          case GetPayloadError:          case GetPayloadError:
5051                  msg = __FUNCTION__ ": truncated packet (hostkey algorithms)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5052                                            "%s: truncated packet (hostkey algorithms)", __FUNCTION__);
5053                    msg = tmp;
5054                  goto error;                  goto error;
5055          case GetPayloadTruncate:          case GetPayloadTruncate:
5056                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed hostkey algorithms is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed hostkey algorithms is too long.", __FUNCTION__);
5057                  break;                  break;
5058          }          }
5059    
# Line 5073  static BOOL handle_SSH2_kexinit(PTInstVa Line 5078  static BOOL handle_SSH2_kexinit(PTInstVa
5078          // 暗号アルゴリズム(クライアント -> サーバ)          // 暗号アルゴリズム(クライアント -> サーバ)
5079          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5080          case GetPayloadError:          case GetPayloadError:
5081                  msg = __FUNCTION__ ": truncated packet (encryption algorithms client to server)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5082                                            "%s: truncated packet (encryption algorithms client to server)", __FUNCTION__);
5083                    msg = tmp;
5084                  goto error;                  goto error;
5085          case GetPayloadTruncate:          case GetPayloadTruncate:
5086                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed encryption algorithms (client to server) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed encryption algorithms (client to server) is too long.", __FUNCTION__);
5087                  break;                  break;
5088          }          }
5089    
# Line 5093  static BOOL handle_SSH2_kexinit(PTInstVa Line 5100  static BOOL handle_SSH2_kexinit(PTInstVa
5100          // 暗号アルゴリズム(サーバ -> クライアント)          // 暗号アルゴリズム(サーバ -> クライアント)
5101          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5102          case GetPayloadError:          case GetPayloadError:
5103                  msg = __FUNCTION__ ": truncated packet (encryption algorithms server to client)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5104                                            "%s: truncated packet (encryption algorithms server to client)", __FUNCTION__);
5105                    msg = tmp;
5106                  goto error;                  goto error;
5107          case GetPayloadTruncate:          case GetPayloadTruncate:
5108                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed encryption algorithms (server to client) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed encryption algorithms (server to client) is too long.", __FUNCTION__);
5109                  break;                  break;
5110          }          }
5111    
# Line 5113  static BOOL handle_SSH2_kexinit(PTInstVa Line 5122  static BOOL handle_SSH2_kexinit(PTInstVa
5122          // MACアルゴリズム(クライアント -> サーバ)          // MACアルゴリズム(クライアント -> サーバ)
5123          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5124          case GetPayloadError:          case GetPayloadError:
5125                  msg = __FUNCTION__ ": truncated packet (MAC algorithms client to server)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5126                                            "%s: truncated packet (MAC algorithms client to server)", __FUNCTION__);
5127                    msg = tmp;
5128                  goto error;                  goto error;
5129          case GetPayloadTruncate:          case GetPayloadTruncate:
5130                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed MAC algorithms (client to server) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed MAC algorithms (client to server) is too long.", __FUNCTION__);
5131                  break;                  break;
5132          }          }
5133    
# Line 5139  static BOOL handle_SSH2_kexinit(PTInstVa Line 5150  static BOOL handle_SSH2_kexinit(PTInstVa
5150          // MACアルゴリズム(サーバ -> クライアント)          // MACアルゴリズム(サーバ -> クライアント)
5151          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5152          case GetPayloadError:          case GetPayloadError:
5153                  msg = __FUNCTION__ ": truncated packet (MAC algorithms server to client)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5154                                            "%s: truncated packet (MAC algorithms server to client)", __FUNCTION__);
5155                    msg = tmp;
5156                  goto error;                  goto error;
5157          case GetPayloadTruncate:          case GetPayloadTruncate:
5158                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed MAC algorithms (server to client) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed MAC algorithms (server to client) is too long.", __FUNCTION__);
5159                  break;                  break;
5160          }          }
5161    
# Line 5165  static BOOL handle_SSH2_kexinit(PTInstVa Line 5178  static BOOL handle_SSH2_kexinit(PTInstVa
5178          // 圧縮アルゴリズム(クライアント -> サーバ)          // 圧縮アルゴリズム(クライアント -> サーバ)
5179          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5180          case GetPayloadError:          case GetPayloadError:
5181                  msg = __FUNCTION__ ": truncated packet (compression algorithms client to server)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5182                                            "%s: truncated packet (compression algorithms client to server)", __FUNCTION__);
5183                    msg = tmp;
5184                  goto error;                  goto error;
5185          case GetPayloadTruncate:          case GetPayloadTruncate:
5186                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed compression algorithms (client to server) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed compression algorithms (client to server) is too long.", __FUNCTION__);
5187                  break;                  break;
5188          }          }
5189    
# Line 5185  static BOOL handle_SSH2_kexinit(PTInstVa Line 5200  static BOOL handle_SSH2_kexinit(PTInstVa
5200          // 圧縮アルゴリズム(サーバ -> クライアント)          // 圧縮アルゴリズム(サーバ -> クライアント)
5201          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5202          case GetPayloadError:          case GetPayloadError:
5203                  msg = __FUNCTION__ ": truncated packet (compression algorithms server to client)";                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
5204                                            "%s: truncated packet (compression algorithms server to client)", __FUNCTION__);
5205                    msg = tmp;
5206                  goto error;                  goto error;
5207          case GetPayloadTruncate:          case GetPayloadTruncate:
5208                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed compression algorithms (server to client) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed compression algorithms (server to client) is too long.", __FUNCTION__);
5209                  break;                  break;
5210          }          }
5211    
# Line 5209  static BOOL handle_SSH2_kexinit(PTInstVa Line 5226  static BOOL handle_SSH2_kexinit(PTInstVa
5226                  // 言語の name-list が取れないという事は KEXINIT パケットのフォーマット自体が想定外であり                  // 言語の name-list が取れないという事は KEXINIT パケットのフォーマット自体が想定外であり
5227                  // 異常な状態であるが、通信に必要なアルゴリズムはすでにネゴ済みで通信自体は行える。                  // 異常な状態であるが、通信に必要なアルゴリズムはすでにネゴ済みで通信自体は行える。
5228                  // 今まではこの部分のチェックを行っていなかったので、警告を記録するのみで処理を続行する。                  // 今まではこの部分のチェックを行っていなかったので、警告を記録するのみで処理を続行する。
5229                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": truncated packet (language client to server)");                  logprintf(LOG_LEVEL_WARNING, "%s: truncated packet (language client to server)", __FUNCTION__);
5230                  goto skip;                  goto skip;
5231          case GetPayloadTruncate:          case GetPayloadTruncate:
5232                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed language (client to server) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed language (client to server) is too long.", __FUNCTION__);
5233                  break;                  break;
5234          }          }
5235    
# Line 5223  static BOOL handle_SSH2_kexinit(PTInstVa Line 5240  static BOOL handle_SSH2_kexinit(PTInstVa
5240          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {          switch (get_namelist_from_payload(pvar, buf, sizeof(buf), &size)) {
5241          case GetPayloadError:          case GetPayloadError:
5242                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。
5243                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": truncated packet (language server to client)");                  logprintf(LOG_LEVEL_WARNING, "%s: truncated packet (language server to client)", __FUNCTION__);
5244                  goto error;                  goto error;
5245          case GetPayloadTruncate:          case GetPayloadTruncate:
5246                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": server proposed language (server to client) is too long.");                  logprintf(LOG_LEVEL_WARNING, "%s: server proposed language (server to client) is too long.", __FUNCTION__);
5247                  break;                  break;
5248          }          }
5249    
# Line 5237  static BOOL handle_SSH2_kexinit(PTInstVa Line 5254  static BOOL handle_SSH2_kexinit(PTInstVa
5254          // SSH_MSG_KEXINIT の後の鍵交換はクライアント側から送るのでサーバ側が 1 にする事はないはず。          // SSH_MSG_KEXINIT の後の鍵交換はクライアント側から送るのでサーバ側が 1 にする事はないはず。
5255          if (!get_boolean_from_payload(pvar, buf)) {          if (!get_boolean_from_payload(pvar, buf)) {
5256                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。
5257                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": truncated packet (first_kex_packet_follows)");                  logprintf(LOG_LEVEL_WARNING, "%s: truncated packet (first_kex_packet_follows)", __FUNCTION__);
5258                  goto skip;                  goto skip;
5259          }          }
5260          if (buf[0] != 0) {          if (buf[0] != 0) {
5261                  // 前述のようにサーバ側は 0 以外にする事はないはずなので、警告を記録する。                  // 前述のようにサーバ側は 0 以外にする事はないはずなので、警告を記録する。
5262                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": first_kex_packet_follows is not 0. (%d)", buf[0]);                  logprintf(LOG_LEVEL_WARNING, "%s: first_kex_packet_follows is not 0. (%d)", __FUNCTION__, buf[0]);
5263          }          }
5264    
5265          // reserved: 現状は常に 0 となる。          // reserved: 現状は常に 0 となる。
5266          if (!get_uint32_from_payload(pvar, &size)) {          if (!get_uint32_from_payload(pvar, &size)) {
5267                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。                  // 言語(クライアント -> サーバ) と同様に、問題があっても警告のみとする。
5268                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": truncated packet (reserved)");                  logprintf(LOG_LEVEL_WARNING, "%s: truncated packet (reserved)", __FUNCTION__ );
5269                  goto skip;                  goto skip;
5270          }          }
5271          if (size != 0) {          if (size != 0) {
5272                  logprintf(LOG_LEVEL_INFO, __FUNCTION__ ": reserved data is not 0. (%d)", size);                  logprintf(LOG_LEVEL_INFO, "%s: reserved data is not 0. (%d)", __FUNCTION__, size);
5273          }          }
5274    
5275  skip:  skip:
# Line 5357  static void SSH2_dh_kex_init(PTInstVar p Line 5374  static void SSH2_dh_kex_init(PTInstVar p
5374          msg = buffer_init();          msg = buffer_init();
5375          if (msg == NULL) {          if (msg == NULL) {
5376                  // TODO: error check                  // TODO: error check
5377                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
5378                  return;                  return;
5379          }          }
5380    
# Line 5421  static void SSH2_dh_gex_kex_init(PTInstV Line 5438  static void SSH2_dh_gex_kex_init(PTInstV
5438          else if (pvar->settings.GexMinimalGroupSize < GEX_GRP_LIMIT_MIN) {          else if (pvar->settings.GexMinimalGroupSize < GEX_GRP_LIMIT_MIN) {
5439                  min = GEX_GRP_LIMIT_MIN;                  min = GEX_GRP_LIMIT_MIN;
5440                  logprintf(LOG_LEVEL_NOTICE,                  logprintf(LOG_LEVEL_NOTICE,
5441                          __FUNCTION__ ": small GexMinimalGroupSize is too small (%d), use minimum limit (%d)",                          "%s: small GexMinimalGroupSize is too small (%d), use minimum limit (%d)", __FUNCTION__,
5442                          pvar->settings.GexMinimalGroupSize, GEX_GRP_LIMIT_MIN);                          pvar->settings.GexMinimalGroupSize, GEX_GRP_LIMIT_MIN);
5443          }          }
5444          else if (pvar->settings.GexMinimalGroupSize > GEX_GRP_LIMIT_MAX) {          else if (pvar->settings.GexMinimalGroupSize > GEX_GRP_LIMIT_MAX) {
5445                  min = GEX_GRP_LIMIT_MAX;                  min = GEX_GRP_LIMIT_MAX;
5446                  logprintf(LOG_LEVEL_NOTICE,                  logprintf(LOG_LEVEL_NOTICE,
5447                          __FUNCTION__ ": small GexMinimalGroupSize is too larse (%d), use maximum limit (%d)",                          "%s: small GexMinimalGroupSize is too larse (%d), use maximum limit (%d)", __FUNCTION__,
5448                          pvar->settings.GexMinimalGroupSize, GEX_GRP_LIMIT_MAX);                          pvar->settings.GexMinimalGroupSize, GEX_GRP_LIMIT_MAX);
5449          }          }
5450          else {          else {
# Line 5512  static BOOL handle_SSH2_dh_gex_group(PTI Line 5529  static BOOL handle_SSH2_dh_gex_group(PTI
5529                  goto error;                  goto error;
5530    
5531          if (!get_mpint_from_payload(pvar, p) || !get_mpint_from_payload(pvar, g)) {          if (!get_mpint_from_payload(pvar, p) || !get_mpint_from_payload(pvar, g)) {
5532                  notify_fatal_error(pvar, __FUNCTION__ ":truncated packet (mpint)", FALSE);                  _snprintf_s(tmpbuf, sizeof(tmpbuf), _TRUNCATE,
5533                                            "%s:truncated packet (mpint)", __FUNCTION__);
5534                    notify_fatal_error(pvar, tmpbuf, FALSE);
5535                  return FALSE;                  return FALSE;
5536          }          }
5537    
# Line 5651  static void SSH2_ecdh_kex_init(PTInstVar Line 5670  static void SSH2_ecdh_kex_init(PTInstVar
5670          msg = buffer_init();          msg = buffer_init();
5671          if (msg == NULL) {          if (msg == NULL) {
5672                  // TODO: error check                  // TODO: error check
5673                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
5674                  return;                  return;
5675          }          }
5676    
# Line 5727  static BOOL ssh2_kex_finish(PTInstVar pv Line 5746  static BOOL ssh2_kex_finish(PTInstVar pv
5746          if ((ret = key_verify(hostkey, signature, siglen, hash, hashlen)) != 1) {          if ((ret = key_verify(hostkey, signature, siglen, hash, hashlen)) != 1) {
5747                  if (ret == -3 && hostkey->type == KEY_RSA) {                  if (ret == -3 && hostkey->type == KEY_RSA) {
5748                          if (!pvar->settings.EnableRsaShortKeyServer) {                          if (!pvar->settings.EnableRsaShortKeyServer) {
5749                                  _snprintf_s(emsg, sizeof(emsg), _TRUNCATE, __FUNCTION__                                  _snprintf_s(emsg, sizeof(emsg), _TRUNCATE,
5750                                          ": key verify error. remote rsa key length is too short (%d-bit)",                                          "%s: key verify error. remote rsa key length is too short (%d-bit)", __FUNCTION__,
5751                                          BN_num_bits(hostkey->rsa->n));                                          BN_num_bits(hostkey->rsa->n));
5752                          }                          }
5753                          else {                          else {
# Line 5736  static BOOL ssh2_kex_finish(PTInstVar pv Line 5755  static BOOL ssh2_kex_finish(PTInstVar pv
5755                          }                          }
5756                  }                  }
5757                  else {                  else {
5758                          _snprintf_s(emsg, sizeof(emsg), _TRUNCATE, __FUNCTION__ ": key verify error (%d)\r\n%s", ret, SENDTOME);                          _snprintf_s(emsg, sizeof(emsg), _TRUNCATE, "%s: key verify error (%d)\r\n%s", __FUNCTION__, ret, SENDTOME);
5759                  }                  }
5760    
5761                  save_memdump(LOGDUMP);                  save_memdump(LOGDUMP);
# Line 5751  cont: Line 5770  cont:
5770          begin_send_packet(pvar, SSH2_MSG_NEWKEYS, 0);          begin_send_packet(pvar, SSH2_MSG_NEWKEYS, 0);
5771          finish_send_packet(pvar);          finish_send_packet(pvar);
5772    
5773          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_NEWKEYS was sent.");          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_NEWKEYS was sent.", __FUNCTION__);
5774    
5775          // SSH2_MSG_NEWKEYSを送り終わったあとにキーの設定および再設定を行う          // SSH2_MSG_NEWKEYSを送り終わったあとにキーの設定および再設定を行う
5776          // 送信用の暗号鍵は SSH2_MSG_NEWKEYS の送信後に、受信用のは SSH2_MSG_NEWKEYS の          // 送信用の暗号鍵は SSH2_MSG_NEWKEYS の送信後に、受信用のは SSH2_MSG_NEWKEYS の
# Line 5830  static BOOL handle_SSH2_dh_kex_reply(PTI Line 5849  static BOOL handle_SSH2_dh_kex_reply(PTI
5849    
5850          hostkey = key_from_blob(data, bloblen);          hostkey = key_from_blob(data, bloblen);
5851          if (hostkey == NULL) {          if (hostkey == NULL) {
5852                  emsg = __FUNCTION__ ": key_from_blob error";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5853                                            "%s: key_from_blob error", __FUNCTION__);
5854                    emsg = emsg_tmp;
5855                  goto error;                  goto error;
5856          }          }
5857          data += bloblen;          data += bloblen;
# Line 5845  static BOOL handle_SSH2_dh_kex_reply(PTI Line 5866  static BOOL handle_SSH2_dh_kex_reply(PTI
5866          }          }
5867          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);
5868          if (pvar->socket == INVALID_SOCKET) {          if (pvar->socket == INVALID_SOCKET) {
5869                  emsg = __FUNCTION__ ": Server disconnected";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5870                                            "%s: Server disconnected", __FUNCTION__);
5871                    emsg = emsg_tmp;
5872                  goto error;                  goto error;
5873          }          }
5874    
5875          server_public = BN_new();          server_public = BN_new();
5876          if (server_public == NULL) {          if (server_public == NULL) {
5877                  emsg = __FUNCTION__ ": Out of memory (1)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5878                                            "%s: Out of memory (1)", __FUNCTION__);
5879                    emsg = emsg_tmp;
5880                  goto error;                  goto error;
5881          }          }
5882    
# Line 5866  static BOOL handle_SSH2_dh_kex_reply(PTI Line 5891  static BOOL handle_SSH2_dh_kex_reply(PTI
5891    
5892          // check public key          // check public key
5893          if (!dh_pub_is_valid(pvar->kexdh, server_public)) {          if (!dh_pub_is_valid(pvar->kexdh, server_public)) {
5894                  emsg = __FUNCTION__ ": invalid server public key";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5895                                            "%s: invalid server public key", __FUNCTION__);
5896                    emsg = emsg_tmp;
5897                  goto error;                  goto error;
5898          }          }
5899          // 共通鍵の生成          // 共通鍵の生成
5900          dh_len = DH_size(pvar->kexdh);          dh_len = DH_size(pvar->kexdh);
5901          dh_buf = malloc(dh_len);          dh_buf = malloc(dh_len);
5902          if (dh_buf == NULL) {          if (dh_buf == NULL) {
5903                  emsg = __FUNCTION__ ": Out of memory (2)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5904                                            "%s: Out of memory (2)", __FUNCTION__);
5905                    emsg = emsg_tmp;
5906                  goto error;                  goto error;
5907          }          }
5908          share_len = DH_compute_key(dh_buf, server_public, pvar->kexdh);          share_len = DH_compute_key(dh_buf, server_public, pvar->kexdh);
5909          share_key = BN_new();          share_key = BN_new();
5910          if (share_key == NULL) {          if (share_key == NULL) {
5911                  emsg = __FUNCTION__ ": Out of memory (3)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5912                                            "%s: Out of memory (3)", __FUNCTION__);
5913                    emsg = emsg_tmp;
5914                  goto error;                  goto error;
5915          }          }
5916          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。
# Line 5973  static BOOL handle_SSH2_dh_gex_reply(PTI Line 6004  static BOOL handle_SSH2_dh_gex_reply(PTI
6004    
6005          hostkey = key_from_blob(data, bloblen);          hostkey = key_from_blob(data, bloblen);
6006          if (hostkey == NULL) {          if (hostkey == NULL) {
6007                  emsg = __FUNCTION__ ": key_from_blob error";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6008                                            "%s: key_from_blob error", __FUNCTION__);
6009                    emsg = emsg_tmp;
6010                  goto error;                  goto error;
6011          }          }
6012          data += bloblen;          data += bloblen;
# Line 5988  static BOOL handle_SSH2_dh_gex_reply(PTI Line 6021  static BOOL handle_SSH2_dh_gex_reply(PTI
6021          }          }
6022          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);
6023          if (pvar->socket == INVALID_SOCKET) {          if (pvar->socket == INVALID_SOCKET) {
6024                  emsg = __FUNCTION__ ": Server disconnected";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6025                                            "%s: Server disconnected", __FUNCTION__);
6026                    emsg = emsg_tmp;
6027                  goto error;                  goto error;
6028          }          }
6029    
6030          server_public = BN_new();          server_public = BN_new();
6031          if (server_public == NULL) {          if (server_public == NULL) {
6032                  emsg = __FUNCTION__ ": Out of memory (1)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6033                                            "%s: Out of memory (1)", __FUNCTION__);
6034                    emsg = emsg_tmp;
6035                  goto error;                  goto error;
6036          }          }
6037    
# Line 6009  static BOOL handle_SSH2_dh_gex_reply(PTI Line 6046  static BOOL handle_SSH2_dh_gex_reply(PTI
6046    
6047          // check public key          // check public key
6048          if (!dh_pub_is_valid(pvar->kexdh, server_public)) {          if (!dh_pub_is_valid(pvar->kexdh, server_public)) {
6049                  emsg = __FUNCTION__ ": invalid server public key";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6050                                            "%s: invalid server public key", __FUNCTION__);
6051                    emsg = emsg_tmp;
6052                  goto error;                  goto error;
6053          }          }
6054          // 共通鍵の生成          // 共通鍵の生成
6055          dh_len = DH_size(pvar->kexdh);          dh_len = DH_size(pvar->kexdh);
6056          dh_buf = malloc(dh_len);          dh_buf = malloc(dh_len);
6057          if (dh_buf == NULL) {          if (dh_buf == NULL) {
6058                  emsg = __FUNCTION__ ": Out of memory (2)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6059                                            "%s: Out of memory (2)", __FUNCTION__);
6060                    emsg = emsg_tmp;
6061                  goto error;                  goto error;
6062          }          }
6063          share_len = DH_compute_key(dh_buf, server_public, pvar->kexdh);          share_len = DH_compute_key(dh_buf, server_public, pvar->kexdh);
6064          share_key = BN_new();          share_key = BN_new();
6065          if (share_key == NULL) {          if (share_key == NULL) {
6066                  emsg = __FUNCTION__ ": Out of memory (3)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6067                                            "%s: Out of memory (3)", __FUNCTION__);
6068                    emsg = emsg_tmp;
6069                  goto error;                  goto error;
6070          }          }
6071          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。
# Line 6122  static BOOL handle_SSH2_ecdh_kex_reply(P Line 6165  static BOOL handle_SSH2_ecdh_kex_reply(P
6165    
6166          hostkey = key_from_blob(data, bloblen);          hostkey = key_from_blob(data, bloblen);
6167          if (hostkey == NULL) {          if (hostkey == NULL) {
6168                  emsg = __FUNCTION__ ": key_from_blob error";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6169                                            "%s: key_from_blob error", __FUNCTION__);
6170                    emsg = emsg_tmp;
6171                  goto error;                  goto error;
6172          }          }
6173          data += bloblen;          data += bloblen;
# Line 6137  static BOOL handle_SSH2_ecdh_kex_reply(P Line 6182  static BOOL handle_SSH2_ecdh_kex_reply(P
6182          }          }
6183          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);          HOSTS_check_host_key(pvar, pvar->ssh_state.hostname, pvar->ssh_state.tcpport, hostkey);
6184          if (pvar->socket == INVALID_SOCKET) {          if (pvar->socket == INVALID_SOCKET) {
6185                  emsg = __FUNCTION__ ": Server disconnected";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6186                                            "%s: Server disconnected", __FUNCTION__);
6187                    emsg = emsg_tmp;
6188                  goto error;                  goto error;
6189          }          }
6190    
# Line 6145  static BOOL handle_SSH2_ecdh_kex_reply(P Line 6192  static BOOL handle_SSH2_ecdh_kex_reply(P
6192          group = EC_KEY_get0_group(pvar->ecdh_client_key);          group = EC_KEY_get0_group(pvar->ecdh_client_key);
6193          server_public = EC_POINT_new(group);          server_public = EC_POINT_new(group);
6194          if (server_public == NULL) {          if (server_public == NULL) {
6195                  emsg = __FUNCTION__ ": Out of memory (1)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6196                                            "%s: Out of memory (1)", __FUNCTION__);
6197                    emsg = emsg_tmp;
6198                  goto error;                  goto error;
6199          }          }
6200    
# Line 6160  static BOOL handle_SSH2_ecdh_kex_reply(P Line 6209  static BOOL handle_SSH2_ecdh_kex_reply(P
6209    
6210          // check public key          // check public key
6211          if (key_ec_validate_public(group, server_public) != 0) {          if (key_ec_validate_public(group, server_public) != 0) {
6212                  emsg = __FUNCTION__ ": invalid server public key";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6213                                            "%s: invalid server public key", __FUNCTION__);
6214                    emsg = emsg_tmp;
6215                  goto error;                  goto error;
6216          }          }
6217          // 共通鍵の生成          // 共通鍵の生成
6218          ecdh_len = (EC_GROUP_get_degree(group) + 7) / 8;          ecdh_len = (EC_GROUP_get_degree(group) + 7) / 8;
6219          ecdh_buf = malloc(ecdh_len);          ecdh_buf = malloc(ecdh_len);
6220          if (ecdh_buf == NULL) {          if (ecdh_buf == NULL) {
6221                  emsg = __FUNCTION__ ": Out of memory (2)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6222                                            "%s: Out of memory (2)", __FUNCTION__);
6223                    emsg = emsg_tmp;
6224                  goto error;                  goto error;
6225          }          }
6226          if (ECDH_compute_key(ecdh_buf, ecdh_len, server_public,          if (ECDH_compute_key(ecdh_buf, ecdh_len, server_public,
6227                               pvar->ecdh_client_key, NULL) != (int)ecdh_len) {                               pvar->ecdh_client_key, NULL) != (int)ecdh_len) {
6228                  emsg = __FUNCTION__ ": Out of memory (3)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6229                                            "%s: Out of memory (3)", __FUNCTION__);
6230                    emsg = emsg_tmp;
6231                  goto error;                  goto error;
6232          }          }
6233          share_key = BN_new();          share_key = BN_new();
6234          if (share_key == NULL) {          if (share_key == NULL) {
6235                  emsg = __FUNCTION__ ": Out of memory (4)";                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
6236                                            "%s: Out of memory (4)", __FUNCTION__);
6237                    emsg = emsg_tmp;
6238                  goto error;                  goto error;
6239          }          }
6240          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。
# Line 6383  BOOL do_SSH2_userauth(PTInstVar pvar) Line 6440  BOOL do_SSH2_userauth(PTInstVar pvar)
6440          msg = buffer_init();          msg = buffer_init();
6441          if (msg == NULL) {          if (msg == NULL) {
6442                  // TODO: error check                  // TODO: error check
6443                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
6444                  return FALSE;                  return FALSE;
6445          }          }
6446          s = "ssh-userauth";          s = "ssh-userauth";
# Line 6412  static BOOL handle_SSH2_service_accept(P Line 6469  static BOOL handle_SSH2_service_accept(P
6469          data = pvar->ssh_state.payload;          data = pvar->ssh_state.payload;
6470    
6471          if ((svc = buffer_get_string(&data, NULL)) == NULL) {          if ((svc = buffer_get_string(&data, NULL)) == NULL) {
6472                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL.", __FUNCTION__);
6473          }          }
6474          logprintf(LOG_LEVEL_VERBOSE, "SSH2_MSG_SERVICE_ACCEPT was received. service-name=%s", NonNull(svc));          logprintf(LOG_LEVEL_VERBOSE, "SSH2_MSG_SERVICE_ACCEPT was received. service-name=%s", NonNull(svc));
6475          free(svc);          free(svc);
# Line 6448  BOOL do_SSH2_authrequest(PTInstVar pvar) Line 6505  BOOL do_SSH2_authrequest(PTInstVar pvar)
6505          msg = buffer_init();          msg = buffer_init();
6506          if (msg == NULL) {          if (msg == NULL) {
6507                  // TODO: error check                  // TODO: error check
6508                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
6509                  return FALSE;                  return FALSE;
6510          }          }
6511    
# Line 6641  static LRESULT CALLBACK ssh_heartbeat_dl Line 6698  static LRESULT CALLBACK ssh_heartbeat_dl
6698                          msg = buffer_init();                          msg = buffer_init();
6699                          if (msg == NULL) {                          if (msg == NULL) {
6700                                  // TODO: error check                                  // TODO: error check
6701                                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
6702                                  return FALSE;                                  return FALSE;
6703                          }                          }
6704                          s = "ssh-heartbeat";                          s = "ssh-heartbeat";
# Line 6813  static BOOL handle_SSH2_userauth_success Line 6870  static BOOL handle_SSH2_userauth_success
6870                  msg = buffer_init();                  msg = buffer_init();
6871                  if (msg == NULL) {                  if (msg == NULL) {
6872                          // TODO: error check                          // TODO: error check
6873                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
6874                          return FALSE;                          return FALSE;
6875                  }                  }
6876                  s = "session";                  s = "session";
# Line 7011  static BOOL handle_SSH2_userauth_banner( Line 7068  static BOOL handle_SSH2_userauth_banner(
7068          logputs(LOG_LEVEL_INFO, "SSH2_MSG_USERAUTH_BANNER was received.");          logputs(LOG_LEVEL_INFO, "SSH2_MSG_USERAUTH_BANNER was received.");
7069    
7070          if (!get_string_from_payload(pvar, buff, sizeof(buff), &msglen, TRUE)) {          if (!get_string_from_payload(pvar, buff, sizeof(buff), &msglen, TRUE)) {
7071                  logputs(LOG_LEVEL_WARNING, __FUNCTION__ ": banner payload corrupted.");                  logprintf(LOG_LEVEL_WARNING, "%s: banner payload corrupted.", __FUNCTION__);
7072                  return TRUE;                  return TRUE;
7073          }          }
7074    
# Line 7064  static BOOL handle_SSH2_userauth_banner( Line 7121  static BOOL handle_SSH2_userauth_banner(
7121          }          }
7122    
7123          if (!get_string_from_payload(pvar, buff, sizeof(buff), &ltaglen, TRUE)) {          if (!get_string_from_payload(pvar, buff, sizeof(buff), &ltaglen, TRUE)) {
7124                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": langtag payload corrupted.");                  logprintf(LOG_LEVEL_WARNING, "%s: langtag payload corrupted.", __FUNCTION__);
7125                  return TRUE;                  return TRUE;
7126          }          }
7127    
# Line 7141  BOOL handle_SSH2_userauth_inforeq(PTInst Line 7198  BOOL handle_SSH2_userauth_inforeq(PTInst
7198          lang = buffer_get_string(&data, NULL);          lang = buffer_get_string(&data, NULL);
7199          lprompt[0] = 0;          lprompt[0] = 0;
7200          if (inst == NULL) {          if (inst == NULL) {
7201                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL. (inst)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL. (inst)", __FUNCTION__);
7202          }          }
7203          else if (strlen(inst) > 0) {          else if (strlen(inst) > 0) {
7204                  strncat_s(lprompt, sizeof(lprompt), inst, _TRUNCATE);                  strncat_s(lprompt, sizeof(lprompt), inst, _TRUNCATE);
7205                  strncat_s(lprompt, sizeof(lprompt), "\r\n", _TRUNCATE);                  strncat_s(lprompt, sizeof(lprompt), "\r\n", _TRUNCATE);
7206          }          }
7207          if (lang == NULL) {          if (lang == NULL) {
7208                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL. (lang)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL. (lang)", __FUNCTION__);
7209          }          }
7210          else if (strlen(lang) > 0) {          else if (strlen(lang) > 0) {
7211                  strncat_s(lprompt, sizeof(lprompt), lang, _TRUNCATE);                  strncat_s(lprompt, sizeof(lprompt), lang, _TRUNCATE);
7212                  strncat_s(lprompt, sizeof(lprompt), "\r\n", _TRUNCATE);                  strncat_s(lprompt, sizeof(lprompt), "\r\n", _TRUNCATE);
7213          }          }
7214    
7215          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": user=%s, inst=%s, lang=%s",          logprintf(LOG_LEVEL_VERBOSE, "%s: user=%s, inst=%s, lang=%s", __FUNCTION__,
7216                  NonNull(name), NonNull(inst), NonNull(lang));                  NonNull(name), NonNull(inst), NonNull(lang));
7217    
7218          free(name);          free(name);
# Line 7166  BOOL handle_SSH2_userauth_inforeq(PTInst Line 7223  BOOL handle_SSH2_userauth_inforeq(PTInst
7223          num = get_uint32_MSBfirst(data);          num = get_uint32_MSBfirst(data);
7224          data += 4;          data += 4;
7225    
7226          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": prompts=%d", num);          logprintf(LOG_LEVEL_VERBOSE, "%s: prompts=%d", __FUNCTION__, num);
7227    
7228          ///////// step2          ///////// step2
7229          // サーバへパスフレーズを送る          // サーバへパスフレーズを送る
7230          msg = buffer_init();          msg = buffer_init();
7231          if (msg == NULL) {          if (msg == NULL) {
7232                  // TODO: error check                  // TODO: error check
7233                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
7234                  return FALSE;                  return FALSE;
7235          }          }
7236          buffer_put_int(msg, num);          buffer_put_int(msg, num);
# Line 7196  BOOL handle_SSH2_userauth_inforeq(PTInst Line 7253  BOOL handle_SSH2_userauth_inforeq(PTInst
7253                  echo = data[0];                  echo = data[0];
7254                  data[0] = '\0'; // ログ出力の為、一時的に NUL Terminate する                  data[0] = '\0'; // ログ出力の為、一時的に NUL Terminate する
7255    
7256                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ":   prompt[%d]=\"%s\", echo=%d, pass-state=%d",                  logprintf(LOG_LEVEL_VERBOSE, "%s:   prompt[%d]=\"%s\", echo=%d, pass-state=%d", __FUNCTION__,
7257                          i, prompt, slen, pvar->keyboard_interactive_password_input);                          i, prompt, slen, pvar->keyboard_interactive_password_input);
7258    
7259                  data[0] = echo; // ログ出力を行ったので、元の値に書き戻す                  data[0] = echo; // ログ出力を行ったので、元の値に書き戻す
# Line 7227  BOOL handle_SSH2_userauth_inforeq(PTInst Line 7284  BOOL handle_SSH2_userauth_inforeq(PTInst
7284          finish_send_packet(pvar);          finish_send_packet(pvar);
7285          buffer_free(msg);          buffer_free(msg);
7286    
7287          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_USERAUTH_INFO_RESPONSE.");          logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_USERAUTH_INFO_RESPONSE.", __FUNCTION__);
7288          return TRUE;          return TRUE;
7289  }  }
7290    
# Line 7330  BOOL handle_SSH2_userauth_pkok(PTInstVar Line 7387  BOOL handle_SSH2_userauth_pkok(PTInstVar
7387                  finish_send_packet(pvar);                  finish_send_packet(pvar);
7388                  buffer_free(msg);                  buffer_free(msg);
7389    
7390                  logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_USERAUTH_REQUEST method=publickey");                  logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_USERAUTH_REQUEST method=publickey", __FUNCTION__);
7391    
7392                  pvar->pageant_keyfinal = TRUE;                  pvar->pageant_keyfinal = TRUE;
7393    
# Line 7468  BOOL handle_SSH2_userauth_passwd_changer Line 7525  BOOL handle_SSH2_userauth_passwd_changer
7525          ret = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHPASSWD_INPUT), pvar->cv->HWin, passwd_change_dialog, (LPARAM)&cp);          ret = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHPASSWD_INPUT), pvar->cv->HWin, passwd_change_dialog, (LPARAM)&cp);
7526    
7527          if (ret == -1) {          if (ret == -1) {
7528                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": DialogBoxParam failed.");                  logprintf(LOG_LEVEL_WARNING, "%s: DialogBoxParam failed.", __FUNCTION__);
7529                  return FALSE;                  return FALSE;
7530          }          }
7531          else if (ret == 0) {          else if (ret == 0) {
7532                  logprintf(LOG_LEVEL_NOTICE, __FUNCTION__ ": dialog cancelled.");                  logprintf(LOG_LEVEL_NOTICE, "%s: dialog cancelled.", __FUNCTION__);
7533                  return FALSE;                  return FALSE;
7534          }          }
7535    
# Line 7485  BOOL handle_SSH2_userauth_passwd_changer Line 7542  BOOL handle_SSH2_userauth_passwd_changer
7542          lang = buffer_get_string(&data, NULL);          lang = buffer_get_string(&data, NULL);
7543          if (info == NULL || lang == NULL) {          if (info == NULL || lang == NULL) {
7544                  logprintf(LOG_LEVEL_ERROR,                  logprintf(LOG_LEVEL_ERROR,
7545                          __FUNCTION__ ": buffer_get_string returns NULL. info=%s, lang=%s",                          "%s: buffer_get_string returns NULL. info=%s, lang=%s", __FUNCTION__,
7546                          NonNull(info), NonNull(lang));                          NonNull(info), NonNull(lang));
7547          }          }
7548          else {          else {
7549                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": info=%s, lang=%s\n", info, lang);                  logprintf(LOG_LEVEL_VERBOSE, "%s: info=%s, lang=%s\n", __FUNCTION__, info, lang);
7550          }          }
7551          free(info);          free(info);
7552          free(lang);          free(lang);
# Line 7497  BOOL handle_SSH2_userauth_passwd_changer Line 7554  BOOL handle_SSH2_userauth_passwd_changer
7554          msg = buffer_init();          msg = buffer_init();
7555          if (msg == NULL) {          if (msg == NULL) {
7556                  // TODO: error check                  // TODO: error check
7557                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
7558                  return FALSE;                  return FALSE;
7559          }          }
7560    
# Line 7564  static BOOL send_channel_request_gen(PTI Line 7621  static BOOL send_channel_request_gen(PTI
7621          finish_send_packet(pvar);          finish_send_packet(pvar);
7622          buffer_free(msg);          buffer_free(msg);
7623    
7624          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_REQUEST. "          logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_CHANNEL_REQUEST. "
7625                    "local: %d, remote: %d, request-type: %s, msg1=%s, msg2=%s",                    "local: %d, remote: %d, request-type: %s, msg1=%s, msg2=%s", __FUNCTION__,
7626                    c->self_id, c->remote_id, req, msg1 ? msg1 : "none", msg2 ? msg2 : "none");                    c->self_id, c->remote_id, req, msg1 ? msg1 : "none", msg2 ? msg2 : "none");
7627          return TRUE;          return TRUE;
7628  }  }
# Line 7586  BOOL send_pty_request(PTInstVar pvar, Ch Line 7643  BOOL send_pty_request(PTInstVar pvar, Ch
7643          msg = buffer_init();          msg = buffer_init();
7644          if (msg == NULL) {          if (msg == NULL) {
7645                  // TODO: error check                  // TODO: error check
7646                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL. (msg)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL. (msg)", __FUNCTION__);
7647                  return FALSE;                  return FALSE;
7648          }          }
7649          ttymsg = buffer_init();          ttymsg = buffer_init();
7650          if (ttymsg == NULL) {          if (ttymsg == NULL) {
7651                  // TODO: error check                  // TODO: error check
7652                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL. (ttymsg)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL. (ttymsg)", __FUNCTION__);
7653                  buffer_free(msg);                  buffer_free(msg);
7654                  return FALSE;                  return FALSE;
7655          }          }
# Line 7647  BOOL send_pty_request(PTInstVar pvar, Ch Line 7704  BOOL send_pty_request(PTInstVar pvar, Ch
7704          buffer_free(msg);          buffer_free(msg);
7705          buffer_free(ttymsg);          buffer_free(ttymsg);
7706    
7707          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": sending SSH2_MSG_CHANNEL_REQUEST. "          logprintf(LOG_LEVEL_VERBOSE, "%s: sending SSH2_MSG_CHANNEL_REQUEST. "
7708                    "local: %d, remote: %d, request-type: %s, "                    "local: %d, remote: %d, request-type: %s, "
7709                    "term: %s, cols: %d, rows: %d, x: %d, y: %d, "                    "term: %s, cols: %d, rows: %d, x: %d, y: %d, "
7710                    "out-speed: %d, in-speed: %d, verase: %s, onlcr: %s",                    "out-speed: %d, in-speed: %d, verase: %s, onlcr: %s", __FUNCTION__,
7711                    c->self_id, c->remote_id, req_type, pvar->ts->TermType,                    c->self_id, c->remote_id, req_type, pvar->ts->TermType,
7712                    pvar->ssh_state.win_cols, pvar->ssh_state.win_rows, x, y,                    pvar->ssh_state.win_cols, pvar->ssh_state.win_rows, x, y,
7713                    pvar->ts->TerminalOutputSpeed, pvar->ts->TerminalInputSpeed,                    pvar->ts->TerminalOutputSpeed, pvar->ts->TerminalInputSpeed,
# Line 7692  static BOOL handle_SSH2_open_confirm(PTI Line 7749  static BOOL handle_SSH2_open_confirm(PTI
7749          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
7750          if (c == NULL) {          if (c == NULL) {
7751                  // TODO:                  // TODO:
7752                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
7753                  return FALSE;                  return FALSE;
7754          }          }
7755    
# Line 7775  static BOOL handle_SSH2_open_confirm(PTI Line 7832  static BOOL handle_SSH2_open_confirm(PTI
7832                  break;                  break;
7833    
7834          default: // NOT REACHED          default: // NOT REACHED
7835                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": Invalid channel-type. (%d)", c->type);                  logprintf(LOG_LEVEL_ERROR, "%s: Invalid channel-type. (%d)", __FUNCTION__, c->type);
7836                  return FALSE;                  return FALSE;
7837          }          }
7838          return TRUE;          return TRUE;
# Line 7806  static BOOL handle_SSH2_open_failure(PTI Line 7863  static BOOL handle_SSH2_open_failure(PTI
7863          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
7864          if (c == NULL) {          if (c == NULL) {
7865                  // TODO: SSH2_MSG_DISCONNECTを送る                  // TODO: SSH2_MSG_DISCONNECTを送る
7866                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
7867                  return FALSE;                  return FALSE;
7868          }          }
7869    
# Line 7828  static BOOL handle_SSH2_open_failure(PTI Line 7885  static BOOL handle_SSH2_open_failure(PTI
7885          cstring = buffer_get_string(&data, NULL);          cstring = buffer_get_string(&data, NULL);
7886    
7887          if (cstring == NULL) {          if (cstring == NULL) {
7888                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL", __FUNCTION__);
7889          }          }
7890          UTIL_get_lang_msg("MSG_SSH_CHANNEL_OPEN_ERROR", pvar,          UTIL_get_lang_msg("MSG_SSH_CHANNEL_OPEN_ERROR", pvar,
7891                            "SSH2_MSG_CHANNEL_OPEN_FAILURE was received.\r\nchannel [%d]: reason: %s(%d) message: %s");                            "SSH2_MSG_CHANNEL_OPEN_FAILURE was received.\r\nchannel [%d]: reason: %s(%d) message: %s");
# Line 7885  static BOOL handle_SSH2_client_global_re Line 7942  static BOOL handle_SSH2_client_global_re
7942    
7943          if (rtype == NULL) {          if (rtype == NULL) {
7944                  // rtype が NULL で無い事の保証                  // rtype が NULL で無い事の保証
7945                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL.");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL.", __FUNCTION__);
7946          }          }
7947          else if (strcmp(rtype, "hostkeys-00@openssh.com") == 0) {          else if (strcmp(rtype, "hostkeys-00@openssh.com") == 0) {
7948                  // OpenSSH 6.8では、サーバのホスト鍵が更新されると、この通知が来る。                  // OpenSSH 6.8では、サーバのホスト鍵が更新されると、この通知が来る。
# Line 7952  static BOOL handle_SSH2_channel_success( Line 8009  static BOOL handle_SSH2_channel_success(
8009                  c = ssh2_channel_lookup(pvar->shell_id);                  c = ssh2_channel_lookup(pvar->shell_id);
8010                  if (c == NULL) {                  if (c == NULL) {
8011                          // TODO: error check                          // TODO: error check
8012                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
8013                          return FALSE;                          return FALSE;
8014                  }                  }
8015                  pvar->agentfwd_enable = TRUE;                  pvar->agentfwd_enable = TRUE;
# Line 7965  static BOOL handle_SSH2_channel_success( Line 8022  static BOOL handle_SSH2_channel_success(
8022                  c = ssh2_channel_lookup(pvar->shell_id);                  c = ssh2_channel_lookup(pvar->shell_id);
8023                  if (c == NULL) {                  if (c == NULL) {
8024                          // TODO: error check                          // TODO: error check
8025                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": shell channel not found.");                          logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
8026                          return FALSE;                          return FALSE;
8027                  }                  }
8028    
# Line 8001  static BOOL handle_SSH2_channel_failure( Line 8058  static BOOL handle_SSH2_channel_failure(
8058          c = ssh2_channel_lookup(channel_id);          c = ssh2_channel_lookup(channel_id);
8059          if (c == NULL) {          if (c == NULL) {
8060                  // TODO: error check                  // TODO: error check
8061                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", channel_id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, channel_id);
8062                  return FALSE;                  return FALSE;
8063          }          }
8064    
# Line 8050  static void do_SSH2_adjust_window_size(P Line 8107  static void do_SSH2_adjust_window_size(P
8107                  msg = buffer_init();                  msg = buffer_init();
8108                  if (msg == NULL) {                  if (msg == NULL) {
8109                          // TODO: error check                          // TODO: error check
8110                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
8111                          return;                          return;
8112                  }                  }
8113                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 8086  void ssh2_channel_send_close(PTInstVar p Line 8143  void ssh2_channel_send_close(PTInstVar p
8143                  msg = buffer_init();                  msg = buffer_init();
8144                  if (msg == NULL) {                  if (msg == NULL) {
8145                          // TODO: error check                          // TODO: error check
8146                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
8147                          return;                          return;
8148                  }                  }
8149                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 8764  static BOOL handle_SSH2_channel_data(PTI Line 8821  static BOOL handle_SSH2_channel_data(PTI
8821          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
8822          if (c == NULL) {          if (c == NULL) {
8823                  // TODO:                  // TODO:
8824                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
8825                  return FALSE;                  return FALSE;
8826          }          }
8827    
# Line 8780  static BOOL handle_SSH2_channel_data(PTI Line 8837  static BOOL handle_SSH2_channel_data(PTI
8837    
8838          // バッファサイズのチェック          // バッファサイズのチェック
8839          if (str_len > c->local_maxpacket) {          if (str_len > c->local_maxpacket) {
8840                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": Data length is larger than local_maxpacket. "                  logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_maxpacket. "
8841                          "len:%d local_maxpacket:%d", str_len, c->local_maxpacket);                          "len:%d local_maxpacket:%d", __FUNCTION__, str_len, c->local_maxpacket);
8842          }          }
8843          if (str_len > c->local_window) {          if (str_len > c->local_window) {
8844                  // TODO: logging                  // TODO: logging
8845                  // local window sizeより大きなパケットは捨てる                  // local window sizeより大きなパケットは捨てる
8846                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": Data length is larger than local_window. "                  logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_window. "
8847                          "len:%d local_window:%d", str_len, c->local_window);                          "len:%d local_window:%d", __FUNCTION__, str_len, c->local_window);
8848                  return FALSE;                  return FALSE;
8849          }          }
8850    
# Line 8849  static BOOL handle_SSH2_channel_extended Line 8906  static BOOL handle_SSH2_channel_extended
8906          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
8907          if (c == NULL) {          if (c == NULL) {
8908                  // TODO:                  // TODO:
8909                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
8910                  return FALSE;                  return FALSE;
8911          }          }
8912    
# Line 8864  static BOOL handle_SSH2_channel_extended Line 8921  static BOOL handle_SSH2_channel_extended
8921          // バッファサイズのチェック          // バッファサイズのチェック
8922          if (strlen > c->local_maxpacket) {          if (strlen > c->local_maxpacket) {
8923                  // TODO: logging                  // TODO: logging
8924                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": Data length is larger than local_maxpacket. "                  logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_maxpacket. "
8925                          "len:%d local_maxpacket:%d", strlen, c->local_maxpacket);                          "len:%d local_maxpacket:%d", __FUNCTION__, strlen, c->local_maxpacket);
8926          }          }
8927          if (strlen > c->local_window) {          if (strlen > c->local_window) {
8928                  // TODO: logging                  // TODO: logging
8929                  // local window sizeより大きなパケットは捨てる                  // local window sizeより大きなパケットは捨てる
8930                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": Data length is larger than local_window. "                  logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_window. "
8931                          "len:%d local_window:%d", strlen, c->local_window);                          "len:%d local_window:%d", __FUNCTION__, strlen, c->local_window);
8932                  return FALSE;                  return FALSE;
8933          }          }
8934    
# Line 8927  static BOOL handle_SSH2_channel_eof(PTIn Line 8984  static BOOL handle_SSH2_channel_eof(PTIn
8984          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
8985          if (c == NULL) {          if (c == NULL) {
8986                  // TODO:                  // TODO:
8987                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
8988                  return FALSE;                  return FALSE;
8989          }          }
8990    
# Line 8960  static BOOL handle_SSH2_channel_open(PTI Line 9017  static BOOL handle_SSH2_channel_open(PTI
9017          buffer_t *msg;          buffer_t *msg;
9018          unsigned char *outmsg;          unsigned char *outmsg;
9019    
9020          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_OPEN was received.");          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_CHANNEL_OPEN was received.", __FUNCTION__);
9021    
9022          // 6byte(サイズ+パディング+タイプ)を取り除いた以降のペイロード          // 6byte(サイズ+パディング+タイプ)を取り除いた以降のペイロード
9023          data = pvar->ssh_state.payload;          data = pvar->ssh_state.payload;
# Line 8978  static BOOL handle_SSH2_channel_open(PTI Line 9035  static BOOL handle_SSH2_channel_open(PTI
9035          remote_maxpacket = get_uint32_MSBfirst(data);          remote_maxpacket = get_uint32_MSBfirst(data);
9036          data += 4;          data += 4;
9037    
9038          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__          logprintf(LOG_LEVEL_VERBOSE,
9039                  ": type=%s, channel=%d, init_winsize=%d, max_packetsize:%d",                  "%s: type=%s, channel=%d, init_winsize=%d, max_packetsize:%d", __FUNCTION__,
9040                  NonNull(ctype), remote_id, remote_window, remote_maxpacket);                  NonNull(ctype), remote_id, remote_window, remote_maxpacket);
9041    
9042          // check Channel Type(string)          // check Channel Type(string)
9043          if (ctype == NULL) {          if (ctype == NULL) {
9044                  // ctype が NULL で無い事の保証の為、先にチェックする                  // ctype が NULL で無い事の保証の為、先にチェックする
9045                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL. (ctype)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL. (ctype)", __FUNCTION__);
9046          }          }
9047          else if (strcmp(ctype, "forwarded-tcpip") == 0) { // port-forwarding(remote to local)          else if (strcmp(ctype, "forwarded-tcpip") == 0) { // port-forwarding(remote to local)
9048                  char *listen_addr, *orig_addr;                  char *listen_addr, *orig_addr;
# Line 9000  static BOOL handle_SSH2_channel_open(PTI Line 9057  static BOOL handle_SSH2_channel_open(PTI
9057                  data += 4;                  data += 4;
9058    
9059                  if (listen_addr && orig_addr) {                  if (listen_addr && orig_addr) {
9060                          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__                          logprintf(LOG_LEVEL_VERBOSE,
9061                                  ": %s: listen_addr=%s, listen_port=%d, orig_addr=%s, orig_port=%d",                                  "%s: %s: listen_addr=%s, listen_port=%d, orig_addr=%s, orig_port=%d", __FUNCTION__,
9062                                  ctype, listen_addr, listen_port, orig_addr, orig_port);                                  ctype, listen_addr, listen_port, orig_addr, orig_port);
9063                          // searching request entry by listen_port & create_local_channel                          // searching request entry by listen_port & create_local_channel
9064                          FWD_open(pvar, remote_id, listen_addr, listen_port, orig_addr, orig_port, &chan_num);                          FWD_open(pvar, remote_id, listen_addr, listen_port, orig_addr, orig_port, &chan_num);
# Line 9023  static BOOL handle_SSH2_channel_open(PTI Line 9080  static BOOL handle_SSH2_channel_open(PTI
9080                          c->remote_maxpacket = remote_maxpacket;                          c->remote_maxpacket = remote_maxpacket;
9081                  }                  }
9082                  else {                  else {
9083                          logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": %s: buffer_get_string returns NULL. "                          logprintf(LOG_LEVEL_ERROR, "%s: %s: buffer_get_string returns NULL. "
9084                                  "linsten_addr=%s, orig_addr=%s",                                  "linsten_addr=%s, orig_addr=%s", __FUNCTION__,
9085                                  ctype, NonNull(listen_addr), NonNull(orig_addr));                                  ctype, NonNull(listen_addr), NonNull(orig_addr));
9086                  }                  }
9087                  free(listen_addr);                  free(listen_addr);
# Line 9039  static BOOL handle_SSH2_channel_open(PTI Line 9096  static BOOL handle_SSH2_channel_open(PTI
9096                  orig_port = get_uint32_MSBfirst(data);                  orig_port = get_uint32_MSBfirst(data);
9097                  data += 4;                  data += 4;
9098    
9099                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": %s: orig_addr=%s, orig_port=%d",                  logprintf(LOG_LEVEL_VERBOSE, "%s: %s: orig_addr=%s, orig_port=%d", __FUNCTION__,
9100                          ctype, orig_str, orig_port);                          ctype, orig_str, orig_port);
9101    
9102                  free(orig_str);                  free(orig_str);
# Line 9083  static BOOL handle_SSH2_channel_open(PTI Line 9140  static BOOL handle_SSH2_channel_open(PTI
9140                          msg = buffer_init();                          msg = buffer_init();
9141                          if (msg == NULL) {                          if (msg == NULL) {
9142                                  // TODO: error check                                  // TODO: error check
9143                                  logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
9144                                  return FALSE;                                  return FALSE;
9145                          }                          }
9146                          buffer_put_int(msg, remote_id);                          buffer_put_int(msg, remote_id);
# Line 9097  static BOOL handle_SSH2_channel_open(PTI Line 9154  static BOOL handle_SSH2_channel_open(PTI
9154                          finish_send_packet(pvar);                          finish_send_packet(pvar);
9155                          buffer_free(msg);                          buffer_free(msg);
9156    
9157                          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_OPEN_FAILURE was sent.");                          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_CHANNEL_OPEN_FAILURE was sent.", __FUNCTION__ );
9158                  }                  }
9159    
9160          } else {          } else {
# Line 9133  static BOOL handle_SSH2_channel_close(PT Line 9190  static BOOL handle_SSH2_channel_close(PT
9190          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
9191          if (c == NULL) {          if (c == NULL) {
9192                  // TODO:                  // TODO:
9193                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
9194                  return FALSE;                  return FALSE;
9195          }          }
9196    
# Line 9193  static BOOL handle_SSH2_channel_request( Line 9250  static BOOL handle_SSH2_channel_request(
9250          c = ssh2_channel_lookup(id);          c = ssh2_channel_lookup(id);
9251          if (c == NULL) {          if (c == NULL) {
9252                  // TODO:                  // TODO:
9253                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
9254                  return FALSE;                  return FALSE;
9255          }          }
9256    
# Line 9202  static BOOL handle_SSH2_channel_request( Line 9259  static BOOL handle_SSH2_channel_request(
9259          want_reply = data[0];          want_reply = data[0];
9260          data += 1;          data += 1;
9261    
9262          logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__          logprintf(LOG_LEVEL_VERBOSE,
9263                  ": local=%d, remote=%d, request=%s, want_reply=%d",                  "%s: local=%d, remote=%d, request=%s, want_reply=%d",  __FUNCTION__,
9264                  c->self_id, c->remote_id, NonNull(request), want_reply);                  c->self_id, c->remote_id, NonNull(request), want_reply);
9265    
9266          if (request == NULL) {          if (request == NULL) {
9267                  // request が NULL で無い事の保証                  // request が NULL で無い事の保証
9268                  logprintf(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_get_string returns NULL. (request)");                  logprintf(LOG_LEVEL_ERROR, "%s: buffer_get_string returns NULL. (request)", __FUNCTION__);
9269          }          }
9270          else if (strcmp(request, "exit-status") == 0) {          else if (strcmp(request, "exit-status") == 0) {
9271                  // 終了コードが含まれているならば                  // 終了コードが含まれているならば
9272                  int estat = get_uint32_MSBfirst(data);                  int estat = get_uint32_MSBfirst(data);
9273                  success = 1;                  success = 1;
9274                  logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": exit-status=%d", estat);                  logprintf(LOG_LEVEL_VERBOSE, "%s: exit-status=%d", __FUNCTION__, estat);
9275          }          }
9276          else if (strcmp(request, "keepalive@openssh.com") == 0) {          else if (strcmp(request, "keepalive@openssh.com") == 0) {
9277                  // 古い OpenSSH では SUCCESS を返しても keepalive に                  // 古い OpenSSH では SUCCESS を返しても keepalive に
# Line 9239  static BOOL handle_SSH2_channel_request( Line 9296  static BOOL handle_SSH2_channel_request(
9296                  msg = buffer_init();                  msg = buffer_init();
9297                  if (msg == NULL) {                  if (msg == NULL) {
9298                          // TODO: error check                          // TODO: error check
9299                          logputs(LOG_LEVEL_ERROR, __FUNCTION__ ": buffer_init returns NULL.");                          logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
9300                          return FALSE;                          return FALSE;
9301                  }                  }
9302                  buffer_put_int(msg, c->remote_id);                  buffer_put_int(msg, c->remote_id);
# Line 9251  static BOOL handle_SSH2_channel_request( Line 9308  static BOOL handle_SSH2_channel_request(
9308                  buffer_free(msg);                  buffer_free(msg);
9309    
9310                  if (success) {                  if (success) {
9311                          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_SUCCESS was sent.");                          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_CHANNEL_SUCCESS was sent.", __FUNCTION__);
9312                  } else {                  } else {
9313                          logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_FAILURE was sent.");                          logprintf(LOG_LEVEL_VERBOSE, "%s: SSH2_MSG_CHANNEL_FAILURE was sent.", __FUNCTION__);
9314                  }                  }
9315          }          }
9316    
# Line 9286  static BOOL handle_SSH2_window_adjust(PT Line 9343  static BOOL handle_SSH2_window_adjust(PT
9343          if (c == NULL) {          if (c == NULL) {
9344                  // channel close後にadjust messageが遅れてやってくるケースもあるため、                  // channel close後にadjust messageが遅れてやってくるケースもあるため、
9345                  // FALSEでは返さないようにする。(2007.12.26 yutaka)                  // FALSEでは返さないようにする。(2007.12.26 yutaka)
9346                  logprintf(LOG_LEVEL_WARNING, __FUNCTION__ ": channel not found. (%d)", id);                  logprintf(LOG_LEVEL_WARNING, "%s: channel not found. (%d)", __FUNCTION__, id);
9347                  return TRUE;                  return TRUE;
9348          }          }
9349    
# Line 9330  static BOOL SSH_agent_response(PTInstVar Line 9387  static BOOL SSH_agent_response(PTInstVar
9387                  req_len = get_uint32_MSBfirst(data);                  req_len = get_uint32_MSBfirst(data);
9388                  if (req_len > AGENT_MAX_MSGLEN - 4) {                  if (req_len > AGENT_MAX_MSGLEN - 4) {
9389                          logprintf(LOG_LEVEL_NOTICE,                          logprintf(LOG_LEVEL_NOTICE,
9390                                  __FUNCTION__ ": Agent Forwarding Error: server request is too large. "                                  "%s: Agent Forwarding Error: server request is too large. size=%u, allowd max=%u.",
9391                                  "size=%u, allowd max=%u.", req_len, AGENT_MAX_MSGLEN-4);                                  __FUNCTION__ , req_len, AGENT_MAX_MSGLEN-4);
9392                          if (pvar->session_settings.ForwardAgentNotify) {                          if (pvar->session_settings.ForwardAgentNotify) {
9393                                  char title[MAX_UIMSG];                                  char title[MAX_UIMSG];
9394                                  UTIL_get_lang_msg("MSG_SSH_AGENTERROR_TITLE", pvar, "Bad agent request");                                  UTIL_get_lang_msg("MSG_SSH_AGENTERROR_TITLE", pvar, "Bad agent request");
# Line 9361  static BOOL SSH_agent_response(PTInstVar Line 9418  static BOOL SSH_agent_response(PTInstVar
9418    
9419          agent_query(data, *agent_request_len, &response, &resplen, NULL, NULL);          agent_query(data, *agent_request_len, &response, &resplen, NULL, NULL);
9420          if (response == NULL || resplen < 5) {          if (response == NULL || resplen < 5) {
9421                  logprintf(LOG_LEVEL_NOTICE, __FUNCTION__ "Agent Forwarding Error: agent_query is failed.");                  logprintf(LOG_LEVEL_NOTICE, "%s Agent Forwarding Error: agent_query is failed.", __FUNCTION__);
9422                  goto error;                  goto error;
9423          }          }
9424    

Legend:
Removed from v.7641  
changed lines
  Added in v.7649

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26