[Libguestfs] [PATCH] sysprep: remove the bash history of users
Richard W.M. Jones
rjones at redhat.com
Thu Apr 12 08:11:20 UTC 2012
On Thu, Apr 12, 2012 at 03:26:48PM +0800, Wanlong Gao wrote:
> Remove the bash history of users in home directory,
> and history of root.
>
> Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
> ---
> sysprep/Makefile.am | 2 ++
> sysprep/sysprep_operation_bash_history.ml | 44 +++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
> create mode 100644 sysprep/sysprep_operation_bash_history.ml
>
> diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
> index 8730bc0..3a48702 100644
> --- a/sysprep/Makefile.am
> +++ b/sysprep/Makefile.am
> @@ -33,6 +33,7 @@ SOURCES = \
> main.ml \
> sysprep_operation.ml \
> sysprep_operation.mli \
> + sysprep_operation_bash_history.ml \
> sysprep_operation_cron_spool.ml \
> sysprep_operation_dhcp_client_state.ml \
> sysprep_operation_dhcp_server_state.ml \
> @@ -56,6 +57,7 @@ if HAVE_OCAML
> OBJECTS = \
> utils.cmx \
> sysprep_operation.cmx \
> + sysprep_operation_bash_history.cmx \
> sysprep_operation_cron_spool.cmx \
> sysprep_operation_dhcp_client_state.cmx \
> sysprep_operation_dhcp_server_state.cmx \
> diff --git a/sysprep/sysprep_operation_bash_history.ml b/sysprep/sysprep_operation_bash_history.ml
> new file mode 100644
> index 0000000..1f33ab6
> --- /dev/null
> +++ b/sysprep/sysprep_operation_bash_history.ml
> @@ -0,0 +1,44 @@
> +(* virt-sysprep
> + * Copyright (C) 2012 Fujitsu Inc.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + *)
> +
> +open Sysprep_operation
> +
> +module G = Guestfs
> +
> +let bash_history_perform g root =
> + let typ = g#inspect_get_type root in
> + if typ <> "windows" then (
> + let files = g#glob_expand "/home/*/.bash_history" in
> + Array.iter g#rm_rf files;
> + g#rm_rf "/root/.bash_history";
Since .bash_history isn't likely to be a directory, I think it's
better to write:
g#rm ...
However you'll need to protect against missing files, so:
try g#rm file with G.Error _ -> ()
(compare with sysprep/sysprep_operation_smolt_uuid.ml)
The rest looks OK to me.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
More information about the Libguestfs
mailing list