~ubuntu-branches/ubuntu/precise/kde-runtime/precise-updates

« back to all changes in this revision

Viewing changes to kioslave/sftp/kio_sftp.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-11-20 15:46:42 UTC
  • mfrom: (18.1.5 precise-proposed)
  • Revision ID: package-import@ubuntu.com-20141120154642-hyesdbuvsk78ihtz
Tags: 4:4.8.5-0ubuntu0.3
* SECURITY UPDATE: Insufficient Input Validation By IO Slaves and
  Webkit Part
 - Add upstream_CVE-2014-8600.diff to escape protocol twice: once
   for i18n, and once for HTML
 - https://www.kde.org/info/security/advisory-20141113-1.txt
 - CVE-2014-8600
 - LP: #1393479

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <config-runtime.h>
25
25
 
26
 
#include <fcntl.h>
 
26
#include <cerrno>
 
27
#include <cstring>
 
28
#include <unistd.h>
27
29
 
28
30
#include <QtCore/QCoreApplication>
29
31
#include <QtCore/QBuffer>
34
36
#include <QtCore/QString>
35
37
#include <QtCore/QVarLengthArray>
36
38
 
37
 
#include <stdlib.h>
38
 
#include <unistd.h>
39
 
#include <errno.h>
40
 
#include <time.h>
41
 
#include <string.h>
42
 
 
43
 
#include <arpa/inet.h>
44
 
#include <netinet/in.h>
45
 
 
46
 
#include <sys/time.h>
47
 
#include <sys/stat.h>
48
 
#include <sys/types.h>
49
 
 
50
39
#include <kapplication.h>
51
40
#include <kuser.h>
52
41
#include <kdebug.h>
56
45
#include <kstandarddirs.h>
57
46
#include <klocale.h>
58
47
#include <kurl.h>
59
 
#include <kio/ioslave_defaults.h>
60
48
#include <kmimetype.h>
61
49
#include <kde_file.h>
62
50
#include <kconfiggroup.h>
63
 
 
64
 
#include <libssh/libssh.h>
65
 
#include <libssh/sftp.h>
66
 
#include <libssh/callbacks.h>
67
 
 
68
 
#include <cerrno>
 
51
#include <kio/ioslave_defaults.h>
 
52
 
69
53
 
70
54
#define KIO_SFTP_SPECIAL_TIMEOUT 30
71
55
#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
72
56
 
 
57
// How big should each data packet be? Definitely not bigger than 64kb or
 
58
// you will overflow the 2 byte size variable in a sftp packet.
 
59
#define MAX_XFER_BUF_SIZE (60 * 1024)
 
60
#define KIO_SFTP_DB 7120
 
61
// Maximum amount of data which can be sent from the KIOSlave in one chunk
 
62
// see TransferJob::slotDataReq (max_size variable) for the value
 
63
#define MAX_TRANSFER_SIZE (14 * 1024 * 1024)
 
64
 
73
65
using namespace KIO;
74
66
extern "C"
75
67
{
195
187
 
196
188
  info.url.setProtocol("sftp");
197
189
  info.url.setHost(mHost);
198
 
  info.url.setPort(mPort);
 
190
  if (mPort > 0 && mPort != DEFAULT_SFTP_PORT) {
 
191
      info.url.setPort(mPort);
 
192
  }
199
193
  info.url.setUser(mUsername);
200
194
 
201
195
  info.comment = "sftp://" + mUsername + "@"  + mHost;
256
250
 
257
251
        infoKbdInt.url.setProtocol("sftp");
258
252
        infoKbdInt.url.setHost(mHost);
259
 
        infoKbdInt.url.setPort(mPort);
 
253
        if (mPort > 0 && mPort != DEFAULT_SFTP_PORT) {
 
254
            infoKbdInt.url.setPort(mPort);
 
255
        }
260
256
 
261
257
        infoKbdInt.caption = i18n("SFTP Login");
262
258
        infoKbdInt.comment = "sftp://" + mUsername + "@"  + mHost;
476
472
  }
