2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 12 aug 96: Erik.Devriendt@te6.siemens.be
22 added support for shared memory implementation of share mode locking
24 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe)
25 Added -L (locks only) -S (shares only) flags and code
30 * This program reports current SMB connections
34 #include "lib/util/server_id.h"
35 #include "smbd/globals.h"
36 #include "system/filesys.h"
37 #include "lib/cmdline/cmdline.h"
38 #include "dbwrap/dbwrap.h"
39 #include "dbwrap/dbwrap_open.h"
40 #include "../libcli/security/security.h"
42 #include "locking/share_mode_lock.h"
43 #include "locking/proto.h"
45 #include "librpc/gen_ndr/open_files.h"
46 #include "smbd/smbd.h"
47 #include "librpc/gen_ndr/notify.h"
50 #include "status_profile.h"
52 #include "status_json.h"
53 #include "smbd/notifyd/notifyd_db.h"
54 #include "cmdline_contexts.h"
55 #include "locking/leases_db.h"
56 #include "lib/util/string_wrappers.h"
60 #include "audit_logging.h" /* various JSON helpers */
61 #include "auth/common_auth.h"
62 #endif /* HAVE_JANSSON */
64 #define SMB_MAXPIDS 2048
65 static uid_t Ucrit_uid = 0; /* added by OH */
66 static struct server_id Ucrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */
67 static int Ucrit_MaxPid=0; /* added by OH */
68 static unsigned int Ucrit_IsActive = 0; /* added by OH */
70 static bool verbose, brief;
71 static bool shares_only; /* Added by RJS */
72 static bool locks_only; /* Added by RJS */
73 static bool processes_only;
75 static bool numeric_only;
76 static bool do_checks = true;
78 const char *username = NULL;
81 static void Ucrit_addUid(uid_t uid)
87 static unsigned int Ucrit_checkUid(uid_t uid)
89 if ( !Ucrit_IsActive )
92 if ( uid == Ucrit_uid )
98 static unsigned int Ucrit_checkPid(struct server_id pid)
102 if ( !Ucrit_IsActive )
105 for (i=0;i<Ucrit_MaxPid;i++) {
106 if (server_id_equal(&pid, &Ucrit_pid[i])) {
114 static bool Ucrit_addPid( struct server_id pid )
116 if ( !Ucrit_IsActive )
119 if ( Ucrit_MaxPid >= SMB_MAXPIDS ) {
120 fprintf(stderr, "ERROR: More than %d pids for user %s!\n",
121 SMB_MAXPIDS, uidtoname(Ucrit_uid));
126 Ucrit_pid[Ucrit_MaxPid++] = pid;
131 static int print_share_mode_stdout(struct traverse_state *state,
133 const char *user_name,
134 const char *denymode,
138 const char *servicepath,
139 const char *filename,
143 d_printf("\nLocked files:\n");
144 d_printf("Pid User(ID) DenyMode Access R/W Oplock SharePath Name Time\n");
145 d_printf("--------------------------------------------------------------------------------------------------\n");
147 state->first = false;
150 d_printf("%-11s %-9s %-10s 0x%-8x %-10s %-14s %s %s %s",
151 pid, user_name, denymode, access_mask, rw, oplock,
152 servicepath, filename, timestr);
156 static int prepare_share_mode(struct traverse_state *state)
158 if (!state->json_output) {
159 /* only print header line if there are open files */
162 add_section_to_json(state, "open_files");
167 static uint32_t map_share_mode_to_deny_mode(
168 uint32_t share_access, uint32_t private_options)
170 switch (share_access & ~FILE_SHARE_DELETE) {
171 case FILE_SHARE_NONE:
173 case FILE_SHARE_READ:
175 case FILE_SHARE_WRITE:
177 case FILE_SHARE_READ|FILE_SHARE_WRITE:
180 if (private_options & NTCREATEX_FLAG_DENY_DOS) {
182 } else if (private_options & NTCREATEX_FLAG_DENY_FCB) {
189 static int print_share_mode(struct file_id fid,
190 const struct share_mode_data *d,
191 const struct share_mode_entry *e,
194 const char *denymode = NULL;
196 const char *oplock = NULL;
197 const char *pid = NULL;
198 const char *rw = NULL;
199 const char *filename = NULL;
200 const char *timestr = NULL;
201 const char *user_str = NULL;
203 struct traverse_state *state = (struct traverse_state *)private_data;
205 TALLOC_CTX *tmp_ctx = talloc_stackframe();
206 if (tmp_ctx == NULL) {
210 if (do_checks && !is_valid_share_mode_entry(e)) {
211 TALLOC_FREE(tmp_ctx);
215 if (do_checks && !serverid_exists(&e->pid)) {
216 /* the process for this entry does not exist any more */
217 TALLOC_FREE(tmp_ctx);
221 if (Ucrit_checkPid(e->pid)) {
222 struct server_id_buf tmp;
223 pid = server_id_str_buf(e->pid, &tmp);
224 if (state->resolve_uids) {
225 user_str = talloc_asprintf(tmp_ctx, "%s", uidtoname(e->uid));
227 user_str = talloc_asprintf(tmp_ctx, "%u", (unsigned int)e->uid);
229 if (user_str == NULL) {
230 TALLOC_FREE(tmp_ctx);
234 denymode_int = map_share_mode_to_deny_mode(e->share_access,
236 switch (denymode_int) {
238 denymode = "DENY_NONE";
241 denymode = "DENY_ALL";
244 denymode = "DENY_DOS";
247 denymode = "DENY_READ";
250 denymode = "DENY_WRITE";
253 denymode = "DENY_FCB";
256 denymode = talloc_asprintf(tmp_ctx,
259 if (denymode == NULL) {
260 TALLOC_FREE(tmp_ctx);
264 "unknown-please report ! "
265 "e->share_access = 0x%x, "
266 "e->private_options = 0x%x\n",
267 (unsigned int)e->share_access,
268 (unsigned int)e->private_options);
272 filename = talloc_asprintf(tmp_ctx,
275 (d->stream_name != NULL) ? d->stream_name : "");
276 if (filename == NULL) {
277 TALLOC_FREE(tmp_ctx);
280 if ((e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA))==
281 (FILE_READ_DATA|FILE_WRITE_DATA)) {
283 } else if (e->access_mask & FILE_WRITE_DATA) {
289 if (e->op_type & BATCH_OPLOCK) {
291 } else if (e->op_type & EXCLUSIVE_OPLOCK) {
292 oplock = "EXCLUSIVE";
293 } else if (e->op_type & LEVEL_II_OPLOCK) {
295 } else if (e->op_type == LEASE_OPLOCK) {
298 status = leases_db_get(
302 &lstate, /* current_state */
304 NULL, /* breaking_to_requested */
305 NULL, /* breaking_to_required */
306 NULL, /* lease_version */
309 if (NT_STATUS_IS_OK(status)) {
310 oplock = talloc_asprintf(tmp_ctx, "LEASE(%s%s%s)%s%s%s",
311 (lstate & SMB2_LEASE_READ)?"R":"",
312 (lstate & SMB2_LEASE_WRITE)?"W":"",
313 (lstate & SMB2_LEASE_HANDLE)?"H":"",
314 (lstate & SMB2_LEASE_READ)?"":" ",
315 (lstate & SMB2_LEASE_WRITE)?"":" ",
316 (lstate & SMB2_LEASE_HANDLE)?"":" ");
318 oplock = "LEASE STATE UNKNOWN";
324 timestr = time_to_asc((time_t)e->time.tv_sec);
326 if (!state->json_output) {
327 print_share_mode_stdout(state,
331 (unsigned int)e->access_mask,
338 print_share_mode_json(state,
348 TALLOC_FREE(tmp_ctx);
352 static void print_brl_stdout(struct traverse_state *state,
358 const char *sharepath,
362 d_printf("Byte range locks:\n");
363 d_printf("Pid dev:inode R/W start size SharePath Name\n");
364 d_printf("--------------------------------------------------------------------------------\n");
366 state->first = false;
368 d_printf("%-10s %-15s %-4s %-9jd %-9jd %-24s %-24s\n",
369 pid, id, desc, start, size, sharepath, fname);
372 static int prepare_brl(struct traverse_state *state)
374 if (!state->json_output) {
375 /* only print header line if there are locked files */
378 add_section_to_json(state, "byte_range_locks");
383 static void print_brl(struct file_id id,
384 struct server_id pid,
385 enum brl_type lock_type,
386 enum brl_flavour lock_flav,
392 static const struct {
393 enum brl_type lock_type;
400 const char *desc="X";
401 const char *sharepath = "";
403 struct share_mode_lock *share_mode;
404 struct server_id_buf tmp;
405 struct file_id_buf ftmp;
406 struct traverse_state *state = (struct traverse_state *)private_data;
408 share_mode = fetch_share_mode_unlocked(NULL, id);
410 fname = share_mode_filename(NULL, share_mode);
411 sharepath = share_mode_servicepath(share_mode);
413 fname = talloc_strdup(NULL, "");
419 for (i=0;i<ARRAY_SIZE(lock_types);i++) {
420 if (lock_type == lock_types[i].lock_type) {
421 desc = lock_types[i].desc;
425 if (!state->json_output) {
426 print_brl_stdout(state,
427 server_id_str_buf(pid, &tmp),
428 file_id_str_buf(id, &ftmp),
435 print_brl_json(state,
448 TALLOC_FREE(share_mode);
451 static const char *session_dialect_str(uint16_t dialect)
453 static fstring unknown_dialect;
456 case SMB2_DIALECT_REVISION_000:
458 case SMB2_DIALECT_REVISION_202:
460 case SMB2_DIALECT_REVISION_210:
462 case SMB2_DIALECT_REVISION_222:
464 case SMB2_DIALECT_REVISION_224:
466 case SMB3_DIALECT_REVISION_300:
468 case SMB3_DIALECT_REVISION_302:
470 case SMB3_DIALECT_REVISION_310:
472 case SMB3_DIALECT_REVISION_311:
476 fstr_sprintf(unknown_dialect, "Unknown (0x%04x)", dialect);
477 return unknown_dialect;
480 static int traverse_connections_stdout(struct traverse_state *state,
481 const char *servicename,
485 const char *encryption,
488 d_printf("%-12s %-7s %-13s %-32s %-12s %-12s\n",
489 servicename, server_id, machine, timestr, encryption, signing);
494 static int prepare_connections(struct traverse_state *state)
496 if (!state->json_output) {
497 /* always print header line */
498 d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
499 d_printf("---------------------------------------------------------------------------------------------\n");
501 add_section_to_json(state, "tcons");
506 static int traverse_connections(const struct connections_data *crec,
509 struct server_id_buf tmp;
510 char *timestr = NULL;
512 const char *encryption = "-";
513 enum crypto_degree encryption_degree = CRYPTO_DEGREE_NONE;
514 const char *signing = "-";
515 enum crypto_degree signing_degree = CRYPTO_DEGREE_NONE;
516 struct traverse_state *state = (struct traverse_state *)private_data;
518 TALLOC_CTX *tmp_ctx = talloc_stackframe();
519 if (tmp_ctx == NULL) {
523 if (crec->cnum == TID_FIELD_INVALID) {
524 TALLOC_FREE(tmp_ctx);
529 (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid))) {
530 TALLOC_FREE(tmp_ctx);
534 timestr = timestring(tmp_ctx, nt_time_to_unix(crec->start));
535 if (timestr == NULL) {
536 TALLOC_FREE(tmp_ctx);
540 if (smbXsrv_is_encrypted(crec->encryption_flags)) {
541 switch (crec->cipher) {
542 case SMB_ENCRYPTION_GSSAPI:
543 encryption = "GSSAPI";
545 case SMB2_ENCRYPTION_AES128_CCM:
546 encryption = "AES-128-CCM";
548 case SMB2_ENCRYPTION_AES128_GCM:
549 encryption = "AES-128-GCM";
555 encryption_degree = CRYPTO_DEGREE_FULL;
558 if (smbXsrv_is_signed(crec->signing_flags)) {
559 switch (crec->signing) {
560 case SMB2_SIGNING_MD5_SMB1:
561 signing = "HMAC-MD5";
563 case SMB2_SIGNING_HMAC_SHA256:
564 signing = "HMAC-SHA256";
566 case SMB2_SIGNING_AES128_CMAC:
567 signing = "AES-128-CMAC";
569 case SMB2_SIGNING_AES128_GMAC:
570 signing = "AES-128-GMAC";
576 signing_degree = CRYPTO_DEGREE_FULL;
579 if (!state->json_output) {
580 result = traverse_connections_stdout(state,
582 server_id_str_buf(crec->pid, &tmp),
588 result = traverse_connections_json(state,
596 TALLOC_FREE(timestr);
597 TALLOC_FREE(tmp_ctx);
602 static int traverse_sessionid_stdout(struct traverse_state *state,
605 char *machine_hostname,
607 const char *encryption_cipher,
608 enum crypto_degree encryption_degree,
609 const char *signing_cipher,
610 enum crypto_degree signing_degree)
615 if (encryption_degree == CRYPTO_DEGREE_FULL) {
616 fstr_sprintf(encryption, "%s", encryption_cipher);
617 } else if (encryption_degree == CRYPTO_DEGREE_PARTIAL) {
618 fstr_sprintf(encryption, "partial(%s)", encryption_cipher);
620 fstr_sprintf(encryption, "-");
622 if (signing_degree == CRYPTO_DEGREE_FULL) {
623 fstr_sprintf(signing, "%s", signing_cipher);
624 } else if (signing_degree == CRYPTO_DEGREE_PARTIAL) {
625 fstr_sprintf(signing, "partial(%s)", signing_cipher);
627 fstr_sprintf(signing, "-");
630 d_printf("%-7s %-25s %-41s %-17s %-20s %-21s\n",
631 server_id, uid_gid_str, machine_hostname, dialect, encryption,
637 static int prepare_sessionid(struct traverse_state *state)
639 if (!state->json_output) {
640 /* always print header line */
641 d_printf("\nSamba version %s\n",samba_version_string());
642 d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", "PID", "Username", "Group", "Machine", "Protocol Version", "Encryption", "Signing");
643 d_printf("----------------------------------------------------------------------------------------------------------------------------------------\n");
645 add_section_to_json(state, "sessions");
651 static int traverse_sessionid(const char *key, struct sessionid *session,
657 struct server_id_buf tmp;
658 char *machine_hostname = NULL;
660 const char *encryption = "-";
661 enum crypto_degree encryption_degree = CRYPTO_DEGREE_NONE;
662 const char *signing = "-";
663 enum crypto_degree signing_degree = CRYPTO_DEGREE_NONE;
664 struct traverse_state *state = (struct traverse_state *)private_data;
666 TALLOC_CTX *tmp_ctx = talloc_stackframe();
667 if (tmp_ctx == NULL) {
672 (!process_exists(session->pid) ||
673 !Ucrit_checkUid(session->uid))) {
674 TALLOC_FREE(tmp_ctx);
678 Ucrit_addPid(session->pid);
681 fstr_sprintf(gid_str, "%u", (unsigned int)session->gid);
682 fstr_sprintf(uid_str, "%u", (unsigned int)session->uid);
683 fstr_sprintf(uid_gid_str, "%-12u %-12u",
684 (unsigned int)session->uid,
685 (unsigned int)session->gid);
687 if (session->uid == -1 && session->gid == -1) {
689 * The session is not fully authenticated yet.
691 fstrcpy(uid_gid_str, "(auth in progress)");
692 fstrcpy(gid_str, "(auth in progress)");
693 fstrcpy(uid_str, "(auth in progress)");
696 * In theory it should not happen that one of
697 * session->uid and session->gid is valid (ie != -1)
698 * while the other is not (ie = -1), so we a check for
699 * that case that bails out would be reasonable.
701 const char *uid_name = "-1";
702 const char *gid_name = "-1";
704 if (session->uid != -1) {
705 uid_name = uidtoname(session->uid);
706 if (uid_name == NULL) {
707 TALLOC_FREE(tmp_ctx);
711 if (session->gid != -1) {
712 gid_name = gidtoname(session->gid);
713 if (gid_name == NULL) {
714 TALLOC_FREE(tmp_ctx);
718 fstr_sprintf(gid_str, "%s", gid_name);
719 fstr_sprintf(uid_str, "%s", uid_name);
720 fstr_sprintf(uid_gid_str, "%-12s %-12s",
725 machine_hostname = talloc_asprintf(tmp_ctx, "%s (%s)",
726 session->remote_machine,
728 if (machine_hostname == NULL) {
729 TALLOC_FREE(tmp_ctx);
733 if (smbXsrv_is_encrypted(session->encryption_flags) ||
734 smbXsrv_is_partially_encrypted(session->encryption_flags)) {
735 switch (session->cipher) {
736 case SMB2_ENCRYPTION_AES128_CCM:
737 encryption = "AES-128-CCM";
739 case SMB2_ENCRYPTION_AES128_GCM:
740 encryption = "AES-128-GCM";
742 case SMB2_ENCRYPTION_AES256_CCM:
743 encryption = "AES-256-CCM";
745 case SMB2_ENCRYPTION_AES256_GCM:
746 encryption = "AES-256-GCM";
753 if (smbXsrv_is_encrypted(session->encryption_flags)) {
754 encryption_degree = CRYPTO_DEGREE_FULL;
755 } else if (smbXsrv_is_partially_encrypted(session->encryption_flags)) {
756 encryption_degree = CRYPTO_DEGREE_PARTIAL;
760 if (smbXsrv_is_signed(session->signing_flags) ||
761 smbXsrv_is_partially_signed(session->signing_flags)) {
762 switch (session->signing) {
763 case SMB2_SIGNING_MD5_SMB1:
764 signing = "HMAC-MD5";
766 case SMB2_SIGNING_HMAC_SHA256:
767 signing = "HMAC-SHA256";
769 case SMB2_SIGNING_AES128_CMAC:
770 signing = "AES-128-CMAC";
772 case SMB2_SIGNING_AES128_GMAC:
773 signing = "AES-128-GMAC";
780 if (smbXsrv_is_signed(session->signing_flags)) {
781 signing_degree = CRYPTO_DEGREE_FULL;
782 } else if (smbXsrv_is_partially_signed(session->signing_flags)) {
783 signing_degree = CRYPTO_DEGREE_PARTIAL;
788 if (!state->json_output) {
789 traverse_sessionid_stdout(state,
790 server_id_str_buf(session->pid, &tmp),
793 session_dialect_str(session->connection_dialect),
799 result = traverse_sessionid_json(state,
807 session_dialect_str(session->connection_dialect));
810 TALLOC_FREE(machine_hostname);
811 TALLOC_FREE(tmp_ctx);
817 static bool print_notify_rec_stdout(struct traverse_state *state,
821 unsigned subdir_filter)
823 d_printf("%s\\%s\\%x\\%x\n", path, server_id_str,
824 filter, subdir_filter);
829 static int prepare_notify(struct traverse_state *state)
831 if (!state->json_output) {
832 /* don't print header line */
834 add_section_to_json(state, "notifies");
839 static bool print_notify_rec(const char *path, struct server_id server,
840 const struct notify_instance *instance,
843 struct server_id_buf idbuf;
844 struct traverse_state *state = (struct traverse_state *)private_data;
847 if (!state->json_output) {
848 result = print_notify_rec_stdout(state,
850 server_id_str_buf(server, &idbuf),
851 (unsigned)instance->filter,
852 (unsigned)instance->subdir_filter);
855 result = print_notify_rec_json(state,
865 OPT_RESOLVE_UIDS = 1000,
868 int main(int argc, const char *argv[])
871 int profile_only = 0;
872 bool show_processes, show_locks, show_shares;
873 bool show_notify = false;
874 poptContext pc = NULL;
875 struct traverse_state state = {0};
876 struct poptOption long_options[] = {
879 .longName = "processes",
881 .argInfo = POPT_ARG_NONE,
884 .descrip = "Show processes only",
887 .longName = "verbose",
889 .argInfo = POPT_ARG_NONE,
892 .descrip = "Be verbose",
897 .argInfo = POPT_ARG_NONE,
900 .descrip = "Show locks only",
903 .longName = "shares",
905 .argInfo = POPT_ARG_NONE,
908 .descrip = "Show shares only",
911 .longName = "notify",
913 .argInfo = POPT_ARG_NONE,
916 .descrip = "Show notifies",
921 .argInfo = POPT_ARG_STRING,
924 .descrip = "Switch to user",
929 .argInfo = POPT_ARG_NONE,
932 .descrip = "Be brief",
935 .longName = "profile",
937 .argInfo = POPT_ARG_NONE,
940 .descrip = "Do profiling",
943 .longName = "profile-rates",
945 .argInfo = POPT_ARG_NONE,
948 .descrip = "Show call rates",
951 .longName = "byterange",
953 .argInfo = POPT_ARG_NONE,
956 .descrip = "Include byte range locks"
959 .longName = "numeric",
961 .argInfo = POPT_ARG_NONE,
964 .descrip = "Numeric uid/gid"
969 .argInfo = POPT_ARG_NONE,
972 .descrip = "JSON output"
977 .argInfo = POPT_ARG_NONE,
980 .descrip = "Skip checks if processes still exist"
983 .longName = "resolve-uids",
985 .argInfo = POPT_ARG_NONE,
987 .val = OPT_RESOLVE_UIDS,
988 .descrip = "Try to resolve UIDs to usernames"
994 TALLOC_CTX *frame = talloc_stackframe();
996 struct messaging_context *msg_ctx = NULL;
1001 state.json_output = false;
1002 state.resolve_uids = false;
1006 ok = samba_cmdline_init(frame,
1007 SAMBA_CMDLINE_CONFIG_CLIENT,
1008 false /* require_smbconf */);
1010 DBG_ERR("Failed to init cmdline parser!\n");
1014 lp_set_cmdline("log level", "0");
1016 pc = samba_popt_get_context(getprogname(),
1020 POPT_CONTEXT_KEEP_FIRST);
1022 DBG_ERR("Failed to setup popt context!\n");
1027 while ((c = poptGetNextOpt(pc)) != -1) {
1030 processes_only = true;
1048 Ucrit_addUid(nametouid(poptGetOptArg(pc)));
1058 numeric_only = true;
1061 state.json_output = true;
1066 case OPT_RESOLVE_UIDS:
1067 state.resolve_uids = true;
1069 case POPT_ERROR_BADOPT:
1070 fprintf(stderr, "\nInvalid option %s: %s\n\n",
1071 poptBadOption(pc, 0), poptStrerror(c));
1072 poptPrintUsage(pc, stderr, 0);
1080 state.root_json = json_new_object();
1081 if (!json_is_invalid(&state.root_json)) {
1082 add_general_information_to_json(&state);
1084 #else /* HAVE_JANSSON */
1085 if (state.json_output) {
1086 fprintf(stderr, "JSON support not available, please install lib Jansson\n");
1089 #endif /* HAVE_JANSSON */
1091 if (getuid() != geteuid()) {
1092 fprintf(stderr, "smbstatus should not be run setuid\n");
1097 if (getuid() != 0) {
1098 fprintf(stderr, "smbstatus only works as root!\n");
1103 /* setup the flags based on the possible combincations */
1105 show_processes = !(shares_only || locks_only || profile_only) || processes_only;
1106 show_locks = !(shares_only || processes_only || profile_only) || locks_only;
1107 show_shares = !(processes_only || locks_only || profile_only) || shares_only;
1110 Ucrit_addUid( nametouid(username) );
1112 if (verbose && !state.json_output) {
1113 d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
1116 msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
1117 if (msg_ctx == NULL) {
1118 fprintf(stderr, "Could not initialize messaging, not root?\n");
1123 switch (profile_only) {
1125 /* Dump profile data */
1126 ok = status_profile_dump(verbose, &state);
1130 /* Continuously display rate-converted data */
1131 if (!state.json_output) {
1132 ok = status_profile_rates(verbose);
1135 fprintf(stderr, "Call rates not available in a json output.\n");
1143 if ( show_processes ) {
1144 prepare_sessionid(&state);
1145 sessionid_traverse_read(traverse_sessionid, &state);
1147 if (processes_only) {
1152 if ( show_shares ) {
1156 prepare_connections(&state);
1157 connections_forall_read(traverse_connections, &state);
1159 if (!state.json_output) {
1163 if ( shares_only ) {
1170 struct db_context *db;
1172 db_path = lock_path(talloc_tos(), "locking.tdb");
1173 if (db_path == NULL) {
1174 fprintf(stderr, "Out of memory - exiting\n");
1179 db = db_open(NULL, db_path, 0,
1180 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
1181 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
1184 fprintf(stderr, "%s not initialised\n", db_path);
1185 fprintf(stderr, "This is normal if an SMB client has never "
1186 "connected to your server.\n");
1187 TALLOC_FREE(db_path);
1192 TALLOC_FREE(db_path);
1195 if (!locking_init_readonly()) {
1196 fprintf(stderr, "Can't initialise locking module - exiting\n");
1201 prepare_share_mode(&state);
1202 result = share_entry_forall(print_share_mode, &state);
1204 if (result == 0 && !state.json_output) {
1205 fprintf(stderr, "No locked files\n");
1206 } else if (result < 0 && !state.json_output) {
1207 fprintf(stderr, "locked file list truncated\n");
1210 if (!state.json_output) {
1215 prepare_brl(&state);
1216 brl_forall(print_brl, &state);
1223 prepare_notify(&state);
1224 notify_walk(msg_ctx, print_notify_rec, &state);
1228 cmdline_messaging_context_free();
1229 poptFreeContext(pc);
1231 if (state.json_output) {
1232 d_printf("%s\n", json_to_string(frame, &state.root_json));
1234 json_free(&state.root_json);
1235 #endif /* HAVE_JANSSON */