unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
@ 2010-07-05 16:00 Leo
  2010-07-06  8:47 ` Daiki Ueno
  0 siblings, 1 reply; 6+ messages in thread
From: Leo @ 2010-07-05 16:00 UTC (permalink / raw)
  To: 6568; +Cc: Daiki Ueno

Assume you have an encrypted file test.gpg and try to open it in emacs.
At the password prompt, type in an incorrect one. A blank buffer is
still opened.

The tricky thing is if you save back the contents in that buffer
(because accidentally you think you have typed in a correct password),
the original content will be gone.

It seems better for easypg not to open a blank buffer when password is
incorrect.

Leo





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
  2010-07-05 16:00 bug#6568: 23.2; easypg opens blank buffer when password is incorrect Leo
@ 2010-07-06  8:47 ` Daiki Ueno
  2010-07-06  9:21   ` Leo
       [not found]   ` <87sk3vi6pv.fsf@stupidchicken.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Daiki Ueno @ 2010-07-06  8:47 UTC (permalink / raw)
  To: Leo; +Cc: 6568

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

Leo <sdl.web@gmail.com> writes:

> Assume you have an encrypted file test.gpg and try to open it in emacs.
> At the password prompt, type in an incorrect one. A blank buffer is
> still opened.
>
> The tricky thing is if you save back the contents in that buffer
> (because accidentally you think you have typed in a correct password),
> the original content will be gone.
>
> It seems better for easypg not to open a blank buffer when password is
> incorrect.

Basically agree.  I have worndered for a long time how to implement
this, because error handling in find-file is too complex to control.

One idea is to re-throw the error in find-file-not-found-functions
(patch attached).  I'm not sure if this approach is palatable as other
basic Emacs commands.  Anyway, testing would be much appreciated.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: epa-file-no-select-empty.diff --]
[-- Type: text/x-patch, Size: 1253 bytes --]

