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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/pthread_glock.h>
16 #include <afs/afsutil.h>
19 #include "cellconfig.h"
22 /* write ThisCell and CellServDB containing exactly one cell's info specified
23 by acellInfo parm. Useful only on the server (which describes only one cell).
27 VerifyEntries(struct afsconf_cell *aci)
32 for (i = 0; i < aci->numServers; i++) {
33 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
34 /* no address spec'd */
35 if (*(aci->hostName[i]) != 0) {
36 th = gethostbyname(aci->hostName[i]);
38 printf("Host %s not found in host database...\n",
40 return AFSCONF_FAILURE;
42 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
45 /* otherwise we're deleting this entry */
47 /* address spec'd, perhaps no name known */
48 if (aci->hostName[i][0] != 0)
49 continue; /* name known too */
50 /* figure out name, if possible */
51 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
54 strcpy(aci->hostName[i], "UNKNOWNHOST");
56 strcpy(aci->hostName[i], th->h_name);
63 /* Changed the interface to accept the afsconf_dir datastructure.
64 This is a handle to the internal cache that is maintained by the bosserver.
68 afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
69 struct afsconf_cell *acellInfo)
73 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
78 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
80 struct afsconf_cell *acellInfo, char clones[])
89 /* write ThisCell file */
90 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
92 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
97 i = (int)strlen(acellInfo->name);
98 code = write(fd, acellInfo->name, i);
101 return AFSCONF_FAILURE;
108 /* make sure we have both name and address for each host, looking up other
110 code = VerifyEntries(acellInfo);
116 /* write CellServDB */
117 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
118 tf = fopen(tbuffer, "w");
121 return AFSCONF_NOTFOUND;
123 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
124 for (i = 0; i < acellInfo->numServers; i++) {
125 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
127 continue; /* delete request */
128 code = ntohl(code); /* convert to host order */
129 if (clones && clones[i])
130 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
131 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
132 acellInfo->hostName[i]);
134 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
135 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
136 acellInfo->hostName[i]);
141 return AFSCONF_FAILURE;
145 /* Reset the timestamp in the cache, so that
146 * the CellServDB is read into the cache next time.
147 * Resolves the lost update problem due to an inconsistent cache
154 return AFSCONF_FAILURE;