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 <afs/param.h>
11 #include <afs/pthread_glock.h>
12 #include <afs/afsutil.h>
13 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
29 #include "cellconfig.h"
32 /* write ThisCell and CellServDB containing exactly one cell's info specified
33 by acellInfo parm. Useful only on the server (which describes only one cell).
36 static VerifyEntries(aci)
37 register struct afsconf_cell *aci; {
39 register struct hostent *th;
41 for(i=0;i<aci->numServers;i++) {
42 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
43 /* no address spec'd */
44 if (*(aci->hostName[i]) != 0) {
45 th = gethostbyname(aci->hostName[i]);
47 printf("Host %s not found in host database...\n", aci->hostName[i]);
48 return AFSCONF_FAILURE;
50 bcopy(th->h_addr, &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
52 /* otherwise we're deleting this entry */
55 /* address spec'd, perhaps no name known */
56 if (aci->hostName[i][0] != 0) continue; /* name known too */
57 /* figure out name, if possible */
58 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4, AF_INET);
60 strcpy(aci->hostName[i], "UNKNOWNHOST");
63 strcpy(aci->hostName[i], th->h_name);
70 /* Changed the interface to accept the afsconf_dir datastructure.
71 This is a handle to the internal cache that is maintained by the bosserver.
74 afsconf_SetCellInfo(adir, apath, acellInfo)
75 struct afsconf_dir *adir;
77 struct afsconf_cell *acellInfo; {
78 register afs_int32 code;
85 /* write ThisCell file */
86 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
88 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
93 i = strlen(acellInfo->name);
94 code = write(fd, acellInfo->name, i);
97 return AFSCONF_FAILURE;
104 /* make sure we have both name and address for each host, looking up other
106 code = VerifyEntries(acellInfo);
112 /* write CellServDB */
113 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
114 tf = fopen(tbuffer, "w");
117 return AFSCONF_NOTFOUND;
119 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
120 for(i=0;i < acellInfo->numServers; i++) {
121 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
122 if (code == 0) continue; /* delete request */
123 code = ntohl(code); /* convert to host order */
124 fprintf(tf, "%d.%d.%d.%d #%s\n", (code>>24) & 0xff, (code>>16)&0xff, (code>>8)&0xff, code&0xff, acellInfo->hostName[i]);
129 return AFSCONF_FAILURE;
133 /* Reset the timestamp in the cache, so that
134 the CellServDB is read into the cache next time.
135 Resolves the lost update problem due to an inconsistent cache
137 if (adir) adir->timeRead = 0;
140 if (code == EOF) return AFSCONF_FAILURE;