On Tue, Sep 02, 2014 at 05:33:26PM +0200, Pino Toscano wrote:
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
I suspect you'll want to catch an exception here (G.Error I _think_?)
Not sure how to handle the exception -- perhaps by ignoring the user
and continuing to the next one, and certainly by not deleting any
directories ...
ACK with some kind of exception handling.
Rich.
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
_______________________________________________
Libguestfs mailing list
Libguestfs(a)redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html