=== modified file 'lisp/epa-file.el'
--- lisp/epa-file.el	2010-01-13 08:35:10 +0000
+++ lisp/epa-file.el	2010-07-06 08:36:24 +0000
@@ -101,6 +101,14 @@
     (insert (epa-file--decode-coding-string string (or coding-system-for-read
 						       'undecided)))))
 
+(defvar epa-file-error nil)
+(defun epa-file--find-file-not-found-function ()
+  (save-window-excursion
+    (let ((error (copy-sequence epa-file-error)))
+      (ignore (kill-buffer))
+      (signal 'file-error
+	      (cons "Opening input file" (cdr error))))))
+
 (defvar last-coding-system-used)
 (defun epa-file-insert-file-contents (file &optional visit beg end replace)
   (barf-if-buffer-read-only)
@@ -126,11 +134,16 @@
 	(progn
 	  (if replace
 	      (goto-char (point-min)))
+	  (add-hook 'find-file-not-found-functions
+		    'epa-file--find-file-not-found-function
+		    nil t)
 	  (condition-case error
 	      (setq string (epg-decrypt-file context local-file nil))
 	    (error
 	     (if (setq entry (assoc file epa-file-passphrase-alist))
 		 (setcdr entry nil))
+	     (make-local-variable 'epa-file-error)
+	     (setq epa-file-error error)
 	     (signal 'file-error
 		     (cons "Opening input file" (cdr error)))))
 	  (make-local-variable 'epa-file-encrypt-to)


[-- Attachment #3: Type: text/plain, Size: 25 bytes --]


Regards,
-- 
Daiki Ueno

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
  2010-07-06  8:47 ` Daiki Ueno
@ 2010-07-06  9:21   ` Leo
  2010-07-07  9:20     ` Daiki Ueno
       [not found]   ` <87sk3vi6pv.fsf@stupidchicken.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Leo @ 2010-07-06  9:21 UTC (permalink / raw)
  To: Daiki Ueno; +Cc: 6568

On 2010-07-06 09:47 +0100, Daiki Ueno wrote:
> Basically agree.  I have worndered for a long time how to implement
> this, because error handling in find-file is too complex to control.
>
> One idea is to re-throw the error in find-file-not-found-functions
> (patch attached).  I'm not sure if this approach is palatable as other
> basic Emacs commands.  Anyway, testing would be much appreciated.
>
> === modified file 'lisp/epa-file.el'
> --- lisp/epa-file.el	2010-01-13 08:35:10 +0000
> +++ lisp/epa-file.el	2010-07-06 08:36:24 +0000
[patch omitted]

Thank you for your prompt action on the bug. Much appreciated.

I have just tested the patch with emacs 23.2 and as far as I can see the
blank buffer is still opened with incorrect passwords or typing C-g at
the password prompt.

Is it plausible to just signal a 'password-error?

BTW, both the magic file and find file functions seem overly complex to
me.

Leo





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
  2010-07-06  9:21   ` Leo
@ 2010-07-07  9:20     ` Daiki Ueno
  2010-07-07  9:53       ` Leo
  0 siblings, 1 reply; 6+ messages in thread
From: Daiki Ueno @ 2010-07-07  9:20 UTC (permalink / raw)
  To: Leo; +Cc: 6568

Leo <sdl.web@gmail.com> writes:

> On 2010-07-06 09:47 +0100, Daiki Ueno wrote:
> I have just tested the patch with emacs 23.2 and as far as I can see the
> blank buffer is still opened with incorrect passwords or typing C-g at
> the password prompt.

Hmm, using the same version and having epa-file.el manually eval'ed, it
works for me.

> Is it plausible to just signal a 'password-error?

No - because epa-file-insert-file-contents may be called not only from
find-file but also from functions which expect file-error rather than
password-error.

Regards,
-- 
Daiki Ueno





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
  2010-07-07  9:20     ` Daiki Ueno
@ 2010-07-07  9:53       ` Leo
  0 siblings, 0 replies; 6+ messages in thread
From: Leo @ 2010-07-07  9:53 UTC (permalink / raw)
  To: Daiki Ueno; +Cc: 6568

On 2010-07-07 10:20 +0100, Daiki Ueno wrote:
> Leo <sdl.web@gmail.com> writes:
>
>> On 2010-07-06 09:47 +0100, Daiki Ueno wrote:
>> I have just tested the patch with emacs 23.2 and as far as I can see the
>> blank buffer is still opened with incorrect passwords or typing C-g at
>> the password prompt.
>
> Hmm, using the same version and having epa-file.el manually eval'ed, it
> works for me.

The patch seems to work beautifully. Thanks.

What I did last time was 'emacs -q -L EMACS_SRC/lisp' but I might have
compiled the wrong elisp file. Sorry about this.

>> Is it plausible to just signal a 'password-error?
>
> No - because epa-file-insert-file-contents may be called not only from
> find-file but also from functions which expect file-error rather than
> password-error.
>
> Regards,

Regards,

Leo





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#6568: 23.2; easypg opens blank buffer when password is incorrect
       [not found]   ` <87sk3vi6pv.fsf@stupidchicken.com>
@ 2010-07-08  1:20     ` Daiki Ueno
  0 siblings, 0 replies; 6+ messages in thread
From: Daiki Ueno @ 2010-07-08  1:20 UTC (permalink / raw)
  To: Chong Yidong; +Cc: 6568-close

Chong Yidong <cyd@stupidchicken.com> writes:

> Looks fine to me.  Please go ahead and check in when you're ready,
> thanks.

Done as r100747.  Thanks,
-- 
Daiki Ueno





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-08  1:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-05 16:00 bug#6568: 23.2; easypg opens blank buffer when password is incorrect Leo
2010-07-06  8:47 ` Daiki Ueno
2010-07-06  9:21   ` Leo
2010-07-07  9:20     ` Daiki Ueno
2010-07-07  9:53       ` Leo
     [not found]   ` <87sk3vi6pv.fsf@stupidchicken.com>
2010-07-08  1:20     ` Daiki Ueno

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).