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(&m_attrs
, 0, sizeof(m_attrs
));
64 memset(&addrs
, 0, sizeof(addrs
));
65 memset(&spare3
, 0, sizeof(spare3
));
67 ubik_VL_GetAddrs(client
, 0, 0, 0, &vlcb
,
68 &server_count
, &addrs
);
70 printf("Fatal error: could not get list of file servers\n");
74 for (i
= 0; i
< server_count
; ++i
) {
75 ip
= addrs
.bulkaddrs_val
[i
];
77 if (((ip
& 0xff000000) == 0xff000000) && (ip
& 0xffff)) {
78 base
= (ip
>> 16) & 0xff;
81 /* server is a multihomed host; query the vldb for its addresses,
82 * and just pick the first one */
84 if ((base
>= 0) && (base
<= VL_MAX_ADDREXTBLKS
) && (index
>= 1)
85 && (index
<= VL_MHSRV_PERBLK
)) {
87 m_attrs
.Mask
= VLADDR_INDEX
;
88 m_attrs
.index
= (base
* VL_MHSRV_PERBLK
) + index
;
90 m_addrs
.bulkaddrs_val
= 0;
91 m_addrs
.bulkaddrs_len
= 0;
93 code
= ubik_VL_GetAddrsU(client
, 0, &m_attrs
, &m_uuid
, &m_uniq
,
94 &m_nentries
, &m_addrs
);
96 if (code
|| m_addrs
.bulkaddrs_len
== 0) {
97 printf("Error getting multihomed addresses for server "
99 afs_inet_ntoa_r(m_addrs
.bulkaddrs_val
[0], hoststr
),
100 afs_printable_int32_ld(m_attrs
.index
));
103 server_id
[i
] = htonl(m_addrs
.bulkaddrs_val
[0]);
107 server_id
[i
] = htonl(addrs
.bulkaddrs_val
[i
]);
116 InvalidateCache(struct cmd_syndesc
*as
, void *arock
)
120 struct rx_connection
*conn
;
122 afs_int32 port
= 7000;
126 afs_int32 spare1
= 0;
127 afs_int32 spare2
, spare3
;
135 code
= ListServers();
140 /* make sure something there */
142 if (!as
->parms
[0].items
&& !as
->parms
[1].items
) {
143 printf("Use -help flag for list of optional argmuments\n");
149 for (i
= 0, u
= as
->parms
[0].items
; i
< 255 && u
; ++i
, u
= u
->next
) {
150 code
= util_GetInt32(u
->data
, &id
[i
]);
152 printf("Fatal error: bad conversion to long for %s\n", u
->data
);
159 vid
.ViceIds_val
= id
;
161 /* get IP addresses, convert to NW byte order */
163 for (i
= 0, u
= as
->parms
[1].items
; i
< 255 && u
; ++i
, u
= u
->next
)
164 ip
[i
] = inet_addr(u
->data
);
168 ipa
.IPAddrs_val
= ip
;
170 for (i
= 0; i
< server_count
; ++i
) {
175 conn
= rx_NewConnection(server_id
[i
], htons(port
), 1, sc
, scindex
);
177 printf("Informational: could not connect to \
178 file server %s\n", afs_inet_ntoa_r(server_id
[i
], hoststr
));
183 /* invalidate the cache */
185 code
= RXAFS_FlushCPS(conn
, &vid
, &ipa
, spare1
, &spare2
, &spare3
);
188 * May get spurious error codes in case server is
189 * down or is reported by VLDB as a file server
190 * even though it is not configured as such in the
195 printf("Informational: failed to invalidate \
196 file server %s cache code = %ld\n", afs_inet_ntoa_r(server_id
[i
], hoststr
),
197 afs_printable_int32_ld(code
));
201 rx_DestroyConnection(conn
);
207 GetServerList(struct cmd_syndesc
*as
, void *arock
)
212 code
= ListServers();
216 printf("There are %d file servers in the cell\n\n", server_count
);
218 for (i
= 0; i
< server_count
; ++i
)
219 printf("%s\n", hostutil_GetNameByINet(server_id
[i
]));
226 User enters lists of:
228 1. AFS user ids - say from "pts exam username".
229 2. IP addresses - say from /etc/hosts (no wildcards).
231 Command is executed in user's cell.
235 MyBeforeProc(struct cmd_syndesc
*as
, void *arock
)
239 struct afsconf_dir
*tdir
;
240 struct afsconf_cell info
;
241 struct rx_connection
*serverconns
[MAXSERVERS
];
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 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
, sc
,
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
);