Remove the RCSID macro
[openafs.git] / src / libadmin / cfg / test / cfgtest.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /* Test driver for configuration functions. */
11
12 #include <afsconfig.h>
13 #include <afs/param.h>
14
15
16 #include <afs/stds.h>
17
18 #include <stddef.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <errno.h>
23
24 #include <pthread.h>
25
26 #include <afs/afs_Admin.h>
27 #include <afs/afs_utilAdmin.h>
28 #include <afs/afs_clientAdmin.h>
29 #include <afs/afs_cfgAdmin.h>
30
31 #include <afs/cellconfig.h>
32 #include <afs/cmd.h>
33
34
35 /* define some globals */
36 static char myCellName[MAXCELLCHARS];
37 static void *myTokenHandle;
38 static void *myCellHandle;
39
40
41
42 /* ------------------- Utility functions ---------------------- */
43
44 static const char *
45 GetErrorText(afs_status_t errorCode)
46 {
47     afs_status_t st;
48     const char *errorCodeText;
49     static const char *failedLookupText = "unable to translate error code";
50
51     if (util_AdminErrorCodeTranslate(errorCode, 0, &errorCodeText, &st)) {
52         return errorCodeText;
53     } else {
54         return failedLookupText;
55     }
56 }
57
58
59 /* ------------------- CellServDB functions ------------------------ */
60
61 #define CSDBCallBackId 42
62 static pthread_mutex_t CSDBCallBackMutex;
63 static pthread_cond_t CSDBCallBackCond;
64 static int CSDBCallBackDone;
65
66 static void ADMINAPI
67 CellServDbCallBack(void *callBackId, cfg_cellServDbStatus_t * statusItemP,
68                    afs_status_t st)
69 {
70     if (statusItemP != NULL) {
71         printf("Updated %s with result '%s' (tid = %u)\n",
72                statusItemP->fsDbHost, GetErrorText(statusItemP->status),
73                (unsigned)pthread_self());
74     } else {
75         printf("Update termination (tid = %u)\n", (unsigned)pthread_self());
76
77         (void)pthread_mutex_lock(&CSDBCallBackMutex);
78         CSDBCallBackDone = 1;
79         (void)pthread_mutex_unlock(&CSDBCallBackMutex);
80         (void)pthread_cond_signal(&CSDBCallBackCond);
81     }
82
83     if (callBackId != (void *)CSDBCallBackId) {
84         printf("Update call back ID invalid (tid = %u)\n",
85                (unsigned)pthread_self());
86     }
87 }
88
89
90 static int
91 DoCellServDbAddHost(struct cmd_syndesc *as, void *arock)
92 {
93     afs_status_t st = 0;
94     int maxUpdates;
95     void *hostHandle;
96     char *cfgHost = as->parms[0].items->data;
97     char *sysHost = NULL;
98
99     if (as->parms[1].items) {
100         sysHost = as->parms[1].items->data;
101     }
102
103     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
104         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
105     } else {
106         CSDBCallBackDone = 0;
107
108         if (!cfg_CellServDbAddHost
109             (hostHandle, sysHost, CellServDbCallBack, (void *)CSDBCallBackId,
110              &maxUpdates, &st)) {
111             printf("cfg_CellServDbAddHost failed (%s)\n", GetErrorText(st));
112             CSDBCallBackDone = 1;
113
114         } else {
115             printf("cfg_CellServDbAddHost succeeded (maxUpdates = %d)\n",
116                    maxUpdates);
117         }
118
119         (void)pthread_mutex_lock(&CSDBCallBackMutex);
120
121         while (!CSDBCallBackDone) {
122             (void)pthread_cond_wait(&CSDBCallBackCond, &CSDBCallBackMutex);
123         }
124
125         (void)pthread_mutex_unlock(&CSDBCallBackMutex);
126
127         if (!cfg_HostClose(hostHandle, &st)) {
128             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
129         }
130     }
131     return (st == 0 ? 0 : 1);
132 }
133
134
135 static int
136 DoCellServDbRemoveHost(struct cmd_syndesc *as, void *arock)
137 {
138     afs_status_t st = 0;
139     int maxUpdates;
140     void *hostHandle;
141     char *cfgHost = as->parms[0].items->data;
142     char *sysHost = NULL;
143
144     if (as->parms[1].items) {
145         sysHost = as->parms[1].items->data;
146     }
147
148     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
149         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
150     } else {
151         CSDBCallBackDone = 0;
152
153         if (!cfg_CellServDbRemoveHost
154             (hostHandle, sysHost, CellServDbCallBack, (void *)CSDBCallBackId,
155              &maxUpdates, &st)) {
156             printf("cfg_CellServDbRemoveHost failed (%s)\n",
157                    GetErrorText(st));
158             CSDBCallBackDone = 1;
159
160         } else {
161             printf("cfg_CellServDbRemoveHost succeeded (maxUpdates = %d)\n",
162                    maxUpdates);
163         }
164
165         (void)pthread_mutex_lock(&CSDBCallBackMutex);
166
167         while (!CSDBCallBackDone) {
168             (void)pthread_cond_wait(&CSDBCallBackCond, &CSDBCallBackMutex);
169         }
170
171         (void)pthread_mutex_unlock(&CSDBCallBackMutex);
172
173         if (!cfg_HostClose(hostHandle, &st)) {
174             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
175         }
176     }
177     return (st == 0 ? 0 : 1);
178 }
179
180
181 static int
182 DoCellServDbEnumerate(struct cmd_syndesc *as, void *arock)
183 {
184     afs_status_t st = 0;
185     char *fsDbHost = as->parms[0].items->data;
186     char *cellName;
187     char *cellDbHosts;
188
189     if (!cfg_CellServDbEnumerate(fsDbHost, &cellName, &cellDbHosts, &st)) {
190         printf("cfg_CellServDbEnumerate failed (%s)\n", GetErrorText(st));
191     } else {
192         char *mstrp;
193
194         printf("%s is in cell %s\n", fsDbHost, cellName);
195
196         for (mstrp = cellDbHosts; *mstrp != '\0'; mstrp += strlen(mstrp) + 1) {
197             printf("\t%s\n", mstrp);
198         }
199
200         if (!cfg_StringDeallocate(cellName, &st)) {
201             printf("cfg_StringDeallocate failed (%s)\n", GetErrorText(st));
202         }
203
204         if (!cfg_StringDeallocate(cellDbHosts, &st)) {
205             printf("cfg_StringDeallocate failed (%s)\n", GetErrorText(st));
206         }
207     }
208     return (st == 0 ? 0 : 1);
209 }
210
211
212 static void
213 SetupCellServDbCmd(void)
214 {
215     struct cmd_syndesc *ts;
216
217     ts = cmd_CreateSyntax("CellServDbAddHost", DoCellServDbAddHost, NULL,
218                           "add configuration target to server CellServDB");
219     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
220                 "configuration host");
221     cmd_AddParm(ts, "-syshost", CMD_SINGLE, CMD_OPTIONAL,
222                 "system control host");
223
224     ts = cmd_CreateSyntax("CellServDbRemoveHost", DoCellServDbRemoveHost, NULL,
225                           "remove configuration target from server CellServDB");
226     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
227                 "configuration host");
228     cmd_AddParm(ts, "-syshost", CMD_SINGLE, CMD_OPTIONAL,
229                 "system control host");
230
231     ts = cmd_CreateSyntax("CellServDbEnumerate", DoCellServDbEnumerate, NULL,
232                           "enumerate server CellServDB from specified host");
233     cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_REQUIRED, "host name");
234
235
236     (void)pthread_mutex_init(&CSDBCallBackMutex, NULL);
237     (void)pthread_cond_init(&CSDBCallBackCond, NULL);
238 }
239
240
241
242 /* ------------------- Server functions ------------------------ */
243
244
245 static int
246 DoDbServersWaitForQuorum(struct cmd_syndesc *as, void *arock)
247 {
248     afs_status_t st = 0;
249     void *hostHandle;
250     char *cfgHost = as->parms[0].items->data;
251     unsigned int timeout = 180;
252
253     if (as->parms[1].items) {
254         timeout = strtoul(as->parms[1].items->data, NULL, 10);
255     }
256
257     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
258         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
259     } else {
260         if (!cfg_DbServersWaitForQuorum(hostHandle, timeout, &st)) {
261             printf("cfg_DbServersWaitForQuorum failed (%s)\n",
262                    GetErrorText(st));
263         }
264
265         if (!cfg_HostClose(hostHandle, &st)) {
266             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
267         }
268     }
269     return (st == 0 ? 0 : 1);
270 }
271
272
273 static int
274 DoFileServerStop(struct cmd_syndesc *as, void *arock)
275 {
276     afs_status_t st = 0;
277     void *hostHandle;
278     char *cfgHost = as->parms[0].items->data;
279
280     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
281         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
282     } else {
283         if (!cfg_FileServerStop(hostHandle, &st)) {
284             printf("cfg_FileServerStop failed (%s)\n", GetErrorText(st));
285         }
286
287         if (!cfg_HostClose(hostHandle, &st)) {
288             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
289         }
290     }
291     return (st == 0 ? 0 : 1);
292 }
293
294 static int
295 DoFileServerStart(struct cmd_syndesc *as, void *arock)
296 {
297     afs_status_t st = 0;
298     void *hostHandle;
299     char *cfgHost = as->parms[0].items->data;
300
301     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
302         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
303     } else {
304         if (!cfg_FileServerStart(hostHandle, &st)) {
305             printf("cfg_FileServerStart failed (%s)\n", GetErrorText(st));
306         }
307
308         if (!cfg_HostClose(hostHandle, &st)) {
309             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
310         }
311     }
312     return (st == 0 ? 0 : 1);
313 }
314
315
316 static void
317 SetupServerCmd(void)
318 {
319     struct cmd_syndesc *ts;
320
321     ts = cmd_CreateSyntax("DbServersWaitForQuorum", DoDbServersWaitForQuorum,
322                           NULL, "wait for database servers to achieve quorum");
323     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
324                 "configuration host");
325     cmd_AddParm(ts, "-timeout", CMD_SINGLE, CMD_OPTIONAL,
326                 "timeout in seconds");
327
328     ts = cmd_CreateSyntax("FileServerStop", DoFileServerStop, NULL,
329                           "stop and unconfigure fileserver on specified host");
330     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
331                 "configuration host");
332
333     ts = cmd_CreateSyntax("FileServerStart", DoFileServerStart, NULL,
334                           "start the fileserver on specified host");
335     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
336                 "configuration host");
337 }
338
339
340
341 /* ------------------- Host functions ------------------------ */
342
343
344 static int
345 DoHostPartitionTableEnumerate(struct cmd_syndesc *as, void *arock)
346 {
347     afs_status_t st = 0;
348     cfg_partitionEntry_t *vptable;
349     int tableCount, i;
350     void *hostHandle;
351     char *cfgHost = as->parms[0].items->data;
352
353     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
354         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
355     } else {
356         if (!cfg_HostPartitionTableEnumerate
357             (hostHandle, &vptable, &tableCount, &st)) {
358             printf("cfg_HostPartitionTableEnumerate failed (%s)\n",
359                    GetErrorText(st));
360         } else {
361             for (i = 0; i < tableCount; i++) {
362                 printf("Partition: %s     Device: %s\n",
363                        vptable[i].partitionName, vptable[i].deviceName);
364             }
365
366             if (!cfg_PartitionListDeallocate(vptable, &st)) {
367                 printf("cfg_PartitionListDeallocate failed (%s)\n",
368                        GetErrorText(st));
369             }
370         }
371
372         if (!cfg_HostClose(hostHandle, &st)) {
373             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
374         }
375     }
376     return (st == 0 ? 0 : 1);
377 }
378
379
380 static void
381 SetupHostCmd(void)
382 {
383     struct cmd_syndesc *ts;
384
385     ts = cmd_CreateSyntax("HostPartitionTableEnumerate",
386                           DoHostPartitionTableEnumerate, NULL,
387                           "enumerate vice partition table");
388     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
389                 "configuration host");
390 }
391
392
393
394
395 /* ------------------- Client functions ------------------------ */
396
397
398 static int
399 DoClientCellServDbAdd(struct cmd_syndesc *as, void *arock)
400 {
401     afs_status_t st = 0;
402     void *hostHandle;
403     char *cfgHost = as->parms[0].items->data;
404     char *cellName = as->parms[1].items->data;
405     char *dbHost = as->parms[2].items->data;
406
407     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
408         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
409     } else {
410         if (!cfg_ClientCellServDbAdd(hostHandle, cellName, dbHost, &st)) {
411             printf("cfg_ClientCellServDbAdd failed (%s)\n", GetErrorText(st));
412         }
413
414         if (!cfg_HostClose(hostHandle, &st)) {
415             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
416         }
417     }
418     return (st == 0 ? 0 : 1);
419 }
420
421
422 static int
423 DoClientCellServDbRemove(struct cmd_syndesc *as, void *arock)
424 {
425     afs_status_t st = 0;
426     void *hostHandle;
427     char *cfgHost = as->parms[0].items->data;
428     char *cellName = as->parms[1].items->data;
429     char *dbHost = as->parms[2].items->data;
430
431     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
432         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
433     } else {
434         if (!cfg_ClientCellServDbRemove(hostHandle, cellName, dbHost, &st)) {
435             printf("cfg_ClientCellServDbRemove failed (%s)\n",
436                    GetErrorText(st));
437         }
438
439         if (!cfg_HostClose(hostHandle, &st)) {
440             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
441         }
442     }
443     return (st == 0 ? 0 : 1);
444 }
445
446
447 static int
448 DoClientStart(struct cmd_syndesc *as, void *arock)
449 {
450     afs_status_t st = 0;
451     void *hostHandle;
452     char *cfgHost = as->parms[0].items->data;
453     char *timeoutStr = as->parms[1].items->data;
454     unsigned int timeoutVal;
455
456     timeoutVal = strtoul(timeoutStr, NULL, 10);
457
458     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
459         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
460     } else {
461         if (!cfg_ClientStart(hostHandle, timeoutVal, &st)) {
462             printf("cfg_ClientStart failed (%s)\n", GetErrorText(st));
463         }
464
465         if (!cfg_HostClose(hostHandle, &st)) {
466             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
467         }
468     }
469     return (st == 0 ? 0 : 1);
470 }
471
472
473
474 static int
475 DoClientStop(struct cmd_syndesc *as, void *arock)
476 {
477     afs_status_t st = 0;
478     void *hostHandle;
479     char *cfgHost = as->parms[0].items->data;
480     char *timeoutStr = as->parms[1].items->data;
481     unsigned int timeoutVal;
482
483     timeoutVal = strtoul(timeoutStr, NULL, 10);
484
485     if (!cfg_HostOpen(myCellHandle, cfgHost, &hostHandle, &st)) {
486         printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
487     } else {
488         if (!cfg_ClientStop(hostHandle, timeoutVal, &st)) {
489             printf("cfg_ClientStop failed (%s)\n", GetErrorText(st));
490         }
491
492         if (!cfg_HostClose(hostHandle, &st)) {
493             printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
494         }
495     }
496     return (st == 0 ? 0 : 1);
497 }
498
499
500
501 static int
502 DoClientSetCell(struct cmd_syndesc *as, void *arock)
503 {
504     afs_status_t st = 0;
505     void *hostHandle;
506     char *cfgHost = as->parms[0].items->data;
507     char *cellName = as->parms[1].items->data;
508     struct cmd_item *citem;
509     char cellDbHosts[1024];
510     char *dbHost = cellDbHosts;
511     void *nullCellHandle;
512
513     /* setup multistring of database hosts */
514     for (citem = as->parms[2].items; citem != NULL; citem = citem->next) {
515         strcpy(dbHost, citem->data);
516         dbHost += strlen(citem->data) + 1;
517     }
518     *dbHost = '\0';
519
520     /* use a null cell handle to avoid "cell mismatch" */
521     if (!afsclient_NullCellOpen(&nullCellHandle, &st)) {
522         printf("afsclient_NullCellOpen failed (%s)\n", GetErrorText(st));
523     } else {
524         if (!cfg_HostOpen(nullCellHandle, cfgHost, &hostHandle, &st)) {
525             printf("cfg_HostOpen failed (%s)\n", GetErrorText(st));
526         } else {
527             if (!cfg_ClientSetCell(hostHandle, cellName, cellDbHosts, &st)) {
528                 printf("cfg_ClientSetCell failed (%s)\n", GetErrorText(st));
529             }
530
531             if (!cfg_HostClose(hostHandle, &st)) {
532                 printf("cfg_HostClose failed (%s)\n", GetErrorText(st));
533             }
534         }
535
536         if (!afsclient_CellClose(nullCellHandle, &st)) {
537             printf("afsclient_CellClose failed (%s)\n", GetErrorText(st));
538         }
539     }
540     return (st == 0 ? 0 : 1);
541 }
542
543
544 static int
545 DoClientQueryStatus(struct cmd_syndesc *as, void *arock)
546 {
547     afs_status_t st = 0;
548     char *cfgHost = as->parms[0].items->data;
549     short cmInstalled;
550     unsigned cmVersion;
551     afs_status_t clientSt;
552     char *clientCell;
553
554     if (!cfg_ClientQueryStatus
555         (cfgHost, &cmInstalled, &cmVersion, &clientSt, &clientCell, &st)) {
556         printf("cfg_ClientQueryStatus failed (%s)\n", GetErrorText(st));
557     } else {
558         if (cmInstalled) {
559             printf("Client (CM) version %u is installed.\n", cmVersion);
560         } else {
561             printf("Client (CM) is not installed.\n");
562         }
563
564         if (clientSt == 0) {
565             printf("Client configuration is valid; default cell is %s.\n",
566                    clientCell);
567         } else {
568             printf("Client configuration is not valid (%s).\n",
569                    GetErrorText(clientSt));
570         }
571     }
572
573     return (st == 0 ? 0 : 1);
574 }
575
576
577
578 static int
579 DoHostQueryStatus(struct cmd_syndesc *as, void *arock)
580 {
581     afs_status_t st = 0;
582     char *cfgHost = as->parms[0].items->data;
583     afs_status_t serverSt;
584     char *serverCell;
585
586     if (!cfg_HostQueryStatus(cfgHost, &serverSt, &serverCell, &st)) {
587         printf("cfg_HostQueryStatus failed (%s)\n", GetErrorText(st));
588     } else {
589         if (serverSt == 0) {
590             printf("Server configuration is valid; cell is %s.\n",
591                    serverCell);
592         } else {
593             printf("Server configuration is not valid (%s).\n",
594                    GetErrorText(serverSt));
595         }
596     }
597
598     return (st == 0 ? 0 : 1);
599 }
600
601
602
603
604
605
606 static void
607 SetupClientCmd(void)
608 {
609     struct cmd_syndesc *ts;
610
611     ts = cmd_CreateSyntax("ClientCellServDbAdd", DoClientCellServDbAdd, NULL,
612                           "add host entry to client CellServDB");
613     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
614                 "configuration host");
615     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name");
616     cmd_AddParm(ts, "-dbhost", CMD_SINGLE, CMD_REQUIRED, "host to add");
617
618     ts = cmd_CreateSyntax("ClientCellServDbRemove", DoClientCellServDbRemove,
619                           NULL, "remove host entry from client CellServDB");
620     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
621                 "configuration host");
622     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name");
623     cmd_AddParm(ts, "-dbhost", CMD_SINGLE, CMD_REQUIRED, "host to remove");
624
625     ts = cmd_CreateSyntax("ClientSetCell", DoClientSetCell, NULL,
626                           "set default client cell");
627     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
628                 "configuration host");
629     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name");
630     cmd_AddParm(ts, "-dbhosts", CMD_LIST, CMD_REQUIRED, "database hosts");
631
632     ts = cmd_CreateSyntax("ClientQueryStatus", DoClientQueryStatus, NULL,
633                           "query status of client on host");
634     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
635                 "configuration host");
636
637     ts = cmd_CreateSyntax("HostQueryStatus", DoHostQueryStatus, NULL,
638                           "query status of server on host");
639     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
640                 "configuration host");
641
642
643     ts = cmd_CreateSyntax("ClientStart", DoClientStart, NULL,
644                           "start the client");
645     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
646                 "configuration host");
647     cmd_AddParm(ts, "-timeout", CMD_SINGLE, CMD_REQUIRED, "wait timeout");
648
649
650     ts = cmd_CreateSyntax("ClientStop", DoClientStop, NULL, "stop the client");
651     cmd_AddParm(ts, "-cfghost", CMD_SINGLE, CMD_REQUIRED,
652                 "configuration host");
653     cmd_AddParm(ts, "-timeout", CMD_SINGLE, CMD_REQUIRED, "wait timeout");
654 }
655
656
657
658
659 int
660 main(int argc, char *argv[])
661 {
662     int code;
663     afs_status_t st;
664     char *whoami = argv[0];
665
666     /* perform client initialization */
667
668     if (!afsclient_Init(&st)) {
669         printf("afsclient_Init failed (%s)\n", GetErrorText(st));
670         exit(1);
671     }
672
673     if (!afsclient_LocalCellGet(myCellName, &st)) {
674         printf("afsclient_LocalCellGet failed (%s)\n", GetErrorText(st));
675         exit(1);
676     } else {
677         printf("%s running in cell %s\n\n", whoami, myCellName);
678     }
679
680     if (!afsclient_TokenGetExisting(myCellName, &myTokenHandle, &st)) {
681         printf("afsclient_TokenGetExisting failed (%s)\n", GetErrorText(st));
682         printf("Test will run unauthenticated\n\n");
683
684         if (!afsclient_TokenGetNew
685             (myCellName, NULL, NULL, &myTokenHandle, &st)) {
686             printf("afsclient_TokenGetNew failed (%s)\n", GetErrorText(st));
687             exit(1);
688         }
689     }
690
691     if (!afsclient_CellOpen(myCellName, myTokenHandle, &myCellHandle, &st)) {
692         printf("afsclient_CellOpen failed (%s)\n", GetErrorText(st));
693         exit(1);
694     }
695
696     /* initialize command syntax and globals */
697
698     SetupCellServDbCmd();
699     SetupServerCmd();
700     SetupHostCmd();
701     SetupClientCmd();
702
703     /* execute command */
704
705     code = cmd_Dispatch(argc, argv);
706
707     /* release handles */
708
709     if (!afsclient_CellClose(myCellHandle, &st)) {
710         printf("afsclient_CellClose failed (%s)\n", GetErrorText(st));
711         exit(1);
712     }
713
714     if (!afsclient_TokenClose(myTokenHandle, &st)) {
715         printf("afsclient_TokenClose failed (%s)\n", GetErrorText(st));
716         exit(1);
717     }
718
719     return (code);
720 }