// The below two functions are duplicated from label_support.c in libselinux.
// The read_spec_entries and read_spec_entry functions may be used to // replace sscanf to read entries from spec files. The file and // property services now use these.
// Read an entry from a spec file (e.g. file_contexts) staticinlineint read_spec_entry(char** entry, char** ptr, int* len) {
*entry = nullptr; char* tmp_buf = nullptr;
while (isspace(**ptr) && **ptr != '\0') (*ptr)++;
tmp_buf = *ptr;
*len = 0;
while (!isspace(**ptr) && **ptr != '\0') {
(*ptr)++;
(*len)++;
}
if (*len) {
*entry = strndup(tmp_buf, *len); if (!*entry) return -1;
}
return0;
}
// line_buf - Buffer containing the spec entries . // num_args - The number of spec parameter entries to process. // ... - A 'char **spec_entry' for each parameter. // returns - The number of items processed. // // This function calls read_spec_entry() to do the actual string processing. staticint read_spec_entries(char* line_buf, int num_args, ...) { char **spec_entry, *buf_p; int len, rc, items, entry_len = 0;
va_list ap;
len = strlen(line_buf); if (line_buf[len - 1] == '\n')
line_buf[len - 1] = '\0'; else // Handle case if line not \n terminated by bumping // the len for the check below (as the line is NUL // terminated by getline(3))
len++;
buf_p = line_buf; while (isspace(*buf_p)) buf_p++;
// Skip comment lines and empty lines. if (*buf_p == '#' || *buf_p == '\0') return0;
// Process the spec file entries
va_start(ap, num_args);
while (getline(&buffer, &line_len, file) > 0) { int items = read_spec_entries(buffer, 2, &prop_prefix, &context); if (items <= 0) { continue;
} if (items == 1) {
free(prop_prefix); continue;
}
// init uses ctl.* properties as an IPC mechanism and does not write them // to a property file, therefore we do not need to create property files // to store them. if (!strncmp(prop_prefix, "ctl.", 4)) {
free(prop_prefix);
free(context); continue;
}
bool ContextsSplit::InitializeProperties() { // If we do find /property_contexts, then this is being // run as part of the OTA updater on older release that had // /property_contexts - b/34370523 if (InitializePropertiesFromFile("/property_contexts")) { returntrue;
}
// Use property_contexts from /system & /vendor, fall back to those from / if (access("/system/etc/selinux/plat_property_contexts", R_OK) != -1) { if (!InitializePropertiesFromFile("/system/etc/selinux/plat_property_contexts")) { returnfalse;
} // Don't check for failure here, since we don't always have all of these partitions. // E.g. In case of recovery, the vendor partition will not have mounted and we // still need the system / platform properties to function. if (access("/vendor/etc/selinux/vendor_property_contexts", R_OK) != -1) {
InitializePropertiesFromFile("/vendor/etc/selinux/vendor_property_contexts");
}
} else { if (!InitializePropertiesFromFile("/plat_property_contexts")) { returnfalse;
} if (access("/vendor_property_contexts", R_OK) != -1) {
InitializePropertiesFromFile("/vendor_property_contexts");
}
}
prop_area* ContextsSplit::GetPropAreaForName(constchar* name) { auto entry = GetPrefixNodeForName(name); if (!entry) { return nullptr;
}
auto cnode = entry->context; if (!cnode->pa()) { // We explicitly do not check no_access_ in this case because unlike the // case of foreach(), we want to generate an selinux audit for each // non-permitted property access in this function.
cnode->Open(false, nullptr);
} return cnode->pa();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.