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