[Pkg-libvirt-commits] [libguestfs] 19/63: sysprep: user-account: remove the correct home

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:43:25 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.39-1
in repository libguestfs.

commit e52742e6d35ae33e55e6fd7a0228e55ec63102d3
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Wed Sep 3 11:13:54 2014 +0200

    sysprep: user-account: remove the correct home
    
    Query using augeas for the home directory of an user, instead of
    hardcoding /home/<username>.
---
 sysprep/sysprep_operation_user_account.ml | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sysprep/sysprep_operation_user_account.ml b/sysprep/sysprep_operation_user_account.ml
index 3d88ffc..cdb0bfd 100644
--- a/sysprep/sysprep_operation_user_account.ml
+++ b/sysprep/sysprep_operation_user_account.ml
@@ -84,6 +84,14 @@ let user_account_perform ~verbose ~quiet g root side_effects =
           String.sub userpath (i+1) (String.length userpath -i-1) in
         if uid >= uid_min && uid <= uid_max
            && check_remove_user username then (
+          (* Get the home before removing the passwd entry. *)
+          let home_dir =
+            try Some (g#aug_get (userpath ^ "/home"))
+            with _ ->
+              if verbose then
+                warning ~prog (f_"Cannot get the home directory for %s")
+                  username;
+              None in
           g#aug_rm userpath;
           (* XXX Augeas doesn't yet have a lens for /etc/shadow, so the
            * next line currently does nothing, but should start to
@@ -91,7 +99,9 @@ let user_account_perform ~verbose ~quiet g root side_effects =
            *)
           g#aug_rm (sprintf "/files/etc/shadow/%s" username);
           g#aug_rm (sprintf "/files/etc/group/%s" username);
-          g#rm_rf ("/home/" ^ username)
+          match home_dir with
+          | None -> ()
+          | Some dir -> g#rm_rf dir
         )
     ) users;
     g#aug_save ();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list