[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] sysprep: user-account: mark "changed file" if users were removed



Removing an user causes /etc/passwd, /etc/shadow, and /etc/group to
change, so mark the side effects as such if any user has been removed.
---
 sysprep/sysprep_operation_user_account.ml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sysprep/sysprep_operation_user_account.ml b/sysprep/sysprep_operation_user_account.ml
index bda6331..e53e5cc 100644
--- a/sysprep/sysprep_operation_user_account.ml
+++ b/sysprep/sysprep_operation_user_account.ml
@@ -55,6 +55,7 @@ let check_remove_user user =
 
 let user_account_perform ~verbose ~quiet g root side_effects =
   let typ = g#inspect_get_type root in
+  let changed = ref false in
   if typ <> "windows" then (
     g#aug_init "/" 0;
     let uid_min = g#aug_get "/files/etc/login.defs/UID_MIN" in
@@ -72,6 +73,7 @@ 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 (
+          changed := true;
           (* Get the home before removing the passwd entry. *)
           let home_dir =
             try Some (g#aug_get (userpath ^ "/home"))
@@ -90,7 +92,9 @@ let user_account_perform ~verbose ~quiet g root side_effects =
         )
     ) users;
     g#aug_save ();
-  )
+  );
+  if !changed then
+    side_effects#changed_file ()
 
 let op = {
   defaults with
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]