[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-3093-g50a347f

Simo Sorce idra at samba.org
Sun Jul 6 16:55:41 GMT 2008


The branch, v3-3-test has been updated
       via  50a347f5503ebed0fcc7b9de60f8368677585bb1 (commit)
      from  f6c92c4759096f839e3854a1e9eea56e6eecad4d (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit 50a347f5503ebed0fcc7b9de60f8368677585bb1
Author: Simo Sorce <idra at samba.org>
Date:   Sun Jul 6 12:55:07 2008 -0400

    Clean up winbindd_group.c too

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

Summary of changes:
 source/winbindd/winbindd_group.c |  465 +++++++++++++++++++++-----------------
 1 files changed, 255 insertions(+), 210 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/winbindd/winbindd_group.c b/source/winbindd/winbindd_group.c
index 20b90e3..69e3a6a 100644
--- a/source/winbindd/winbindd_group.c
+++ b/source/winbindd/winbindd_group.c
@@ -45,7 +45,9 @@ static void add_member(const char *domain, const char *user,
  Add member users resulting from sid. Expand if it is a domain group.
 **********************************************************************/
 
-static void add_expanded_sid(const DOM_SID *sid, char **pp_members, size_t *p_num_members)
+static void add_expanded_sid(const DOM_SID *sid,
+			     char **pp_members,
+			     size_t *p_num_members)
 {
 	DOM_SID dom_sid;
 	uint32 rid;
@@ -143,8 +145,8 @@ static void add_expanded_sid(const DOM_SID *sid, char **pp_members, size_t *p_nu
 }
 
 static bool fill_passdb_alias_grmem(struct winbindd_domain *domain,
-			     DOM_SID *group_sid, 
-			     size_t *num_gr_mem, char **gr_mem, size_t *gr_mem_len)
+				    DOM_SID *group_sid, size_t *num_gr_mem,
+				    char **gr_mem, size_t *gr_mem_len)
 {
 	DOM_SID *members;
 	size_t i, num_members;
@@ -177,7 +179,7 @@ static bool fill_passdb_alias_grmem(struct winbindd_domain *domain,
 
 /* Fill a grent structure from various other information */
 
-static bool fill_grent(struct winbindd_gr *gr, const char *dom_name, 
+static bool fill_grent(struct winbindd_gr *gr, const char *dom_name,
 		       const char *gr_name, gid_t unix_gid)
 {
 	fstring full_group_name;
@@ -185,9 +187,9 @@ static bool fill_grent(struct winbindd_gr *gr, const char *dom_name,
 	fill_domain_username( full_group_name, dom_name, gr_name, True );
 
 	gr->gr_gid = unix_gid;
-    
+
 	/* Group name and password */
-    
+
 	safe_strcpy(gr->gr_name, full_group_name, sizeof(gr->gr_name) - 1);
 	safe_strcpy(gr->gr_passwd, "x", sizeof(gr->gr_passwd) - 1);
 
@@ -208,7 +210,7 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 				     struct winbindd_cli_state *state,
 				     DOM_SID *group_sid,
 				     enum lsa_SidType group_name_type,
-				     size_t *num_gr_mem, char **gr_mem, 
+				     size_t *num_gr_mem, char **gr_mem,
 				     size_t *gr_mem_len)
 {
 	DOM_SID querying_user_sid;
@@ -232,7 +234,8 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 			status = idmap_uid_to_sid(&querying_user_sid, ret_uid);
 			if (NT_STATUS_IS_OK(status)) {
 				pquerying_user_sid = &querying_user_sid;
-				DEBUG(10,("fill_grent_mem_domain_users: querying uid %u -> %s\n",
+				DEBUG(10,("fill_grent_mem_domain_users: "
+					  "querying uid %u -> %s\n",
 					  (unsigned int)ret_uid,
 					  sid_string_dbg(pquerying_user_sid)));
 			}
@@ -242,22 +245,23 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 	/* Only look up if it was a winbindd user in this domain. */
 	if (pquerying_user_sid &&
 	    (sid_compare_domain(pquerying_user_sid, &domain->sid) == 0)) {
-		
+
 		DEBUG(10,("fill_grent_mem_domain_users: querying user = %s\n",
 			  sid_string_dbg(pquerying_user_sid) ));
-		
+
 		status = domain->methods->lookup_usergroups(domain,
 							    mem_ctx,
 							    pquerying_user_sid,
 							    &num_groups,
 							    &user_sids);
 		if (!NT_STATUS_IS_OK(status)) {
-			DEBUG(1, ("fill_grent_mem_domain_users: lookup_usergroups failed "
-				  "for sid %s in domain %s (error: %s)\n", 
+			DEBUG(1, ("fill_grent_mem_domain_users: "
+				  "lookup_usergroups failed "
+				  "for sid %s in domain %s (error: %s)\n",
 				  sid_string_dbg(pquerying_user_sid),
 				  domain->name,
 				  nt_errstr(status)));
-		        return False;			
+		        return False;
 		}
 
 		for (i = 0; i < num_groups; i++) {
@@ -269,18 +273,19 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 			}
 		}
 	}
-	
+
 	if (u_in_group) {
 		size_t len = 0;
 		char *domainname = NULL;
 		char *username = NULL;
 		fstring name;
 		enum lsa_SidType type;
-		
-		DEBUG(10,("fill_grent_mem_domain_users: sid %s in 'Domain Users' in domain %s\n",
+
+		DEBUG(10,("fill_grent_mem_domain_users: "
+			  "sid %s in 'Domain Users' in domain %s\n",
 			  sid_string_dbg(pquerying_user_sid),
 			  domain->name ));
-		
+
 		status = domain->methods->sid_to_name(domain, mem_ctx,
 						      pquerying_user_sid,
 						      &domainname,
@@ -288,38 +293,39 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 						      &type);
 		if (!NT_STATUS_IS_OK(status)) {
 			DEBUG(1, ("could not lookup username for user "
-				  "sid %s in domain %s (error: %s)\n", 
+				  "sid %s in domain %s (error: %s)\n",
 				  sid_string_dbg(pquerying_user_sid),
 				  domain->name,
 				  nt_errstr(status)));
-			return False;			
+			return False;
 		}
 		fill_domain_username(name, domain->name, username, True);
 		len = strlen(name);
 		buf_len = len + 1;
 		if (!(buf = (char *)SMB_MALLOC(buf_len))) {
 			DEBUG(1, ("out of memory\n"));
-			return False;			
+			return False;
 		}
 		memcpy(buf, name, buf_len);
-		
+
 		DEBUG(10,("fill_grent_mem_domain_users: user %s in "
 			  "'Domain Users' in domain %s\n",
 			  name, domain->name ));
-		
+
 		/* user is the only member */
 		*num_gr_mem = 1;
 	}
-		
+
 	*gr_mem = buf;
 	*gr_mem_len = buf_len;
-	
-	DEBUG(10, ("fill_grent_mem_domain_users: num_mem = %u, len = %u, mem = %s\n", 
-		   (unsigned int)*num_gr_mem, 
-		   (unsigned int)buf_len, *num_gr_mem ? buf : "NULL")); 
+
+	DEBUG(10, ("fill_grent_mem_domain_users: "
+		   "num_mem = %u, len = %u, mem = %s\n",
+		   (unsigned int)*num_gr_mem,
+		   (unsigned int)buf_len, *num_gr_mem ? buf : "NULL"));
 
 	return True;
-}					 
+}
 
 /***********************************************************************
  Add names to a list.  Assumes  a canonical version of the string
@@ -328,28 +334,29 @@ static bool fill_grent_mem_domusers( TALLOC_CTX *mem_ctx,
 
 static int namecmp( const void *a, const void *b )
 {
-	return StrCaseCmp( * (char * const *) a, * (char * const *) b);	
+	return StrCaseCmp( * (char * const *) a, * (char * const *) b);
 }
 
-static NTSTATUS add_names_to_list( TALLOC_CTX *ctx, 
-				   char ***list, uint32 *n_list, 
+static NTSTATUS add_names_to_list( TALLOC_CTX *ctx,
+				   char ***list, uint32 *n_list,
 				   char **names, uint32 n_names )
 {
-	char **new_list = NULL;	
-	uint32 n_new_list = 0;	
-	int i, j;	
+	char **new_list = NULL;
+	uint32 n_new_list = 0;
+	int i, j;
 
 	if ( !names || (n_names == 0) )
 		return NT_STATUS_OK;
-	
+
 	/* Alloc the maximum size we'll need */
 
         if ( *list == NULL ) {
-		if ( (new_list = TALLOC_ARRAY( ctx, char *, n_names )) == NULL ) 
+		if ((new_list = TALLOC_ARRAY(ctx, char *, n_names)) == NULL) {
 			return NT_STATUS_NO_MEMORY;
-		n_new_list = n_names;		
+		}
+		n_new_list = n_names;
 	} else {
-		new_list = TALLOC_REALLOC_ARRAY( ctx, *list, char *, 
+		new_list = TALLOC_REALLOC_ARRAY( ctx, *list, char *,
 						 (*n_list) + n_names );
 		if ( !new_list )
 			return NT_STATUS_NO_MEMORY;
@@ -364,33 +371,33 @@ static NTSTATUS add_names_to_list( TALLOC_CTX *ctx,
 
 	/* search for duplicates for sorting and looking for matching
 	   neighbors */
-	
+
 	qsort( new_list, n_new_list, sizeof(char*), QSORT_CAST namecmp );
-	
+
 	for ( i=1; i<n_new_list; i++ ) {
-		if ( strcmp( new_list[i-1], new_list[i] ) == 0 ) {			
-			memmove( &new_list[i-1], &new_list[i], 
+		if ( strcmp( new_list[i-1], new_list[i] ) == 0 ) {
+			memmove( &new_list[i-1], &new_list[i],
 				 sizeof(char*)*(n_new_list-i) );
 			n_new_list--;
 		}
 	}
 
 	*list = new_list;
-	*n_list = n_new_list;	
+	*n_list = n_new_list;
 
-	return NT_STATUS_OK;	
+	return NT_STATUS_OK;
 }
 
 /***********************************************************************
 ***********************************************************************/
 
-static NTSTATUS expand_groups( TALLOC_CTX *ctx, 
+static NTSTATUS expand_groups( TALLOC_CTX *ctx,
 			       struct winbindd_domain *d,
 			       DOM_SID *glist, uint32 n_glist,
 			       DOM_SID **new_glist, uint32 *n_new_glist,
 			       char ***members, uint32 *n_members )
 {
-	int i, j;	
+	int i, j;
 	NTSTATUS status = NT_STATUS_OK;
 	uint32 num_names = 0;
 	uint32 *name_types = NULL;
@@ -398,25 +405,25 @@ static NTSTATUS expand_groups( TALLOC_CTX *ctx,
 	DOM_SID *sid_mem = NULL;
 	TALLOC_CTX *tmp_ctx = NULL;
 	DOM_SID *new_groups = NULL;
-	size_t new_groups_size = 0;	
-	
+	size_t new_groups_size = 0;
+
 	*members = NULL;
-	*n_members = 0;	
+	*n_members = 0;
 	*new_glist = NULL;
-	*n_new_glist = 0;	
-	
+	*n_new_glist = 0;
+
 	for ( i=0; i<n_glist; i++ ) {
 		tmp_ctx = talloc_new( ctx );
 
 		/* Lookup the group membership */
 
-		status = d->methods->lookup_groupmem(d, tmp_ctx, 
+		status = d->methods->lookup_groupmem(d, tmp_ctx,
 						     &glist[i], &num_names,
-						     &sid_mem, &names, 
+						     &sid_mem, &names,
 						     &name_types);
-		if ( !NT_STATUS_IS_OK(status) ) 
+		if ( !NT_STATUS_IS_OK(status) )
 			goto out;
-				
+
 		/* Separate users and groups into two lists */
 
 		for ( j=0; j<num_names; j++ ) {
@@ -425,14 +432,14 @@ static NTSTATUS expand_groups( TALLOC_CTX *ctx,
 			if ( name_types[j] == SID_NAME_USER ||
 			     name_types[j] == SID_NAME_COMPUTER )
 			{
-				status = add_names_to_list( ctx, members, 
+				status = add_names_to_list( ctx, members,
 							    n_members,
 							    names+j, 1 );
 				if ( !NT_STATUS_IS_OK(status) )
 					goto out;
 
-				continue;				
-			} 
+				continue;
+			}
 
 			/* Groups */
 			if ( name_types[j] == SID_NAME_DOM_GRP ||
@@ -454,12 +461,12 @@ static NTSTATUS expand_groups( TALLOC_CTX *ctx,
 	}
 
 	*new_glist = new_groups;
-	*n_new_glist = (uint32)new_groups_size;	
-	
+	*n_new_glist = (uint32)new_groups_size;
+
  out:
 	TALLOC_FREE( tmp_ctx );
-	
-	return status;	
+
+	return status;
 }
 
 /***********************************************************************
@@ -468,9 +475,10 @@ static NTSTATUS expand_groups( TALLOC_CTX *ctx,
 
 static bool fill_grent_mem(struct winbindd_domain *domain,
 			   struct winbindd_cli_state *state,
-			   DOM_SID *group_sid, 
-			   enum lsa_SidType group_name_type, 
-			   size_t *num_gr_mem, char **gr_mem, size_t *gr_mem_len)
+			   DOM_SID *group_sid,
+			   enum lsa_SidType group_name_type,
+			   size_t *num_gr_mem, char **gr_mem,
+			   size_t *gr_mem_len)
 {
 	uint32 num_names = 0;
 	unsigned int buf_len = 0, buf_ndx = 0, i;
@@ -480,8 +488,8 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 	uint32 group_rid;
 	DOM_SID *glist = NULL;
 	DOM_SID *new_glist = NULL;
-	uint32 n_glist, n_new_glist;	
-	int max_depth = lp_winbind_expand_groups();	
+	uint32 n_glist, n_new_glist;
+	int max_depth = lp_winbind_expand_groups();
 
 	if (!(mem_ctx = talloc_init("fill_grent_mem(%s)", domain->name)))
 		return False;
@@ -508,7 +516,7 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 	if ( !((group_name_type==SID_NAME_DOM_GRP) ||
 	       ((group_name_type==SID_NAME_ALIAS) && domain->primary)) )
 	{
-		DEBUG(1, ("SID %s in domain %s isn't a domain group (%d)\n", 
+		DEBUG(1, ("SID %s in domain %s isn't a domain group (%d)\n",
 			  sid_string_dbg(group_sid),
 			  domain->name, group_name_type));
                 goto done;
@@ -519,15 +527,15 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 
 	sid_peek_rid( group_sid, &group_rid );
 	if (!lp_winbind_enum_users() && group_rid == DOMAIN_GROUP_RID_USERS) {
-		result = fill_grent_mem_domusers( mem_ctx, domain, state, 
+		result = fill_grent_mem_domusers( mem_ctx, domain, state,
 						  group_sid, group_name_type,
 						  num_gr_mem, gr_mem,
 						  gr_mem_len );
-		goto done;		
+		goto done;
 	}
 
 	/* Real work goes here.  Create a list of group names to
-	   expand startign with the initial one.  Pass that to 
+	   expand startign with the initial one.  Pass that to
 	   expand_groups() which returns a list of more group names
 	   to expand.  Do this up to the max search depth. */
 
@@ -536,33 +544,33 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 		DEBUG(0,("fill_grent_mem: talloc failure!\n"));
 		goto done;
 	}
-	sid_copy( &glist[0], group_sid );	
-	n_glist = 1;	
+	sid_copy( &glist[0], group_sid );
+	n_glist = 1;
 
 	for ( i=0; i<max_depth && glist; i++ ) {
 		uint32 n_members = 0;
 		char **members = NULL;
-		NTSTATUS nt_status;		
+		NTSTATUS nt_status;
 
 		nt_status = expand_groups( mem_ctx, domain,
-					   glist, n_glist, 
+					   glist, n_glist,
 					   &new_glist, &n_new_glist,
 					   &members, &n_members);
 		if ( !NT_STATUS_IS_OK(nt_status) ) {
-			result = False;			
+			result = False;
 			goto done;
-		}		
-		
+		}
+
 		/* Add new group members to list */
 
-		nt_status = add_names_to_list( mem_ctx, &names, &num_names, 
+		nt_status = add_names_to_list( mem_ctx, &names, &num_names,
 					       members, n_members );
 		if ( !NT_STATUS_IS_OK(nt_status) ) {
-			result = False;			
+			result = False;
 			goto done;
 		}
-		
-		TALLOC_FREE( members );		
+
+		TALLOC_FREE( members );
 
 		/* If we have no more groups to expand, break out
 		   early */
@@ -575,8 +583,8 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 		glist = new_glist;
 		n_glist = n_new_glist;
 	}
-	TALLOC_FREE( glist );	
-	 
+	TALLOC_FREE( glist );
+
 	DEBUG(10, ("looked up %d names\n", num_names));
 
  again:
@@ -584,11 +592,11 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 
 	for (i = 0; i < num_names; i++) {
 		int len;
-			
+
 		DEBUG(10, ("processing name %s\n", names[i]));
 
 		len = strlen(names[i]);
-		
+
 		/* Add to list or calculate buffer length */
 
 		if (!buf) {
@@ -596,7 +604,8 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 			(*num_gr_mem)++;
 			DEBUG(10, ("buf_len + %d = %d\n", len + 1, buf_len));
 		} else {
-			DEBUG(10, ("appending %s at ndx %d\n", names[i], buf_ndx));
+			DEBUG(10, ("appending %s at ndx %d\n",
+				   names[i], buf_ndx));
 			safe_strcpy(&buf[buf_ndx], names[i], len);
 			buf_ndx += len;
 			buf[buf_ndx] = ',';
@@ -625,26 +634,27 @@ static bool fill_grent_mem(struct winbindd_domain *domain,
 	*gr_mem = buf;
 	*gr_mem_len = buf_len;
 
-	DEBUG(10, ("num_mem = %u, len = %u, mem = %s\n", (unsigned int)*num_gr_mem, 
-		   (unsigned int)buf_len, *num_gr_mem ? buf : "NULL")); 
+	DEBUG(10, ("num_mem = %u, len = %u, mem = %s\n",
+		   (unsigned int)*num_gr_mem,
+		   (unsigned int)buf_len, *num_gr_mem ? buf : "NULL"));
 	result = True;
 
 done:
 
 	talloc_destroy(mem_ctx);
-	
+
 	DEBUG(10, ("fill_grent_mem returning %d\n", result));
 
 	return result;
 }
 
-static void winbindd_getgrsid( struct winbindd_cli_state *state, DOM_SID group_sid );
+static void winbindd_getgrsid(struct winbindd_cli_state *state, DOM_SID group_sid);
 
-static void getgrnam_recv( void *private_data, bool success, const DOM_SID *sid, 
+static void getgrnam_recv( void *private_data, bool success, const DOM_SID *sid,
 			   enum lsa_SidType type )
 {
 	struct winbindd_cli_state *state = (struct winbindd_cli_state*)private_data;
-	
+
 	if (!success) {
 		DEBUG(5,("getgrnam_recv: lookupname failed!\n"));
 		request_error(state);
@@ -655,12 +665,12 @@ static void getgrnam_recv( void *private_data, bool success, const DOM_SID *sid,
 		DEBUG(5,("getgrnam_recv: not a group!\n"));
 		request_error(state);
 		return;
-	}	
+	}
 
 	winbindd_getgrsid( state, *sid );
 }
 
-	


-- 
Samba Shared Repository


More information about the samba-cvs mailing list