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>
39 #include "cellconfig.h"
42 /* write ThisCell and CellServDB containing exactly one cell's info specified
43 by acellInfo parm. Useful only on the server (which describes only one cell).
47 VerifyEntries(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(struct afsconf_dir *adir, const char *apath,
89 struct afsconf_cell *acellInfo)
93 code = afsconf_SetExtendedCellInfo(adir, apath, acellInfo, NULL);
98 afsconf_SetExtendedCellInfo(struct afsconf_dir *adir,
100 struct afsconf_cell *acellInfo, char clones[])
102 register afs_int32 code;
106 register afs_int32 i;
109 /* write ThisCell file */
110 strcompose(tbuffer, 1024, apath, "/", AFSDIR_THISCELL_FILE, NULL);
112 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
117 i = (int)strlen(acellInfo->name);
118 code = write(fd, acellInfo->name, i);
121 return AFSCONF_FAILURE;
128 /* make sure we have both name and address for each host, looking up other
130 code = VerifyEntries(acellInfo);
136 /* write CellServDB */
137 strcompose(tbuffer, 1024, apath, "/", AFSDIR_CELLSERVDB_FILE, NULL);
138 tf = fopen(tbuffer, "w");
141 return AFSCONF_NOTFOUND;
143 fprintf(tf, ">%s #Cell name\n", acellInfo->name);
144 for (i = 0; i < acellInfo->numServers; i++) {
145 code = acellInfo->hostAddr[i].sin_addr.s_addr; /* net order */
147 continue; /* delete request */
148 code = ntohl(code); /* convert to host order */
149 if (clones && clones[i])
150 fprintf(tf, "[%d.%d.%d.%d] #%s\n", (code >> 24) & 0xff,
151 (code >> 16) & 0xff, (code >> 8) & 0xff, code & 0xff,
152 acellInfo->hostName[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]);
161 return AFSCONF_FAILURE;
165 /* Reset the timestamp in the cache, so that
166 * the CellServDB is read into the cache next time.
167 * Resolves the lost update problem due to an inconsistent cache
174 return AFSCONF_FAILURE;