Commit c9a73bb IFP: Use sized_domain_name to format the groups the user is a member of

1 file Authored and Committed by jhrozek 5 months ago
IFP: Use sized_domain_name to format the groups the user is a member of

Resolves:
    https://pagure.io/SSSD/sssd/issue/3268

Uses the common function sized_domain_name() to format a group the user
is a member of to the appropriate format.

To see the code is working correctly, run:
        dbus-send --system --print-reply --dest=org.freedesktop.sssd.infopipe
                  /org/freedesktop/sssd/infopipe
                  org.freedesktop.sssd.infopipe.GetUserGroups
                  string:trusted_user

Where trusted_user is a user from a trusted domain that is a member of groups
from the joined domain and a trusted domain as well. The groups from the
joined domain should not be qualified, the groups from the trusted
domain should be qualified.

Reviewed-by: Pavel Březina <pbrezina@redhat.com>

    
 1 @@ -369,10 +369,11 @@
 2                             struct ifp_req *ireq,
 3                             struct ldb_result *res)
 4   {
 5 -     int i, num;
 6 +     int i, gri, num;
 7       const char *name;
 8       const char **groupnames;
 9 -     char *out_name;
10 +     struct sized_string *group_name;
11 +     errno_t ret;
12   
13       /* one less, the first one is the user entry */
14       num = res->count - 1;
15 @@ -381,6 +382,7 @@
16           return sbus_request_finish(ireq->dbus_req, NULL);
17       }
18   
19 +     gri = 0;
20       for (i = 0; i < num; i++) {
21           name = sss_view_ldb_msg_find_attr_as_string(domain,
22                                                       res->msgs[i + 1],
23 @@ -390,22 +392,21 @@
24               continue;
25           }
26   
27 -         out_name = sss_output_name(ireq, name, domain->case_preserve,
28 -                                    ireq->ifp_ctx->rctx->override_space);
29 -         if (out_name == NULL) {
30 +         ret = sized_domain_name(ireq, ireq->ifp_ctx->rctx, name, &group_name);
31 +         if (ret != EOK) {
32 +             DEBUG(SSSDBG_MINOR_FAILURE,
33 +                   "Unable to get sized name for %s [%d]: %s\n",
34 +                   name, ret, sss_strerror(ret));
35               continue;
36           }
37   
38 -         if (domain->fqnames) {
39 -             groupnames[i] = sss_tc_fqname(groupnames, domain->names,
40 -                                           domain, out_name);
41 -             if (out_name == NULL) {
42 -                 DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
43 -                 continue;
44 -             }
45 -         } else {
46 -             groupnames[i] = talloc_steal(groupnames, out_name);
47 +         groupnames[gri] = talloc_strndup(groupnames,
48 +                                          group_name->str, group_name->len);
49 +         if (groupnames[gri] == NULL) {
50 +             DEBUG(SSSDBG_MINOR_FAILURE, "talloc_strndup failed\n");
51 +             continue;
52           }
53 +         gri++;
54   
55           DEBUG(SSSDBG_TRACE_FUNC, "Adding group %s\n", groupnames[i]);
56       }