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