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
11 #include <afsconfig.h>
12 #include <afs/param.h>
20 #include <afs/cellconfig.h>
21 #include <afs/afsint.h>
22 #include <afs/vlserver.h>
26 #include <afs/kauth.h>
27 #include <afs/afsutil.h>
28 #include <afs/vldbint.h>
31 File servers in NW byte order.
34 static afs_int32 server_count = 0;
35 static afs_int32 server_id[256];
37 static struct ubik_client *client;
39 static struct rx_securityClass *sc;
43 Obtain list of file servers as known to VLDB. These may
44 not actually be configured as file servers in the cell.
52 struct VLCallBack vlcb;
53 struct VLCallBack spare3;
54 bulkaddrs addrs, m_addrs;
56 afs_int32 base, index;
61 ListAddrByAttributes m_attrs;
63 memset(&addrs, 0, sizeof(addrs));
64 memset(&spare3, 0, sizeof(spare3));
66 ubik_VL_GetAddrs(client, 0, 0, 0, &vlcb,
67 &server_count, &addrs);
69 printf("Fatal error: could not get list of file servers\n");
73 for (i = 0; i < server_count; ++i) {
74 ip = addrs.bulkaddrs_val[i];
76 if (((ip & 0xff000000) == 0xff000000) && (ip & 0xffff)) {
77 base = (ip >> 16) & 0xff;
80 /* server is a multihomed host; query the vldb for its addresses,
81 * and just pick the first one */
83 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
84 && (index <= VL_MHSRV_PERBLK)) {
86 m_attrs.Mask = VLADDR_INDEX;
87 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
89 m_addrs.bulkaddrs_val = 0;
90 m_addrs.bulkaddrs_len = 0;
92 code = ubik_VL_GetAddrsU(client, 0, &m_attrs, &m_uuid, &m_uniq,
93 &m_nentries, &m_addrs);
95 if (code || m_addrs.bulkaddrs_len == 0) {
96 printf("Error getting multihomed addresses for server "
98 afs_inet_ntoa_r(m_addrs.bulkaddrs_val[0], hoststr),
99 afs_printable_int32_ld(m_attrs.index));
102 server_id[i] = htonl(m_addrs.bulkaddrs_val[0]);
106 server_id[i] = htonl(addrs.bulkaddrs_val[i]);
115 InvalidateCache(struct cmd_syndesc *as, void *arock)
119 struct rx_connection *conn;
121 afs_int32 port = 7000;
125 afs_int32 spare1 = 0;
126 afs_int32 spare2, spare3;
134 code = ListServers();
139 /* make sure something there */
141 if (!as->parms[0].items && !as->parms[1].items) {
142 printf("Use -help flag for list of optional argmuments\n");
148 for (i = 0, u = as->parms[0].items; i < 255 && u; ++i, u = u->next) {
149 code = util_GetInt32(u->data, &id[i]);
151 printf("Fatal error: bad conversion to long for %s\n", u->data);
158 vid.ViceIds_val = id;
160 /* get IP addresses, convert to NW byte order */
162 for (i = 0, u = as->parms[1].items; i < 255 && u; ++i, u = u->next)
163 ip[i] = inet_addr(u->data);
167 ipa.IPAddrs_val = ip;
169 for (i = 0; i < server_count; ++i) {
174 conn = rx_NewConnection(server_id[i], htons(port), 1, sc, scindex);
176 printf("Informational: could not connect to \
177 file server %s\n", afs_inet_ntoa_r(server_id[i], hoststr));
182 /* invalidate the cache */
184 code = RXAFS_FlushCPS(conn, &vid, &ipa, spare1, &spare2, &spare3);
187 * May get spurious error codes in case server is
188 * down or is reported by VLDB as a file server
189 * even though it is not configured as such in the
194 printf("Informational: failed to invalidate \
195 file server %s cache code = %ld\n", afs_inet_ntoa_r(server_id[i], hoststr),
196 afs_printable_int32_ld(code));
200 rx_DestroyConnection(conn);
206 GetServerList(struct cmd_syndesc *as, void *arock)
211 code = ListServers();
215 printf("There are %d file servers in the cell\n\n", server_count);
217 for (i = 0; i < server_count; ++i)
218 printf("%s\n", hostutil_GetNameByINet(server_id[i]));
225 User enters lists of:
227 1. AFS user ids - say from "pts exam username".
228 2. IP addresses - say from /etc/hosts (no wildcards).
230 Command is executed in user's cell.
234 MyBeforeProc(struct cmd_syndesc *as, void *arock)
238 struct afsconf_dir *tdir;
239 struct afsconf_cell info;
240 struct rx_connection *serverconns[MAXSERVERS];
242 struct rx_securityClass *scnull;
243 rxkad_level sclevel = rxkad_auth;
245 sprintf(confdir, "%s", AFSDIR_CLIENT_ETC_DIRPATH);
246 if (as->parms[4].items) { /* -localauth */
247 sprintf(confdir, "%s", AFSDIR_SERVER_ETC_DIRPATH);
250 if (as->parms[5].items) { /* -encrypt */
251 sclevel = rxkad_crypt;
254 /* setup to talk to servers */
257 printf("Warning: could not initialize network communication.\n");
261 scnull = sc = rxnull_NewClientSecurityObject();
264 tdir = afsconf_Open(confdir);
266 printf("Warning: could not get cell configuration.\n");
270 if (as->parms[2].items) /* if -cell specified */
271 tcell = as->parms[2].items->data;
272 code = afsconf_GetCellInfo(tdir, tcell, AFSCONF_VLDBSERVICE, &info);
273 if (code || info.numServers > MAXSERVERS) {
274 printf("Warning: could not init cell info.\n");
278 if (as->parms[4].items) { /* -localauth */
279 if (sclevel == rxkad_crypt) {
280 code = afsconf_ClientAuthSecure(tdir, &sc, &scindex);
282 code = afsconf_ClientAuth(tdir, &sc, &scindex);
284 if (code || scindex == 0) {
286 fprintf(stderr, "Could not get security object for -localauth (code: %d)\n",
291 } else if (!as->parms[3].items) { /* not -noauth */
292 struct ktc_principal sname;
293 struct ktc_token ttoken;
295 strcpy(sname.cell, info.name);
296 sname.instance[0] = '\0';
297 strcpy(sname.name, "afs");
299 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
301 fprintf(stderr, "Could not get afs tokens, running unauthenticated\n");
304 sc = rxkad_NewClientSecurityObject(sclevel, &ttoken.sessionKey,
305 ttoken.kvno, ttoken.ticketLen,
310 for (i = 0; i < info.numServers; ++i)
312 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
313 info.hostAddr[i].sin_port, USER_SERVICE_ID, scnull,
315 for (; i < MAXSERVERS; ++i) {
316 serverconns[i] = (struct rx_connection *)0;
318 code = ubik_ClientInit(serverconns, &client);
320 printf("Warning: could not initialize RPC interface.\n");
328 main(int argc, char **argv)
331 struct cmd_syndesc *ts;
334 struct sigaction nsa;
336 sigemptyset(&nsa.sa_mask);
337 nsa.sa_handler = SIG_DFL;
338 nsa.sa_flags = SA_FULLDUMP;
339 sigaction(SIGSEGV, &nsa, NULL);
343 * Look in /usr/vice/etc (client side database).
345 cmd_SetBeforeProc(MyBeforeProc, NULL);
347 ts = cmd_CreateSyntax("initcmd" /*"invalidatecache" */ , InvalidateCache,
348 NULL, 0, "invalidate server ACL cache");
349 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "user identifier");
350 cmd_AddParm(ts, "-ip", CMD_LIST, CMD_OPTIONAL, "IP address");
351 cmd_CreateAlias(ts, "ic");
352 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
353 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");
354 cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL, "user server tickets");
355 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");
357 ts = cmd_CreateSyntax("listservers", GetServerList, NULL, 0,
358 "list servers in the cell");
359 cmd_CreateAlias(ts, "ls");
361 code = cmd_Dispatch(argc, argv);