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