[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#606885: xpdf: no longer asks for password in dialog window



> Nowadays, when the user attempts to view a password-protected PDF
> file, no dialog window is shown

In the original Xpdf, StandardSecurityHandler::checkEncryption calls
back into PDFCore::getPassword if the password's wrong. This code has
been removed from Poppler, so xpdf's implementation of getPassword
wasn't being called.

I've fixed it in xpopple with the following patch, which makes it prompt
for the password up to three times if opening a file fails with
errEncrypted:

--- xpdf/PDFCore.cc
+++ xpdf/PDFCore.cc
@@ -139,11 +139,26 @@ PDFCore::~PDFCore() {
 int PDFCore::loadFile(QCONST GooString *fileName, QCONST GooString *ownerPassword,
 		      QCONST GooString *userPassword) {
   int err;
+  std::unique_ptr<GooString> promptPassword;
+
+  for (int i = 0; i < 3; ++i) {
+    setBusyCursor(true);
+    err = loadFile2(new PDFDoc(fileName->copy(), ownerPassword, userPassword,
+			       this));
+    setBusyCursor(false);
+
+    if (err != errEncrypted) {
+      break;
+    }
+
+    // Password not supplied or not correct -- prompt for it
+    promptPassword.reset(getPassword());
+    if (!promptPassword) {
+      break;
+    }
+    ownerPassword = userPassword = promptPassword.get();
+  }
 
-  setBusyCursor(true);
-  err = loadFile2(new PDFDoc(fileName->copy(), ownerPassword, userPassword,
-			     this));
-  setBusyCursor(false);
   return err;
 }

(You may also need to add #include <memory> to get the definition of
unique_ptr if it's not already in your version.)
 
Thanks,

-- 
Adam Sampson <ats@offog.org>                         <http://offog.org/>


Reply to: