1bc9cae600d4f663e33b9b97f1756011fd086447
[openafs.git] / src / auth / test / testcellconf.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 /*
11 testcellconfig.c:
12
13     Test of the routines used by the FileServer to manipulate the cell/server database and
14     determine the local cell name:
15         1) Reading in the local cell name from file.
16         2) Reading in the cell/server database from disk.
17         3) Reporting the set of servers associated with a given cell name.
18         4) Printing out the contents of the cell/server database.
19         5) Reclaiming the space used by an in-memory database.
20
21 Creation date:
22     17 August 1987
23
24 --------------------------------------------------------------------------------------------------------------*/
25 #include <afsconfig.h>
26 #include <afs/param.h>
27
28 RCSID
29     ("$Header$");
30
31 #include <sys/types.h>
32 #include <stddef.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <afs/afsutil.h>
36 #ifdef AFS_NT40_ENV
37 #include <winsock2.h>
38 #else
39 #include <netinet/in.h>
40 #endif
41 #include <afs/cellconfig.h>
42
43 int 
44 PrintOneCell(struct afsconf_cell *ainfo, void *arock, struct afsconf_dir *adir)
45 {
46     register int i;
47     long temp;
48
49     printf("Cell %s:\n", ainfo->name);
50     for (i = 0; i < ainfo->numServers; i++) {
51         memcpy(&temp, &ainfo->hostAddr[i].sin_addr, sizeof(long));
52         printf("    host %s at %x.%x\n", ainfo->hostName[i], temp,
53                ainfo->hostAddr[i].sin_port);
54     }
55     return 0;
56 }
57
58 /*Main for testcellconfig*/
59 main(argc, argv)
60      int argc;
61      char *argv[];
62 {
63     struct afsconf_dir *theDir;
64     char tbuffer[1024];
65     struct afsconf_cell theCell;
66     long i;
67     register long code;
68     char *dirName;
69
70     if (argc < 2) {
71         printf
72             ("usage: testcellconfig <conf-dir-name> [<cell-to-display>]*\n");
73         exit(1);
74     }
75
76     dirName = argv[1];
77     theDir = afsconf_Open(dirName);
78     if (!theDir) {
79         printf("could not open configuration files in '%s'\n", dirName);
80         exit(1);
81     }
82
83     /* get the cell */
84     code = afsconf_GetLocalCell(theDir, tbuffer, sizeof(tbuffer));
85     if (code != 0) {
86         printf("get local cell failed, code %d\n", code);
87         exit(1);
88     }
89     printf("Local cell is '%s'\n\n", tbuffer);
90
91     if (argc == 2) {
92         printf("About to print cell database contents:\n");
93         afsconf_CellApply(theDir, PrintOneCell, 0);
94         printf("Done.\n\n");
95         /* do this junk once */
96         printf("start of special test\n");
97         code = afsconf_GetCellInfo(theDir, NULL, "afsprot", &theCell);
98         if (code)
99             printf("failed to find afsprot service (%d)\n", code);
100         else {
101             printf("AFSPROT service:\n");
102             PrintOneCell(&theCell, NULL, theDir);
103         }
104         code = afsconf_GetCellInfo(theDir, 0, "bozotheclown", &theCell);
105         if (code == 0)
106             printf("unexpectedly found service 'bozotheclown'\n");
107         code = afsconf_GetCellInfo(theDir, NULL, "telnet", &theCell);
108         printf("Here's the telnet service:\n");
109         PrintOneCell(&theCell, NULL, theDir);
110         printf("done with special test\n");
111     } else {
112         /* now print out specified cell info */
113         for (i = 2; i < argc; i++) {
114             code = afsconf_GetCellInfo(theDir, argv[i], 0, &theCell);
115             if (code) {
116                 printf("Could not find info for cell '%s', code %d\n",
117                        argv[i], code);
118             } else
119                 PrintOneCell(&theCell, NULL, theDir);
120         }
121     }
122
123     /* all done */
124     exit(0);
125 }