[PATCH] Add '--resolve-uids' option to smbstatus

Andreas Schneider asn at samba.org
Mon Feb 18 16:18:15 UTC 2019


Hi,

I got a request to add an option to resolve uids into usernames for 'smbstatus 
-L' the attached patch adds an option to do so.

The attached patch implements that.


Review much appreciated.


Thanks,


	Andreas

-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
-------------- next part --------------
>From abd44f089c61e7cf332d24a9ca8d8ae22211bf2e Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 18 Feb 2019 14:11:32 +0100
Subject: [PATCH] s3:utils: Add 'smbstatus -L --resolve-uids' to show usernames

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13793

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source3/utils/status.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/source3/utils/status.c b/source3/utils/status.c
index 0acdfd3221a..d18033778dc 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -122,6 +122,7 @@ static int print_share_mode(struct file_id fid,
 			    const struct share_mode_entry *e,
 			    void *private_data)
 {
+	bool resolve_uids = *((bool *)private_data);
 	static int count;
 
 	if (do_checks && !is_valid_share_mode_entry(e)) {
@@ -130,7 +131,7 @@ static int print_share_mode(struct file_id fid,
 
 	if (count==0) {
 		d_printf("Locked files:\n");
-		d_printf("Pid          Uid        DenyMode   Access      R/W        Oplock           SharePath   Name   Time\n");
+		d_printf("Pid          User(ID)   DenyMode   Access      R/W        Oplock           SharePath   Name   Time\n");
 		d_printf("--------------------------------------------------------------------------------------------------\n");
 	}
 	count++;
@@ -143,7 +144,11 @@ static int print_share_mode(struct file_id fid,
 	if (Ucrit_checkPid(e->pid)) {
 		struct server_id_buf tmp;
 		d_printf("%-11s  ", server_id_str_buf(e->pid, &tmp));
-		d_printf("%-9u  ", (unsigned int)e->uid);
+		if (resolve_uids) {
+			d_printf("%-14s  ", uidtoname(e->uid));
+		} else {
+			d_printf("%-9u  ", (unsigned int)e->uid);
+		}
 		switch (map_share_mode_to_deny_mode(e->share_access,
 						    e->private_options)) {
 			case DENY_NONE: d_printf("DENY_NONE  "); break;
@@ -502,12 +507,17 @@ static bool print_notify_rec(const char *path, struct server_id server,
 	return true;
 }
 
+enum {
+	OPT_RESOLVE_UIDS = 1000,
+};
+
 int main(int argc, const char *argv[])
 {
 	int c;
 	int profile_only = 0;
 	bool show_processes, show_locks, show_shares;
 	bool show_notify = false;
+	bool resolve_uids = false;
 	poptContext pc;
 	struct poptOption long_options[] = {
 		POPT_AUTOHELP
@@ -607,6 +617,14 @@ int main(int argc, const char *argv[])
 			.val        = 'f',
 			.descrip    = "Skip checks if processes still exist"
 		},
+		{
+			.longName   = "resolve-uids",
+			.shortName  = 0,
+			.argInfo    = POPT_ARG_NONE,
+			.arg        = NULL,
+			.val        = OPT_RESOLVE_UIDS,
+			.descrip    = "Try to resolve UIDs to usernames"
+		},
 		POPT_COMMON_SAMBA
 		POPT_TABLEEND
 	};
@@ -674,6 +692,9 @@ int main(int argc, const char *argv[])
 		case 'f':
 			do_checks = false;
 			break;
+		case OPT_RESOLVE_UIDS:
+			resolve_uids = true;
+			break;
 		}
 	}
 
@@ -778,7 +799,7 @@ int main(int argc, const char *argv[])
 			goto done;
 		}
 
-		result = share_entry_forall(print_share_mode, NULL);
+		result = share_entry_forall(print_share_mode, &resolve_uids);
 
 		if (result == 0) {
 			d_printf("No locked files\n");
-- 
2.20.1



More information about the samba-technical mailing list