477
473
 
478
474
  mHost = host;
479
 
 
480
 
  if (port > 0) {
481
 
    mPort = port;
482
 
  } else {
483
 
    struct servent *pse;
484
 
    if ((pse = getservbyname("ssh", "tcp") ) == NULL) {
485
 
      mPort = 22;
486
 
    } else {
487
 
      mPort = ntohs(pse->s_port);
488
 
    }
489
 
  }
490
 
 
 
475
  mPort = port;
491
476
  mUsername = user;
492
477
  mPassword = pass;
493
478
}
511
496
  AuthInfo info;
512
497
  info.url.setProtocol("sftp");
513
498
  info.url.setHost(mHost);
514
 
  info.url.setPort(mPort);
 
499
  if ( mPort > 0 && mPort != DEFAULT_SFTP_PORT ) {
 
500
      info.url.setPort(mPort);
 
501
  }
515
502
  info.url.setUser(mUsername);
516
503
  info.username = mUsername;
517
 
  const QString origPasswd (mPassword);
518
504
 
519
505
  // Check for cached authentication info if no password is specified...
520
506
  if (mPassword.isEmpty()) {
521
 
    kDebug(KIO_SFTP_DB) << "checking cache: info.username = " << info.username
522
 
                        << ", info.url = " << info.url.prettyUrl();
523
 
 
 
507
    kDebug(KIO_SFTP_DB) << "checking cache: info.username =" << info.username
 
508
                        << ", info.url =" << info.url.prettyUrl();
524
509
    checkCachedAuthentication(info);
 
510
  } else {
 
511
      info.password = mPassword;
525
512
  }
526
513
 
527
514
  // Start the ssh connection.
723
710
      }
724
711
    }
725
712
 
726
 
    if (!firstTime || mPassword.isEmpty()) {
 
713
    if (!firstTime || info.password.isEmpty()) {
727
714
 
728
715
      info.keepPassword = true; // make the "keep Password" check box visible to the user.
729
716
      info.setModified(false);
730
717
 
 
718
      QString username (info.username);
 
719
 
731
720
      if (firstTime) {
732
721
        dlgResult = openPasswordDialog(info);
733
722
      } else {
745
734
 
746
735
      firstTime = false;
747
736
 
748
 
      if (!mUsername.isEmpty() && mUsername != info.username) {
749
 
        kDebug(KIO_SFTP_DB) << "Username changed from" << mUsername << "to" << info.username;
 
737
      if (info.isModified() && !username.isEmpty() && username != info.username) {
 
738
        kDebug(KIO_SFTP_DB) << "Username changed from" << username << "to" << info.username;
750
739
        info.url.setUser(info.username);
751
 
        mUsername = info.username;
752
 
        mPassword = info.password;
753
740
        closeConnection();
754
741
        goto login_start;
755
742
      }
756
 
 
757
 
      mUsername = info.username;
758
 
      mPassword = info.password;
759
743
    }
760
744
 
761
745
    // Try to authenticate with keyboard interactive
820
804
  setTimeoutSpecialCommand(KIO_SFTP_SPECIAL_TIMEOUT);
821
805
 
822
806
  mConnected = true;
823
 
  mPassword = origPasswd;
824
807
  connected();
825
808
 
826
809
  info.password.fill('x');
2119
2102
    redirectUrl.setUser( mUsername );
2120
2103
    redirectUrl.setPass( mPassword );
2121
2104
    redirectUrl.setHost( mHost );
2122
 
    if (mPort > 0)
2123
 
      redirectUrl.setPort( mPort );
 
2105
    if (mPort > 0 && mPort != DEFAULT_SFTP_PORT) {
 
2106
        redirectUrl.setPort( mPort );
 
2107
    }
2124
2108
    kDebug(KIO_SFTP_DB) << "redirecting to" << redirectUrl;
2125
2109
    redirection( redirectUrl );
2126
2110
}