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

Stefan Metzmacher metze at samba.org
Sun Apr 6 13:37:12 GMT 2008


The branch, v3-2-test has been updated
       via  31375c02631cb3f37a8bbd4ea17d3ef69c4d07bf (commit)
       via  4f712452e911db1f0aa74e3ccd636c1a18bdf9ef (commit)
      from  c78f4dc043523842cf42f1a3fd4e8f3855518efa (commit)

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


- Log -----------------------------------------------------------------
commit 31375c02631cb3f37a8bbd4ea17d3ef69c4d07bf
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Apr 2 08:03:11 2008 +0200

    net_rpc: let get_user_sids() use wbcLookupName(), wbcGidToSid() and wbcGetGroups()
    
    metze

commit 4f712452e911db1f0aa74e3ccd636c1a18bdf9ef
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Apr 2 08:02:02 2008 +0200

    net_rpc: let get_user_tokens() use wbcListUsers()
    
    metze

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

Summary of changes:
 source/utils/net_rpc.c |  158 +++++++++++++++++++++---------------------------
 1 files changed, 69 insertions(+), 89 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/utils/net_rpc.c b/source/utils/net_rpc.c
index 0d47b65..5abae7f 100644
--- a/source/utils/net_rpc.c
+++ b/source/utils/net_rpc.c
@@ -4469,88 +4469,84 @@ static void collect_alias_memberships(NT_USER_TOKEN *token)
 
 static bool get_user_sids(const char *domain, const char *user, NT_USER_TOKEN *token)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	enum wbcSidType type;
 	fstring full_name;
-	NSS_STATUS result;
-
+	struct wbcDomainSid wsid;
+	char *sid_str = NULL;
 	DOM_SID user_sid;
-
-	int i;
+	uint32_t num_groups;
+	gid_t *groups = NULL;
+	uint32_t i;
 
 	fstr_sprintf(full_name, "%s%c%s",
 		     domain, *lp_winbind_separator(), user);
 
 	/* First let's find out the user sid */
 
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
+	wbc_status = wbcLookupName(domain, user, &wsid, &type);
 
-	fstrcpy(request.data.name.dom_name, domain);
-	fstrcpy(request.data.name.name, user);
-
-	result = winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		DEBUG(1, ("winbind could not find %s: %s\n",
+			  full_name, wbcErrorString(wbc_status)));
+		return false;
+	}
 
-	if (result != NSS_STATUS_SUCCESS) {
-		DEBUG(1, ("winbind could not find %s\n", full_name));
-		return False;
+	wbc_status = wbcSidToString(&wsid, &sid_str);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		return false;
 	}
 
