diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2016-12-30 08:36:40 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-12-30 08:36:41 +0000 |
commit | db6284efe2b62b7c245d8ee461ca0c21ca2c7a5a (patch) | |
tree | 9289f06040b24390025c0c7c0629145a010e0690 /libselinux/src | |
parent | 44b5dfe8895c7c202b345dd5c23430636f519e9b (diff) | |
parent | 66e671111140090a1452db969fc2913c9561c10f (diff) | |
download | android_external_selinux-db6284efe2b62b7c245d8ee461ca0c21ca2c7a5a.tar.gz android_external_selinux-db6284efe2b62b7c245d8ee461ca0c21ca2c7a5a.tar.bz2 android_external_selinux-db6284efe2b62b7c245d8ee461ca0c21ca2c7a5a.zip |
Merge "Revert "Add ability to specify multiple input files to the selabel_open.""
Diffstat (limited to 'libselinux/src')
-rw-r--r-- | libselinux/src/label.c | 20 | ||||
-rw-r--r-- | libselinux/src/label_file.c | 92 | ||||
-rw-r--r-- | libselinux/src/label_internal.h | 6 |
3 files changed, 34 insertions, 84 deletions
diff --git a/libselinux/src/label.c b/libselinux/src/label.c index 951031e5..60639cfc 100644 --- a/libselinux/src/label.c +++ b/libselinux/src/label.c @@ -269,11 +269,7 @@ static int selabel_fini(struct selabel_handle *rec, struct selabel_lookup_rec *lr, int translating) { - char *path = NULL; - - if (rec->spec_files) - path = rec->spec_files[0]; - if (compat_validate(rec, lr, path, 0)) + if (compat_validate(rec, lr, rec->spec_file, 0)) return -1; if (translating && !lr->ctx_trans && @@ -372,9 +368,11 @@ struct selabel_handle *selabel_open(unsigned int backend, rec->digest = selabel_is_digest_set(opts, nopts, rec->digest); if ((*initfuncs[backend])(rec, opts, nopts)) { - selabel_close(rec); + free(rec->spec_file); + free(rec); rec = NULL; } + out: return rec; } @@ -492,18 +490,12 @@ int selabel_digest(struct selabel_handle *rec, void selabel_close(struct selabel_handle *rec) { - size_t i; selabel_subs_fini(rec->subs); selabel_subs_fini(rec->dist_subs); - if (rec->spec_files) { - for (i = 0; i < rec->spec_files_len; i++) - free(rec->spec_files[i]); - free(rec->spec_files); - } if (rec->digest) selabel_digest_fini(rec->digest); - if (rec->func_close) - rec->func_close(rec); + rec->func_close(rec); + free(rec->spec_file); free(rec); } diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 647e0a4a..a4dc3cdf 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -565,106 +565,66 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts, unsigned n) { struct saved_data *data = (struct saved_data *)rec->data; - size_t num_paths = 0; - char **path = NULL; + const char *path = NULL; const char *prefix = NULL; - int status = -1; - size_t i; - bool baseonly = false; - bool path_provided; + int status = -1, baseonly = 0; /* Process arguments */ - i = n; - while (i--) - switch(opts[i].type) { + while (n--) + switch(opts[n].type) { case SELABEL_OPT_PATH: - num_paths++; + path = opts[n].value; break; case SELABEL_OPT_SUBSET: - prefix = opts[i].value; + prefix = opts[n].value; break; case SELABEL_OPT_BASEONLY: - baseonly = !!opts[i].value; + baseonly = !!opts[n].value; break; } - if (!num_paths) { - num_paths = 1; - path_provided = false; - } else { - path_provided = true; - } - - path = calloc(num_paths, sizeof(*path)); - if (path == NULL) { - goto finish; - } - rec->spec_files = path; - rec->spec_files_len = num_paths; - - if (path_provided) { - i = n; - while (i--) - switch(opts[i].type) { - case SELABEL_OPT_PATH: - *path = strdup(opts[i].value); - if (*path == NULL) - goto finish; - path++; - break; - default: - break; - } - } #if !defined(BUILD_HOST) && !defined(ANDROID) char subs_file[PATH_MAX + 1]; /* Process local and distribution substitution files */ - if (!path_provided) { + if (!path) { rec->dist_subs = selabel_subs_init(selinux_file_context_subs_dist_path(), rec->dist_subs, rec->digest); rec->subs = selabel_subs_init(selinux_file_context_subs_path(), rec->subs, rec->digest); - rec->spec_files[0] = strdup(selinux_file_context_path()); - if (rec->spec_files[0] == NULL) - goto finish; + path = selinux_file_context_path(); } else { - for (i = 0; i < num_paths; i++) { - snprintf(subs_file, sizeof(subs_file), "%s.subs_dist", rec->spec_files[i]); - rec->dist_subs = selabel_subs_init(subs_file, rec->dist_subs, rec->digest); - snprintf(subs_file, sizeof(subs_file), "%s.subs", rec->spec_files[i]); - rec->subs = selabel_subs_init(subs_file, rec->subs, rec->digest); - } - } -#else - if (!path_provided) { - selinux_log(SELINUX_ERROR, "No path given to file labeling backend\n"); - goto finish; + snprintf(subs_file, sizeof(subs_file), "%s.subs_dist", path); + rec->dist_subs = selabel_subs_init(subs_file, rec->dist_subs, + rec->digest); + snprintf(subs_file, sizeof(subs_file), "%s.subs", path); + rec->subs = selabel_subs_init(subs_file, rec->subs, + rec->digest); } + #endif + rec->spec_file = strdup(path); /* - * Do detailed validation of the input and fill the spec array + * The do detailed validation of the input and fill the spec array */ - for (i = 0; i < num_paths; i++) { - status = process_file(rec->spec_files[i], NULL, rec, prefix, rec->digest); + status = process_file(path, NULL, rec, prefix, rec->digest); + if (status) + goto finish; + + if (rec->validating) { + status = nodups_specs(data, path); if (status) goto finish; - - if (rec->validating) { - status = nodups_specs(data, rec->spec_files[i]); - if (status) - goto finish; - } } if (!baseonly) { - status = process_file(rec->spec_files[0], "homedirs", rec, prefix, + status = process_file(path, "homedirs", rec, prefix, rec->digest); if (status && errno != ENOENT) goto finish; - status = process_file(rec->spec_files[0], "local", rec, prefix, + status = process_file(path, "local", rec, prefix, rec->digest); if (status && errno != ENOENT) goto finish; diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h index 62c1720e..3d7ff748 100644 --- a/libselinux/src/label_internal.h +++ b/libselinux/src/label_internal.h @@ -108,12 +108,10 @@ struct selabel_handle { void *data; /* - * The main spec file(s) used. Note for file contexts the local and/or + * The main spec file used. Note for file contexts the local and/or * homedirs could also have been used to resolve a context. */ - size_t spec_files_len; - char **spec_files; - + char *spec_file; /* substitution support */ struct selabel_sub *dist_subs; |