fs_config: introduce passwd generator am: 316f9462af am: 62d75469b1

am: 13be8e4305

Change-Id: I9a8681f10746bad905225f52d6774ace3799973c
This commit is contained in:
William Roberts 2016-12-10 00:36:21 +00:00 committed by android-build-merger
commit 55e33be098
2 changed files with 92 additions and 1 deletions

View File

@ -105,7 +105,6 @@ LOCAL_GENERATED_SOURCES := $(oem) $(gen)
my_fs_config_h := $(gen)
my_gen_oem_aid := $(oem)
system_android_filesystem_config :=
gen :=
oem :=
endif
@ -151,6 +150,25 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := $(dir $(my_gen_oem_aid))
LOCAL_EXPORT_C_INCLUDE_DEPS := $(my_gen_oem_aid)
include $(BUILD_STATIC_LIBRARY)
##################################
# Generate the system/etc/passwd text file for the target
# This file may be empty if no AIDs are defined in
# TARGET_FS_CONFIG_GEN files.
include $(CLEAR_VARS)
LOCAL_MODULE := passwd
LOCAL_MODULE_CLASS := ETC
include $(BUILD_SYSTEM)/base_rules.mk
$(LOCAL_BUILT_MODULE): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
$(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
$(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
@mkdir -p $(dir $@)
$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
system_android_filesystem_config :=
endif
ANDROID_FS_CONFIG_H :=

View File

@ -1153,6 +1153,79 @@ class OEMAidGen(BaseGenerator):
print OEMAidGen._GENERIC_DEFINE % (aid.identifier, aid.value)
@generator('passwd')
class PasswdGen(BaseGenerator):
"""Generates the /etc/passwd file per man (5) passwd."""
_GENERATED = ('#\n# THIS IS AN AUTOGENERATED FILE! DO NOT MODIFY!\n#')
_FILE_COMMENT = '# Defined in file: \"%s\"'
def __init__(self):
self._old_file = None
def add_opts(self, opt_group):
opt_group.add_argument(
'fsconfig', nargs='+', help='The list of fsconfig files to parse.')
opt_group.add_argument(
'--aid-header',
required=True,
help='An android_filesystem_config.h file'
'to parse AIDs and OEM Ranges from')
def __call__(self, args):
hdr_parser = AIDHeaderParser(args['aid_header'])
parser = FSConfigFileParser(args['fsconfig'], hdr_parser.oem_ranges)
aids = parser.aids
# nothing to do if no aids defined
if len(aids) == 0:
return
print PasswdGen._GENERATED
for aid in aids:
self._print_aid_passwd_line(aid)
def _print_aid_passwd_line(self, aid):
"""
Prints the aid to stdout in the passwd format.
Internal use only.
Colon delimited:
login name, friendly name
encrypted password (optional)
uid (int)
gid (int)
User name or comment field
home directory
interpreter (optional)
Args:
aid (AID): The aid to print.
"""
if self._old_file != aid.found:
self._old_file = aid.found
print PasswdGen._FILE_COMMENT % aid.found
logon = aid.friendly
uid = aid.normalized_value
if ':' in uid:
sys.exit('Cannot specify delimiter character ":" in uid: "%s"' %
uid)
if ':' in logon:
sys.exit('Cannot specify delimiter character ":" in logon: "%s"' %
logon)
print "%s::%s:%s::/:/system/bin/sh" % (logon, uid, uid)
def main():
"""Main entry point for execution."""