diff options
| author | Jun Hao | 2016-04-24 14:43:06 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2016-04-24 14:43:06 +0200 |
| commit | 97ecff0783128edeb6fe5f6e441993c9bbf2a25a (patch) | |
| tree | 7c2360206ff452d5dc0ae118f2235002150bc683 | |
| parent | ef4ed84e72a323b3d29dc34df92d3f89ad4fc322 (diff) | |
| download | emacs-97ecff0783128edeb6fe5f6e441993c9bbf2a25a.tar.gz emacs-97ecff0783128edeb6fe5f6e441993c9bbf2a25a.zip | |
Handle auth-source items with special characters on OS X
* lisp/auth-source.el
(auth-source-macos-keychain-search-items): Handle keychain
output correctly when has special chararcters (bug#22824).
| -rw-r--r-- | lisp/auth-source.el | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index cfd21a523cd..d691b54d67e 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -1758,12 +1758,28 @@ entries for git.gnus.org: | |||
| 1758 | items))) | 1758 | items))) |
| 1759 | items)) | 1759 | items)) |
| 1760 | 1760 | ||
| 1761 | |||
| 1762 | (defun auth-source--decode-octal-string (string) | ||
| 1763 | "Convert octal string to utf-8 string. E.g: 'a\134b' to 'a\b'" | ||
| 1764 | (let ((list (string-to-list string)) | ||
| 1765 | (size (length string))) | ||
| 1766 | (decode-coding-string | ||
| 1767 | (apply #'unibyte-string | ||
| 1768 | (loop for i = 0 then (+ i (if (eq (nth i list) ?\\) 4 1)) | ||
| 1769 | for var = (nth i list) | ||
| 1770 | while (< i size) | ||
| 1771 | if (eq var ?\\) | ||
| 1772 | collect (string-to-number | ||
| 1773 | (concat (cl-subseq list (+ i 1) (+ i 4))) 8) | ||
| 1774 | else | ||
| 1775 | collect var)) | ||
| 1776 | 'utf-8))) | ||
| 1777 | |||
| 1761 | (defun* auth-source-macos-keychain-search-items (coll _type _max | 1778 | (defun* auth-source-macos-keychain-search-items (coll _type _max |
| 1762 | host port | 1779 | host port |
| 1763 | &key label type | 1780 | &key label type |
| 1764 | user | 1781 | user |
| 1765 | &allow-other-keys) | 1782 | &allow-other-keys) |
| 1766 | |||
| 1767 | (let* ((keychain-generic (eq type 'macos-keychain-generic)) | 1783 | (let* ((keychain-generic (eq type 'macos-keychain-generic)) |
| 1768 | (args `(,(if keychain-generic | 1784 | (args `(,(if keychain-generic |
| 1769 | "find-generic-password" | 1785 | "find-generic-password" |
| @@ -1792,29 +1808,32 @@ entries for git.gnus.org: | |||
| 1792 | (goto-char (point-min)) | 1808 | (goto-char (point-min)) |
| 1793 | (while (not (eobp)) | 1809 | (while (not (eobp)) |
| 1794 | (cond | 1810 | (cond |
| 1795 | ((looking-at "^password: \"\\(.+\\)\"$") | 1811 | ((looking-at "^password: \\(?:0x[0-9A-F]+\\)? *\"\\(.+\\)\"") |
| 1796 | (setq ret (auth-source-macos-keychain-result-append | 1812 | (setq ret (auth-source-macos-keychain-result-append |
| 1797 | ret | 1813 | ret |
| 1798 | keychain-generic | 1814 | keychain-generic |
| 1799 | "secret" | 1815 | "secret" |
| 1800 | (lexical-let ((v (match-string 1))) | 1816 | (lexical-let ((v (auth-source--decode-octal-string |
| 1817 | (match-string 1)))) | ||
| 1801 | (lambda () v))))) | 1818 | (lambda () v))))) |
| 1802 | ;; TODO: check if this is really the label | 1819 | ;; TODO: check if this is really the label |
| 1803 | ;; match 0x00000007 <blob>="AppleID" | 1820 | ;; match 0x00000007 <blob>="AppleID" |
| 1804 | ((looking-at "^[ ]+0x00000007 <blob>=\"\\(.+\\)\"") | 1821 | ((looking-at |
| 1822 | "^[ ]+0x00000007 <blob>=\\(?:0x[0-9A-F]+\\)? *\"\\(.+\\)\"") | ||
| 1805 | (setq ret (auth-source-macos-keychain-result-append | 1823 | (setq ret (auth-source-macos-keychain-result-append |
| 1806 | ret | 1824 | ret |
| 1807 | keychain-generic | 1825 | keychain-generic |
| 1808 | "label" | 1826 | "label" |
| 1809 | (match-string 1)))) | 1827 | (auth-source--decode-octal-string (match-string 1))))) |
| 1810 | ;; match "crtr"<uint32>="aapl" | 1828 | ;; match "crtr"<uint32>="aapl" |
| 1811 | ;; match "svce"<blob>="AppleID" | 1829 | ;; match "svce"<blob>="AppleID" |
| 1812 | ((looking-at "^[ ]+\"\\([a-z]+\\)\"[^=]+=\"\\(.+\\)\"") | 1830 | ((looking-at |
| 1831 | "^[ ]+\"\\([a-z]+\\)\"[^=]+=\\(?:0x[0-9A-F]+\\)? *\"\\(.+\\)\"") | ||
| 1813 | (setq ret (auth-source-macos-keychain-result-append | 1832 | (setq ret (auth-source-macos-keychain-result-append |
| 1814 | ret | 1833 | ret |
| 1815 | keychain-generic | 1834 | keychain-generic |
| 1816 | (match-string 1) | 1835 | (auth-source--decode-octal-string (match-string 1)) |
| 1817 | (match-string 2))))) | 1836 | (auth-source--decode-octal-string (match-string 2)))))) |
| 1818 | (forward-line))) | 1837 | (forward-line))) |
| 1819 | ;; return `ret' iff it has the :secret key | 1838 | ;; return `ret' iff it has the :secret key |
| 1820 | (and (plist-get ret :secret) (list ret)))) | 1839 | (and (plist-get ret :secret) (list ret)))) |