LCOV - code coverage report
Current view: top level - source3/utils - net_tdb.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 30 43 69.8 %
Date: 2024-02-28 12:06:22 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Samba Unix/Linux client library
       3             :  * net tdb commands to query tdb record information
       4             :  * Copyright (C) 2016, 2017 Christof Schmitt <cs@samba.org>
       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             : 
      20             : #include "includes.h"
      21             : #include "utils/net.h"
      22             : #include "locking/share_mode_lock.h"
      23             : #include "locking/proto.h"
      24             : #include "librpc/gen_ndr/open_files.h"
      25             : #include "librpc/gen_ndr/ndr_open_files.h"
      26             : 
      27          16 : static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
      28             : {
      29          16 :         TALLOC_CTX *mem_ctx = talloc_stackframe();
      30           0 :         struct share_mode_lock *lock;
      31          16 :         DATA_BLOB blob = { .data = NULL };
      32          16 :         struct file_id id = { .inode = 0 };
      33          16 :         int ret = -1;
      34           0 :         bool ok;
      35             : 
      36          16 :         if (argc < 1) {
      37           0 :                 d_printf("Usage: net tdb locking <key> [ dump ]\n");
      38           0 :                 goto out;
      39             :         }
      40             : 
      41          16 :         ok = locking_init_readonly();
      42          16 :         if (!ok) {
      43           0 :                 d_printf("locking_init_readonly failed\n");
      44           0 :                 goto out;
      45             :         }
      46             : 
      47          16 :         blob = strhex_to_data_blob(mem_ctx, argv[0]);
      48          16 :         if (blob.length != sizeof(struct file_id)) {
      49           0 :                 d_printf("Invalid length %zu of key, expected %zu\n",
      50             :                          blob.length,
      51             :                          sizeof(struct file_id));
      52           0 :                 goto out;
      53             :         }
      54             : 
      55          16 :         memcpy(&id, blob.data, blob.length);
      56             : 
      57          16 :         lock = fetch_share_mode_unlocked(mem_ctx, id);
      58          16 :         if (lock == NULL) {
      59           0 :                 d_printf("Record with key %s not found.\n", argv[1]);
      60           0 :                 goto out;
      61             :         }
      62             : 
      63          22 :         if (argc == 2 && strequal(argv[1], "dump")) {
      64           6 :                 char *dump = share_mode_data_dump(mem_ctx, lock);
      65           6 :                 d_printf("%s\n", dump);
      66           6 :                 TALLOC_FREE(dump);
      67             :         } else {
      68           0 :                 NTSTATUS status;
      69          10 :                 size_t num_share_modes = 0;
      70             : 
      71          10 :                 status = share_mode_count_entries(id, &num_share_modes);
      72          10 :                 if (!NT_STATUS_IS_OK(status)) {
      73           0 :                         d_fprintf(stderr,
      74             :                                   "Could not count share entries: %s\n",
      75             :                                   nt_errstr(status));
      76           0 :                         goto out;
      77             :                 }
      78             : 
      79          10 :                 d_printf("Share path:            %s\n",
      80             :                          share_mode_servicepath(lock));
      81          10 :                 d_printf("Name:                  %s\n",
      82             :                          share_mode_filename(mem_ctx, lock));
      83          10 :                 d_printf("Number of share modes: %zu\n", num_share_modes);
      84             :         }
      85             : 
      86          16 :         ret = 0;
      87          16 : out:
      88          16 :         TALLOC_FREE(mem_ctx);
      89          16 :         return ret;
      90             : }
      91             : 
      92          16 : int net_tdb(struct net_context *c, int argc, const char **argv)
      93             : {
      94          16 :         struct functable func[] = {
      95             :                 { "locking",
      96             :                   net_tdb_locking,
      97             :                   NET_TRANSPORT_LOCAL,
      98             :                   N_("Show information for a record in locking.tdb"),
      99             :                   N_("net tdb locking <key>")
     100             :                 },
     101             :                 {NULL, NULL, 0, NULL, NULL}
     102             :         };
     103             : 
     104          16 :         return net_run_function(c, argc, argv, "net tdb", func);
     105             : }

Generated by: LCOV version 1.14