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 %zu of key, expected %zu\n",
56 sizeof(struct file_id
));
60 id
= *(struct file_id
*)blob
.data
;
62 ok
= locking_init_readonly();
64 d_printf("locking_init_readonly failed\n");
68 *lock
= fetch_share_mode_unlocked(mem_ctx
, id
);
71 d_printf("Record with key %s not found.\n", hexkey
);
78 static int net_tdb_locking(struct net_context
*c
, int argc
, const char **argv
)
80 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
81 struct share_mode_lock
*lock
;
85 d_printf("Usage: net tdb locking <key> [ dump ]\n");
90 ret
= net_tdb_locking_fetch(mem_ctx
, argv
[0], &lock
);
95 if (argc
== 2 && strequal(argv
[1], "dump")) {
96 ret
= net_tdb_locking_dump(mem_ctx
, lock
->data
);
99 size_t num_share_modes
= 0;
101 status
= share_mode_count_entries(
102 lock
->data
->id
, &num_share_modes
);
103 if (!NT_STATUS_IS_OK(status
)) {
105 "Could not count share entries: %s\n",
109 d_printf("Share path: %s\n", lock
->data
->servicepath
);
110 d_printf("Name: %s\n", lock
->data
->base_name
);
111 d_printf("Number of share modes: %zu\n", num_share_modes
);
115 TALLOC_FREE(mem_ctx
);
119 int net_tdb(struct net_context
*c
, int argc
, const char **argv
)
121 struct functable func
[] = {
125 N_("Show information for a record in locking.tdb"),
126 N_("net tdb locking <key>")
128 {NULL
, NULL
, 0, NULL
, NULL
}
131 return net_run_function(c
, argc
, argv
, "net tdb", func
);