From 0c47cf7807a064b854d59488007d904089dccbd7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 27 Mar 2021 15:42:01 -0700 Subject: :AS connection type uses :SU not :SUDO Signed-off-by: Sean Whitton --- src/connection/su.lisp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/connection/su.lisp (limited to 'src/connection/su.lisp') 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 + +;;; 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 . + +(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))) -- cgit v1.2.3