Skip to content

Commit 58ace71

Browse files
committed
Remove selinux support code
Signed-off-by: Jo-Philipp Wich <[email protected]>
1 parent fb5c011 commit 58ace71

File tree

4 files changed

+17
-130
lines changed

4 files changed

+17
-130
lines changed

ext4_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct selabel_handle;
158158
int make_ext4fs_internal(int fd, const char *directory,
159159
const char *mountpoint, fs_config_func_t fs_config_func, int gzip,
160160
int sparse, int crc, int wipe,
161-
struct selabel_handle *sehnd, int verbose, time_t fixed_time,
161+
int verbose, time_t fixed_time,
162162
FILE* block_list_file);
163163

164164
int read_ext(int fd, int verbose);

make_ext4fs.c

Lines changed: 12 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,7 @@
3535
#include <sys/stat.h>
3636
#include <sys/types.h>
3737

38-
#ifdef USE_MINGW
39-
40-
#include <winsock2.h>
41-
42-
/* These match the Linux definitions of these flags.
43-
L_xx is defined to avoid conflicting with the win32 versions.
44-
*/
45-
#define L_S_IRUSR 00400
46-
#define L_S_IWUSR 00200
47-
#define L_S_IXUSR 00100
48-
#define S_IRWXU (L_S_IRUSR | L_S_IWUSR | L_S_IXUSR)
49-
#define S_IRGRP 00040
50-
#define S_IWGRP 00020
51-
#define S_IXGRP 00010
52-
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
53-
#define S_IROTH 00004
54-
#define S_IWOTH 00002
55-
#define S_IXOTH 00001
56-
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
57-
#define S_ISUID 0004000
58-
#define S_ISGID 0002000
59-
#define S_ISVTX 0001000
60-
61-
#else
62-
63-
#include <selinux/selinux.h>
64-
#include <selinux/label.h>
65-
#include <selinux/android.h>
38+
#ifndef USE_MINGW
6639

6740
#define O_BINARY 0
6841

@@ -79,8 +52,7 @@ static int filter_dot(const struct dirent *d)
7952
return (strcmp(d->d_name, "..") && strcmp(d->d_name, "."));
8053
}
8154

