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 <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
17 #include <sys/resource.h>
19 #include <netinet/in.h>
25 #include <afs/cellconfig.h>
27 #include <afs/com_err.h>
33 char *whoami = "test_rxkad_free";
38 printf("New Objects client %d, server %d. Destroyed objects %d.\n",
39 rxkad_stats.clientObjects, rxkad_stats.serverObjects,
40 rxkad_stats.destroyObject);
41 printf("client conns: %d %d %d, destroyed client %d.\n",
42 rxkad_stats.connections[0], rxkad_stats.connections[1],
43 rxkad_stats.connections[2], rxkad_stats.destroyClient);
44 printf("server challenges %d, responses %d %d %d\n",
45 rxkad_stats.challengesSent, rxkad_stats.responses[0],
46 rxkad_stats.responses[1], rxkad_stats.responses[2]);
47 printf("server conns %d %d %d unused %d, unauth %d\n",
48 rxkad_stats.destroyConn[0], rxkad_stats.destroyConn[1],
49 rxkad_stats.destroyConn[2], rxkad_stats.destroyUnused,
50 rxkad_stats.destroyUnauth);
54 Main(struct cmd_syndesc *as, void *arock)
57 char name[MAXKTCNAMELEN];
58 char instance[MAXKTCNAMELEN];
59 char newCell[MAXKTCREALMLEN];
62 long serverList[MAXSERVERS];
63 extern struct passwd *getpwuid();
66 struct ktc_encryptionKey key;
72 int verbose = (as->parms[1].items != 0);
73 int hostUsage = (as->parms[2].items != 0);
74 int waitReap = (as->parms[4].items != 0);
75 int doAuth = (as->parms[5].items != 0);
76 int number; /* number of iterations */
77 int callsPerSecond; /* to allow conn GC to run */
79 unsigned long lo, hi; /* mem usage */
80 unsigned long highWater; /* mem usage after reap period */
81 unsigned long lastWater; /* mem usage after last msg */
82 int serversUse[MAXSERVERS]; /* usage of each server */
83 long serversHost[MAXSERVERS]; /* host addr */
84 unsigned long startTime;
91 if (as->parms[0].items)
92 number = atoi(as->parms[0].items->data);
95 if (as->parms[3].items)
96 callsPerSecond = atoi(as->parms[3].items->data);
99 if (doAuth && hostUsage) {
101 "Can't report host usage when calling UserAuthenticate\n");
105 if (as->parms[12].items) { /* if username specified */
107 ka_ParseLoginName(as->parms[12].items->data, name, instance,
110 afs_com_err(whoami, code, "parsing user's name '%s'",
111 as->parms[12].items->data);
114 if (strlen(newCell) > 0)
117 /* No explicit name provided: use Unix uid. */
118 pw = getpwuid(getuid());
120 printf("Can't figure out your name from your user id.\n");
123 strncpy(name, pw->pw_name, sizeof(name));
124 strcpy(instance, "");
127 if (strcmp(as->parms[14].name, "-cell") == 0) {
128 if (as->parms[14].items) { /* if cell specified */
130 printf("Duplicate cell specification not allowed\n");
132 strncpy(newCell, as->parms[14].items->data, sizeof(newCell));
136 code = ka_ExpandCell(newCell, newCell, 0 /*local */ );
138 afs_com_err(whoami, code, "Can't expand cell name");
143 if (as->parms[13].items) { /* if password specified */
144 strncpy(passwd, as->parms[13].items->data, sizeof(passwd));
145 memset(as->parms[13].items->data, 0,
146 strlen(as->parms[13].items->data));
148 char msg[sizeof(name) + 15];
149 if (as->parms[12].items)
150 strcpy(msg, "Admin Password: ");
152 sprintf(msg, "Password for %s: ", name);
153 code = read_pw_string(passwd, sizeof(passwd), msg, 0);
156 else if (strlen(passwd) == 0)
157 code = KANULLPASSWORD;
159 afs_com_err(whoami, code, "reading password");
163 if (as->parms[15].items) {
165 char *ap[MAXSERVERS + 2];
167 for (ip = as->parms[15].items, i = 2; ip; ip = ip->next, i++)
171 code = ubik_ParseClientList(i, ap, serverList);
173 afs_com_err(whoami, code, "could not parse server list");
176 ka_ExplicitCell(cell, serverList);
180 ka_StringToKey(passwd, cell, &key);
181 memset(passwd, 0, sizeof(passwd));
184 memset(serversUse, 0, sizeof(serversUse));
185 memset(serversHost, 0, sizeof(serversHost));
189 for (i = 0; i < number; i++) {
193 ka_UserAuthenticateLife(0, name, instance, cell, passwd, 0,
196 fprintf(stderr, "Unable to authenticate to AFS because %s.\n",
201 struct ktc_token token;
202 struct ktc_token *pToken;
203 struct ubik_client *ubikConn;
204 struct kaentryinfo tentry;
208 ka_GetAdminToken(name, instance, cell, &key, 3600, &token,
211 afs_com_err(whoami, code, "getting admin token");
215 if (token.ticketLen == 0) {
216 fprintf("Can't get admin token\n");
221 ka_AuthServerConn(cell, KA_MAINTENANCE_SERVICE, pToken,
224 afs_com_err(whoami, code, "Getting AuthServer ubik conn");
229 for (c = 0; c < MAXSERVERS; c++) {
230 struct rx_connection *rxConn =
231 ubik_GetRPCConn(ubikConn, c);
232 struct rx_peer *peer;
236 peer = rx_PeerOf(rxConn);
237 printf("conn to %s:%d secObj:%x\n",
238 inet_ntoa(rx_HostOf(peer)), ntohs(rx_PortOf(peer)),
239 rxConn->securityObject);
243 ubik_Call(KAM_GetEntry, ubikConn, 0, name, instance,
244 KAMAJORVERSION, &tentry);
246 afs_com_err(whoami, code, "getting information for %s.%s", name,
251 for (c = 0; c < MAXSERVERS; c++) {
252 struct rx_connection *rxConn = ubik_GetRPCConn(ubikConn, c);
256 if (rxConn->serial > 0) {
257 long host = rx_HostOf(rx_PeerOf(rxConn));
258 for (d = 0; d < MAXSERVERS; d++) {
259 if (serversHost[d] == 0)
260 serversHost[d] = host;
261 if (host == serversHost[d]) {
268 printf("serial is %d\n", rxConn->serial);
270 ubik_ClientDestroy(ubikConn);
276 if (i && ((i & 0x3f) == 0)) {
277 unsigned long this = sbrk(0);
278 printf(" mem after %d: lo=%x, cur=%x => %d (@ %d)\n", i, lo,
279 this, this - lo, (this - lo) / i);
280 if (highWater && (lastWater != this)) {
282 printf(" core leaking (after %d) should be %x, is %x\n", i,
286 if ((highWater == 0) && ((now - startTime) > 61)) {
288 lastWater = highWater;
289 printf(" mem highWater mark (after %d) should be %x\n", i,
292 if (callsPerSecond) {
294 if (callsPerSecond > 0)
295 target = i / callsPerSecond;
296 else /* if negative interpret as seconds per call */
297 target = i * (-callsPerSecond);
298 target = (startTime + target) - now;
303 printf("calling finalize\n");
308 for (i = 0; i < MAXSERVERS; i++) {
309 total += serversUse[i];
310 if (serversHost[i] == 0)
312 printf("host %s used %d times (%2g%%)\n",
313 inet_ntoa(serversHost[i]), serversUse[i],
314 100.0 * serversUse[i] / (double)number);
317 printf(" %2g%% retries\n",
318 100.0 * (total - number) / (double)number);
321 printf("mem usage: lo=%x, hi=%x => %d (@ %d)\n", lo, hi, hi - lo,
324 unsigned long mediumHi;
325 printf("Waiting 61 seconds for all connections to be reaped\n");
331 printf("mem usage: lo=%x, hi=%x => %d (@ %d)\n", lo, hi, hi - lo,
334 /* most of these checks are sure to fail w/o waiting for reap */
336 && ((rxkad_stats_clientObjects != rxkad_stats.destroyObject)
337 || (rxkad_stats.connections[0] + rxkad_stats.connections[1] +
338 rxkad_stats.connections[2] != rxkad_stats.destroyClient)
339 || (rxkad_stats.responses[0] != rxkad_stats.destroyConn[0])
340 || (rxkad_stats.responses[1] != rxkad_stats.destroyConn[1])
341 || (rxkad_stats.responses[2] != rxkad_stats.destroyConn[2])
342 /* values of destroyUnused and destroyUnauth should be very small */
344 fprintf(stderr, "Some rxkad security storage not freed\n");
347 if ((highWater != 0) && (highWater < hi)) {
348 /* We should reach steady state memory usage after 60 seconds (the Rx
349 * connection reap period). If we are still using memory, there must
351 fprintf(stderr, "Core leak\n");
362 struct cmd_syndesc *ts;
365 initialize_U_error_table();
366 initialize_CMD_error_table();
367 initialize_RXK_error_table();
368 initialize_KTC_error_table();
369 initialize_ACFG_error_table();
370 initialize_KA_error_table();
372 ts = cmd_CreateSyntax(NULL, Main, NULL, "Main program");
373 /* 0 */ cmd_AddParm(ts, "-number", CMD_SINGLE, CMD_OPTIONAL,
374 "number of iterations");
375 /* 1 */ cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
376 "long form of output");
377 /* 2 */ cmd_AddParm(ts, "-hostusage", CMD_FLAG, CMD_OPTIONAL,
378 "report distribution of host usage");
379 /* 3 */ cmd_AddParm(ts, "-rate", CMD_SINGLE, CMD_OPTIONAL,
381 /* 4 */ cmd_AddParm(ts, "-waitforreap", CMD_FLAG, CMD_OPTIONAL,
382 "wait one reap time before exit");
383 /* 5 */ cmd_AddParm(ts, "-doauth", CMD_FLAG, CMD_OPTIONAL,
384 "call UserAuthenticate instead of GetEntry");
386 /* 12 */ cmd_AddParm(ts, "-admin_username", CMD_SINGLE, CMD_OPTIONAL,
387 "admin principal to use for authentication");
388 /* 13 */ cmd_AddParm(ts, "-password_for_admin", CMD_SINGLE, CMD_OPTIONAL,
390 /* 14 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
391 /* 15 */ cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL,
392 "explicit list of authentication servers");
393 code = cmd_Dispatch(argc, argv);