// This file mmap's /*/etc/passwd and /*/etc/group in order to return their contents without any // allocations. Note that these files and the strings contained within them are explicitly not // null-terminated. ':'s are used to deliminate fields and '\n's are used to deliminate lines. // There is a check that the file ends with '\n', such that terminating loops at '\n' ensures that // memory will be not read beyond the mmap region.
char* end = nullptr;
errno = 0;
uid_t result = strtoul(field, &end, 0); if (errno != 0 || field == end || *end != ':') { returnfalse;
}
*uid = result; returntrue;
}
// Returns a pointer to one past the end of line. constchar* ParseLine(constchar* begin, constchar* end, constchar** fields, size_t num_fields) {
size_t fields_written = 0; constchar* position = begin;
fields[fields_written++] = position;
while (position < end && fields_written < num_fields) { if (*position == '\n') { return position + 1;
} if (*position == ':') {
fields[fields_written++] = position + 1;
}
position++;
}
while (position < end && *position != '\n') {
position++;
}
return position + 1;
}
struct PasswdLine { constchar* name() const { return fields[0];
} // Password is not supported. constchar* uid() const { return fields[2];
} constchar* gid() const { return fields[3];
} // User Info is not supported constchar* dir() const { return fields[5];
} constchar* shell() const { return fields[6];
}
while (line_beginning < end) {
line_beginning = ParseLine(line_beginning, end, line->fields, line->kNumFields); #ifdefined(__ANDROID__) // To comply with Treble, users/groups from each partition need to be prefixed with // the partition name. if (required_prefix_ != nullptr) { if (strncmp(line->fields[0], required_prefix_, strlen(required_prefix_)) != 0) { char name[kGrpPwdBufferSize];
CopyFieldToString(name, line->fields[0], sizeof(name));
async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Found user/group name '%s' in '%s' without required prefix '%s'",
name, filename_, required_prefix_); continue;
}
} #endif if (predicate(line)) returntrue;
}
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.