-	if (response.data.sid.type != SID_NAME_USER) {
+	if (type != SID_NAME_USER) {
+		wbcFreeMemory(sid_str);
 		DEBUG(1, ("%s is not a user\n", full_name));
-		return False;
+		return false;
 	}
 
-	if (!string_to_sid(&user_sid, response.data.sid.sid)) {
-		DEBUG(1, ("Could not convert string '%s' to SID\n", response.data.sid.sid));
-		return False;
-	}
+	string_to_sid(&user_sid, sid_str);
+	wbcFreeMemory(sid_str);
+	sid_str = NULL;
 
 	init_user_token(token, &user_sid);
 
 	/* And now the groups winbind knows about */
 
-	ZERO_STRUCT(response);
-
-	fstrcpy(request.data.username, full_name);
-
-	result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
-
-	if (result != NSS_STATUS_SUCCESS) {
-		DEBUG(1, ("winbind could not get groups of %s\n", full_name));
-		return False;
+	wbc_status = wbcGetGroups(full_name, &num_groups, &groups);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		DEBUG(1, ("winbind could not get groups of %s: %s\n",
+			full_name, wbcErrorString(wbc_status)));
+		return false;
 	}
 
-	for (i = 0; i < response.data.num_entries; i++) {
-		gid_t gid = ((gid_t *)response.extra_data.data)[i];
+	for (i = 0; i < num_groups; i++) {
+		gid_t gid = groups[i];
 		DOM_SID sid;
 
-		struct winbindd_request sidrequest;
-		struct winbindd_response sidresponse;
-
-		ZERO_STRUCT(sidrequest);
-		ZERO_STRUCT(sidresponse);
-
-		sidrequest.data.gid = gid;
-
-		result = winbindd_request_response(WINBINDD_GID_TO_SID,
-					  &sidrequest, &sidresponse);
+		wbc_status = wbcGidToSid(gid, &wsid);
+		if (!WBC_ERROR_IS_OK(wbc_status)) {
+			DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
+				  gid, wbcErrorString(wbc_status)));
+			wbcFreeMemory(groups);
+			return false;
+		}
 
-		if (result != NSS_STATUS_SUCCESS) {
-			DEBUG(1, ("winbind could not find SID of gid %d\n",
-				  gid));
-			return False;
+		wbc_status = wbcSidToString(&wsid, &sid_str);
+		if (!WBC_ERROR_IS_OK(wbc_status)) {
+			wbcFreeMemory(groups);
+			return false;
 		}
 
-		DEBUG(3, (" %s\n", sidresponse.data.sid.sid));
+		DEBUG(3, (" %s\n", sid_str));
+
+		string_to_sid(&sid, sid_str);
+		wbcFreeMemory(sid_str);
+		sid_str = NULL;
 
-		string_to_sid(&sid, sidresponse.data.sid.sid);
 		add_sid_to_token(token, &sid);
 	}
+	wbcFreeMemory(groups);
 
-	SAFE_FREE(response.extra_data.data);
-
-	return True;
+	return true;
 }
 	
 /**
@@ -4559,11 +4555,9 @@ static bool get_user_sids(const char *domain, const char *user, NT_USER_TOKEN *t
 
 static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	const char *extra_data;
-	char *name;
-	int i;
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	uint32_t i, num_users;
+	const char **users;
 	struct user_token *result;
 	TALLOC_CTX *frame = NULL;
 
@@ -4571,58 +4565,43 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
 	    (opt_target_workgroup == NULL)) {
 		d_fprintf(stderr, "winbind use default domain = yes set, "
 			 "please specify a workgroup\n");
-		return False;
+		return false;
 	}
 
 	/* Send request to winbind daemon */
 
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
-
-	if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
-	    NSS_STATUS_SUCCESS)
-		return False;
-
-	/* Look through extra data */
-
-	if (!response.extra_data.data)
-		return False;
-
-	extra_data = (const char *)response.extra_data.data;
-	*num_tokens = 0;
-
-	frame = talloc_stackframe();
-	while(next_token_talloc(frame, &extra_data, &name, ",")) {
-		*num_tokens += 1;
+	wbc_status = wbcListUsers(NULL, &num_users, &users);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		DEBUG(1, ("winbind could not list users: %s\n",
+			  wbcErrorString(wbc_status)));
+		return false;
 	}
 
-	result = SMB_MALLOC_ARRAY(struct user_token, *num_tokens);
+	result = SMB_MALLOC_ARRAY(struct user_token, num_users);
 
 	if (result == NULL) {
 		DEBUG(1, ("Could not malloc sid array\n"));
-		TALLOC_FREE(frame);
-		return False;
+		wbcFreeMemory(users);
+		return false;
 	}
 
-	extra_data = (const char *)response.extra_data.data;
-	i=0;
-
-	while(next_token_talloc(frame, &extra_data, &name, ",")) {
+	frame = talloc_stackframe();
+	for (i=0; i < num_users; i++) {
 		fstring domain, user;
 		char *p;
 
-		fstrcpy(result[i].name, name);
+		fstrcpy(result[i].name, users[i]);
 
-		p = strchr(name, *lp_winbind_separator());
+		p = strchr(users[i], *lp_winbind_separator());
 
-		DEBUG(3, ("%s\n", name));
+		DEBUG(3, ("%s\n", users[i]));
 
 		if (p == NULL) {
 			fstrcpy(domain, opt_target_workgroup);
-			fstrcpy(user, name);
+			fstrcpy(user, users[i]);
 		} else {
 			*p++ = '\0';
-			fstrcpy(domain, name);
+			fstrcpy(domain, users[i]);
 			strupper_m(domain);
 			fstrcpy(user, p);
 		}
@@ -4631,11 +4610,12 @@ static bool get_user_tokens(int *num_tokens, struct user_token **user_tokens)
 		i+=1;
 	}
 	TALLOC_FREE(frame);
-	SAFE_FREE(response.extra_data.data);
+	wbcFreeMemory(users);
 
+	*num_tokens = num_users;
 	*user_tokens = result;
 
-	return True;
+	return true;
 }
 
 static bool get_user_tokens_from_file(FILE *f,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list