display-accts: check for duplicate gid/uid values

Make sure people don't accidentally add a group or user with a duplicate
id.  And fix up the one case so far where this happened.

BUG=None
TEST=`./display-accts.py` no longer errors out

Change-Id: I998b3ac8ead4b4efefa10154c6614e5104734ecf
Reviewed-on: https://chromium-review.googlesource.com/317400
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
diff --git a/profiles/base/accounts/display-accts.py b/profiles/base/accounts/display-accts.py
index a5fb3c4..e3d318f 100755
--- a/profiles/base/accounts/display-accts.py
+++ b/profiles/base/accounts/display-accts.py
@@ -115,7 +115,28 @@
 
   This does not check for syntax/etc... errors on a per-account basis as the
   main _ParseAccount function above took care of that.
+
+  Args:
+    groups: A list of Group objects.
+    users: A list of User objects.
+
+  Returns:
+    True if everything is consistent.
   """
+  ret = True
+
+  gid_counts = collections.Counter(x.gid for x in groups)
+  for gid in [k for k, v in gid_counts.items() if v > 1]:
+    ret = False
+    dupes = ', '.join(x.group for x in groups if x.gid == gid)
+    print('error: duplicate gid found: %s: %s' % (gid, dupes), file=sys.stderr)
+
+  uid_counts = collections.Counter(x.uid for x in users)
+  for uid in [k for k, v in uid_counts.items() if v > 1]:
+    ret = False
+    dupes = ', '.join(x.user for x in users if x.uid == uid)
+    print('error: duplicate uid found: %s: %s' % (uid, dupes), file=sys.stderr)
+
   found_users = set(x.user for x in users)
   want_users = set()
   for group in groups:
@@ -124,6 +145,7 @@
 
   missing_users = want_users - found_users
   if missing_users:
+    ret = False
     print('error: group lists unknown users', file=sys.stderr)
     for group in groups:
       for user in missing_users:
@@ -131,7 +153,7 @@
           print('error: group "%s" wants missing user "%s"' %
                 (group.group, user), file=sys.stderr)
 
-  return not bool(missing_users)
+  return ret
 
 
 def GetParser():
diff --git a/profiles/base/accounts/group/adb b/profiles/base/accounts/group/adb
index 371511e..39338c8 100644
--- a/profiles/base/accounts/group/adb
+++ b/profiles/base/accounts/group/adb
@@ -1,3 +1,3 @@
 group:adb
-gid:269
+gid:272
 users:adb
diff --git a/profiles/base/accounts/user/adb b/profiles/base/accounts/user/adb
index 91a7a53..9e2d982 100644
--- a/profiles/base/accounts/user/adb
+++ b/profiles/base/accounts/user/adb
@@ -1,6 +1,6 @@
 user:adb
-uid:269
-gid:269
+uid:272
+gid:272
 password:x
 gecos:Android Debug Bridge User
 home:/home/adb