[PATCH] NEW API: add a new api restorecon
Add a new api restorecon to restore file(s) default SELinux security contexts. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 69 + generator/actions.ml | 25 + gobject/Makefile.inc | 6 +- po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 21 files changed, 13282 insertions(+), 28030 deletions(-) diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..14bc666 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h" +#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX) int @@ -106,3 +110,68 @@ do_getcon (void) } #endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *excludedir, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *exdir; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_EXCLUDEDIR_BITMASK) { + if (excludedir) { + exdir = sysroot_path (excludedir); + if (!exdir) { + reply_with_error ("malloc"); + return -1; + } + ADD_ARG (argv, i, "-e"); + ADD_ARG (argv, i, exdir); + } + } + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + if (labelprefix) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (exdir) free (exdir); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..12796a7 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,31 @@ If the optional C<suffix> parameter is given, then the suffix See also: C<guestfs_mkdtemp>." }; + { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "excludedir"; OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + tests = [ + InitScratchFS, Always, TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "/a/d"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..5cded4e 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -138,6 +138,7 @@ fish/tilde.c fish/time.c format/format.c fuse/guestmount.c +gobject/docs/guestfs-scan.c gobject/src/optargs-add_domain.c gobject/src/optargs-add_drive.c gobject/src/optargs-btrfs_filesystem_resize.c @@ -167,6 +168,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
On Wed, Oct 24, 2012 at 02:04:47PM +0800, Wanlong Gao wrote:
Add a new api restorecon to restore file(s) default SELinux security contexts.
In general terms, yes. However there are some specific problems with this patch, see below.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 69 + generator/actions.ml | 25 + gobject/Makefile.inc | 6 +- po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 21 files changed, 13282 insertions(+), 28030 deletions(-)
diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..14bc666 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h"
+#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX)
int @@ -106,3 +110,68 @@ do_getcon (void) }
#endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *excludedir, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *exdir; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_EXCLUDEDIR_BITMASK) { + if (excludedir) { + exdir = sysroot_path (excludedir); + if (!exdir) { + reply_with_error ("malloc"); + return -1; + } + ADD_ARG (argv, i, "-e"); + ADD_ARG (argv, i, exdir); + } + }
Note that the -e option can be specified multiple times (see the man page). It's possible to encode this using OStringList. On the other hand that is complicated and I don't mind if you just drop the excludedir optional argument, and we'll wait and see if anyone asks for it.
+ if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + if (labelprefix) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (exdir) free (exdir); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..12796a7 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,31 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "excludedir"; OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + tests = [ + InitScratchFS, Always, TestRun (
This test shouldn't be 'Always'. It should be conditional on having selinux.
+ [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "/a/d"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; diff --git a/po/POTFILES b/po/POTFILES index a73377d..5cded4e 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -138,6 +138,7 @@ fish/tilde.c fish/time.c format/format.c fuse/guestmount.c +gobject/docs/guestfs-scan.c gobject/src/optargs-add_domain.c gobject/src/optargs-add_drive.c gobject/src/optargs-btrfs_filesystem_resize.c
This hunk is wrong. I think you've got a rogue file which needs to be deleted. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
+} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..12796a7 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,31 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "excludedir"; OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + tests = [ + InitScratchFS, Always, TestRun (
This test shouldn't be 'Always'. It should be conditional on having selinux.
Do you mean "IfAvailable of HAVE_LIBSELINUX" here? Thanks, Wanlong Gao
On Wed, Oct 24, 2012 at 05:28:16PM +0800, Wanlong Gao wrote:
+} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..12796a7 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,31 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "excludedir"; OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + tests = [ + InitScratchFS, Always, TestRun (
This test shouldn't be 'Always'. It should be conditional on having selinux.
Do you mean "IfAvailable of HAVE_LIBSELINUX" here?
https://github.com/libguestfs/libguestfs/blob/master/generator/types.ml#L291 However "HAVE_LIBSELINUX" isn't going to work. You need to use the right option group from this list: http://libguestfs.org/guestfs.3.html#groups-of-functionality-in-the-applianc... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Add a new api restorecon to restore file(s) default SELinux security contexts. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 54 + generator/actions.ml | 26 + gobject/Makefile.inc | 6 +- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 21 files changed, 13267 insertions(+), 28030 deletions(-) diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..e8b2f5d 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h" +#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX) int @@ -106,3 +110,53 @@ do_getcon (void) } #endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + if (labelprefix) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix See also: C<guestfs_mkdtemp>." }; + { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
On Wed, Oct 24, 2012 at 06:01:28PM +0800, Wanlong Gao wrote: [...] Just noticed one more thing ...
+int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + if (labelprefix) {
The second if-statement here isn't needed. OString arguments can never be NULL, *if* the corresponding bitmask bit is set. 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
Add a new api restorecon to restore file(s) default SELinux security contexts. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 26 ++++++++++++++++++++++++++ gobject/Makefile.inc | 6 ++++-- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..f5e8cb2 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h" +#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX) int @@ -106,3 +110,51 @@ do_getcon (void) } #endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix See also: C<guestfs_mkdtemp>." }; + { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
Dan & Dan, Any comments on the design of this restorecon interface? As implemented here, it is merely a simple encoding of the restorecon command line tool and arguments. My main worry is that it'll use the wrong policy file, or perhaps no policy file, or if SELinux isn't enabled properly it'll end up destroying labels instead of setting them. Also I've no idea if it's legit to run restorecon on a filesystem from one guest, using the restorecon command from another system (the host in this case). Rich. On Wed, Oct 24, 2012 at 10:00:53PM +0800, Wanlong Gao wrote:
Add a new api restorecon to restore file(s) default SELinux security contexts.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 26 ++++++++++++++++++++++++++ gobject/Makefile.inc | 6 ++++-- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..f5e8cb2 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h"
+#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX)
int @@ -106,3 +110,51 @@ do_getcon (void) }
#endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h
guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/24/2012 11:42 AM, Richard W.M. Jones wrote:
Dan & Dan,
Any comments on the design of this restorecon interface? As implemented here, it is merely a simple encoding of the restorecon command line tool and arguments.
My main worry is that it'll use the wrong policy file, or perhaps no policy file, or if SELinux isn't enabled properly it'll end up destroying labels instead of setting them.
Also I've no idea if it's legit to run restorecon on a filesystem from one guest, using the restorecon command from another system (the host in this case).
Rich.
The restorecon inside the guest will attempt to read /etc/selinux/context/POLICYTYPE/files/file_context If it exists. - From restorecons point of view does this file exists? And is it in the container. Also restorecon will only work if it thinks SELinux is enabled and the kernel undestands the labels. If from the restorecon point of view SELinux is not enabled or /proc/fs/selinux points to the hosts /proc/fs/selinux then there is a chance that the host will reject labels in the guest. If you want to fix labels in a guest where the process thinks SELinux is disabled, then setfiles would be a better tool.
On Wed, Oct 24, 2012 at 10:00:53PM +0800, Wanlong Gao wrote:
Add a new api restorecon to restore file(s) default SELinux security contexts.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 26 ++++++++++++++++++++++++++ gobject/Makefile.inc | 6 ++++-- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..f5e8cb2 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h"
+#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX)
int @@ -106,3 +110,51 @@ do_getcon (void) }
#endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h
guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlCIMB0ACgkQrlYvE4MpobOgTwCfewHzhAC3w5uT1RkWZnKAc2jB xfEAn2WKpX59+s59qQnNGUkjju6RIRtC =jnlO -----END PGP SIGNATURE-----
On 10/25/2012 02:14 AM, Daniel J Walsh wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 10/24/2012 11:42 AM, Richard W.M. Jones wrote:
Dan & Dan,
Any comments on the design of this restorecon interface? As implemented here, it is merely a simple encoding of the restorecon command line tool and arguments.
My main worry is that it'll use the wrong policy file, or perhaps no policy file, or if SELinux isn't enabled properly it'll end up destroying labels instead of setting them.
Also I've no idea if it's legit to run restorecon on a filesystem from one guest, using the restorecon command from another system (the host in this case).
Rich.
The restorecon inside the guest will attempt to read /etc/selinux/context/POLICYTYPE/files/file_context If it exists.
So, Rich, we have some problems here? Thanks, Wanlong Gao
- From restorecons point of view does this file exists? And is it in the container.
Also restorecon will only work if it thinks SELinux is enabled and the kernel undestands the labels. If from the restorecon point of view SELinux is not enabled or /proc/fs/selinux points to the hosts /proc/fs/selinux then there is a chance that the host will reject labels in the guest.
If you want to fix labels in a guest where the process thinks SELinux is disabled, then setfiles would be a better tool.
On Wed, Oct 24, 2012 at 10:00:53PM +0800, Wanlong Gao wrote:
Add a new api restorecon to restore file(s) default SELinux security contexts.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 26 ++++++++++++++++++++++++++ gobject/Makefile.inc | 6 ++++-- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..f5e8cb2 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h"
+#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX)
int @@ -106,3 +110,51 @@ do_getcon (void) }
#endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h
guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
iEYEARECAAYFAlCIMB0ACgkQrlYvE4MpobOgTwCfewHzhAC3w5uT1RkWZnKAc2jB xfEAn2WKpX59+s59qQnNGUkjju6RIRtC =jnlO -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/25/2012 09:47 PM, Wanlong Gao wrote:
On 10/25/2012 02:14 AM, Daniel J Walsh wrote: On 10/24/2012 11:42 AM, Richard W.M. Jones wrote:
Dan & Dan,
Any comments on the design of this restorecon interface? As implemented here, it is merely a simple encoding of the restorecon command line tool and arguments.
My main worry is that it'll use the wrong policy file, or perhaps no policy file, or if SELinux isn't enabled properly it'll end up destroying labels instead of setting them.
Also I've no idea if it's legit to run restorecon on a filesystem from one guest, using the restorecon command from another system (the host in this case).
Rich.
The restorecon inside the guest will attempt to read /etc/selinux/context/POLICYTYPE/files/file_context If it exists.
So, Rich, we have some problems here?
Thanks, Wanlong Gao
- From restorecons point of view does this file exists? And is it in the container.
Also restorecon will only work if it thinks SELinux is enabled and the kernel undestands the labels. If from the restorecon point of view SELinux is not enabled or /proc/fs/selinux points to the hosts /proc/fs/selinux then there is a chance that the host will reject labels in the guest.
If you want to fix labels in a guest where the process thinks SELinux is disabled, then setfiles would be a better tool.
On Wed, Oct 24, 2012 at 10:00:53PM +0800, Wanlong Gao wrote:
Add a new api restorecon to restore file(s) default SELinux security contexts.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/selinux.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 26 ++++++++++++++++++++++++++ gobject/Makefile.inc | 6 ++++-- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/daemon/selinux.c b/daemon/selinux.c index 40590e1..f5e8cb2 100644 --- a/daemon/selinux.c +++ b/daemon/selinux.c @@ -31,6 +31,10 @@ #include "actions.h" #include "optgroups.h"
+#define MAX_ARGS 128 + +GUESTFSD_EXT_CMD(str_restorecon, restorecon); + #if defined(HAVE_LIBSELINUX)
int @@ -106,3 +110,51 @@ do_getcon (void) }
#endif /* !HAVE_LIBSELINUX */ + +int +do_restorecon (const char *pathname, + const char *labelprefix, + int recursion, + int force) +{ + int r; + size_t i = 0; + char *buf; + char *err; + const char *argv[MAX_ARGS]; + + buf = sysroot_path (pathname); + if (!buf) { + reply_with_error ("malloc"); + return -1; + } + + ADD_ARG (argv, i, str_restorecon); + + if (optargs_bitmask & GUESTFS_RESTORECON_LABELPREFIX_BITMASK) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, labelprefix); + } + + if (optargs_bitmask & GUESTFS_RESTORECON_RECURSION_BITMASK) + if (recursion) + ADD_ARG (argv, i, "-R"); + + if (optargs_bitmask & GUESTFS_RESTORECON_FORCE_BITMASK) + if (force) + ADD_ARG (argv, i, "-F"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", pathname, err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index 71aee37..786c229 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -10241,6 +10241,32 @@ If the optional C<suffix> parameter is given, then the suffix
See also: C<guestfs_mkdtemp>." };
+ { defaults with + name = "restorecon"; + style = RErr, [Pathname "pathname"], [OString "labelprefix"; OBool "recursion"; OBool "force"]; + proc_nr = Some 374; + optional = Some "selinux"; + tests = [ + InitScratchFS, IfAvailable "selinux", TestRun ( + [["mkdir"; "/a"]; + ["mkdir"; "/a/b"]; + ["touch"; "/a/b/c"]; + ["mkdir"; "/a/d"]; + ["touch"; "/a/d/e"]; + ["restorecon"; "/a"; "NOARG"; "true"; "true"]]) + ]; + shortdesc = "restore file(s) default SELinux security contexts"; + longdesc = "\ +This program is primarily used to reset the security context (type) +(extended attributes) on one or more files. + +It can be run at any time to correct errors, to add support for new policy. + +If a file object does not have a context, restorecon will write the default +context to the file object's extended attributes. If a file object has a +context, C<restorecon> will only modify the type portion of the security +context. The C<force> option will force a replacement of the entire context."}; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 95a4b6b..7451d8e 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -82,7 +82,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-hivex_open.h \ include/guestfs-gobject/optargs-xfs_repair.h \ include/guestfs-gobject/optargs-mke2fs.h \ - include/guestfs-gobject/optargs-mktemp.h + include/guestfs-gobject/optargs-mktemp.h \ + include/guestfs-gobject/optargs-restorecon.h
guestfs_gobject_sources= \ src/session.c \ @@ -146,4 +147,5 @@ guestfs_gobject_sources= \ src/optargs-hivex_open.c \ src/optargs-xfs_repair.c \ src/optargs-mke2fs.c \ - src/optargs-mktemp.c + src/optargs-mktemp.c \ + src/optargs-restorecon.c diff --git a/po/POTFILES b/po/POTFILES index a73377d..8d6656b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -167,6 +167,7 @@ gobject/src/optargs-mount_local.c gobject/src/optargs-ntfsclone_out.c gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c +gobject/src/optargs-restorecon.c gobject/src/optargs-rsync.c gobject/src/optargs-rsync_in.c gobject/src/optargs-rsync_out.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index a5c3fde..38a45c3 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -373 +374 -- 1.8.0
BTW It is fairly easy to add C Code to do the labeling here. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlCKlrgACgkQrlYvE4MpobNY6ACgoYJRoSP7c4Jpe4FJynwPGfhA lO4An003i3sFF8w5RjXxsi7GUTzgSy5/ =veTC -----END PGP SIGNATURE-----
On Fri, Oct 26, 2012 at 09:47:40AM +0800, Wanlong Gao wrote:
So, Rich, we have some problems here?
Yeah, I don't see a way to use the restorecon API safely. 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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/28/2012 04:45 AM, Richard W.M. Jones wrote:
On Fri, Oct 26, 2012 at 09:47:40AM +0800, Wanlong Gao wrote:
So, Rich, we have some problems here?
Yeah, I don't see a way to use the restorecon API safely.
Rich.
Why is that? selabel_file, with setfilecon() or setfscreatecon() should be able to do what you want? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlCOhKwACgkQrlYvE4MpobMxPACgsqG9kARHIci09x4gYY29nc+a 82gAmwfWUGUPyh69pogZH2xFHg9FI+D5 =N3ME -----END PGP SIGNATURE-----
On Mon, Oct 29, 2012 at 09:29:16AM -0400, Daniel J Walsh wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 10/28/2012 04:45 AM, Richard W.M. Jones wrote:
On Fri, Oct 26, 2012 at 09:47:40AM +0800, Wanlong Gao wrote:
So, Rich, we have some problems here?
Yeah, I don't see a way to use the restorecon API safely.
Rich.
Why is that? selabel_file, with setfilecon() or setfscreatecon() should be able to do what you want?
I mean the API as proposed in the patch, where it just runs "restorecon" from the host on the guest. There may be other ways to do it, but none of them seem simpler than the way we currently do it (touching /.autorelabel in the guest). 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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/29/2012 09:42 AM, Richard W.M. Jones wrote:
On Mon, Oct 29, 2012 at 09:29:16AM -0400, Daniel J Walsh wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 10/28/2012 04:45 AM, Richard W.M. Jones wrote:
On Fri, Oct 26, 2012 at 09:47:40AM +0800, Wanlong Gao wrote:
So, Rich, we have some problems here?
Yeah, I don't see a way to use the restorecon API safely.
Rich.
Why is that? selabel_file, with setfilecon() or setfscreatecon() should be able to do what you want?
I mean the API as proposed in the patch, where it just runs "restorecon" from the host on the guest. There may be other ways to do it, but none of them seem simpler than the way we currently do it (touching /.autorelabel in the guest).
Rich.
Yes, as has been stated restorecon will probably not work because it will either get the wrong labels from the host or think that SELinux is disabled and do nothing. /usr/sbin/setfiles PATHTOFILECONTE PATHTORESTORE Would work on a machine even if it thought SELinux was disabled and you could specify the path, Or you could use the c API. Or you could just trigger a reboot when the system starts up by executing touch /.autorelabel -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlCOjRUACgkQrlYvE4MpobMHBQCfVL61kooHMlRLn9fEUDBg0akf uDUAoNuwqXhWWe/2IK8HasDDA50smUSn =F+Nq -----END PGP SIGNATURE-----
participants (3)
-
Daniel J Walsh -
Richard W.M. Jones -
Wanlong Gao