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 <afs/param.h>
12 #include <afs/afs_args.h>
30 #include <rx\rx_null.h>
31 #include <WINNT/syscfg.h>
32 #include <WINNT/afsreg.h>
36 #include "lanahelper.h"
38 #include "cm_memmap.h"
40 extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
41 extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
43 extern afs_uint32 cryptall;
44 extern afs_uint32 cm_anonvldb;
45 extern int cm_enableServerLocks;
46 extern int cm_followBackupPath;
47 extern int cm_deleteReadOnly;
49 extern afs_int32 cm_BPlusTrees;
51 extern afs_int32 cm_OfflineROIsValid;
52 extern afs_int32 cm_giveUpAllCBs;
53 extern const char **smb_ExecutableExtensions;
57 cm_config_data_t cm_data;
59 char cm_rootVolumeName[VL_MAXNAMELEN];
60 DWORD cm_rootVolumeNameLen;
61 char cm_mountRoot[1024];
62 DWORD cm_mountRootLen;
77 char cm_HostName[200];
79 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
81 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
83 char cm_CachePath[MAX_PATH];
84 DWORD cm_CachePathLen;
85 DWORD cm_ValidateCache = 1;
87 BOOL reportSessionStartups = FALSE;
89 cm_initparams_v1 cm_initParams;
92 unsigned int cm_sysNameCount = 0;
93 char *cm_sysNameList[MAXNUMSYSNAMES];
95 DWORD TraceOption = 0;
98 * AFSD Initialization Log
100 * This is distinct from the regular debug logging facility.
101 * Log items go directly to a file, not to an array in memory, so that even
102 * if AFSD crashes, the log can be inspected.
108 int cm_dnsEnabled = 1;
112 static int afsi_log_useTimestamp = 1;
115 afsi_log(char *pattern, ...)
117 char s[256], t[100], d[100], u[512];
120 va_start(ap, pattern);
122 StringCbVPrintfA(s, sizeof(s), pattern, ap);
123 if ( afsi_log_useTimestamp ) {
124 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
125 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
126 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
127 if (afsi_file != INVALID_HANDLE_VALUE)
128 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
133 if (afsi_file != INVALID_HANDLE_VALUE)
134 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
138 extern initUpperCaseTable();
139 void afsd_initUpperCaseTable()
141 initUpperCaseTable();
148 char t[100], u[100], *p, *path;
154 DWORD maxLogSize = 100 * 1024;
156 afsi_file = INVALID_HANDLE_VALUE;
157 code = GetTempPath(sizeof(wd)-15, wd);
158 if ( code == 0 || code > (sizeof(wd)-15) )
159 return; /* unable to create a log */
161 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
162 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
163 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
164 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
166 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
167 0, KEY_QUERY_VALUE, &parmKey);
168 if (code == ERROR_SUCCESS) {
169 dummyLen = sizeof(maxLogSize);
170 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
171 (BYTE *) &maxLogSize, &dummyLen);
172 RegCloseKey (parmKey);
176 dwLow = GetFileSize( afsi_file, &dwHigh );
177 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
178 CloseHandle(afsi_file);
179 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
180 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
184 SetFilePointer(afsi_file, 0, NULL, FILE_END);
185 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
186 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
187 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
188 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
189 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
191 code = GetEnvironmentVariable("PATH", NULL, 0);
193 code = GetEnvironmentVariable("PATH", path, code);
194 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
195 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
196 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
199 /* Initialize C RTL Code Page conversion functions */
200 /* All of the path info obtained from the SMB client is in the OEM code page */
201 afsi_log("OEM Code Page = %d", GetOEMCP());
202 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
204 /* Two things to look into. First, should mbstowcs() be performing
205 * character set translations from OEM to Unicode in smb3.c;
206 * Second, do we need to set this translation in each function
207 * due to multi-threading.
209 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
210 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
215 * Standard AFSD trace
218 void afsd_ForceTrace(BOOL flush)
227 len = GetTempPath(sizeof(buf)-10, buf);
228 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
229 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
230 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
231 if (handle == INVALID_HANDLE_VALUE) {
233 osi_panic("Cannot create log file", __FILE__, __LINE__);
235 osi_LogPrint(afsd_logp, handle);
237 FlushFileBuffers(handle);
242 configureBackConnectionHostNames(void)
244 /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
245 * there is a restriction on the use of SMB authentication on loopback connections.
246 * There are two work arounds available:
248 * (1) We can disable the check for matching host names. This does not
250 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
251 * "DisableLoopbackCheck"=dword:00000001
253 * (2) We can add the AFS SMB/CIFS service name to an approved list. This
254 * does require a reboot:
255 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
256 * "BackConnectionHostNames"=multi-sz
258 * The algorithm will be:
259 * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
260 * (2a) If not, add it to the list. (This will not take effect until the next reboot.)
261 * (2b1) and check to see if DisableLoopbackCheck is set.
262 * (2b2) If not set, set the DisableLoopbackCheck value to 0x1
263 * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck
264 * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
265 * check for the UnsetDisableLoopbackCheck value.
266 * If set, set the DisableLoopbackCheck flag to 0x0
267 * and delete the UnsetDisableLoopbackCheck value
269 * Starting in Longhorn Beta 1, an entry in the BackConnectionHostNames value will
270 * force Windows to use the loopback authentication mechanism for the specified
277 DWORD dwSize, dwAllocSize;
279 PBYTE pHostNames = NULL, pName = NULL;
280 BOOL bNameFound = FALSE;
282 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
283 "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
286 &hkMSV10) == ERROR_SUCCESS )
288 if ((RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0,
289 &dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
290 (dwType == REG_MULTI_SZ))
292 dwAllocSize += 1 /* in case the source string is not nul terminated */
293 + strlen(cm_NetbiosName) + 2;
294 pHostNames = malloc(dwAllocSize);
295 dwSize = dwAllocSize;
296 if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType,
297 pHostNames, &dwSize) == ERROR_SUCCESS)
299 for (pName = pHostNames;
300 (pName - pHostNames < dwSize) && *pName ;
301 pName += strlen(pName) + 1)
303 if ( !stricmp(pName, cm_NetbiosName) ) {
312 size_t size = strlen(cm_NetbiosName) + 2;
314 pHostNames = malloc(size);
317 StringCbCopyA(pName, size, cm_NetbiosName);
319 *pName = '\0'; /* add a second nul terminator */
321 dwType = REG_MULTI_SZ;
322 dwSize = pName - pHostNames + 1;
323 RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
325 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
326 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
329 &hkLsa) == ERROR_SUCCESS )
331 dwSize = sizeof(DWORD);
332 if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS ||
335 dwSize = sizeof(DWORD);
337 RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
339 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
340 AFSREG_CLT_OPENAFS_SUBKEY,
343 REG_OPTION_NON_VOLATILE,
347 NULL) == ERROR_SUCCESS) {
350 dwSize = sizeof(DWORD);
352 RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
353 RegCloseKey(hkClient);
359 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
360 AFSREG_CLT_OPENAFS_SUBKEY,
363 REG_OPTION_NON_VOLATILE,
367 NULL) == ERROR_SUCCESS) {
369 dwSize = sizeof(DWORD);
370 if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
372 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
373 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
376 &hkLsa) == ERROR_SUCCESS )
378 RegDeleteValue(hkLsa, "DisableLoopbackCheck");
382 RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
383 RegCloseKey(hkClient);
386 RegCloseKey(hkMSV10);
395 static void afsd_InitServerPreferences(void)
398 DWORD dwType, dwSize;
402 DWORD dwHostSize = 256;
404 struct sockaddr_in saddr;
407 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
408 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
410 KEY_READ|KEY_QUERY_VALUE,
411 &hkPrefs) == ERROR_SUCCESS) {
413 RegQueryInfoKey( hkPrefs,
416 NULL, /* lpReserved */
417 NULL, /* lpcSubKeys */
418 NULL, /* lpcMaxSubKeyLen */
419 NULL, /* lpcMaxClassLen */
420 &dwPrefs, /* lpcValues */
421 NULL, /* lpcMaxValueNameLen */
422 NULL, /* lpcMaxValueLen */
423 NULL, /* lpcbSecurityDescriptor */
424 NULL /* lpftLastWriteTime */
427 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
429 dwSize = sizeof(DWORD);
432 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
433 &dwType, (LPBYTE)&dwRank, &dwSize))
435 afsi_log("RegEnumValue(hkPrefs) failed");
439 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
441 if (isdigit(szHost[0]))
443 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
447 if ((pEntry = gethostbyname (szHost)) == NULL)
450 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
452 saddr.sin_family = AF_INET;
453 dwRank += (rand() & 0x000f);
455 tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
456 if ( tsp ) /* an existing server - ref count increased */
458 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
460 /* set preferences for an existing vlserver */
461 cm_ChangeRankCellVLServer(tsp);
462 cm_PutServer(tsp); /* decrease refcount */
464 else /* add a new server without a cell */
466 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
467 tsp->ipRank = (USHORT)dwRank;
471 RegCloseKey(hkPrefs);
474 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
475 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\File",
477 KEY_READ|KEY_QUERY_VALUE,
478 &hkPrefs) == ERROR_SUCCESS) {
480 RegQueryInfoKey( hkPrefs,
483 NULL, /* lpReserved */
484 NULL, /* lpcSubKeys */
485 NULL, /* lpcMaxSubKeyLen */
486 NULL, /* lpcMaxClassLen */
487 &dwPrefs, /* lpcValues */
488 NULL, /* lpcMaxValueNameLen */
489 NULL, /* lpcMaxValueLen */
490 NULL, /* lpcbSecurityDescriptor */
491 NULL /* lpftLastWriteTime */
494 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
496 dwSize = sizeof(DWORD);
499 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
500 &dwType, (LPBYTE)&dwRank, &dwSize))
502 afsi_log("RegEnumValue(hkPrefs) failed");
506 afsi_log("File Server Preference: %s = %d",szHost, dwRank);
508 if (isdigit(szHost[0]))
510 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
514 if ((pEntry = gethostbyname (szHost)) == NULL)
517 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
519 saddr.sin_family = AF_INET;
520 dwRank += (rand() & 0x000f);
522 tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
523 if ( tsp ) /* an existing server - ref count increased */
525 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
527 /* find volumes which might have RO copy
528 /* on server and change the ordering of
531 cm_ChangeRankVolume(tsp);
532 cm_PutServer(tsp); /* decrease refcount */
534 else /* add a new server without a cell */
536 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
537 tsp->ipRank = (USHORT)dwRank;
541 RegCloseKey(hkPrefs);
547 * AFSD Initialization
550 int afsd_InitCM(char **reasonP)
553 afs_uint64 cacheBlocks;
561 DWORD rx_enable_peer_stats;
562 DWORD rx_enable_process_stats;
567 long virtualCache = 0;
568 char rootCellName[256];
569 struct rx_service *serverp;
570 static struct rx_securityClass *nullServerSecurityClassp;
578 /*int freelanceEnabled;*/
582 int cm_noIPAddr; /* number of client network interfaces */
583 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
584 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
585 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
586 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
588 WSAStartup(0x0101, &WSAjunk);
590 afsd_initUpperCaseTable();
591 init_et_to_sys_error();
593 /* setup osidebug server at RPC slot 1000 */
594 osi_LongToUID(1000, &debugID);
595 code = osi_InitDebug(&debugID);
596 afsi_log("osi_InitDebug code %d", code);
598 // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
600 if (code == RPC_S_NO_PROTSEQS)
601 *reasonP = "No RPC Protocol Sequences registered. Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
603 *reasonP = "unknown error";
608 gethostname(cm_HostName, sizeof(cm_HostName));
609 afsi_log("gethostname %s", cm_HostName);
610 thp = gethostbyname(cm_HostName);
611 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
613 /* seed random number generator */
614 srand(ntohl(cm_HostAddr));
616 /* Look up configuration parameters in Registry */
617 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
618 0, KEY_QUERY_VALUE, &parmKey);
619 if (code != ERROR_SUCCESS) {
620 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
621 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
622 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
623 StringCbPrintfA(buf, sizeof(buf),
624 "Failure in configuration while opening Registry: %s",
626 osi_panic(buf, __FILE__, __LINE__);
629 dummyLen = sizeof(maxcpus);
630 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
631 (BYTE *) &maxcpus, &dummyLen);
632 if (code == ERROR_SUCCESS) {
634 DWORD_PTR processAffinityMask, systemAffinityMask;
636 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
637 FALSE, GetCurrentProcessId());
638 if ( hProcess != NULL &&
639 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
642 DWORD_PTR mask, newAffinityMask;
649 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
650 if ( processAffinityMask & mask ) {
651 newAffinityMask |= mask;
657 SetProcessAffinityMask(hProcess, newAffinityMask);
658 CloseHandle(hProcess);
659 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
661 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
665 dummyLen = sizeof(TraceOption);
666 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
667 (BYTE *) &TraceOption, &dummyLen);
668 afsi_log("Trace Options = %lX", TraceOption);
670 dummyLen = sizeof(traceBufSize);
671 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
672 (BYTE *) &traceBufSize, &dummyLen);
673 if (code == ERROR_SUCCESS)
674 afsi_log("Trace Buffer size %d", traceBufSize);
676 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
677 afsi_log("Default trace buffer size %d", traceBufSize);
680 /* setup and enable debug log */
681 afsd_logp = osi_LogCreate("afsd", traceBufSize);
682 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
683 if ((TraceOption & 0x8)
688 osi_LogEnable(afsd_logp);
692 osi_Log0(afsd_logp, "Log init");
694 dummyLen = sizeof(cacheSize);
695 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
696 (BYTE *) &cacheSize, &dummyLen);
697 if (code == ERROR_SUCCESS)
698 afsi_log("Cache size %d", cacheSize);
700 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
701 afsi_log("Default cache size %d", cacheSize);
704 dummyLen = sizeof(logChunkSize);
705 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
706 (BYTE *) &logChunkSize, &dummyLen);
707 if (code == ERROR_SUCCESS) {
708 if (logChunkSize < 12 || logChunkSize > 30) {
709 afsi_log("Invalid chunk size %d, using default",
711 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
714 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
716 cm_logChunkSize = logChunkSize;
717 cm_chunkSize = 1 << logChunkSize;
718 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
720 dummyLen = sizeof(blockSize);
721 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
722 (BYTE *) &blockSize, &dummyLen);
723 if (code == ERROR_SUCCESS) {
725 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
727 afsi_log("Invalid block size %u specified, using default", blockSize);
728 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
731 * if the blockSize is less than 1024 we permit the blockSize to be
732 * specified in multiples of the default blocksize
734 if (blockSize <= 1024)
735 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
738 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
740 if (blockSize > cm_chunkSize) {
741 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
742 blockSize, cm_chunkSize);
743 blockSize = cm_chunkSize;
745 if (cm_chunkSize % blockSize != 0) {
746 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
747 blockSize, cm_chunkSize);
748 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
750 afsi_log("Block size %u", blockSize);
752 dummyLen = sizeof(numBkgD);
753 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
754 (BYTE *) &numBkgD, &dummyLen);
755 if (code == ERROR_SUCCESS) {
756 if (numBkgD > CM_MAX_DAEMONS)
757 numBkgD = CM_MAX_DAEMONS;
758 afsi_log("%d background daemons", numBkgD);
760 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
761 afsi_log("Defaulting to %d background daemons", numBkgD);
764 dummyLen = sizeof(numSvThreads);
765 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
766 (BYTE *) &numSvThreads, &dummyLen);
767 if (code == ERROR_SUCCESS)
768 afsi_log("%d server threads", numSvThreads);
770 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
771 afsi_log("Defaulting to %d server threads", numSvThreads);
774 dummyLen = sizeof(stats);
775 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
776 (BYTE *) &stats, &dummyLen);
777 if (code == ERROR_SUCCESS)
778 afsi_log("Status cache entries: %d", stats);
780 stats = CM_CONFIGDEFAULT_STATS;
781 afsi_log("Default status cache entries: %d", stats);
784 dummyLen = sizeof(volumes);
785 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
786 (BYTE *) &volumes, &dummyLen);
787 if (code == ERROR_SUCCESS)
788 afsi_log("Volumes cache entries: %d", volumes);
790 volumes = CM_CONFIGDEFAULT_STATS / 3;
791 afsi_log("Default volume cache entries: %d", volumes);
794 dummyLen = sizeof(cells);
795 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
796 (BYTE *) &cells, &dummyLen);
797 if (code == ERROR_SUCCESS)
798 afsi_log("Cell cache entries: %d", cells);
800 cells = CM_CONFIGDEFAULT_CELLS;
801 afsi_log("Default cell cache entries: %d", cells);
804 dummyLen = sizeof(ltt);
805 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
806 (BYTE *) <t, &dummyLen);
807 if (code != ERROR_SUCCESS)
809 smb_LogoffTokenTransfer = ltt;
810 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
813 dummyLen = sizeof(ltto);
814 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
815 NULL, NULL, (BYTE *) <to, &dummyLen);
816 if (code != ERROR_SUCCESS)
821 smb_LogoffTransferTimeout = ltto;
822 afsi_log("Logoff token transfer timeout %d seconds", ltto);
824 dummyLen = sizeof(cm_rootVolumeName);
825 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
826 cm_rootVolumeName, &dummyLen);
827 if (code == ERROR_SUCCESS)
828 afsi_log("Root volume %s", cm_rootVolumeName);
830 StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
831 afsi_log("Default root volume name root.afs");
834 cm_mountRootLen = sizeof(cm_mountRoot);
835 code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
836 cm_mountRoot, &cm_mountRootLen);
837 if (code == ERROR_SUCCESS) {
838 afsi_log("Mount root %s", cm_mountRoot);
839 cm_mountRootLen = (DWORD)strlen(cm_mountRoot);
841 StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
846 dummyLen = sizeof(buf);
847 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
849 if (code == ERROR_SUCCESS && buf[0]) {
850 if (regType == REG_EXPAND_SZ) {
851 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
852 if (dummyLen > sizeof(cm_CachePath)) {
853 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
854 osi_panic("CachePath too long", __FILE__, __LINE__);
857 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
859 afsi_log("Cache path %s", cm_CachePath);
861 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
862 if (dummyLen > sizeof(cm_CachePath)) {
863 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
864 sizeof(cm_CachePath));
865 osi_panic("CachePath too long", __FILE__, __LINE__);
867 afsi_log("Default cache path %s", cm_CachePath);
870 dummyLen = sizeof(virtualCache);
871 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
872 (LPBYTE)&virtualCache, &dummyLen);
873 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
876 dummyLen = sizeof(cm_ValidateCache);
877 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
878 (LPBYTE)&cm_ValidateCache, &dummyLen);
879 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
880 cm_ValidateCache = 1;
881 switch (cm_ValidateCache) {
883 afsi_log("Cache Validation disabled");
886 afsi_log("Cache Validation on Startup");
889 afsi_log("Cache Validation on Startup and Shutdown");
894 dummyLen = sizeof(traceOnPanic);
895 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
896 (BYTE *) &traceOnPanic, &dummyLen);
897 if (code != ERROR_SUCCESS)
898 traceOnPanic = 1; /* log */
899 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
901 dummyLen = sizeof(reportSessionStartups);
902 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
903 (BYTE *) &reportSessionStartups, &dummyLen);
904 if (code == ERROR_SUCCESS)
905 afsi_log("Session startups %s be recorded in the Event Log",
906 reportSessionStartups ? "will" : "will not");
908 reportSessionStartups = 0;
912 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
913 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
914 cm_sysNameList[i][0] = '\0';
916 cm_sysName = cm_sysNameList[0];
918 dummyLen = sizeof(buf);
919 code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, buf, &dummyLen);
920 if (code != ERROR_SUCCESS || !buf[0]) {
922 StringCbCopyA(buf, sizeof(buf), "ia64_win64");
923 #elif defined(_AMD64_)
924 StringCbCopyA(buf, sizeof(buf), "amd64_win64 x86_win32 i386_w2k");
925 #else /* assume x86 32-bit */
926 StringCbCopyA(buf, sizeof(buf), "x86_win32 i386_w2k i386_nt40");
929 afsi_log("Sys name %s", buf);
931 /* breakup buf into individual search string entries */
932 for (p = q = buf; p < buf + dummyLen; p++)
934 if (*p == '\0' || isspace(*p)) {
935 memcpy(cm_sysNameList[cm_sysNameCount],q,p-q);
936 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
943 } while (*p == '\0' || isspace(*p));
949 StringCbCopyA(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
951 dummyLen = sizeof(cryptall);
952 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
953 (BYTE *) &cryptall, &dummyLen);
954 if (code == ERROR_SUCCESS) {
955 afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
958 afsi_log("Default SecurityLevel is clear");
962 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
964 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
966 dummyLen = sizeof(cryptall);
967 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
968 (BYTE *) &cm_anonvldb, &dummyLen);
969 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
972 dummyLen = sizeof(cm_dnsEnabled);
973 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
974 (BYTE *) &cm_dnsEnabled, &dummyLen);
975 if (code == ERROR_SUCCESS) {
976 afsi_log("DNS %s be used to find AFS cell servers",
977 cm_dnsEnabled ? "will" : "will not");
980 cm_dnsEnabled = 1; /* default on */
981 afsi_log("Default to use DNS to find AFS cell servers");
983 #else /* AFS_AFSDB_ENV */
984 afsi_log("AFS not built with DNS support to find AFS cell servers");
985 #endif /* AFS_AFSDB_ENV */
987 #ifdef AFS_FREELANCE_CLIENT
988 dummyLen = sizeof(cm_freelanceEnabled);
989 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
990 (BYTE *) &cm_freelanceEnabled, &dummyLen);
991 if (code == ERROR_SUCCESS) {
992 afsi_log("Freelance client feature %s activated",
993 cm_freelanceEnabled ? "is" : "is not");
996 cm_freelanceEnabled = 1; /* default on */
998 #endif /* AFS_FREELANCE_CLIENT */
1000 dummyLen = sizeof(smb_hideDotFiles);
1001 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
1002 (BYTE *) &smb_hideDotFiles, &dummyLen);
1003 if (code != ERROR_SUCCESS) {
1004 smb_hideDotFiles = 1; /* default on */
1006 afsi_log("Dot files/dirs will %sbe marked hidden",
1007 smb_hideDotFiles ? "" : "not ");
1009 dummyLen = sizeof(smb_maxMpxRequests);
1010 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1011 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1012 if (code != ERROR_SUCCESS) {
1013 smb_maxMpxRequests = 50;
1015 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1017 dummyLen = sizeof(smb_maxVCPerServer);
1018 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1019 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1020 if (code != ERROR_SUCCESS) {
1021 smb_maxVCPerServer = 100;
1023 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1025 dummyLen = sizeof(smb_authType);
1026 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1027 (BYTE *) &smb_authType, &dummyLen);
1029 if (code != ERROR_SUCCESS ||
1030 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1031 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1033 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1035 dummyLen = sizeof(rx_nojumbo);
1036 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1037 (BYTE *) &rx_nojumbo, &dummyLen);
1038 if (code != ERROR_SUCCESS) {
1042 afsi_log("RX Jumbograms are disabled");
1044 dummyLen = sizeof(rx_extraPackets);
1045 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1046 (BYTE *) &rx_extraPackets, &dummyLen);
1047 if (code != ERROR_SUCCESS) {
1048 rx_extraPackets = 120;
1050 if (rx_extraPackets)
1051 afsi_log("RX extraPackets is %d", rx_extraPackets);
1053 dummyLen = sizeof(rx_mtu);
1054 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1055 (BYTE *) &rx_mtu, &dummyLen);
1056 if (code != ERROR_SUCCESS || !rx_mtu) {
1060 afsi_log("RX maximum MTU is %d", rx_mtu);
1062 dummyLen = sizeof(rx_enable_peer_stats);
1063 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1064 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1065 if (code != ERROR_SUCCESS) {
1066 rx_enable_peer_stats = 1;
1068 if (rx_enable_peer_stats)
1069 afsi_log("RX Peer Statistics gathering is enabled");
1071 afsi_log("RX Peer Statistics gathering is disabled");
1073 dummyLen = sizeof(rx_enable_process_stats);
1074 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1075 (BYTE *) &rx_enable_process_stats, &dummyLen);
1076 if (code != ERROR_SUCCESS) {
1077 rx_enable_process_stats = 1;
1079 if (rx_enable_process_stats)
1080 afsi_log("RX Process Statistics gathering is enabled");
1082 afsi_log("RX Process Statistics gathering is disabled");
1084 dummyLen = sizeof(dwValue);
1086 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1087 (BYTE *) &dwValue, &dummyLen);
1088 if (code != ERROR_SUCCESS || dwValue != 0) {
1089 rx_EnableHotThread();
1090 afsi_log("RX Hot Thread is enabled");
1093 afsi_log("RX Hot Thread is disabled");
1095 dummyLen = sizeof(DWORD);
1096 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1097 (BYTE *) &dwValue, &dummyLen);
1098 if (code == ERROR_SUCCESS) {
1099 cm_callbackport = (unsigned short) dwValue;
1101 afsi_log("CM CallBackPort is %u", cm_callbackport);
1103 dummyLen = sizeof(DWORD);
1104 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1105 (BYTE *) &dwValue, &dummyLen);
1106 if (code == ERROR_SUCCESS) {
1107 cm_enableServerLocks = (unsigned short) dwValue;
1109 switch (cm_enableServerLocks) {
1111 afsi_log("EnableServerLocks: never");
1114 afsi_log("EnableServerLocks: always");
1118 afsi_log("EnableServerLocks: server requested");
1122 dummyLen = sizeof(DWORD);
1123 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1124 (BYTE *) &dwValue, &dummyLen);
1125 if (code == ERROR_SUCCESS) {
1126 cm_deleteReadOnly = (unsigned short) dwValue;
1128 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1131 dummyLen = sizeof(DWORD);
1132 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1133 (BYTE *) &dwValue, &dummyLen);
1134 if (code == ERROR_SUCCESS) {
1135 cm_BPlusTrees = (unsigned short) dwValue;
1137 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1139 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1141 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1144 afsi_log("CM BPlusTrees is not supported");
1147 if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0,
1148 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1149 (regType == REG_MULTI_SZ))
1152 dummyLen += 3; /* in case the source string is not nul terminated */
1153 pSz = malloc(dummyLen);
1154 if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, ®Type,
1155 pSz, &dummyLen) == ERROR_SUCCESS) &&
1156 (regType == REG_MULTI_SZ))
1161 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1);
1163 smb_ExecutableExtensions = malloc(sizeof(char *) * (cnt+1));
1165 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1)
1167 smb_ExecutableExtensions[cnt] = p;
1168 afsi_log("PrefetchExecutableExtension: \"%s\"", p);
1170 smb_ExecutableExtensions[cnt] = NULL;
1173 if (!smb_ExecutableExtensions)
1176 if (!smb_ExecutableExtensions)
1177 afsi_log("No PrefetchExecutableExtensions");
1179 dummyLen = sizeof(DWORD);
1180 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1181 (BYTE *) &dwValue, &dummyLen);
1182 if (code == ERROR_SUCCESS) {
1183 cm_OfflineROIsValid = (unsigned short) dwValue;
1185 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1187 dummyLen = sizeof(DWORD);
1188 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1189 (BYTE *) &dwValue, &dummyLen);
1190 if (code == ERROR_SUCCESS) {
1191 cm_giveUpAllCBs = (unsigned short) dwValue;
1193 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1195 dummyLen = sizeof(DWORD);
1196 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1197 (BYTE *) &dwValue, &dummyLen);
1198 if (code == ERROR_SUCCESS) {
1199 cm_followBackupPath = (unsigned short) dwValue;
1201 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1203 RegCloseKey (parmKey);
1205 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1207 /* get network related info */
1208 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1209 code = syscfg_GetIFInfo(&cm_noIPAddr,
1210 cm_IPAddr, cm_SubnetMask,
1211 cm_NetMtu, cm_NetFlags);
1213 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1214 afsi_log("syscfg_GetIFInfo error code %d", code);
1216 afsi_log("First Network address %x SubnetMask %x",
1217 cm_IPAddr[0], cm_SubnetMask[0]);
1220 * Save client configuration for GetCacheConfig requests
1222 cm_initParams.nChunkFiles = 0;
1223 cm_initParams.nStatCaches = stats;
1224 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1225 cm_initParams.nVolumeCaches = volumes;
1226 cm_initParams.firstChunkSize = cm_chunkSize;
1227 cm_initParams.otherChunkSize = cm_chunkSize;
1228 cm_initParams.cacheSize = cacheSize;
1229 cm_initParams.setTime = 0;
1230 cm_initParams.memCache = 1;
1232 /* Ensure the AFS Netbios Name is registered to allow loopback access */
1233 configureBackConnectionHostNames();
1235 /* init user daemon, and other packages */
1248 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1249 afsi_log("cm_InitMappedMemory code %x", code);
1251 *reasonP = "error initializing cache file";
1255 #ifdef AFS_AFSDB_ENV
1256 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1257 if (cm_InitDNS(cm_dnsEnabled) == -1)
1258 cm_dnsEnabled = 0; /* init failed, so deactivate */
1259 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1263 /* Set RX parameters before initializing RX */
1266 afsi_log("rx_SetNoJumbo successful");
1269 if ( rx_mtu != -1 ) {
1270 rx_SetMaxMTU(rx_mtu);
1271 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1274 /* initialize RX, and tell it to listen to the callbackport,
1275 * which is used for callback RPC messages.
1277 code = rx_Init(htons(cm_callbackport));
1279 afsi_log("rx_Init code %x - retrying with a random port number", code);
1282 afsi_log("rx_Init code %x", code);
1284 *reasonP = "afsd: failed to init rx client";
1288 /* create an unauthenticated service #1 for callbacks */
1289 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1290 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1291 RXAFSCB_ExecuteRequest);
1292 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1293 if (serverp == NULL) {
1294 *reasonP = "unknown error";
1298 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1299 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1300 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1301 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1302 if (serverp == NULL) {
1303 *reasonP = "unknown error";
1307 /* start server threads, *not* donating this one to the pool */
1309 afsi_log("rx_StartServer");
1311 if (rx_enable_peer_stats)
1312 rx_enablePeerRPCStats();
1314 if (rx_enable_process_stats)
1315 rx_enableProcessRPCStats();
1317 code = cm_GetRootCellName(rootCellName);
1318 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1319 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1320 if (code != 0 && !cm_freelanceEnabled)
1322 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1325 else if (cm_freelanceEnabled)
1326 cm_data.rootCellp = NULL;
1328 if (code == 0 && !cm_freelanceEnabled)
1330 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1331 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1332 if (cm_data.rootCellp == NULL)
1334 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1339 #ifdef AFS_FREELANCE_CLIENT
1340 if (cm_freelanceEnabled)
1344 /* Initialize the RPC server for session keys */
1348 afsd_InitServerPreferences();
1353 int afsd_ShutdownCM(void)
1355 cm_ReleaseSCache(cm_data.rootSCachep);
1360 int afsd_InitDaemons(char **reasonP)
1367 /* this should really be in an init daemon from here on down */
1369 if (!cm_freelanceEnabled) {
1372 osi_Log0(afsd_logp, "Loading Root Volume from cell");
1374 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
1375 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
1376 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
1377 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
1378 } while (code && --attempts);
1380 *reasonP = "can't find root volume in root cell";
1385 /* compute the root fid */
1386 if (!cm_freelanceEnabled) {
1387 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
1390 cm_FakeRootFid(&cm_data.rootFid);
1392 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
1393 afsi_log("cm_GetSCache code %x scache %x", code,
1394 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
1396 *reasonP = "unknown error";
1400 cm_InitDaemon(numBkgD);
1401 afsi_log("cm_InitDaemon complete");
1406 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1413 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1414 0, KEY_QUERY_VALUE, &parmKey);
1415 if (code == ERROR_SUCCESS) {
1416 dummyLen = sizeof(DWORD);
1417 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1418 (BYTE *) &dwValue, &dummyLen);
1419 if (code == ERROR_SUCCESS)
1420 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1421 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1423 dummyLen = sizeof(DWORD);
1424 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1425 (BYTE *) &dwValue, &dummyLen);
1426 if (code == ERROR_SUCCESS)
1427 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1428 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1430 dummyLen = sizeof(DWORD);
1431 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1432 (BYTE *) &dwValue, &dummyLen);
1433 if (code == ERROR_SUCCESS) {
1434 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1435 if (dwValue > cm_chunkSize)
1436 smb_AsyncStoreSize = cm_chunkSize;
1437 else if (dwValue < cm_data.buf_blockSize)
1438 smb_AsyncStoreSize = cm_data.buf_blockSize;
1440 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1442 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1443 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1445 RegCloseKey (parmKey);
1448 /* Do this last so that we don't handle requests before init is done.
1449 * Here we initialize the SMB listener.
1451 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1452 afsi_log("smb_Init complete");
1465 #pragma pack( push, before_imagehlp, 8 )
1466 #include <imagehlp.h>
1467 #pragma pack( pop, before_imagehlp )
1469 #define MAXNAMELEN 1024
1471 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1473 HANDLE hProcess = GetCurrentProcess();
1475 #if defined(_AMD64_)
1477 #elif defined(_X86_)
1481 char functionName[MAXNAMELEN];
1483 IMAGEHLP_MODULE Module;
1487 IMAGEHLP_SYMBOL *pSym;
1489 afsi_log_useTimestamp = 0;
1491 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1493 memset( &s, '\0', sizeof s );
1494 if (!SymInitialize(hProcess, NULL, 1) )
1496 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1498 SymCleanup( hProcess );
1504 symOptions = SymGetOptions();
1505 symOptions |= SYMOPT_LOAD_LINES;
1506 symOptions &= ~SYMOPT_UNDNAME;
1507 SymSetOptions( symOptions );
1510 * init STACKFRAME for first call
1511 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1512 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1513 * and good riddance.
1515 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1516 #error The STACKFRAME initialization in afsd_printStack() for this platform
1517 #error must be properly configured
1518 #elif defined(_AMD64_)
1519 s.AddrPC.Offset = c->Rip;
1520 s.AddrPC.Mode = AddrModeFlat;
1521 s.AddrFrame.Offset = c->Rbp;
1522 s.AddrFrame.Mode = AddrModeFlat;
1524 s.AddrPC.Offset = c->Eip;
1525 s.AddrPC.Mode = AddrModeFlat;
1526 s.AddrFrame.Offset = c->Ebp;
1527 s.AddrFrame.Mode = AddrModeFlat;
1530 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1531 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1532 pSym->MaxNameLength = MAXNAMELEN;
1534 memset( &Line, '\0', sizeof Line );
1535 Line.SizeOfStruct = sizeof Line;
1537 memset( &Module, '\0', sizeof Module );
1538 Module.SizeOfStruct = sizeof Module;
1542 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1544 for ( frameNum = 0; ; ++ frameNum )
1547 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1548 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1549 * ERROR_NOACCESS (998), you can assume that either you are done, or
1550 * that the stack is so hosed that the next deeper frame could not be
1553 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1554 NULL, SymFunctionTableAccess, SymGetModuleBase,
1558 /* display its contents */
1559 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1560 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1561 s.AddrPC.Offset, s.AddrReturn.Offset,
1562 s.AddrFrame.Offset, s.AddrStack.Offset );
1564 if ( s.AddrPC.Offset == 0 )
1566 afsi_log("(-nosymbols- PC == 0)" );
1570 /* show procedure info from a valid PC */
1571 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1573 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1575 afsi_log("SymGetSymFromAddr(): errno = %lu",
1581 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1583 afsi_log("%s", functionName );
1587 afsi_log(" %+ld bytes", (long) offset);
1591 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1593 if (GetLastError() != ERROR_INVALID_ADDRESS)
1595 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1601 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1602 Line.LineNumber, offset);
1606 /* no return address means no deeper stackframe */
1607 if (s.AddrReturn.Offset == 0)
1614 if (GetLastError() != 0)
1616 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1619 SymCleanup(hProcess);
1624 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1625 static DWORD afsd_crtDbgBreaks[256];
1628 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1629 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1630 MINIDUMP_TYPE DumpType,
1631 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1632 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1633 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1642 code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
1643 if ( code == 0 || code > sizeof(wd) )
1645 if (!GetWindowsDirectory(wd, sizeof(wd)))
1648 StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
1649 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1650 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1654 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1656 if (IsDebuggerPresent())
1661 // Generate exception to get proper context in dump
1664 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1666 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1672 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1673 HANDLE hFile = NULL;
1674 HMODULE hDbgHelp = NULL;
1676 hDbgHelp = LoadLibrary("Dbghelp.dll");
1677 if ( hDbgHelp == NULL )
1680 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1681 if ( pMiniDumpWriteDump == NULL ) {
1682 FreeLibrary(hDbgHelp);
1686 hFile = OpenDumpFile();
1693 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1695 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1696 0, KEY_QUERY_VALUE, &parmKey);
1697 if (code == ERROR_SUCCESS) {
1698 dummyLen = sizeof(DWORD);
1699 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1700 (BYTE *) &dwValue, &dummyLen);
1701 if (code == ERROR_SUCCESS)
1702 dwMiniDumpType = dwValue;
1703 RegCloseKey (parmKey);
1706 eInfo.ThreadId = GetCurrentThreadId();
1707 eInfo.ExceptionPointers = ep;
1708 eInfo.ClientPointers = FALSE;
1710 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1711 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1716 FreeLibrary(hDbgHelp);
1720 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1724 BOOL allocRequestBrk = FALSE;
1726 HMODULE hLib = NULL;
1728 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1729 ep->ExceptionRecord->ExceptionCode,
1730 ep->ExceptionRecord->ExceptionAddress);
1733 if (afsd_crtDbgBreakCurrent &&
1734 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1736 allocRequestBrk = TRUE;
1737 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1741 /* save context if we want to print the stack information */
1742 context = *ep->ContextRecord;
1744 afsd_printStack(GetCurrentThread(), &context);
1746 GenerateMiniDump(ep);
1748 hLib = LoadLibrary("Faultrep.dll");
1750 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1752 pReportFault(ep, 0);
1756 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1758 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1761 if (allocRequestBrk)
1763 afsd_crtDbgBreakCurrent++;
1764 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1768 ep->ContextRecord->Eip++;
1770 #if defined(_AMD64_)
1771 ep->ContextRecord->Rip++;
1773 return EXCEPTION_CONTINUE_EXECUTION;
1777 return EXCEPTION_CONTINUE_SEARCH;
1781 void afsd_SetUnhandledExceptionFilter()
1783 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1787 void afsd_DbgBreakAllocInit()
1789 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1790 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1793 void afsd_DbgBreakAdd(DWORD requestNumber)
1796 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1798 if (afsd_crtDbgBreaks[i] == -1)
1803 afsd_crtDbgBreaks[i] = requestNumber;
1805 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);