2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/vldbint.h>
12 #include <afsconfig.h>
13 #include <afs/param.h>
24 #include <sys/types.h>
26 #include <afs/cellconfig.h>
31 #include <afs/kauth.h>
32 #include <afs/afsutil.h>
35 File servers in NW byte order.
39 afs_int32 server_id[256];
41 struct ubik_client *client;
45 afs_int32 *ViceIds_val;
50 afs_int32 *IPAddrs_val;
53 struct ubik_dbase *VL_dbase;
54 struct afsconf_dir *vldb_confdir;
55 struct kadstats dynamic_statistics;
56 struct rx_securityClass *junk;
58 #include <sys/socket.h>
59 #include <netinet/in.h>
60 #include <arpa/inet.h>
62 extern int VL_GetAddrs();
65 InvalidateCache(struct cmd_syndesc *as, void *arock)
69 struct rx_connection *conn;
71 afs_int32 port = 7000;
74 afs_int32 spare2, spare3;
87 /* make sure something there */
89 if (!as->parms[0].items && !as->parms[1].items) {
90 printf("Use -help flag for list of optional argmuments\n");
96 for (i = 0, u = as->parms[0].items; i < 255 && u; ++i, u = u->next) {
97 code = util_GetInt32(u->data, &id[i]);
99 printf("Fatal error: bad conversion to long for %s\n", u->data);
106 vid.ViceIds_val = id;
108 /* get IP addresses, convert to NW byte order */
110 for (i = 0, u = as->parms[1].items; i < 255 && u; ++i, u = u->next)
111 ip[i] = inet_addr(u->data);
115 ipa.IPAddrs_val = ip;
117 for (i = 0; i < server_count; ++i) {
118 conn = rx_NewConnection(server_id[i], htonl(port), 1, junk, 0);
120 printf("Informational: could not connect to \
121 file server %lx\n", server_id[i]);
125 /* invalidate the cache */
127 code = RXAFS_FlushCPS(conn, &vid, &ipa, spare1, &spare2, &spare3);
130 * May get spurious error codes in case server is
131 * down or is reported by VLDB as a file server
132 * even though it is not configured as such in the
137 printf("Informational: failed to invalidate \
138 file server %lx cache code = %ld\n", server_id[i], code);
140 rx_DestroyConnection(conn);
146 Obtain list of file servers as known to VLDB. These may
147 not actually be configured as file servers in the cell.
154 struct rx_connection *conn;
155 struct rx_call *call;
159 afs_int32 base, index;
161 afs_int32 Handle = 0;
162 afs_int32 spare2 = 0;
163 struct VLCallBack spare3;
165 bulkaddrs addrs, m_addrs;
166 ListAddrByAttributes m_attrs;
167 afs_int32 m_unique, m_nentries;
170 /* get list of file servers in NW byte order */
171 memset(&addrs, 0, sizeof(addrs));
172 memset(&spare3, 0, sizeof(spare3));
174 ubik_VL_GetAddrs(client, 0, Handle, spare2, &spare3,
175 &server_count, &addrs);
177 printf("Fatal error: could not get list of file servers\n");
181 for (i = 0, p = addrs.bulkaddrs_val; i < server_count; ++i, ++p) {
182 if (((*p & 0xff000000) == 0xff000000) && ((*p) & 0xffff)) {
183 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
184 && (index <= VL_MHSRV_PERBLK)) {
185 m_attrs.Mask = VLADDR_INDEX;
186 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
188 m_addrs.bulkaddrs_val = 0;
189 m_addrs.bulkaddrs_len = 0;
191 ubik_VL_GetAddrsU(client, 0, &m_attrs, &m_uuid,
192 &m_unique, &m_nentries, &m_addrs);
196 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
197 for (j = 0; j < m_nentries; j++, m_addrp++) {
198 server_id[i] = *m_addrp;
199 *m_addrp = htonl(*m_addrp);
200 printf("host %s\n", hostutil_GetNameByINet(*p));
206 printf("host %s\n", hostutil_GetNameByINet(*p));
213 GetServerList(struct cmd_syndesc *as, void *arock)
218 code = ListServers();
222 printf("There are %d file servers in the cell\n\n", server_count);
224 for (i = 0; i < server_count; ++i)
225 printf("%s\n", hostutil_GetNameByINet(server_id[i]));
232 User enters lists of:
234 1. AFS user ids - say from "pts exam username".
235 2. IP addresses - say from /etc/hosts (no wildcards).
237 Command is executed in user's cell.
241 MyBeforeProc(struct cmd_syndesc *as, void *arock)
245 struct afsconf_dir *tdir;
246 struct afsconf_cell info;
247 struct rx_connection *serverconns[MAXSERVERS];
251 sprintf(confdir, "%s", AFSDIR_CLIENT_ETC_DIRPATH);
252 /* setup to talk to servers */
255 printf("Warning: could not initialize network communication.\n");
257 junk = rxnull_NewClientSecurityObject();
258 tdir = afsconf_Open(confdir);
260 printf("Warning: could not get cell configuration.\n");
262 if (as->parms[2].items) /* if -cell specified */
263 tcell = as->parms[2].items->data;
264 code = afsconf_GetCellInfo(tdir, tcell, AFSCONF_VLDBSERVICE, &info);
265 if (info.numServers > MAXSERVERS)
266 printf("Warning: could not init cell info.\n");
268 for (i = 0; i < info.numServers; ++i)
270 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
271 info.hostAddr[i].sin_port, USER_SERVICE_ID, junk,
273 for (; i < MAXSERVERS; ++i) {
274 serverconns[i] = (struct rx_connection *)0;
276 code = ubik_ClientInit(serverconns, &client);
278 printf("Warning: could not initialize RPC interface.\n");
288 struct cmd_syndesc *ts;
292 struct sigaction nsa;
294 sigemptyset(&nsa.sa_mask);
295 nsa.sa_handler = SIG_DFL;
296 nsa.sa_flags = SA_FULLDUMP;
297 sigaction(SIGSEGV, &nsa, NULL);
301 * Look in /usr/vice/etc (client side database).
303 cmd_SetBeforeProc(MyBeforeProc, NULL);
305 ts = cmd_CreateSyntax("initcmd" /*"invalidatecache" */ , InvalidateCache,
306 NULL, "invalidate server ACL cache");
307 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user identifier");
308 cmd_AddParm(ts, "-ip", CMD_LIST, CMD_OPTIONAL, "IP address");
309 cmd_CreateAlias(ts, "ic");
310 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
312 ts = cmd_CreateSyntax("listservers", GetServerList, NULL,
313 "list servers in the cell");
314 cmd_CreateAlias(ts, "ls");
316 code = cmd_Dispatch(argc, argv);