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

Jeremy Allison jra at samba.org
Wed Oct 29 16:54:06 GMT 2008


The branch, v3-3-test has been updated
       via  edb1e08c04175e7758ce9a9c250747d9184c5624 (commit)
       via  6176fbc116a8ebd608dcee1693f758126ca4124f (commit)
      from  4528d0b5b32ab4cbbc2d5b09cd0d49062120e50b (commit)

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


- Log -----------------------------------------------------------------
commit edb1e08c04175e7758ce9a9c250747d9184c5624
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Oct 29 09:53:20 2008 -0700

    wbinfo --sid-to-fullname
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 6176fbc116a8ebd608dcee1693f758126ca4124f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Oct 29 09:43:41 2008 -0700

    wbcGetDisplayName
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 source/nsswitch/libwbclient/wbc_sid.c  |   44 ++++++++++++++++++++++++++++++++
 source/nsswitch/libwbclient/wbclient.h |    5 +++
 source/nsswitch/wbinfo.c               |   42 +++++++++++++++++++++++++++++-
 3 files changed, 90 insertions(+), 1 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/nsswitch/libwbclient/wbc_sid.c b/source/nsswitch/libwbclient/wbc_sid.c
index 4cfdd79..9c886df 100644
--- a/source/nsswitch/libwbclient/wbc_sid.c
+++ b/source/nsswitch/libwbclient/wbc_sid.c
@@ -675,3 +675,47 @@ wbcErr wbcListGroups(const char *domain_name,
 	}
 	return wbc_status;
 }
+
+wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
+			 char **pdomain,
+			 char **pfullname,
+			 enum wbcSidType *pname_type)
+{
+	wbcErr wbc_status;
+	char *domain = NULL;
+	char *name = NULL;
+	enum wbcSidType name_type;
+
+	wbc_status = wbcLookupSid(sid, &domain, &name, &name_type);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	if (name_type == WBC_SID_NAME_USER) {
+		uid_t uid;
+		struct passwd *pwd;
+
+		wbc_status = wbcSidToUid(sid, &uid);
+		BAIL_ON_WBC_ERROR(wbc_status);
+
+		wbc_status = wbcGetpwuid(uid, &pwd);
+		BAIL_ON_WBC_ERROR(wbc_status);
+
+		wbcFreeMemory(name);
+
+		name = talloc_strdup(NULL, pwd->pw_gecos);
+		BAIL_ON_PTR_ERROR(name, wbc_status);
+	}
+
+	wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+	if (WBC_ERROR_IS_OK(wbc_status)) {
+		*pdomain = domain;
+		*pfullname = name;
+		*pname_type = name_type;
+	} else {
+		wbcFreeMemory(domain);
+		wbcFreeMemory(name);
+	}
+
+	return wbc_status;
+}
diff --git a/source/nsswitch/libwbclient/wbclient.h b/source/nsswitch/libwbclient/wbclient.h
index cae3fee..1789e8e 100644
--- a/source/nsswitch/libwbclient/wbclient.h
+++ b/source/nsswitch/libwbclient/wbclient.h
@@ -438,6 +438,11 @@ wbcErr wbcListGroups(const char *domain_name,
 		     uint32_t *num_groups,
 		     const char ***groups);
 
+wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
+			 char **pdomain,
+			 char **pfullname,
+			 enum wbcSidType *pname_type);
+
 /*
  * SID/uid/gid Mappings
  */
diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c
index 60524d1..cee8cc3 100644
--- a/source/nsswitch/wbinfo.c
+++ b/source/nsswitch/wbinfo.c
@@ -760,6 +760,36 @@ static bool wbinfo_lookupsid(const char *sid_str)
 	return true;
 }
 
+/* Convert sid to fullname */
+
+static bool wbinfo_lookupsid_fullname(const char *sid_str)
+{
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct wbcDomainSid sid;
+	char *domain;
+	char *name;
+	enum wbcSidType type;
+
+	/* Send off request */
+
+	wbc_status = wbcStringToSid(sid_str, &sid);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		return false;
+	}
+
+	wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
+		return false;
+	}
+
+	/* Display response */
+
+	d_printf("%s%c%s %d\n",
+		 domain, winbind_separator(), name, type);
+
+	return true;
+}
+
 /* Lookup a list of RIDs */
 
 static bool wbinfo_lookuprids(const char *domain, const char *arg)
@@ -1383,7 +1413,8 @@ enum {
 	OPT_GROUP_INFO,
 	OPT_VERBOSE,
 	OPT_ONLINESTATUS,
-	OPT_CHANGE_USER_PASSWORD
+	OPT_CHANGE_USER_PASSWORD,
+	OPT_SID_TO_FULLNAME
 };
 
 int main(int argc, char **argv, char **envp)
@@ -1409,6 +1440,8 @@ int main(int argc, char **argv, char **envp)
 		{ "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
 		{ "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
 		{ "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
+		{ "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
+		  OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
 		{ "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
 		{ "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
 		{ "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
@@ -1516,6 +1549,13 @@ int main(int argc, char **argv, char **envp)
 				goto done;
 			}
 			break;
+		case OPT_SID_TO_FULLNAME:
+			if (!wbinfo_lookupsid_fullname(string_arg)) {
+				d_fprintf(stderr, "Could not lookup sid %s\n",
+					  string_arg);
+				goto done;
+			}
+			break;
 		case 'R':
 			if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
 				d_fprintf(stderr, "Could not lookup RIDs %s\n", string_arg);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list