6370f7002e8b80b61b6b7f4281b8e64445fe421e
[kai/samba-autobuild/.git] / source3 / utils / status.c
1 /* 
2    Unix SMB/CIFS implementation.
3    status reporting
4    Copyright (C) Andrew Tridgell 1994-1998
5
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.
10
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.
15
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/>.
18
19    Revision History:
20
21    12 aug 96: Erik.Devriendt@te6.siemens.be
22    added support for shared memory implementation of share mode locking
23
24    21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe)
25    Added -L (locks only) -S (shares only) flags and code
26
27 */
28
29 /*
30  * This program reports current SMB connections
31  */
32
33 #include "includes.h"
34 #include "lib/util/server_id.h"
35 #include "smbd/globals.h"
36 #include "system/filesys.h"
37 #include "popt_common.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/proto.h"
43 #include "messages.h"
44 #include "librpc/gen_ndr/open_files.h"
45 #include "smbd/smbd.h"
46 #include "librpc/gen_ndr/notify.h"
47 #include "lib/conn_tdb.h"
48 #include "serverid.h"
49 #include "status_profile.h"
50 #include "smbd/notifyd/notifyd.h"
51
52 #define SMB_MAXPIDS             2048
53 static uid_t            Ucrit_uid = 0;               /* added by OH */
54 static struct server_id Ucrit_pid[SMB_MAXPIDS];  /* Ugly !!! */   /* added by OH */
55 static int              Ucrit_MaxPid=0;                    /* added by OH */
56 static unsigned int     Ucrit_IsActive = 0;                /* added by OH */
57
58 static bool verbose, brief;
59 static bool shares_only;            /* Added by RJS */
60 static bool locks_only;            /* Added by RJS */
61 static bool processes_only;
62 static bool show_brl;
63 static bool numeric_only;
64 static bool do_checks = true;
65
66 const char *username = NULL;
67
68 /* added by OH */
69 static void Ucrit_addUid(uid_t uid)
70 {
71         Ucrit_uid = uid;
72         Ucrit_IsActive = 1;
73 }
74
75 static unsigned int Ucrit_checkUid(uid_t uid)
76 {
77         if ( !Ucrit_IsActive ) 
78                 return 1;
79
80         if ( uid == Ucrit_uid ) 
81                 return 1;
82
83         return 0;
84 }
85
86 static unsigned int Ucrit_checkPid(struct server_id pid)
87 {
88         int i;
89
90         if ( !Ucrit_IsActive ) 
91                 return 1;
92
93         for (i=0;i<Ucrit_MaxPid;i++) {
94                 if (serverid_equal(&pid, &Ucrit_pid[i])) {
95                         return 1;
96                 }
97         }
98
99         return 0;
100 }
101
102 static bool Ucrit_addPid( struct server_id pid )
103 {
104         if ( !Ucrit_IsActive )
105                 return True;
106
107         if ( Ucrit_MaxPid >= SMB_MAXPIDS ) {
108                 d_printf("ERROR: More than %d pids for user %s!\n",
109                          SMB_MAXPIDS, uidtoname(Ucrit_uid));
110
111                 return False;
112         }
113
114         Ucrit_pid[Ucrit_MaxPid++] = pid;
115
116         return True;
117 }
118
119 static int print_share_mode(const struct share_mode_entry *e,
120                             const struct file_id *id,
121                             const char *sharepath,
122                             const char *fname,
123                             const char *sname,
124                             void *dummy)
125 {
126         static int count;
127
128         if (do_checks && !is_valid_share_mode_entry(e)) {
129                 return 0;
130         }
131
132         if (count==0) {
133                 d_printf("Locked files:\n");
134                 d_printf("Pid          Uid        DenyMode   Access      R/W        Oplock           SharePath   Name   Time\n");
135                 d_printf("--------------------------------------------------------------------------------------------------\n");
136         }
137         count++;
138
139         if (do_checks && !serverid_exists(&e->pid)) {
140                 /* the process for this entry does not exist any more */
141                 return 0;
142         }
143
144         if (Ucrit_checkPid(e->pid)) {
145                 struct server_id_buf tmp;
146                 d_printf("%-11s  ", server_id_str_buf(e->pid, &tmp));
147                 d_printf("%-9u  ", (unsigned int)e->uid);
148                 switch (map_share_mode_to_deny_mode(e->share_access,
149                                                     e->private_options)) {
150                         case DENY_NONE: d_printf("DENY_NONE  "); break;
151                         case DENY_ALL:  d_printf("DENY_ALL   "); break;
152                         case DENY_DOS:  d_printf("DENY_DOS   "); break;
153                         case DENY_READ: d_printf("DENY_READ  "); break;
154                         case DENY_WRITE:printf("DENY_WRITE "); break;
155                         case DENY_FCB:  d_printf("DENY_FCB "); break;
156                         default: {
157                                 d_printf("unknown-please report ! "
158                                          "e->share_access = 0x%x, "
159                                          "e->private_options = 0x%x\n",
160                                          (unsigned int)e->share_access,
161                                          (unsigned int)e->private_options );
162                                 break;
163                         }
164                 }
165                 d_printf("0x%-8x  ",(unsigned int)e->access_mask);
166                 if ((e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA))==
167                                 (FILE_READ_DATA|FILE_WRITE_DATA)) {
168                         d_printf("RDWR       ");
169                 } else if (e->access_mask & FILE_WRITE_DATA) {
170                         d_printf("WRONLY     ");
171                 } else {
172                         d_printf("RDONLY     ");
173                 }
174
175                 if((e->op_type & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == 
176                                         (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) {
177                         d_printf("EXCLUSIVE+BATCH ");
178                 } else if (e->op_type & EXCLUSIVE_OPLOCK) {
179                         d_printf("EXCLUSIVE       ");
180                 } else if (e->op_type & BATCH_OPLOCK) {
181                         d_printf("BATCH           ");
182                 } else if (e->op_type & LEVEL_II_OPLOCK) {
183                         d_printf("LEVEL_II        ");
184                 } else if (e->op_type == LEASE_OPLOCK) {
185                         uint32_t lstate = e->lease->current_state;
186                         d_printf("LEASE(%s%s%s)%s%s%s      ",
187                                  (lstate & SMB2_LEASE_READ)?"R":"",
188                                  (lstate & SMB2_LEASE_WRITE)?"W":"",
189                                  (lstate & SMB2_LEASE_HANDLE)?"H":"",
190                                  (lstate & SMB2_LEASE_READ)?"":" ",
191                                  (lstate & SMB2_LEASE_WRITE)?"":" ",
192                                  (lstate & SMB2_LEASE_HANDLE)?"":" ");
193                 } else {
194                         d_printf("NONE            ");
195                 }
196
197                 d_printf(" %s   %s%s   %s",
198                          sharepath, fname,
199                          sname ? sname : "",
200                          time_to_asc((time_t)e->time.tv_sec));
201         }
202
203         return 0;
204 }
205
206 static void print_brl(struct file_id id,
207                         struct server_id pid, 
208                         enum brl_type lock_type,
209                         enum brl_flavour lock_flav,
210                         br_off start,
211                         br_off size,
212                         void *private_data)
213 {
214         static int count;
215         unsigned int i;
216         static const struct {
217                 enum brl_type lock_type;
218                 const char *desc;
219         } lock_types[] = {
220                 { READ_LOCK, "R" },
221                 { WRITE_LOCK, "W" },
222                 { PENDING_READ_LOCK, "PR" },
223                 { PENDING_WRITE_LOCK, "PW" },
224                 { UNLOCK_LOCK, "U" }
225         };
226         const char *desc="X";
227         const char *sharepath = "";
228         char *fname = NULL;
229         struct share_mode_lock *share_mode;
230         struct server_id_buf tmp;
231
232         if (count==0) {
233                 d_printf("Byte range locks:\n");
234                 d_printf("Pid        dev:inode       R/W  start     size      SharePath               Name\n");
235                 d_printf("--------------------------------------------------------------------------------\n");
236         }
237         count++;
238
239         share_mode = fetch_share_mode_unlocked(NULL, id);
240         if (share_mode) {
241                 bool has_stream = share_mode->data->stream_name != NULL;
242
243                 fname = talloc_asprintf(NULL, "%s%s%s",
244                                         share_mode->data->base_name,
245                                         has_stream ? ":" : "",
246                                         has_stream ?
247                                         share_mode->data->stream_name :
248                                         "");
249         } else {
250                 fname = talloc_strdup(NULL, "");
251                 if (fname == NULL) {
252                         return;
253                 }
254         }
255
256         for (i=0;i<ARRAY_SIZE(lock_types);i++) {
257                 if (lock_type == lock_types[i].lock_type) {
258                         desc = lock_types[i].desc;
259                 }
260         }
261
262         d_printf("%-10s %-15s %-4s %-9jd %-9jd %-24s %-24s\n",
263                  server_id_str_buf(pid, &tmp), file_id_string_tos(&id),
264                  desc,
265                  (intmax_t)start, (intmax_t)size,
266                  sharepath, fname);
267
268         TALLOC_FREE(fname);
269         TALLOC_FREE(share_mode);
270 }
271
272 static const char *session_dialect_str(uint16_t dialect)
273 {
274         static fstring unkown_dialect;
275
276         switch(dialect){
277         case SMB2_DIALECT_REVISION_000:
278                 return "NT1";
279         case SMB2_DIALECT_REVISION_202:
280                 return "SMB2_02";
281         case SMB2_DIALECT_REVISION_210:
282                 return "SMB2_10";
283         case SMB2_DIALECT_REVISION_222:
284                 return "SMB2_22";
285         case SMB2_DIALECT_REVISION_224:
286                 return "SMB2_24";
287         case SMB3_DIALECT_REVISION_300:
288                 return "SMB3_00";
289         case SMB3_DIALECT_REVISION_302:
290                 return "SMB3_02";
291         case SMB3_DIALECT_REVISION_310:
292                 return "SMB3_10";
293         case SMB3_DIALECT_REVISION_311:
294                 return "SMB3_11";
295         }
296
297         fstr_sprintf(unkown_dialect, "Unknown (0x%04x)", dialect);
298         return unkown_dialect;
299 }
300
301 static int traverse_connections(const struct connections_key *key,
302                                 const struct connections_data *crec,
303                                 void *private_data)
304 {
305         TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
306         struct server_id_buf tmp;
307         char *timestr = NULL;
308         int result = 0;
309         const char *encryption = "-";
310         const char *signing = "-";
311
312         if (crec->cnum == TID_FIELD_INVALID)
313                 return 0;
314
315         if (do_checks &&
316             (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid))) {
317                 return 0;
318         }
319
320         timestr = timestring(mem_ctx, crec->start);
321         if (timestr == NULL) {
322                 return -1;
323         }
324
325         if (smbXsrv_is_encrypted(crec->encryption_flags)) {
326                 switch (crec->cipher) {
327                 case SMB_ENCRYPTION_GSSAPI:
328                         encryption = "GSSAPI";
329                         break;
330                 case SMB2_ENCRYPTION_AES128_CCM:
331                         encryption = "AES-128-CCM";
332                         break;
333                 case SMB2_ENCRYPTION_AES128_GCM:
334                         encryption = "AES-128-GCM";
335                         break;
336                 default:
337                         encryption = "???";
338                         result = -1;
339                         break;
340                 }
341         }
342
343         if (smbXsrv_is_signed(crec->signing_flags)) {
344                 if (crec->dialect >= SMB3_DIALECT_REVISION_302) {
345                         signing = "AES-128-CMAC";
346                 } else if (crec->dialect >= SMB2_DIALECT_REVISION_202) {
347                         signing = "HMAC-SHA256";
348                 } else {
349                         signing = "HMAC-MD5";
350                 }
351         }
352
353         d_printf("%-12s %-7s %-13s %-32s %-12s %-12s\n",
354                  crec->servicename, server_id_str_buf(crec->pid, &tmp),
355                  crec->machine,
356                  timestr,
357                  encryption,
358                  signing);
359
360         TALLOC_FREE(timestr);
361
362         return result;
363 }
364
365 static int traverse_sessionid(const char *key, struct sessionid *session,
366                               void *private_data)
367 {
368         TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
369         fstring uid_gid_str;
370         struct server_id_buf tmp;
371         char *machine_hostname = NULL;
372         int result = 0;
373         const char *encryption = "-";
374         const char *signing = "-";
375
376         if (do_checks &&
377             (!process_exists(session->pid) ||
378              !Ucrit_checkUid(session->uid))) {
379                 return 0;
380         }
381
382         Ucrit_addPid(session->pid);
383
384         if (numeric_only) {
385                 fstr_sprintf(uid_gid_str, "%-12u %-12u",
386                              (unsigned int)session->uid,
387                              (unsigned int)session->gid);
388         } else {
389                 if (session->uid == -1 && session->gid == -1) {
390                         /*
391                          * The session is not fully authenticated yet.
392                          */
393                         fstrcpy(uid_gid_str, "(auth in progress)");
394                 } else {
395                         /*
396                          * In theory it should not happen that one of
397                          * session->uid and session->gid is valid (ie != -1)
398                          * while the other is not (ie = -1), so we a check for
399                          * that case that bails out would be reasonable.
400                          */
401                         const char *uid_name = "-1";
402                         const char *gid_name = "-1";
403
404                         if (session->uid != -1) {
405                                 uid_name = uidtoname(session->uid);
406                                 if (uid_name == NULL) {
407                                         return -1;
408                                 }
409                         }
410                         if (session->gid != -1) {
411                                 gid_name = gidtoname(session->gid);
412                                 if (gid_name == NULL) {
413                                         return -1;
414                                 }
415                         }
416                         fstr_sprintf(uid_gid_str, "%-12s %-12s",
417                                      uid_name, gid_name);
418                 }
419         }
420
421         machine_hostname = talloc_asprintf(mem_ctx, "%s (%s)",
422                                            session->remote_machine,
423                                            session->hostname);
424         if (machine_hostname == NULL) {
425                 return -1;
426         }
427
428         if (smbXsrv_is_encrypted(session->encryption_flags)) {
429                 switch (session->cipher) {
430                 case SMB2_ENCRYPTION_AES128_CCM:
431                         encryption = "AES-128-CCM";
432                         break;
433                 case SMB2_ENCRYPTION_AES128_GCM:
434                         encryption = "AES-128-GCM";
435                         break;
436                 default:
437                         encryption = "???";
438                         result = -1;
439                         break;
440                 }
441         } else if (smbXsrv_is_partially_encrypted(session->encryption_flags)) {
442                 switch (session->cipher) {
443                 case SMB_ENCRYPTION_GSSAPI:
444                         encryption = "partial(GSSAPI)";
445                         break;
446                 case SMB2_ENCRYPTION_AES128_CCM:
447                         encryption = "partial(AES-128-CCM)";
448                         break;
449                 case SMB2_ENCRYPTION_AES128_GCM:
450                         encryption = "partial(AES-128-GCM)";
451                         break;
452                 default:
453                         encryption = "???";
454                         result = -1;
455                         break;
456                 }
457         }
458
459         if (smbXsrv_is_signed(session->signing_flags)) {
460                 if (session->connection_dialect >= SMB3_DIALECT_REVISION_302) {
461                         signing = "AES-128-CMAC";
462                 } else if (session->connection_dialect >= SMB2_DIALECT_REVISION_202) {
463                         signing = "HMAC-SHA256";
464                 } else {
465                         signing = "HMAC-MD5";
466                 }
467         } else if (smbXsrv_is_partially_signed(session->signing_flags)) {
468                 if (session->connection_dialect >= SMB3_DIALECT_REVISION_302) {
469                         signing = "partial(AES-128-CMAC)";
470                 } else if (session->connection_dialect >= SMB2_DIALECT_REVISION_202) {
471                         signing = "partial(HMAC-SHA256)";
472                 } else {
473                         signing = "partial(HMAC-MD5)";
474                 }
475         }
476
477
478         d_printf("%-7s %-25s %-41s %-17s %-20s %-21s\n",
479                  server_id_str_buf(session->pid, &tmp),
480                  uid_gid_str,
481                  machine_hostname,
482                  session_dialect_str(session->connection_dialect),
483                  encryption,
484                  signing);
485
486         TALLOC_FREE(machine_hostname);
487
488         return result;
489 }
490
491
492 static bool print_notify_rec(const char *path, struct server_id server,
493                              const struct notify_instance *instance,
494                              void *private_data)
495 {
496         struct server_id_buf idbuf;
497
498         d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf),
499                  (unsigned)instance->filter,
500                  (unsigned)instance->subdir_filter);
501
502         return true;
503 }
504
505 int main(int argc, const char *argv[])
506 {
507         int c;
508         int profile_only = 0;
509         bool show_processes, show_locks, show_shares;
510         bool show_notify = false;
511         poptContext pc;
512         struct poptOption long_options[] = {
513                 POPT_AUTOHELP
514                 {"processes",   'p', POPT_ARG_NONE,     NULL, 'p', "Show processes only" },
515                 {"verbose",     'v', POPT_ARG_NONE,     NULL, 'v', "Be verbose" },
516                 {"locks",       'L', POPT_ARG_NONE,     NULL, 'L', "Show locks only" },
517                 {"shares",      'S', POPT_ARG_NONE,     NULL, 'S', "Show shares only" },
518                 {"notify",      'N', POPT_ARG_NONE,     NULL, 'N', "Show notifies" },
519                 {"user",        'u', POPT_ARG_STRING,   &username, 'u', "Switch to user" },
520                 {"brief",       'b', POPT_ARG_NONE,     NULL, 'b', "Be brief" },
521                 {"profile",     'P', POPT_ARG_NONE, NULL, 'P', "Do profiling" },
522                 {"profile-rates", 'R', POPT_ARG_NONE, NULL, 'R', "Show call rates" },
523                 {"byterange",   'B', POPT_ARG_NONE,     NULL, 'B', "Include byte range locks"},
524                 {"numeric",     'n', POPT_ARG_NONE,     NULL, 'n', "Numeric uid/gid"},
525                 {"fast",        'f', POPT_ARG_NONE,     NULL, 'f', "Skip checks if processes still exist"},
526                 POPT_COMMON_SAMBA
527                 POPT_TABLEEND
528         };
529         TALLOC_CTX *frame = talloc_stackframe();
530         int ret = 0;
531         struct tevent_context *ev;
532         struct messaging_context *msg_ctx = NULL;
533         char *db_path;
534         bool ok;
535
536         sec_init();
537         smb_init_locale();
538
539         setup_logging(argv[0], DEBUG_STDERR);
540         lp_set_cmdline("log level", "0");
541
542         if (getuid() != geteuid()) {
543                 d_printf("smbstatus should not be run setuid\n");
544                 ret = 1;
545                 goto done;
546         }
547
548         if (getuid() != 0) {
549                 d_printf("smbstatus only works as root!\n");
550                 ret = 1;
551                 goto done;
552         }
553
554
555         pc = poptGetContext(NULL, argc, argv, long_options,
556                             POPT_CONTEXT_KEEP_FIRST);
557
558         while ((c = poptGetNextOpt(pc)) != -1) {
559                 switch (c) {
560                 case 'p':
561                         processes_only = true;
562                         break;
563                 case 'v':
564                         verbose = true;
565                         break;
566                 case 'L':
567                         locks_only = true;
568                         break;
569                 case 'S':
570                         shares_only = true;
571                         break;
572                 case 'N':
573                         show_notify = true;
574                         break;
575                 case 'b':
576                         brief = true;
577                         break;
578                 case 'u':
579                         Ucrit_addUid(nametouid(poptGetOptArg(pc)));
580                         break;
581                 case 'P':
582                 case 'R':
583                         profile_only = c;
584                         break;
585                 case 'B':
586                         show_brl = true;
587                         break;
588                 case 'n':
589                         numeric_only = true;
590                         break;
591                 case 'f':
592                         do_checks = false;
593                         break;
594                 }
595         }
596
597         /* setup the flags based on the possible combincations */
598
599         show_processes = !(shares_only || locks_only || profile_only) || processes_only;
600         show_locks     = !(shares_only || processes_only || profile_only) || locks_only;
601         show_shares    = !(processes_only || locks_only || profile_only) || shares_only;
602
603         if ( username )
604                 Ucrit_addUid( nametouid(username) );
605
606         if (verbose) {
607                 d_printf("using configfile = %s\n", get_dyn_CONFIGFILE());
608         }
609
610         if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
611                 fprintf(stderr, "Can't load %s - run testparm to debug it\n",
612                         get_dyn_CONFIGFILE());
613                 ret = -1;
614                 goto done;
615         }
616
617
618         /*
619          * This implicitly initializes the global ctdbd connection,
620          * usable by the db_open() calls further down.
621          */
622         ev = samba_tevent_context_init(NULL);
623         if (ev == NULL) {
624                 fprintf(stderr, "samba_tevent_context_init failed\n");
625                 ret = -1;
626                 goto done;
627         }
628
629         msg_ctx = messaging_init(NULL, ev);
630         if (msg_ctx == NULL) {
631                 fprintf(stderr, "messaging_init failed\n");
632                 ret = -1;
633                 goto done;
634         }
635
636         if (!lp_load_global(get_dyn_CONFIGFILE())) {
637                 fprintf(stderr, "Can't load %s - run testparm to debug it\n",
638                         get_dyn_CONFIGFILE());
639                 ret = -1;
640                 goto done;
641         }
642
643         switch (profile_only) {
644                 case 'P':
645                         /* Dump profile data */
646                         ok = status_profile_dump(verbose);
647                         return ok ? 0 : 1;
648                 case 'R':
649                         /* Continuously display rate-converted data */
650                         ok = status_profile_rates(verbose);
651                         return ok ? 0 : 1;
652                 default:
653                         break;
654         }
655
656         if ( show_processes ) {
657                 d_printf("\nSamba version %s\n",samba_version_string());
658                 d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n", "PID", "Username", "Group", "Machine", "Protocol Version", "Encryption", "Signing");
659                 d_printf("----------------------------------------------------------------------------------------------------------------------------------------\n");
660
661                 sessionid_traverse_read(traverse_sessionid, frame);
662
663                 if (processes_only) {
664                         goto done;
665                 }
666         }
667
668         if ( show_shares ) {
669                 if (brief) {
670                         goto done;
671                 }
672
673                 d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
674                 d_printf("---------------------------------------------------------------------------------------------\n");
675
676                 connections_forall_read(traverse_connections, frame);
677
678                 d_printf("\n");
679
680                 if ( shares_only ) {
681                         goto done;
682                 }
683         }
684
685         if ( show_locks ) {
686                 int result;
687                 struct db_context *db;
688
689                 db_path = lock_path("locking.tdb");
690                 if (db_path == NULL) {
691                         d_printf("Out of memory - exiting\n");
692                         ret = -1;
693                         goto done;
694                 }
695
696                 db = db_open(NULL, db_path, 0,
697                              TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
698                              DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
699
700                 if (!db) {
701                         d_printf("%s not initialised\n", db_path);
702                         d_printf("This is normal if an SMB client has never "
703                                  "connected to your server.\n");
704                         TALLOC_FREE(db_path);
705                         exit(0);
706                 } else {
707                         TALLOC_FREE(db);
708                         TALLOC_FREE(db_path);
709                 }
710
711                 if (!locking_init_readonly()) {
712                         d_printf("Can't initialise locking module - exiting\n");
713                         ret = 1;
714                         goto done;
715                 }
716
717                 result = share_entry_forall(print_share_mode, NULL);
718
719                 if (result == 0) {
720                         d_printf("No locked files\n");
721                 } else if (result < 0) {
722                         d_printf("locked file list truncated\n");
723                 }
724
725                 d_printf("\n");
726
727                 if (show_brl) {
728                         brl_forall(print_brl, NULL);
729                 }
730
731                 locking_end();
732         }
733
734         if (show_notify) {
735                 struct notify_context *n;
736
737                 n = notify_init(talloc_tos(), msg_ctx,
738                                 messaging_tevent_context(msg_ctx),
739                                 NULL, NULL);
740                 if (n == NULL) {
741                         goto done;
742                 }
743                 notify_walk(n, print_notify_rec, NULL);
744                 TALLOC_FREE(n);
745         }
746
747 done:
748         TALLOC_FREE(frame);
749         return ret;
750 }