s3:net_serverid: remove connections_forall from "net serverid wipedbs"
[mat/samba.git] / source3 / utils / net_serverid.c
1 /*
2    Samba Unix/Linux SMB client library
3    net serverid commands
4    Copyright (C) Volker Lendecke 2010
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 "dbwrap/dbwrap.h"
23 #include "serverid.h"
24 #include "session.h"
25 #include "lib/conn_tdb.h"
26
27 static int net_serverid_list_fn(const struct server_id *id,
28                                 uint32_t msg_flags, void *priv)
29 {
30         char *str = server_id_str(talloc_tos(), id);
31         d_printf("%s %llu 0x%x\n", str, (unsigned long long)id->unique_id,
32                  (unsigned int)msg_flags);
33         TALLOC_FREE(str);
34         return 0;
35 }
36
37 static int net_serverid_list(struct net_context *c, int argc,
38                              const char **argv)
39 {
40         d_printf("pid unique_id msg_flags\n");
41         return serverid_traverse_read(net_serverid_list_fn, NULL) ? 0 : -1;
42 }
43
44 static int net_serverid_wipe_fn(struct db_record *rec,
45                                 const struct server_id *id,
46                                 uint32_t msg_flags, void *private_data)
47 {
48         NTSTATUS status;
49
50         if (id->vnn != get_my_vnn()) {
51                 return 0;
52         }
53         status = dbwrap_record_delete(rec);
54         if (!NT_STATUS_IS_OK(status)) {
55                 char *str = server_id_str(talloc_tos(), id);
56                 DEBUG(1, ("Could not delete serverid.tdb record %s: %s\n",
57                           str, nt_errstr(status)));
58                 TALLOC_FREE(str);
59         }
60         return 0;
61 }
62
63 static int net_serverid_wipe(struct net_context *c, int argc,
64                              const char **argv)
65 {
66         return serverid_traverse(net_serverid_wipe_fn, NULL) ? 0 : -1;
67 }
68
69 static int net_serverid_wipedbs(struct net_context *c, int argc,
70                                 const char **argv)
71 {
72         d_printf("TODO reimplement!\n");
73         return 0;
74 }
75
76 int net_serverid(struct net_context *c, int argc, const char **argv)
77 {
78         struct functable func[] = {
79                 {
80                         "list",
81                         net_serverid_list,
82                         NET_TRANSPORT_LOCAL,
83                         N_("List all entries from serverid.tdb"),
84                         N_("net serverid list\n"
85                            "    List all entries from serverid.tdb")
86                 },
87                 {
88                         "wipe",
89                         net_serverid_wipe,
90                         NET_TRANSPORT_LOCAL,
91                         N_("Wipe the serverid.tdb for the current node"),
92                         N_("net serverid wipe\n"
93                            "    Wipe the serverid.tdb for the current node")
94                 },
95                 {
96                         "wipedbs",
97                         net_serverid_wipedbs,
98                         NET_TRANSPORT_LOCAL,
99                         N_("Clean dead entries from temporary databases"),
100                         N_("net serverid wipedbs\n"
101                            "    Clean dead entries from temporary databases")
102                 },
103                 {NULL, NULL, 0, NULL, NULL}
104         };
105
106         return net_run_function(c, argc, argv, "net serverid", func);
107 }