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

Stefan Metzmacher metze at samba.org
Fri Mar 28 14:13:11 GMT 2008


The branch, v3-2-test has been updated
       via  7714f9232110b2ee50e6ba8371f0bc23b83717a6 (commit)
       via  8945dce4a18874bdf1a57f1ff8116a66a6f699a0 (commit)
       via  5a0ae1ad0c36e5ef97008a2c6bc2a921ca6538bd (commit)
       via  ff16b66631bc93909c0e7adf9e6bb1cf1d641ffd (commit)
       via  7a4de23aa318bd24948e576a5582a5c74d335154 (commit)
       via  df127f0b40d36ea8ee605c24ea88558c7d40a7fe (commit)
       via  38007a387a1f1b53877ef9ea518f83ecf026f4f3 (commit)
      from  cc654892c0d76dea001cd8f7bd6f50cf9e89e9c9 (commit)

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


- Log -----------------------------------------------------------------
commit 7714f9232110b2ee50e6ba8371f0bc23b83717a6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 24 21:05:30 2008 +0100

    wbinfo: use wbcDomainInfo()
    
    metze

commit 8945dce4a18874bdf1a57f1ff8116a66a6f699a0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 24 20:44:34 2008 +0100

    wbinfo: use wbcGetgrnam()
    
    metze

commit 5a0ae1ad0c36e5ef97008a2c6bc2a921ca6538bd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 24 20:32:14 2008 +0100

    wbinfo: use wbcListUsers() and wbcListGroups()
    
    metze

commit ff16b66631bc93909c0e7adf9e6bb1cf1d641ffd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Mar 23 22:41:45 2008 +0100

    wbinfo: use wbcLookupUserSids()
    
    metze

commit 7a4de23aa318bd24948e576a5582a5c74d335154
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 24 21:07:01 2008 +0100

    libwbclient: remove prototype of non existing wbcDomainSequenceNumbers()
    
    metze

commit df127f0b40d36ea8ee605c24ea88558c7d40a7fe
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 24 20:31:37 2008 +0100

    libwbclient: add wbcListUsers() and wbcListGroups()
    
    metze

commit 38007a387a1f1b53877ef9ea518f83ecf026f4f3
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 21 10:18:54 2008 +0100

    libwbclient: add wbcLookupUserSids()
    
    metze

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

Summary of changes:
 source/nsswitch/libwbclient/wbc_sid.c  |  224 ++++++++++++++++++++++++++++++
 source/nsswitch/libwbclient/wbclient.h |   15 ++-
 source/nsswitch/wbinfo.c               |  233 +++++++++++++++-----------------
 3 files changed, 348 insertions(+), 124 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/nsswitch/libwbclient/wbc_sid.c b/source/nsswitch/libwbclient/wbc_sid.c
index 0519d8b..6ef9f44 100644
--- a/source/nsswitch/libwbclient/wbc_sid.c
+++ b/source/nsswitch/libwbclient/wbc_sid.c
@@ -423,3 +423,227 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
 
 	return wbc_status;
 }
