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>
44 #include "cellconfig.h"
47 /* write ThisCell and CellServDB containing exactly one cell's info specified
48 by acellInfo parm. Useful only on the server (which describes only one cell).
53 register struct afsconf_cell *aci;
56 register struct hostent *th;
58 for (i = 0; i < aci->numServers; i++) {
59 if (aci->hostAddr[i].sin_addr.s_addr == 0) {
60 /* no address spec'd */
61 if (*(aci->hostName[i]) != 0) {
62 th = gethostbyname(aci->hostName[i]);
64 printf("Host %s not found in host database...\n",
66 return AFSCONF_FAILURE;
68 memcpy(&aci->hostAddr[i].sin_addr, th->h_addr,
71 /* otherwise we're deleting this entry */
73 /* address spec'd, perhaps no name known */
74 if (aci->hostName[i][0] != 0)
75 continue; /* name known too */
76 /* figure out name, if possible */
77 th = gethostbyaddr((char *)(&aci->hostAddr[i].sin_addr), 4,
80 strcpy(aci->hostName[i], "UNKNOWNHOST");
82 strcpy(aci->hostName[i], th->h_name);
89 /* Changed the interface to accept the afsconf_dir datastructure.
90 This is a handle to the internal cache that is maintained by the bosserver.
94 afsconf_SetCellInfo(adir, apath, acellInfo)
95 struct afsconf_dir *adir;
97 struct afsconf_cell *acellInfo;
101 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
106 afsconf_SetExtendedCellInfo(adir, apath, acellInfo, clones)
107 struct afsconf_dir *adir;
109 struct afsconf_cell *acellInfo;
112 register afs_int32 code;
116 register afs_int32 i;
119 /* write ThisCell file */
120 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
122 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
127 i = (int)strlen(acellInfo->name);
128 code = write(fd, acellInfo->name, i);
131 return AFSCONF_FAILURE;
138 /* make sure we have both name and address for each host, looking up other
140 code = VerifyEntries(acellInfo);
146 /* write CellServDB */
147 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
148 tf = fopen(tbuffer, "w");
151 return AFSCONF_NOTFOUND;
153 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
154 for (i = 0; i < acellInfo->numServers; i++) {
155 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
157 continue; /* delete request */
158 code = ntohl(code); /* convert to host order */
159 if (clones && clones[i])
160 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
161 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
162 acellInfo->hostName[i]);
164 fprintf(tf, "%d.%d.%d.%d #%s\n", (code >> 24) & 0xff,
165 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
166 acellInfo->hostName[i]);
171 return AFSCONF_FAILURE;
175 /* Reset the timestamp in the cache, so that
176 * the CellServDB is read into the cache next time.
177 * Resolves the lost update problem due to an inconsistent cache
184 return AFSCONF_FAILURE;