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