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>
18 #include <sys/types.h>
25 #include <sys/socket.h>
26 #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).
47 register struct afsconf_cell *aci;
50 register struct hostent *th;
52 for (i = 0; i < aci->numServers; i++) {
53 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
54 /* no address spec'd */
55 if (*(aci->hostName[i]) != 0) {
56 th = gethostbyname(aci->hostName[i]);
58 printf("Host %s not found in host database...\n",
60 return AFSCONF_FAILURE;
62 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
65 /* otherwise we're deleting this entry */
67 /* address spec'd, perhaps no name known */
68 if (aci->hostName[i][0] != 0)
69 continue; /* name known too */
70 /* figure out name, if possible */
71 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
74 strcpy(aci->hostName[i], "UNKNOWNHOST");
76 strcpy(aci->hostName[i], th->h_name);
83 /* Changed the interface to accept the afsconf_dir datastructure.
84 This is a handle to the internal cache that is maintained by the bosserver.
88 afsconf_SetCellInfo(adir, apath, acellInfo)
89 struct afsconf_dir *adir;
91 struct afsconf_cell *acellInfo;
95 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
100 afsconf_SetExtendedCellInfo(adir, apath, acellInfo, clones)
101 struct afsconf_dir *adir;
103 struct afsconf_cell *acellInfo;
106 register afs_int32 code;
110 register afs_int32 i;
113 /* write ThisCell file */
114 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
116 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
121 i = (int)strlen(acellInfo->name);
122 code = write(fd, acellInfo->name, i);
125 return AFSCONF_FAILURE;
132 /* make sure we have both name and address for each host, looking up other
134 code = VerifyEntries(acellInfo);
140 /* write CellServDB */
141 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
142 tf = fopen(tbuffer, "w");
145 return AFSCONF_NOTFOUND;
147 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
148 for (i = 0; i < acellInfo->numServers; i++) {
149 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
151 continue; /* delete request */
152 code = ntohl(code); /* convert to host order */
153 if (clones && clones[i])
154 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
155 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
156 acellInfo->hostName[i]);
158 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
159 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
160 acellInfo->hostName[i]);
165 return AFSCONF_FAILURE;
169 /* Reset the timestamp in the cache, so that
170 * the CellServDB is read into the cache next time.
171 * Resolves the lost update problem due to an inconsistent cache
178 return AFSCONF_FAILURE;