diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-26 13:42:03 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-27 08:33:17 -0700 |
commit | b1688ced028a63e6817e97f490ecf081d45c14c9 (patch) | |
tree | 5280fb4cc0ed1dfc4e47a127c9e547c4b9793602 /src/connection/sudo.lisp | |
parent | 03e93e96fdc7b4dd17e24a101202a25fb6d20c1e (diff) | |
download | consfigurator-b1688ced028a63e6817e97f490ecf081d45c14c9.tar.gz |
factor out SHELL-WRAP-CONNECTION superclass
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/sudo.lisp')
-rw-r--r-- | src/connection/sudo.lisp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/connection/sudo.lisp b/src/connection/sudo.lisp index fabae71..234dac7 100644 --- a/src/connection/sudo.lisp +++ b/src/connection/sudo.lisp @@ -63,19 +63,17 @@ (format t "Establishing sudo connection to ~A~%" user) (make-instance 'sudo-connection :user user :password password)) -(defclass sudo-connection (posix-connection) +(defclass sudo-connection (shell-wrap-connection) ((user :initarg :user) (password :initarg :password))) -(defun sudocmd (connection &rest args) +(defmethod connection-shell-wrap ((connection sudo-connection) cmd) ;; wrap in sh -c so that it is more likely we are either asked for a ;; password for all our commands or not asked for one for any (format nil "sudo -HkS --prompt=\"\" --user=~A sh -c ~A" - (slot-value connection 'user) - (escape-sh-token - (if (cdr args) (escape-sh-command args) (car args))))) + (slot-value connection 'user) (escape-sh-token cmd))) (defmethod connection-run ((c sudo-connection) cmd &optional input) ;; send the password followed by ^M, then the real stdin. use CODE-CHAR in @@ -103,19 +101,7 @@ input-stream) (t nil)))) - (mrun :may-fail :input new-input (sudocmd c cmd)))) - -(defmethod connection-readfile ((c sudo-connection) path) - (multiple-value-bind (out exit-code) - (connection-run - c - (format nil "test -r ~A && cat ~:*~A" (escape-sh-token path))) - (if (= 0 exit-code) - out - (error "File ~S not readable" path)))) - -(defmethod connection-writefile ((c sudo-connection) path contents) - (connection-run c #?"cat >${path}" contents)) + (call-next-method c cmd new-input))) (defmethod connection-upload ((c sudo-connection) from to) - (run (sudocmd c "cp" from to))) + (connection-run c #?"cp ${from} ${to}" nil)) |