Commit 6ec541f16b643e671df79a3a714e752dbfa56967

Thomas de Grivel 2018-07-10T12:45:14

user

diff --git a/unix/defs.lisp b/unix/defs.lisp
index 38f4a11..f6dc5db 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -29,7 +29,7 @@
 
 ;;  User
 
-(define-resource-class user ()
+(define-resource-class user (resource-container)
   ()
   ((probe-user-in-/etc/passwd :properties (:ensure :login :uid :gid :realname
                                                    :home :shell))
diff --git a/unix/operations.lisp b/unix/operations.lisp
index 69150f9..5d882aa 100644
--- a/unix/operations.lisp
+++ b/unix/operations.lisp
@@ -43,21 +43,21 @@
 
 ;;  User
 
-(defmethod op-update-user ((user user) (os os-unix) &key ensure uid gid
-                                                      realname home shell
-                                                      login-class
-                                                      groups)
+(defmethod op-update-user ((user user) (os os-unix)
+                           &key ensure uid gid realname home shell
+                             login-class groups)
   (run-as-root
    (join-str " "
              (ecase ensure
                ((:absent)  "userdel")
-               ((:present) "useradd")
+               ((:present) "useradd -m")
                ((nil)      "usermod"))
              (when realname `("-c" ,(sh-quote realname)))
              (when home `("-d" ,(sh-quote home)))
              (when gid `("-g" ,(sh-quote gid)))
              (when login-class `("-L" ,(sh-quote login-class)))
-             (when groups `("-S" ,(join-str "," (mapcar #'sh-quote groups))))
+             (when groups `("-S" ,(join-str "," (mapcar #'sh-quote
+                                                        groups))))
              (when shell `("-s" ,(sh-quote shell)))
              (when uid `("-u" ,(sh-quote uid)))
              (sh-quote (resource-id user)))))
diff --git a/unix/probes.lisp b/unix/probes.lisp
index a1b3beb..9d7badf 100644
--- a/unix/probes.lisp
+++ b/unix/probes.lisp
@@ -45,9 +45,10 @@
         (when (etypecase id
                 (string (string= id login))
                 (integer (= id uid)))
-          (setq ensure nil
-                home (resource 'directory home)
-                shell (resource 'file shell))
+          (with-parent-resource *host*
+            (setq ensure nil
+                  home (resource 'directory home)
+                  shell (resource 'file shell)))
           (return (values* #1#))))
       (properties* (ensure . #1#)))))
 
@@ -62,14 +63,16 @@
              (user-group nil))
         (with-group<5> (name passwd gid members)
             (grep user-login "/etc/group")
-          (cond ((= user-gid gid)
-                 (setq user-group (resource 'group name)))
-                ((find user-login members :test #'string=)
-                 (push (resource 'group name) groups))))
-        (setq groups (sort groups #'string< :key #'resource-id)
-              groups (if user-group
-                         (cons user-group groups)
-                         groups))))
+          (when name
+            (with-parent-resource *host*
+              (cond ((= user-gid gid)
+                     (setq user-group (resource 'group name)))
+                    ((find user-login members :test #'string=)
+                     (push (resource 'group name) groups))))
+            (setq groups (sort groups #'string< :key #'resource-id)
+                  groups (if user-group
+                             (cons user-group groups)
+                             groups))))))
     (properties* groups)))
 
 ;;  VNode (filesystem node)