From f2191929a8888e4b8799cda3c7c188020a4cabf6 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 17 Jun 2022 13:49:34 -0700 Subject: wrap OSICAT:USER-INFO with getent(1) fallback Signed-off-by: Sean Whitton --- src/property/user.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/property') diff --git a/src/property/user.lisp b/src/property/user.lisp index 74d4737..1dd9f1d 100644 --- a/src/property/user.lisp +++ b/src/property/user.lisp @@ -141,3 +141,23 @@ properties not strictly POSIX-compatible." (defun user-exists (username) (zerop (mrun :for-exit "getent" "passwd" username))) + +(defun user-info (username-or-uid) + "Return passwd database entry for USERNAME-OR-UID as an alist. + +Falls back to getent(1), which is not specified in POSIX, so use of this +function makes properties not strictly POSIX-compatible." + ;; getpwnam(3) and getpwuid(3) can fail to load the required NSS modules if + ;; we have chrooted or similar. In that case, it appears as though the user + ;; does not exist. So fall back to getent(1). + (or (and (lisp-connection-p) (osicat:user-info username-or-uid)) + (aand (runlines "getent" "passwd" (aetypecase username-or-uid + (string it) + (number (write-to-string it)))) + (destructuring-bind (name password uid gid &rest rest) + (split-string (car it) :separator '(#\:)) + (declare (ignore password)) + (list* (cons :name name) + (cons :user-id (parse-integer uid)) + (cons :group-id (parse-integer gid)) + (pairlis '(:gecos :home :shell) rest)))))) -- cgit v1.2.3