~ubuntu-branches/ubuntu/quantal/libssh/quantal

« back to all changes in this revision

Viewing changes to libssh/client.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-03-13 22:06:00 UTC
  • mfrom: (1.1.9 upstream) (4.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110313220600-bbqbkcj8zelnfbbo
Tags: 0.4.8-2
* Upload to unstable
* debian/control: Add texlive-fonts-recommended to Build-Depends-Indep
  (Closes: #608319)

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
  const char *banner = session->serverbanner;
111
111
  const char *openssh;
112
112
 
113
 
  ssh_log(session, SSH_LOG_RARE, "Analyzing banner: %s", banner);
114
 
 
115
 
  if (strncmp(banner, "SSH-", 4) != 0) {
116
 
    ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
117
 
    return -1;
 
113
  if (banner == NULL) {
 
114
      ssh_set_error(session, SSH_FATAL, "Invalid banner");
 
115
      return -1;
118
116
  }
119
117
 
120
118
  /*
121
119
   * Typical banners e.g. are:
122
 
   * SSH-1.5-blah
123
 
   * SSH-1.99-blah
124
 
   * SSH-2.0-blah
 
120
   *
 
121
   * SSH-1.5-openSSH_5.4
 
122
   * SSH-1.99-openSSH_3.0
 
123
   *
 
124
   * SSH-2.0-something
 
125
   * 012345678901234567890
125
126
   */
 
127
  if (strlen(banner) < 6 ||
 
128
      strncmp(banner, "SSH-", 4) != 0) {
 
129
    ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
 
130
    return -1;
 
131
  }
 
132
 
 
133
  ssh_log(session, SSH_LOG_RARE, "Analyzing banner: %s", banner);
 
134
 
126
135
  switch(banner[4]) {
127
136
    case '1':
128
137
      *ssh1 = 1;
129
 
      if (banner[6] == '9') {
130
 
        *ssh2 = 1;
131
 
      } else {
132
 
        *ssh2 = 0;
 
138
      if (strlen(banner) > 6) {
 
139
          if (banner[6] == '9') {
 
140
            *ssh2 = 1;
 
141
          } else {
 
142
            *ssh2 = 0;
 
143
          }
133
144
      }
134
145
      break;
135
146
    case '2':
143
154
 
144
155
  openssh = strstr(banner, "OpenSSH");
145
156
  if (openssh != NULL) {
146
 
    int major, minor;
147
 
    major = strtol(openssh + 8, (char **) NULL, 10);
148
 
    minor = strtol(openssh + 10, (char **) NULL, 10);
149
 
    session->openssh = SSH_VERSION_INT(major, minor, 0);
150
 
    ssh_log(session, SSH_LOG_RARE,
151
 
        "We are talking to an OpenSSH server version: %d.%d (%x)",
152
 
        major, minor, session->openssh);
 
157
      int major, minor;
 
158
 
 
159
      /*
 
160
       * The banner is typical:
 
161
       * OpenSSH_5.4
 
162
       * 012345678901234567890
 
163
       */
 
164
      if (strlen(openssh) > 9) {
 
165
          major = strtol(openssh + 8, (char **) NULL, 10);
 
166
          minor = strtol(openssh + 10, (char **) NULL, 10);
 
167
          session->openssh = SSH_VERSION_INT(major, minor, 0);
 
168
          ssh_log(session, SSH_LOG_RARE,
 
169
                  "We are talking to an OpenSSH client version: %d.%d (%x)",
 
170
                  major, minor, session->openssh);
 
171
      }
153
172
  }
154
173
 
155
174
  return 0;