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
17 #include <WINNT\afssw.h>
18 #include <WINNT\afsreg.h>
20 #include <afs/param.h>
22 #include <afs/cellconfig.h>
26 #include <afs/afsint.h>
29 static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp)
38 for(tp = lineBufferp; *tp; tp++) {
47 /* comment or line end */
48 if (tc == '#' || tc == '\r' || tc == '\n')
51 /* square bracket comment -- look for closing delim */
58 if (tc == ' ' || tc == '\t')
66 /* now we have a real character, put it in the appropriate bucket */
75 /* null terminate the strings */
79 return 0; /* and return success */
83 IsWindowsModule(const char * name)
88 /* Do not perform searches for probable Windows modules */
89 for (p = name, i=0; *p; p++) {
93 p = strrchr(name, '.');
95 /* as of 2009-09-04 these are not valid ICANN ccTLDs */
97 (!cm_stricmp_utf8N(p,".dll") ||
98 !cm_stricmp_utf8N(p,".exe") ||
99 !cm_stricmp_utf8N(p,".ini") ||
100 !cm_stricmp_utf8N(p,".db") ||
101 !cm_stricmp_utf8N(p,".drv")))
107 /* search for a cell, and either return an error code if we don't find it,
108 * or return 0 if we do, in which case we also fill in the addresses in
111 * new feature: we can handle abbreviations and are insensitive to case.
112 * If the caller wants the "real" cell name, it puts a non-null pointer in
113 * newCellNamep. Anomaly: if cellNamep is ambiguous, we may modify
114 * newCellNamep but return an error code.
116 * Linked Cells: the CellServDB format permits linked cells
117 * >cell [linked-cell] #Description
119 * newCellNamep and linkedNamep are required to be CELL_MAXNAMELEN in size.
121 long cm_SearchCellFile(char *cellNamep, char *newCellNamep,
122 cm_configProc_t *procp, void *rockp)
124 return cm_SearchCellFileEx(cellNamep, newCellNamep, NULL, procp, rockp);
127 long cm_SearchCellFileEx(char *cellNamep, char *newCellNamep,
129 cm_configProc_t *procp, void *rockp)
131 char wdir[MAX_PATH]="";
132 FILE *tfilep = NULL, *bestp, *tempp;
134 char lineBuffer[257];
137 struct sockaddr_in vlSockAddr;
141 int tracking = 1, partial = 0;
143 if ( IsWindowsModule(cellNamep) )
146 cm_GetCellServDB(wdir, sizeof(wdir));
148 tfilep = fopen(wdir, "r");
153 bestp = fopen(wdir, "r");
155 #ifdef CELLSERV_DEBUG
156 osi_Log2(afsd_logp,"cm_searchfile fopen handle[%p], wdir[%s]", bestp,
157 osi_LogSaveString(afsd_logp,wdir));
159 /* have we seen the cell line for the guy we're looking for? */
162 tp = fgets(lineBuffer, sizeof(lineBuffer), tfilep);
164 (void) fgets(lineBuffer, sizeof(lineBuffer), bestp);
170 * found partial match earlier;
183 return (foundCell? 0 : -3);
188 /* turn trailing cr or lf into null */
189 tp = strrchr(lineBuffer, '\r');
191 tp = strrchr(lineBuffer, '\n');
194 /* skip blank lines */
195 if (lineBuffer[0] == 0) continue;
199 * >[cell] [linked-cell] #[Description]
200 * where linked-cell and Description are optional
202 if (lineBuffer[0] == '>') {
206 return(foundCell ? 0 : -6);
210 * terminate the cellname at the first white space
211 * leaving 'tp' pointing to the next string if any
213 for (tp = &lineBuffer[1]; tp && !isspace(*tp); tp++);
216 for (tp++ ;tp && isspace(*tp); tp++);
219 for (; tp && !isspace(*tp); tp++);
225 /* now see if this is the right cell */
226 if (stricmp(lineBuffer+1, cellNamep) == 0) {
227 /* found the cell we're looking for */
229 strncpy(newCellNamep, lineBuffer+1,CELL_MAXNAMELEN);
230 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
231 strlwr(newCellNamep);
234 strncpy(linkedNamep, linkp ? linkp : "", CELL_MAXNAMELEN);
235 linkedNamep[CELL_MAXNAMELEN-1] = '\0';
240 #ifdef CELLSERV_DEBUG
241 osi_Log2(afsd_logp, "cm_searchfile is cell inRightCell[%p], linebuffer[%s]",
242 inRightCell, osi_LogSaveString(afsd_logp,lineBuffer));
245 else if (cm_stricmp_utf8(lineBuffer+1, cellNamep) == 0) {
247 if (partial) { /* ambiguous */
253 strncpy(newCellNamep, lineBuffer+1,CELL_MAXNAMELEN);
254 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
255 strlwr(newCellNamep);
258 strncpy(linkedNamep, linkp ? linkp : "", CELL_MAXNAMELEN);
259 linkedNamep[CELL_MAXNAMELEN-1] = '\0';
266 else inRightCell = 0;
269 valuep = strchr(lineBuffer, '#');
270 if (valuep == NULL) {
275 valuep++; /* skip the "#" */
277 valuep += strspn(valuep, " \t"); /* skip SP & TAB */
278 /* strip spaces and tabs in the end. They should not be there according to CellServDB format
279 * so do this just in case
281 while (valuep[strlen(valuep) - 1] == ' ' || valuep[strlen(valuep) - 1] == '\t')
282 valuep[strlen(valuep) - 1] = '\0';
288 isClone = (lineBuffer[0] == '[');
290 /* copy just the first word and ignore trailing white space */
291 for ( i=0; valuep[i] && !isspace(valuep[i]) && i<sizeof(hostname); i++)
292 hostname[i] = valuep[i];
295 /* add the server to the VLDB list */
297 thp = gethostbyname(hostname);
298 #ifdef CELLSERV_DEBUG
299 osi_Log3(afsd_logp,"cm_searchfile inRightCell thp[%p], valuep[%s], WSAGetLastError[%d]",
300 thp, osi_LogSaveString(afsd_logp,hostname), WSAGetLastError());
304 for (i=0 ; thp->h_addr_list[i]; i++) {
305 if (thp->h_addrtype != AF_INET)
307 memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr_list[i],
309 vlSockAddr.sin_family = AF_INET;
310 /* sin_port supplied by connection code */
312 (*procp)(rockp, &vlSockAddr, hostname, 0);
315 /* if we didn't find a valid address, force the use of the specified one */
321 unsigned int c1, c2, c3, c4;
323 /* Since there is no gethostbyname() data
324 * available we will read the IP address
325 * stored in the CellServDB file
328 code = sscanf(lineBuffer, "[%u.%u.%u.%u]",
331 code = sscanf(lineBuffer, " %u.%u.%u.%u",
333 if (code == 4 && c1<256 && c2<256 && c3<256 && c4<256) {
334 tp = (unsigned char *) &ip_addr;
339 memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
341 vlSockAddr.sin_family = AF_INET;
342 /* sin_port supplied by connection code */
344 (*procp)(rockp, &vlSockAddr, hostname, 0);
350 } /* while loop processing all lines */
352 /* if for some unknown reason cell is not found, return negative code (-11) ??? */
353 return (foundCell) ? 0 : -11;
357 * The CellServDB registry schema is as follows:
359 * HKLM\SOFTWARE\OpenAFS\Client\CellServDB\[cellname]\
360 * "LinkedCell" REG_SZ "[cellname]"
361 * "Description" REG_SZ "[comment]"
362 * "ForceDNS" DWORD {0,1}
364 * HKLM\SOFTWARE\OpenAFS\Client\CellServDB\[cellname]\[servername]\
365 * "HostName" REG_SZ "[hostname]"
366 * "IPv4Address" REG_SZ "[address]"
367 * "IPv6Address" REG_SZ "[address]" <future>
368 * "Comment" REG_SZ "[comment]"
369 * "Rank" DWORD "0..65535"
370 * "Clone" DWORD "{0,1}"
371 * "vlserver" DWORD "7003" <future>
372 * "ptserver" DWORD ... <future>
374 * ForceDNS is implied non-zero if there are no [servername]
375 * keys under the [cellname] key. Otherwise, ForceDNS is zero.
376 * If [servername] keys are specified and none of them evaluate
377 * to a valid server configuration, the return code is success.
378 * This prevents failover to the CellServDB file or DNS.
380 long cm_SearchCellRegistry(afs_uint32 client,
381 char *cellNamep, char *newCellNamep,
383 cm_configProc_t *procp, void *rockp)
385 HKEY hkCellServDB = 0, hkCellName = 0, hkServerName = 0;
386 DWORD dwType, dwSize;
387 DWORD dwCells, dwServers, dwForceDNS;
388 DWORD dwIndex, dwRank;
389 unsigned short ipRank;
391 FILETIME ftLastWriteTime;
392 char szCellName[CELL_MAXNAMELEN];
393 char szServerName[MAXHOSTCHARS];
394 char szHostName[MAXHOSTCHARS];
397 struct sockaddr_in vlSockAddr;
400 if ( IsWindowsModule(cellNamep) )
403 /* No Server CellServDB list (yet) */
405 return CM_ERROR_NOSUCHCELL;
407 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
408 AFSREG_CLT_OPENAFS_SUBKEY "\\CellServDB",
410 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
411 &hkCellServDB) != ERROR_SUCCESS)
412 return CM_ERROR_NOSUCHCELL;
414 if (RegOpenKeyEx( hkCellServDB,
417 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
418 &hkCellName) != ERROR_SUCCESS) {
421 /* We did not find an exact match. Much search for partial matches. */
423 code = RegQueryInfoKey( hkCellServDB,
426 NULL, /* lpReserved */
427 &dwCells, /* lpcSubKeys */
428 NULL, /* lpcMaxSubKeyLen */
429 NULL, /* lpcMaxClassLen */
430 NULL, /* lpcValues */
431 NULL, /* lpcMaxValueNameLen */
432 NULL, /* lpcMaxValueLen */
433 NULL, /* lpcbSecurityDescriptor */
434 &ftLastWriteTime /* lpftLastWriteTime */
436 if (code != ERROR_SUCCESS)
440 * We search the entire list to ensure that there is only
441 * one prefix match. If there is more than one, we return none.
443 for ( dwIndex = 0; dwIndex < dwCells; dwIndex++ ) {
444 dwSize = CELL_MAXNAMELEN;
445 code = RegEnumKeyEx( hkCellServDB, dwIndex, szCellName, &dwSize, NULL,
446 NULL, NULL, &ftLastWriteTime);
447 if (code != ERROR_SUCCESS)
449 szCellName[CELL_MAXNAMELEN-1] = '\0';
452 /* if not a prefix match, try the next key */
453 if (strncmp(cellNamep, szCellName, strlen(cellNamep)))
456 /* If we have a prefix match and we already found another
457 * match, return neither */
460 RegCloseKey( hkCellName);
464 if (RegOpenKeyEx( hkCellServDB,
467 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
468 &hkCellName) != ERROR_SUCCESS)
472 strncpy(newCellNamep, szCellName, CELL_MAXNAMELEN);
473 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
479 RegCloseKey(hkCellServDB);
480 return CM_ERROR_NOSUCHCELL;
482 } else if (newCellNamep) {
483 strncpy(newCellNamep, cellNamep, CELL_MAXNAMELEN);
484 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
485 strlwr(newCellNamep);
489 dwSize = CELL_MAXNAMELEN;
490 code = RegQueryValueEx(hkCellName, "LinkedCell", NULL, &dwType,
491 (BYTE *) linkedNamep, &dwSize);
492 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
493 linkedNamep[CELL_MAXNAMELEN-1] = '\0';
496 linkedNamep[0] = '\0';
500 /* Check to see if DNS lookups are required */
501 dwSize = sizeof(DWORD);
502 code = RegQueryValueEx(hkCellName, "ForceDNS", NULL, &dwType,
503 (BYTE *) &dwForceDNS, &dwSize);
504 if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
512 * Using the defined server list. Enumerate and populate
513 * the server list for the cell.
515 code = RegQueryInfoKey( hkCellName,
518 NULL, /* lpReserved */
519 &dwServers, /* lpcSubKeys */
520 NULL, /* lpcMaxSubKeyLen */
521 NULL, /* lpcMaxClassLen */
522 NULL, /* lpcValues */
523 NULL, /* lpcMaxValueNameLen */
524 NULL, /* lpcMaxValueLen */
525 NULL, /* lpcbSecurityDescriptor */
526 &ftLastWriteTime /* lpftLastWriteTime */
528 if (code != ERROR_SUCCESS)
531 for ( dwIndex = 0; dwIndex < dwServers; dwIndex++ ) {
532 dwSize = MAXHOSTCHARS;
533 code = RegEnumKeyEx( hkCellName, dwIndex, szServerName, &dwSize, NULL,
534 NULL, NULL, &ftLastWriteTime);
535 if (code != ERROR_SUCCESS)
538 szServerName[MAXHOSTCHARS-1] = '\0';
539 if (RegOpenKeyEx( hkCellName,
542 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
543 &hkServerName) != ERROR_SUCCESS)
546 /* We have a handle to a valid server key. Now we need
547 * to add the server to the cell */
549 /* First, see if there is an alternate hostname specified */
550 dwSize = MAXHOSTCHARS;
551 code = RegQueryValueEx(hkServerName, "HostName", NULL, &dwType,
552 (BYTE *) szHostName, &dwSize);
553 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
554 szHostName[MAXHOSTCHARS-1] = '\0';
561 dwSize = sizeof(DWORD);
562 code = RegQueryValueEx(hkServerName, "Rank", NULL, &dwType,
563 (BYTE *) &dwRank, &dwSize);
564 if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
565 ipRank = (unsigned short)(dwRank <= 65535 ? dwRank : 65535);
570 dwSize = sizeof(szAddr);
571 code = RegQueryValueEx(hkServerName, "IPv4Address", NULL, &dwType,
572 (BYTE *) szAddr, &dwSize);
573 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
580 thp = gethostbyname(s);
582 memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr, sizeof(long));
583 vlSockAddr.sin_family = AF_INET;
584 /* sin_port supplied by connection code */
586 (*procp)(rockp, &vlSockAddr, s, ipRank);
587 } else if (szAddr[0]) {
589 unsigned int c1, c2, c3, c4;
591 /* Since there is no gethostbyname() data
592 * available we will read the IP address
593 * stored in the CellServDB file
595 code = sscanf(szAddr, " %u.%u.%u.%u",
597 if (code == 4 && c1<256 && c2<256 && c3<256 && c4<256) {
598 unsigned char * tp = (unsigned char *) &ip_addr;
603 memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
605 vlSockAddr.sin_family = AF_INET;
606 /* sin_port supplied by connection code */
608 (*procp)(rockp, &vlSockAddr, s, ipRank);
612 RegCloseKey( hkServerName);
616 RegCloseKey(hkCellName);
617 RegCloseKey(hkCellServDB);
619 return ((dwForceDNS || dwServers == 0) ? CM_ERROR_FORCE_DNS_LOOKUP : 0);
622 long cm_EnumerateCellRegistry(afs_uint32 client, cm_enumCellRegistryProc_t *procp, void *rockp)
624 HKEY hkCellServDB = 0;
625 DWORD dwType, dwSize;
629 FILETIME ftLastWriteTime;
630 char szCellName[CELL_MAXNAMELEN];
632 /* No server CellServDB in the registry. */
633 if (!client || procp == NULL)
636 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
637 AFSREG_CLT_OPENAFS_SUBKEY "\\CellServDB",
639 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
640 &hkCellServDB) != ERROR_SUCCESS)
643 code = RegQueryInfoKey( hkCellServDB,
646 NULL, /* lpReserved */
647 &dwCells, /* lpcSubKeys */
648 NULL, /* lpcMaxSubKeyLen */
649 NULL, /* lpcMaxClassLen */
650 NULL, /* lpcValues */
651 NULL, /* lpcMaxValueNameLen */
652 NULL, /* lpcMaxValueLen */
653 NULL, /* lpcbSecurityDescriptor */
654 &ftLastWriteTime /* lpftLastWriteTime */
656 if (code != ERROR_SUCCESS)
660 * Enumerate each Cell and
662 for ( dwIndex = 0; dwIndex < dwCells; dwIndex++ ) {
663 dwSize = CELL_MAXNAMELEN;
664 code = RegEnumKeyEx( hkCellServDB, dwIndex, szCellName, &dwSize, NULL,
665 NULL, NULL, &ftLastWriteTime);
666 if (code != ERROR_SUCCESS)
668 szCellName[CELL_MAXNAMELEN-1] = '\0';
671 (*procp)(rockp, szCellName);
674 RegCloseKey(hkCellServDB);
678 /* newCellNamep is required to be CELL_MAXNAMELEN in size */
679 long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
680 cm_configProc_t *procp, void *rockp)
684 int cellHostAddrs[AFSMAXCELLHOSTS];
685 char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
686 unsigned short ipRanks[AFSMAXCELLHOSTS];
689 struct sockaddr_in vlSockAddr;
690 #ifdef CELLSERV_DEBUG
691 osi_Log1(afsd_logp,"SearchCellDNS-Doing search for [%s]", osi_LogSaveString(afsd_logp,cellNamep));
694 * Do not perform a DNS lookup if the name is
695 * either a well-known Windows DLL or directory,
696 * or if the name does not contain a top-level
697 * domain, or if the file prefix is the afs pioctl
700 if ( IsWindowsModule(cellNamep) ||
701 cm_FsStrChr(cellNamep, '.') == NULL ||
702 strncasecmp(cellNamep, CM_IOCTL_FILENAME_NOSLASH, strlen(CM_IOCTL_FILENAME_NOSLASH)) == 0)
705 rc = getAFSServer(cellNamep, cellHostAddrs, cellHostNames, ipRanks, &numServers, ttl);
706 if (rc == 0 && numServers > 0) { /* found the cell */
707 for (i = 0; i < numServers; i++) {
708 memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i],
710 vlSockAddr.sin_family = AF_INET;
711 /* sin_port supplied by connection code */
713 (*procp)(rockp, &vlSockAddr, cellHostNames[i], ipRanks[i]);
716 strncpy(newCellNamep,cellNamep,CELL_MAXNAMELEN);
717 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
718 strlwr(newCellNamep);
720 return 0; /* found cell */
723 return -1; /* not found */
725 return -1; /* not found */
726 #endif /* AFS_AFSDB_ENV */
729 /* use cm_GetConfigDir() plus AFS_CELLSERVDB to
730 * generate the fully qualified name of the CellServDB
733 long cm_GetCellServDB(char *cellNamep, afs_uint32 len)
737 cm_GetConfigDir(cellNamep, len);
739 /* add trailing backslash, if required */
740 tlen = (int)strlen(cellNamep);
742 if (cellNamep[tlen-1] != '\\') {
743 strncat(cellNamep, "\\", len);
744 cellNamep[len-1] = '\0';
747 strncat(cellNamep, AFS_CELLSERVDB, len);
748 cellNamep[len-1] = '\0';
753 /* look up the root cell's name in the Registry
754 * Input buffer must be at least CELL_MAXNAMELEN
755 * in size. (Defined in cm_cell.h)
757 long cm_GetRootCellName(char *cellNamep)
759 DWORD code, dummyLen;
762 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
763 0, KEY_QUERY_VALUE, &parmKey);
764 if (code != ERROR_SUCCESS)
767 dummyLen = CELL_MAXNAMELEN;
768 code = RegQueryValueEx(parmKey, "Cell", NULL, NULL,
769 cellNamep, &dummyLen);
770 RegCloseKey (parmKey);
771 if (code != ERROR_SUCCESS || cellNamep[0] == 0)
777 cm_configFile_t *cm_CommonOpen(char *namep, char *rwp)
779 char wdir[MAX_PATH]="";
782 cm_GetConfigDir(wdir, sizeof(wdir));
784 strncat(wdir, namep, sizeof(wdir));
785 wdir[sizeof(wdir)-1] = '\0';
787 tfilep = fopen(wdir, rwp);
789 return ((cm_configFile_t *) tfilep);
792 long cm_WriteConfigString(char *labelp, char *valuep)
794 DWORD code, dummyDisp;
797 code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
798 0, "container", 0, KEY_SET_VALUE, NULL,
799 &parmKey, &dummyDisp);
800 if (code != ERROR_SUCCESS)
803 code = RegSetValueEx(parmKey, labelp, 0, REG_SZ,
804 valuep, (DWORD)strlen(valuep) + 1);
805 RegCloseKey (parmKey);
806 if (code != ERROR_SUCCESS)
812 long cm_WriteConfigInt(char *labelp, long value)
814 DWORD code, dummyDisp;
817 code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
818 0, "container", 0, KEY_SET_VALUE, NULL,
819 &parmKey, &dummyDisp);
820 if (code != ERROR_SUCCESS)
823 code = RegSetValueEx(parmKey, labelp, 0, REG_DWORD,
824 (LPBYTE)&value, sizeof(value));
825 RegCloseKey (parmKey);
826 if (code != ERROR_SUCCESS)
832 cm_configFile_t *cm_OpenCellFile(void)
834 cm_configFile_t *cfp;
836 cfp = cm_CommonOpen(AFS_CELLSERVDB ".new", "w");
840 long cm_AppendPrunedCellList(cm_configFile_t *ofp, char *cellNamep)
842 cm_configFile_t *tfilep; /* input file */
844 char lineBuffer[256];
849 tfilep = cm_CommonOpen(AFS_CELLSERVDB, "r");
855 /* have we seen the cell line for the guy we're looking for? */
858 tp = fgets(lineBuffer, sizeof(lineBuffer), (FILE *)tfilep);
860 if (feof((FILE *)tfilep)) {
862 fclose((FILE *)tfilep);
867 /* turn trailing cr or lf into null */
868 tp = strchr(lineBuffer, '\r');
870 tp = strchr(lineBuffer, '\n');
873 /* skip blank lines */
874 if (lineBuffer[0] == 0) {
875 fprintf((FILE *)ofp, "%s\n", lineBuffer);
879 if (lineBuffer[0] == '>') {
880 /* trim off at white space or '#' chars */
881 tp = strchr(lineBuffer, ' ');
883 tp = strchr(lineBuffer, '\t');
885 tp = strchr(lineBuffer, '#');
888 /* now see if this is the right cell */
889 if (strcmp(lineBuffer+1, cellNamep) == 0) {
890 /* found the cell we're looking for */
895 fprintf((FILE *)ofp, "%s\n", lineBuffer);
899 valuep = strchr(lineBuffer, '#');
900 if (valuep == NULL) return -2;
901 valuep++; /* skip the "#" */
903 fprintf((FILE *)ofp, "%s\n", lineBuffer);
906 } /* while loop processing all lines */
909 long cm_AppendNewCell(cm_configFile_t *filep, char *cellNamep)
911 fprintf((FILE *)filep, ">%s\n", cellNamep);
915 long cm_AppendNewCellLine(cm_configFile_t *filep, char *linep)
917 fprintf((FILE *)filep, "%s\n", linep);
921 long cm_CloseCellFile(cm_configFile_t *filep)
927 closeCode = fclose((FILE *)filep);
929 cm_GetConfigDir(wdir, sizeof(wdir));
932 if (closeCode != 0) {
933 /* something went wrong, preserve original database */
934 strncat(wdir, AFS_CELLSERVDB ".new", sizeof(wdir));
935 wdir[sizeof(wdir)-1] = '\0';
940 strncat(wdir, AFS_CELLSERVDB, sizeof(wdir));
941 wdir[sizeof(wdir)-1] = '\0';
942 strncat(sdir, AFS_CELLSERVDB ".new", sizeof(sdir));/* new file */
943 sdir[sizeof(sdir)-1] = '\0';
945 unlink(sdir); /* delete old file */
947 code = rename(sdir, wdir); /* do the rename */
955 void cm_GetConfigDir(char *dir, afs_uint32 len)
959 if (!afssw_GetClientCellServDBDir(&dirp)) {
960 strncpy(dir, dirp, len);