+
+/** @brief Get the groups a user belongs to
+ *
+ **/
+
+wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
+			 bool domain_groups_only,
+			 uint32_t *num_sids,
+			 struct wbcDomainSid **_sids)
+{
+	uint32_t i;
+	const char *s;
+	struct winbindd_request request;
+	struct winbindd_response response;
+	char *sid_string = NULL;
+	struct wbcDomainSid *sids = NULL;
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	int cmd;
+
+	/* Initialise request */
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	if (!user_sid) {
+		wbc_status = WBC_ERR_INVALID_PARAM;
+		BAIL_ON_WBC_ERROR(wbc_status);
+	}
+
+	wbc_status = wbcSidToString(user_sid, &sid_string);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1);
+	wbcFreeMemory(sid_string);
+
+	if (domain_groups_only) {
+		cmd = WINBINDD_GETUSERDOMGROUPS;
+	} else {
+		cmd = WINBINDD_GETUSERSIDS;
+	}
+
+	wbc_status = wbcRequestResponse(cmd,
+					&request,
+					&response);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	if (response.data.num_entries &&
+	    !response.extra_data.data) {
+		wbc_status = WBC_INVALID_RESPONSE;
+		BAIL_ON_WBC_ERROR(wbc_status);
+	}
+
+	sids = talloc_array(NULL, struct wbcDomainSid,
+			    response.data.num_entries);
+	BAIL_ON_PTR_ERROR(sids, wbc_status);
+
+	s = (const char *)response.extra_data.data;
+	for (i = 0; i < response.data.num_entries; i++) {
+		char *n = strchr(s, '\n');
+		if (n) {
+			*n = '\0';
+		}
+		wbc_status = wbcStringToSid(s, &sids[i]);
+		BAIL_ON_WBC_ERROR(wbc_status);
+		s += strlen(s) + 1;
+	}
+
+	*num_sids = response.data.num_entries;
+	*_sids = sids;
+	sids = NULL;
+	wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+	if (response.extra_data.data) {
+		free(response.extra_data.data);
+	}
+	if (sids) {
+		talloc_free(sids);
+	}
+
+	return wbc_status;
+}
+
+/** @brief Lists Users
+ *
+ **/
+
+wbcErr wbcListUsers(const char *domain_name,
+		    uint32_t *_num_users,
+		    const char ***_users)
+{
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct winbindd_request request;
+	struct winbindd_response response;
+	uint32_t num_users = 0;
+	const char **users = NULL;
+	const char *next;
+
+	/* Initialise request */
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	if (domain_name) {
+		strncpy(request.domain_name, domain_name,
+			sizeof(request.domain_name)-1);
+	}
+
+	wbc_status = wbcRequestResponse(WINBINDD_LIST_USERS,
+					&request,
+					&response);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	/* Look through extra data */
+
+	next = (const char *)response.extra_data.data;
+	while (next) {
+		const char **tmp;
+		const char *current = next;
+		char *k = strchr(next, ',');
+		if (k) {
+			k[0] = '\0';
+			next = k+1;
+		} else {
+			next = NULL;
+		}
+
+		tmp = talloc_realloc(NULL, users,
+				     const char *,
+				     num_users+1);
+		BAIL_ON_PTR_ERROR(tmp, wbc_status);
+		users = tmp;
+
+		users[num_users] = talloc_strdup(users, current);
+		BAIL_ON_PTR_ERROR(users[num_users], wbc_status);
+
+		num_users++;
+	}
+
+	*_num_users = num_users;
+	*_users = users;
+	users = NULL;
+	wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+	if (response.extra_data.data) {
+		free(response.extra_data.data);
+	}
+	if (users) {
+		talloc_free(users);
+	}
+	return wbc_status;
+}
+
+/** @brief Lists Groups
+ *
+ **/
+
+wbcErr wbcListGroups(const char *domain_name,
+		     uint32_t *_num_groups,
+		     const char ***_groups)
+{
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct winbindd_request request;
+	struct winbindd_response response;
+	uint32_t num_groups = 0;
+	const char **groups = NULL;
+	const char *next;
+
+	/* Initialise request */
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	if (domain_name) {
+		strncpy(request.domain_name, domain_name,
+			sizeof(request.domain_name)-1);
+	}
+
+	wbc_status = wbcRequestResponse(WINBINDD_LIST_GROUPS,
+					&request,
+					&response);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	/* Look through extra data */
+
+	next = (const char *)response.extra_data.data;
+	while (next) {
+		const char **tmp;
+		const char *current = next;
+		char *k = strchr(next, ',');
+		if (k) {
+			k[0] = '\0';
+			next = k+1;
+		} else {
+			next = NULL;
+		}
+
+		tmp = talloc_realloc(NULL, groups,
+				     const char *,
+				     num_groups+1);
+		BAIL_ON_PTR_ERROR(tmp, wbc_status);
+		groups = tmp;
+
+		groups[num_groups] = talloc_strdup(groups, current);
+		BAIL_ON_PTR_ERROR(groups[num_groups], wbc_status);
+
+		num_groups++;
+	}
+
+	*_num_groups = num_groups;
+	*_groups = groups;
+	groups = NULL;
+	wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+	if (response.extra_data.data) {
+		free(response.extra_data.data);
+	}
+	if (groups) {
+		talloc_free(groups);
+	}
+	return wbc_status;
+}
diff --git a/source/nsswitch/libwbclient/wbclient.h b/source/nsswitch/libwbclient/wbclient.h
index c01db96..e5047af 100644
--- a/source/nsswitch/libwbclient/wbclient.h
+++ b/source/nsswitch/libwbclient/wbclient.h
@@ -298,6 +298,19 @@ wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
 		     const char ***names,
 		     enum wbcSidType **types);
 
+wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
+			 bool domain_groups_only,
+			 uint32_t *num_sids,
+			 struct wbcDomainSid **sids);
+
+wbcErr wbcListUsers(const char *domain_name,
+		    uint32_t *num_users,
+		    const char ***users);
+
+wbcErr wbcListGroups(const char *domain_name,
+		     uint32_t *num_groups,
+		     const char ***groups);
+
 /*
  * SID/uid/gid Mappings
  */
@@ -350,8 +363,6 @@ wbcErr wbcGetgrent(struct group **grp);
 wbcErr wbcDomainInfo(const char *domain,
 		     struct wbcDomainInfo **info);
 
-wbcErr wbcDomainSequenceNumbers(void);
-
 /*
  * Athenticate functions
  */
diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c
index ee51cce..15d6ae2 100644
--- a/source/nsswitch/wbinfo.c
+++ b/source/nsswitch/wbinfo.c
@@ -174,29 +174,22 @@ static bool wbinfo_get_uidinfo(int uid)
 }
 
 /* pull grent for a given group */
-static bool wbinfo_get_groupinfo(char *group)
+static bool wbinfo_get_groupinfo(const char *group)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	NSS_STATUS result;
-
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
-
-	/* Send request */
-
-	fstrcpy(request.data.groupname, group);
-
-	result = winbindd_request_response(WINBINDD_GETGRNAM, &request,
-					   &response);
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct group *grp;
 
-	if ( result != NSS_STATUS_SUCCESS)
+	wbc_status = wbcGetgrnam(group, &grp);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
 		return false;
+	}
 
-	d_printf( "%s:%s:%d\n",
-		  response.data.gr.gr_name,
-		  response.data.gr.gr_passwd,
-		  response.data.gr.gr_gid );
+	d_printf("%s:%s:%d\n",
+		 grp->gr_name,
+		 grp->gr_passwd,
+		 grp->gr_gid);
+
+	wbcFreeMemory(grp);
 
 	return true;
 }
@@ -232,58 +225,72 @@ static bool wbinfo_get_usergroups(char *user)
 
 
 /* List group SIDs a user SID is a member of */
-static bool wbinfo_get_usersids(char *user_sid)
+static bool wbinfo_get_usersids(const char *user_sid_str)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	NSS_STATUS result;
-	int i;
-	const char *s;
-
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	uint32_t num_sids;
+	uint32_t i;
+	struct wbcDomainSid user_sid, *sids = NULL;
 
 	/* Send request */
-	fstrcpy(request.data.sid, user_sid);
 
-	result = winbindd_request_response(WINBINDD_GETUSERSIDS, &request, &response);
+	wbc_status = wbcStringToSid(user_sid_str, &user_sid);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		return false;
+	}
 
-	if (result != NSS_STATUS_SUCCESS)
+	wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
 		return false;
+	}
 
-	s = (const char *)response.extra_data.data;
-	for (i = 0; i < response.data.num_entries; i++) {
-		d_printf("%s\n", s);
-		s += strlen(s) + 1;
+	for (i = 0; i < num_sids; i++) {
+		char *str = NULL;
+		wbc_status = wbcSidToString(&sids[i], &str);
+		if (!WBC_ERROR_IS_OK(wbc_status)) {
+			wbcFreeMemory(sids);
+			return false;
+		}
+		d_printf("%s\n", str);
+		wbcFreeMemory(str);
 	}
 
-	SAFE_FREE(response.extra_data.data);
+	wbcFreeMemory(sids);
 
 	return true;
 }
 
