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>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
33 #include "cellconfig.h"
36 /* write ThisCell and CellServDB containing exactly one cell's info specified
37 by acellInfo parm. Useful only on the server (which describes only one cell).
40 static VerifyEntries(aci)
41 register struct afsconf_cell *aci; {
43 register struct hostent *th;
45 for(i=0;i<aci->numServers;i++) {
46 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
47 /* no address spec'd */
48 if (*(aci->hostName[i]) != 0) {
49 th = gethostbyname(aci->hostName[i]);
51 printf("Host %s not found in host database...\n", aci->hostName[i]);
52 return AFSCONF_FAILURE;
54 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr, sizeof(afs_int32));
56 /* otherwise we're deleting this entry */
59 /* address spec'd, perhaps no name known */
60 if (aci->hostName[i][0] != 0) continue; /* name known too */
61 /* figure out name, if possible */
62 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4, AF_INET);
64 strcpy(aci->hostName[i], "UNKNOWNHOST");
67 strcpy(aci->hostName[i], th->h_name);
74 /* Changed the interface to accept the afsconf_dir datastructure.
75 This is a handle to the internal cache that is maintained by the bosserver.
78 afsconf_SetCellInfo(adir, apath, acellInfo)
79 struct afsconf_dir *adir;
81 struct afsconf_cell *acellInfo;
85 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, (char *)0);
89 afsconf_SetExtendedCellInfo(adir, apath, acellInfo, clones)
90 struct afsconf_dir *adir;
92 struct afsconf_cell *acellInfo;
95 register afs_int32 code;
102 /* write ThisCell file */
103 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
105 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
110 i = strlen(acellInfo->name);
111 code = write(fd, acellInfo->name, i);
114 return AFSCONF_FAILURE;
121 /* make sure we have both name and address for each host, looking up other
123 code = VerifyEntries(acellInfo);
129 /* write CellServDB */
130 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
131 tf = fopen(tbuffer, "w");
134 return AFSCONF_NOTFOUND;
136 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
137 for(i=0;i < acellInfo->numServers; i++) {
138 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
139 if (code == 0) continue; /* delete request */
140 code = ntohl(code); /* convert to host order */
141 if (clones && clones[i])
142 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code>>24) & 0xff, (code>>16)&0xff, (code>>8)&0xff, code&0xff, acellInfo->hostName[i]);
144 fprintf(tf, "%d.%d.%d.%d #%s\n", (code>>24) & 0xff, (code>>16)&0xff, (code>>8)&0xff, code&0xff, acellInfo->hostName[i]);
149 return AFSCONF_FAILURE;
153 /* Reset the timestamp in the cache, so that
154 the CellServDB is read into the cache next time.
155 Resolves the lost update problem due to an inconsistent cache
157 if (adir) adir->timeRead = 0;
160 if (code == EOF) return AFSCONF_FAILURE;