]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:winbind: Add wbint_LookupAliasMembers to winbind interface
authorPavel Filipenský <pfilipensky@samba.org>
Wed, 29 Mar 2023 12:53:14 +0000 (14:53 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 13 Jun 2023 12:15:32 +0000 (12:15 +0000)
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
librpc/idl/winbind.idl
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_dual_srv.c
source3/winbindd/winbindd_proto.h

index de8fbc75c233d1ae37ab5cd1f02fd62fef83fbed..50e36884129cd1c7897677cb4fea726bcd60ef73 100644 (file)
@@ -130,6 +130,12 @@ interface winbind
        [out] wbint_Principals *members
        );
 
+    NTSTATUS wbint_LookupAliasMembers(
+       [in] dom_sid *sid,
+       [in] lsa_SidType type,
+       [out] wbint_SidArray *sids
+       );
+
     typedef [public] struct {
        uint32 num_userinfos;
        [size_is(num_userinfos)] wbint_userinfo userinfos[];
index 9804bfc7d5daecd43d94e304fe14174fd1313deb..3692965270877eb831e9f0c0ecd686beb55240c0 100644 (file)
@@ -2560,6 +2560,130 @@ NTSTATUS wb_cache_lookup_useraliases(struct winbindd_domain *domain,
        return status;
 }
 
+static NTSTATUS wcache_lookup_aliasmem(struct winbindd_domain *domain,
+                                      TALLOC_CTX *mem_ctx,
+                                      const struct dom_sid *group_sid,
+                                      uint32_t *num_names,
+                                      struct dom_sid **sid_mem)
+{
+       struct winbind_cache *cache = get_cache(domain);
+       struct cache_entry *centry = NULL;
+       NTSTATUS status;
+       unsigned int i;
+       struct dom_sid_buf sid_string;
+
+       if (cache->tdb == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
+
+       centry = wcache_fetch(cache,
+                             domain,
+                             "AM/%s",
+                             dom_sid_str_buf(group_sid, &sid_string));
+       if (centry == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
+
+       *sid_mem = NULL;
+
+       *num_names = centry_uint32(centry);
+       if (*num_names == 0) {
+               centry_free(centry);
+               return NT_STATUS_OK;
+       }
+
+       *sid_mem = talloc_array(mem_ctx, struct dom_sid, *num_names);
+       if (*sid_mem == NULL) {
+               TALLOC_FREE(*sid_mem);
+               centry_free(centry);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       for (i = 0; i < (*num_names); i++) {
+               centry_sid(centry, &(*sid_mem)[i]);
+       }
+
+       status = centry->status;
+
+       D_DEBUG("[Cached] - cached info for domain %s "
+               "status: %s\n",
+               domain->name,
+               nt_errstr(status));
+
+       centry_free(centry);
+       return status;
+}
+
+NTSTATUS wb_cache_lookup_aliasmem(struct winbindd_domain *domain,
+                                 TALLOC_CTX *mem_ctx,
+                                 const struct dom_sid *group_sid,
+                                 enum lsa_SidType type,
+                                 uint32_t *num_sids,
+                                 struct dom_sid **sid_mem)
+{
+       struct cache_entry *centry = NULL;
+       NTSTATUS status;
+       unsigned int i;
+       struct dom_sid_buf sid_string;
+       bool old_status;
+
+       old_status = domain->online;
+       status = wcache_lookup_aliasmem(domain,
+                                       mem_ctx,
+                                       group_sid,
+                                       num_sids,
+                                       sid_mem);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               return status;
+       }
+
+       (*num_sids) = 0;
+       (*sid_mem) = NULL;
+
+       D_DEBUG("[Cached] - doing backend query for info for domain %s\n",
+               domain->name);
+
+       status = domain->backend->lookup_aliasmem(domain,
+                                                 mem_ctx,
+                                                 group_sid,
+                                                 type,
+                                                 num_sids,
+                                                 sid_mem);
+
+       if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) ||
+           NT_STATUS_EQUAL(status, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND)) {
+               if (!domain->internal && old_status) {
+                       set_domain_offline(domain);
+               }
+               if (!domain->internal && !domain->online && old_status) {
+                       NTSTATUS cache_status;
+                       cache_status = wcache_lookup_aliasmem(domain,
+                                                             mem_ctx,
+                                                             group_sid,
+                                                             num_sids,
+                                                             sid_mem);
+                       return cache_status;
+               }
+       }
+       /* and save it */
+       refresh_sequence_number(domain);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       centry = centry_start(domain, status);
+       if (!centry)
+               goto skip_save;
+       centry_put_uint32(centry, *num_sids);
+       for (i = 0; i < (*num_sids); i++) {
+               centry_put_sid(centry, &(*sid_mem)[i]);
+       }
+       centry_end(centry, "AM/%s", dom_sid_str_buf(group_sid, &sid_string));
+       centry_free(centry);
+
+skip_save:
+       return status;
+}
+
 static NTSTATUS wcache_lookup_groupmem(struct winbindd_domain *domain,
                                       TALLOC_CTX *mem_ctx,
                                       const struct dom_sid *group_sid,
index 2272a8b80a85bf7fc96c45850c67cc928328a77f..ab0eb6c44cffae01f808fc9b696f2a5567c9b7a3 100644 (file)
@@ -486,6 +486,29 @@ NTSTATUS _wbint_LookupGroupMembers(struct pipes_struct *p,
        return NT_STATUS_OK;
 }
 
+NTSTATUS _wbint_LookupAliasMembers(struct pipes_struct *p,
+                                  struct wbint_LookupAliasMembers *r)
+{
+       struct winbindd_domain *domain = wb_child_domain();
+       NTSTATUS status;
+
+       if (domain == NULL) {
+               return NT_STATUS_REQUEST_NOT_ACCEPTED;
+       }
+       status = wb_cache_lookup_aliasmem(domain,
+                                         p->mem_ctx,
+                                         r->in.sid,
+                                         r->in.type,
+                                         &r->out.sids->num_sids,
+                                         &r->out.sids->sids);
+       reset_cm_connection_on_error(domain, NULL, status);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
 NTSTATUS _wbint_QueryGroupList(struct pipes_struct *p,
                               struct wbint_QueryGroupList *r)
 {
index 384d2ad776fe463728107e60e239c7adcd52f894..ba54558e7ff4bc1a80bf7ab4ba3e46d20b2c60a2 100644 (file)
@@ -106,6 +106,12 @@ NTSTATUS wb_cache_lookup_groupmem(struct winbindd_domain *domain,
                                  struct dom_sid **sid_mem,
                                  char ***names,
                                  uint32_t **name_types);
+NTSTATUS wb_cache_lookup_aliasmem(struct winbindd_domain *domain,
+                                 TALLOC_CTX *mem_ctx,
+                                 const struct dom_sid *group_sid,
+                                 enum lsa_SidType type,
+                                 uint32_t *num_names,
+                                 struct dom_sid **sid_mem);
 NTSTATUS wb_cache_sequence_number(struct winbindd_domain *domain,
                                  uint32_t *seq);
 NTSTATUS wb_cache_lockout_policy(struct winbindd_domain *domain,