82-
static u32 build_default_directory_structure(const char *dir_path,
83-
struct selabel_handle *sehnd)
55+
static u32 build_default_directory_structure(const char *dir_path)
8456
{
8557
u32 inode;
8658
u32 root_inode;
@@ -98,22 +70,6 @@ static u32 build_default_directory_structure(const char *dir_path,
9870
inode_set_permissions(inode, dentries.mode,
9971
dentries.uid, dentries.gid, dentries.mtime);
10072

101-
#ifndef USE_MINGW
102-
if (sehnd) {
103-
char *path = NULL;
104-
char *secontext = NULL;
105-
106-
asprintf(&path, "%slost+found", dir_path);
107-
if (selabel_lookup(sehnd, &secontext, path, S_IFDIR) < 0) {
108-
error("cannot lookup security context for %s", path);
109-
} else {
110-
inode_set_selinux(inode, secontext);
111-
freecon(secontext);
112-
}
113-
free(path);
114-
}
115-
#endif
116-
11773
return root_inode;
11874
}
11975

@@ -127,7 +83,7 @@ static u32 build_default_directory_structure(const char *dir_path,
12783
if the image were mounted at the specified mount point */
12884
static u32 build_directory_structure(const char *full_path, const char *dir_path,
12985
u32 dir_inode, fs_config_func_t fs_config_func,
130-
struct selabel_handle *sehnd, int verbose, time_t fixed_time)
86+
int verbose, time_t fixed_time)
13187
{
13288
int entries = 0;
13389
struct dentry *dentries;
@@ -212,16 +168,6 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
212168
error("can't set android permissions - built without android support");
213169
#endif
214170
}
215-
#ifndef USE_MINGW
216-
if (sehnd) {
217-
if (selabel_lookup(sehnd, &dentries[i].secon, dentries[i].path, stat.st_mode) < 0) {
218-
error("cannot lookup security context for %s", dentries[i].path);
219-
}
220-
221-
if (dentries[i].secon && verbose)
222-
printf("Labeling %s as %s\n", dentries[i].path, dentries[i].secon);
223-
}
224-
#endif
225171

226172
if (S_ISREG(stat.st_mode)) {
227173
dentries[i].file_type = EXT4_FT_REG_FILE;
@@ -263,10 +209,6 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
263209
dentries[0].file_type = EXT4_FT_DIR;
264210
dentries[0].uid = 0;
265211
dentries[0].gid = 0;
266-
if (sehnd) {
267-
if (selabel_lookup(sehnd, &dentries[0].secon, dentries[0].path, dentries[0].mode) < 0)
268-
error("cannot lookup security context for %s", dentries[0].path);
269-
}
270212
entries++;
271213
dirs++;
272214
}
@@ -288,7 +230,7 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
288230
if (ret < 0)
289231
critical_error_errno("asprintf");
290232
entry_inode = build_directory_structure(subdir_full_path,
291-
subdir_dir_path, inode, fs_config_func, sehnd, verbose, fixed_time);
233+
subdir_dir_path, inode, fs_config_func, verbose, fixed_time);
292234
free(subdir_full_path);
293235
free(subdir_dir_path);
294236
} else if (dentries[i].file_type == EXT4_FT_SYMLINK) {
@@ -401,16 +343,16 @@ void reset_ext4fs_info() {
401343
}
402344

403345
int make_ext4fs_sparse_fd(int fd, long long len,
404-
const char *mountpoint, struct selabel_handle *sehnd)
346+
const char *mountpoint)
405347
{
406348
reset_ext4fs_info();
407349
info.len = len;
408350

409-
return make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 1, 0, 0, sehnd, 0, -1, NULL);
351+
return make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 1, 0, 0, 0, -1, NULL);
410352
}
411353

412354
int make_ext4fs(const char *filename, long long len,
413-
const char *mountpoint, struct selabel_handle *sehnd)
355+
const char *mountpoint)
414356
{
415357
int fd;
416358
int status;
@@ -424,7 +366,7 @@ int make_ext4fs(const char *filename, long long len,
424366
return EXIT_FAILURE;
425367
}
426368

427-
status = make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 0, 0, 1, sehnd, 0, -1, NULL);
369+
status = make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 0, 0, 1, 0, -1, NULL);
428370
close(fd);
429371

430372
return status;
@@ -493,7 +435,7 @@ static char *canonicalize_rel_slashes(const char *str)
493435
int make_ext4fs_internal(int fd, const char *_directory,
494436
const char *_mountpoint, fs_config_func_t fs_config_func, int gzip,
495437
int sparse, int crc, int wipe,
496-
struct selabel_handle *sehnd, int verbose, time_t fixed_time,
438+
int verbose, time_t fixed_time,
497439
FILE* block_list_file)
498440
{
499441
u32 root_inode_num;
@@ -599,35 +541,18 @@ int make_ext4fs_internal(int fd, const char *_directory,
599541
#ifdef USE_MINGW
600542
// Windows needs only 'create an empty fs image' functionality
601543
assert(!directory);
602-
root_inode_num = build_default_directory_structure(mountpoint, sehnd);
544+
root_inode_num = build_default_directory_structure(mountpoint);
603545
#else
604546
if (directory)
605547
root_inode_num = build_directory_structure(directory, mountpoint, 0,
606-
fs_config_func, sehnd, verbose, fixed_time);
548+
fs_config_func, verbose, fixed_time);
607549
else
608-
root_inode_num = build_default_directory_structure(mountpoint, sehnd);
550+
root_inode_num = build_default_directory_structure(mountpoint);
609551
#endif
610552

611553
root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
612554
inode_set_permissions(root_inode_num, root_mode, 0, 0, 0);
613555

614-
#ifndef USE_MINGW
615-
if (sehnd) {
616-
char *secontext = NULL;
617-
618-
if (selabel_lookup(sehnd, &secontext, mountpoint, S_IFDIR) < 0) {
619-
error("cannot lookup security context for %s", mountpoint);
620-
}
621-
if (secontext) {
622-
if (verbose) {
623-
printf("Labeling %s as %s\n", mountpoint, secontext);
624-
}
625-
inode_set_selinux(root_inode_num, secontext);
626-
}
627-
freecon(secontext);
628-
}
629-
#endif
630-
631556
ext4_update_free();
632557

633558
ext4_queue_sb();

make_ext4fs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
extern "C" {
2222
#endif
2323

24-
struct selabel_handle;
25-
2624
int make_ext4fs(const char *filename, long long len,
27-
const char *mountpoint, struct selabel_handle *sehnd);
25+
const char *mountpoint);
2826
int make_ext4fs_sparse_fd(int fd, long long len,
29-
const char *mountpoint, struct selabel_handle *sehnd);
27+
const char *mountpoint);
3028

