spoolss: accept XPS_PASS datatype used by Windows 8
[Samba.git] / source3 / utils / net_serverid.c
blob5e61f11473829ece768327d7c9b2b02043b8f79c
1 /*
2 Samba Unix/Linux SMB client library
3 net serverid commands
4 Copyright (C) Volker Lendecke 2010
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 "dbwrap.h"
23 #include "serverid.h"
24 #include "session.h"
26 static int net_serverid_list_fn(const struct server_id *id,
27 uint32_t msg_flags, void *priv)
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;
36 static int net_serverid_list(struct net_context *c, int argc,
37 const char **argv)
39 if (!serverid_init_readonly(c)) {
40 d_printf("failed to open serverid.tdb\n");
41 return -1;
43 d_printf("pid unique_id msg_flags\n");
44 return serverid_traverse_read(net_serverid_list_fn, NULL) ? 0 : -1;
47 static int net_serverid_wipe_fn(struct db_record *rec,
48 const struct server_id *id,
49 uint32_t msg_flags, void *private_data)
51 NTSTATUS status;
53 if (id->vnn != get_my_vnn()) {
54 return 0;
56 status = rec->delete_rec(rec);
57 if (!NT_STATUS_IS_OK(status)) {
58 char *str = procid_str(talloc_tos(), id);
59 DEBUG(1, ("Could not delete serverid.tdb record %s: %s\n",
60 str, nt_errstr(status)));
61 TALLOC_FREE(str);
63 return 0;
66 static int net_serverid_wipe(struct net_context *c, int argc,
67 const char **argv)
69 return serverid_traverse(net_serverid_wipe_fn, NULL) ? 0 : -1;
72 static int net_serverid_wipedbs_conn(
73 struct db_record *rec,
74 const struct connections_key *key,
75 const struct connections_data *data,
76 void *private_data)
78 if (!serverid_exists(&key->pid)) {
79 NTSTATUS status;
81 DEBUG(10, ("Deleting connections.tdb record for pid %s\n",
82 procid_str(talloc_tos(), &key->pid)));
84 status = rec->delete_rec(rec);
85 if (!NT_STATUS_IS_OK(status)) {
86 DEBUG(1, ("Could not delete connections.tdb record "
87 "for pid %s: %s\n",
88 procid_str(talloc_tos(), &key->pid),
89 nt_errstr(status)));
92 return 0;
95 static int net_serverid_wipedbs_sessionid(struct db_record *rec,
96 const char *key,
97 struct sessionid *session,
98 void *private_data)
100 if (!serverid_exists(&session->pid)) {
101 NTSTATUS status;
103 DEBUG(10, ("Deleting sessionid.tdb record for pid %s\n",
104 procid_str(talloc_tos(), &session->pid)));
106 status = rec->delete_rec(rec);
107 if (!NT_STATUS_IS_OK(status)) {
108 DEBUG(1, ("Could not delete session.tdb record "
109 "for pid %s: %s\n",
110 procid_str(talloc_tos(), &session->pid),
111 nt_errstr(status)));
114 return 0;
117 static int net_serverid_wipedbs(struct net_context *c, int argc,
118 const char **argv)
120 if (!sessionid_init()) {
121 d_printf("failed to open sessionid.tdb\n");
122 return -1;
125 connections_forall(net_serverid_wipedbs_conn, NULL);
126 sessionid_traverse(net_serverid_wipedbs_sessionid, NULL);
127 return 0;
130 int net_serverid(struct net_context *c, int argc, const char **argv)
132 struct functable func[] = {
134 "list",
135 net_serverid_list,
136 NET_TRANSPORT_LOCAL,
137 N_("List all entries from serverid.tdb"),
138 N_("net serverid list\n"
139 " List all entries from serverid.tdb")
142 "wipe",
143 net_serverid_wipe,
144 NET_TRANSPORT_LOCAL,
145 N_("Wipe the serverid.tdb for the current node"),
146 N_("net serverid wipe\n"
147 " Wipe the serverid.tdb for the current node")
150 "wipedbs",
151 net_serverid_wipedbs,
152 NET_TRANSPORT_LOCAL,
153 N_("Clean dead entries from connections.tdb and "
154 "sessionid.tdb"),
155 N_("net serverid wipedbs\n"
156 " Clean dead entries from connections.tdb and "
157 "sessionid.tdb")
159 {NULL, NULL, 0, NULL, NULL}
162 return net_run_function(c, argc, argv, "net serverid", func);