4627b48bece01a6c667c33574cbab2aea91f9dc7
[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 <afs/param.h>
26 #include <sys/types.h>
27 #include <stddef.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <afs/afsutil.h>
31 #ifdef AFS_NT40_ENV
32 #include <winsock2.h>
33 #else
34 #include <netinet/in.h>
35 #endif
36 #include <afs/cellconfig.h>
37
38 PrintOneCell(ainfo, arock, adir)
39 struct afsconf_cell *ainfo;
40 char *arock;
41 struct afsconf_dir *adir; {
42     register int i;
43     long temp;
44
45     printf("Cell %s:\n", ainfo->name);
46     for(i=0;i<ainfo->numServers;i++) {
47         bcopy(&ainfo->hostAddr[i].sin_addr, &temp, sizeof(long));
48         printf("    host %s at %x.%x\n", ainfo->hostName[i], temp, ainfo->hostAddr[i].sin_port);
49     }
50     return 0;
51 }
52
53 /*Main for testcellconfig*/
54 main(argc, argv)
55 int argc;
56 char *argv[];
57 {
58     struct afsconf_dir *theDir;
59     char tbuffer[1024];
60     struct afsconf_cell theCell;
61     long i;
62     register long code;
63     char *dirName;
64
65     if (argc < 2) {
66         printf("usage: testcellconfig <conf-dir-name> [<cell-to-display>]*\n");
67         exit(1);
68     }
69
70     dirName = argv[1];
71     theDir = afsconf_Open(dirName);
72     if (!theDir) {
73         printf("could not open configuration files in '%s'\n", dirName);
74         exit(1);
75     }
76     
77     /* get the cell */
78     code = afsconf_GetLocalCell(theDir, tbuffer, sizeof(tbuffer));
79     if (code != 0) {
80         printf("get local cell failed, code %d\n", code);
81         exit(1);
82     }
83     printf("Local cell is '%s'\n\n", tbuffer);
84     
85     if (argc == 2) {
86         printf("About to print cell database contents:\n");
87         afsconf_CellApply(theDir, PrintOneCell, 0);
88         printf("Done.\n\n");
89         /* do this junk once */
90         printf("start of special test\n");
91         code = afsconf_GetCellInfo(theDir, (char *) 0, "afsprot", &theCell);
92         if (code) printf("failed to find afsprot service (%d)\n", code);
93         else {
94             printf("AFSPROT service:\n");
95             PrintOneCell(&theCell, (char *) (char *) 0, theDir);
96         }
97         code = afsconf_GetCellInfo(theDir, 0, "bozotheclown", &theCell);
98         if (code == 0) printf("unexpectedly found service 'bozotheclown'\n");
99         code = afsconf_GetCellInfo(theDir, (char *) 0, "telnet", &theCell);
100         printf("Here's the telnet service:\n");
101         PrintOneCell(&theCell, (char *) 0, theDir);
102         printf("done with special test\n");
103     }
104     else {
105         /* now print out specified cell info */
106         for(i = 2; i<argc; i++) {
107             code = afsconf_GetCellInfo(theDir, argv[i], 0, &theCell);
108             if (code) {
109                 printf("Could not find info for cell '%s', code %d\n", argv[i], code);
110             }
111             else PrintOneCell(&theCell, (char *) 0, theDir);
112         }
113     }
114
115     /* all done */
116     exit(0);
117 }