This removes tmp files under /tmp and /var/tmp. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- sysprep/Makefile.am | 1 + sysprep/sysprep_operation_tmp_files.ml | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 sysprep/sysprep_operation_tmp_files.ml diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index fcd17fc..b89345a 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -65,6 +65,7 @@ operations = \ ssh_hostkeys \ ssh_userdir \ sssd_db_log \ + tmp_files \ udev_persistent_net \ user_account \ utmp yum_uuid diff --git a/sysprep/sysprep_operation_tmp_files.ml b/sysprep/sysprep_operation_tmp_files.ml new file mode 100644 index 0000000..a2187df --- /dev/null +++ b/sysprep/sysprep_operation_tmp_files.ml @@ -0,0 +1,52 @@ +(* virt-sysprep + * Copyright (C) 2013 Fujitsu Limited. + * + * 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 +open Common_gettext.Gettext + +module G = Guestfs + +let tmp_files_perform g root + let typ = g#inspect_get_type root in + if typ <> "windows" then ( + let paths = [ "/tmp/*"; + "/var/tmp/*"; ] in + List.iter ( + fun path -> + let files = g#glob_expand path in + Array.iter ( + fun file -> + g#rm_rf file; + ) files; + ) paths; + + [] + ) + else [] + +let op = { + defaults with + name = "tmp-files"; + enabled_by_default = true; + heading = s_"Remove the tmp files"; + pod_description = Some (s_"\ +This removes the temporary files under C</tmp> and C</var/tmp>."); + perform_on_filesystems = Some tmp_files_perform; +} + +let () = register_operation op -- 1.8.4.27.g0a41de8
Wanlong Gao
2013-Sep-06 07:52 UTC
[Libguestfs] [PATCH 2/5] sysprep: remove the NFS settings
This remove the NFS settings by removing /etc/export. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- sysprep/Makefile.am | 1 + sysprep/sysprep_operation_nfs_setting.ml | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 sysprep/sysprep_operation_nfs_setting.ml diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index b89345a..9894baf 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -51,6 +51,7 @@ operations = \ mail_spool \ net_hostname \ net_hwaddr \ + nfs_setting \ pacct_log \ package_manager_cache \ pam_data \ diff --git a/sysprep/sysprep_operation_nfs_setting.ml b/sysprep/sysprep_operation_nfs_setting.ml new file mode 100644 index 0000000..6d74cba --- /dev/null +++ b/sysprep/sysprep_operation_nfs_setting.ml @@ -0,0 +1,43 @@ +(* virt-sysprep + * Copyright (C) 2013 Fujitsu Limited. + * + * 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 +open Common_gettext.Gettext + +module G = Guestfs + +let nfs_setting_perform g root + let typ = g#inspect_get_type root in + if typ <> "windows" then ( + let path = "/etc/export" in + (try g#rm path with G.Error _ -> ()); + [] + ) + else [] + +let op = { + defaults with + name = "NFS-setting"; + enabled_by_default = false; + heading = s_"Remove the NFS settings"; + pod_description = Some (s_"\ +This removes the NFS settings by removing C</etc/export>."); + perform_on_filesystems = Some nfs_setting_perform; +} + +let () = register_operation op -- 1.8.4.27.g0a41de8
Wanlong Gao
2013-Sep-06 07:52 UTC
[Libguestfs] [PATCH 3/5] sysprep: remove the custom kdump configurations
This removes the custom kdump configurations by emptying the configuration file /etc/kdump.conf. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- sysprep/Makefile.am | 1 + sysprep/sysprep_operation_kdump_config.ml | 44 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 sysprep/sysprep_operation_kdump_config.ml diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index 9894baf..eb372aa 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -44,6 +44,7 @@ operations = \ firstboot \ fs_uuids \ hostname \ + kdump_config \ kerberos_data \ lvm_uuids \ logfiles \ diff --git a/sysprep/sysprep_operation_kdump_config.ml b/sysprep/sysprep_operation_kdump_config.ml new file mode 100644 index 0000000..358f97d --- /dev/null +++ b/sysprep/sysprep_operation_kdump_config.ml @@ -0,0 +1,44 @@ +(* virt-sysprep + * Copyright (C) 2013 Fujitsu Limited. + * + * 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 +open Common_gettext.Gettext + +module G = Guestfs + +let kdump_config_perform g root + let typ = g#inspect_get_type root in + if typ <> "windows" then ( + let path = "/etc/kdump.conf" in + (try g#rm path with G.Error _ -> ()); + (try g#touch path with G.Error _ -> ()); + [ `Created_files ] + ) + else [] + +let op = { + defaults with + name = "kdump-config"; + enabled_by_default = false; + heading = s_"Remove the kdump configurations"; + pod_description = Some (s_"\ +This removes the kdump configurations by emptying C</etc/kdump.conf>."); + perform_on_filesystems = Some kdump_config_perform; +} + +let () = register_operation op -- 1.8.4.27.g0a41de8
Wanlong Gao
2013-Sep-06 07:52 UTC
[Libguestfs] [PATCH 4/5] sysprep: remove the custom tcp wrappers
This removes the custom tcp wrappers by emptying the /etc/hosts.* configuration files. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- sysprep/Makefile.am | 1 + sysprep/sysprep_operation_tcp_wrapper.ml | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 sysprep/sysprep_operation_tcp_wrapper.ml diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index eb372aa..aa49605 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -67,6 +67,7 @@ operations = \ ssh_hostkeys \ ssh_userdir \ sssd_db_log \ + tcp_wrapper \ tmp_files \ udev_persistent_net \ user_account \ diff --git a/sysprep/sysprep_operation_tcp_wrapper.ml b/sysprep/sysprep_operation_tcp_wrapper.ml new file mode 100644 index 0000000..77f1e0a --- /dev/null +++ b/sysprep/sysprep_operation_tcp_wrapper.ml @@ -0,0 +1,52 @@ +(* virt-sysprep + * Copyright (C) 2013 Fujitsu Limited. + * + * 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 +open Common_gettext.Gettext + +module G = Guestfs + +let tcp_wrapper_perform g root + let typ = g#inspect_get_type root in + if typ <> "windows" then ( + let paths = [ "/etc/hosts.atm"; + "/etc/hosts.allow"; + "/etc/hosts.deny"; ] in + List.iter ( + fun path -> + (try g#rm path with G.Error _ -> ()); + (try g#touch path with G.Error _ -> ()); + ) paths; + [ `Created_files ] + ) + else [] + +let op = { + defaults with + name = "tcp-wrapper"; + enabled_by_default = false; + heading = s_"Remove the custom tcp wrappers"; + pod_description = Some (s_"\ +This removes the custom tcp wrappers by emptying C</etc/hosts.*>. + +Note this is I<not> enabled by default since it may expose guests +to exploits. Use with care."); + perform_on_filesystems = Some tcp_wrapper_perform; +} + +let () = register_operation op -- 1.8.4.27.g0a41de8
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- po/POTFILES-ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/po/POTFILES-ml b/po/POTFILES-ml index 1edca86..7bf6e1c 100644 --- a/po/POTFILES-ml +++ b/po/POTFILES-ml @@ -24,6 +24,7 @@ sysprep/sysprep_operation_firstboot.ml sysprep/sysprep_operation_flag_reconfiguration.ml sysprep/sysprep_operation_fs_uuids.ml sysprep/sysprep_operation_hostname.ml +sysprep/sysprep_operation_kdump_config.ml sysprep/sysprep_operation_kerberos_data.ml sysprep/sysprep_operation_logfiles.ml sysprep/sysprep_operation_lvm_uuids.ml @@ -31,6 +32,7 @@ sysprep/sysprep_operation_machine_id.ml sysprep/sysprep_operation_mail_spool.ml sysprep/sysprep_operation_net_hostname.ml sysprep/sysprep_operation_net_hwaddr.ml +sysprep/sysprep_operation_nfs_setting.ml sysprep/sysprep_operation_pacct_log.ml sysprep/sysprep_operation_package_manager_cache.ml sysprep/sysprep_operation_pam_data.ml @@ -45,6 +47,8 @@ sysprep/sysprep_operation_smolt_uuid.ml sysprep/sysprep_operation_ssh_hostkeys.ml sysprep/sysprep_operation_ssh_userdir.ml sysprep/sysprep_operation_sssd_db_log.ml +sysprep/sysprep_operation_tcp_wrapper.ml +sysprep/sysprep_operation_tmp_files.ml sysprep/sysprep_operation_udev_persistent_net.ml sysprep/sysprep_operation_user_account.ml sysprep/sysprep_operation_utmp.ml -- 1.8.4.27.g0a41de8
Richard W.M. Jones
2013-Sep-06 08:01 UTC
Re: [Libguestfs] [PATCH 2/5] sysprep: remove the NFS settings
On Fri, Sep 06, 2013 at 03:52:39PM +0800, Wanlong Gao wrote:> This remove the NFS settings by removing /etc/export. > > Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> > --- > sysprep/Makefile.am | 1 + > sysprep/sysprep_operation_nfs_setting.ml | 43 ++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > create mode 100644 sysprep/sysprep_operation_nfs_setting.ml > > diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am > index b89345a..9894baf 100644 > --- a/sysprep/Makefile.am > +++ b/sysprep/Makefile.am > @@ -51,6 +51,7 @@ operations = \ > mail_spool \ > net_hostname \ > net_hwaddr \ > + nfs_setting \This needs to be called 'nfs_settings' and ...> + name = "NFS-setting";this should be "nfs-settings". Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2013-Sep-06 08:04 UTC
Re: [Libguestfs] [PATCH 4/5] sysprep: remove the custom tcp wrappers
On Fri, Sep 06, 2013 at 03:52:41PM +0800, Wanlong Gao wrote:> + let paths = [ "/etc/hosts.atm";I don't suppose anyone uses it these days, but '/etc/hosts.atm' contains ATM settings. It's got nothing to do with TCP wrappers. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2013-Sep-06 08:06 UTC
Re: [Libguestfs] [PATCH 3/5] sysprep: remove the custom kdump configurations
On Fri, Sep 06, 2013 at 03:52:40PM +0800, Wanlong Gao wrote:> + kdump_config \Better to call this one just "kdump" ? However I'm unclear why anyone would want to remove kdump config in a sysprep operation. Or TCP wrappers for that matter. There seems to be no useful point in having virt-sysprep start to remove random config files. 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://people.redhat.com/~rjones/virt-top