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/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"
27 static int net_tdb_locking(struct net_context
*c
, int argc
, const char **argv
)
29 TALLOC_CTX
*mem_ctx
= talloc_stackframe();
30 struct share_mode_lock
*lock
;
31 DATA_BLOB blob
= { .data
= NULL
};
32 struct file_id id
= { .inode
= 0 };
37 d_printf("Usage: net tdb locking <key> [ dump ]\n");
41 ok
= locking_init_readonly();
43 d_printf("locking_init_readonly failed\n");
47 blob
= strhex_to_data_blob(mem_ctx
, argv
[0]);
48 if (blob
.length
!= sizeof(struct file_id
)) {
49 d_printf("Invalid length %zu of key, expected %zu\n",
51 sizeof(struct file_id
));
55 memcpy(&id
, blob
.data
, blob
.length
);
57 lock
= fetch_share_mode_unlocked(mem_ctx
, id
);
59 d_printf("Record with key %s not found.\n", argv
[1]);
63 if (argc
== 2 && strequal(argv
[1], "dump")) {
64 char *dump
= share_mode_data_dump(mem_ctx
, lock
);
65 d_printf("%s\n", dump
);
69 size_t num_share_modes
= 0;
71 status
= share_mode_count_entries(id
, &num_share_modes
);
72 if (!NT_STATUS_IS_OK(status
)) {
74 "Could not count share entries: %s\n",
79 d_printf("Share path: %s\n",
80 share_mode_servicepath(lock
));
81 d_printf("Name: %s\n",
82 share_mode_filename(mem_ctx
, lock
));
83 d_printf("Number of share modes: %zu\n", num_share_modes
);
92 int net_tdb(struct net_context
*c
, int argc
, const char **argv
)
94 struct functable func
[] = {
98 N_("Show information for a record in locking.tdb"),
99 N_("net tdb locking <key>")
101 {NULL
, NULL
, 0, NULL
, NULL
}
104 return net_run_function(c
, argc
, argv
, "net tdb", func
);