Honor GID provided in user specification, if provided

Not all user/group pairs use the same UID and GID. For the
ones that specify different numbers, honor that.

BUG=chromium:343369
TEST=build an image, run security_AccountsBaseline

Change-Id: I34cb1e6da4ad5bf9f2dfb66a4e05a076d085c44a
Reviewed-on: https://chromium-review.googlesource.com/190731
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
diff --git a/eclass/user.eclass b/eclass/user.eclass
index c787e55..6fc06eb 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -248,6 +248,11 @@
 	fi
 	einfo " - Userid: ${euid}"
 
+	# See if there's a provided gid and use it if so.
+	local provided_gid=$(_get_value_for_user "${euser}" gid)
+	local egid=${provided_gid:-${euid}}
+	einfo " - Groupid: ${egid}"
+
 	# handle shell
 	local eshell=$1; shift
 	if [[ -n ${eshell} && ${eshell} != "-1" ]] ; then
@@ -296,7 +301,7 @@
 
 	local epassword=$(_get_value_for_user "${euser}" password)
 	: ${epassword:="!"}
-	local entry="${euser}:${epassword}:${euid}:${euid}:${comment}:${ehome}:${eshell}"
+	local entry="${euser}:${epassword}:${euid}:${egid}:${comment}:${ehome}:${eshell}"
 	if [[ ${EBUILD_PHASE} == "setup" ]] ; then
 		_write_entry_to_db "${entry}" passwd / || die "Must be able to add users during setup."
 	fi