The branch, master has been updated
       via  6296c32 Re-enable token groups fallback
       via  76d9483 winbindd: find the domain based on the sid within 
wb_lookupusergroups_send()
       via  1a12cfb Revert "winbind: Remove wb_lookupusergroups"
       via  a34c0a8 Revert "winbind: Remove wbint_LookupUserGroups"
       via  55321a3 Revert "winbind: Remove wb_cache_lookup_usergroups"
       via  52105eb Revert "winbind: Remove wcache_lookup_usergroups"
       via  174b14b Revert "winbind: Remove validate_ug"
       via  3f5fa7c Revert "winbind: Remove "lookup_usergroups" winbind method"
       via  8fafdad Revert "winbind: Remove rpc_lookup_usergroups"
      from  bdce9f5 s3:libads: remove unused fallback to gss_acquire_cred()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 6296c32668af60118ae7059772d2f70e58e1f0d1
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 15:14:51 2017 +0100

    Re-enable token groups fallback
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>
    
    Autobuild-User(master): Ralph Böhme <[email protected]>
    Autobuild-Date(master): Mon Mar  6 19:18:31 CET 2017 on sn-devel-144

commit 76d94838049b77555cdf7dad2d15692cb18b4dab
Author: Stefan Metzmacher <[email protected]>
Date:   Mon Mar 6 10:30:52 2017 +0100

    winbindd: find the domain based on the sid within wb_lookupusergroups_send()
    
    That simplifies the potential caller.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 1a12cfbf1fbcb3542d9799236ed1a9290550ccc1
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:56:09 2017 +0100

    Revert "winbind: Remove wb_lookupusergroups"
    
    This reverts commit c0570e6ae8f8f0057ece48d764580897ff2b6f62.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit a34c0a8638556ddcb8fa30cb5a311330e3f0bbc0
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:55:15 2017 +0100

    Revert "winbind: Remove wbint_LookupUserGroups"
    
    This reverts commit 256632ed3cc724bab0fc22132ca6b52faf680ab2.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 55321a39bbb481eac82d4439a3874567bfb0b229
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:54:46 2017 +0100

    Revert "winbind: Remove wb_cache_lookup_usergroups"
    
    This reverts commit f83863b4d1510a9519d15934c960fd1675235812.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 52105ebaa82a4a4e0a48dd93c9419c5fd91561a4
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:54:23 2017 +0100

    Revert "winbind: Remove wcache_lookup_usergroups"
    
    This reverts commit 876dc28b9cf13343a2962b1a1b035fe78c1858a6.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 174b14b5aa8fbff4732a2213494a870aee1c7569
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:54:09 2017 +0100

    Revert "winbind: Remove validate_ug"
    
    This reverts commit 3f58a8cabab75a594cff9088d5dd8ea439b36178.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 3f5fa7c458dbc673b35827bb588e424cd14332c7
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:53:47 2017 +0100

    Revert "winbind: Remove "lookup_usergroups" winbind method"
    
    This reverts commit b231814c6b0ad17255139bc8934f269610348b2b.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 8fafdada52f76ccc5e56ce1a736d4ca9815b387b
Author: Volker Lendecke <[email protected]>
Date:   Thu Mar 2 14:52:49 2017 +0100

    Revert "winbind: Remove rpc_lookup_usergroups"
    
    This reverts commit 91b73b1e93bb8fb38e2f1cea6c1cbd012c952542.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12612
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 librpc/idl/winbind.idl                    |   5 +
 source3/winbindd/wb_gettoken.c            |  28 ++-
 source3/winbindd/wb_lookupusergroups.c    | 106 +++++++++
 source3/winbindd/winbindd.h               |   8 +
 source3/winbindd/winbindd_ads.c           | 377 ++++++++++++++++++++++++++++++
 source3/winbindd/winbindd_cache.c         | 162 +++++++++++++
 source3/winbindd/winbindd_dual_srv.c      |  17 ++
 source3/winbindd/winbindd_msrpc.c         |  72 ++++++
 source3/winbindd/winbindd_proto.h         |  15 ++
 source3/winbindd/winbindd_reconnect.c     |  21 ++
 source3/winbindd/winbindd_reconnect_ads.c |  22 ++
 source3/winbindd/winbindd_rpc.c           |  74 ++++++
 source3/winbindd/winbindd_rpc.h           |   9 +
 source3/winbindd/winbindd_samr.c          |  65 ++++++
 source3/winbindd/wscript_build            |   1 +
 15 files changed, 975 insertions(+), 7 deletions(-)
 create mode 100644 source3/winbindd/wb_lookupusergroups.c


