Browse Source

KPasswordEdit::password() now returns a TQString instead of a const char *. This relates to bug 2961.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/6/head
Michele Calgaro 5 months ago
parent
commit
6ec26d859b
Signed by: Michele Calgaro <michele.calgaro@yahoo.it> GPG Key ID: 2A75B7CA8ADED5CF

+ 2
- 2
tdecert/tdecertpart.cc View File

@@ -482,7 +482,7 @@ emit completed();
482 482
 //       x-pkcs12 loading
483 483
 /////////////////////////////////////////////////////////////////////////////
484 484
 if (whatType == "application/x-pkcs12") {
485
-	TQCString pass;
485
+	TQString pass;
486 486
 	_p12 = KSSLPKCS12::loadCertFile(m_file);
487 487
 
488 488
 	while (!_p12) {
@@ -490,7 +490,7 @@ if (whatType == "application/x-pkcs12") {
490 490
 		int rc = KPasswordDialog::getPassword(pass, i18n("Certificate Password"));
491 491
 		if (rc != KPasswordDialog::Accepted) break;
492 492
 
493
-		_p12 = KSSLPKCS12::loadCertFile(m_file, TQString(pass));
493
+		_p12 = KSSLPKCS12::loadCertFile(m_file, pass);
494 494
 
495 495
 		if (!_p12) {
496 496
 			rc = KMessageBox::warningContinueCancel(_frame, i18n("The certificate file could not be loaded. Try a different password?"), i18n("Certificate Import"),i18n("Try Different"));

+ 7
- 10
tdeio/kssl/ksslpemcallback.cc View File

@@ -28,26 +28,23 @@
28 28
 
29 29
 int KSSLPemCallback(char *buf, int size, int rwflag, void *userdata) {
30 30
 #ifdef KSSL_HAVE_SSL
31
-	TQCString pass;
31
+	TQString pass2;
32 32
 	Q_UNUSED(userdata);
33 33
 	Q_UNUSED(rwflag);
34 34
 
35 35
 	if (!buf) return -1;
36
-	int rc = KPasswordDialog::getPassword(pass, i18n("Certificate password"));
36
+	int rc = KPasswordDialog::getPassword(pass2, i18n("Certificate password"));
37 37
 	if (rc != KPasswordDialog::Accepted) return -1;
38 38
 
39
+	TQCString pass = pass2.utf8();  // utf8 length may differ from TQString length
39 40
 	const uint passlen = pass.length();
40 41
 	if (passlen > (unsigned int)size-1)
41 42
 		pass.truncate((unsigned int)size-1);
42 43
 
43
-	tqstrncpy(buf, pass.data(), size-1);
44
-    
45
-	for (unsigned int i = 0; i < passlen; i++)
46
-		pass[i] = 0;
47
-	// To be sure that it doesn't optimise the previous loop away
48
-	for (unsigned int i = 0; i < passlen; i++)
49
-		pass[i] = pass[i];
50
-	buf[size-1] = 0;
44
+	tqstrncpy(buf, pass, size-1);
45
+  buf[size-1] = 0;
46
+  pass.fill(' ');
47
+  pass2.fill(' ');
51 48
 	return (int)passlen;
52 49
 #else
53 50
 	Q_UNUSED(buf);

+ 7
- 7
tdeio/misc/tdewalletd/tdewalletd.cpp View File

@@ -471,13 +471,13 @@ int TDEWalletD::internalOpen(const TQCString& appid, const TQString& wallet, boo
471 471
 			kpd->setAllowEmptyPasswords(true);
472 472
 		}
473 473
 
474
-		const char *p = 0L;
474
+		TQCString p;
475 475
 		while (!b->isOpen()) {
476 476
 			assert(kpd); // kpd can't be null if isOpen() is false
477 477
 			setupDialog( kpd, w, appid, modal );
478 478
 			if (kpd->exec() == KDialog::Accepted) {
479
-				p = kpd->password();
480
-				int rc = b->open(TQByteArray().duplicate(p, strlen(p)));
479
+				p = kpd->password().utf8();
480
+				int rc = b->open(TQByteArray().duplicate(p));
481 481
 				if (!b->isOpen()) {
482 482
 					kpd->setPrompt(i18n("<qt>Error opening the wallet '<b>%1</b>'. Please try again.<br>(Error code %2: %3)").arg(TQStyleSheet::escape(wallet)).arg(rc).arg(TDEWallet::Backend::openRCToString(rc)));
483 483
 					kpd->clearPassword();
@@ -487,7 +487,7 @@ int TDEWalletD::internalOpen(const TQCString& appid, const TQString& wallet, boo
487 487
 			}
488 488
 		}
489 489
 
490
-		if (!emptyPass && (!p || !b->isOpen())) {
490
+		if (!emptyPass && (p.isEmpty() || !b->isOpen())) {
491 491
 			delete b;
492 492
 			delete kpd;
493 493
 			return -1;
@@ -662,11 +662,11 @@ void TDEWalletD::doTransactionChangePassword(const TQCString& appid, const TQStr
662 662
 	kpd->setAllowEmptyPasswords(true);
663 663
 	setupDialog( kpd, wId, appid, false );
664 664
 	if (kpd->exec() == KDialog::Accepted) {
665
-		const char *p = kpd->password();
666
-		if (p) {
665
+		TQCString p = kpd->password().utf8();
666
+		if (!p.isEmpty()) {
667 667
 			_passwords[wallet] = p;
668 668
 			TQByteArray pa;
669
-			pa.duplicate(p, strlen(p));
669
+			pa.duplicate(p);
670 670
 			int rc = w->close(pa);
671 671
 			if (rc < 0) {
672 672
 				KMessageBox::sorryWId(wId, i18n("Error re-encrypting the wallet. Password was not changed."), i18n("TDE Wallet Service"));

+ 1
- 1
tdenewstuff/security.cpp View File

@@ -172,7 +172,7 @@ void Security::slotDataArrived(KProcIO *procIO)
172 172
        case Sign:
173 173
          if (data.find("passphrase.enter") != -1)
174 174
          {
175
-           TQCString password;
175
+           TQString password;
176 176
            KeyStruct key = m_keys[m_secretKey];
177 177
            int result = KPasswordDialog::getPassword(password, i18n("<qt>Enter passphrase for key <b>0x%1</b>, belonging to<br><i>%2&lt;%3&gt;</i>:</qt>").arg(m_secretKey).arg(key.name).arg(key.mail));
178 178
            if (result == KPasswordDialog::Accepted)

+ 4
- 4
tdersync/tdersync.cpp View File

@@ -497,13 +497,13 @@ KDE_EXPORT int KRsync::establishConnectionRsync(char *buffer, TDEIO::fileoffset_
497 497
                 myDebug( << "sending mpass" << endl);
498 498
                 connectionAuth.prompt = thisFn+buf;
499 499
                 connectionAuth.password = TQString(); // don't prefill
500
-                TQCString thispass;
500
+                TQString thispass;
501 501
                 if (KPasswordDialog::getPassword (thispass, i18n("Remote authorization required") + TQString("\n") + i18n("Please input") + TQString(" ") + TQString(buf), NULL) != 1) {
502 502
                     shutdownConnection(true, false);
503 503
                     return -1;
504 504
                 }
505 505
                 else {
506
-                    connectionAuth.password = TQString(thispass);
506
+                    connectionAuth.password = thispass;
507 507
                 }
508 508
                 connectionAuth.password += "\n";
509 509
                 myDebug( << "sending pass" << endl);
@@ -620,13 +620,13 @@ KDE_EXPORT int KRsync::establishConnectionUnison(char *buffer, TDEIO::fileoffset
620 620
                 myDebug( << "sending mpass" << endl);
621 621
                 connectionAuth.prompt = thisFn+buf;
622 622
                 connectionAuth.password = TQString(); // don't prefill
623
-                TQCString thispass;
623
+                TQString thispass;
624 624
                 if (KPasswordDialog::getPassword (thispass, i18n("Remote authorization required") + TQString("\n") + i18n("Please input") + TQString(" ") + TQString(buf), NULL) != 1) {
625 625
                     slotUnisonCancelled();
626 626
                     return -1;
627 627
                 }
628 628
                 else {
629
-                    connectionAuth.password = TQString(thispass);
629
+                    connectionAuth.password = thispass;
630 630
                 }
631 631
                 connectionAuth.password += "\n";
632 632
                 myDebug( << "sending pass" << endl);

+ 8
- 9
tdeui/kpassdlg.cpp View File

@@ -138,8 +138,8 @@ KPasswordEdit::~KPasswordEdit()
138 138
 {
139 139
 }
140 140
 
141
-const char *KPasswordEdit::password() const {
142
-    return text().ascii();
141
+TQString KPasswordEdit::password() const {
142
+    return text();
143 143
 }
144 144
 
145 145
 void KPasswordEdit::erase()
@@ -404,7 +404,7 @@ void KPasswordDialog::erase()
404 404
 void KPasswordDialog::slotOk()
405 405
 {
406 406
     if (m_Type == NewPassword) {
407
-	if (strcmp(m_pEdit->password(), m_pEdit2->password())) {
407
+	if (m_pEdit->password() != m_pEdit2->password()) {
408 408
 	    KMessageBox::sorry(this, i18n("You entered two different "
409 409
 		    "passwords. Please try again."));
410 410
 	    erase();
@@ -459,8 +459,7 @@ void KPasswordDialog::slotLayout()
459 459
 }
460 460
 
461 461
 
462
-// static . antlarr: KDE 4: Make it const TQString & prompt
463
-int KPasswordDialog::getPassword(TQCString &password, TQString prompt,
462
+int KPasswordDialog::getPassword(TQString &password, TQString prompt,
464 463
 	int *keep)
465 464
 {
466 465
     const bool enableKeep = (keep && *keep);
@@ -477,7 +476,7 @@ int KPasswordDialog::getPassword(TQCString &password, TQString prompt,
477 476
 
478 477
 
479 478
 // static . antlarr: KDE 4: Make it const TQString & prompt
480
-int KPasswordDialog::getNewPassword(TQCString &password, TQString prompt)
479
+int KPasswordDialog::getNewPassword(TQString &password, TQString prompt)
481 480
 {
482 481
     KPasswordDialog* const dlg = new KPasswordDialog(NewPassword, prompt);
483 482
     const int ret = dlg->exec();
@@ -502,8 +501,8 @@ void KPasswordDialog::virtual_hook( int id, void* data )
502 501
 void KPasswordDialog::enableOkBtn()
503 502
 {
504 503
     if (m_Type == NewPassword) {
505
-      const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0
506
-                   && (d->allowEmptyPasswords || m_pEdit->password()[0]);
504
+      const bool match = (m_pEdit->password() == m_pEdit2->password())
505
+                   && (d->allowEmptyPasswords || !m_pEdit->password().isEmpty());
507 506
 
508 507
       const TQString pass(m_pEdit->password());
509 508
 
@@ -515,7 +514,7 @@ void KPasswordDialog::enableOkBtn()
515 514
           enableButtonOK( match );
516 515
       }
517 516
 
518
-      if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) {
517
+      if ( match && d->allowEmptyPasswords && m_pEdit->password().isEmpty() ) {
519 518
           d->m_MatchLabel->setText( i18n("Password is empty") );
520 519
       } else {
521 520
           if ((int) pass.length() < minPasswordLength) {

+ 8
- 18
tdeui/kpassdlg.h View File

@@ -76,10 +76,9 @@ public:
76 76
     ~KPasswordEdit();
77 77
 
78 78
     /**
79
-     * Returns the password. The memory is freed in the destructor
80
-     * so you should make a copy.
79
+     * Returns the password.
81 80
      */
82
-    const char *password() const;
81
+    TQString password() const;
83 82
 
84 83
     /**
85 84
      * Erases the current password.
@@ -129,7 +128,7 @@ private:
129 128
  * <b>Usage example</b>\n
130 129
  *
131 130
  * \code
132
- * TQCString password;
131
+ * TQString password;
133 132
  * int result = KPasswordDialog::getPassword(password, i18n("Prompt message"));
134 133
  * if (result == KPasswordDialog::Accepted)
135 134
  *     use(password);
@@ -146,14 +145,6 @@ private:
146 145
  * Core dumps are dangerous because they are an image of the process memory,
147 146
  * and thus include any passwords that were in memory.
148 147
  *
149
- * @li You should delete passwords as soon as they are not needed anymore.
150
- * The functions getPassword() and getNewPassword() return the
151
- * password as a TQCString. I believe this is safer than a TQString. A QString
152
- * stores its characters internally as 16-bit wide values, so conversions are
153
- * needed, both for creating the TQString and by using it. The temporary
154
- * memory used for these conversion is probably not erased. This could lead
155
- * to stray  passwords in memory, even if you think you erased all of them.
156
- *
157 148
  * @author Geert Jansen <jansen@kde.org>
158 149
  */
159 150
 
@@ -327,10 +318,9 @@ public:
327 318
     int passwordStrengthWarningLevel() const;
328 319
 
329 320
     /**
330
-     * Returns the password entered. The memory is freed in the destructor,
331
-     * so you should make a copy.
321
+     * Returns the password entered.
332 322
      */
333
-    const char *password() const { return m_pEdit->password(); }
323
+    TQString password() const { return m_pEdit->password(); }
334 324
 
335 325
     /**
336 326
      * Clears the password input field. You might want to use this after the
@@ -356,7 +346,7 @@ public:
356 346
      * is shown and the result is stored in *keep.
357 347
      * @return Result code: Accepted or Rejected.
358 348
      */
359
-    static int getPassword(TQCString &password, TQString prompt, int *keep=0L);
349
+    static int getPassword(TQString &password, TQString prompt, int *keep=0L);
360 350
 
361 351
     /**
362 352
      * Pops up the dialog, asks the user for a password and returns it. The
@@ -368,7 +358,7 @@ public:
368 358
      * information. The text is word broken to fit nicely in the dialog.
369 359
      * @return Result code: Accepted or Rejected.
370 360
      */
371
-    static int getNewPassword(TQCString &password, TQString prompt);
361
+    static int getNewPassword(TQString &password, TQString prompt);
372 362
 
373 363
     /**
374 364
      * Static helper function that disables core dumps.
@@ -388,7 +378,7 @@ protected:
388 378
      * checking in derived classes. It should return @p true if the
389 379
      * password is valid, @p false otherwise.
390 380
      */
391
-    virtual bool checkPassword(const char *) { return true; }
381
+    virtual bool checkPassword(const TQString&) { return true; }
392 382
 
393 383
 private slots:
394 384
   void enableOkBtn();

Loading…
Cancel
Save