[PATCH consfigurator] add user:has-user-with-uid
David Bremner
david at tethera.net
Mon Aug 30 01:23:48 BST 2021
The anticipated use case is where both uid and gid are to be set; making gid
an optional keyword argument just allows a shorthand for the case of matching
gid and uid.
Signed-off-by: David Bremner <david at tethera.net>
---
src/package.lisp | 1 +
src/property/user.lisp | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/src/package.lisp b/src/package.lisp
index 2cbff57..f896609 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -440,6 +440,7 @@
(:local-nicknames (#:file #:consfigurator.property.file)
(#:os #:consfigurator.property.os))
(:export #:has-account
+ #:has-user-with-uid
#:has-groups
#:has-desktop-groups
#:has-login-shell
diff --git a/src/property/user.lisp b/src/property/user.lisp
index be7ca36..504705d 100644
--- a/src/property/user.lisp
+++ b/src/property/user.lisp
@@ -29,6 +29,28 @@ Note that this uses getent(1) and so is not strictly POSIX-compatible."
(assert-euid-root)
(mrun "useradd" "-m" username)))
+(defprop %has-uid-gid :posix (username uid gid)
+ "Ensure USERNAME has given UID and GID, and matching ownership of home directory.
+Note that this uses getent(1) and so is not strictly POSIX-compatible."
+ (:check
+ (and (= uid (parse-integer (passwd-entry 2 username)))
+ (= gid (parse-integer (passwd-entry 3 username)))))
+ (:apply
+ (let* ((gid-str (write-to-string gid))
+ (uid-str (write-to-string uid))
+ (uid+gid (format nil "~d:~d" uid gid))
+ (home (passwd-entry 5 username)))
+ (mrun "groupmod" "--gid" gid-str username)
+ (mrun "usermod" "--uid" uid-str username)
+ (mrun "chown" "-R" uid+gid home))))
+
+(defproplist has-user-with-uid :posix (username uid &key (gid uid))
+ "Ensure there is an account for USERNAME with uid UID .
+Note that this uses getent(1) and so is not strictly POSIX-compatible."
+ (:desc #?"${username} has uid ${uid} gid ${gid}")
+ (has-account username)
+ (%has-uid-gid username uid gid))
+
(defprop has-groups :posix
(username &rest groups &aux (groups* (format nil "~{~A~^,~}" groups)))
"Ensure that USERNAME is a member of secondary groups GROUPS."
--
2.33.0
More information about the sgo-software-discuss
mailing list