Changeset truncated at 500 lines:

diff --git a/librpc/idl/winbind.idl b/librpc/idl/winbind.idl
index 6245e13..05db6b9 100644
--- a/librpc/idl/winbind.idl
+++ b/librpc/idl/winbind.idl
@@ -103,6 +103,11 @@ interface winbind
        [out] wbint_RidArray *rids
        );
 
+    NTSTATUS wbint_LookupUserGroups(
+       [in] dom_sid *sid,
+       [out] wbint_SidArray *sids
+       );
+
     NTSTATUS wbint_QuerySequenceNumber(
        [out] uint32 *sequence
        );
diff --git a/source3/winbindd/wb_gettoken.c b/source3/winbindd/wb_gettoken.c
index 07c7fc7..a393b0f 100644
--- a/source3/winbindd/wb_gettoken.c
+++ b/source3/winbindd/wb_gettoken.c
@@ -38,6 +38,7 @@ static NTSTATUS wb_add_rids_to_sids(TALLOC_CTX *mem_ctx,
                                    int num_rids, uint32_t *rids);
 
 static void wb_gettoken_gotuser(struct tevent_req *subreq);
+static void wb_gettoken_gotgroups(struct tevent_req *subreq);
 static void wb_gettoken_gotlocalgroups(struct tevent_req *subreq);
 static void wb_gettoken_gotbuiltins(struct tevent_req *subreq);
 
@@ -71,10 +72,7 @@ static void wb_gettoken_gotuser(struct tevent_req *subreq)
                subreq, struct tevent_req);
        struct wb_gettoken_state *state = tevent_req_data(
                req, struct wb_gettoken_state);
-       struct winbindd_domain *domain;
        struct wbint_userinfo *info;
-       uint32_t i, num_groups;
-       struct dom_sid *groups;
        NTSTATUS status;
 
        status = wb_queryuser_recv(subreq, state, &info);
@@ -92,11 +90,27 @@ static void wb_gettoken_gotuser(struct tevent_req *subreq)
        sid_copy(&state->sids[0], &info->user_sid);
        sid_copy(&state->sids[1], &info->group_sid);
 
-       status = lookup_usergroups_cached(
-               state, &info->user_sid, &num_groups, &groups);
+       subreq = wb_lookupusergroups_send(state, state->ev, &info->user_sid);
+       if (tevent_req_nomem(subreq, req)) {
+               return;
+       }
+       tevent_req_set_callback(subreq, wb_gettoken_gotgroups, req);
+}
+
+static void wb_gettoken_gotgroups(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct wb_gettoken_state *state = tevent_req_data(
+               req, struct wb_gettoken_state);
+       int i, num_groups;
+       struct dom_sid *groups;
+       struct winbindd_domain *domain;
+       NTSTATUS status;
+
+       status = wb_lookupusergroups_recv(subreq, state, &num_groups, &groups);
+       TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("lookup_usergroups_cached failed (%s), not doing "
-                         "supplementary group lookups\n", nt_errstr(status));
                tevent_req_done(req);
                return;
        }
