user.eclass: Ensure existence of shadow file before adding users

Previous changes that removed touching the shadow file in src_install()
caused issues when the package was upgraded and the shadow file was
removed. Now making sure that shadow file exists before adding new
users.

BUG=chromium:1026899
TEST=(grunt) emerge chromeos-base with existing shadow file and without.
Check shadow file to make sure it's populated proper

Change-Id: I6dbb7caeedaaa6733fe1b19b3f39b6ef85972a68
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/eclass-overlay/+/1933125
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Pranay Shoroff <pshoroff@google.com>
Commit-Queue: Pranay Shoroff <pshoroff@google.com>
diff --git a/eclass/user.eclass b/eclass/user.eclass
index 7fc5b5d..0837b1f 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -359,6 +359,12 @@
 	local is_in_shadow=false
 	if [[ ${epassword} == "x" ]]; then
 		should_have_shadow_entry=true
+
+		# Make sure shadow file exists.
+		if [[ ! -f "${ROOT}/etc/shadow" ]]; then
+			touch "${ROOT}/etc/shadow" || die
+		fi
+
 		if [[ -n "$(egetent shadow "${euser}")" ]]; then
 			is_in_shadow=true
 		fi
@@ -485,6 +491,12 @@
 	fi
 
 	local is_in_system_shadow=false
+
+	# Make sure shadow file exists.
+	if [[ ! -f "/etc/shadow" ]]; then
+		touch "/etc/shadow" || die
+	fi
+
 	if [[ -n "$(egetent shadow "${euser}" /)" ]]; then
 		is_in_system_shadow=true
 	fi