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>
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 #include "utils/net.h"
22 #include "locking/proto.h"
23 #include "librpc/gen_ndr/open_files.h"
24 #include "librpc/gen_ndr/ndr_open_files.h"
26 static int net_tdb_locking_dump(TALLOC_CTX *mem_ctx,
27 struct share_mode_data *data)
29 struct ndr_print *ndr_print;
31 ndr_print = talloc_zero(mem_ctx, struct ndr_print);
32 if (ndr_print == NULL) {
33 d_printf("Could not allocate memory.\n");
37 ndr_print->print = ndr_print_printf_helper;
39 ndr_print_share_mode_data(ndr_print, "SHARE_MODE_DATA", data);
40 TALLOC_FREE(ndr_print);
45 static int net_tdb_locking_fetch(TALLOC_CTX *mem_ctx, const char *hexkey,
46 struct share_mode_lock **lock)
52 blob = strhex_to_data_blob(mem_ctx, hexkey);
53 if (blob.length != sizeof(struct file_id)) {
54 d_printf("Invalid length of key\n");
58 id = *(struct file_id *)blob.data;
60 ok = locking_init_readonly();
62 d_printf("locking_init_readonly failed\n");
66 *lock = fetch_share_mode_unlocked(mem_ctx, id);
69 d_printf("Record with key %s not found.\n", hexkey);
76 static int net_tdb_locking(struct net_context *c, int argc, const char **argv)
78 TALLOC_CTX *mem_ctx = talloc_stackframe();
79 struct share_mode_lock *lock;
83 d_printf("Usage: net tdb locking <key> [ dump ]\n");
88 ret = net_tdb_locking_fetch(mem_ctx, argv[0], &lock);
93 if (argc == 2 && strequal(argv[1], "dump")) {
94 ret = net_tdb_locking_dump(mem_ctx, lock->data);
96 d_printf("Share path: %s\n", lock->data->servicepath);
97 d_printf("Name: %s\n", lock->data->base_name);
98 d_printf("Number of share modes: %" PRIu32 "\n",
99 lock->data->num_share_modes);
103 TALLOC_FREE(mem_ctx);
107 int net_tdb(struct net_context *c, int argc, const char **argv)
109 struct functable func[] = {
113 N_("Show information for a record in locking.tdb"),
114 N_("net tdb locking <key>")
116 {NULL, NULL, 0, NULL, NULL}
119 return net_run_function(c, argc, argv, "net tdb", func);