diff --git a/source3/winbindd/wb_lookupusergroups.c 
b/source3/winbindd/wb_lookupusergroups.c
new file mode 100644
index 0000000..7647fbd
--- /dev/null
+++ b/source3/winbindd/wb_lookupusergroups.c
@@ -0,0 +1,106 @@
+/*
+   Unix SMB/CIFS implementation.
+   async lookupusergroups
+   Copyright (C) Volker Lendecke 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+#include "librpc/gen_ndr/ndr_winbind_c.h"
+#include "../libcli/security/security.h"
+
+struct wb_lookupusergroups_state {
+       struct tevent_context *ev;
+       struct dom_sid sid;
+       struct wbint_SidArray sids;
+};
+
+static void wb_lookupusergroups_done(struct tevent_req *subreq);
+
+struct tevent_req *wb_lookupusergroups_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           const struct dom_sid *sid)
+{
+       struct tevent_req *req, *subreq;
+       struct wb_lookupusergroups_state *state;
+       struct winbindd_domain *domain;
+       NTSTATUS status;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct wb_lookupusergroups_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       sid_copy(&state->sid, sid);
+
+       status = lookup_usergroups_cached(state,
+                                         &state->sid,
+                                         &state->sids.num_sids,
+                                         &state->sids.sids);
+       if (NT_STATUS_IS_OK(status)) {
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
+       }
+
+       domain = find_domain_from_sid_noinit(&state->sid);
+       if (domain == NULL) {
+               char buf[DOM_SID_STR_BUFLEN];
+               dom_sid_string_buf(&state->sid, buf, sizeof(buf));
+               DEBUG(1,("could not find domain entry for sid %s\n", buf));
+               tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
+               return tevent_req_post(req, ev);
+       }
+
+       subreq = dcerpc_wbint_LookupUserGroups_send(
+               state, ev, dom_child_handle(domain), &state->sid, &state->sids);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, wb_lookupusergroups_done, req);
+       return req;
+}
+
+static void wb_lookupusergroups_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct wb_lookupusergroups_state *state = tevent_req_data(
+               req, struct wb_lookupusergroups_state);
+       NTSTATUS status, result;
+
+       status = dcerpc_wbint_LookupUserGroups_recv(subreq, state, &result);
+       TALLOC_FREE(subreq);
+       if (any_nt_status_not_ok(status, result, &status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS wb_lookupusergroups_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                 int *num_sids, struct dom_sid **sids)
+{
+       struct wb_lookupusergroups_state *state = tevent_req_data(
+               req, struct wb_lookupusergroups_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       *num_sids = state->sids.num_sids;
+       *sids = talloc_move(mem_ctx, &state->sids.sids);
+       return NT_STATUS_OK;
+}
diff --git a/source3/winbindd/winbindd.h b/source3/winbindd/winbindd.h
index 0f95703..c220573 100644
--- a/source3/winbindd/winbindd.h
+++ b/source3/winbindd/winbindd.h
@@ -262,6 +262,14 @@ struct winbindd_methods {
                                  char ***names,
                                  enum lsa_SidType **types);
 
+       /* lookup all groups that a user is a member of. The backend
+          can also choose to lookup by username or rid for this
+          function */
+       NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
+                                     TALLOC_CTX *mem_ctx,
+                                     const struct dom_sid *user_sid,
+                                     uint32_t *num_groups, struct dom_sid 
**user_gids);
+
        /* Lookup all aliases that the sids delivered are member of. This is
         * to implement 'domain local groups' correctly */
        NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
index cde9099..d2e1ac4 100644
--- a/source3/winbindd/winbindd_ads.c
+++ b/source3/winbindd/winbindd_ads.c
@@ -574,6 +574,382 @@ static NTSTATUS rids_to_names(struct winbindd_domain 
*domain,
                                           domain_name, names, types);
 }
 
