| 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.h"
|
|---|
| 23 | #include "serverid.h"
|
|---|
| 24 | #include "session.h"
|
|---|
| 25 |
|
|---|
| 26 | static int net_serverid_list_fn(const struct server_id *id,
|
|---|
| 27 | uint32_t msg_flags, void *priv)
|
|---|
| 28 | {
|
|---|
| 29 | char *str = procid_str(talloc_tos(), id);
|
|---|
| 30 | d_printf("%s %llu 0x%x\n", str, (unsigned long long)id->unique_id,
|
|---|
| 31 | (unsigned int)msg_flags);
|
|---|
| 32 | TALLOC_FREE(str);
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | static int net_serverid_list(struct net_context *c, int argc,
|
|---|
| 37 | const char **argv)
|
|---|
| 38 | {
|
|---|
| 39 | d_printf("pid unique_id msg_flags\n");
|
|---|
| 40 | return serverid_traverse_read(net_serverid_list_fn, NULL) ? 0 : -1;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | static int net_serverid_wipe_fn(struct db_record *rec,
|
|---|
| 44 | const struct server_id *id,
|
|---|
| 45 | uint32_t msg_flags, void *private_data)
|
|---|
| 46 | {
|
|---|
| 47 | NTSTATUS status;
|
|---|
| 48 |
|
|---|
| 49 | if (id->vnn != get_my_vnn()) {
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 | status = rec->delete_rec(rec);
|
|---|
| 53 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 54 | char *str = procid_str(talloc_tos(), id);
|
|---|
| 55 | DEBUG(1, ("Could not delete serverid.tdb record %s: %s\n",
|
|---|
| 56 | str, nt_errstr(status)));
|
|---|
| 57 | TALLOC_FREE(str);
|
|---|
| 58 | }
|
|---|
| 59 | return 0;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | static int net_serverid_wipe(struct net_context *c, int argc,
|
|---|
| 63 | const char **argv)
|
|---|
| 64 | {
|
|---|
| 65 | return serverid_traverse(net_serverid_wipe_fn, NULL) ? 0 : -1;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | static int net_serverid_wipedbs_conn(
|
|---|
| 69 | struct db_record *rec,
|
|---|
| 70 | const struct connections_key *key,
|
|---|
| 71 | const struct connections_data *data,
|
|---|
| 72 | void *private_data)
|
|---|
| 73 | {
|
|---|
| 74 | if (!serverid_exists(&key->pid)) {
|
|---|
| 75 | NTSTATUS status;
|
|---|
| 76 |
|
|---|
| 77 | DEBUG(10, ("Deleting connections.tdb record for pid %s\n",
|
|---|
| 78 | procid_str(talloc_tos(), &key->pid)));
|
|---|
| 79 |
|
|---|
| 80 | status = rec->delete_rec(rec);
|
|---|
| 81 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 82 | DEBUG(1, ("Could not delete connections.tdb record "
|
|---|
| 83 | "for pid %s: %s\n",
|
|---|
| 84 | procid_str(talloc_tos(), &key->pid),
|
|---|
| 85 | nt_errstr(status)));
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 | return 0;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | static int net_serverid_wipedbs_sessionid(struct db_record *rec,
|
|---|
| 92 | const char *key,
|
|---|
| 93 | struct sessionid *session,
|
|---|
| 94 | void *private_data)
|
|---|
| 95 | {
|
|---|
| 96 | if (!serverid_exists(&session->pid)) {
|
|---|
| 97 | NTSTATUS status;
|
|---|
| 98 |
|
|---|
| 99 | DEBUG(10, ("Deleting sessionid.tdb record for pid %s\n",
|
|---|
| 100 | procid_str(talloc_tos(), &session->pid)));
|
|---|
| 101 |
|
|---|
| 102 | status = rec->delete_rec(rec);
|
|---|
| 103 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 104 | DEBUG(1, ("Could not delete session.tdb record "
|
|---|
| 105 | "for pid %s: %s\n",
|
|---|
| 106 | procid_str(talloc_tos(), &session->pid),
|
|---|
| 107 | nt_errstr(status)));
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | return 0;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | static int net_serverid_wipedbs(struct net_context *c, int argc,
|
|---|
| 114 | const char **argv)
|
|---|
| 115 | {
|
|---|
| 116 | connections_forall(net_serverid_wipedbs_conn, NULL);
|
|---|
| 117 | sessionid_traverse(net_serverid_wipedbs_sessionid, NULL);
|
|---|
| 118 | return 0;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | int net_serverid(struct net_context *c, int argc, const char **argv)
|
|---|
| 122 | {
|
|---|
| 123 | struct functable func[] = {
|
|---|
| 124 | {
|
|---|
| 125 | "list",
|
|---|
| 126 | net_serverid_list,
|
|---|
| 127 | NET_TRANSPORT_LOCAL,
|
|---|
| 128 | N_("List all entries from serverid.tdb"),
|
|---|
| 129 | N_("net serverid list\n"
|
|---|
| 130 | " List all entries from serverid.tdb")
|
|---|
| 131 | },
|
|---|
| 132 | {
|
|---|
| 133 | "wipe",
|
|---|
| 134 | net_serverid_wipe,
|
|---|
| 135 | NET_TRANSPORT_LOCAL,
|
|---|
| 136 | N_("Wipe the serverid.tdb for the current node"),
|
|---|
| 137 | N_("net serverid wipe\n"
|
|---|
| 138 | " Wipe the serverid.tdb for the current node")
|
|---|
| 139 | },
|
|---|
| 140 | {
|
|---|
| 141 | "wipedbs",
|
|---|
| 142 | net_serverid_wipedbs,
|
|---|
| 143 | NET_TRANSPORT_LOCAL,
|
|---|
| 144 | N_("Clean dead entries from connections.tdb and "
|
|---|
| 145 | "sessionid.tdb"),
|
|---|
| 146 | N_("net serverid wipedbs\n"
|
|---|
| 147 | " Clean dead entries from connections.tdb and "
|
|---|
| 148 | "sessionid.tdb")
|
|---|
| 149 | },
|
|---|
| 150 | {NULL, NULL, 0, NULL, NULL}
|
|---|
| 151 | };
|
|---|
| 152 |
|
|---|
| 153 | return net_run_function(c, argc, argv, "net serverid", func);
|
|---|
| 154 | }
|
|---|