diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-17 13:49:34 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-06-17 14:13:58 -0700 |
commit | f2191929a8888e4b8799cda3c7c188020a4cabf6 (patch) | |
tree | e7911a1fe279499505900ee7a5be0d0cfb6ec16e /src/property | |
parent | 0b1fdac4616a56831827134abae259eadd3dc67d (diff) | |
download | consfigurator-f2191929a8888e4b8799cda3c7c188020a4cabf6.tar.gz |
wrap OSICAT:USER-INFO with getent(1) fallback
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property')
-rw-r--r-- | src/property/user.lisp | 20 |
1 files changed, 20 insertions, 0 deletions
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)))))) |