From 42489752b4c78f6bbc80bb56a4347b692a067c29 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 25 Jul 2021 13:03:57 -0700 Subject: add Linux namespace-entering connections Signed-off-by: Sean Whitton --- src/util.lisp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/util.lisp') 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 -- cgit v1.2.3