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