[BACK]Return to packet.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/packet.c between version 1.244 and 1.245

version 1.244, 2017/02/03 02:56:00 version 1.245, 2017/02/03 23:03:33
Line 347 
Line 347 
 }  }
   
 int  int
   ssh_packet_set_log_preamble(struct ssh *ssh, const char *fmt, ...)
   {
           va_list args;
           int r;
   
           free(ssh->log_preamble);
           if (fmt == NULL)
                   ssh->log_preamble = NULL;
           else {
                   va_start(args, fmt);
                   r = vasprintf(&ssh->log_preamble, fmt, args);
                   va_end(args);
                   if (r < 0 || ssh->log_preamble == NULL)
                           return SSH_ERR_ALLOC_FAIL;
           }
           return 0;
   }
   
   int
 ssh_packet_stop_discard(struct ssh *ssh)  ssh_packet_stop_discard(struct ssh *ssh)
 {  {
         struct session_state *state = ssh->state;          struct session_state *state = ssh->state;
Line 2062 
Line 2081 
                 fatal("%s: %s", __func__, ssh_err(r));                  fatal("%s: %s", __func__, ssh_err(r));
 }  }
   
   static void
   fmt_connection_id(struct ssh *ssh, char *s, size_t l)
   {
           snprintf(s, l, "%.200s%s%s port %d",
               ssh->log_preamble ? ssh->log_preamble : "",
               ssh->log_preamble ? " " : "",
               ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
   }
   
 /*  /*
  * Pretty-print connection-terminating errors and exit.   * Pretty-print connection-terminating errors and exit.
  */   */
 void  void
 sshpkt_fatal(struct ssh *ssh, const char *tag, int r)  sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
 {  {
           char remote_id[512];
   
           fmt_connection_id(ssh, remote_id, sizeof(remote_id));
   
         switch (r) {          switch (r) {
         case SSH_ERR_CONN_CLOSED:          case SSH_ERR_CONN_CLOSED:
                 logdie("Connection closed by %.200s port %d",                  logdie("Connection closed by %s", remote_id);
                     ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));  
         case SSH_ERR_CONN_TIMEOUT:          case SSH_ERR_CONN_TIMEOUT:
                 logdie("Connection %s %.200s port %d timed out",                  logdie("Connection %s %s timed out",
                     ssh->state->server_side ? "from" : "to",                      ssh->state->server_side ? "from" : "to", remote_id);
                     ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));  
         case SSH_ERR_DISCONNECTED:          case SSH_ERR_DISCONNECTED:
                 logdie("Disconnected from %.200s port %d",                  logdie("Disconnected from %s", remote_id);
                     ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));  
         case SSH_ERR_SYSTEM_ERROR:          case SSH_ERR_SYSTEM_ERROR:
                 if (errno == ECONNRESET)                  if (errno == ECONNRESET)
                         logdie("Connection reset by %.200s port %d",                          logdie("Connection reset by %s", remote_id);
                             ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));  
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case SSH_ERR_NO_CIPHER_ALG_MATCH:          case SSH_ERR_NO_CIPHER_ALG_MATCH:
         case SSH_ERR_NO_MAC_ALG_MATCH:          case SSH_ERR_NO_MAC_ALG_MATCH:
Line 2090 
Line 2118 
         case SSH_ERR_NO_KEX_ALG_MATCH:          case SSH_ERR_NO_KEX_ALG_MATCH:
         case SSH_ERR_NO_HOSTKEY_ALG_MATCH:          case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
                 if (ssh && ssh->kex && ssh->kex->failed_choice) {                  if (ssh && ssh->kex && ssh->kex->failed_choice) {
                         logdie("Unable to negotiate with %.200s port %d: %s. "                          logdie("Unable to negotiate with %s: %s. "
                             "Their offer: %s", ssh_remote_ipaddr(ssh),                              "Their offer: %s", remote_id, ssh_err(r),
                             ssh_remote_port(ssh), ssh_err(r),  
                             ssh->kex->failed_choice);                              ssh->kex->failed_choice);
                 }                  }
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         default:          default:
                 logdie("%s%sConnection %s %.200s port %d: %s",                  logdie("%s%sConnection %s %s: %s",
                     tag != NULL ? tag : "", tag != NULL ? ": " : "",                      tag != NULL ? tag : "", tag != NULL ? ": " : "",
                     ssh->state->server_side ? "from" : "to",                      ssh->state->server_side ? "from" : "to",
                     ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), ssh_err(r));                      remote_id, ssh_err(r));
         }          }
 }  }
   
Line 2113 
Line 2140 
 void  void
 ssh_packet_disconnect(struct ssh *ssh, const char *fmt,...)  ssh_packet_disconnect(struct ssh *ssh, const char *fmt,...)
 {  {
         char buf[1024];          char buf[1024], remote_id[512];
         va_list args;          va_list args;
         static int disconnecting = 0;          static int disconnecting = 0;
         int r;          int r;
Line 2126 
Line 2153 
          * Format the message.  Note that the caller must make sure the           * Format the message.  Note that the caller must make sure the
          * message is of limited size.           * message is of limited size.
          */           */
           fmt_connection_id(ssh, remote_id, sizeof(remote_id));
         va_start(args, fmt);          va_start(args, fmt);
         vsnprintf(buf, sizeof(buf), fmt, args);          vsnprintf(buf, sizeof(buf), fmt, args);
         va_end(args);          va_end(args);
   
         /* Display the error locally */          /* Display the error locally */
         logit("Disconnecting: %.100s", buf);          logit("Disconnecting %s: %.100s", remote_id, buf);
   
         /*          /*
          * Send the disconnect message to the other side, and wait           * Send the disconnect message to the other side, and wait

Legend:
Removed from v.1.244  
changed lines
  Added in v.1.245