+/* Lookup groups a user is a member of - alternate method, for when
+   tokenGroups are not available. */
+static NTSTATUS lookup_usergroups_member(struct winbindd_domain *domain,
+                                        TALLOC_CTX *mem_ctx,
+                                        const char *user_dn, 
+                                        struct dom_sid *primary_group,
+                                        uint32_t *p_num_groups, struct dom_sid 
**user_sids)
+{
+       ADS_STATUS rc;
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       int count;
+       LDAPMessage *res = NULL;
+       LDAPMessage *msg = NULL;
+       char *ldap_exp;
+       ADS_STRUCT *ads;
+       const char *group_attrs[] = {"objectSid", NULL};
+       char *escaped_dn;
+       uint32_t num_groups = 0;
+
+       DEBUG(3,("ads: lookup_usergroups_member\n"));
+
+       if ( !winbindd_can_contact_domain( domain ) ) {
+               DEBUG(10,("lookup_usergroups_members: No incoming trust for 
domain %s\n",
+                         domain->name));               
+               return NT_STATUS_OK;
+       }
+
+       ads = ads_cached_connection(domain);
+
+       if (!ads) {
+               domain->last_status = NT_STATUS_SERVER_DISABLED;
+               goto done;
+       }
+
+       if (!(escaped_dn = escape_ldap_string(talloc_tos(), user_dn))) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       ldap_exp = talloc_asprintf(mem_ctx,
+               "(&(member=%s)(objectCategory=group)(groupType:dn:%s:=%d))",
+               escaped_dn,
+               ADS_LDAP_MATCHING_RULE_BIT_AND,
+               GROUP_TYPE_SECURITY_ENABLED);
+       if (!ldap_exp) {
+               DEBUG(1,("lookup_usergroups(dn=%s) asprintf failed!\n", 
user_dn));
+               TALLOC_FREE(escaped_dn);
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       TALLOC_FREE(escaped_dn);
+
+       rc = ads_search_retry(ads, &res, ldap_exp, group_attrs);
+
+       if (!ADS_ERR_OK(rc)) {
+               DEBUG(1,("lookup_usergroups ads_search member=%s: %s\n", 
user_dn, ads_errstr(rc)));
+               return ads_ntstatus(rc);
+       } else if (!res) {
+               DEBUG(1,("lookup_usergroups ads_search returned NULL res\n"));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+
+       count = ads_count_replies(ads, res);
+
+       *user_sids = NULL;
+       num_groups = 0;
+
+       /* always add the primary group to the sid array */
+       status = add_sid_to_array(mem_ctx, primary_group, user_sids,
+                                 &num_groups);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       if (count > 0) {
+               for (msg = ads_first_entry(ads, res); msg;
+                    msg = ads_next_entry(ads, msg)) {
+                       struct dom_sid group_sid;
+
+                       if (!ads_pull_sid(ads, msg, "objectSid", &group_sid)) {
+                               DEBUG(1,("No sid for this group ?!?\n"));
+                               continue;
+                       }
+
+                       /* ignore Builtin groups from ADS - Guenther */
+                       if (sid_check_is_in_builtin(&group_sid)) {
+                               continue;
+                       }
+
+                       status = add_sid_to_array(mem_ctx, &group_sid,
+                                                 user_sids, &num_groups);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               goto done;
+                       }
+               }
+
+       }
+
+       *p_num_groups = num_groups;
+       status = (user_sids != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
+
+       DEBUG(3,("ads lookup_usergroups (member) succeeded for dn=%s\n", 
user_dn));
+done:
+       if (res) 
+               ads_msgfree(ads, res);
+
+       return status;
+}
+
+/* Lookup groups a user is a member of - alternate method, for when
+   tokenGroups are not available. */
+static NTSTATUS lookup_usergroups_memberof(struct winbindd_domain *domain,
+                                          TALLOC_CTX *mem_ctx,
+                                          const char *user_dn,
+                                          struct dom_sid *primary_group,
+                                          uint32_t *p_num_groups,
+                                          struct dom_sid **user_sids)
+{
+       ADS_STATUS rc;
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       ADS_STRUCT *ads;
+       const char *attrs[] = {"memberOf", NULL};
+       uint32_t num_groups = 0;
+       struct dom_sid *group_sids = NULL;
+       int i;
+       char **strings = NULL;
+       size_t num_strings = 0, num_sids = 0;
+
+
+       DEBUG(3,("ads: lookup_usergroups_memberof\n"));
+
+       if ( !winbindd_can_contact_domain( domain ) ) {
+               DEBUG(10,("lookup_usergroups_memberof: No incoming trust for "
+                         "domain %s\n", domain->name));
+               return NT_STATUS_OK;
+       }
+
+       ads = ads_cached_connection(domain);
+
+       if (!ads) {
+               domain->last_status = NT_STATUS_SERVER_DISABLED;
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       rc = ads_search_retry_extended_dn_ranged(ads, mem_ctx, user_dn, attrs,
+                                                ADS_EXTENDED_DN_HEX_STRING,
+                                                &strings, &num_strings);
+
+       if (!ADS_ERR_OK(rc)) {
+               DEBUG(1,("lookup_usergroups_memberof ads_search "
+                       "member=%s: %s\n", user_dn, ads_errstr(rc)));
+               return ads_ntstatus(rc);
+       }
+
+       *user_sids = NULL;
+       num_groups = 0;
+
+       /* always add the primary group to the sid array */
+       status = add_sid_to_array(mem_ctx, primary_group, user_sids,
+                                 &num_groups);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       group_sids = talloc_zero_array(mem_ctx, struct dom_sid, num_strings + 
1);
+       if (!group_sids) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       for (i=0; i<num_strings; i++) {
+               rc = ads_get_sid_from_extended_dn(mem_ctx, strings[i],
+                                                 ADS_EXTENDED_DN_HEX_STRING,
+                                                 &(group_sids)[i]);
+               if (!ADS_ERR_OK(rc)) {
+                       /* ignore members without SIDs */
+                       if (NT_STATUS_EQUAL(ads_ntstatus(rc),
+                           NT_STATUS_NOT_FOUND)) {
+                               continue;
+                       }
+                       else {
+                               status = ads_ntstatus(rc);
+                               goto done;
+                       }
+               }
+               num_sids++;
+       }
+
+       if (i == 0) {
+               DEBUG(1,("No memberOf for this user?!?\n"));
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       for (i=0; i<num_sids; i++) {
+
+               /* ignore Builtin groups from ADS - Guenther */
+               if (sid_check_is_in_builtin(&group_sids[i])) {
+                       continue;
+               }
+
+               status = add_sid_to_array(mem_ctx, &group_sids[i], user_sids,
+                                         &num_groups);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto done;
+               }
+
+       }
+
+       *p_num_groups = num_groups;
+       status = (*user_sids != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
+
+       DEBUG(3,("ads lookup_usergroups (memberof) succeeded for dn=%s\n",
+               user_dn));
+
+done:
+       TALLOC_FREE(strings);
+       TALLOC_FREE(group_sids);
+
+       return status;
+}
+
+
+/* Lookup groups a user is a member of. */
+static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
+                                 TALLOC_CTX *mem_ctx,
+                                 const struct dom_sid *sid,
+                                 uint32_t *p_num_groups, struct dom_sid 
**user_sids)
+{
+       ADS_STRUCT *ads = NULL;
+       const char *attrs[] = {"tokenGroups", "primaryGroupID", NULL};
+       ADS_STATUS rc;
+       int count;
+       LDAPMessage *msg = NULL;
+       char *user_dn = NULL;
+       struct dom_sid *sids;
+       int i;
+       struct dom_sid primary_group;
+       uint32_t primary_group_rid;
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       uint32_t num_groups = 0;
+
+       DEBUG(3,("ads: lookup_usergroups\n"));
+       *p_num_groups = 0;
+
+       status = lookup_usergroups_cached(mem_ctx, sid,
+                                         p_num_groups, user_sids);
+       if (NT_STATUS_IS_OK(status)) {
+               return NT_STATUS_OK;
+       }
+
+       if ( !winbindd_can_contact_domain( domain ) ) {
+               DEBUG(10,("lookup_usergroups: No incoming trust for domain 
%s\n",
+                         domain->name));
+
+               /* Tell the cache manager not to remember this one */
+
+               return NT_STATUS_SYNCHRONIZATION_REQUIRED;
+       }
+
+       ads = ads_cached_connection(domain);
+
+       if (!ads) {
+               domain->last_status = NT_STATUS_SERVER_DISABLED;
+               status = NT_STATUS_SERVER_DISABLED;
+               goto done;
+       }
+
+       rc = ads_search_retry_sid(ads, &msg, sid, attrs);
+
+       if (!ADS_ERR_OK(rc)) {
+               status = ads_ntstatus(rc);
+               DEBUG(1, ("lookup_usergroups(sid=%s) ads_search tokenGroups: "
+                         "%s\n", sid_string_dbg(sid), ads_errstr(rc)));
+               goto done;
+       }
+
+       count = ads_count_replies(ads, msg);
+       if (count != 1) {
+               status = NT_STATUS_UNSUCCESSFUL;
+               DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: "
+                        "invalid number of results (count=%d)\n", 
+                        sid_string_dbg(sid), count));
+               goto done;
+       }
+
+       if (!msg) {
+               DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: 
NULL msg\n", 


-- 
Samba Shared Repository

Reply via email to