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>
17 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
38 #include "cellconfig.h"
41 /* write ThisCell and CellServDB containing exactly one cell's info specified
42 by acellInfo parm. Useful only on the server (which describes only one cell).
46 VerifyEntries(struct afsconf_cell *aci)
51 for (i = 0; i < aci->numServers; i++) {
52 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
53 /* no address spec'd */
54 if (*(aci->hostName[i]) != 0) {
55 th = gethostbyname(aci->hostName[i]);
57 printf("Host %s not found in host database...\n",
59 return AFSCONF_FAILURE;
61 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
64 /* otherwise we're deleting this entry */
66 /* address spec'd, perhaps no name known */
67 if (aci->hostName[i][0] != 0)
68 continue; /* name known too */
69 /* figure out name, if possible */
70 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
73 strcpy(aci->hostName[i], "UNKNOWNHOST");
75 strcpy(aci->hostName[i], th->h_name);
82 /* Changed the interface to accept the afsconf_dir datastructure.
83 This is a handle to the internal cache that is maintained by the bosserver.
87 afsconf_SetCellInfo(struct afsconf_dir *adir, const char *apath,
88 struct afsconf_cell *acellInfo)
92 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
97 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
99 struct afsconf_cell *acellInfo, char clones[])
108 /* write ThisCell file */
109 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
111 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
116 i = (int)strlen(acellInfo->name);
117 code = write(fd, acellInfo->name, i);
120 return AFSCONF_FAILURE;
127 /* make sure we have both name and address for each host, looking up other
129 code = VerifyEntries(acellInfo);
135 /* write CellServDB */
136 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
137 tf = fopen(tbuffer, "w");
140 return AFSCONF_NOTFOUND;
142 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
143 for (i = 0; i < acellInfo->numServers; i++) {
144 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
146 continue; /* delete request */
147 code = ntohl(code); /* convert to host order */
148 if (clones && clones[i])
149 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
150 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
151 acellInfo->hostName[i]);
153 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
154 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
155 acellInfo->hostName[i]);
160 return AFSCONF_FAILURE;
164 /* Reset the timestamp in the cache, so that
165 * the CellServDB is read into the cache next time.
166 * Resolves the lost update problem due to an inconsistent cache
173 return AFSCONF_FAILURE;