CVE-2020-25719 kdc: Avoid races and multiple DB lookups in s4u2self check
[Samba.git] / source3 / utils / status.c
bloba92881700099320bef2fc19635a3f8c1ea5b4076
1 /*
2 Unix SMB/CIFS implementation.
3 status reporting
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/>.
19 Revision History:
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
33 #include "includes.h"
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"
41 #include "session.h"
42 #include "locking/share_mode_lock.h"
43 #include "locking/proto.h"
44 #include "messages.h"
45 #include "librpc/gen_ndr/open_files.h"
46 #include "smbd/smbd.h"
47 #include "librpc/gen_ndr/notify.h"
48 #include "conn_tdb.h"
49 #include "serverid.h"
50 #include "status_profile.h"
51 #include "smbd/notifyd/notifyd_db.h"
52 #include "cmdline_contexts.h"
53 #include "locking/leases_db.h"
54 #include "lib/util/string_wrappers.h"
56 #define SMB_MAXPIDS 2048
57 static uid_t Ucrit_uid = 0; /* added by OH */
58 static struct server_id Ucrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */
59 static int Ucrit_MaxPid=0; /* added by OH */
60 static unsigned int Ucrit_IsActive = 0; /* added by OH */
62 static bool verbose, brief;
63 static bool shares_only; /* Added by RJS */
64 static bool locks_only; /* Added by RJS */
65 static bool processes_only;
66 static bool show_brl;
67 static bool numeric_only;
68 static bool do_checks = true;
70 const char *username = NULL;
72 /* added by OH */
73 static void Ucrit_addUid(uid_t uid)
75 Ucrit_uid = uid;
76 Ucrit_IsActive = 1;
79 static unsigned int Ucrit_checkUid(uid_t uid)
81 if ( !Ucrit_IsActive )
82 return 1;
84 if ( uid == Ucrit_uid )
85 return 1;
87 return 0;
90 static unsigned int Ucrit_checkPid(struct server_id pid)
92 int i;
94 if ( !Ucrit_IsActive )
95 return 1;
97 for (i=0;i<Ucrit_MaxPid;i++) {
98 if (server_id_equal(&pid, &Ucrit_pid[i])) {
99 return 1;
103 return 0;
106 static bool Ucrit_addPid( struct server_id pid )
108 if ( !Ucrit_IsActive )
109 return True;
111 if ( Ucrit_MaxPid >= SMB_MAXPIDS ) {
112 d_printf("ERROR: More than %d pids for user %s!\n",
113 SMB_MAXPIDS, uidtoname(Ucrit_uid));
115 return False;
118 Ucrit_pid[Ucrit_MaxPid++] = pid;
120 return True;
123 static int print_share_mode(struct file_id fid,
124 const struct share_mode_data *d,
125 const struct share_mode_entry *e,
126 void *private_data)
128 bool resolve_uids = *((bool *)private_data);
129 static int count;
131 if (do_checks && !is_valid_share_mode_entry(e)) {
132 return 0;
135 if (count==0) {
136 d_printf("Locked files:\n");
137 d_printf("Pid User(ID) DenyMode Access R/W Oplock SharePath Name Time\n");
138 d_printf("--------------------------------------------------------------------------------------------------\n");
140 count++;
142 if (do_checks && !serverid_exists(&e->pid)) {
143 /* the process for this entry does not exist any more */
144 return 0;
147 if (Ucrit_checkPid(e->pid)) {
148 struct server_id_buf tmp;
149 d_printf("%-11s ", server_id_str_buf(e->pid, &tmp));
150 if (resolve_uids) {
151 d_printf("%-14s ", uidtoname(e->uid));
152 } else {
153 d_printf("%-9u ", (unsigned int)e->uid);
155 switch (map_share_mode_to_deny_mode(e->share_access,
156 e->private_options)) {
157 case DENY_NONE: d_printf("DENY_NONE "); break;
158 case DENY_ALL: d_printf("DENY_ALL "); break;
159 case DENY_DOS: d_printf("DENY_DOS "); break;
160 case DENY_READ: d_printf("DENY_READ "); break;
161 case DENY_WRITE:d_printf("DENY_WRITE "); break;
162 case DENY_FCB: d_printf("DENY_FCB "); break;
163 default: {
164 d_printf("unknown-please report ! "
165 "e->share_access = 0x%x, "
166 "e->private_options = 0x%x\n",
167 (unsigned int)e->share_access,
168 (unsigned int)e->private_options );
169 break;
172 d_printf("0x%-8x ",(unsigned int)e->access_mask);
173 if ((e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA))==
174 (FILE_READ_DATA|FILE_WRITE_DATA)) {
175 d_printf("RDWR ");
176 } else if (e->access_mask & FILE_WRITE_DATA) {
177 d_printf("WRONLY ");
178 } else {
179 d_printf("RDONLY ");
182 if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
183 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) {
184 d_printf("EXCLUSIVE+BATCH ");
185 } else if (e->op_type & EXCLUSIVE_OPLOCK) {
186 d_printf("EXCLUSIVE ");
187 } else if (e->op_type & BATCH_OPLOCK) {
188 d_printf("BATCH ");
189 } else if (e->op_type & LEVEL_II_OPLOCK) {
190 d_printf("LEVEL_II ");
191 } else if (e->op_type == LEASE_OPLOCK) {
192 NTSTATUS status;
193 uint32_t lstate;
195 status = leases_db_get(
196 &e->client_guid,
197 &e->lease_key,
198 &d->id,
199 &lstate, /* current_state */
200 NULL, /* breaking */
201 NULL, /* breaking_to_requested */
202 NULL, /* breaking_to_required */
203 NULL, /* lease_version */
204 NULL); /* epoch */
206 if (NT_STATUS_IS_OK(status)) {
207 d_printf("LEASE(%s%s%s)%s%s%s ",
208 (lstate & SMB2_LEASE_READ)?"R":"",
209 (lstate & SMB2_LEASE_WRITE)?"W":"",
210 (lstate & SMB2_LEASE_HANDLE)?"H":"",
211 (lstate & SMB2_LEASE_READ)?"":" ",
212 (lstate & SMB2_LEASE_WRITE)?"":" ",
213 (lstate & SMB2_LEASE_HANDLE)?"":" ");
214 } else {
215 d_printf("LEASE STATE UNKNOWN");
217 } else {
218 d_printf("NONE ");
221 d_printf(" %s %s%s %s",
222 d->servicepath, d->base_name,
223 (d->stream_name != NULL) ? d->stream_name : "",
224 time_to_asc((time_t)e->time.tv_sec));
227 return 0;
230 static void print_brl(struct file_id id,
231 struct server_id pid,
232 enum brl_type lock_type,
233 enum brl_flavour lock_flav,
234 br_off start,
235 br_off size,
236 void *private_data)
238 static int count;
239 unsigned int i;
240 static const struct {
241 enum brl_type lock_type;
242 const char *desc;
243 } lock_types[] = {
244 { READ_LOCK, "R" },
245 { WRITE_LOCK, "W" },
246 { UNLOCK_LOCK, "U" }
248 const char *desc="X";
249 const char *sharepath = "";
250 char *fname = NULL;
251 struct share_mode_lock *share_mode;
252 struct server_id_buf tmp;
253 struct file_id_buf ftmp;
255 if (count==0) {
256 d_printf("Byte range locks:\n");
257 d_printf("Pid dev:inode R/W start size SharePath Name\n");
258 d_printf("--------------------------------------------------------------------------------\n");
260 count++;
262 share_mode = fetch_share_mode_unlocked(NULL, id);
263 if (share_mode) {
264 fname = share_mode_filename(NULL, share_mode);
265 } else {
266 fname = talloc_strdup(NULL, "");
267 if (fname == NULL) {
268 return;
272 for (i=0;i<ARRAY_SIZE(lock_types);i++) {
273 if (lock_type == lock_types[i].lock_type) {
274 desc = lock_types[i].desc;
278 d_printf("%-10s %-15s %-4s %-9jd %-9jd %-24s %-24s\n",
279 server_id_str_buf(pid, &tmp),
280 file_id_str_buf(id, &ftmp),
281 desc,
282 (intmax_t)start, (intmax_t)size,
283 sharepath, fname);
285 TALLOC_FREE(fname);
286 TALLOC_FREE(share_mode);
289 static const char *session_dialect_str(uint16_t dialect)
291 static fstring unkown_dialect;
293 switch(dialect){
294 case SMB2_DIALECT_REVISION_000:
295 return "NT1";
296 case SMB2_DIALECT_REVISION_202:
297 return "SMB2_02";
298 case SMB2_DIALECT_REVISION_210:
299 return "SMB2_10";
300 case SMB2_DIALECT_REVISION_222:
301 return "SMB2_22";
302 case SMB2_DIALECT_REVISION_224:
303 return "SMB2_24";
304 case SMB3_DIALECT_REVISION_300:
305 return "SMB3_00";
306 case SMB3_DIALECT_REVISION_302:
307 return "SMB3_02";
308 case SMB3_DIALECT_REVISION_310:
309 return "SMB3_10";
310 case SMB3_DIALECT_REVISION_311:
311 return "SMB3_11";
314 fstr_sprintf(unkown_dialect, "Unknown (0x%04x)", dialect);
315 return unkown_dialect;
318 static int traverse_connections(const struct connections_key *key,
319 const struct connections_data *crec,
320 void *private_data)
322 TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
323 struct server_id_buf tmp;
324 char *timestr = NULL;
325 int result = 0;
326 const char *encryption = "-";
327 const char *signing = "-";
329 if (crec->cnum == TID_FIELD_INVALID)
330 return 0;
332 if (do_checks &&
333 (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid))) {
334 return 0;
337 timestr = timestring(mem_ctx, crec->start);
338 if (timestr == NULL) {
339 return -1;
342 if (smbXsrv_is_encrypted(crec->encryption_flags)) {
343 switch (crec->cipher) {
344 case SMB_ENCRYPTION_GSSAPI:
345 encryption = "GSSAPI";
346 break;
347 case SMB2_ENCRYPTION_AES128_CCM:
348 encryption = "AES-128-CCM";
349 break;
350 case SMB2_ENCRYPTION_AES128_GCM:
351 encryption = "AES-128-GCM";
352 break;
353 default:
354 encryption = "???";
355 result = -1;
356 break;
360 if (smbXsrv_is_signed(crec->signing_flags)) {
361 switch (crec->signing) {
362 case SMB2_SIGNING_MD5_SMB1:
363 signing = "HMAC-MD5";
364 break;
365 case SMB2_SIGNING_HMAC_SHA256:
366 signing = "HMAC-SHA256";
367 break;
368 case SMB2_SIGNING_AES128_CMAC:
369 signing = "AES-128-CMAC";
370 break;
371 case SMB2_SIGNING_AES128_GMAC:
372 signing = "AES-128-GMAC";
373 break;
374 default:
375 signing = "???";
376 result = -1;
377 break;
381 d_printf("%-12s %-7s %-13s %-32s %-12s %-12s\n",
382 crec->servicename, server_id_str_buf(crec->pid, &tmp),
383 crec->machine,
384 timestr,
385 encryption,
386 signing);
388 TALLOC_FREE(timestr);
390 return result;
393 static int traverse_sessionid(const char *key, struct sessionid *session,
394 void *private_data)
396 TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
397 fstring uid_gid_str;
398 struct server_id_buf tmp;
399 char *machine_hostname = NULL;
400 int result = 0;
401 const char *encryption = "-";
402 const char *signing = "-";
404 if (do_checks &&
405 (!process_exists(session->pid) ||
406 !Ucrit_checkUid(session->uid))) {
407 return 0;
410 Ucrit_addPid(session->pid);
412 if (numeric_only) {
413 fstr_sprintf(uid_gid_str, "%-12u %-12u",
414 (unsigned int)session->uid,
415 (unsigned int)session->gid);
416 } else {
417 if (session->uid == -1 && session->gid == -1) {
419 * The session is not fully authenticated yet.
421 fstrcpy(uid_gid_str, "(auth in progress)");
422 } else {
424 * In theory it should not happen that one of
425 * session->uid and session->gid is valid (ie != -1)
426 * while the other is not (ie = -1), so we a check for
427 * that case that bails out would be reasonable.
429 const char *uid_name = "-1";
430 const char *gid_name = "-1";
432 if (session->uid != -1) {
433 uid_name = uidtoname(session->uid);
434 if (uid_name == NULL) {
435 return -1;
438 if (session->gid != -1) {
439 gid_name = gidtoname(session->gid);
440 if (gid_name == NULL) {
441 return -1;
444 fstr_sprintf(uid_gid_str, "%-12s %-12s",
445 uid_name, gid_name);
449 machine_hostname = talloc_asprintf(mem_ctx, "%s (%s)",
450 session->remote_machine,
451 session->hostname);
452 if (machine_hostname == NULL) {
453 return -1;
456 if (smbXsrv_is_encrypted(session->encryption_flags)) {
457 switch (session->cipher) {
458 case SMB2_ENCRYPTION_AES128_CCM:
459 encryption = "AES-128-CCM";
460 break;
461 case SMB2_ENCRYPTION_AES128_GCM:
462 encryption = "AES-128-GCM";
463 break;
464 case SMB2_ENCRYPTION_AES256_CCM:
465 encryption = "AES-256-CCM";
466 break;
467 case SMB2_ENCRYPTION_AES256_GCM:
468 encryption = "AES-256-GCM";
469 break;
470 default:
471 encryption = "???";
472 result = -1;
473 break;
475 } else if (smbXsrv_is_partially_encrypted(session->encryption_flags)) {
476 switch (session->cipher) {
477 case SMB_ENCRYPTION_GSSAPI:
478 encryption = "partial(GSSAPI)";
479 break;
480 case SMB2_ENCRYPTION_AES128_CCM:
481 encryption = "partial(AES-128-CCM)";
482 break;
483 case SMB2_ENCRYPTION_AES128_GCM:
484 encryption = "partial(AES-128-GCM)";
485 break;
486 case SMB2_ENCRYPTION_AES256_CCM:
487 encryption = "partial(AES-256-CCM)";
488 break;
489 case SMB2_ENCRYPTION_AES256_GCM:
490 encryption = "partial(AES-256-GCM)";
491 break;
492 default:
493 encryption = "???";
494 result = -1;
495 break;
499 if (smbXsrv_is_signed(session->signing_flags)) {
500 switch (session->signing) {
501 case SMB2_SIGNING_MD5_SMB1:
502 signing = "HMAC-MD5";
503 break;
504 case SMB2_SIGNING_HMAC_SHA256:
505 signing = "HMAC-SHA256";
506 break;
507 case SMB2_SIGNING_AES128_CMAC:
508 signing = "AES-128-CMAC";
509 break;
510 case SMB2_SIGNING_AES128_GMAC:
511 signing = "AES-128-GMAC";
512 break;
513 default:
514 signing = "???";
515 result = -1;
516 break;
518 } else if (smbXsrv_is_partially_signed(session->signing_flags)) {
519 switch (session->signing) {
520 case SMB2_SIGNING_MD5_SMB1:
521 signing = "partial(HMAC-MD5)";
522 break;
523 case SMB2_SIGNING_HMAC_SHA256:
524 signing = "partial(HMAC-SHA256)";
525 break;
526 case SMB2_SIGNING_AES128_CMAC:
527 signing = "partial(AES-128-CMAC)";
528 break;
529 case SMB2_SIGNING_AES128_GMAC:
530 signing = "partial(AES-128-GMAC)";
531 break;
532 default:
533 signing = "???";
534 result = -1;
535 break;
540 d_printf("%-7s %-25s %-41s %-17s %-20s %-21s\n",
541 server_id_str_buf(session->pid, &tmp),
542 uid_gid_str,
543 machine_hostname,
544 session_dialect_str(session->connection_dialect),
545 encryption,
546 signing);
548 TALLOC_FREE(machine_hostname);
550 return result;
554 static bool print_notify_rec(const char *path, struct server_id server,
555 const struct notify_instance *instance,
556 void *private_data)
558 struct server_id_buf idbuf;
560 d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf),
561 (unsigned)instance->filter,
562 (unsigned)instance->subdir_filter);
564 return true;
567 enum {
568 OPT_RESOLVE_UIDS = 1000,
571 int main(int argc, const char *argv[])
573 int c;
574 int profile_only = 0;
575 bool show_processes, show_locks, show_shares;
576 bool show_notify = false;
577 bool resolve_uids = false;
578 poptContext pc = NULL;
579 struct poptOption long_options[] = {
580 POPT_AUTOHELP
582 .longName = "processes",
583 .shortName = 'p',
584 .argInfo = POPT_ARG_NONE,
585 .arg = NULL,
586 .val = 'p',
587 .descrip = "Show processes only",
590 .longName = "verbose",
591 .shortName = 'v',
592 .argInfo = POPT_ARG_NONE,
593 .arg = NULL,
594 .val = 'v',
595 .descrip = "Be verbose",
598 .longName = "locks",
599 .shortName = 'L',
600 .argInfo = POPT_ARG_NONE,
601 .arg = NULL,
602 .val = 'L',
603 .descrip = "Show locks only",
606 .longName = "shares",
607 .shortName = 'S',
608 .argInfo = POPT_ARG_NONE,
609 .arg = NULL,
610 .val = 'S',
611 .descrip = "Show shares only",
614 .longName = "notify",
615 .shortName = 'N',
616 .argInfo = POPT_ARG_NONE,
617 .arg = NULL,
618 .val = 'N',
619 .descrip = "Show notifies",
622 .longName = "user",
623 .shortName = 'u',
624 .argInfo = POPT_ARG_STRING,
625 .arg = &username,
626 .val = 'u',
627 .descrip = "Switch to user",
630 .longName = "brief",
631 .shortName = 'b',
632 .argInfo = POPT_ARG_NONE,
633 .arg = NULL,
634 .val = 'b',
635 .descrip = "Be brief",
638 .longName = "profile",
639 .shortName = 'P',
640 .argInfo = POPT_ARG_NONE,
641 .arg = NULL,
642 .val = 'P',
643 .descrip = "Do profiling",
646 .longName = "profile-rates",
647 .shortName = 'R',
648 .argInfo = POPT_ARG_NONE,
649 .arg = NULL,
650 .val = 'R',
651 .descrip = "Show call rates",
654 .longName = "byterange",
655 .shortName = 'B',
656 .argInfo = POPT_ARG_NONE,
657 .arg = NULL,
658 .val = 'B',
659 .descrip = "Include byte range locks"
662 .longName = "numeric",
663 .shortName = 'n',
664 .argInfo = POPT_ARG_NONE,
665 .arg = NULL,
666 .val = 'n',
667 .descrip = "Numeric uid/gid"
670 .longName = "fast",
671 .shortName = 'f',
672 .argInfo = POPT_ARG_NONE,
673 .arg = NULL,
674 .val = 'f',
675 .descrip = "Skip checks if processes still exist"
678 .longName = "resolve-uids",
679 .shortName = 0,
680 .argInfo = POPT_ARG_NONE,
681 .arg = NULL,
682 .val = OPT_RESOLVE_UIDS,
683 .descrip = "Try to resolve UIDs to usernames"
685 POPT_COMMON_SAMBA
686 POPT_COMMON_VERSION
687 POPT_TABLEEND
689 TALLOC_CTX *frame = talloc_stackframe();
690 int ret = 0;
691 struct messaging_context *msg_ctx = NULL;
692 char *db_path;
693 bool ok;
695 smb_init_locale();
697 ok = samba_cmdline_init(frame,
698 SAMBA_CMDLINE_CONFIG_CLIENT,
699 false /* require_smbconf */);
700 if (!ok) {
701 DBG_ERR("Failed to init cmdline parser!\n");
702 TALLOC_FREE(frame);
703 exit(1);
705 lp_set_cmdline("log level", "0");
707 pc = samba_popt_get_context(getprogname(),
708 argc,
709 argv,
710 long_options,
711 POPT_CONTEXT_KEEP_FIRST);
712 if (pc == NULL) {
713 DBG_ERR("Failed to setup popt context!\n");
714 TALLOC_FREE(frame);
715 exit(1);
718 while ((c = poptGetNextOpt(pc)) != -1) {
719 switch (c) {
720 case 'p':
721 processes_only = true;
722 break;
723 case 'v':
724 verbose = true;
725 break;
726 case 'L':
727 locks_only = true;
728 break;
729 case 'S':
730 shares_only = true;
731 break;
732 case 'N':
733 show_notify = true;
734 break;
735 case 'b':
736 brief = true;
737 break;
738 case 'u':
739 Ucrit_addUid(nametouid(poptGetOptArg(pc)));
740 break;
741 case 'P':
742 case 'R':
743 profile_only = c;
744 break;
745 case 'B':
746 show_brl = true;
747 break;
748 case 'n':
749 numeric_only = true;
750 break;
751 case 'f':
752 do_checks = false;
753 break;
754 case OPT_RESOLVE_UIDS:
755 resolve_uids = true;
756 break;
757 case POPT_ERROR_BADOPT:
758 fprintf(stderr, "\nInvalid option %s: %s\n\n",
759 poptBadOption(pc, 0), poptStrerror(c));
760 poptPrintUsage(pc, stderr, 0);
761 exit(1);
765 sec_init();
767 if (getuid() != geteuid()) {
768 d_printf("smbstatus should not be run setuid\n");
769 ret = 1;
770 goto done;
773 if (getuid() != 0) {
774 d_printf("smbstatus only works as root!\n");
775 ret = 1;
776 goto done;
779 /* setup the flags based on the possible combincations */
781 show_processes = !(shares_only || locks_only || profile_only) || processes_only;
782 show_locks = !(shares_only || processes_only || profile_only) || locks_only;
783 show_shares = !(processes_only || locks_only || profile_only) || shares_only;
785 if ( username )
786 Ucrit_addUid( nametouid(username) );
788 if (verbose) {
789 d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
792 msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
793 if (msg_ctx == NULL) {
794 fprintf(stderr, "Could not initialize messaging, not root?\n");
795 ret = -1;
796 goto done;
799 switch (profile_only) {
800 case 'P':
801 /* Dump profile data */
802 ok = status_profile_dump(verbose);
803 ret = ok ? 0 : 1;
804 goto done;
805 case 'R':
806 /* Continuously display rate-converted data */
807 ok = status_profile_rates(verbose);
808 ret = ok ? 0 : 1;
809 goto done;
810 default:
811 break;
814 if ( show_processes ) {
815 d_printf("\nSamba version %s\n",samba_version_string());
816 d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", "PID", "Username", "Group", "Machine", "Protocol Version", "Encryption", "Signing");
817 d_printf("----------------------------------------------------------------------------------------------------------------------------------------\n");
819 sessionid_traverse_read(traverse_sessionid, frame);
821 if (processes_only) {
822 goto done;
826 if ( show_shares ) {
827 if (brief) {
828 goto done;
831 d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
832 d_printf("---------------------------------------------------------------------------------------------\n");
834 connections_forall_read(traverse_connections, frame);
836 d_printf("\n");
838 if ( shares_only ) {
839 goto done;
843 if ( show_locks ) {
844 int result;
845 struct db_context *db;
847 db_path = lock_path(talloc_tos(), "locking.tdb");
848 if (db_path == NULL) {
849 d_printf("Out of memory - exiting\n");
850 ret = -1;
851 goto done;
854 db = db_open(NULL, db_path, 0,
855 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
856 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
858 if (!db) {
859 d_printf("%s not initialised\n", db_path);
860 d_printf("This is normal if an SMB client has never "
861 "connected to your server.\n");
862 TALLOC_FREE(db_path);
863 exit(0);
864 } else {
865 TALLOC_FREE(db);
866 TALLOC_FREE(db_path);
869 if (!locking_init_readonly()) {
870 d_printf("Can't initialise locking module - exiting\n");
871 ret = 1;
872 goto done;
875 result = share_entry_forall(print_share_mode, &resolve_uids);
877 if (result == 0) {
878 d_printf("No locked files\n");
879 } else if (result < 0) {
880 d_printf("locked file list truncated\n");
883 d_printf("\n");
885 if (show_brl) {
886 brl_forall(print_brl, NULL);
889 locking_end();
892 if (show_notify) {
893 notify_walk(msg_ctx, print_notify_rec, NULL);
896 done:
897 cmdline_messaging_context_free();
898 poptFreeContext(pc);
899 TALLOC_FREE(frame);
900 return ret;