aboutsummaryrefslogtreecommitdiff
path: root/src/connection/su.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-27 15:42:01 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-27 15:42:01 -0700
commit0c47cf7807a064b854d59488007d904089dccbd7 (patch)
tree679fcbbc3f210bd532f642e84ba923d528634cb9 /src/connection/su.lisp
parentcfe16b763ba7f643861fef76ad1ed5642c5de264 (diff)
downloadconsfigurator-0c47cf7807a064b854d59488007d904089dccbd7.tar.gz
:AS connection type uses :SU not :SUDO
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/su.lisp')
-rw-r--r--src/connection/su.lisp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/connection/su.lisp b/src/connection/su.lisp
new file mode 100644
index 0000000..444ece2
--- /dev/null
+++ b/src/connection/su.lisp
@@ -0,0 +1,34 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2021 Sean Whitton <spwhitton@spwhitton.name>
+
+;;; This file is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator.connection.su)
+(named-readtables:in-readtable :consfigurator)
+
+(defmethod establish-connection ((type (eql :su)) remaining &key to)
+ (declare (ignore remaining))
+ ;; We don't support using su with a password. Use :SUDO for that.
+ (assert-euid-root)
+ (informat 1 "~&Switching to user ~A" to)
+ (make-instance 'su-connection :user to))
+
+(defclass su-connection (shell-wrap-connection)
+ ((user :initarg :user)))
+
+(defmethod connection-shell-wrap ((connection su-connection) cmd)
+ (format nil "su ~A -c ~A"
+ (escape-sh-token (slot-value connection 'user))
+ (escape-sh-token cmd)))