aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog46
-rw-r--r--lisp/allout.el206
2 files changed, 164 insertions, 88 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d7def506d98..71fc929308b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,49 @@
12011-07-04 Ken Manheimer <ken.manheimer@gmail.com>
2
3 * allout.el (allout-encrypt-unencrypted-on-saves): Do not provide
4 insecure exception for current topic. Also note that auto-saves
5 are handled differently.
6
7 (allout-auto-save-temporarily-disabled), (allout-just-did-undo):
8 State variables for tracking auto-save inhibition situation.
9
10 (allout-write-contents-hook-handler): Rename from
11 'allout-write-file-hook-handler', and describe how it depends on
12 write-contents-functions sensitivity to non-nil value to prevent
13 file write.
14
15 (allout-auto-save-hook-handler): Remove. auto-save does not check
16 this in individual buffers, only in the starting buffer, so this
17 is not the right way for us to inhibit auto-save in a buffer
18 according to its condition.
19
20 (allout-mode): Use new allout-write-contents-hook-handler, and
21 only with write-contents-functions. Remove auto-save provisions -
22 they're implemented elsewhere.
23
24 (allout-before-change-handler): If undo is in progress, note that
25 for attention of allout-post-command-business.
26
27 (allout-post-command-business): If the command we're following was
28 an undo, check for change in the status of encrypted items and
29 adjust auto-save inhibitions accordingly.
30
31 (allout-toggle-subtree-encryption): Adjust auto-save inhibition
32 according to whether there are or aren't any plain-text topics
33 pending encryption.
34
35 (allout-inhibit-auto-save-info-for-decryption): Adjust
36 buffer-saved-size and some allout state to inhibit auto-saves if
37 there are plain-text topics pending encryption.
38
39 (allout-maybe-resume-auto-save-info-after-encryption): Adjust
40 buffer-saved-size and some allout state to not inhibit auto-saves
41 if there are no longer any plain-text topics pending encryption.
42
43 (allout-next-topic-pending-encryption),
44 (allout-encrypt-decrypted): No longer provide for exemption of the
45 current topic.
46
12011-07-04 Juri Linkov <juri@jurta.org> 472011-07-04 Juri Linkov <juri@jurta.org>
2 48
3 Add 7z operations to delete and save changed members (bug#8968). 49 Add 7z operations to delete and save changed members (bug#8968).
diff --git a/lisp/allout.el b/lisp/allout.el
index d238745df17..5b8a7a7de1a 100644
--- a/lisp/allout.el
+++ b/lisp/allout.el
@@ -823,37 +823,32 @@ formatted copy."
823 :group 'allout-encryption) 823 :group 'allout-encryption)
824;;;_ = allout-encrypt-unencrypted-on-saves 824;;;_ = allout-encrypt-unencrypted-on-saves
825(defcustom allout-encrypt-unencrypted-on-saves t 825(defcustom allout-encrypt-unencrypted-on-saves t
826 "When saving, should topics pending encryption be encrypted? 826 "If non-nil, topics pending encryption are encrypted during buffer saves.
827 827
828The idea is to prevent file-system exposure of any un-encrypted stuff, and 828This provents file-system exposure of un-encrypted contents of
829mostly covers both deliberate file writes and auto-saves. 829items marked for encryption.
830 830
831 - Yes: encrypt all topics pending encryption, even if it's the one 831When non-nil, if the topic currently being edited is decrypted,
832 currently being edited. (In that case, the currently edited topic 832it will be encrypted for saving but automatically decrypted
833 will be automatically decrypted before any user interaction, so they 833before any subsequent user interaction, so it is once again clear
834 can continue editing but the copy on the file system will be 834text for editing though the file system copy is encrypted.
835 encrypted.) 835
836 Auto-saves will use the \"All except current topic\" mode if this 836\(Auto-saves are handled differently. Buffers with plain-text
837 one is selected, to avoid practical difficulties -- see below. 837exposed encrypted topics are exempted from auto saves until all
838 - All except current topic: skip the topic currently being edited, even if 838such topics are encrypted.)"
839 it's pending encryption. This may expose the current topic on the 839
840 file sytem, but avoids the nuisance of prompts for the encryption 840 :type 'boolean
841 passphrase in the middle of editing for, eg, autosaves. 841 :version "23.1"
842 This mode is used for auto-saves for both this option and \"Yes\".
843 - No: leave it to the user to encrypt any unencrypted topics.
844
845For practical reasons, auto-saves always use the 'except-current policy
846when auto-encryption is enabled. (Otherwise, spurious passphrase prompts
847and unavoidable timing collisions are too disruptive.) If security for a
848file requires that even the current topic is never auto-saved in the clear,
849disable auto-saves for that file."
850
851 :type '(choice (const :tag "Yes" t)
852 (const :tag "All except current topic" except-current)
853 (const :tag "No" nil))
854 :version "22.1"
855 :group 'allout-encryption) 842 :group 'allout-encryption)
856(make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) 843(make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves)
844(defvar allout-auto-save-temporarily-disabled nil
845 "True while topic encryption is pending and auto-saving was active.
846
847The value of buffer-saved-size at the time of decryption is used,
848for restoring when all encryptions are established.")
849(defvar allout-just-did-undo nil
850 "True just after undo commands, until allout-post-command-business.")
851(make-variable-buffer-local 'allout-just-did-undo)
857 852
858;;;_ + Developer 853;;;_ + Developer
859;;;_ = allout-developer group 854;;;_ = allout-developer group
@@ -1564,39 +1559,43 @@ See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
1564(defmacro allout-mode-p () 1559(defmacro allout-mode-p ()
1565 "Return t if `allout-mode' is active in current buffer." 1560 "Return t if `allout-mode' is active in current buffer."
1566 'allout-mode) 1561 'allout-mode)
1567;;;_ > allout-write-file-hook-handler () 1562;;;_ > allout-write-contents-hook-handler ()
1568(defun allout-write-file-hook-handler () 1563(defun allout-write-contents-hook-handler ()
1569 "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes." 1564 "Implement `allout-encrypt-unencrypted-on-saves' for file writes
1565
1566Return nil if all goes smoothly, or else return an informative
1567message if an error is encountered. The message will serve as a
1568non-nil return on `write-contents-functions' to prevent saving of
1569the buffer while it has decrypted content.
1570
1571This behavior depends on emacs versions that implement the
1572`write-contents-functions' hook."
1570 1573
1571 (if (or (not (allout-mode-p)) 1574 (if (or (not (allout-mode-p))
1572 (not (boundp 'allout-encrypt-unencrypted-on-saves)) 1575 (not (boundp 'allout-encrypt-unencrypted-on-saves))
1573 (not allout-encrypt-unencrypted-on-saves)) 1576 (not allout-encrypt-unencrypted-on-saves))
1574 nil 1577 nil
1575 (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves 1578 (if (save-excursion (goto-char (point-min))
1576 'except-current) 1579 (allout-next-topic-pending-encryption))
1577 (point-marker)))) 1580 (progn
1578 (if (save-excursion (goto-char (point-min)) 1581 (message "auto-encrypting pending topics")
1579 (allout-next-topic-pending-encryption except-mark)) 1582 (sit-for 0)
1580 (progn 1583 (condition-case failure
1581 (message "auto-encrypting pending topics") 1584 (progn
1582 (sit-for 0)
1583 (condition-case failure
1584 (setq allout-after-save-decrypt 1585 (setq allout-after-save-decrypt
1585 (allout-encrypt-decrypted except-mark)) 1586 (allout-encrypt-decrypted))
1586 (error (message 1587 ;; aok - return nil:
1587 "allout-write-file-hook-handler suppressing error %s" 1588 nil)
1588 failure) 1589 (error
1589 (sit-for 2))))) 1590 ;; whoops - probably some still-decrypted items, return non-nil:
1590 )) 1591 (let ((text (format (concat "%s contents write inhibited due to"
1591 nil) 1592 " encrypted topic encryption error:"
1592;;;_ > allout-auto-save-hook-handler () 1593 " %s")
1593(defun allout-auto-save-hook-handler () 1594 (buffer-name (current-buffer))
1594 "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save." 1595 failure)))
1595 1596 (message text)(sit-for 2)
1596 (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves) 1597 text)))))
1597 ;; Always implement 'except-current policy when enabled. 1598 ))
1598 (let ((allout-encrypt-unencrypted-on-saves 'except-current))
1599 (allout-write-file-hook-handler))))
1600;;;_ > allout-after-saves-handler () 1599;;;_ > allout-after-saves-handler ()
1601(defun allout-after-saves-handler () 1600(defun allout-after-saves-handler ()
1602 "Decrypt topic encrypted for save, if it's currently being edited. 1601 "Decrypt topic encrypted for save, if it's currently being edited.
@@ -1960,12 +1959,7 @@ OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1960 :lighter " Allout" 1959 :lighter " Allout"
1961 :keymap 'allout-mode-map 1960 :keymap 'allout-mode-map
1962 1961
1963 (let ((write-file-hook-var-name (cond ((boundp 'write-file-functions) 1962 (let ((use-layout (if (listp allout-layout)
1964 'write-file-functions)
1965 ((boundp 'write-file-hooks)
1966 'write-file-hooks)
1967 (t 'local-write-file-hooks)))
1968 (use-layout (if (listp allout-layout)
1969 allout-layout 1963 allout-layout
1970 allout-default-layout))) 1964 allout-default-layout)))
1971 1965
@@ -1984,9 +1978,8 @@ OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
1984 (remove-hook 'post-command-hook 'allout-post-command-business t) 1978 (remove-hook 'post-command-hook 'allout-post-command-business t)
1985 (remove-hook 'before-change-functions 'allout-before-change-handler t) 1979 (remove-hook 'before-change-functions 'allout-before-change-handler t)
1986 (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) 1980 (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t)
1987 (remove-hook write-file-hook-var-name 1981 (remove-hook 'write-contents-functions
1988 'allout-write-file-hook-handler t) 1982 'allout-write-contents-hook-handler t)
1989 (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t)
1990 1983
1991 (remove-overlays (point-min) (point-max) 1984 (remove-overlays (point-min) (point-max)
1992 'category 'allout-exposure-category)) 1985 'category 'allout-exposure-category))
@@ -2019,9 +2012,8 @@ OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
2019 (add-hook 'post-command-hook 'allout-post-command-business nil t) 2012 (add-hook 'post-command-hook 'allout-post-command-business nil t)
2020 (add-hook 'before-change-functions 'allout-before-change-handler nil t) 2013 (add-hook 'before-change-functions 'allout-before-change-handler nil t)
2021 (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) 2014 (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t)
2022 (add-hook write-file-hook-var-name 'allout-write-file-hook-handler 2015 (add-hook 'write-contents-functions 'allout-write-contents-hook-handler
2023 nil t) 2016 nil t)
2024 (add-hook 'auto-save-hook 'allout-auto-save-hook-handler nil t)
2025 2017
2026 ;; Stash auto-fill settings and adjust so custom allout auto-fill 2018 ;; Stash auto-fill settings and adjust so custom allout auto-fill
2027 ;; func will be used if auto-fill is active or activated. (The 2019 ;; func will be used if auto-fill is active or activated. (The
@@ -2154,8 +2146,10 @@ internal functions use this feature cohesively bunch changes."
2154 2146
2155See `allout-overlay-interior-modification-handler' for details." 2147See `allout-overlay-interior-modification-handler' for details."
2156 2148
2157 (when (and (allout-mode-p) undo-in-progress (allout-hidden-p)) 2149 (when (and (allout-mode-p) undo-in-progress)
2158 (allout-show-children)) 2150 (setq allout-just-did-undo t)
2151 (if (allout-hidden-p)
2152 (allout-show-children)))
2159 2153
2160 ;; allout-overlay-interior-modification-handler on an overlay handles 2154 ;; allout-overlay-interior-modification-handler on an overlay handles
2161 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. 2155 ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
@@ -3308,12 +3302,29 @@ coordinating with allout activity.")
3308- Implement (and clear) `allout-post-goto-bullet', for hot-spot 3302- Implement (and clear) `allout-post-goto-bullet', for hot-spot
3309 outline commands. 3303 outline commands.
3310 3304
3305- If the command we're following was an undo, check for change in
3306 the status of encrypted items and adjust auto-save inhibitions
3307 accordingly.
3308
3311- Decrypt topic currently being edited if it was encrypted for a save." 3309- Decrypt topic currently being edited if it was encrypted for a save."
3312 3310
3313 ; Apply any external change func:
3314 (if (not (allout-mode-p)) ; In allout-mode. 3311 (if (not (allout-mode-p)) ; In allout-mode.
3315 nil 3312 nil
3316 3313
3314 (when allout-just-did-undo
3315 (setq allout-just-did-undo nil)
3316 (cond ((and (= buffer-saved-size -1)
3317 allout-auto-save-temporarily-disabled)
3318 ;; user possibly undid a decryption, deinhibit auto-save:
3319 (allout-maybe-resume-auto-save-info-after-encryption))
3320 ((save-excursion
3321 (save-restriction
3322 (widen)
3323 (goto-char (point-min))
3324 (not (allout-next-topic-pending-encryption))))
3325 ;; plain-text encrypted items are present, inhibit auto-save:
3326 (allout-inhibit-auto-save-info-for-decryption (buffer-size)))))
3327
3317 (if (and (boundp 'allout-after-save-decrypt) 3328 (if (and (boundp 'allout-after-save-decrypt)
3318 allout-after-save-decrypt) 3329 allout-after-save-decrypt)
3319 (allout-after-saves-handler)) 3330 (allout-after-saves-handler))
@@ -5899,6 +5910,8 @@ See `allout-toggle-current-subtree-encryption' for more details."
5899 " shift it in to make it encryptable"))) 5910 " shift it in to make it encryptable")))
5900 5911
5901 (let* ((allout-buffer (current-buffer)) 5912 (let* ((allout-buffer (current-buffer))
5913 ;; for use with allout-auto-save-temporarily-disabled, if necessary:
5914 (was-buffer-saved-size buffer-saved-size)
5902 ;; Assess location: 5915 ;; Assess location:
5903 (bullet-pos allout-recent-prefix-beginning) 5916 (bullet-pos allout-recent-prefix-beginning)
5904 (after-bullet-pos (point)) 5917 (after-bullet-pos (point))
@@ -5978,6 +5991,12 @@ See `allout-toggle-current-subtree-encryption' for more details."
5978 ;; Add the is-encrypted bullet qualifier: 5991 ;; Add the is-encrypted bullet qualifier:
5979 (goto-char after-bullet-pos) 5992 (goto-char after-bullet-pos)
5980 (insert "*")))) 5993 (insert "*"))))
5994
5995 ;; adjust buffer's auto-save eligibility:
5996 (if was-encrypted
5997 (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size)
5998 (allout-maybe-resume-auto-save-info-after-encryption))
5999
5981 (run-hook-with-args 'allout-structure-added-hook 6000 (run-hook-with-args 'allout-structure-added-hook
5982 bullet-pos subtree-end)))) 6001 bullet-pos subtree-end))))
5983;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue 6002;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
@@ -6029,6 +6048,7 @@ signal."
6029 (epg-context-set-passphrase-callback 6048 (epg-context-set-passphrase-callback
6030 context #'epa-passphrase-callback-function) 6049 context #'epa-passphrase-callback-function)
6031 context)) 6050 context))
6051
6032 (encoding (with-current-buffer allout-buffer 6052 (encoding (with-current-buffer allout-buffer
6033 buffer-file-coding-system)) 6053 buffer-file-coding-system))
6034 (multibyte (with-current-buffer allout-buffer 6054 (multibyte (with-current-buffer allout-buffer
@@ -6150,8 +6170,29 @@ signal."
6150 result-text)) 6170 result-text))
6151 (error (concat "Encryption produced non-armored text, which" 6171 (error (concat "Encryption produced non-armored text, which"
6152 "conflicts with allout mode -- reconfigure!"))) 6172 "conflicts with allout mode -- reconfigure!")))
6153
6154 (t result-text)))) 6173 (t result-text))))
6174;;;_ > allout-inhibit-auto-save-info-for-decryption
6175(defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size)
6176 "Temporarily prevent auto-saves in this buffer when an item is decrypted.
6177
6178WAS-BUFFER-SAVED-SIZE is the value of buffer-saved-size *before*
6179the decryption."
6180 (when (not (or (= buffer-saved-size -1) (= was-buffer-saved-size -1)))
6181 (setq allout-auto-save-temporarily-disabled was-buffer-saved-size
6182 buffer-saved-size -1)))
6183;;;_ > allout-maybe-resume-auto-save-info-after-encryption ()
6184(defun allout-maybe-resume-auto-save-info-after-encryption ()
6185 "Restore auto-save info, *if* there are no topics pending encryption."
6186 (when (and allout-auto-save-temporarily-disabled
6187 (= buffer-saved-size -1)
6188 (save-excursion
6189 (save-restriction
6190 (widen)
6191 (goto-char (point-min))
6192 (not (allout-next-topic-pending-encryption)))))
6193 (setq buffer-saved-size allout-auto-save-temporarily-disabled
6194 allout-auto-save-temporarily-disabled nil)))
6195
6155;;;_ > allout-encrypted-topic-p () 6196;;;_ > allout-encrypted-topic-p ()
6156(defun allout-encrypted-topic-p () 6197(defun allout-encrypted-topic-p ()
6157 "True if the current topic is encryptable and encrypted." 6198 "True if the current topic is encryptable and encrypted."
@@ -6162,14 +6203,10 @@ signal."
6162 (save-match-data (looking-at "\\*"))) 6203 (save-match-data (looking-at "\\*")))
6163 ) 6204 )
6164 ) 6205 )
6165;;;_ > allout-next-topic-pending-encryption (&optional except-mark) 6206;;;_ > allout-next-topic-pending-encryption ()
6166(defun allout-next-topic-pending-encryption (&optional except-mark) 6207(defun allout-next-topic-pending-encryption ()
6167 "Return the point of the next topic pending encryption, or nil if none. 6208 "Return the point of the next topic pending encryption, or nil if none.
6168 6209
6169EXCEPT-MARK identifies a point whose containing topics should be excluded
6170from encryption. This supports 'except-current mode of
6171`allout-encrypt-unencrypted-on-saves'.
6172
6173Such a topic has the `allout-topic-encryption-bullet' without an 6210Such a topic has the `allout-topic-encryption-bullet' without an
6174immediately following '*' that would mark the topic as being encrypted. It 6211immediately following '*' that would mark the topic as being encrypted. It
6175must also have content." 6212must also have content."
@@ -6204,10 +6241,7 @@ must also have content."
6204 (setq content-beg (point)) 6241 (setq content-beg (point))
6205 (backward-char 1) 6242 (backward-char 1)
6206 (allout-end-of-subtree) 6243 (allout-end-of-subtree)
6207 (if (or (<= (point) content-beg) 6244 (if (<= (point) content-beg)
6208 (and except-mark
6209 (<= content-beg except-mark)
6210 (>= (point) except-mark)))
6211 ;; Continue looking 6245 ;; Continue looking
6212 (setq got nil) 6246 (setq got nil)
6213 ;; Got it! 6247 ;; Got it!
@@ -6219,14 +6253,10 @@ must also have content."
6219 ) 6253 )
6220 ) 6254 )
6221 ) 6255 )
6222;;;_ > allout-encrypt-decrypted (&optional except-mark) 6256;;;_ > allout-encrypt-decrypted ()
6223(defun allout-encrypt-decrypted (&optional except-mark) 6257(defun allout-encrypt-decrypted ()
6224 "Encrypt topics pending encryption except those containing exemption point. 6258 "Encrypt topics pending encryption except those containing exemption point.
6225 6259
6226EXCEPT-MARK identifies a point whose containing topics should be excluded
6227from encryption. This supports the `except-current' mode of
6228`allout-encrypt-unencrypted-on-saves'.
6229
6230If a topic that is currently being edited was encrypted, we return a list 6260If a topic that is currently being edited was encrypted, we return a list
6231containing the location of the topic and the location of the cursor just 6261containing the location of the topic and the location of the cursor just
6232before the topic was encrypted. This can be used, eg, to decrypt the topic 6262before the topic was encrypted. This can be used, eg, to decrypt the topic
@@ -6242,7 +6272,7 @@ save. See `allout-encrypt-unencrypted-on-saves' for more info."
6242 bo-subtree 6272 bo-subtree
6243 editing-topic editing-point) 6273 editing-topic editing-point)
6244 (goto-char (point-min)) 6274 (goto-char (point-min))
6245 (while (allout-next-topic-pending-encryption except-mark) 6275 (while (allout-next-topic-pending-encryption)
6246 (setq was-modified (buffer-modified-p)) 6276 (setq was-modified (buffer-modified-p))
6247 (when (save-excursion 6277 (when (save-excursion
6248 (and (boundp 'allout-encrypt-unencrypted-on-saves) 6278 (and (boundp 'allout-encrypt-unencrypted-on-saves)