-static bool wbinfo_get_userdomgroups(const char *user_sid)
+static bool wbinfo_get_userdomgroups(const char *user_sid_str)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	NSS_STATUS result;
-
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	uint32_t num_sids;
+	uint32_t i;
+	struct wbcDomainSid user_sid, *sids = NULL;
 
 	/* Send request */
-	fstrcpy(request.data.sid, user_sid);
 
-	result = winbindd_request_response(WINBINDD_GETUSERDOMGROUPS, &request,
-					   &response);
+	wbc_status = wbcStringToSid(user_sid_str, &user_sid);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		return false;
+	}
 
-	if (result != NSS_STATUS_SUCCESS)
+	wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
 		return false;
+	}
 
-	if (response.data.num_entries != 0)
-		printf("%s", (char *)response.extra_data.data);
+	for (i = 0; i < num_sids; i++) {
+		char *str = NULL;
+		wbc_status = wbcSidToString(&sids[i], &str);
+		if (!WBC_ERROR_IS_OK(wbc_status)) {
+			wbcFreeMemory(sids);
+			return false;
+		}
+		d_printf("%s\n", str);
+		wbcFreeMemory(str);
+	}
 
-	SAFE_FREE(response.extra_data.data);
+	wbcFreeMemory(sids);
 
 	return true;
 }
@@ -432,39 +439,46 @@ static bool wbinfo_show_sequence(const char *domain)
 
 /* Show domain info */
 
-static bool wbinfo_domain_info(const char *domain_name)
+static bool wbinfo_domain_info(const char *domain)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct wbcDomainInfo *dinfo = NULL;
+	char *sid_str = NULL;
 
-	if ((strequal(domain_name, ".")) || (domain_name[0] == '\0'))
-		fstrcpy(request.domain_name, get_winbind_domain());
-	else
-		fstrcpy(request.domain_name, domain_name);
+	if (strcmp(domain, ".") == 0 || domain[0] == '\0') {
+		domain = get_winbind_domain();
+	}
 
 	/* Send request */
 
-	if (winbindd_request_response(WINBINDD_DOMAIN_INFO, &request, &response) !=
-	    NSS_STATUS_SUCCESS)
+	wbc_status = wbcDomainInfo(domain, &dinfo);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
 		return false;
+	}
+
+	wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		wbcFreeMemory(dinfo);
+		return false;
+	}
 
 	/* Display response */
 
-	d_printf("Name              : %s\n", response.data.domain_info.name);
-	d_printf("Alt_Name          : %s\n", response.data.domain_info.alt_name);
+	d_printf("Name              : %s\n", dinfo->short_name);
+	d_printf("Alt_Name          : %s\n", dinfo->dns_name);
 
-	d_printf("SID               : %s\n", response.data.domain_info.sid);
+	d_printf("SID               : %s\n", sid_str);
 
 	d_printf("Active Directory  : %s\n",
-		 response.data.domain_info.active_directory ? "Yes" : "No");
+		 (dinfo->flags & WBC_DOMINFO_AD) ? "Yes" : "No");
 	d_printf("Native            : %s\n",
-		 response.data.domain_info.native_mode ? "Yes" : "No");
+		 (dinfo->flags & WBC_DOMINFO_NATIVE) ? "Yes" : "No");
 
 	d_printf("Primary           : %s\n",
-		 response.data.domain_info.primary ? "Yes" : "No");
+		 (dinfo->flags & WBC_DOMINFO_PRIMARY) ? "Yes" : "No");
+
+	wbcFreeMemory(sid_str);
+	wbcFreeMemory(dinfo);
 
 	return true;
 }
@@ -1060,42 +1074,28 @@ static bool wbinfo_klog(char *username)
 
 static bool print_domain_users(const char *domain)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	const char *extra_data;
-	char *name;
-	TALLOC_CTX *frame = NULL;
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	uint32_t i;
+	uint32_t num_users = 0;
+	const char **users = NULL;
 
 	/* Send request to winbind daemon */
 
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
-
-	if (domain) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list