[Libguestfs] [PATCH] sysprep: user-account: remove the correct home

Pino Toscano ptoscano at redhat.com
Tue Sep 2 15:33:26 UTC 2014


Query using augeas for the home directory of an user, instead of
hardcoding /home/<username>.
---
 sysprep/sysprep_operation_user_account.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sysprep/sysprep_operation_user_account.ml b/sysprep/sysprep_operation_user_account.ml
index 3d88ffc..dc194f4 100644
--- a/sysprep/sysprep_operation_user_account.ml
+++ b/sysprep/sysprep_operation_user_account.ml
@@ -84,6 +84,8 @@ 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 = g#aug_get (userpath ^ "/home") 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 +93,7 @@ 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)
+          g#rm_rf home_dir
         )
     ) users;
     g#aug_save ();
-- 
1.9.3




More information about the Libguestfs mailing list