Commit da18da90 authored by Ivan Savin's avatar Ivan Savin
Browse files

Refactoring of the code.

Reduced the number of nested blocks
in the add_to_user_identities_user_of_subject () function.
parent 4ccf3283
Pipeline #248303 passed with stage
in 1 minute and 42 seconds
......@@ -2307,48 +2307,56 @@ addition_to_user_identities_user_of_subject (PolkitIdentity *user_of_subject
}
/* Check if the user_of_subject is a member of groups with the required privileges. */
if (unix_groups != NULL)
if (unix_groups == NULL)
{
uid_t uid = polkit_unix_user_get_uid (POLKIT_UNIX_USER (user_of_subject));
struct passwd *passwd = getpwuid (uid);
if (passwd != NULL)
return;
}
uid_t uid = polkit_unix_user_get_uid (POLKIT_UNIX_USER (user_of_subject));
struct passwd *passwd = getpwuid (uid);
if (passwd == NULL)
{
return;
}
gid_t gids[512];
int num_gids = 512;
if (getgrouplist (passwd->pw_name,
passwd->pw_gid,
gids,
&num_gids) >= 0)
{
gint n;
for (n = 0; n < num_gids; n++)
{
gid_t gids[512];
int num_gids = 512;
struct group *group;
group = getgrgid (gids[n]);
if (getgrouplist (passwd->pw_name,
passwd->pw_gid,
gids,
&num_gids) >= 0)
if (group == NULL)
{
gint n;
for (n = 0; n < num_gids; n++)
continue;
}
for (l = unix_groups; l != NULL; l = l->next)
{
PolkitIdentity *identity = POLKIT_IDENTITY (l->data);
if (POLKIT_IS_UNIX_GROUP (identity))
{
struct group *group;
group = getgrgid (gids[n]);
if (group != NULL)
{
for (l = unix_groups; l != NULL; l = l->next)
{
PolkitIdentity *identity = POLKIT_IDENTITY (l->data);
gid_t gid = polkit_unix_group_get_gid (POLKIT_UNIX_GROUP (identity));
if (POLKIT_IS_UNIX_GROUP (identity))
{
gid_t gid = polkit_unix_group_get_gid (POLKIT_UNIX_GROUP (identity));
if (gid == group->gr_gid)
{
/* Add user_of_subject to the list */
user_identities = g_list_append (user_identities, g_object_ref (user_of_subject));
return;
}
}
} // for # 2
} // if (group != NULL)
} // for # 1
} // getgrouplist
} // passwd != NULL
} // unix_groups != NULL
if (gid == group->gr_gid)
{
/* Add user_of_subject to the list */
user_identities = g_list_append (user_identities, g_object_ref (user_of_subject));
return;
}
}
} // for # 2
} // for # 1
} // getgrouplist
}
/* ---------------------------------------------------------------------------------------------------- */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment