2 * Copyright 2000, International Business Machines Corporation and others.
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
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.
24 --------------------------------------------------------------------------------------------------------------*/
25 #include <afsconfig.h>
26 #include <afs/param.h>
29 #include <sys/types.h>
34 #include <afs/afsutil.h>
38 #include <netinet/in.h>
40 #include <afs/cellconfig.h>
43 int _afsconf_Touch(struct afsconf_dir *adir);
52 PrintOneCell(struct afsconf_cell *ainfo, void *arock, struct afsconf_dir *adir)
57 printf("Cell %s:\n", ainfo->name);
58 for (i = 0; i < ainfo->numServers; i++) {
59 memcpy(&temp, &ainfo->hostAddr[i].sin_addr, sizeof(long));
60 printf(" %d host %s at %lx port %x clone %s\n", i, ainfo->hostName[i], temp,
61 ainfo->hostAddr[i].sin_port, (ainfo->clone[i] ? "yes" : "no"));
67 PrintClones(char *clones, int numServers)
72 for (i = 0; i < numServers; i++) {
73 printf(" %d clone %s\n", i, (clones[i] ? "yes" : "no"));
78 TestCellConfig(struct cmd_syndesc *as, void *arock)
80 struct afsconf_dir *theDir;
82 struct afsconf_cell theCell;
85 char clones[MAXHOSTSPERCELL];
87 struct cmd_item *cells = NULL;
89 memset(clones, 0, sizeof(clones));
91 cmd_OptionAsString(as, OPT_confdir, &dirName);
92 reload = cmd_OptionPresent(as, OPT_reload);
95 dirName = strdup(AFSDIR_SERVER_ETC_DIRPATH);
96 theDir = afsconf_Open(dirName);
98 printf("could not open configuration files in '%s'\n", dirName);
104 code = afsconf_GetLocalCell(theDir, tbuffer, sizeof(tbuffer));
106 printf("get local cell failed, code %d\n", code);
107 afsconf_Close(theDir);
111 printf("Local cell is '%s'\n\n", tbuffer);
113 if (cmd_OptionAsList(as, OPT_cell, &cells) != 0) {
114 printf("About to print cell database contents:\n");
115 afsconf_CellApply(theDir, PrintOneCell, 0);
117 /* do this junk once */
118 printf("start of special test\n");
119 code = afsconf_GetCellInfo(theDir, NULL, "afsprot", &theCell);
121 printf("failed to find afsprot service (%d)\n", code);
123 printf("AFSPROT service:\n");
124 PrintOneCell(&theCell, NULL, theDir);
126 code = afsconf_GetExtendedCellInfo(theDir, NULL, "afsprot", &theCell, clones);
128 printf("failed to find extended cell info (%d)\n", code);
130 printf("AFSPROT service extended info:\n");
131 PrintOneCell(&theCell, NULL, theDir);
132 PrintClones(clones, theCell.numServers);
134 code = afsconf_GetCellInfo(theDir, 0, "bozotheclown", &theCell);
136 printf("unexpectedly found service 'bozotheclown'\n");
137 code = afsconf_GetCellInfo(theDir, NULL, "telnet", &theCell);
138 printf("Here's the telnet service:\n");
139 PrintOneCell(&theCell, NULL, theDir);
140 printf("done with special test\n");
142 /* Now print out specified cell info. */
143 for (; cells != NULL; cells = cells->next) {
144 char *cell = cells->data;
145 code = afsconf_GetCellInfo(theDir, cell, 0, &theCell);
147 printf("Could not find info for cell '%s', code %d\n",
150 PrintOneCell(&theCell, NULL, theDir);
152 /* And print extended cell info. */
153 memset(clones, 0, sizeof(clones));
154 code = afsconf_GetExtendedCellInfo(theDir, cell, "afsprot", &theCell, clones);
156 printf("Could not find extended info for cell '%s', code %d\n",
159 PrintOneCell(&theCell, NULL, theDir);
160 PrintClones(clones, theCell.numServers);
166 printf("Forcing reload\n");
167 code = _afsconf_Touch(theDir);
169 printf("Unable to touch cellservdb file (%d)\n", code);
172 code = afsconf_GetCellInfo(theDir, NULL, "afsprot", &theCell);
174 printf("failed to find afsprot service (%d)\n", code);
176 PrintOneCell(&theCell, NULL, theDir);
181 afsconf_Close(theDir);
188 main(int argc, char *argv[])
191 struct cmd_syndesc *ts;
195 /* Start up sockets */
196 WSAStartup(0x0101, &WSAjunk);
197 #endif /* AFS_NT40_ENV */
199 ts = cmd_CreateSyntax("initcmd", TestCellConfig, NULL, 0, "Test cell configuration");
200 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
201 "Configuration directory pathname");
202 cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_LIST, CMD_OPTIONAL, "Cell to display");
203 cmd_AddParmAtOffset(ts, OPT_reload, "-reload", CMD_FLAG, CMD_OPTIONAL, "Perform reload test");
205 code = cmd_Dispatch(argc, argv);