WBinfo Update

Esh, Andrew AEsh at tricord.com
Wed Aug 15 19:12:59 GMT 2001


Here is a patch for nsswitch/wbinfo.c which adds the -N argument, which
converts a uid to a name. It even works.

--- wbinfo.c	Wed Aug 15 14:08:24 2001
+++ wbinfo.c.new	Wed Aug 15 14:08:07 2001
@@ -137,6 +137,31 @@
 	return True;
 }
 
+/* Convert uid to pwnam */
+
+static BOOL wbinfo_uid_to_pwnam(uid_t uid)
+{
+	struct winbindd_request request;
+	struct winbindd_response response;
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	/* Send request */
+
+	request.data.uid = uid;
+	if (winbindd_request(WINBINDD_GETPWNAM_FROM_UID, &request,
&response) ==
+	    WINBINDD_ERROR) {
+		return False;
+	}
+
+	/* Display response */
+
+	printf("%s\n", response.data.pw.pw_name);
+
+	return True;
+}
+
 /* Convert gid to sid */
 
 static BOOL wbinfo_gid_to_sid(gid_t gid)
@@ -322,12 +347,13 @@
 
 static void usage(void)
 {
-	printf("Usage: wbinfo -ug | -n name | -sSY sid | -UG uid/gid |
-tm\n");
+	printf("Usage: wbinfo -ug | -n name | -sSY sid | -UGN uid/gid |
-tm\n");
 	printf("\t-u\tlists all domain users\n");
 	printf("\t-g\tlists all domain groups\n");
 	printf("\t-n name\tconverts name to sid\n");
 	printf("\t-s sid\tconverts sid to name\n");
 	printf("\t-U uid\tconverts uid to sid\n");
+	printf("\t-N uid\tconverts uid to name\n");
 	printf("\t-G gid\tconverts gid to sid\n");
 	printf("\t-S sid\tconverts sid to uid\n");
 	printf("\t-Y sid\tconverts sid to gid\n");
@@ -371,7 +397,7 @@
 		return 1;
 	}
 
-	while ((opt = getopt(argc, argv, "ugs:n:U:G:S:Y:tmr:")) != EOF) {
+	while ((opt = getopt(argc, argv, "ugs:n:U:N:G:S:Y:tmr:")) != EOF) {
 		switch (opt) {
 		case 'u':
 			if (!print_domain_users()) {
@@ -400,6 +426,13 @@
 		case 'U':
 			if (!wbinfo_uid_to_sid(atoi(optarg))) {
 				printf("Could not convert uid %s to sid\n",
+				       optarg);
+				return 1;
+			}
+			break;
+		case 'N':
+			if (!wbinfo_uid_to_pwnam(atoi(optarg))) {
+				printf("Could not convert uid %s to
pwnam\n",
 				       optarg);
 				return 1;
 			}


---
Andrew C. Esh                mail:Andrew.Esh at tricord.com
Tricord Systems, Inc.
2905 Northwest Blvd., Suite 20        763-557-9005 (main)
Plymouth, MN 55441-2644 USA      763-551-6418 (direct)
http://www.tricord.com - Tricord Home Page


-------------- next part --------------
HTML attachment scrubbed and removed


More information about the samba-technical mailing list