[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0be85f2: SQL mode supports sending passwords in process
From: |
Michael Mauger |
Subject: |
master 0be85f2: SQL mode supports sending passwords in process |
Date: |
Tue, 19 Oct 2021 00:19:27 -0400 (EDT) |
branch: master
commit 0be85f22176730b951e9ec18e298c9e1e039d8fb
Author: Michael R. Mauger <michael@mauger.com>
Commit: Michael R. Mauger <michael@mauger.com>
SQL mode supports sending passwords in process
---
etc/NEWS | 6 ++++++
lisp/progmodes/sql.el | 15 +++++++++++++++
test/lisp/progmodes/sql-tests.el | 10 ++++++++++
3 files changed, 31 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 80d4ca9..68168b4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -247,6 +247,12 @@ This function allows defining a number of keystrokes with
one form.
This macro allows defining keymap variables more conveniently.
---
+**** sql now supports sending of passwords in-process.
+To improve security, if a sql product has ':password-in-comint' set to
+true, a password supplied via the minibuffer will be sent in-process,
+as opposed to via the command-line.
+
+---
** 'kbd' can now be used in built-in, preloaded libraries.
It no longer depends on edmacro.el and cl-lib.el.
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 0789c95..f5888a0 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4659,6 +4659,14 @@ the call to \\[sql-product-interactive] with
(get-buffer new-sqli-buffer)))))
(user-error "No default SQL product defined: set `sql-product'")))
+(defun sql-comint-automatic-password (_)
+ "Intercept password prompts when we know the password.
+This must also do the job of detecting password prompts."
+ (when (and
+ sql-password
+ (not (string= "" sql-password)))
+ sql-password))
+
(defun sql-comint (product params &optional buf-name)
"Set up a comint buffer to run the SQL processor.
@@ -4683,6 +4691,13 @@ buffer. If nil, a name is chosen for it."
(setq buf-name (sql-generate-unique-sqli-buffer-name product nil)))
(set-text-properties 0 (length buf-name) nil buf-name)
+ ;; Create the buffer first, because we want to set it up before
+ ;; comint starts to run.
+ (set-buffer (get-buffer-create buf-name))
+ ;; Set up the automatic population of passwords, if supported.
+ (when (sql-get-product-feature product :password-in-comint)
+ (setq comint-password-function #'sql-comint-automatic-password))
+
;; Start the command interpreter in the buffer
;; PROC-NAME is BUF-NAME without enclosing asterisks
(let ((proc-name (replace-regexp-in-string "\\`[*]\\(.*\\)[*]\\'" "\\1"
buf-name)))
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el
index 99b79b6..aed82b1 100644
--- a/test/lisp/progmodes/sql-tests.el
+++ b/test/lisp/progmodes/sql-tests.el
@@ -416,6 +416,16 @@ The ACTION will be tested after set-up of PRODUCT."
(kill-buffer "*SQL: exist*")))
+(ert-deftest sql-tests-comint-automatic-password ()
+ (let ((sql-password nil))
+ (should-not (sql-comint-automatic-password "Password: ")))
+ (let ((sql-password ""))
+ (should-not (sql-comint-automatic-password "Password: ")))
+ (let ((sql-password "password"))
+ (should (equal "password" (sql-comint-automatic-password "Password: "))))
+ ;; Also, we shouldn't care what the password is - we rely on comint for that.
+ (let ((sql-password "password"))
+ (should (equal "password" (sql-comint-automatic-password "")))))
(provide 'sql-tests)
;;; sql-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 0be85f2: SQL mode supports sending passwords in process,
Michael Mauger <=