r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[abartlet/samba.git/.git] / source3 / nsswitch / winbindd_ads.c
index d362f3173b2ec47ef610f001306783b41e27fcde..3f9308cb66affd4fd38766deee7a8b4560b6dc82 100644 (file)
@@ -9,7 +9,7 @@
    
    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 2 of the License, or
+   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,
@@ -18,8 +18,7 @@
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -570,7 +569,12 @@ static NTSTATUS lookup_usergroups_member(struct winbindd_domain *domain,
                goto done;
        }
 
-       if (!(ldap_exp = talloc_asprintf(mem_ctx, "(&(member=%s)(objectCategory=group))", escaped_dn))) {
+       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));
                SAFE_FREE(escaped_dn);
                status = NT_STATUS_NO_MEMORY;
@@ -969,7 +973,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                goto done;
        } 
        
-       DEBUG(10, ("ads lookup_groupmem: got %d sids via extended dn call\n", num_members));
+       DEBUG(10, ("ads lookup_groupmem: got %d sids via extended dn call\n", (int)num_members));
        
        /* Now that we have a list of sids, we need to get the
         * lists of names and name_types belonging to these sids.
@@ -1017,7 +1021,11 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                        DEBUG(10,("ads: lookup_groupmem: got sid %s from cache\n",
                                 sid_string_static(&sid)));
                        sid_copy(&(*sid_mem)[*num_names], &sid);
-                       (*names)[*num_names] = CONST_DISCARD(char *,name);
+                       (*names)[*num_names] = talloc_asprintf(*names, "%s%c%s",
+                                                              domain_name,
+                                                              *lp_winbind_separator(),
+                                                              name );
+
                        (*name_types)[*num_names] = name_type;
                        (*num_names)++;
                }
@@ -1055,14 +1063,17 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                        /* Copy the entries over from the "_nocache" arrays 
                         * to the result arrays, skipping the gaps the 
                         * lookup_sids call left. */
-                       *num_names = 0;
                        for (i=0; i < num_nocache; i++) {
                                if (((names_nocache)[i] != NULL) && 
                                    ((name_types_nocache)[i] != SID_NAME_UNKNOWN)) 
                                {
                                        sid_copy(&(*sid_mem)[*num_names],
                                                 &sid_mem_nocache[i]);
-                                       (*names)[*num_names] = talloc_move(*names, &names_nocache[i]);
+                                       (*names)[*num_names] = talloc_asprintf( *names, 
+                                                                               "%s%c%s",
+                                                                               domains_nocache[i],
+                                                                               *lp_winbind_separator(),
+                                                                               names_nocache[i] );
                                        (*name_types)[*num_names] = name_types_nocache[i];
                                        (*num_names)++;
                                }
@@ -1078,7 +1089,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                else if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(10, ("lookup_groupmem: Error looking up %d "
                                   "sids via rpc_lsa_lookup_sids: %s\n",
-                                  num_members, nt_errstr(status)));
+                                  (int)num_members, nt_errstr(status)));
                        goto done;
                }
        }