Commit 851d312 NSS: Add InvalidateGroupById handler

4 files Authored and Committed by fidencio 4 months ago
NSS: Add InvalidateGroupById handler

There are some situations where, from the backend, the NSS responder
will have to be notified to invalidate a group.

In order to achieve this in a clean way, let's add the
InvalidateGroupById handler and make use of it later in this very same
series.

Related:
https://pagure.io/SSSD/sssd/issue/2653

Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>

    
 1 @@ -199,12 +199,28 @@
 2       return iface_nss_memorycache_UpdateInitgroups_finish(sbus_req);
 3   }
 4   
 5 + int nss_memorycache_invalidate_group_by_id(struct sbus_request *sbus_req,
 6 +                                            void *data,
 7 +                                            gid_t gid)
 8 + {
 9 +     struct resp_ctx *rctx = talloc_get_type(data, struct resp_ctx);
10 +     struct nss_ctx *nctx = talloc_get_type(rctx->pvt_ctx, struct nss_ctx);
11 + 
12 +     DEBUG(SSSDBG_TRACE_LIBS,
13 +           "Invalidating group %"PRIu32" from memory cache\n", gid);
14 + 
15 +     sss_mmap_cache_gr_invalidate_gid(nctx->grp_mc_ctx, gid);
16 + 
17 +     return iface_nss_memorycache_InvalidateGroupById_finish(sbus_req);
18 + }
19 + 
20   struct iface_nss_memorycache iface_nss_memorycache = {
21       { &iface_nss_memorycache_meta, 0 },
22       .UpdateInitgroups = nss_memorycache_update_initgroups,
23       .InvalidateAllUsers = nss_memorycache_invalidate_users,
24       .InvalidateAllGroups = nss_memorycache_invalidate_groups,
25       .InvalidateAllInitgroups = nss_memorycache_invalidate_initgroups,
26 +     .InvalidateGroupById = nss_memorycache_invalidate_group_by_id,
27   };
28   
29   static struct sbus_iface_map iface_map[] = {
1 @@ -14,5 +14,8 @@
2           </method>
3           <method name="InvalidateAllInitgroups">
4           </method>
5 +         <method name="InvalidateGroupById">
6 +             <arg name="gid" type="u" direction="in" />
7 +         </method>
8       </interface>
9   </node>
 1 @@ -12,6 +12,9 @@
 2   /* invokes a handler with a 'ssau' DBus signature */
 3   static int invoke_ssau_method(struct sbus_request *dbus_req, void *function_ptr);
 4   
 5 + /* invokes a handler with a 'u' DBus signature */
 6 + static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr);
 7 + 
 8   /* arguments for org.freedesktop.sssd.nss.MemoryCache.UpdateInitgroups */
 9   const struct sbus_arg_meta iface_nss_memorycache_UpdateInitgroups__in[] = {
10       { "user", "s" },
11 @@ -44,6 +47,18 @@
12                                            DBUS_TYPE_INVALID);
13   }
14   
15 + /* arguments for org.freedesktop.sssd.nss.MemoryCache.InvalidateGroupById */
16 + const struct sbus_arg_meta iface_nss_memorycache_InvalidateGroupById__in[] = {
17 +     { "gid", "u" },
18 +     { NULL, }
19 + };
20 + 
21 + int iface_nss_memorycache_InvalidateGroupById_finish(struct sbus_request *req)
22 + {
23 +    return sbus_request_return_and_finish(req,
24 +                                          DBUS_TYPE_INVALID);
25 + }
26 + 
27   /* methods for org.freedesktop.sssd.nss.MemoryCache */
28   const struct sbus_method_meta iface_nss_memorycache__methods[] = {
29       {
30 @@ -74,6 +89,13 @@
31           offsetof(struct iface_nss_memorycache, InvalidateAllInitgroups),
32           NULL, /* no invoker */
33       },
34 +     {
35 +         "InvalidateGroupById", /* name */
36 +         iface_nss_memorycache_InvalidateGroupById__in,
37 +         NULL, /* no out_args */
38 +         offsetof(struct iface_nss_memorycache, InvalidateGroupById),
39 +         invoke_u_method,
40 +     },
41       { NULL, }
42   };
43   
44 @@ -86,6 +108,22 @@
45       sbus_invoke_get_all, /* GetAll invoker */
46   };
47   
48 + /* invokes a handler with a 'u' DBus signature */
49 + static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr)
50 + {
51 +     uint32_t arg_0;
52 +     int (*handler)(struct sbus_request *, void *, uint32_t) = function_ptr;
53 + 
54 +     if (!sbus_request_parse_or_finish(dbus_req,
55 +                                DBUS_TYPE_UINT32, &arg_0,
56 +                                DBUS_TYPE_INVALID)) {
57 +          return EOK; /* request handled */
58 +     }
59 + 
60 +     return (handler)(dbus_req, dbus_req->intf->handler_data,
61 +                      arg_0);
62 + }
63 + 
64   /* invokes a handler with a 'ssau' DBus signature */
65   static int invoke_ssau_method(struct sbus_request *dbus_req, void *function_ptr)
66   {
 1 @@ -18,6 +18,7 @@
 2   #define IFACE_NSS_MEMORYCACHE_INVALIDATEALLUSERS "InvalidateAllUsers"
 3   #define IFACE_NSS_MEMORYCACHE_INVALIDATEALLGROUPS "InvalidateAllGroups"
 4   #define IFACE_NSS_MEMORYCACHE_INVALIDATEALLINITGROUPS "InvalidateAllInitgroups"
 5 + #define IFACE_NSS_MEMORYCACHE_INVALIDATEGROUPBYID "InvalidateGroupById"
 6   
 7   /* ------------------------------------------------------------------------
 8    * DBus handlers
 9 @@ -44,6 +45,7 @@
10       int (*InvalidateAllUsers)(struct sbus_request *req, void *data);
11       int (*InvalidateAllGroups)(struct sbus_request *req, void *data);
12       int (*InvalidateAllInitgroups)(struct sbus_request *req, void *data);
13 +     int (*InvalidateGroupById)(struct sbus_request *req, void *data, uint32_t arg_gid);
14   };
15   
16   /* finish function for UpdateInitgroups */
17 @@ -58,6 +60,9 @@
18   /* finish function for InvalidateAllInitgroups */
19   int iface_nss_memorycache_InvalidateAllInitgroups_finish(struct sbus_request *req);
20   
21 + /* finish function for InvalidateGroupById */
22 + int iface_nss_memorycache_InvalidateGroupById_finish(struct sbus_request *req);
23 + 
24   /* ------------------------------------------------------------------------
25    * DBus Interface Metadata
26    *