fs_config: introduce group generator
am: 1c4721c3c5
Change-Id: I2eccb5f0d39a3740f540b683fb332df405728c4f
This commit is contained in:
commit
3315954861
|
@ -168,6 +168,24 @@ $(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_G
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
|
$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Generate the system/etc/group 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 := group
|
||||||
|
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) $< group --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
|
||||||
|
|
||||||
system_android_filesystem_config :=
|
system_android_filesystem_config :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,32 @@ class Utils(object):
|
||||||
|
|
||||||
return any(lower <= value <= upper for (lower, upper) in ranges)
|
return any(lower <= value <= upper for (lower, upper) in ranges)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_login_and_uid_cleansed(aid):
|
||||||
|
"""Returns a passwd/group file safe logon and uid.
|
||||||
|
|
||||||
|
This checks that the logon and uid of the AID do not
|
||||||
|
contain the delimiter ":" for a passwd/group file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
aid (AID): The aid to check
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
logon, uid of the AID after checking its safe.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If there is a delimiter charcter found.
|
||||||
|
"""
|
||||||
|
logon = aid.friendly
|
||||||
|
uid = aid.normalized_value
|
||||||
|
if ':' in uid:
|
||||||
|
raise ValueError(
|
||||||
|
'Cannot specify delimiter character ":" in uid: "%s"' % uid)
|
||||||
|
if ':' in logon:
|
||||||
|
raise ValueError(
|
||||||
|
'Cannot specify delimiter character ":" in logon: "%s"' % logon)
|
||||||
|
return logon, uid
|
||||||
|
|
||||||
|
|
||||||
class AID(object):
|
class AID(object):
|
||||||
"""This class represents an Android ID or an AID.
|
"""This class represents an Android ID or an AID.
|
||||||
|
@ -1191,12 +1217,10 @@ class PasswdGen(BaseGenerator):
|
||||||
print PasswdGen._GENERATED
|
print PasswdGen._GENERATED
|
||||||
|
|
||||||
for aid in aids:
|
for aid in aids:
|
||||||
self._print_aid_passwd_line(aid)
|
self._print_formatted_line(aid)
|
||||||
|
|
||||||
def _print_aid_passwd_line(self, aid):
|
def _print_formatted_line(self, aid):
|
||||||
"""
|
"""Prints the aid to stdout in the passwd format. Internal use only.
|
||||||
Prints the aid to stdout in the passwd format.
|
|
||||||
Internal use only.
|
|
||||||
|
|
||||||
Colon delimited:
|
Colon delimited:
|
||||||
login name, friendly name
|
login name, friendly name
|
||||||
|
@ -1214,18 +1238,40 @@ class PasswdGen(BaseGenerator):
|
||||||
self._old_file = aid.found
|
self._old_file = aid.found
|
||||||
print PasswdGen._FILE_COMMENT % aid.found
|
print PasswdGen._FILE_COMMENT % aid.found
|
||||||
|
|
||||||
logon = aid.friendly
|
try:
|
||||||
uid = aid.normalized_value
|
logon, uid = Utils.get_login_and_uid_cleansed(aid)
|
||||||
if ':' in uid:
|
except ValueError as exception:
|
||||||
sys.exit('Cannot specify delimiter character ":" in uid: "%s"' %
|
sys.exit(exception)
|
||||||
uid)
|
|
||||||
if ':' in logon:
|
|
||||||
sys.exit('Cannot specify delimiter character ":" in logon: "%s"' %
|
|
||||||
logon)
|
|
||||||
|
|
||||||
print "%s::%s:%s::/:/system/bin/sh" % (logon, uid, uid)
|
print "%s::%s:%s::/:/system/bin/sh" % (logon, uid, uid)
|
||||||
|
|
||||||
|
|
||||||
|
@generator('group')
|
||||||
|
class GroupGen(PasswdGen):
|
||||||
|
"""Generates the /etc/group file per man (5) group."""
|
||||||
|
|
||||||
|
# Overrides parent
|
||||||
|
def _print_formatted_line(self, aid):
|
||||||
|
"""Prints the aid to stdout in the group format. Internal use only.
|
||||||
|
|
||||||
|
Formatted (per man 5 group) like:
|
||||||
|
group_name:password:GID:user_list
|
||||||
|
|
||||||
|
Args:
|
||||||
|
aid (AID): The aid to print.
|
||||||
|
"""
|
||||||
|
if self._old_file != aid.found:
|
||||||
|
self._old_file = aid.found
|
||||||
|
print PasswdGen._FILE_COMMENT % aid.found
|
||||||
|
|
||||||
|
try:
|
||||||
|
logon, uid = Utils.get_login_and_uid_cleansed(aid)
|
||||||
|
except ValueError as exception:
|
||||||
|
sys.exit(exception)
|
||||||
|
|
||||||
|
print "%s::%s:" % (logon, uid)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point for execution."""
|
"""Main entry point for execution."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue