-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
You can now set [root,dev,fs,]context attributes Signed-off-by: Matthew Thode <prometheanfire@gentoo.org>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,11 +334,38 @@ mtab_update(char *dataset, char *mntpoint, char *type, char *mntopts) | |
return (MOUNT_SUCCESS); | ||
} | ||
|
||
#ifdef HAVE_LIBSELINUX | ||
This comment has been minimized.
Sorry, something went wrong. |
||
static void | ||
__zfs_selinux_setcontext(const char *name, const char *context, char *mntopts, | ||
char *mtabopt) | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
{ | ||
char tmp[MNT_LINE_MAX]; | ||
|
||
snprintf(tmp, MNT_LINE_MAX, ",%s=\"%s\"", name, context); | ||
strlcat(mntopts, tmp, MNT_LINE_MAX); | ||
strlcat(mtabopt, tmp, MNT_LINE_MAX); | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
} | ||
|
||
static void | ||
zfs_selinux_setcontext(zfs_handle_t *zhp, zfs_prop_t zpt, const char *name, | ||
char *mntopts, char *mtabopt) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
char context[ZFS_MAXPROPLEN]; | ||
|
||
if (zfs_prop_get(zhp, zpt, context, sizeof (context), | ||
NULL, NULL, 0, B_FALSE) == 0) { | ||
if (strcmp(context, "none") != 0) | ||
__zfs_selinux_setcontext(name, context, mntopts, mtabopt); | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
}; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
#endif | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
zfs_handle_t *zhp; | ||
char legacy[ZFS_MAXPROPLEN]; | ||
char prop[ZFS_MAXPROPLEN]; | ||
char mntopts[MNT_LINE_MAX] = { '\0' }; | ||
char badopt[MNT_LINE_MAX] = { '\0' }; | ||
char mtabopt[MNT_LINE_MAX] = { '\0' }; | ||
|
@@ -433,21 +460,6 @@ main(int argc, char **argv) | |
} | ||
} | ||
|
||
#ifdef HAVE_LIBSELINUX | ||
/* | ||
* Automatically add the default zfs context when selinux is enabled | ||
* and the caller has not specified their own context. This must be | ||
* done until zfs is added to the default selinux policy configuration | ||
* as a known filesystem type which supports xattrs. | ||
*/ | ||
if (is_selinux_enabled() && !(zfsflags & ZS_NOCONTEXT)) { | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
(void) strlcat(mntopts, ",context=\"system_u:" | ||
"object_r:file_t:s0\"", sizeof (mntopts)); | ||
(void) strlcat(mtabopt, ",context=\"system_u:" | ||
"object_r:file_t:s0\"", sizeof (mtabopt)); | ||
} | ||
#endif /* HAVE_LIBSELINUX */ | ||
|
||
|
||
if (verbose) | ||
(void) fprintf(stdout, gettext("mount.zfs:\n" | ||
|
@@ -476,12 +488,36 @@ main(int argc, char **argv) | |
return (MOUNT_USAGE); | ||
} | ||
|
||
#ifdef HAVE_LIBSELINUX | ||
/* | ||
* Checks to see if the ZFS_PROP_SELINUX_CONTEXT exists | ||
* if it does, create a tmp variable in case it's needed | ||
* checks to see if the selinux context is set to the default | ||
* if it is, allow the setting of the other context properties | ||
* this is needed because the 'context' property overrides others | ||
* if it is not the default, set the 'context' property | ||
*/ | ||
if (zfs_prop_get(zhp, ZFS_PROP_SELINUX_CONTEXT, prop, sizeof (prop), | ||
NULL, NULL, 0, B_FALSE) == 0) { | ||
if (strcmp(prop, "none") == 0) { | ||
zfs_selinux_setcontext(zhp, ZFS_PROP_SELINUX_FSCONTEXT, | ||
"fscontext", mntopts, mtabopt); | ||
zfs_selinux_setcontext(zhp, ZFS_PROP_SELINUX_DEFCONTEXT, | ||
"defcontext", mntopts, mtabopt); | ||
zfs_selinux_setcontext(zhp, ZFS_PROP_SELINUX_ROOTCONTEXT, | ||
"rootcontext", mntopts, mtabopt); | ||
} else { | ||
__zfs_selinux_setcontext("context", prop, mntopts, mtabopt); | ||
}; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
#endif /* HAVE_LIBSELINUX */ | ||
|
||
/* treat all snapshots as legacy mount points */ | ||
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) | ||
(void) strlcpy(legacy, ZFS_MOUNTPOINT_LEGACY, ZFS_MAXPROPLEN); | ||
(void) strlcpy(prop, ZFS_MOUNTPOINT_LEGACY, ZFS_MAXPROPLEN); | ||
else | ||
(void) zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, legacy, | ||
sizeof (legacy), NULL, NULL, 0, B_FALSE); | ||
(void) zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, prop, | ||
sizeof (prop), NULL, NULL, 0, B_FALSE); | ||
|
||
zfs_close(zhp); | ||
libzfs_fini(g_zfs); | ||
|
@@ -497,17 +533,17 @@ main(int argc, char **argv) | |
* using zfs as your root file system both rc.sysinit/umountroot and | ||
* systemd depend on 'mount -o remount <mountpoint>' to work. | ||
*/ | ||
if (zfsutil && !strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) { | ||
if (zfsutil && !strcmp(prop, ZFS_MOUNTPOINT_LEGACY)) { | ||
(void) fprintf(stderr, gettext( | ||
"filesystem '%s' cannot be mounted using 'zfs mount'.\n" | ||
"Use 'zfs set mountpoint=%s' or 'mount -t zfs %s %s'.\n" | ||
"See zfs(8) for more information.\n"), | ||
dataset, mntpoint, dataset, mntpoint); | ||
dataset, mntpoint, dataset, mntpoint); | ||
return (MOUNT_USAGE); | ||
} | ||
|
||
if (!zfsutil && !(remount || fake) && | ||
strcmp(legacy, ZFS_MOUNTPOINT_LEGACY)) { | ||
strcmp(prop, ZFS_MOUNTPOINT_LEGACY)) { | ||
(void) fprintf(stderr, gettext( | ||
"filesystem '%s' cannot be mounted using 'mount'.\n" | ||
"Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,19 @@ Increase verbosity. | |
.BI "\-h" | ||
Print the usage message. | ||
.TP | ||
.BI "\-o context" | ||
This flag sets the SELinux context for all files in the filesytem | ||
under that mountpoint. | ||
.TP | ||
.BI "\-o fscontext" | ||
This flag sets the SELinux context for the filesytem being mounted. | ||
.TP | ||
.BI "\-o defcontext" | ||
This flag sets the SELinux context for unlabled files. | ||
.TP | ||
.BI "\-o rootcontext" | ||
This flag sets the SELinux context for the root inode of the filesystem. | ||
.TP | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
.BI "\-o legacy" | ||
This private flag indicates that the | ||
.I dataset | ||
|
1 comment
on commit 1818ddf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prometheanfire On the whole this looks really good, just a little more cleanup and we should be there!
I believe we can safely drop the HAVE_LIBSELINUX wrapper and autoconf checks. They were only strictly needed because
is_selinux_enabled()
was a library function which we needed to ensure was available. Since you've removed that call we can drop all of that infrastructure including linking against $(LIBSELINUX) incmd/mount_zfs/Makefile.am
.