smbd: Show blk and chr devices as nfs reparse points
[Samba.git] / source3 / utils / net_tdb.c
blob29585eb718283eae19ec8724fd777b84019c3509
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>
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/>.
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"
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 };
33 int ret = -1;
34 bool ok;
36 if (argc < 1) {
37 d_printf("Usage: net tdb locking <key> [ dump ]\n");
38 goto out;
41 ok = locking_init_readonly();
42 if (!ok) {
43 d_printf("locking_init_readonly failed\n");
44 goto out;
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",
50 blob.length,
51 sizeof(struct file_id));
52 goto out;
55 memcpy(&id, blob.data, blob.length);
57 lock = fetch_share_mode_unlocked(mem_ctx, id);
58 if (lock == NULL) {
59 d_printf("Record with key %s not found.\n", argv[1]);
60 goto out;
63 if (argc == 2 && strequal(argv[1], "dump")) {
64 char *dump = share_mode_data_dump(mem_ctx, lock);
65 d_printf("%s\n", dump);
66 TALLOC_FREE(dump);
67 } else {
68 NTSTATUS status;
69 size_t num_share_modes = 0;
71 status = share_mode_count_entries(id, &num_share_modes);
72 if (!NT_STATUS_IS_OK(status)) {
73 d_fprintf(stderr,
74 "Could not count share entries: %s\n",
75 nt_errstr(status));
76 goto out;
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);
86 ret = 0;
87 out:
88 TALLOC_FREE(mem_ctx);
89 return ret;
92 int net_tdb(struct net_context *c, int argc, const char **argv)
94 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>")
101 {NULL, NULL, 0, NULL, NULL}
104 return net_run_function(c, argc, argv, "net tdb", func);