[PATCH] add user:has-account-with-uid

Sean Whitton spwhitton at spwhitton.name
Sun Sep 12 21:22:43 BST 2021


Hello David,

On Fri 10 Sep 2021 at 10:32PM -03, David Bremner wrote:

> diff --git a/src/package.lisp b/src/package.lisp
> index 31288d2..c3b1948 100644
> --- a/src/package.lisp
> +++ b/src/package.lisp
> @@ -445,6 +445,7 @@
>    (:local-nicknames (#:file  #:consfigurator.property.file)
>                      (#:os    #:consfigurator.property.os))
>    (:export #:has-account
> +           #:has-account-with-uid
>             #:has-groups
>             #:has-desktop-groups
>  	   #:has-login-shell
> diff --git a/src/property/user.lisp b/src/property/user.lisp
> index be7ca36..4dfb7fb 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."
> +  (: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))))

I've realised a potential problem with your approach here, sorry I
didn't think of it earlier -- what happens if the caller specifies a gid
of a group that doesn't exist?  I guess the chown will still succeed,
but is that okay?  Should we also ensure the group exists?  Seems
especially relevant on operating systems which don't create a group with
the same name as the user when creating a user.

Also just while we're here, do you mind if I switch $HOME for HOME?  I
believe that is the standard way to refer to environment variables
outside of shell scripts.

-- 
Sean Whitton



More information about the sgo-software-discuss mailing list