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
18 #include <WINNT\afssw.h>
19 #include <WINNT\afsreg.h>
21 #include <afs/param.h>
23 #include <afs/cellconfig.h>
26 #include <afs/afsint.h>
28 static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp)
37 for(tp = lineBufferp; *tp; tp++) {
46 /* comment or line end */
47 if (tc == '#' || tc == '\r' || tc == '\n')
50 /* square bracket comment -- look for closing delim */
57 if (tc == ' ' || tc == '\t')
65 /* now we have a real character, put it in the appropriate bucket */
74 /* null terminate the strings */
78 return 0; /* and return success */
82 IsWindowsModule(const char * name)
87 /* Do not perform searches for probable Windows modules */
88 for (p = name, i=0; *p; p++) {
92 p = strrchr(name, '.');
94 /* as of 2009-09-04 these are not valid ICANN ccTLDs */
96 (!cm_stricmp_utf8N(p,".dll") ||
97 !cm_stricmp_utf8N(p,".exe") ||
98 !cm_stricmp_utf8N(p,".ini") ||
99 !cm_stricmp_utf8N(p,".db") ||
100 !cm_stricmp_utf8N(p,".drv")))
106 /* search for a cell, and either return an error code if we don't find it,
107 * or return 0 if we do, in which case we also fill in the addresses in
110 * new feature: we can handle abbreviations and are insensitive to case.
111 * If the caller wants the "real" cell name, it puts a non-null pointer in
112 * newCellNamep. Anomaly: if cellNamep is ambiguous, we may modify
113 * newCellNamep but return an error code.
115 * Linked Cells: the CellServDB format permits linked cells
116 * >cell [linked-cell] #Description
118 * newCellNamep and linkedNamep are required to be CELL_MAXNAMELEN in size.
120 long cm_SearchCellFile(char *cellNamep, char *newCellNamep,
121 cm_configProc_t *procp, void *rockp)
123 return cm_SearchCellFileEx(cellNamep, newCellNamep, NULL, procp, rockp);
126 long cm_SearchCellFileEx(char *cellNamep, char *newCellNamep,
128 cm_configProc_t *procp, void *rockp)
130 char wdir[MAX_PATH]="";
131 FILE *tfilep = NULL, *bestp, *tempp;
133 char lineBuffer[257];
136 struct sockaddr_in vlSockAddr;
140 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 if (FAILED(StringCchCopy(newCellNamep, CELL_MAXNAMELEN, lineBuffer+1))) {
234 strlwr(newCellNamep);
237 if (FAILED(StringCchCopy(linkedNamep, CELL_MAXNAMELEN, linkp ? linkp : ""))) {
246 #ifdef CELLSERV_DEBUG
247 osi_Log2(afsd_logp, "cm_searchfile is cell inRightCell[%p], linebuffer[%s]",
248 inRightCell, osi_LogSaveString(afsd_logp,lineBuffer));
251 else if (cm_stricmp_utf8(lineBuffer+1, cellNamep) == 0) {
253 if (partial) { /* ambiguous */
259 if (FAILED(StringCchCopy(newCellNamep, CELL_MAXNAMELEN, lineBuffer+1))) {
264 strlwr(newCellNamep);
267 if (FAILED(StringCchCopy(linkedNamep, CELL_MAXNAMELEN, linkp ? linkp : ""))) {
278 else inRightCell = 0;
281 valuep = strchr(lineBuffer, '#');
282 if (valuep == NULL) {
287 valuep++; /* skip the "#" */
289 valuep += strspn(valuep, " \t"); /* skip SP & TAB */
291 * strip spaces and tabs in the end. They should not be there according to CellServDB format
292 * so do this just in case
294 if(FAILED(StringCchLength(valuep, sizeof(lineBuffer), &len))) {
300 while(isspace(valuep[len]))
301 valuep[len--] = '\0';
302 while(isspace(*valuep))
310 isClone = (lineBuffer[0] == '[');
312 /* copy just the first word and ignore trailing white space */
313 for ( i=0; valuep[i] && !isspace(valuep[i]) && i<sizeof(hostname); i++)
314 hostname[i] = valuep[i];
317 /* add the server to the VLDB list */
319 thp = gethostbyname(hostname);
320 #ifdef CELLSERV_DEBUG
321 osi_Log3(afsd_logp,"cm_searchfile inRightCell thp[%p], valuep[%s], WSAGetLastError[%d]",
322 thp, osi_LogSaveString(afsd_logp,hostname), WSAGetLastError());
326 for (i=0 ; thp->h_addr_list[i]; i++) {
327 if (thp->h_addrtype != AF_INET)
329 memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr_list[i],
331 vlSockAddr.sin_port = htons(7003);
332 vlSockAddr.sin_family = AF_INET;
333 /* sin_port supplied by connection code */
335 (*procp)(rockp, &vlSockAddr, hostname, 0);
338 /* if we didn't find a valid address, force the use of the specified one */
344 unsigned int c1, c2, c3, c4;
346 /* Since there is no gethostbyname() data
347 * available we will read the IP address
348 * stored in the CellServDB file
351 code = sscanf(lineBuffer, "[%u.%u.%u.%u]",
354 code = sscanf(lineBuffer, " %u.%u.%u.%u",
356 if (code == 4 && c1<256 && c2<256 && c3<256 && c4<256) {
357 tp = (unsigned char *) &ip_addr;
362 memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
364 vlSockAddr.sin_port = htons(7003);
365 vlSockAddr.sin_family = AF_INET;
366 /* sin_port supplied by connection code */
368 (*procp)(rockp, &vlSockAddr, hostname, 0);
374 } /* while loop processing all lines */
376 /* if for some unknown reason cell is not found, return negative code (-11) ??? */
377 return (foundCell) ? 0 : -11;
381 cm_EnumerateCellFile(afs_uint32 client, cm_enumCellProc_t *procp, void *rockp)
383 char wdir[MAX_PATH]="";
386 char lineBuffer[257];
391 cm_GetCellServDB(wdir, sizeof(wdir));
393 tfilep = fopen(wdir, "r");
398 #ifdef CELLSERV_DEBUG
399 osi_Log2(afsd_logp,"cm_enumfile fopen handle[%p], wdir[%s]", tfilep,
400 osi_LogSaveString(afsd_logp,wdir));
403 tp = fgets(lineBuffer, sizeof(lineBuffer), tfilep);
404 if (tp == NULL && feof(tfilep)) {
410 /* turn trailing cr or lf into null */
411 tp = strrchr(lineBuffer, '\r');
413 tp = strrchr(lineBuffer, '\n');
416 /* skip blank lines */
417 if (lineBuffer[0] == 0)
422 * >[cell] [linked-cell] #[Description]
423 * where linked-cell and Description are optional
424 * but we are only going to use the initial cell name
426 if (lineBuffer[0] == '>') {
428 * terminate the cellname at the first white space
429 * leaving 'tp' pointing to the next string if any
431 for (tp = &lineBuffer[1]; tp && !isspace(*tp); tp++);
435 /* Now process the cell */
436 (*procp)(rockp, &lineBuffer[1]);
438 } /* while loop processing all lines */
444 * The CellServDB registry schema is as follows:
446 * HKLM\SOFTWARE\OpenAFS\Client\CellServDB\[cellname]\
447 * "LinkedCell" REG_SZ "[cellname]"
448 * "Description" REG_SZ "[comment]"
449 * "ForceDNS" DWORD {0,1}
451 * HKLM\SOFTWARE\OpenAFS\Client\CellServDB\[cellname]\[servername]\
452 * "HostName" REG_SZ "[hostname]"
453 * "IPv4Address" REG_SZ "[address]"
454 * "IPv6Address" REG_SZ "[address]" <future>
455 * "Comment" REG_SZ "[comment]"
456 * "Rank" DWORD "0..65535"
457 * "Clone" DWORD "{0,1}"
458 * "vlserver" DWORD "7003" <future>
459 * "ptserver" DWORD "7002" <future>
461 * ForceDNS is implied non-zero if there are no [servername]
462 * keys under the [cellname] key. Otherwise, ForceDNS is zero.
463 * If [servername] keys are specified and none of them evaluate
464 * to a valid server configuration, the return code is success.
465 * This prevents failover to the CellServDB file or DNS.
467 long cm_SearchCellRegistry(afs_uint32 client,
468 char *cellNamep, char *newCellNamep,
470 cm_configProc_t *procp, void *rockp)
472 HKEY hkCellServDB = 0, hkCellName = 0, hkServerName = 0;
473 DWORD dwType, dwSize;
474 DWORD dwCells, dwServers, dwForceDNS;
475 DWORD dwIndex, dwRank, dwPort;
476 unsigned short ipRank;
477 unsigned short vlPort;
479 FILETIME ftLastWriteTime;
480 char szCellName[CELL_MAXNAMELEN];
481 char szServerName[MAXHOSTCHARS];
482 char szHostName[MAXHOSTCHARS];
485 struct sockaddr_in vlSockAddr;
489 if ( IsWindowsModule(cellNamep) )
492 /* No Server CellServDB list (yet) */
494 return CM_ERROR_NOSUCHCELL;
496 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
497 AFSREG_CLT_OPENAFS_SUBKEY "\\CellServDB",
499 KEY_READ|KEY_QUERY_VALUE,
500 &hkCellServDB) != ERROR_SUCCESS)
501 return CM_ERROR_NOSUCHCELL;
503 if (RegOpenKeyEx( hkCellServDB,
506 KEY_READ|KEY_QUERY_VALUE,
507 &hkCellName) != ERROR_SUCCESS) {
510 /* We did not find an exact match. Much search for partial matches. */
512 code = RegQueryInfoKey( hkCellServDB,
515 NULL, /* lpReserved */
516 &dwCells, /* lpcSubKeys */
517 NULL, /* lpcMaxSubKeyLen */
518 NULL, /* lpcMaxClassLen */
519 NULL, /* lpcValues */
520 NULL, /* lpcMaxValueNameLen */
521 NULL, /* lpcMaxValueLen */
522 NULL, /* lpcbSecurityDescriptor */
523 &ftLastWriteTime /* lpftLastWriteTime */
525 if (code != ERROR_SUCCESS)
529 * We search the entire list to ensure that there is only
530 * one prefix match. If there is more than one, we return none.
532 for ( dwIndex = 0; dwIndex < dwCells; dwIndex++ ) {
533 dwSize = CELL_MAXNAMELEN;
534 code = RegEnumKeyEx( hkCellServDB, dwIndex, szCellName, &dwSize, NULL,
535 NULL, NULL, &ftLastWriteTime);
536 if (code != ERROR_SUCCESS)
538 szCellName[CELL_MAXNAMELEN-1] = '\0';
541 /* if not a prefix match, try the next key */
542 if (FAILED(StringCchLength(cellNamep, CELL_MAXNAMELEN, &len)))
545 if (strncmp(cellNamep, szCellName, len))
548 /* If we have a prefix match and we already found another
549 * match, return neither */
552 RegCloseKey( hkCellName);
556 if (RegOpenKeyEx( hkCellServDB,
559 KEY_READ|KEY_QUERY_VALUE,
560 &hkCellName) != ERROR_SUCCESS)
564 if (FAILED(StringCchCopy(newCellNamep, CELL_MAXNAMELEN, cellNamep)))
571 RegCloseKey(hkCellServDB);
572 return CM_ERROR_NOSUCHCELL;
574 } else if (newCellNamep) {
575 strncpy(newCellNamep, cellNamep, CELL_MAXNAMELEN);
576 newCellNamep[CELL_MAXNAMELEN-1] = '\0';
577 strlwr(newCellNamep);
581 dwSize = CELL_MAXNAMELEN;
582 code = RegQueryValueEx(hkCellName, "LinkedCell", NULL, &dwType,
583 (BYTE *) linkedNamep, &dwSize);
584 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
585 linkedNamep[CELL_MAXNAMELEN-1] = '\0';
588 linkedNamep[0] = '\0';
592 /* Check to see if DNS lookups are required */
593 dwSize = sizeof(DWORD);
594 code = RegQueryValueEx(hkCellName, "ForceDNS", NULL, &dwType,
595 (BYTE *) &dwForceDNS, &dwSize);
596 if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
604 * Using the defined server list. Enumerate and populate
605 * the server list for the cell.
607 code = RegQueryInfoKey( hkCellName,
610 NULL, /* lpReserved */
611 &dwServers, /* lpcSubKeys */
612 NULL, /* lpcMaxSubKeyLen */
613 NULL, /* lpcMaxClassLen */
614 NULL, /* lpcValues */
615 NULL, /* lpcMaxValueNameLen */
616 NULL, /* lpcMaxValueLen */
617 NULL, /* lpcbSecurityDescriptor */
618 &ftLastWriteTime /* lpftLastWriteTime */
620 if (code != ERROR_SUCCESS)
623 for ( dwIndex = 0; dwIndex < dwServers; dwIndex++ ) {
624 dwSize = MAXHOSTCHARS;
625 code = RegEnumKeyEx( hkCellName, dwIndex, szServerName, &dwSize, NULL,
626 NULL, NULL, &ftLastWriteTime);
627 if (code != ERROR_SUCCESS)
630 szServerName[MAXHOSTCHARS-1] = '\0';
631 if (RegOpenKeyEx( hkCellName,
634 KEY_READ|KEY_QUERY_VALUE,
635 &hkServerName) != ERROR_SUCCESS)
638 /* We have a handle to a valid server key. Now we need
639 * to add the server to the cell */
641 /* First, see if there is an alternate hostname specified */
642 dwSize = MAXHOSTCHARS;
643 code = RegQueryValueEx(hkServerName, "HostName", NULL, &dwType,
644 (BYTE *) szHostName, &dwSize);
645 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
646 szHostName[MAXHOSTCHARS-1] = '\0';
653 dwSize = sizeof(DWORD);
654 code = RegQueryValueEx(hkServerName, "Rank", NULL, &dwType,
655 (BYTE *) &dwRank, &dwSize);
656 if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
657 ipRank = (unsigned short)(dwRank <= 65535 ? dwRank : 65535);
662 dwSize = sizeof(szAddr);
663 code = RegQueryValueEx(hkServerName, "IPv4Address", NULL, &dwType,
664 (BYTE *) szAddr, &dwSize);
665 if (code == ERROR_SUCCESS && dwType == REG_SZ) {
671 dwSize = sizeof(DWORD);
672 code = RegQueryValueEx(hkServerName, "vlserver", NULL, &dwType,
673 (BYTE *) &dwPort, &dwSize);
674 if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
675 vlPort = htons((unsigned short)dwPort);
677 vlPort = htons(7003);
681 thp = gethostbyname(s);
683 memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr, sizeof(long));
684 vlSockAddr.sin_port = htons(7003);
685 vlSockAddr.sin_family = AF_INET;
686 /* sin_port supplied by connection code */
688 (*procp)(rockp, &vlSockAddr, s, ipRank);
689 } else if (szAddr[0]) {
691 unsigned int c1, c2, c3, c4;
693 /* Since there is no gethostbyname() data
694 * available we will read the IP address
695 * stored in the CellServDB file
697 code = sscanf(szAddr, " %u.%u.%u.%u",
699 if (code == 4 && c1<256 && c2<256 && c3<256 && c4<256) {
700 unsigned char * tp = (unsigned char *) &ip_addr;
705 memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
707 vlSockAddr.sin_port = vlPort;
708 vlSockAddr.sin_family = AF_INET;
709 /* sin_port supplied by connection code */
711 (*procp)(rockp, &vlSockAddr, s, ipRank);
715 RegCloseKey( hkServerName);
719 RegCloseKey(hkCellName);
720 RegCloseKey(hkCellServDB);
722 return ((dwForceDNS || dwServers == 0) ? CM_ERROR_FORCE_DNS_LOOKUP : 0);
725 long cm_EnumerateCellRegistry(afs_uint32 client, cm_enumCellRegistryProc_t *procp, void *rockp)
727 HKEY hkCellServDB = 0;
732 FILETIME ftLastWriteTime;
733 char szCellName[CELL_MAXNAMELEN];
735 /* No server CellServDB in the registry. */
736 if (!client || procp == NULL)
739 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
740 AFSREG_CLT_OPENAFS_SUBKEY "\\CellServDB",
742 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
743 &hkCellServDB) != ERROR_SUCCESS)
746 code = RegQueryInfoKey( hkCellServDB,
749 NULL, /* lpReserved */
750 &dwCells, /* lpcSubKeys */
751 NULL, /* lpcMaxSubKeyLen */
752 NULL, /* lpcMaxClassLen */
753 NULL, /* lpcValues */
754 NULL, /* lpcMaxValueNameLen */
755 NULL, /* lpcMaxValueLen */
756 NULL, /* lpcbSecurityDescriptor */
757 &ftLastWriteTime /* lpftLastWriteTime */
759 if (code != ERROR_SUCCESS)
763 * Enumerate each Cell and
765 for ( dwIndex = 0; dwIndex < dwCells; dwIndex++ ) {
766 dwSize = CELL_MAXNAMELEN;
767 code = RegEnumKeyEx( hkCellServDB, dwIndex, szCellName, &dwSize, NULL,
768 NULL, NULL, &ftLastWriteTime);
769 if (code != ERROR_SUCCESS)
771 szCellName[CELL_MAXNAMELEN-1] = '\0';
774 (*procp)(rockp, szCellName);
777 RegCloseKey(hkCellServDB);
781 /* newCellNamep is required to be CELL_MAXNAMELEN in size */
782 long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
783 cm_configProc_t *procp, void *rockp)
786 int cellHostAddrs[AFSMAXCELLHOSTS];
787 char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
788 unsigned short ipRanks[AFSMAXCELLHOSTS];
789 unsigned short ports[AFSMAXCELLHOSTS]; /* network byte order */
792 struct sockaddr_in vlSockAddr;
794 #ifdef CELLSERV_DEBUG
795 osi_Log1(afsd_logp,"SearchCellDNS-Doing search for [%s]", osi_LogSaveString(afsd_logp,cellNamep));
798 * Do not perform a DNS lookup if the name is
799 * either a well-known Windows DLL or directory,
800 * or if the name does not contain a top-level
801 * domain, or if the file prefix is the afs pioctl
804 if ( IsWindowsModule(cellNamep) ||
805 cm_FsStrChr(cellNamep, '.') == NULL ||
806 strncasecmp(cellNamep, CM_IOCTL_FILENAME_NOSLASH, sizeof(CM_IOCTL_FILENAME_NOSLASH)-1) == 0)
809 rc = getAFSServer("afs3-vlserver", "udp", cellNamep, htons(7003),
810 cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, ttl);
811 if (rc == 0 && numServers > 0) { /* found the cell */
812 for (i = 0; i < numServers; i++) {
813 memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i],
815 vlSockAddr.sin_port = ports[i];
816 vlSockAddr.sin_family = AF_INET;
818 (*procp)(rockp, &vlSockAddr, cellHostNames[i], ipRanks[i]);
821 if(FAILED(StringCchCopy(newCellNamep, CELL_MAXNAMELEN, cellNamep)))
823 strlwr(newCellNamep);
825 return 0; /* found cell */
828 return -1; /* not found */
831 /* use cm_GetConfigDir() plus AFS_CELLSERVDB to
832 * generate the fully qualified name of the CellServDB
835 long cm_GetCellServDB(char *cellNamep, afs_uint32 len)
839 cm_GetConfigDir(cellNamep, len);
841 /* add trailing backslash, if required */
842 if (FAILED(StringCchLength(cellNamep, len, &tlen)))
846 if (cellNamep[tlen-1] != '\\') {
847 if (FAILED(StringCchCat(cellNamep, len, "\\")))
851 if (FAILED(StringCchCat(cellNamep, len, AFS_CELLSERVDB)))
857 /* look up the root cell's name in the Registry
858 * Input buffer must be at least CELL_MAXNAMELEN
859 * in size. (Defined in cm_cell.h)
861 long cm_GetRootCellName(char *cellNamep)
863 DWORD code, dummyLen;
866 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
867 0, KEY_QUERY_VALUE, &parmKey);
868 if (code != ERROR_SUCCESS)
871 dummyLen = CELL_MAXNAMELEN;
872 code = RegQueryValueEx(parmKey, "Cell", NULL, NULL,
873 cellNamep, &dummyLen);
874 RegCloseKey (parmKey);
875 if (code != ERROR_SUCCESS || cellNamep[0] == 0)
881 cm_configFile_t *cm_CommonOpen(char *namep, char *rwp)
883 char wdir[MAX_PATH]="";
886 cm_GetConfigDir(wdir, sizeof(wdir));
888 if (FAILED(StringCchCat(wdir, MAX_PATH, namep)))
891 tfilep = fopen(wdir, rwp);
893 return ((cm_configFile_t *) tfilep);
896 long cm_WriteConfigString(char *labelp, char *valuep)
898 DWORD code, dummyDisp;
902 code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
903 0, "container", 0, KEY_SET_VALUE, NULL,
904 &parmKey, &dummyDisp);
905 if (code != ERROR_SUCCESS)
908 if (FAILED(StringCchLength(valuep, CM_CONFIGDEFAULT_CELLS, &len)))
911 code = RegSetValueEx(parmKey, labelp, 0, REG_SZ, valuep, (DWORD)(len + 1));
912 RegCloseKey (parmKey);
913 if (code != ERROR_SUCCESS)
919 long cm_WriteConfigInt(char *labelp, long value)
921 DWORD code, dummyDisp;
924 code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
925 0, "container", 0, KEY_SET_VALUE, NULL,
926 &parmKey, &dummyDisp);
927 if (code != ERROR_SUCCESS)
930 code = RegSetValueEx(parmKey, labelp, 0, REG_DWORD,
931 (LPBYTE)&value, sizeof(value));
932 RegCloseKey (parmKey);
933 if (code != ERROR_SUCCESS)
939 cm_configFile_t *cm_OpenCellFile(void)
941 cm_configFile_t *cfp;
943 cfp = cm_CommonOpen(AFS_CELLSERVDB ".new", "w");
947 long cm_AppendPrunedCellList(cm_configFile_t *ofp, char *cellNamep)
949 cm_configFile_t *tfilep; /* input file */
951 char lineBuffer[256];
956 tfilep = cm_CommonOpen(AFS_CELLSERVDB, "r");
962 /* have we seen the cell line for the guy we're looking for? */
965 tp = fgets(lineBuffer, sizeof(lineBuffer), (FILE *)tfilep);
967 if (feof((FILE *)tfilep)) {
969 fclose((FILE *)tfilep);
974 /* turn trailing cr or lf into null */
975 tp = strchr(lineBuffer, '\r');
977 tp = strchr(lineBuffer, '\n');
980 /* skip blank lines */
981 if (lineBuffer[0] == 0) {
982 fprintf((FILE *)ofp, "%s\n", lineBuffer);
986 if (lineBuffer[0] == '>') {
987 /* trim off at white space or '#' chars */
988 tp = strchr(lineBuffer, ' ');
990 tp = strchr(lineBuffer, '\t');
992 tp = strchr(lineBuffer, '#');
995 /* now see if this is the right cell */
996 if (strcmp(lineBuffer+1, cellNamep) == 0) {
997 /* found the cell we're looking for */
1002 fprintf((FILE *)ofp, "%s\n", lineBuffer);
1006 valuep = strchr(lineBuffer, '#');
1007 if (valuep == NULL) return -2;
1008 valuep++; /* skip the "#" */
1010 fprintf((FILE *)ofp, "%s\n", lineBuffer);
1013 } /* while loop processing all lines */
1016 long cm_AppendNewCell(cm_configFile_t *filep, char *cellNamep)
1018 fprintf((FILE *)filep, ">%s\n", cellNamep);
1022 long cm_AppendNewCellLine(cm_configFile_t *filep, char *linep)
1024 fprintf((FILE *)filep, "%s\n", linep);
1028 long cm_CloseCellFile(cm_configFile_t *filep)
1030 char wdir[MAX_PATH];
1031 char sdir[MAX_PATH];
1033 long closeCode = fclose((FILE *)filep);
1035 cm_GetConfigDir(wdir, sizeof(wdir));
1036 if (FAILED(StringCchCopy(sdir, sizeof(sdir), wdir)))
1039 if (closeCode != 0) {
1040 /* something went wrong, preserve original database */
1041 if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB ".new")))
1047 if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB)))
1049 if (FAILED(StringCchCat(sdir, sizeof(sdir), AFS_CELLSERVDB ".new"))) /* new file */
1052 unlink(sdir); /* delete old file */
1054 code = rename(sdir, wdir); /* do the rename */
1062 void cm_GetConfigDir(char *dir, afs_uint32 len)
1066 if (!afssw_GetClientCellServDBDir(&dirp)) {
1067 if (FAILED(StringCchCopy(dir, len, dirp)))