2013-01-23 20:04:50 +01:00
|
|
|
#include <getopt.h>
|
2015-09-25 03:10:54 +02:00
|
|
|
#include <stdbool.h>
|
2012-10-02 18:46:37 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-09-25 03:10:54 +02:00
|
|
|
#include <string.h>
|
2016-01-15 02:06:37 +01:00
|
|
|
#include <unistd.h>
|
2015-09-25 03:10:54 +02:00
|
|
|
#include <sepol/module.h>
|
|
|
|
#include <sepol/policydb/policydb.h>
|
2012-10-02 18:46:37 +02:00
|
|
|
#include <sepol/sepol.h>
|
2023-10-05 00:44:24 +02:00
|
|
|
#include <selinux/context.h>
|
2012-10-02 18:46:37 +02:00
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/label.h>
|
2016-01-15 02:06:37 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2012-10-02 18:46:37 +02:00
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
static const char * const CHECK_FC_ASSERT_ATTRS[] = { "fs_type", "dev_type", "file_type", NULL };
|
|
|
|
static const char * const CHECK_PC_ASSERT_ATTRS[] = { "property_type", NULL };
|
|
|
|
static const char * const CHECK_SC_ASSERT_ATTRS[] = { "service_manager_type", NULL };
|
2017-04-06 22:22:44 +02:00
|
|
|
static const char * const CHECK_HW_SC_ASSERT_ATTRS[] = { "hwservice_manager_type", NULL };
|
|
|
|
static const char * const CHECK_VND_SC_ASSERT_ATTRS[] = { "vndservice_manager_type", NULL };
|
2015-09-25 03:10:54 +02:00
|
|
|
|
|
|
|
typedef enum filemode filemode;
|
|
|
|
enum filemode {
|
|
|
|
filemode_file_contexts = 0,
|
|
|
|
filemode_property_contexts,
|
2017-04-06 22:22:44 +02:00
|
|
|
filemode_service_contexts,
|
|
|
|
filemode_hw_service_contexts,
|
|
|
|
filemode_vendor_service_contexts
|
2015-09-25 03:10:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
/* policy */
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
/* Union these so we don't have to cast */
|
|
|
|
sepol_policydb_t *sdb;
|
|
|
|
policydb_t *pdb;
|
|
|
|
};
|
|
|
|
sepol_policy_file_t *pf;
|
|
|
|
sepol_handle_t *handle;
|
|
|
|
FILE *file;
|
|
|
|
#define SEHANDLE_CNT 2
|
|
|
|
struct selabel_handle *sehnd[SEHANDLE_CNT];
|
|
|
|
} sepolicy;
|
|
|
|
|
|
|
|
/* assertions */
|
|
|
|
struct {
|
|
|
|
const char * const *attrs; /* for the original set to print on error */
|
|
|
|
ebitmap_t set; /* the ebitmap representation of the attrs */
|
|
|
|
} assert;
|
|
|
|
|
|
|
|
} global_state;
|
|
|
|
|
|
|
|
static const char * const *filemode_to_assert_attrs(filemode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case filemode_file_contexts:
|
|
|
|
return CHECK_FC_ASSERT_ATTRS;
|
|
|
|
case filemode_property_contexts:
|
|
|
|
return CHECK_PC_ASSERT_ATTRS;
|
|
|
|
case filemode_service_contexts:
|
|
|
|
return CHECK_SC_ASSERT_ATTRS;
|
2017-04-06 22:22:44 +02:00
|
|
|
case filemode_hw_service_contexts:
|
|
|
|
return CHECK_HW_SC_ASSERT_ATTRS;
|
|
|
|
case filemode_vendor_service_contexts:
|
|
|
|
return CHECK_VND_SC_ASSERT_ATTRS;
|
2015-09-25 03:10:54 +02:00
|
|
|
}
|
|
|
|
/* die on invalid parameters */
|
|
|
|
fprintf(stderr, "Error: Invalid mode of operation: %d\n", mode);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_attr_bit(policydb_t *policydb, const char *attr_name)
|
|
|
|
{
|
|
|
|
struct type_datum *attr = hashtab_search(policydb->p_types.table, (char *)attr_name);
|
|
|
|
if (!attr) {
|
|
|
|
fprintf(stderr, "Error: \"%s\" is not defined in this policy.\n", attr_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->flavor != TYPE_ATTRIB) {
|
|
|
|
fprintf(stderr, "Error: \"%s\" is not an attribute in this policy.\n", attr_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return attr->s.value - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ebitmap_attribute_assertion_init(ebitmap_t *assertions, const char * const attributes[])
|
|
|
|
{
|
|
|
|
|
|
|
|
while (*attributes) {
|
|
|
|
|
|
|
|
int bit_pos = get_attr_bit(global_state.sepolicy.pdb, *attributes);
|
|
|
|
if (bit_pos < 0) {
|
|
|
|
/* get_attr_bit() logs error */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int err = ebitmap_set_bit(assertions, bit_pos, 1);
|
|
|
|
if (err) {
|
|
|
|
fprintf(stderr, "Error: setting bit on assertion ebitmap!\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
attributes++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_type_of_attribute_set(policydb_t *policydb, const char *type_name,
|
|
|
|
ebitmap_t *attr_set)
|
|
|
|
{
|
|
|
|
struct type_datum *type = hashtab_search(policydb->p_types.table, (char *)type_name);
|
|
|
|
if (!type) {
|
|
|
|
fprintf(stderr, "Error: \"%s\" is not defined in this policy.\n", type_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type->flavor != TYPE_TYPE) {
|
|
|
|
fprintf(stderr, "Error: \"%s\" is not a type in this policy.\n", type_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ebitmap_t dst;
|
|
|
|
ebitmap_init(&dst);
|
|
|
|
|
|
|
|
/* Take the intersection, if the set is empty, then its a failure */
|
|
|
|
int rc = ebitmap_and(&dst, attr_set, &policydb->type_attr_map[type->s.value - 1]);
|
|
|
|
if (rc) {
|
|
|
|
fprintf(stderr, "Error: Could not perform ebitmap_and: %d\n", rc);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = (bool)ebitmap_length(&dst);
|
|
|
|
|
|
|
|
ebitmap_destroy(&dst);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_char_array(FILE *stream, const char * const *strings)
|
|
|
|
{
|
|
|
|
|
|
|
|
const char * const *p = strings;
|
|
|
|
|
|
|
|
fprintf(stream, "\"");
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
const char *s = *p++;
|
|
|
|
const char *fmt = *p ? "%s, " : "%s\"";
|
|
|
|
fprintf(stream, fmt, s);
|
|
|
|
}
|
|
|
|
}
|
2012-10-02 18:46:37 +02:00
|
|
|
|
|
|
|
static int validate(char **contextp)
|
|
|
|
{
|
2015-09-25 03:10:54 +02:00
|
|
|
bool res;
|
|
|
|
char *context = *contextp;
|
|
|
|
|
|
|
|
sepol_context_t *ctx;
|
|
|
|
int rc = sepol_context_from_string(global_state.sepolicy.handle, context,
|
|
|
|
&ctx);
|
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "Error: Could not allocate context from string");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = sepol_context_check(global_state.sepolicy.handle,
|
|
|
|
global_state.sepolicy.sdb, ctx);
|
|
|
|
if (rc < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *type_name = sepol_context_get_type(ctx);
|
|
|
|
|
2022-02-16 03:26:11 +01:00
|
|
|
// Temporarily exempt hal_power_stats_vendor_service from the check.
|
|
|
|
// TODO(b/211953546): remove this
|
|
|
|
if (strcmp(type_name, "hal_power_stats_vendor_service") == 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
uint32_t len = ebitmap_length(&global_state.assert.set);
|
|
|
|
if (len > 0) {
|
|
|
|
res = !is_type_of_attribute_set(global_state.sepolicy.pdb, type_name,
|
|
|
|
&global_state.assert.set);
|
|
|
|
if (res) {
|
|
|
|
fprintf(stderr, "Error: type \"%s\" is not of set: ", type_name);
|
|
|
|
dump_char_array(stderr, global_state.assert.attrs);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
/* The calls above did not affect rc, so set error before going to out */
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Success: Although it should be 0, we explicitly set rc to 0 for clarity */
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
sepol_context_free(ctx);
|
|
|
|
return rc;
|
2012-10-02 18:46:37 +02:00
|
|
|
}
|
|
|
|
|
2013-01-23 20:04:50 +01:00
|
|
|
static void usage(char *name) {
|
2017-04-06 22:22:44 +02:00
|
|
|
fprintf(stderr, "usage1: %s [-l|-p|-s|-v] [-e] sepolicy context_file\n\n"
|
2015-09-25 03:10:54 +02:00
|
|
|
"Parses a context file and checks for syntax errors.\n"
|
2017-04-06 22:22:44 +02:00
|
|
|
"If -p is specified, the property backend is used.\n"
|
|
|
|
"If -s is specified, the service backend is used to verify binder services.\n"
|
|
|
|
"If -l is specified, the service backend is used to verify hwbinder services.\n"
|
|
|
|
"If -v is specified, the service backend is used to verify vndbinder services.\n"
|
|
|
|
"Otherwise, context_file is assumed to be a file_contexts file\n"
|
2016-01-15 02:06:37 +01:00
|
|
|
"If -e is specified, then the context_file is allowed to be empty.\n\n"
|
2015-09-25 03:10:54 +02:00
|
|
|
|
|
|
|
"usage2: %s -c file_contexts1 file_contexts2\n\n"
|
2023-10-05 00:44:24 +02:00
|
|
|
"Compares two file contexts files and reports one of \n"
|
|
|
|
"subset, equal, superset, or incomparable.\n\n"
|
|
|
|
|
|
|
|
"usage3: %s -t file_contexts test_data\n\n"
|
|
|
|
"Validates a file contexts file against test_data.\n"
|
|
|
|
"test_data is a text file where each line has the format:\n"
|
|
|
|
" path expected_type\n\n\n",
|
|
|
|
name, name, name);
|
2013-01-23 20:04:50 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
static void cleanup(void) {
|
|
|
|
|
|
|
|
if (global_state.sepolicy.file) {
|
|
|
|
fclose(global_state.sepolicy.file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global_state.sepolicy.sdb) {
|
|
|
|
sepol_policydb_free(global_state.sepolicy.sdb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global_state.sepolicy.pf) {
|
|
|
|
sepol_policy_file_free(global_state.sepolicy.pf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global_state.sepolicy.handle) {
|
|
|
|
sepol_handle_destroy(global_state.sepolicy.handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
ebitmap_destroy(&global_state.assert.set);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < SEHANDLE_CNT; i++) {
|
|
|
|
struct selabel_handle *sehnd = global_state.sepolicy.sehnd[i];
|
|
|
|
if (sehnd) {
|
|
|
|
selabel_close(sehnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_compare_and_die_on_error(struct selinux_opt opts[], unsigned int backend, char *paths[])
|
|
|
|
{
|
|
|
|
enum selabel_cmp_result result;
|
|
|
|
char *result_str[] = { "subset", "equal", "superset", "incomparable" };
|
|
|
|
int i;
|
|
|
|
|
|
|
|
opts[0].value = NULL; /* not validating against a policy when comparing */
|
|
|
|
|
|
|
|
for (i = 0; i < SEHANDLE_CNT; i++) {
|
|
|
|
opts[1].value = paths[i];
|
|
|
|
global_state.sepolicy.sehnd[i] = selabel_open(backend, opts, 2);
|
|
|
|
if (!global_state.sepolicy.sehnd[i]) {
|
|
|
|
fprintf(stderr, "Error: could not load context file from %s\n", paths[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = selabel_cmp(global_state.sepolicy.sehnd[0], global_state.sepolicy.sehnd[1]);
|
|
|
|
printf("%s\n", result_str[result]);
|
|
|
|
}
|
|
|
|
|
2023-10-20 04:14:26 +02:00
|
|
|
static int warnings = 0;
|
|
|
|
static int log_callback(int type, const char *fmt, ...) {
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (type == SELINUX_WARNING) {
|
|
|
|
warnings += 1;
|
|
|
|
}
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-05 00:44:24 +02:00
|
|
|
static void do_test_data_and_die_on_error(struct selinux_opt opts[], unsigned int backend,
|
|
|
|
char *paths[])
|
|
|
|
{
|
|
|
|
opts[0].value = NULL; /* not validating against a policy */
|
|
|
|
opts[1].value = paths[0];
|
|
|
|
global_state.sepolicy.sehnd[0] = selabel_open(backend, opts, 2);
|
|
|
|
if (!global_state.sepolicy.sehnd[0]) {
|
|
|
|
fprintf(stderr, "Error: could not load context file from %s: %s\n",
|
|
|
|
paths[0], strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* test_data = fopen(paths[1], "r");
|
|
|
|
if (test_data == NULL) {
|
|
|
|
fprintf(stderr, "Error: could not load test file from %s : %s\n",
|
|
|
|
paths[1], strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char line[1024];
|
|
|
|
while (fgets(line, sizeof(line), test_data)) {
|
|
|
|
char *path;
|
|
|
|
char *expected_type;
|
|
|
|
|
|
|
|
if (!strcmp(line, "\n") || line[0] == '#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = sscanf(line, "%ms %ms", &path, &expected_type);
|
|
|
|
if (ret != 2) {
|
|
|
|
fprintf(stderr, "Error: unable to parse the line %s\n", line);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *found_context;
|
|
|
|
ret = selabel_lookup(global_state.sepolicy.sehnd[0], &found_context, path, 0);
|
|
|
|
if (ret != 0) {
|
|
|
|
fprintf(stderr, "Error: unable to lookup the path for %s\n", line);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
context_t found = context_new(found_context);
|
|
|
|
const char *found_type = context_type_get(found);
|
|
|
|
|
|
|
|
if (strcmp(found_type, expected_type)) {
|
|
|
|
fprintf(stderr, "Incorrect type for %s: resolved to %s, expected %s\n",
|
|
|
|
path, found_type, expected_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(found_context);
|
|
|
|
context_free(found);
|
|
|
|
free(path);
|
|
|
|
free(expected_type);
|
|
|
|
}
|
|
|
|
fclose(test_data);
|
|
|
|
|
|
|
|
// Prints the coverage of file_contexts on the test data. It includes
|
|
|
|
// warnings for rules that have not been hit by any test example.
|
2023-10-20 04:14:26 +02:00
|
|
|
union selinux_callback cb;
|
|
|
|
cb.func_log = log_callback;
|
|
|
|
selinux_set_callback(SELINUX_CB_LOG, cb);
|
2023-10-05 00:44:24 +02:00
|
|
|
selabel_stats(global_state.sepolicy.sehnd[0]);
|
2023-10-20 04:14:26 +02:00
|
|
|
if (warnings) {
|
|
|
|
fprintf(stderr, "No test entries were found for the contexts above. " \
|
|
|
|
"You may need to update %s.\n", paths[1]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-10-05 00:44:24 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
static void do_fc_check_and_die_on_error(struct selinux_opt opts[], unsigned int backend, filemode mode,
|
2016-01-15 02:06:37 +01:00
|
|
|
const char *sepolicy_file, const char *context_file, bool allow_empty)
|
2015-09-25 03:10:54 +02:00
|
|
|
{
|
2016-01-15 02:06:37 +01:00
|
|
|
struct stat sb;
|
|
|
|
if (stat(context_file, &sb) < 0) {
|
|
|
|
perror("Error: could not get stat on file contexts file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.st_size == 0) {
|
|
|
|
/* Nothing to check on empty file_contexts file if allowed*/
|
|
|
|
if (allow_empty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* else: We could throw the error here, but libselinux backend will catch it */
|
|
|
|
}
|
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
global_state.sepolicy.file = fopen(sepolicy_file, "r");
|
|
|
|
if (!global_state.sepolicy.file) {
|
|
|
|
perror("Error: could not open policy file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
global_state.sepolicy.handle = sepol_handle_create();
|
|
|
|
if (!global_state.sepolicy.handle) {
|
|
|
|
fprintf(stderr, "Error: could not create policy handle: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sepol_policy_file_create(&global_state.sepolicy.pf) < 0) {
|
|
|
|
perror("Error: could not create policy handle");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sepol_policy_file_set_fp(global_state.sepolicy.pf, global_state.sepolicy.file);
|
|
|
|
sepol_policy_file_set_handle(global_state.sepolicy.pf, global_state.sepolicy.handle);
|
|
|
|
|
|
|
|
int rc = sepol_policydb_create(&global_state.sepolicy.sdb);
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error: could not create policy db");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = sepol_policydb_read(global_state.sepolicy.sdb, global_state.sepolicy.pf);
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error: could not read file into policy db");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
global_state.assert.attrs = filemode_to_assert_attrs(mode);
|
|
|
|
|
|
|
|
bool ret = ebitmap_attribute_assertion_init(&global_state.assert.set, global_state.assert.attrs);
|
|
|
|
if (!ret) {
|
|
|
|
/* error messages logged by ebitmap_attribute_assertion_init() */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
selinux_set_callback(SELINUX_CB_VALIDATE,
|
|
|
|
(union selinux_callback)&validate);
|
|
|
|
|
|
|
|
opts[1].value = context_file;
|
|
|
|
|
|
|
|
global_state.sepolicy.sehnd[0] = selabel_open(backend, opts, 2);
|
|
|
|
if (!global_state.sepolicy.sehnd[0]) {
|
|
|
|
fprintf(stderr, "Error: could not load context file from %s\n", context_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:46:37 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct selinux_opt opts[] = {
|
|
|
|
{ SELABEL_OPT_VALIDATE, (void*)1 },
|
|
|
|
{ SELABEL_OPT_PATH, NULL }
|
|
|
|
};
|
2013-01-23 20:04:50 +01:00
|
|
|
|
|
|
|
// Default backend unless changed by input argument.
|
|
|
|
unsigned int backend = SELABEL_CTX_FILE;
|
|
|
|
|
2016-01-15 02:06:37 +01:00
|
|
|
bool allow_empty = false;
|
2015-08-05 18:43:15 +02:00
|
|
|
bool compare = false;
|
2023-10-05 00:44:24 +02:00
|
|
|
bool test_data = false;
|
2013-01-23 20:04:50 +01:00
|
|
|
char c;
|
2012-10-02 18:46:37 +02:00
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
filemode mode = filemode_file_contexts;
|
|
|
|
|
2023-10-05 00:44:24 +02:00
|
|
|
while ((c = getopt(argc, argv, "clpsvet")) != -1) {
|
2013-01-23 20:04:50 +01:00
|
|
|
switch (c) {
|
2015-08-05 18:43:15 +02:00
|
|
|
case 'c':
|
|
|
|
compare = true;
|
|
|
|
break;
|
2016-01-15 02:06:37 +01:00
|
|
|
case 'e':
|
|
|
|
allow_empty = true;
|
|
|
|
break;
|
2013-01-23 20:04:50 +01:00
|
|
|
case 'p':
|
2015-09-25 03:10:54 +02:00
|
|
|
mode = filemode_property_contexts;
|
|
|
|
backend = SELABEL_CTX_ANDROID_PROP;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
mode = filemode_service_contexts;
|
2016-09-08 14:15:19 +02:00
|
|
|
backend = SELABEL_CTX_ANDROID_SERVICE;
|
2013-01-23 20:04:50 +01:00
|
|
|
break;
|
2017-04-06 22:22:44 +02:00
|
|
|
case 'l':
|
|
|
|
mode = filemode_hw_service_contexts;
|
|
|
|
backend = SELABEL_CTX_ANDROID_SERVICE;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
mode = filemode_vendor_service_contexts;
|
|
|
|
backend = SELABEL_CTX_ANDROID_SERVICE;
|
|
|
|
break;
|
2023-10-05 00:44:24 +02:00
|
|
|
case 't':
|
|
|
|
test_data = true;
|
|
|
|
break;
|
2013-01-23 20:04:50 +01:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = optind;
|
|
|
|
if (argc - optind != 2) {
|
|
|
|
usage(argv[0]);
|
2012-10-02 18:46:37 +02:00
|
|
|
}
|
|
|
|
|
2023-10-05 00:44:24 +02:00
|
|
|
if ((compare || test_data) && backend != SELABEL_CTX_FILE) {
|
2015-08-05 18:43:15 +02:00
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
atexit(cleanup);
|
2013-01-23 20:04:50 +01:00
|
|
|
|
2015-09-25 03:10:54 +02:00
|
|
|
if (compare) {
|
|
|
|
do_compare_and_die_on_error(opts, backend, &(argv[index]));
|
2023-10-05 00:44:24 +02:00
|
|
|
} else if (test_data) {
|
|
|
|
do_test_data_and_die_on_error(opts, backend, &(argv[index]));
|
2015-09-25 03:10:54 +02:00
|
|
|
} else {
|
|
|
|
/* remaining args are sepolicy file and context file */
|
|
|
|
char *sepolicy_file = argv[index];
|
|
|
|
char *context_file = argv[index + 1];
|
2012-10-02 18:46:37 +02:00
|
|
|
|
2016-01-15 02:06:37 +01:00
|
|
|
do_fc_check_and_die_on_error(opts, backend, mode, sepolicy_file, context_file, allow_empty);
|
2012-10-02 18:46:37 +02:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|