diff options
author | Nick Kralevich <nnk@google.com> | 2014-04-27 01:05:28 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-04-27 01:05:28 +0000 |
commit | 79950456925b801273cd93d03145aba8477a9eb4 (patch) | |
tree | d8a736492daa9c273e45bcb5ca4465b7928ac6f3 | |
parent | fb109b894a5fc2891e49ec8e81c0dda171b45b7f (diff) | |
parent | 7907ac7c811670643c3606125657a39226507ea1 (diff) | |
download | extras-79950456925b801273cd93d03145aba8477a9eb4.tar.gz |
Merge "Label lost+found directories with SELinux security contexts."
-rw-r--r-- | ext4_utils/make_ext4fs.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c index 0cb5bae9..b9a24b83 100644 --- a/ext4_utils/make_ext4fs.c +++ b/ext4_utils/make_ext4fs.c @@ -79,7 +79,8 @@ static int filter_dot(const struct dirent *d) return (strcmp(d->d_name, "..") && strcmp(d->d_name, ".")); } -static u32 build_default_directory_structure() +static u32 build_default_directory_structure(const char *dir_path, + struct selabel_handle *sehnd) { u32 inode; u32 root_inode; @@ -97,6 +98,22 @@ static u32 build_default_directory_structure() inode_set_permissions(inode, dentries.mode, dentries.uid, dentries.gid, dentries.mtime); +#ifndef USE_MINGW + if (sehnd) { + char *path = NULL; + char *secontext = NULL; + + asprintf(&path, "%slost+found", dir_path); + if (selabel_lookup(sehnd, &secontext, path, S_IFDIR) < 0) { + error("cannot lookup security context for %s", path); + } else { + inode_set_selinux(inode, secontext); + freecon(secontext); + } + free(path); + } +#endif + return root_inode; } @@ -564,13 +581,13 @@ int make_ext4fs_internal(int fd, const char *_directory, #ifdef USE_MINGW // Windows needs only 'create an empty fs image' functionality assert(!directory); - root_inode_num = build_default_directory_structure(); + root_inode_num = build_default_directory_structure(mountpoint, sehnd); #else if (directory) root_inode_num = build_directory_structure(directory, mountpoint, 0, fs_config_func, sehnd, verbose); else - root_inode_num = build_default_directory_structure(); + root_inode_num = build_default_directory_structure(mountpoint, sehnd); #endif root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |