From fcd4ae3c76ef6ca801cf833c5ae665ec00312679 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 8 Jan 2019 12:21:36 +0100 Subject: [PATCH 1/4] s3:utils: Use C99 initializer for poptOption in smbstatus Signed-off-by: Andreas Schneider Reviewed-by: Douglas Bagnall (cherry picked from commit 83d25ca9d90897925a4431dd55e68c78244900b3) --- source3/utils/status.c | 108 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 12 deletions(-) diff --git a/source3/utils/status.c b/source3/utils/status.c index 0fe2c820eb2..0acdfd3221a 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -511,18 +511,102 @@ int main(int argc, const char *argv[]) poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP - {"processes", 'p', POPT_ARG_NONE, NULL, 'p', "Show processes only" }, - {"verbose", 'v', POPT_ARG_NONE, NULL, 'v', "Be verbose" }, - {"locks", 'L', POPT_ARG_NONE, NULL, 'L', "Show locks only" }, - {"shares", 'S', POPT_ARG_NONE, NULL, 'S', "Show shares only" }, - {"notify", 'N', POPT_ARG_NONE, NULL, 'N', "Show notifies" }, - {"user", 'u', POPT_ARG_STRING, &username, 'u', "Switch to user" }, - {"brief", 'b', POPT_ARG_NONE, NULL, 'b', "Be brief" }, - {"profile", 'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" }, - {"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" }, - {"byterange", 'B', POPT_ARG_NONE, NULL, 'B', "Include byte range locks"}, - {"numeric", 'n', POPT_ARG_NONE, NULL, 'n', "Numeric uid/gid"}, - {"fast", 'f', POPT_ARG_NONE, NULL, 'f', "Skip checks if processes still exist"}, + { + .longName = "processes", + .shortName = 'p', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'p', + .descrip = "Show processes only", + }, + { + .longName = "verbose", + .shortName = 'v', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'v', + .descrip = "Be verbose", + }, + { + .longName = "locks", + .shortName = 'L', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'L', + .descrip = "Show locks only", + }, + { + .longName = "shares", + .shortName = 'S', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'S', + .descrip = "Show shares only", + }, + { + .longName = "notify", + .shortName = 'N', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'N', + .descrip = "Show notifies", + }, + { + .longName = "user", + .shortName = 'u', + .argInfo = POPT_ARG_STRING, + .arg = &username, + .val = 'u', + .descrip = "Switch to user", + }, + { + .longName = "brief", + .shortName = 'b', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'b', + .descrip = "Be brief", + }, + { + .longName = "profile", + .shortName = 'P', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'P', + .descrip = "Do profiling", + }, + { + .longName = "profile-rates", + .shortName = 'R', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'R', + .descrip = "Show call rates", + }, + { + .longName = "byterange", + .shortName = 'B', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'B', + .descrip = "Include byte range locks" + }, + { + .longName = "numeric", + .shortName = 'n', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'n', + .descrip = "Numeric uid/gid" + }, + { + .longName = "fast", + .shortName = 'f', + .argInfo = POPT_ARG_NONE, + .arg = NULL, + .val = 'f', + .descrip = "Skip checks if processes still exist" + }, POPT_COMMON_SAMBA POPT_TABLEEND }; -- 2.21.0 From bcad15e2d2ce385e553a91bb4d1697dc0beadff9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 18 Feb 2019 14:11:32 +0100 Subject: [PATCH 2/4] 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 Reviewed-by: Andrew Bartlett (cherry picked from commit ffad76ae260ac33926db87c61aede5b66d9b09e6) --- 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.21.0 From 92c09dc990fe3c065f4ee95fbd37756287706893 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 13 Mar 2019 12:00:11 +0100 Subject: [PATCH 3/4] selftest: Add smbstatus to testhelper BUG: https://bugzilla.samba.org/show_bug.cgi?id=13793 Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett (cherry picked from commit 6106b8a053e06699c332fd1a6d7636f550422cc7) --- selftest/selftesthelpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selftest/selftesthelpers.py b/selftest/selftesthelpers.py index acce6d24cce..39b8a1782c6 100644 --- a/selftest/selftesthelpers.py +++ b/selftest/selftesthelpers.py @@ -208,3 +208,4 @@ smbget = binpath('smbget') rpcclient = binpath('rpcclient') smbcacls = binpath('smbcacls') smbcontrol = binpath('smbcontrol') +smbstatus = binpath('smbstatus') -- 2.21.0 From a75b287efc896b70a05f79c5342577ec50cbd5ad Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 13 Mar 2019 12:00:27 +0100 Subject: [PATCH 4/4] s3:tests: Add test for smbstatus and smbstatus --resolve_uids BUG: https://bugzilla.samba.org/show_bug.cgi?id=13793 Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Wed Mar 27 14:33:35 UTC 2019 on sn-devel-144 (cherry picked from commit 2e7f4b1d3701b9da32e03dcee1095711945f22b8) --- source3/script/tests/test_smbstatus.sh | 155 +++++++++++++++++++++++++ source3/selftest/tests.py | 6 +- 2 files changed, 160 insertions(+), 1 deletion(-) create mode 100755 source3/script/tests/test_smbstatus.sh diff --git a/source3/script/tests/test_smbstatus.sh b/source3/script/tests/test_smbstatus.sh new file mode 100755 index 00000000000..b29ba15c377 --- /dev/null +++ b/source3/script/tests/test_smbstatus.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +# This runs smbstatus tests + +if [ $# -lt 12 ]; then + echo "Usage: test_smbstatus.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT CONFIGURATION PROTOCOL" + exit 1 +fi + +SERVER="${1}" +SERVER_IP="${2}" +DOMAIN="${3}" +USERNAME="${4}" +PASSWORD="${5}" +USERID="${6}" +LOCAL_PATH="${7}" +PREFIX="${8}" +SMBCLIENT="${9}" +SMBSTATUS="${10}" +CONFIGURATION="${11}" +PROTOCOL="${12}" + +shift 12 + +RAWARGS="${CONFIGURATION} -m${PROTOCOL}" +ADDARGS="${RAWARGS} $@" + +incdir=`dirname $0`/../../../testprogs/blackbox +. $incdir/subunit.sh + +failed=0 + +test_smbstatus() +{ + local cmdfile=$PREFIX/smbclient_commands + local tmpfile=$PREFIX/smclient_lock_file + local file=smclient_lock_file + local cmd="" + local ret=0 + local userid=$(id -u $USERNAME) + + cat > $tmpfile < $cmdfile < $tmpfile < $cmdfile <