From: Michael Albinus <michael.albinus@gmx.de>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Gustavo Barros <gusbrs.2016@gmail.com>, 57856@debbugs.gnu.org
Subject: bug#57856: 28.2; bookmark context strings in encrypted files
Date: Tue, 20 Sep 2022 16:49:58 +0200 [thread overview]
Message-ID: <878rmegkx5.fsf@gmx.de> (raw)
In-Reply-To: <8735cnryp6.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 19 Sep 2022 20:44:37 +0200")
[-- Attachment #1: Type: text/plain, Size: 352 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
Hi Lars,
> Michael Albinus <michael.albinus@gmx.de> writes:
>
>> But we will protect users who do in their init file
>>
>> (setq auth-sources '("~/.authinfo" "~/my-own-netrc-file-name"))
>
> Yes, that's a good point.
I gave it a try. WDYT?
(Documentation must be added, of course)
Best regards, Michael.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 4515 bytes --]
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index 86e0b48a79..4519705e14 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -319,6 +319,16 @@ auth-source-pass--name-port-user-suffixes
(list
(format "%s" name)))))
+(defun auth-source-pass-file-name-p (file)
+ "Say whether FILE is used by `auth-source-pass'."
+ (and (stringp file) (stringp auth-source-pass-filename)
+ (string-equal
+ (expand-file-name file) (expand-file-name auth-source-pass-filename))))
+
+(with-eval-after-load 'bookmark
+ (add-hook 'bookmark-inhibit-bookmark-functions
+ #'auth-source-pass-file-name-p))
+
(provide 'auth-source-pass)
;;; auth-source-pass.el ends here
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index c79e5b81f7..13ebd80106 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -522,6 +522,21 @@ auth-source-backend-parse-parameters
;; (mapcar #'auth-source-backend-parse auth-sources)
+(defun auth-source-file-name-p (file)
+ "Say whether FILE is used by `auth-sources'."
+ (let* ((backends (mapcar #'auth-source-backend-parse auth-sources))
+ (files
+ (mapcar (lambda (x)
+ (when (member (slot-value x 'type) '(json netrc plstore))
+ (slot-value x 'source)))
+ backends)))
+ (member (expand-file-name file)
+ (mapcar #'expand-file-name (remq nil files)))))
+
+(with-eval-after-load 'bookmark
+ (add-hook 'bookmark-inhibit-bookmark-functions
+ #'auth-source-file-name-p))
+
(cl-defun auth-source-search (&rest spec
&key max require create delete
&allow-other-keys)
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index f150a24bbf..941cf7932c 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -592,6 +592,14 @@ bookmark-make-record-function
in which case a default heuristic will be used. The function can also
equivalently just return ALIST without NAME.")
+(defcustom bookmark-inhibit-bookmark-functions nil
+ "List of functions to call before make a bookmark record.
+The functions take `buffer-file-name' as argument. If any of
+these functions returns non-nil, the current buffer is not used
+for a bookmark."
+ :type 'hook
+ :version "29.1")
+
(defun bookmark-make-record ()
"Return a new bookmark record (NAME . ALIST) for the current location."
(let* ((bookmark-search-size
@@ -599,10 +607,8 @@ bookmark-make-record
;; don't include any context in the bookmark file, because
;; that would leak (possibly secret) data.
(if (and buffer-file-name
- (or (and (fboundp 'epa-file-name-p)
- (epa-file-name-p buffer-file-name))
- (and (fboundp 'tramp-crypt-file-name-p)
- (tramp-crypt-file-name-p buffer-file-name))))
+ (not (run-hook-with-args-until-success
+ 'bookmark-inhibit-bookmark-functions buffer-file-name)))
0
bookmark-search-size))
(record (funcall bookmark-make-record-function)))
diff --git a/lisp/epa-hook.el b/lisp/epa-hook.el
index 70c3030881..f4616b3b91 100644
--- a/lisp/epa-hook.el
+++ b/lisp/epa-hook.el
@@ -92,6 +92,10 @@ epa-file-name-p
"Say whether FILE is handled by `epa-file'."
(and auto-encryption-mode (string-match-p epa-file-name-regexp file)))
+(with-eval-after-load 'bookmark
+ (add-hook 'bookmark-inhibit-bookmark-functions
+ #'epa-file-name-p))
+
(define-minor-mode auto-encryption-mode
"Toggle automatic file encryption/decryption (Auto Encryption mode)."
:global t :init-value t :group 'epa-file :version "23.1"
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index d556c87606..60a1c37c9c 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -852,6 +852,14 @@ tramp-crypt-handle-unlock-file
(tramp-compat-funcall
'unlock-file (tramp-crypt-encrypt-file-name filename))))
+(with-eval-after-load 'bookmark
+ (add-hook 'bookmark-inhibit-bookmark-functions
+ #'tramp-crypt-file-name-p)
+ (add-hook 'tramp-crypt-unload-hook
+ (lambda ()
+ (remove-hook 'bookmark-inhibit-bookmark-functions
+ #'tramp-crypt-file-name-p))))
+
(add-hook 'tramp-unload-hook
(lambda ()
(unload-feature 'tramp-crypt 'force)))
next prev parent reply other threads:[~2022-09-20 14:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 11:08 bug#57856: 28.2; bookmark context strings in encrypted files Gustavo Barros
2022-09-16 12:07 ` Lars Ingebrigtsen
2022-09-16 12:30 ` Gustavo Barros
2022-09-16 13:01 ` Lars Ingebrigtsen
2022-09-16 13:18 ` Michael Albinus
2022-09-18 10:19 ` Lars Ingebrigtsen
2022-09-18 10:43 ` Michael Albinus
2022-09-19 7:42 ` Lars Ingebrigtsen
2022-09-19 9:00 ` Michael Albinus
2022-09-19 12:03 ` Lars Ingebrigtsen
2022-09-19 12:16 ` Michael Albinus
2022-09-19 12:34 ` Lars Ingebrigtsen
2022-09-19 13:03 ` Michael Albinus
2022-09-19 18:44 ` Lars Ingebrigtsen
2022-09-20 14:49 ` Michael Albinus [this message]
2022-09-20 14:53 ` Lars Ingebrigtsen
2022-09-20 15:00 ` Michael Albinus
2022-09-20 15:03 ` Gustavo Barros
2022-09-20 16:19 ` Michael Albinus
2022-09-19 11:13 ` Gustavo Barros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878rmegkx5.fsf@gmx.de \
--to=michael.albinus@gmx.de \
--cc=57856@debbugs.gnu.org \
--cc=gusbrs.2016@gmail.com \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).