3129
#ifdef __cplusplus
3230
}

make_ext4fs_main.c

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
#include <private/android_filesystem_config.h>
3030
#endif
3131

32-
#ifndef USE_MINGW
33-
#include <selinux/selinux.h>
34-
#include <selinux/label.h>
35-
#include <selinux/android.h>
36-
#else
37-
struct selabel_handle;
38-
#endif
39-
4032
#include "make_ext4fs.h"
4133
#include "ext4_utils.h"
4234
#include "canned_fs_config.h"
@@ -74,13 +66,9 @@ int main(int argc, char **argv)
7466
int exitcode;
7567
int verbose = 0;
7668
time_t fixed_time = -1;
77-
struct selabel_handle *sehnd = NULL;
7869
FILE* block_list_file = NULL;
79-
#ifndef USE_MINGW
80-
struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "" } };
81-
#endif
8270

83-
while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:S:T:C:B:fwzJsctv")) != -1) {
71+
while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:T:C:B:fwzJsctv")) != -1) {
8472
switch (opt) {
8573
case 'l':
8674
info.len = parse_num(optarg);
@@ -133,16 +121,6 @@ int main(int argc, char **argv)
133121
case 't':
134122
fprintf(stderr, "Warning: -t (initialize inode tables) is deprecated\n");
135123
break;
136-
case 'S':
137-
#ifndef USE_MINGW
138-
seopts[0].value = optarg;
139-
sehnd = selabel_open(SELABEL_CTX_FILE, seopts, 1);
140-
if (!sehnd) {
141-
perror(optarg);
142-
exit(EXIT_FAILURE);
143-
}
144-
#endif
145-
break;
146124
case 'v':
147125
verbose = 1;
148126
break;
@@ -165,26 +143,12 @@ int main(int argc, char **argv)
165143
}
166144
}
167145

168-
#if !defined(HOST)
169-
// Use only if -S option not requested
170-
if (!sehnd && mountpoint) {
171-
sehnd = selinux_android_file_context_handle();
172-
173-
if (!sehnd) {
174-
perror(optarg);
175-
exit(EXIT_FAILURE);
176-
}
177-
}
178-
#endif
179-
180146
if (fs_config_file) {
181147
if (load_canned_fs_config(fs_config_file) < 0) {
182148
fprintf(stderr, "failed to load %s\n", fs_config_file);
183149
exit(EXIT_FAILURE);
184150
}
185151
fs_config_func = canned_fs_config;
186-
} else if (mountpoint) {
187-
fs_config_func = fs_config;
188152
}
189153

190154
if (wipe && sparse) {
@@ -227,7 +191,7 @@ int main(int argc, char **argv)
227191
}
228192

229193
exitcode = make_ext4fs_internal(fd, directory, mountpoint, fs_config_func, gzip,
230-
sparse, crc, wipe, sehnd, verbose, fixed_time, block_list_file);
194+
sparse, crc, wipe, verbose, fixed_time, block_list_file);
231195
close(fd);
232196
if (block_list_file)
233197
fclose(block_list_file);

0 commit comments

Comments
 (0)