Hack: always look in /etc/passwd when generating user list 19/189519/1 accepted/tizen_5.0_unified accepted/tizen/5.0/unified/20181102.024648 accepted/tizen/unified/20180918.152344 submit/tizen/20180918.101339 submit/tizen_5.0/20181101.000006
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 18 Sep 2018 08:53:16 +0000 (10:53 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 18 Sep 2018 08:56:22 +0000 (10:56 +0200)
Change-Id: I6c5947c5d67553f0e55ab8b7c506c801da67a9f4

src/daemon/core/gumd-daemon-user.c

index d84ac84..efbabd6 100755 (executable)
@@ -2164,9 +2164,13 @@ gumd_daemon_user_get_user_list (
                 "Database already locked", error, NULL);
     }
 
+    FILE *fpasswd = fopen("/etc/passwd", "r");
+
     fn = gum_config_get_string (config, GUM_CONFIG_GENERAL_PASSWD_FILE);
-    if (!fn || !(fp = fopen (fn, "r"))) {
+    if (!fn || !fpasswd || !(fp = fopen (fn, "r"))) {
         gum_lock_pwdf_unlock ();
+       if (fpasswd)
+            fclose (fpasswd);
         GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_OPEN,
                 "Opening passwd file failed", error, NULL);
     }
@@ -2178,25 +2182,31 @@ gumd_daemon_user_get_user_list (
             GUM_CONFIG_GENERAL_SYS_UID_MAX, GUM_USER_INVALID_UID);
 
     g_variant_builder_init (&builder, (const GVariantType *)"au");
-    while ((pent = fgetpwent (fp)) != NULL) {
-        /* If type is an empty string, all users are fetched. User type is
-         * first compared with usertype in gecos field. If gecos field for
-         * usertype does not exist, then all the users are considered as
-         * normal users other than system users which are filtered out based
-         * on system min and max uids
-         * */
-        ut = _get_usertype_from_gecos (pent);
-        if (ut == GUM_USERTYPE_NONE) {
-            if (pent->pw_uid >=sys_uid_min && pent->pw_uid <= sys_uid_max)
-                ut = GUM_USERTYPE_SYSTEM;
-        }
-        if (ut & in_types) {
-            g_variant_builder_add (&builder, "u", pent->pw_uid);
-        }
-        pent = NULL;
+
+    FILE *fparr[] = {fpasswd, fp};
+    for (int i = 0; i < G_N_ELEMENTS(fparr); i++) {
+        while ((pent = fgetpwent (fparr[i])) != NULL) {
+             /* If type is an empty string, all users are fetched. User type is
+              * first compared with usertype in gecos field. If gecos field for
+              * usertype does not exist, then all the users are considered as
+              * normal users other than system users which are filtered out based
+              * on system min and max uids
+              * */
+             ut = _get_usertype_from_gecos (pent);
+             if (ut == GUM_USERTYPE_NONE) {
+                  if (pent->pw_uid >=sys_uid_min && pent->pw_uid <= sys_uid_max)
+                       ut = GUM_USERTYPE_SYSTEM;
+             }
+             if (ut & in_types) {
+                  g_variant_builder_add (&builder, "u", pent->pw_uid);
+             }
+             pent = NULL;
+        }
     }
+
     users = g_variant_builder_end (&builder);
     fclose (fp);
+    fclose (fpasswd);
 
     gum_lock_pwdf_unlock ();
     return users;