aboutsummaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-07-25 13:03:57 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-11-08 12:31:48 -0700
commit42489752b4c78f6bbc80bb56a4347b692a067c29 (patch)
treeb7df4b0d7ad0fdd8dc6c25124947c586ba6d2d45 /src/util.lisp
parent9d857f62af05ff2f9a4ec22f1cfacecf071b668a (diff)
downloadconsfigurator-42489752b4c78f6bbc80bb56a4347b692a067c29.tar.gz
add Linux namespace-entering connections
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/util.lisp b/src/util.lisp
index dc111a2..fd6d020 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -598,10 +598,10 @@ interactive debugger."))
(2 (signal 'skipped-properties) nil)
(t ,on-failure))))
-(defun posix-login-environment (uid logname home)
+(defun posix-login-environment (&optional uid logname home)
"Reset the environment after switching UID, or similar, in a :LISP connection.
Does not currently establish a PAM session."
- (let ((rootp (zerop uid))
+ (let ((rootp (zerop (or uid (nix:geteuid))))
(maybe-preserve '("TERM")))
(when rootp
(push "SSH_AUTH_SOCK" maybe-preserve))
@@ -610,15 +610,16 @@ Does not currently establish a PAM session."
when val collect var and collect val)))
(clearenv)
(loop for (var val) on preserved by #'cddr do (setf (getenv var) val)))
- (setf (getenv "HOME") (drop-trailing-slash (unix-namestring home))
- (getenv "USER") logname
- (getenv "LOGNAME") logname
- (getenv "SHELL") "/bin/sh"
+ (when logname
+ (setf (getenv "USER") logname (getenv "LOGNAME") logname))
+ (when home
+ (setf (getenv "HOME") (drop-trailing-slash (unix-namestring home)))
+ (uiop:chdir home))
+ (setf (getenv "SHELL") "/bin/sh"
(getenv "PATH")
(if rootp
"/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
- "/usr/local/bin:/bin:/usr/bin"))
- (uiop:chdir home)))
+ "/usr/local/bin:/bin:/usr/bin"))))
;;;; System and libc calls which can fail