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"
43 extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
44 extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
46 extern afs_uint32 cryptall;
47 extern afs_uint32 cm_anonvldb;
48 extern int cm_enableServerLocks;
49 extern int cm_followBackupPath;
50 extern int cm_deleteReadOnly;
52 extern afs_int32 cm_BPlusTrees;
54 extern afs_int32 cm_OfflineROIsValid;
55 extern afs_int32 cm_giveUpAllCBs;
56 extern const clientchar_t **smb_ExecutableExtensions;
60 cm_config_data_t cm_data;
62 fschar_t cm_rootVolumeName[VL_MAXNAMELEN];
63 DWORD cm_rootVolumeNameLen;
65 fschar_t cm_mountRoot[1024];
66 DWORD cm_mountRootLen;
68 clientchar_t cm_mountRootC[1024];
69 DWORD cm_mountRootCLen;
85 char cm_HostName[200];
87 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
89 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
90 clientchar_t cm_NetbiosNameC[MAX_NB_NAME_LENGTH] = _C("");
92 char cm_CachePath[MAX_PATH];
93 DWORD cm_ValidateCache = 1;
95 BOOL reportSessionStartups = FALSE;
97 cm_initparams_v1 cm_initParams;
99 clientchar_t *cm_sysName = 0;
100 unsigned int cm_sysNameCount = 0;
101 clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
103 DWORD TraceOption = 0;
106 * AFSD Initialization Log
108 * This is distinct from the regular debug logging facility.
109 * Log items go directly to a file, not to an array in memory, so that even
110 * if AFSD crashes, the log can be inspected.
116 int cm_dnsEnabled = 1;
120 static int afsi_log_useTimestamp = 1;
123 afsi_log(char *pattern, ...)
125 char s[256], t[100], d[100], u[512];
128 va_start(ap, pattern);
130 StringCbVPrintfA(s, sizeof(s), pattern, ap);
131 if ( afsi_log_useTimestamp ) {
132 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
133 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
134 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
135 if (afsi_file != INVALID_HANDLE_VALUE)
136 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
141 if (afsi_file != INVALID_HANDLE_VALUE)
142 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
150 char t[100], u[100], *p, *path;
156 DWORD maxLogSize = 100 * 1024;
158 afsi_file = INVALID_HANDLE_VALUE;
159 code = GetTempPath(sizeof(wd)-15, wd);
160 if ( code == 0 || code > (sizeof(wd)-15) )
161 return; /* unable to create a log */
163 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
164 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
165 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
166 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
168 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
169 0, KEY_QUERY_VALUE, &parmKey);
170 if (code == ERROR_SUCCESS) {
171 dummyLen = sizeof(maxLogSize);
172 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
173 (BYTE *) &maxLogSize, &dummyLen);
174 RegCloseKey (parmKey);
178 dwLow = GetFileSize( afsi_file, &dwHigh );
179 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
180 CloseHandle(afsi_file);
181 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
182 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
186 SetFilePointer(afsi_file, 0, NULL, FILE_END);
187 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
188 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
189 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
190 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
191 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
193 code = GetEnvironmentVariable("PATH", NULL, 0);
195 code = GetEnvironmentVariable("PATH", path, code);
196 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
197 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
198 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
201 /* Initialize C RTL Code Page conversion functions */
202 /* All of the path info obtained from the SMB client is in the OEM code page */
203 afsi_log("OEM Code Page = %d", GetOEMCP());
204 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
206 /* Two things to look into. First, should mbstowcs() be performing
207 * character set translations from OEM to Unicode in smb3.c;
208 * Second, do we need to set this translation in each function
209 * due to multi-threading.
211 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
212 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
217 * Standard AFSD trace
220 void afsd_ForceTrace(BOOL flush)
229 len = GetTempPath(sizeof(buf)-10, buf);
230 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
231 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
232 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
233 if (handle == INVALID_HANDLE_VALUE) {
235 osi_panic("Cannot create log file", __FILE__, __LINE__);
237 osi_LogPrint(afsd_logp, handle);
239 FlushFileBuffers(handle);
244 configureBackConnectionHostNames(void)
246 /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
247 * there is a restriction on the use of SMB authentication on loopback connections.
248 * There are two work arounds available:
250 * (1) We can disable the check for matching host names. This does not
252 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
253 * "DisableLoopbackCheck"=dword:00000001
255 * (2) We can add the AFS SMB/CIFS service name to an approved list. This
256 * does require a reboot:
257 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
258 * "BackConnectionHostNames"=multi-sz
260 * The algorithm will be:
261 * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
262 * (2a) If not, add it to the list. (This will not take effect until the next reboot.)
263 * (2b1) and check to see if DisableLoopbackCheck is set.
264 * (2b2) If not set, set the DisableLoopbackCheck value to 0x1
265 * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck
266 * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
267 * check for the UnsetDisableLoopbackCheck value.
268 * If set, set the DisableLoopbackCheck flag to 0x0
269 * and delete the UnsetDisableLoopbackCheck value
271 * Starting in Longhorn Beta 1, an entry in the BackConnectionHostNames value will
272 * force Windows to use the loopback authentication mechanism for the specified
279 DWORD dwSize, dwAllocSize;
281 PBYTE pHostNames = NULL, pName = NULL;
282 BOOL bNameFound = FALSE;
284 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
285 "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
288 &hkMSV10) == ERROR_SUCCESS )
290 if ((RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0,
291 &dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
292 (dwType == REG_MULTI_SZ))
294 dwAllocSize += 1 /* in case the source string is not nul terminated */
295 + strlen(cm_NetbiosName) + 2;
296 pHostNames = malloc(dwAllocSize);
297 dwSize = dwAllocSize;
298 if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType,
299 pHostNames, &dwSize) == ERROR_SUCCESS)
301 for (pName = pHostNames;
302 (pName - pHostNames < (int) dwSize) && *pName ;
303 pName += strlen(pName) + 1)
305 if ( !stricmp(pName, cm_NetbiosName) ) {
314 size_t size = strlen(cm_NetbiosName) + 2;
316 pHostNames = malloc(size);
319 StringCbCopyA(pName, size, cm_NetbiosName);
321 *pName = '\0'; /* add a second nul terminator */
323 dwType = REG_MULTI_SZ;
324 dwSize = pName - pHostNames + 1;
325 RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
327 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
328 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
331 &hkLsa) == ERROR_SUCCESS )
333 dwSize = sizeof(DWORD);
334 if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS ||
337 dwSize = sizeof(DWORD);
339 RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
341 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
342 AFSREG_CLT_OPENAFS_SUBKEY,
345 REG_OPTION_NON_VOLATILE,
349 NULL) == ERROR_SUCCESS) {
352 dwSize = sizeof(DWORD);
354 RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
355 RegCloseKey(hkClient);
361 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
362 AFSREG_CLT_OPENAFS_SUBKEY,
365 REG_OPTION_NON_VOLATILE,
369 NULL) == ERROR_SUCCESS) {
371 dwSize = sizeof(DWORD);
372 if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
374 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
375 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
378 &hkLsa) == ERROR_SUCCESS )
380 RegDeleteValue(hkLsa, "DisableLoopbackCheck");
384 RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
385 RegCloseKey(hkClient);
388 RegCloseKey(hkMSV10);
396 static void afsd_InitServerPreferences(void)
399 DWORD dwType, dwSize;
403 DWORD dwHostSize = 256;
405 struct sockaddr_in saddr;
408 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
409 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
411 KEY_READ|KEY_QUERY_VALUE,
412 &hkPrefs) == ERROR_SUCCESS) {
414 RegQueryInfoKey( hkPrefs,
417 NULL, /* lpReserved */
418 NULL, /* lpcSubKeys */
419 NULL, /* lpcMaxSubKeyLen */
420 NULL, /* lpcMaxClassLen */
421 &dwPrefs, /* lpcValues */
422 NULL, /* lpcMaxValueNameLen */
423 NULL, /* lpcMaxValueLen */
424 NULL, /* lpcbSecurityDescriptor */
425 NULL /* lpftLastWriteTime */
428 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
430 dwSize = sizeof(DWORD);
433 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
434 &dwType, (LPBYTE)&dwRank, &dwSize))
436 afsi_log("RegEnumValue(hkPrefs) failed");
440 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
442 if (isdigit(szHost[0]))
444 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
448 if ((pEntry = gethostbyname (szHost)) == NULL)
451 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
453 saddr.sin_family = AF_INET;
454 dwRank += (rand() & 0x000f);
456 tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
457 if ( tsp ) /* an existing server - ref count increased */
459 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
461 /* set preferences for an existing vlserver */
462 cm_ChangeRankCellVLServer(tsp);
463 cm_PutServer(tsp); /* decrease refcount */
465 else /* add a new server without a cell */
467 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
468 tsp->ipRank = (USHORT)dwRank;
472 RegCloseKey(hkPrefs);
475 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
476 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\File",
478 KEY_READ|KEY_QUERY_VALUE,
479 &hkPrefs) == ERROR_SUCCESS) {
481 RegQueryInfoKey( hkPrefs,
484 NULL, /* lpReserved */
485 NULL, /* lpcSubKeys */
486 NULL, /* lpcMaxSubKeyLen */
487 NULL, /* lpcMaxClassLen */
488 &dwPrefs, /* lpcValues */
489 NULL, /* lpcMaxValueNameLen */
490 NULL, /* lpcMaxValueLen */
491 NULL, /* lpcbSecurityDescriptor */
492 NULL /* lpftLastWriteTime */
495 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
497 dwSize = sizeof(DWORD);
500 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
501 &dwType, (LPBYTE)&dwRank, &dwSize))
503 afsi_log("RegEnumValue(hkPrefs) failed");
507 afsi_log("File Server Preference: %s = %d",szHost, dwRank);
509 if (isdigit(szHost[0]))
511 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
515 if ((pEntry = gethostbyname (szHost)) == NULL)
518 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
520 saddr.sin_family = AF_INET;
521 dwRank += (rand() & 0x000f);
523 tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
524 if ( tsp ) /* an existing server - ref count increased */
526 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
528 /* find volumes which might have RO copy
529 /* on server and change the ordering of
532 cm_ChangeRankVolume(tsp);
533 cm_PutServer(tsp); /* decrease refcount */
535 else /* add a new server without a cell */
537 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
538 tsp->ipRank = (USHORT)dwRank;
542 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;
563 DWORD rx_udpbufsize = -1;
564 DWORD lockOrderValidation;
569 long virtualCache = 0;
570 fschar_t rootCellName[256];
571 struct rx_service *serverp;
572 static struct rx_securityClass *nullServerSecurityClassp;
580 /*int freelanceEnabled;*/
583 int cm_noIPAddr; /* number of client network interfaces */
584 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
585 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
586 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
587 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
589 WSAStartup(0x0101, &WSAjunk);
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(lockOrderValidation);
630 code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
631 (BYTE *) &lockOrderValidation, &dummyLen);
632 if (code != ERROR_SUCCESS) {
634 lockOrderValidation = 1;
636 lockOrderValidation = 0;
639 osi_SetLockOrderValidation(lockOrderValidation);
640 afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
642 dummyLen = sizeof(maxcpus);
643 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
644 (BYTE *) &maxcpus, &dummyLen);
645 if (code == ERROR_SUCCESS) {
647 DWORD_PTR processAffinityMask, systemAffinityMask;
649 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
650 FALSE, GetCurrentProcessId());
651 if ( hProcess != NULL &&
652 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
655 DWORD_PTR mask, newAffinityMask;
662 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
663 if ( processAffinityMask & mask ) {
664 newAffinityMask |= mask;
670 SetProcessAffinityMask(hProcess, newAffinityMask);
671 CloseHandle(hProcess);
672 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
674 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
678 dummyLen = sizeof(TraceOption);
679 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
680 (BYTE *) &TraceOption, &dummyLen);
681 afsi_log("Trace Options = %lX", TraceOption);
683 dummyLen = sizeof(traceBufSize);
684 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
685 (BYTE *) &traceBufSize, &dummyLen);
686 if (code == ERROR_SUCCESS)
687 afsi_log("Trace Buffer size %d", traceBufSize);
689 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
690 afsi_log("Default trace buffer size %d", traceBufSize);
693 /* setup and enable debug log */
694 afsd_logp = osi_LogCreate("afsd", traceBufSize);
695 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
696 if ((TraceOption & 0x8)
701 osi_LogEnable(afsd_logp);
705 osi_Log0(afsd_logp, "Log init");
707 dummyLen = sizeof(cacheSize);
708 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
709 (BYTE *) &cacheSize, &dummyLen);
710 if (code == ERROR_SUCCESS)
711 afsi_log("Cache size %d", cacheSize);
713 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
714 afsi_log("Default cache size %d", cacheSize);
717 dummyLen = sizeof(logChunkSize);
718 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
719 (BYTE *) &logChunkSize, &dummyLen);
720 if (code == ERROR_SUCCESS) {
721 if (logChunkSize < 12 || logChunkSize > 30) {
722 afsi_log("Invalid chunk size %d, using default",
724 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
727 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
729 cm_logChunkSize = logChunkSize;
730 cm_chunkSize = 1 << logChunkSize;
731 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
733 dummyLen = sizeof(blockSize);
734 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
735 (BYTE *) &blockSize, &dummyLen);
736 if (code == ERROR_SUCCESS) {
738 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
740 afsi_log("Invalid block size %u specified, using default", blockSize);
741 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
744 * if the blockSize is less than 1024 we permit the blockSize to be
745 * specified in multiples of the default blocksize
747 if (blockSize <= 1024)
748 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
751 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
753 if (blockSize > cm_chunkSize) {
754 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
755 blockSize, cm_chunkSize);
756 blockSize = cm_chunkSize;
758 if (cm_chunkSize % blockSize != 0) {
759 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
760 blockSize, cm_chunkSize);
761 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
763 afsi_log("Block size %u", blockSize);
765 dummyLen = sizeof(numBkgD);
766 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
767 (BYTE *) &numBkgD, &dummyLen);
768 if (code == ERROR_SUCCESS) {
769 if (numBkgD > CM_MAX_DAEMONS)
770 numBkgD = CM_MAX_DAEMONS;
771 afsi_log("%d background daemons", numBkgD);
773 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
774 afsi_log("Defaulting to %d background daemons", numBkgD);
777 dummyLen = sizeof(numSvThreads);
778 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
779 (BYTE *) &numSvThreads, &dummyLen);
780 if (code == ERROR_SUCCESS)
781 afsi_log("%d server threads", numSvThreads);
783 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
784 afsi_log("Defaulting to %d server threads", numSvThreads);
787 dummyLen = sizeof(stats);
788 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
789 (BYTE *) &stats, &dummyLen);
790 if (code == ERROR_SUCCESS)
791 afsi_log("Status cache entries: %d", stats);
793 stats = CM_CONFIGDEFAULT_STATS;
794 afsi_log("Default status cache entries: %d", stats);
797 dummyLen = sizeof(volumes);
798 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
799 (BYTE *) &volumes, &dummyLen);
800 if (code == ERROR_SUCCESS)
801 afsi_log("Volumes cache entries: %d", volumes);
803 volumes = CM_CONFIGDEFAULT_STATS / 3;
804 afsi_log("Default volume cache entries: %d", volumes);
807 dummyLen = sizeof(cells);
808 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
809 (BYTE *) &cells, &dummyLen);
810 if (code == ERROR_SUCCESS)
811 afsi_log("Cell cache entries: %d", cells);
813 cells = CM_CONFIGDEFAULT_CELLS;
814 afsi_log("Default cell cache entries: %d", cells);
817 dummyLen = sizeof(ltt);
818 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
819 (BYTE *) <t, &dummyLen);
820 if (code != ERROR_SUCCESS)
822 smb_LogoffTokenTransfer = ltt;
823 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
826 dummyLen = sizeof(ltto);
827 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
828 NULL, NULL, (BYTE *) <to, &dummyLen);
829 if (code != ERROR_SUCCESS)
834 smb_LogoffTransferTimeout = ltto;
835 afsi_log("Logoff token transfer timeout %d seconds", ltto);
837 dummyLen = sizeof(cm_rootVolumeName);
838 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
839 (LPBYTE) cm_rootVolumeName, &dummyLen);
840 if (code == ERROR_SUCCESS)
841 afsi_log("Root volume %s", cm_rootVolumeName);
843 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
844 afsi_log("Default root volume name root.afs");
847 cm_mountRootCLen = sizeof(cm_mountRootC);
848 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
849 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
850 if (code == ERROR_SUCCESS) {
851 afsi_log("Mount root %S", cm_mountRootC);
852 cm_mountRootCLen = cm_ClientStrLen(cm_mountRootC);
854 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
855 cm_mountRootCLen = cm_ClientStrLen(cm_mountRootC);
859 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
860 cm_mountRootLen = cm_FsStrLen(cm_mountRoot);
862 dummyLen = sizeof(buf);
863 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
865 if (code == ERROR_SUCCESS && buf[0]) {
866 if (regType == REG_EXPAND_SZ) {
867 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
868 if (dummyLen > sizeof(cm_CachePath)) {
869 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
870 osi_panic("CachePath too long", __FILE__, __LINE__);
873 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
875 afsi_log("Cache path %s", cm_CachePath);
877 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
878 if (dummyLen > sizeof(cm_CachePath)) {
879 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
880 sizeof(cm_CachePath));
881 osi_panic("CachePath too long", __FILE__, __LINE__);
883 afsi_log("Default cache path %s", cm_CachePath);
886 dummyLen = sizeof(virtualCache);
887 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
888 (LPBYTE)&virtualCache, &dummyLen);
889 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
892 dummyLen = sizeof(cm_ValidateCache);
893 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
894 (LPBYTE)&cm_ValidateCache, &dummyLen);
895 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
896 cm_ValidateCache = 1;
897 switch (cm_ValidateCache) {
899 afsi_log("Cache Validation disabled");
902 afsi_log("Cache Validation on Startup");
905 afsi_log("Cache Validation on Startup and Shutdown");
910 dummyLen = sizeof(traceOnPanic);
911 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
912 (BYTE *) &traceOnPanic, &dummyLen);
913 if (code != ERROR_SUCCESS)
914 traceOnPanic = 1; /* log */
915 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
917 dummyLen = sizeof(reportSessionStartups);
918 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
919 (BYTE *) &reportSessionStartups, &dummyLen);
920 if (code == ERROR_SUCCESS)
921 afsi_log("Session startups %s be recorded in the Event Log",
922 reportSessionStartups ? "will" : "will not");
924 reportSessionStartups = 0;
928 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
929 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
930 cm_sysNameList[i][0] = '\0';
932 cm_sysName = cm_sysNameList[0];
936 clientchar_t * cbuf = (clientchar_t *) buf;
937 dummyLen = sizeof(buf);
938 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
939 if (code != ERROR_SUCCESS || !cbuf[0]) {
941 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
942 #elif defined(_AMD64_)
943 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
944 #else /* assume x86 32-bit */
945 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
948 afsi_log("Sys name %S", cbuf);
950 /* breakup buf into individual search string entries */
951 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
952 if (*p == '\0' || iswspace(*p)) {
953 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
954 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
960 } while (*p == '\0' || isspace(*p));
967 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
969 dummyLen = sizeof(cryptall);
970 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
971 (BYTE *) &cryptall, &dummyLen);
972 if (code == ERROR_SUCCESS) {
973 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
976 afsi_log("Default SecurityLevel is clear");
980 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
981 else if (cryptall == 2)
982 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
984 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
986 dummyLen = sizeof(cryptall);
987 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
988 (BYTE *) &cm_anonvldb, &dummyLen);
989 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
992 dummyLen = sizeof(cm_dnsEnabled);
993 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
994 (BYTE *) &cm_dnsEnabled, &dummyLen);
995 if (code == ERROR_SUCCESS) {
996 afsi_log("DNS %s be used to find AFS cell servers",
997 cm_dnsEnabled ? "will" : "will not");
1000 cm_dnsEnabled = 1; /* default on */
1001 afsi_log("Default to use DNS to find AFS cell servers");
1003 #else /* AFS_AFSDB_ENV */
1004 afsi_log("AFS not built with DNS support to find AFS cell servers");
1005 #endif /* AFS_AFSDB_ENV */
1007 #ifdef AFS_FREELANCE_CLIENT
1008 dummyLen = sizeof(cm_freelanceEnabled);
1009 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
1010 (BYTE *) &cm_freelanceEnabled, &dummyLen);
1011 if (code == ERROR_SUCCESS) {
1012 afsi_log("Freelance client feature %s activated",
1013 cm_freelanceEnabled ? "is" : "is not");
1016 cm_freelanceEnabled = 1; /* default on */
1018 #endif /* AFS_FREELANCE_CLIENT */
1020 dummyLen = sizeof(smb_UseUnicode);
1021 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
1022 (BYTE *) &smb_UseUnicode, &dummyLen);
1023 if (code != ERROR_SUCCESS) {
1024 smb_UseUnicode = 1; /* default on */
1026 afsi_log("SMB Server Unicode Support is %s",
1027 smb_UseUnicode ? "enabled" : "disabled");
1029 dummyLen = sizeof(smb_hideDotFiles);
1030 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
1031 (BYTE *) &smb_hideDotFiles, &dummyLen);
1032 if (code != ERROR_SUCCESS) {
1033 smb_hideDotFiles = 1; /* default on */
1035 afsi_log("Dot files/dirs will %sbe marked hidden",
1036 smb_hideDotFiles ? "" : "not ");
1038 dummyLen = sizeof(smb_maxMpxRequests);
1039 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1040 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1041 if (code != ERROR_SUCCESS) {
1042 smb_maxMpxRequests = 50;
1044 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1046 dummyLen = sizeof(smb_maxVCPerServer);
1047 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1048 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1049 if (code != ERROR_SUCCESS) {
1050 smb_maxVCPerServer = 100;
1052 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1054 dummyLen = sizeof(smb_authType);
1055 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1056 (BYTE *) &smb_authType, &dummyLen);
1058 if (code != ERROR_SUCCESS ||
1059 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1060 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1062 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1064 dummyLen = sizeof(rx_nojumbo);
1065 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1066 (BYTE *) &rx_nojumbo, &dummyLen);
1067 if (code != ERROR_SUCCESS) {
1071 afsi_log("RX Jumbograms are disabled");
1073 afsi_log("RX Jumbograms are enabled");
1075 dummyLen = sizeof(rx_extraPackets);
1076 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1077 (BYTE *) &rx_extraPackets, &dummyLen);
1078 if (code != ERROR_SUCCESS) {
1079 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
1081 if (rx_extraPackets)
1082 afsi_log("RX extraPackets is %d", rx_extraPackets);
1084 dummyLen = sizeof(rx_udpbufsize);
1085 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
1086 (BYTE *) &rx_udpbufsize, &dummyLen);
1087 if (code != ERROR_SUCCESS) {
1088 rx_udpbufsize = 256*1024;
1090 if (rx_udpbufsize != -1)
1091 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
1093 dummyLen = sizeof(rx_mtu);
1094 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1095 (BYTE *) &rx_mtu, &dummyLen);
1096 if (code != ERROR_SUCCESS || !rx_mtu) {
1100 afsi_log("RX maximum MTU is %d", rx_mtu);
1102 dummyLen = sizeof(rx_enable_peer_stats);
1103 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1104 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1105 if (code != ERROR_SUCCESS) {
1106 rx_enable_peer_stats = 1;
1108 if (rx_enable_peer_stats)
1109 afsi_log("RX Peer Statistics gathering is enabled");
1111 afsi_log("RX Peer Statistics gathering is disabled");
1113 dummyLen = sizeof(rx_enable_process_stats);
1114 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1115 (BYTE *) &rx_enable_process_stats, &dummyLen);
1116 if (code != ERROR_SUCCESS) {
1117 rx_enable_process_stats = 1;
1119 if (rx_enable_process_stats)
1120 afsi_log("RX Process Statistics gathering is enabled");
1122 afsi_log("RX Process Statistics gathering is disabled");
1124 dummyLen = sizeof(dwValue);
1126 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1127 (BYTE *) &dwValue, &dummyLen);
1128 if (code != ERROR_SUCCESS || dwValue != 0) {
1129 rx_EnableHotThread();
1130 afsi_log("RX Hot Thread is enabled");
1133 afsi_log("RX Hot Thread is disabled");
1135 dummyLen = sizeof(DWORD);
1136 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1137 (BYTE *) &dwValue, &dummyLen);
1138 if (code == ERROR_SUCCESS) {
1139 cm_callbackport = (unsigned short) dwValue;
1141 afsi_log("CM CallBackPort is %u", cm_callbackport);
1143 dummyLen = sizeof(DWORD);
1144 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1145 (BYTE *) &dwValue, &dummyLen);
1146 if (code == ERROR_SUCCESS) {
1147 cm_enableServerLocks = (unsigned short) dwValue;
1149 switch (cm_enableServerLocks) {
1151 afsi_log("EnableServerLocks: never");
1154 afsi_log("EnableServerLocks: always");
1158 afsi_log("EnableServerLocks: server requested");
1162 dummyLen = sizeof(DWORD);
1163 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1164 (BYTE *) &dwValue, &dummyLen);
1165 if (code == ERROR_SUCCESS) {
1166 cm_deleteReadOnly = (unsigned short) dwValue;
1168 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1171 dummyLen = sizeof(DWORD);
1172 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1173 (BYTE *) &dwValue, &dummyLen);
1174 if (code == ERROR_SUCCESS) {
1175 cm_BPlusTrees = (unsigned short) dwValue;
1177 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1179 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1181 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1184 afsi_log("CM BPlusTrees is not supported");
1187 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1188 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1189 (regType == REG_MULTI_SZ))
1192 dummyLen += 3; /* in case the source string is not nul terminated */
1193 pSz = malloc(dummyLen);
1194 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1195 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1196 (regType == REG_MULTI_SZ))
1201 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1203 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1205 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1206 smb_ExecutableExtensions[cnt] = p;
1207 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1209 smb_ExecutableExtensions[cnt] = NULL;
1212 if (!smb_ExecutableExtensions)
1215 if (!smb_ExecutableExtensions)
1216 afsi_log("No PrefetchExecutableExtensions");
1218 dummyLen = sizeof(DWORD);
1219 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1220 (BYTE *) &dwValue, &dummyLen);
1221 if (code == ERROR_SUCCESS) {
1222 cm_OfflineROIsValid = (unsigned short) dwValue;
1224 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1226 dummyLen = sizeof(DWORD);
1227 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1228 (BYTE *) &dwValue, &dummyLen);
1229 if (code == ERROR_SUCCESS) {
1230 cm_giveUpAllCBs = (unsigned short) dwValue;
1232 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1234 dummyLen = sizeof(DWORD);
1235 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1236 (BYTE *) &dwValue, &dummyLen);
1237 if (code == ERROR_SUCCESS) {
1238 cm_followBackupPath = (unsigned short) dwValue;
1240 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1242 RegCloseKey (parmKey);
1244 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1246 /* get network related info */
1247 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1248 code = syscfg_GetIFInfo(&cm_noIPAddr,
1249 cm_IPAddr, cm_SubnetMask,
1250 cm_NetMtu, cm_NetFlags);
1252 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1253 afsi_log("syscfg_GetIFInfo error code %d", code);
1255 afsi_log("First Network address %x SubnetMask %x",
1256 cm_IPAddr[0], cm_SubnetMask[0]);
1259 * Save client configuration for GetCacheConfig requests
1261 cm_initParams.nChunkFiles = 0;
1262 cm_initParams.nStatCaches = stats;
1263 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1264 cm_initParams.nVolumeCaches = volumes;
1265 cm_initParams.firstChunkSize = cm_chunkSize;
1266 cm_initParams.otherChunkSize = cm_chunkSize;
1267 cm_initParams.cacheSize = cacheSize;
1268 cm_initParams.setTime = 0;
1269 cm_initParams.memCache = 1;
1271 /* Ensure the AFS Netbios Name is registered to allow loopback access */
1272 configureBackConnectionHostNames();
1274 /* init user daemon, and other packages */
1287 cm_InitNormalization();
1289 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1290 afsi_log("cm_InitMappedMemory code %x", code);
1292 *reasonP = "error initializing cache file";
1296 #ifdef AFS_AFSDB_ENV
1297 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1298 if (cm_InitDNS(cm_dnsEnabled) == -1)
1299 cm_dnsEnabled = 0; /* init failed, so deactivate */
1300 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1304 /* Set RX parameters before initializing RX */
1307 afsi_log("rx_SetNoJumbo successful");
1310 if ( rx_mtu != -1 ) {
1311 extern void rx_SetMaxMTU(int);
1313 rx_SetMaxMTU(rx_mtu);
1314 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1317 if ( rx_udpbufsize != -1 ) {
1318 rx_SetUdpBufSize(rx_udpbufsize);
1319 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1322 /* initialize RX, and tell it to listen to the callbackport,
1323 * which is used for callback RPC messages.
1325 code = rx_Init(htons(cm_callbackport));
1327 afsi_log("rx_Init code %x - retrying with a random port number", code);
1330 afsi_log("rx_Init code %x", code);
1332 *reasonP = "afsd: failed to init rx client";
1336 /* create an unauthenticated service #1 for callbacks */
1337 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1338 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1339 RXAFSCB_ExecuteRequest);
1340 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1341 if (serverp == NULL) {
1342 *reasonP = "unknown error";
1346 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1347 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1348 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1349 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1350 if (serverp == NULL) {
1351 *reasonP = "unknown error";
1355 /* start server threads, *not* donating this one to the pool */
1357 afsi_log("rx_StartServer");
1359 if (rx_enable_peer_stats)
1360 rx_enablePeerRPCStats();
1362 if (rx_enable_process_stats)
1363 rx_enableProcessRPCStats();
1365 code = cm_GetRootCellName(rootCellName);
1366 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1367 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1368 if (code != 0 && !cm_freelanceEnabled)
1370 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1373 else if (cm_freelanceEnabled)
1374 cm_data.rootCellp = NULL;
1376 if (code == 0 && !cm_freelanceEnabled)
1378 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1379 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1380 if (cm_data.rootCellp == NULL)
1382 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1387 #ifdef AFS_FREELANCE_CLIENT
1388 if (cm_freelanceEnabled)
1392 /* Initialize the RPC server for session keys */
1395 afsd_InitServerPreferences();
1399 int afsd_ShutdownCM(void)
1401 cm_ReleaseSCache(cm_data.rootSCachep);
1408 int afsd_InitDaemons(char **reasonP)
1415 /* this should really be in an init daemon from here on down */
1417 if (!cm_freelanceEnabled) {
1420 osi_Log0(afsd_logp, "Loading Root Volume from cell");
1422 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
1423 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
1424 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
1425 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
1426 } while (code && --attempts);
1428 *reasonP = "can't find root volume in root cell";
1433 /* compute the root fid */
1434 if (!cm_freelanceEnabled) {
1435 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
1438 cm_FakeRootFid(&cm_data.rootFid);
1440 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
1441 afsi_log("cm_GetSCache code %x scache %x", code,
1442 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
1444 *reasonP = "unknown error";
1448 cm_InitDaemon(numBkgD);
1449 afsi_log("cm_InitDaemon complete");
1454 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1461 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1462 0, KEY_QUERY_VALUE, &parmKey);
1463 if (code == ERROR_SUCCESS) {
1464 dummyLen = sizeof(DWORD);
1465 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1466 (BYTE *) &dwValue, &dummyLen);
1467 if (code == ERROR_SUCCESS)
1468 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1469 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1471 dummyLen = sizeof(DWORD);
1472 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1473 (BYTE *) &dwValue, &dummyLen);
1474 if (code == ERROR_SUCCESS)
1475 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1476 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1478 dummyLen = sizeof(DWORD);
1479 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1480 (BYTE *) &dwValue, &dummyLen);
1481 if (code == ERROR_SUCCESS) {
1482 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1483 if (dwValue > cm_chunkSize)
1484 smb_AsyncStoreSize = cm_chunkSize;
1485 else if (dwValue < cm_data.buf_blockSize)
1486 smb_AsyncStoreSize = cm_data.buf_blockSize;
1488 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1490 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1491 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1493 RegCloseKey (parmKey);
1496 /* Do this last so that we don't handle requests before init is done.
1497 * Here we initialize the SMB listener.
1499 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1500 afsi_log("smb_Init complete");
1513 #pragma pack( push, before_imagehlp, 8 )
1514 #include <imagehlp.h>
1515 #pragma pack( pop, before_imagehlp )
1517 #define MAXNAMELEN 1024
1519 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1521 HANDLE hProcess = GetCurrentProcess();
1523 #if defined(_AMD64_)
1525 #elif defined(_X86_)
1529 char functionName[MAXNAMELEN];
1531 IMAGEHLP_MODULE Module;
1535 IMAGEHLP_SYMBOL *pSym;
1537 afsi_log_useTimestamp = 0;
1539 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1541 memset( &s, '\0', sizeof s );
1542 if (!SymInitialize(hProcess, NULL, 1) )
1544 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1546 SymCleanup( hProcess );
1552 symOptions = SymGetOptions();
1553 symOptions |= SYMOPT_LOAD_LINES;
1554 symOptions &= ~SYMOPT_UNDNAME;
1555 SymSetOptions( symOptions );
1558 * init STACKFRAME for first call
1559 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1560 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1561 * and good riddance.
1563 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1564 #error The STACKFRAME initialization in afsd_printStack() for this platform
1565 #error must be properly configured
1566 #elif defined(_AMD64_)
1567 s.AddrPC.Offset = c->Rip;
1568 s.AddrPC.Mode = AddrModeFlat;
1569 s.AddrFrame.Offset = c->Rbp;
1570 s.AddrFrame.Mode = AddrModeFlat;
1572 s.AddrPC.Offset = c->Eip;
1573 s.AddrPC.Mode = AddrModeFlat;
1574 s.AddrFrame.Offset = c->Ebp;
1575 s.AddrFrame.Mode = AddrModeFlat;
1578 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1579 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1580 pSym->MaxNameLength = MAXNAMELEN;
1582 memset( &Line, '\0', sizeof Line );
1583 Line.SizeOfStruct = sizeof Line;
1585 memset( &Module, '\0', sizeof Module );
1586 Module.SizeOfStruct = sizeof Module;
1590 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1592 for ( frameNum = 0; ; ++ frameNum )
1595 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1596 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1597 * ERROR_NOACCESS (998), you can assume that either you are done, or
1598 * that the stack is so hosed that the next deeper frame could not be
1601 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1602 NULL, SymFunctionTableAccess, SymGetModuleBase,
1606 /* display its contents */
1607 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1608 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1609 s.AddrPC.Offset, s.AddrReturn.Offset,
1610 s.AddrFrame.Offset, s.AddrStack.Offset );
1612 if ( s.AddrPC.Offset == 0 )
1614 afsi_log("(-nosymbols- PC == 0)" );
1618 /* show procedure info from a valid PC */
1619 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1621 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1623 afsi_log("SymGetSymFromAddr(): errno = %lu",
1629 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1631 afsi_log("%s", functionName );
1635 afsi_log(" %+ld bytes", (long) offset);
1639 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1641 if (GetLastError() != ERROR_INVALID_ADDRESS)
1643 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1649 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1650 Line.LineNumber, offset);
1654 /* no return address means no deeper stackframe */
1655 if (s.AddrReturn.Offset == 0)
1662 if (GetLastError() != 0)
1664 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1667 SymCleanup(hProcess);
1672 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1673 static DWORD afsd_crtDbgBreaks[256];
1676 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1677 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1678 MINIDUMP_TYPE DumpType,
1679 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1680 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1681 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1690 code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
1691 if ( code == 0 || code > sizeof(wd) )
1693 if (!GetWindowsDirectory(wd, sizeof(wd)))
1696 StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
1697 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1698 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1702 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1704 if (IsDebuggerPresent())
1709 // Generate exception to get proper context in dump
1712 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1714 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1720 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1721 HANDLE hFile = NULL;
1722 HMODULE hDbgHelp = NULL;
1724 hDbgHelp = LoadLibrary("Dbghelp.dll");
1725 if ( hDbgHelp == NULL )
1728 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1729 if ( pMiniDumpWriteDump == NULL ) {
1730 FreeLibrary(hDbgHelp);
1734 hFile = OpenDumpFile();
1741 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1743 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1744 0, KEY_QUERY_VALUE, &parmKey);
1745 if (code == ERROR_SUCCESS) {
1746 dummyLen = sizeof(DWORD);
1747 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1748 (BYTE *) &dwValue, &dummyLen);
1749 if (code == ERROR_SUCCESS)
1750 dwMiniDumpType = dwValue;
1751 RegCloseKey (parmKey);
1754 eInfo.ThreadId = GetCurrentThreadId();
1755 eInfo.ExceptionPointers = ep;
1756 eInfo.ClientPointers = FALSE;
1758 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1759 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1764 FreeLibrary(hDbgHelp);
1768 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1772 BOOL allocRequestBrk = FALSE;
1774 HMODULE hLib = NULL;
1776 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1777 ep->ExceptionRecord->ExceptionCode,
1778 ep->ExceptionRecord->ExceptionAddress);
1781 if (afsd_crtDbgBreakCurrent &&
1782 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1784 allocRequestBrk = TRUE;
1785 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1789 /* save context if we want to print the stack information */
1790 context = *ep->ContextRecord;
1792 afsd_printStack(GetCurrentThread(), &context);
1794 GenerateMiniDump(ep);
1796 hLib = LoadLibrary("Faultrep.dll");
1798 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1800 pReportFault(ep, 0);
1804 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1806 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1809 if (allocRequestBrk)
1811 afsd_crtDbgBreakCurrent++;
1812 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1816 ep->ContextRecord->Eip++;
1818 #if defined(_AMD64_)
1819 ep->ContextRecord->Rip++;
1821 return EXCEPTION_CONTINUE_EXECUTION;
1825 return EXCEPTION_CONTINUE_SEARCH;
1829 void afsd_SetUnhandledExceptionFilter()
1832 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1837 void afsd_DbgBreakAllocInit()
1839 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1840 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1843 void afsd_DbgBreakAdd(DWORD requestNumber)
1846 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1848 if (afsd_crtDbgBreaks[i] == -1)
1853 afsd_crtDbgBreaks[i] = requestNumber;
1855 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);