fs_config: introduce passwd generator

Introduce a generator that outputs passwd files per man(5) passwd.

Succinctly, the output is a colon delimited string containing the following
fields:

  * login name
  * encrypted password (optional)
  * uid (int)
  * gid (int)
  * User name or comment field
  * home directory
  * interpreter (optional)

Multiple colon delimited lines may exist, but will not be separated
across lines.

When run, produces:

foo::2900:2900::/:/system/bin/sh
foo_bar::2901:2901::/:/system/bin/sh
custom_oem1::2902:2902::/:/system/bin/sh

Note that this generator allows for 0 or more config.fs files. This allows for:
  * Unconditional inclusion of /system/etc/passwd in the generated image
  * A blank passwd file if no config.fs files are specified.

This ensures that when OEMs add config.fs files, there is no additional steps
for proper functionality (simpler for OEMs).

The one draw back is the additional inode consumption on system for a possible
blank file.

Test: That it produces a valid passwd file.
Change-Id: I19691c8260f02147ed861f8a319aeab3f5b1738e
Signed-off-by: William Roberts <william.c.roberts@intel.com>
diff --git a/tools/fs_config/Android.mk b/tools/fs_config/Android.mk
index 7f216d2..84bfa88 100644
--- a/tools/fs_config/Android.mk
+++ b/tools/fs_config/Android.mk
@@ -105,7 +105,6 @@
 
 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_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 :=