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 <rx\rxstat.h>
32 #include <WINNT/syscfg.h>
33 #include <WINNT/afsreg.h>
34 #include <afs\afscbint.h>
38 #include "lanahelper.h"
40 #include "cm_memmap.h"
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;
71 int cm_readonlyVolumeVersioning = 0;
86 char cm_HostName[200];
88 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
90 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "NOT.YET.SET";
91 clientchar_t cm_NetbiosNameC[MAX_NB_NAME_LENGTH] = _C("NOT.YET.SET");
93 char cm_CachePath[MAX_PATH];
94 DWORD cm_ValidateCache = 1;
96 BOOL reportSessionStartups = FALSE;
98 cm_initparams_v1 cm_initParams;
100 clientchar_t *cm_sysName = 0;
101 unsigned int cm_sysNameCount = 0;
102 clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
104 DWORD TraceOption = 0;
107 * AFSD Initialization Log
109 * This is distinct from the regular debug logging facility.
110 * Log items go directly to a file, not to an array in memory, so that even
111 * if AFSD crashes, the log can be inspected.
116 int cm_dnsEnabled = 1;
119 static int afsi_log_useTimestamp = 1;
122 afsi_log(char *pattern, ...)
124 char s[256], t[100], d[100], u[512];
127 va_start(ap, pattern);
129 StringCbVPrintfA(s, sizeof(s), pattern, ap);
130 if ( afsi_log_useTimestamp ) {
131 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
132 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
133 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
134 if (afsi_file != INVALID_HANDLE_VALUE)
135 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
140 if (afsi_file != INVALID_HANDLE_VALUE)
141 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
149 char t[100], u[100], *p, *path;
155 DWORD maxLogSize = 100 * 1024;
157 afsi_file = INVALID_HANDLE_VALUE;
158 code = GetTempPath(sizeof(wd)-15, wd);
159 if ( code == 0 || code > (sizeof(wd)-15) )
160 return; /* unable to create a log */
162 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
163 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
164 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
165 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
167 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
168 0, KEY_QUERY_VALUE, &parmKey);
169 if (code == ERROR_SUCCESS) {
170 dummyLen = sizeof(maxLogSize);
171 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
172 (BYTE *) &maxLogSize, &dummyLen);
173 RegCloseKey (parmKey);
177 dwLow = GetFileSize( afsi_file, &dwHigh );
178 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
179 CloseHandle(afsi_file);
180 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
181 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
185 SetFilePointer(afsi_file, 0, NULL, FILE_END);
186 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
187 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
188 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
189 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
190 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
192 code = GetEnvironmentVariable("PATH", NULL, 0);
194 code = GetEnvironmentVariable("PATH", path, code);
195 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
196 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
197 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
200 /* Initialize C RTL Code Page conversion functions */
201 /* All of the path info obtained from the SMB client is in the OEM code page */
202 afsi_log("OEM Code Page = %d", GetOEMCP());
203 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
205 /* Two things to look into. First, should mbstowcs() be performing
206 * character set translations from OEM to Unicode in smb3.c;
207 * Second, do we need to set this translation in each function
208 * due to multi-threading.
210 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
211 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
216 * Standard AFSD trace
219 void afsd_ForceTrace(BOOL flush)
228 len = GetTempPath(sizeof(buf)-10, buf);
229 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
230 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
231 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
232 if (handle == INVALID_HANDLE_VALUE) {
234 osi_panic("Cannot create log file", __FILE__, __LINE__);
236 osi_LogPrint(afsd_logp, handle);
238 FlushFileBuffers(handle);
242 static void afsd_InitServerPreferences(void)
245 DWORD dwType, dwSize;
249 DWORD dwHostSize = 256;
251 struct sockaddr_in saddr;
254 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
255 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
257 KEY_READ|KEY_QUERY_VALUE,
258 &hkPrefs) == ERROR_SUCCESS) {
260 RegQueryInfoKey( hkPrefs,
263 NULL, /* lpReserved */
264 NULL, /* lpcSubKeys */
265 NULL, /* lpcMaxSubKeyLen */
266 NULL, /* lpcMaxClassLen */
267 &dwPrefs, /* lpcValues */
268 NULL, /* lpcMaxValueNameLen */
269 NULL, /* lpcMaxValueLen */
270 NULL, /* lpcbSecurityDescriptor */
271 NULL /* lpftLastWriteTime */
274 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
276 dwSize = sizeof(DWORD);
279 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
280 &dwType, (LPBYTE)&dwRank, &dwSize))
282 afsi_log("RegEnumValue(hkPrefs) failed");
286 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
288 if (isdigit(szHost[0]))
290 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
294 if ((pEntry = gethostbyname (szHost)) == NULL)
297 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
299 saddr.sin_port = htons(7003);
300 saddr.sin_family = AF_INET;
301 dwRank += (rand() & 0x000f);
303 tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
304 if ( tsp ) /* an existing server - ref count increased */
306 lock_ObtainMutex(&tsp->mx);
307 tsp->ipRank = (USHORT)dwRank;
308 tsp->flags |= CM_SERVERFLAG_PREF_SET;
309 tsp->adminRank = tsp->ipRank;
310 lock_ReleaseMutex(&tsp->mx);
312 /* set preferences for an existing vlserver */
313 cm_ChangeRankCellVLServer(tsp);
314 cm_PutServer(tsp); /* decrease refcount */
316 else /* add a new server without a cell */
318 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
319 lock_ObtainMutex(&tsp->mx);
320 tsp->ipRank = (USHORT)dwRank;
321 tsp->flags |= CM_SERVERFLAG_PREF_SET;
322 tsp->adminRank = tsp->ipRank;
323 lock_ReleaseMutex(&tsp->mx);
327 RegCloseKey(hkPrefs);
330 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
331 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\File",
333 KEY_READ|KEY_QUERY_VALUE,
334 &hkPrefs) == ERROR_SUCCESS) {
336 RegQueryInfoKey( hkPrefs,
339 NULL, /* lpReserved */
340 NULL, /* lpcSubKeys */
341 NULL, /* lpcMaxSubKeyLen */
342 NULL, /* lpcMaxClassLen */
343 &dwPrefs, /* lpcValues */
344 NULL, /* lpcMaxValueNameLen */
345 NULL, /* lpcMaxValueLen */
346 NULL, /* lpcbSecurityDescriptor */
347 NULL /* lpftLastWriteTime */
350 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
352 dwSize = sizeof(DWORD);
355 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
356 &dwType, (LPBYTE)&dwRank, &dwSize))
358 afsi_log("RegEnumValue(hkPrefs) failed");
362 afsi_log("File Server Preference: %s = %d",szHost, dwRank);
364 if (isdigit(szHost[0]))
366 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
370 if ((pEntry = gethostbyname (szHost)) == NULL)
373 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
375 saddr.sin_port = htons(7000);
376 saddr.sin_family = AF_INET;
377 dwRank += (rand() & 0x000f);
379 tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
380 if ( tsp ) /* an existing server - ref count increased */
382 lock_ObtainMutex(&tsp->mx);
383 tsp->ipRank = (USHORT)dwRank;
384 tsp->flags |= CM_SERVERFLAG_PREF_SET;
385 tsp->adminRank = tsp->ipRank;
386 lock_ReleaseMutex(&tsp->mx);
388 /* find volumes which might have RO copy
389 /* on server and change the ordering of
392 cm_ChangeRankVolume(tsp);
393 cm_PutServer(tsp); /* decrease refcount */
395 else /* add a new server without a cell */
397 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
398 lock_ObtainMutex(&tsp->mx);
399 tsp->ipRank = (USHORT)dwRank;
400 tsp->flags |= CM_SERVERFLAG_PREF_SET;
401 tsp->adminRank = tsp->ipRank;
402 lock_ReleaseMutex(&tsp->mx);
406 RegCloseKey(hkPrefs);
412 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
417 static BOOL bChecked = FALSE;
418 static BOOL bIsWow64 = FALSE;
423 LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
425 h1 = GetModuleHandle("kernel32.dll");
427 (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process");
429 /* If we don't find the fnIsWow64Process function then we
430 * are not running in a broken Wow64
432 if (fnIsWow64Process)
433 fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
443 * AFSD Initialization
447 afsd_InitRoot(char **reasonP)
454 if (cm_freelanceEnabled) {
455 cm_FakeRootFid(&cm_data.rootFid);
459 osi_Log0(afsd_logp, "Loading Root Volume from cell");
461 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
462 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
463 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
464 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
465 } while (code && --attempts);
467 *reasonP = "can't find root volume in root cell";
471 /* compute the root fid */
472 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
475 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
476 afsi_log("cm_GetSCache code %x scache %x", code,
477 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
479 *reasonP = "unknown error";
487 afsd_InitCM(char **reasonP)
490 afs_uint64 cacheBlocks;
498 DWORD rx_enable_peer_stats;
499 DWORD rx_enable_process_stats;
500 DWORD rx_udpbufsize = -1;
501 DWORD lockOrderValidation;
506 int rx_max_rwin_size;
507 int rx_max_swin_size;
508 int rx_min_peer_timeout;
509 long virtualCache = 0;
510 fschar_t rootCellName[256];
511 struct rx_service *serverp;
512 static struct rx_securityClass *nullServerSecurityClassp;
520 /*int freelanceEnabled;*/
523 int cm_noIPAddr; /* number of client network interfaces */
524 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
525 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
526 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
527 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
530 WSAStartup(0x0101, &WSAjunk);
532 init_et_to_sys_error();
536 /* setup osidebug server at RPC slot 1000 */
537 osi_LongToUID(1000, &debugID);
538 code = osi_InitDebug(&debugID);
539 afsi_log("osi_InitDebug code %d", code);
544 *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment";
549 // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
551 if (code == RPC_S_NO_PROTSEQS)
552 *reasonP = "No RPC Protocol Sequences registered. Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
554 *reasonP = "unknown error";
559 gethostname(cm_HostName, sizeof(cm_HostName));
560 afsi_log("gethostname %s", cm_HostName);
561 thp = gethostbyname(cm_HostName);
562 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
564 /* seed random number generator */
565 srand(ntohl(cm_HostAddr));
567 /* Look up configuration parameters in Registry */
568 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
569 0, KEY_QUERY_VALUE, &parmKey);
570 if (code != ERROR_SUCCESS) {
571 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
572 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
573 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
574 StringCbPrintfA(buf, sizeof(buf),
575 "Failure in configuration while opening Registry: %s",
577 osi_panic(buf, __FILE__, __LINE__);
580 dummyLen = sizeof(dwPriority);
581 code = RegQueryValueEx(parmKey, "PriorityClass", NULL, NULL,
582 (BYTE *) &dwPriority, &dummyLen);
583 if (code != ERROR_SUCCESS || dwPriority == 0) {
584 dwPriority = HIGH_PRIORITY_CLASS;
586 if (dwPriority != GetPriorityClass(GetCurrentProcess()))
587 SetPriorityClass(GetCurrentProcess(), dwPriority);
588 afsi_log("PriorityClass 0x%x", GetPriorityClass(GetCurrentProcess()));
590 dummyLen = sizeof(lockOrderValidation);
591 code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
592 (BYTE *) &lockOrderValidation, &dummyLen);
593 if (code != ERROR_SUCCESS) {
595 lockOrderValidation = 1;
597 lockOrderValidation = 0;
600 osi_SetLockOrderValidation(lockOrderValidation);
601 afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
603 dummyLen = sizeof(maxcpus);
604 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
605 (BYTE *) &maxcpus, &dummyLen);
606 if (code == ERROR_SUCCESS) {
608 DWORD_PTR processAffinityMask, systemAffinityMask;
610 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
611 FALSE, GetCurrentProcessId());
612 if ( hProcess != NULL &&
613 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
616 DWORD_PTR mask, newAffinityMask;
623 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
624 if ( processAffinityMask & mask ) {
625 newAffinityMask |= mask;
631 SetProcessAffinityMask(hProcess, newAffinityMask);
632 CloseHandle(hProcess);
633 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
635 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
639 dummyLen = sizeof(TraceOption);
640 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
641 (BYTE *) &TraceOption, &dummyLen);
642 afsi_log("Trace Options = %lX", TraceOption);
644 dummyLen = sizeof(traceBufSize);
645 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
646 (BYTE *) &traceBufSize, &dummyLen);
647 if (code == ERROR_SUCCESS)
648 afsi_log("Trace Buffer size %d", traceBufSize);
650 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
651 afsi_log("Default trace buffer size %d", traceBufSize);
654 /* setup and enable debug log */
655 afsd_logp = osi_LogCreate("afsd", traceBufSize);
656 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
657 if ((TraceOption & 0x8)
662 osi_LogEnable(afsd_logp);
666 osi_Log0(afsd_logp, "Log init");
668 dummyLen = sizeof(smb_monitorReqs);
669 code = RegQueryValueEx(parmKey, "SMBRequestMonitor", NULL, NULL,
670 (BYTE *) &smb_monitorReqs, &dummyLen);
671 afsi_log("SMB request monitoring is %s", (smb_monitorReqs != 0)? "enabled": "disabled");
673 dummyLen = sizeof(cacheSize);
674 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
675 (BYTE *) &cacheSize, &dummyLen);
676 if (code == ERROR_SUCCESS)
677 afsi_log("Cache size %d", cacheSize);
679 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
680 afsi_log("Default cache size %d", cacheSize);
683 dummyLen = sizeof(logChunkSize);
684 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
685 (BYTE *) &logChunkSize, &dummyLen);
686 if (code == ERROR_SUCCESS) {
687 if (logChunkSize < 12 || logChunkSize > 30) {
688 afsi_log("Invalid chunk size %d, using default",
690 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
693 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
695 cm_logChunkSize = logChunkSize;
696 cm_chunkSize = 1 << logChunkSize;
697 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
699 dummyLen = sizeof(blockSize);
700 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
701 (BYTE *) &blockSize, &dummyLen);
702 if (code == ERROR_SUCCESS) {
704 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
706 afsi_log("Invalid block size %u specified, using default", blockSize);
707 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
710 * if the blockSize is less than 1024 we permit the blockSize to be
711 * specified in multiples of the default blocksize
713 if (blockSize <= 1024)
714 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
717 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
719 if (blockSize > cm_chunkSize) {
720 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
721 blockSize, cm_chunkSize);
722 blockSize = cm_chunkSize;
724 if (cm_chunkSize % blockSize != 0) {
725 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
726 blockSize, cm_chunkSize);
727 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
729 afsi_log("Block size %u", blockSize);
731 dummyLen = sizeof(numBkgD);
732 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
733 (BYTE *) &numBkgD, &dummyLen);
734 if (code == ERROR_SUCCESS) {
735 if (numBkgD > CM_MAX_DAEMONS)
736 numBkgD = CM_MAX_DAEMONS;
737 afsi_log("%d background daemons", numBkgD);
739 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
740 afsi_log("Defaulting to %d background daemons", numBkgD);
743 dummyLen = sizeof(numSvThreads);
744 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
745 (BYTE *) &numSvThreads, &dummyLen);
746 if (code == ERROR_SUCCESS)
747 afsi_log("%d server threads", numSvThreads);
749 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
750 afsi_log("Defaulting to %d server threads", numSvThreads);
753 dummyLen = sizeof(stats);
754 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
755 (BYTE *) &stats, &dummyLen);
756 if (code == ERROR_SUCCESS)
757 afsi_log("Status cache entries: %d", stats);
759 stats = CM_CONFIGDEFAULT_STATS;
760 afsi_log("Default status cache entries: %d", stats);
763 dummyLen = sizeof(volumes);
764 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
765 (BYTE *) &volumes, &dummyLen);
766 if (code == ERROR_SUCCESS)
767 afsi_log("Volumes cache entries: %d", volumes);
769 volumes = CM_CONFIGDEFAULT_STATS / 3;
770 afsi_log("Default volume cache entries: %d", volumes);
773 dummyLen = sizeof(cells);
774 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
775 (BYTE *) &cells, &dummyLen);
776 if (code == ERROR_SUCCESS)
777 afsi_log("Cell cache entries: %d", cells);
779 cells = CM_CONFIGDEFAULT_CELLS;
780 afsi_log("Default cell cache entries: %d", cells);
783 dummyLen = sizeof(ltt);
784 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
785 (BYTE *) <t, &dummyLen);
786 if (code != ERROR_SUCCESS)
788 smb_LogoffTokenTransfer = ltt;
789 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
792 dummyLen = sizeof(ltto);
793 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
794 NULL, NULL, (BYTE *) <to, &dummyLen);
795 if (code != ERROR_SUCCESS)
800 smb_LogoffTransferTimeout = ltto;
801 afsi_log("Logoff token transfer timeout %d seconds", ltto);
803 dummyLen = sizeof(cm_rootVolumeName);
804 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
805 (LPBYTE) cm_rootVolumeName, &dummyLen);
806 if (code == ERROR_SUCCESS)
807 afsi_log("Root volume %s", cm_rootVolumeName);
809 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
810 afsi_log("Default root volume name root.afs");
813 cm_mountRootCLen = sizeof(cm_mountRootC);
814 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
815 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
816 if (code == ERROR_SUCCESS) {
817 afsi_log("Mount root %S", cm_mountRootC);
818 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
820 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
821 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
825 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
826 cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
828 dummyLen = sizeof(buf);
829 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
831 if (code == ERROR_SUCCESS && buf[0]) {
832 if (regType == REG_EXPAND_SZ) {
833 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
834 if (dummyLen > sizeof(cm_CachePath)) {
835 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
836 osi_panic("CachePath too long", __FILE__, __LINE__);
839 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
841 afsi_log("Cache path %s", cm_CachePath);
843 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
844 if (dummyLen > sizeof(cm_CachePath)) {
845 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
846 sizeof(cm_CachePath));
847 osi_panic("CachePath too long", __FILE__, __LINE__);
849 afsi_log("Default cache path %s", cm_CachePath);
852 dummyLen = sizeof(virtualCache);
853 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
854 (LPBYTE)&virtualCache, &dummyLen);
855 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
858 dummyLen = sizeof(cm_ValidateCache);
859 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
860 (LPBYTE)&cm_ValidateCache, &dummyLen);
861 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
862 cm_ValidateCache = 1;
863 switch (cm_ValidateCache) {
865 afsi_log("Cache Validation disabled");
868 afsi_log("Cache Validation on Startup");
871 afsi_log("Cache Validation on Startup and Shutdown");
876 dummyLen = sizeof(traceOnPanic);
877 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
878 (BYTE *) &traceOnPanic, &dummyLen);
879 if (code != ERROR_SUCCESS)
880 traceOnPanic = 1; /* log */
881 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
883 dummyLen = sizeof(reportSessionStartups);
884 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
885 (BYTE *) &reportSessionStartups, &dummyLen);
886 if (code == ERROR_SUCCESS)
887 afsi_log("Session startups %s be recorded in the Event Log",
888 reportSessionStartups ? "will" : "will not");
890 reportSessionStartups = 0;
894 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
895 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
896 cm_sysNameList[i][0] = '\0';
898 cm_sysName = cm_sysNameList[0];
902 clientchar_t * cbuf = (clientchar_t *) buf;
903 dummyLen = sizeof(buf);
904 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
905 if (code != ERROR_SUCCESS || !cbuf[0]) {
907 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
908 #elif defined(_AMD64_)
909 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
910 #else /* assume x86 32-bit */
911 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
914 afsi_log("Sys name %S", cbuf);
916 /* breakup buf into individual search string entries */
917 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
918 if (*p == '\0' || iswspace(*p)) {
919 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
920 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
926 } while (*p == '\0' || isspace(*p));
933 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
935 dummyLen = sizeof(cryptall);
936 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
937 (BYTE *) &cryptall, &dummyLen);
938 if (code == ERROR_SUCCESS) {
939 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
942 afsi_log("Default SecurityLevel is clear");
946 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
947 else if (cryptall == 2)
948 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
950 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
952 dummyLen = sizeof(cryptall);
953 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
954 (BYTE *) &cm_anonvldb, &dummyLen);
955 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
957 dummyLen = sizeof(cm_dnsEnabled);
958 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
959 (BYTE *) &cm_dnsEnabled, &dummyLen);
960 if (code == ERROR_SUCCESS) {
961 afsi_log("DNS %s be used to find AFS cell servers",
962 cm_dnsEnabled ? "will" : "will not");
965 cm_dnsEnabled = 1; /* default on */
966 afsi_log("Default to use DNS to find AFS cell servers");
969 #ifdef AFS_FREELANCE_CLIENT
970 dummyLen = sizeof(cm_freelanceEnabled);
971 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
972 (BYTE *) &cm_freelanceEnabled, &dummyLen);
973 afsi_log("Freelance client feature %s activated",
974 cm_freelanceEnabled ? "is" : "is not");
976 dummyLen = sizeof(cm_freelanceImportCellServDB);
977 code = RegQueryValueEx(parmKey, "FreelanceImportCellServDB", NULL, NULL,
978 (BYTE *) &cm_freelanceImportCellServDB, &dummyLen);
979 afsi_log("Freelance client %s import CellServDB",
980 cm_freelanceImportCellServDB ? "does" : "does not");
981 #endif /* AFS_FREELANCE_CLIENT */
983 dummyLen = sizeof(smb_UseUnicode);
984 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
985 (BYTE *) &smb_UseUnicode, &dummyLen);
986 if (code != ERROR_SUCCESS) {
987 smb_UseUnicode = 1; /* default on */
989 afsi_log("SMB Server Unicode Support is %s",
990 smb_UseUnicode ? "enabled" : "disabled");
992 dummyLen = sizeof(smb_hideDotFiles);
993 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
994 (BYTE *) &smb_hideDotFiles, &dummyLen);
995 if (code != ERROR_SUCCESS) {
996 smb_hideDotFiles = 1; /* default on */
998 afsi_log("Dot files/dirs will %sbe marked hidden",
999 smb_hideDotFiles ? "" : "not ");
1001 dummyLen = sizeof(dwValue);
1002 code = RegQueryValueEx(parmKey, "UnixModeFileDefault", NULL, NULL,
1003 (BYTE *) &dwValue, &dummyLen);
1004 if (code == ERROR_SUCCESS) {
1005 smb_unixModeDefaultFile = (dwValue & 07777);
1007 afsi_log("Default unix mode bits for files is 0%04o", smb_unixModeDefaultFile);
1009 dummyLen = sizeof(dwValue);
1010 code = RegQueryValueEx(parmKey, "UnixModeDirDefault", NULL, NULL,
1011 (BYTE *) &dwValue, &dummyLen);
1012 if (code == ERROR_SUCCESS) {
1013 smb_unixModeDefaultDir = (dwValue & 07777);
1015 afsi_log("Default unix mode bits for directories is 0%04o", smb_unixModeDefaultDir);
1017 dummyLen = sizeof(smb_maxMpxRequests);
1018 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1019 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1020 if (code != ERROR_SUCCESS) {
1021 smb_maxMpxRequests = 50;
1023 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1025 dummyLen = sizeof(smb_maxVCPerServer);
1026 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1027 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1028 if (code != ERROR_SUCCESS) {
1029 smb_maxVCPerServer = 100;
1031 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1033 dummyLen = sizeof(smb_authType);
1034 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1035 (BYTE *) &smb_authType, &dummyLen);
1037 if (code != ERROR_SUCCESS ||
1038 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1039 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1041 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1043 dummyLen = sizeof(rx_max_rwin_size);
1044 code = RegQueryValueEx(parmKey, "RxMaxRecvWinSize", NULL, NULL,
1045 (BYTE *) &rx_max_rwin_size, &dummyLen);
1046 if (code == ERROR_SUCCESS)
1047 rx_SetMaxReceiveWindow(rx_max_rwin_size);
1048 afsi_log("Rx Maximum Receive Window Size is %d", rx_GetMaxReceiveWindow());
1050 dummyLen = sizeof(rx_max_swin_size);
1051 code = RegQueryValueEx(parmKey, "RxMaxSendWinSize", NULL, NULL,
1052 (BYTE *) &rx_max_swin_size, &dummyLen);
1053 if (code == ERROR_SUCCESS)
1054 rx_SetMaxSendWindow(rx_max_swin_size);
1055 afsi_log("Rx Maximum Send Window Size is %d", rx_GetMaxSendWindow());
1057 dummyLen = sizeof(rx_min_peer_timeout);
1058 code = RegQueryValueEx(parmKey, "RxMinPeerTimeout", NULL, NULL,
1059 (BYTE *) &rx_min_peer_timeout, &dummyLen);
1060 if (code == ERROR_SUCCESS)
1061 rx_SetMinPeerTimeout(rx_min_peer_timeout);
1062 afsi_log("Rx Minimum Peer Timeout is %d ms", rx_GetMinPeerTimeout());
1064 dummyLen = sizeof(rx_nojumbo);
1065 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1066 (BYTE *) &rx_nojumbo, &dummyLen);
1067 if (code != ERROR_SUCCESS) {
1069 dummyLen = sizeof(jumbo);
1070 code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
1071 (BYTE *) &jumbo, &dummyLen);
1072 if (code != ERROR_SUCCESS) {
1075 rx_nojumbo = !jumbo;
1079 afsi_log("RX Jumbograms are disabled");
1081 afsi_log("RX Jumbograms are enabled");
1083 dummyLen = sizeof(rx_extraPackets);
1084 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1085 (BYTE *) &rx_extraPackets, &dummyLen);
1086 if (code != ERROR_SUCCESS) {
1087 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
1089 if (rx_extraPackets)
1090 afsi_log("RX extraPackets is %d", rx_extraPackets);
1092 dummyLen = sizeof(rx_udpbufsize);
1093 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
1094 (BYTE *) &rx_udpbufsize, &dummyLen);
1095 if (code != ERROR_SUCCESS) {
1096 rx_udpbufsize = 256*1024;
1098 if (rx_udpbufsize != -1)
1099 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
1101 dummyLen = sizeof(rx_mtu);
1102 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1103 (BYTE *) &rx_mtu, &dummyLen);
1104 if (code != ERROR_SUCCESS || !rx_mtu) {
1108 afsi_log("RX maximum MTU is %d", rx_mtu);
1110 dummyLen = sizeof(rx_enable_peer_stats);
1111 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1112 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1113 if (code != ERROR_SUCCESS) {
1114 rx_enable_peer_stats = 1;
1116 if (rx_enable_peer_stats)
1117 afsi_log("RX Peer Statistics gathering is enabled");
1119 afsi_log("RX Peer Statistics gathering is disabled");
1121 dummyLen = sizeof(rx_enable_process_stats);
1122 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1123 (BYTE *) &rx_enable_process_stats, &dummyLen);
1124 if (code != ERROR_SUCCESS) {
1125 rx_enable_process_stats = 1;
1127 if (rx_enable_process_stats)
1128 afsi_log("RX Process Statistics gathering is enabled");
1130 afsi_log("RX Process Statistics gathering is disabled");
1132 dummyLen = sizeof(dwValue);
1134 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1135 (BYTE *) &dwValue, &dummyLen);
1136 if (code != ERROR_SUCCESS || dwValue != 0) {
1137 rx_EnableHotThread();
1138 afsi_log("RX Hot Thread is enabled");
1141 afsi_log("RX Hot Thread is disabled");
1143 dummyLen = sizeof(DWORD);
1144 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1145 (BYTE *) &dwValue, &dummyLen);
1146 if (code == ERROR_SUCCESS) {
1147 cm_callbackport = (unsigned short) dwValue;
1149 afsi_log("CM CallBackPort is %u", cm_callbackport);
1151 dummyLen = sizeof(DWORD);
1152 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1153 (BYTE *) &dwValue, &dummyLen);
1154 if (code == ERROR_SUCCESS) {
1155 cm_enableServerLocks = (unsigned short) dwValue;
1157 switch (cm_enableServerLocks) {
1159 afsi_log("EnableServerLocks: never");
1162 afsi_log("EnableServerLocks: always");
1166 afsi_log("EnableServerLocks: server requested");
1170 dummyLen = sizeof(DWORD);
1171 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1172 (BYTE *) &dwValue, &dummyLen);
1173 if (code == ERROR_SUCCESS) {
1174 cm_deleteReadOnly = (unsigned short) dwValue;
1176 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1179 dummyLen = sizeof(DWORD);
1180 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1181 (BYTE *) &dwValue, &dummyLen);
1182 if (code == ERROR_SUCCESS) {
1183 cm_BPlusTrees = (unsigned short) dwValue;
1185 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1187 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1189 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1192 afsi_log("CM BPlusTrees is not supported");
1195 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1196 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1197 (regType == REG_MULTI_SZ))
1200 dummyLen += 3; /* in case the source string is not nul terminated */
1201 pSz = malloc(dummyLen);
1202 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1203 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1204 (regType == REG_MULTI_SZ))
1209 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1211 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1213 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1214 smb_ExecutableExtensions[cnt] = p;
1215 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1217 smb_ExecutableExtensions[cnt] = NULL;
1220 if (!smb_ExecutableExtensions)
1223 if (!smb_ExecutableExtensions)
1224 afsi_log("No PrefetchExecutableExtensions");
1226 dummyLen = sizeof(DWORD);
1227 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1228 (BYTE *) &dwValue, &dummyLen);
1229 if (code == ERROR_SUCCESS) {
1230 cm_OfflineROIsValid = (unsigned short) dwValue;
1232 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1234 dummyLen = sizeof(DWORD);
1235 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1236 (BYTE *) &dwValue, &dummyLen);
1237 if (code == ERROR_SUCCESS) {
1238 cm_giveUpAllCBs = (unsigned short) dwValue;
1240 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1242 dummyLen = sizeof(DWORD);
1243 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1244 (BYTE *) &dwValue, &dummyLen);
1245 if (code == ERROR_SUCCESS) {
1246 cm_followBackupPath = (unsigned short) dwValue;
1248 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1250 dummyLen = sizeof(DWORD);
1251 code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
1252 (BYTE *) &dwValue, &dummyLen);
1253 if (code == ERROR_SUCCESS) {
1254 cm_accessPerFileCheck = (int) dwValue;
1256 afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
1258 dummyLen = sizeof(DWORD);
1259 code = RegQueryValueEx(parmKey, "ReadOnlyVolumeVersioning", NULL, NULL,
1260 (BYTE *) &dwValue, &dummyLen);
1261 if (code == ERROR_SUCCESS) {
1262 cm_readonlyVolumeVersioning = (unsigned short) dwValue;
1264 afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
1266 RegCloseKey (parmKey);
1268 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1270 /* get network related info */
1271 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1272 code = syscfg_GetIFInfo(&cm_noIPAddr,
1273 cm_IPAddr, cm_SubnetMask,
1274 cm_NetMtu, cm_NetFlags);
1276 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1277 afsi_log("syscfg_GetIFInfo error code %d", code);
1279 afsi_log("First Network address %x SubnetMask %x",
1280 cm_IPAddr[0], cm_SubnetMask[0]);
1283 * Save client configuration for GetCacheConfig requests
1285 cm_initParams.nChunkFiles = 0;
1286 cm_initParams.nStatCaches = stats;
1287 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1288 cm_initParams.nVolumeCaches = volumes;
1289 cm_initParams.firstChunkSize = cm_chunkSize;
1290 cm_initParams.otherChunkSize = cm_chunkSize;
1291 cm_initParams.cacheSize = cacheSize;
1292 cm_initParams.setTime = 0;
1293 cm_initParams.memCache = 1;
1295 /* init user daemon, and other packages */
1308 cm_InitNormalization();
1310 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1311 afsi_log("cm_InitMappedMemory code %x", code);
1313 *reasonP = "error initializing cache file";
1317 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1318 if (cm_InitDNS(cm_dnsEnabled) == -1)
1319 cm_dnsEnabled = 0; /* init failed, so deactivate */
1320 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1323 /* Set RX parameters before initializing RX */
1326 afsi_log("rx_SetNoJumbo successful");
1329 if ( rx_mtu != -1 ) {
1330 extern void rx_SetMaxMTU(int);
1332 rx_SetMaxMTU(rx_mtu);
1333 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1336 if ( rx_udpbufsize != -1 ) {
1337 rx_SetUdpBufSize(rx_udpbufsize);
1338 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1341 /* initialize RX, and tell it to listen to the callbackport,
1342 * which is used for callback RPC messages.
1344 code = rx_Init(htons(cm_callbackport));
1346 afsi_log("rx_Init code %x - retrying with a random port number", code);
1349 afsi_log("rx_Init code %x", code);
1351 *reasonP = "afsd: failed to init rx client";
1355 /* create an unauthenticated service #1 for callbacks */
1356 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1357 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1358 RXAFSCB_ExecuteRequest);
1359 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1360 if (serverp == NULL) {
1361 *reasonP = "unknown error";
1364 rx_SetMinProcs(serverp, 2);
1365 rx_SetMaxProcs(serverp, 4);
1366 rx_SetCheckReach(serverp, 1);
1368 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1369 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1370 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1371 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1372 if (serverp == NULL) {
1373 *reasonP = "unknown error";
1376 rx_SetMinProcs(serverp, 2);
1377 rx_SetMaxProcs(serverp, 4);
1379 /* start server threads, *not* donating this one to the pool */
1381 afsi_log("rx_StartServer");
1383 if (rx_enable_peer_stats)
1384 rx_enablePeerRPCStats();
1386 if (rx_enable_process_stats)
1387 rx_enableProcessRPCStats();
1389 code = cm_GetRootCellName(rootCellName);
1390 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1391 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1392 if (code != 0 && !cm_freelanceEnabled)
1394 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1397 else if (cm_freelanceEnabled)
1398 cm_data.rootCellp = NULL;
1400 if (code == 0 && !cm_freelanceEnabled)
1402 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1403 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1404 if (cm_data.rootCellp == NULL)
1406 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1411 #ifdef AFS_FREELANCE_CLIENT
1412 if (cm_freelanceEnabled)
1416 /* Initialize the RPC server for session keys */
1419 /* Initialize the RPC server for pipe services */
1422 afsd_InitServerPreferences();
1424 code = afsd_InitRoot(reasonP);
1429 int afsd_ShutdownCM(void)
1433 cm_ReleaseSCache(cm_data.rootSCachep);
1442 int afsd_InitDaemons(char **reasonP)
1444 cm_InitDaemon(numBkgD);
1445 afsi_log("cm_InitDaemon complete");
1450 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1457 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1458 0, KEY_QUERY_VALUE, &parmKey);
1459 if (code == ERROR_SUCCESS) {
1460 dummyLen = sizeof(DWORD);
1461 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1462 (BYTE *) &dwValue, &dummyLen);
1463 if (code == ERROR_SUCCESS)
1464 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1465 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1467 dummyLen = sizeof(DWORD);
1468 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1469 (BYTE *) &dwValue, &dummyLen);
1470 if (code == ERROR_SUCCESS)
1471 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1472 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1474 dummyLen = sizeof(DWORD);
1475 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1476 (BYTE *) &dwValue, &dummyLen);
1477 if (code == ERROR_SUCCESS) {
1478 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1479 if (dwValue > cm_chunkSize)
1480 smb_AsyncStoreSize = cm_chunkSize;
1481 else if (dwValue < cm_data.buf_blockSize)
1482 smb_AsyncStoreSize = cm_data.buf_blockSize;
1484 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1486 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1487 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1489 RegCloseKey (parmKey);
1492 /* Do this last so that we don't handle requests before init is done.
1493 * Here we initialize the SMB listener.
1495 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1496 afsi_log("smb_Init complete");
1509 #pragma pack( push, before_imagehlp, 8 )
1510 #include <imagehlp.h>
1511 #pragma pack( pop, before_imagehlp )
1513 #define MAXNAMELEN 1024
1515 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1517 HANDLE hProcess = GetCurrentProcess();
1519 #if defined(_AMD64_)
1521 #elif defined(_X86_)
1525 char functionName[MAXNAMELEN];
1527 IMAGEHLP_MODULE Module;
1531 IMAGEHLP_SYMBOL *pSym;
1533 afsi_log_useTimestamp = 0;
1535 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1537 memset( &s, '\0', sizeof s );
1538 if (!SymInitialize(hProcess, NULL, 1) )
1540 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1542 SymCleanup( hProcess );
1548 symOptions = SymGetOptions();
1549 symOptions |= SYMOPT_LOAD_LINES;
1550 symOptions &= ~SYMOPT_UNDNAME;
1551 SymSetOptions( symOptions );
1554 * init STACKFRAME for first call
1555 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1556 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1557 * and good riddance.
1559 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1560 #error The STACKFRAME initialization in afsd_printStack() for this platform
1561 #error must be properly configured
1562 #elif defined(_AMD64_)
1563 s.AddrPC.Offset = c->Rip;
1564 s.AddrPC.Mode = AddrModeFlat;
1565 s.AddrFrame.Offset = c->Rbp;
1566 s.AddrFrame.Mode = AddrModeFlat;
1568 s.AddrPC.Offset = c->Eip;
1569 s.AddrPC.Mode = AddrModeFlat;
1570 s.AddrFrame.Offset = c->Ebp;
1571 s.AddrFrame.Mode = AddrModeFlat;
1574 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1575 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1576 pSym->MaxNameLength = MAXNAMELEN;
1578 memset( &Line, '\0', sizeof Line );
1579 Line.SizeOfStruct = sizeof Line;
1581 memset( &Module, '\0', sizeof Module );
1582 Module.SizeOfStruct = sizeof Module;
1586 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1588 for ( frameNum = 0; ; ++ frameNum )
1591 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1592 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1593 * ERROR_NOACCESS (998), you can assume that either you are done, or
1594 * that the stack is so hosed that the next deeper frame could not be
1597 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1598 NULL, SymFunctionTableAccess, SymGetModuleBase,
1602 /* display its contents */
1603 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1604 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1605 s.AddrPC.Offset, s.AddrReturn.Offset,
1606 s.AddrFrame.Offset, s.AddrStack.Offset );
1608 if ( s.AddrPC.Offset == 0 )
1610 afsi_log("(-nosymbols- PC == 0)" );
1614 /* show procedure info from a valid PC */
1615 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1617 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1619 afsi_log("SymGetSymFromAddr(): errno = %lu",
1625 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1627 afsi_log("%s", functionName );
1631 afsi_log(" %+ld bytes", (long) offset);
1635 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1637 if (GetLastError() != ERROR_INVALID_ADDRESS)
1639 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1645 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1646 Line.LineNumber, offset);
1650 /* no return address means no deeper stackframe */
1651 if (s.AddrReturn.Offset == 0)
1658 if (GetLastError() != 0)
1660 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1663 SymCleanup(hProcess);
1668 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1669 static DWORD afsd_crtDbgBreaks[256];
1672 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1673 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1674 MINIDUMP_TYPE DumpType,
1675 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1676 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1677 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1688 code = GetEnvironmentVariable("TEMP", tmp, sizeof(tmp));
1689 if ( code == 0 || code > sizeof(tmp) )
1691 if (!GetWindowsDirectory(tmp, sizeof(tmp)))
1695 StringCbPrintfA(wd, sizeof(wd),
1696 "%s\\afsd-%04d-%02d-%02d-%02d_%02d_%02d.dmp", tmp,
1697 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
1698 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1699 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1703 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1705 if (IsDebuggerPresent())
1710 // Generate exception to get proper context in dump
1713 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1715 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1721 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1722 HANDLE hFile = NULL;
1723 HMODULE hDbgHelp = NULL;
1725 hDbgHelp = LoadLibrary("Dbghelp.dll");
1726 if ( hDbgHelp == NULL )
1729 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1730 if ( pMiniDumpWriteDump == NULL ) {
1731 FreeLibrary(hDbgHelp);
1735 hFile = OpenDumpFile();
1742 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1744 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1745 0, KEY_QUERY_VALUE, &parmKey);
1746 if (code == ERROR_SUCCESS) {
1747 dummyLen = sizeof(DWORD);
1748 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1749 (BYTE *) &dwValue, &dummyLen);
1750 if (code == ERROR_SUCCESS)
1751 dwMiniDumpType = dwValue;
1752 RegCloseKey (parmKey);
1755 eInfo.ThreadId = GetCurrentThreadId();
1756 eInfo.ExceptionPointers = ep;
1757 eInfo.ClientPointers = FALSE;
1759 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1760 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1765 FreeLibrary(hDbgHelp);
1769 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1773 BOOL allocRequestBrk = FALSE;
1775 HMODULE hLib = NULL;
1777 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1778 ep->ExceptionRecord->ExceptionCode,
1779 ep->ExceptionRecord->ExceptionAddress);
1782 if (afsd_crtDbgBreakCurrent &&
1783 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1785 allocRequestBrk = TRUE;
1786 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1790 /* save context if we want to print the stack information */
1791 context = *ep->ContextRecord;
1793 afsd_printStack(GetCurrentThread(), &context);
1795 GenerateMiniDump(ep);
1797 hLib = LoadLibrary("Faultrep.dll");
1799 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1801 pReportFault(ep, 0);
1805 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1807 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1810 if (allocRequestBrk)
1812 afsd_crtDbgBreakCurrent++;
1813 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1817 ep->ContextRecord->Eip++;
1819 #if defined(_AMD64_)
1820 ep->ContextRecord->Rip++;
1822 return EXCEPTION_CONTINUE_EXECUTION;
1826 return EXCEPTION_CONTINUE_SEARCH;
1830 void afsd_SetUnhandledExceptionFilter()
1833 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1838 void afsd_DbgBreakAllocInit()
1840 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1841 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1844 void afsd_DbgBreakAdd(DWORD requestNumber)
1847 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1849 if (afsd_crtDbgBreaks[i] == -1)
1854 afsd_crtDbgBreaks[i] = requestNumber;
1856 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);