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>
14 #include <afs/pthread_glock.h>
15 #include <afs/afsutil.h>
16 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
37 #include "cellconfig.h"
40 /* write ThisCell and CellServDB containing exactly one cell's info specified
41 by acellInfo parm. Useful only on the server (which describes only one cell).
45 VerifyEntries(struct afsconf_cell *aci)
50 for (i = 0; i < aci->numServers; i++) {
51 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
52 /* no address spec'd */
53 if (*(aci->hostName[i]) != 0) {
54 th = gethostbyname(aci->hostName[i]);
56 printf("Host %s not found in host database...\n",
58 return AFSCONF_FAILURE;
60 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
63 /* otherwise we're deleting this entry */
65 /* address spec'd, perhaps no name known */
66 if (aci->hostName[i][0] != 0)
67 continue; /* name known too */
68 /* figure out name, if possible */
69 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
72 strcpy(aci->hostName[i], "UNKNOWNHOST");
74 strcpy(aci->hostName[i], th->h_name);
81 /* Changed the interface to accept the afsconf_dir datastructure.
82 This is a handle to the internal cache that is maintained by the bosserver.
86 afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
87 struct afsconf_cell *acellInfo)
91 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
96 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
98 struct afsconf_cell *acellInfo, char clones[])
107 /* write ThisCell file */
108 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
110 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
115 i = (int)strlen(acellInfo->name);
116 code = write(fd, acellInfo->name, i);
119 return AFSCONF_FAILURE;
126 /* make sure we have both name and address for each host, looking up other
128 code = VerifyEntries(acellInfo);
134 /* write CellServDB */
135 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
136 tf = fopen(tbuffer, "w");
139 return AFSCONF_NOTFOUND;
141 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
142 for (i = 0; i < acellInfo->numServers; i++) {
143 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
145 continue; /* delete request */
146 code = ntohl(code); /* convert to host order */
147 if (clones && clones[i])
148 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
149 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
150 acellInfo->hostName[i]);
152 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
153 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
154 acellInfo->hostName[i]);
159 return AFSCONF_FAILURE;
163 /* Reset the timestamp in the cache, so that
164 * the CellServDB is read into the cache next time.
165 * Resolves the lost update problem due to an inconsistent cache
172 return AFSCONF_FAILURE;