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>
16 #include <afs/pthread_glock.h>
17 #include <afs/afsutil.h>
20 #include "cellconfig.h"
23 /* write ThisCell and CellServDB containing exactly one cell's info specified
24 by acellInfo parm. Useful only on the server (which describes only one cell).
28 VerifyEntries(struct afsconf_cell *aci)
33 for (i = 0; i < aci->numServers; i++) {
34 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
35 /* no address spec'd */
36 if (*(aci->hostName[i]) != 0) {
37 th = gethostbyname(aci->hostName[i]);
39 printf("Host %s not found in host database...\n",
41 return AFSCONF_FAILURE;
43 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
46 /* otherwise we're deleting this entry */
48 /* address spec'd, perhaps no name known */
49 if (aci->hostName[i][0] != 0)
50 continue; /* name known too */
51 /* figure out name, if possible */
52 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
55 strcpy(aci->hostName[i], "UNKNOWNHOST");
57 if (strlcpy(aci->hostName[i],
59 sizeof(aci->hostName[i]))
60 >= sizeof(aci->hostName[i])) {
61 strcpy(aci->hostName[i], "UNKNOWNHOST");
69 /* Changed the interface to accept the afsconf_dir datastructure.
70 This is a handle to the internal cache that is maintained by the bosserver.
74 afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
75 struct afsconf_cell *acellInfo)
79 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
84 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
86 struct afsconf_cell *acellInfo, char clones[])
95 /* write ThisCell file */
96 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, (char *)NULL);
98 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
103 i = (int)strlen(acellInfo->name);
104 code = write(fd, acellInfo->name, i);
107 return AFSCONF_FAILURE;
114 /* make sure we have both name and address for each host, looking up other
116 code = VerifyEntries(acellInfo);
122 /* write CellServDB */
123 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, (char *)NULL);
124 tf = fopen(tbuffer, "w");
127 return AFSCONF_NOTFOUND;
129 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
130 for (i = 0; i < acellInfo->numServers; i++) {
131 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
133 continue; /* delete request */
134 code = ntohl(code); /* convert to host order */
135 if (clones && clones[i])
136 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
137 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
138 acellInfo->hostName[i]);
140 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
141 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
142 acellInfo->hostName[i]);
147 return AFSCONF_FAILURE;
151 /* Reset the timestamp in the cache, so that
152 * the CellServDB is read into the cache next time.
153 * Resolves the lost update problem due to an inconsistent cache
160 return AFSCONF_FAILURE;