4f8002615df83c048dc3448ea990dc7f37b9aa8f
[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 PrintOneCell(ainfo, arock, adir)
44      struct afsconf_cell *ainfo;
45      char *arock;
46      struct afsconf_dir *adir;
47 {
48     register int i;
49     long temp;
50
51     printf("Cell %s:\n", ainfo->name);
52     for (i = 0; i < ainfo->numServers; i++) {
53         memcpy(&temp, &ainfo->hostAddr[i].sin_addr, sizeof(long));
54         printf("    host %s at %x.%x\n", ainfo->hostName[i], temp,
55                ainfo->hostAddr[i].sin_port);
56     }
57     return 0;
58 }
59
60 /*Main for testcellconfig*/
61 main(argc, argv)
62      int argc;
63      char *argv[];
64 {
65     struct afsconf_dir *theDir;
66     char tbuffer[1024];
67     struct afsconf_cell theCell;
68     long i;
69     register long code;
70     char *dirName;
71
72     if (argc < 2) {
73         printf
74             ("usage: testcellconfig <conf-dir-name> [<cell-to-display>]*\n");
75         exit(1);
76     }
77
78     dirName = argv[1];
79     theDir = afsconf_Open(dirName);
80     if (!theDir) {
81         printf("could not open configuration files in '%s'\n", dirName);
82         exit(1);
83     }
84
85     /* get the cell */
86     code = afsconf_GetLocalCell(theDir, tbuffer, sizeof(tbuffer));
87     if (code != 0) {
88         printf("get local cell failed, code %d\n", code);
89         exit(1);
90     }
91     printf("Local cell is '%s'\n\n", tbuffer);
92
93     if (argc == 2) {
94         printf("About to print cell database contents:\n");
95         afsconf_CellApply(theDir, PrintOneCell, 0);
96         printf("Done.\n\n");
97         /* do this junk once */
98         printf("start of special test\n");
99         code = afsconf_GetCellInfo(theDir, NULL, "afsprot", &theCell);
100         if (code)
101             printf("failed to find afsprot service (%d)\n", code);
102         else {
103             printf("AFSPROT service:\n");
104             PrintOneCell(&theCell, (char *)NULL, theDir);
105         }
106         code = afsconf_GetCellInfo(theDir, 0, "bozotheclown", &theCell);
107         if (code == 0)
108             printf("unexpectedly found service 'bozotheclown'\n");
109         code = afsconf_GetCellInfo(theDir, NULL, "telnet", &theCell);
110         printf("Here's the telnet service:\n");
111         PrintOneCell(&theCell, NULL, theDir);
112         printf("done with special test\n");
113     } else {
114         /* now print out specified cell info */
115         for (i = 2; i < argc; i++) {
116             code = afsconf_GetCellInfo(theDir, argv[i], 0, &theCell);
117             if (code) {
118                 printf("Could not find info for cell '%s', code %d\n",
119                        argv[i], code);
120             } else
121                 PrintOneCell(&theCell, NULL, theDir);
122         }
123     }
124
125     /* all done */
126     exit(0);
127 }