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 <afsconfig.h>
11 #include <afs/param.h>
16 #include <afs/afs_args.h>
34 #include <rx\rx_null.h>
35 #include <rx\rxstat.h>
36 #include <WINNT/syscfg.h>
37 #include <WINNT/afsreg.h>
38 #include <afs\afscbint.h>
42 #include "lanahelper.h"
44 #include "cm_memmap.h"
50 extern afs_uint32 cryptall;
51 extern afs_uint32 cm_anonvldb;
52 extern int cm_enableServerLocks;
53 extern int cm_followBackupPath;
54 extern int cm_deleteReadOnly;
56 extern afs_int32 cm_BPlusTrees;
58 extern afs_int32 cm_OfflineROIsValid;
59 extern afs_int32 cm_giveUpAllCBs;
60 extern const clientchar_t **smb_ExecutableExtensions;
64 cm_config_data_t cm_data;
66 fschar_t cm_rootVolumeName[VL_MAXNAMELEN];
67 DWORD cm_rootVolumeNameLen;
69 fschar_t cm_mountRoot[1024];
70 DWORD cm_mountRootLen;
72 clientchar_t cm_mountRootC[1024];
73 DWORD cm_mountRootCLen;
75 int cm_readonlyVolumeVersioning = 0;
90 char cm_HostName[200];
92 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
94 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "NOT.YET.SET";
95 clientchar_t cm_NetbiosNameC[MAX_NB_NAME_LENGTH] = _C("NOT.YET.SET");
97 char cm_CachePath[MAX_PATH];
98 DWORD cm_ValidateCache = 1;
100 BOOL reportSessionStartups = FALSE;
102 cm_initparams_v1 cm_initParams;
104 clientchar_t *cm_sysName = 0;
105 unsigned int cm_sysNameCount = 0;
106 clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
108 DWORD TraceOption = 0;
111 * AFSD Initialization Log
113 * This is distinct from the regular debug logging facility.
114 * Log items go directly to a file, not to an array in memory, so that even
115 * if AFSD crashes, the log can be inspected.
120 int cm_dnsEnabled = 1;
123 static int afsi_log_useTimestamp = 1;
126 afsi_log(char *pattern, ...)
128 char s[256], t[100], d[100], u[512];
131 va_start(ap, pattern);
133 StringCbVPrintfA(s, sizeof(s), pattern, ap);
134 if ( afsi_log_useTimestamp ) {
135 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
136 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
137 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
138 if (afsi_file != INVALID_HANDLE_VALUE)
139 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
144 if (afsi_file != INVALID_HANDLE_VALUE)
145 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
153 char t[100], u[100], *p, *path;
159 DWORD maxLogSize = 100 * 1024;
161 afsi_file = INVALID_HANDLE_VALUE;
162 code = GetTempPath(sizeof(wd)-15, wd);
163 if ( code == 0 || code > (sizeof(wd)-15) )
164 return; /* unable to create a log */
166 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
167 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
168 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
169 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
171 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
172 0, KEY_QUERY_VALUE, &parmKey);
173 if (code == ERROR_SUCCESS) {
174 dummyLen = sizeof(maxLogSize);
175 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
176 (BYTE *) &maxLogSize, &dummyLen);
177 RegCloseKey (parmKey);
181 dwLow = GetFileSize( afsi_file, &dwHigh );
182 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
183 CloseHandle(afsi_file);
184 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
185 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
189 SetFilePointer(afsi_file, 0, NULL, FILE_END);
190 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
191 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
192 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
193 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
194 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
196 code = GetEnvironmentVariable("PATH", NULL, 0);
198 code = GetEnvironmentVariable("PATH", path, code);
199 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
200 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
201 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
204 /* Initialize C RTL Code Page conversion functions */
205 /* All of the path info obtained from the SMB client is in the OEM code page */
206 afsi_log("OEM Code Page = %d", GetOEMCP());
207 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
209 /* Two things to look into. First, should mbstowcs() be performing
210 * character set translations from OEM to Unicode in smb3.c;
211 * Second, do we need to set this translation in each function
212 * due to multi-threading.
214 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
215 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
220 * Standard AFSD trace
223 void afsd_ForceTrace(BOOL flush)
232 len = GetTempPath(sizeof(buf)-10, buf);
233 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
234 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
235 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
236 if (handle == INVALID_HANDLE_VALUE) {
238 osi_panic("Cannot create log file", __FILE__, __LINE__);
240 osi_LogPrint(afsd_logp, handle);
242 FlushFileBuffers(handle);
246 static void afsd_InitServerPreferences(void)
249 DWORD dwType, dwSize;
253 DWORD dwHostSize = 256;
255 struct sockaddr_in saddr;
258 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
259 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
261 KEY_READ|KEY_QUERY_VALUE,
262 &hkPrefs) == ERROR_SUCCESS) {
264 RegQueryInfoKey( hkPrefs,
267 NULL, /* lpReserved */
268 NULL, /* lpcSubKeys */
269 NULL, /* lpcMaxSubKeyLen */
270 NULL, /* lpcMaxClassLen */
271 &dwPrefs, /* lpcValues */
272 NULL, /* lpcMaxValueNameLen */
273 NULL, /* lpcMaxValueLen */
274 NULL, /* lpcbSecurityDescriptor */
275 NULL /* lpftLastWriteTime */
278 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
280 dwSize = sizeof(DWORD);
283 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
284 &dwType, (LPBYTE)&dwRank, &dwSize))
286 afsi_log("RegEnumValue(hkPrefs) failed");
290 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
292 if (isdigit(szHost[0]))
294 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
298 if ((pEntry = gethostbyname (szHost)) == NULL)
301 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
303 saddr.sin_port = htons(7003);
304 saddr.sin_family = AF_INET;
305 dwRank += (rand() & 0x000f);
307 tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
308 if ( tsp ) /* an existing server - ref count increased */
310 lock_ObtainMutex(&tsp->mx);
311 tsp->ipRank = (USHORT)dwRank;
312 tsp->flags |= CM_SERVERFLAG_PREF_SET;
313 tsp->adminRank = tsp->ipRank;
314 lock_ReleaseMutex(&tsp->mx);
316 /* set preferences for an existing vlserver */
317 cm_ChangeRankCellVLServer(tsp);
318 cm_PutServer(tsp); /* decrease refcount */
320 else /* add a new server without a cell */
322 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
323 lock_ObtainMutex(&tsp->mx);
324 tsp->ipRank = (USHORT)dwRank;
325 tsp->flags |= CM_SERVERFLAG_PREF_SET;
326 tsp->adminRank = tsp->ipRank;
327 lock_ReleaseMutex(&tsp->mx);
331 RegCloseKey(hkPrefs);
334 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
335 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\File",
337 KEY_READ|KEY_QUERY_VALUE,
338 &hkPrefs) == ERROR_SUCCESS) {
340 RegQueryInfoKey( hkPrefs,
343 NULL, /* lpReserved */
344 NULL, /* lpcSubKeys */
345 NULL, /* lpcMaxSubKeyLen */
346 NULL, /* lpcMaxClassLen */
347 &dwPrefs, /* lpcValues */
348 NULL, /* lpcMaxValueNameLen */
349 NULL, /* lpcMaxValueLen */
350 NULL, /* lpcbSecurityDescriptor */
351 NULL /* lpftLastWriteTime */
354 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
356 dwSize = sizeof(DWORD);
359 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
360 &dwType, (LPBYTE)&dwRank, &dwSize))
362 afsi_log("RegEnumValue(hkPrefs) failed");
366 afsi_log("File Server Preference: %s = %d",szHost, dwRank);
368 if (isdigit(szHost[0]))
370 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
374 if ((pEntry = gethostbyname (szHost)) == NULL)
377 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
379 saddr.sin_port = htons(7000);
380 saddr.sin_family = AF_INET;
381 dwRank += (rand() & 0x000f);
383 tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
384 if ( tsp ) /* an existing server - ref count increased */
386 lock_ObtainMutex(&tsp->mx);
387 tsp->ipRank = (USHORT)dwRank;
388 tsp->flags |= CM_SERVERFLAG_PREF_SET;
389 tsp->adminRank = tsp->ipRank;
390 lock_ReleaseMutex(&tsp->mx);
392 /* find volumes which might have RO copy
393 /* on server and change the ordering of
396 cm_ChangeRankVolume(tsp);
397 cm_PutServer(tsp); /* decrease refcount */
399 else /* add a new server without a cell */
401 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
402 lock_ObtainMutex(&tsp->mx);
403 tsp->ipRank = (USHORT)dwRank;
404 tsp->flags |= CM_SERVERFLAG_PREF_SET;
405 tsp->adminRank = tsp->ipRank;
406 lock_ReleaseMutex(&tsp->mx);
410 RegCloseKey(hkPrefs);
416 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
421 static BOOL bChecked = FALSE;
422 static BOOL bIsWow64 = FALSE;
427 LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
429 h1 = GetModuleHandle("kernel32.dll");
431 (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process");
433 /* If we don't find the fnIsWow64Process function then we
434 * are not running in a broken Wow64
436 if (fnIsWow64Process)
437 fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
447 * AFSD Initialization
451 afsd_InitRoot(char **reasonP)
458 if (cm_freelanceEnabled) {
459 cm_FakeRootFid(&cm_data.rootFid);
463 osi_Log0(afsd_logp, "Loading Root Volume from cell");
465 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
466 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
467 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
468 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
469 } while (code && --attempts);
471 *reasonP = "can't find root volume in root cell";
475 /* compute the root fid */
476 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
479 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
480 afsi_log("cm_GetSCache code %x scache %x", code,
481 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
483 *reasonP = "unknown error";
491 afsd_InitCM(char **reasonP)
494 afs_uint64 cacheBlocks;
502 DWORD rx_enable_peer_stats;
503 DWORD rx_enable_process_stats;
504 DWORD rx_udpbufsize = -1;
505 DWORD lockOrderValidation;
510 int rx_max_rwin_size;
511 int rx_max_swin_size;
512 int rx_min_peer_timeout;
513 long virtualCache = 0;
514 fschar_t rootCellName[256];
515 struct rx_service *serverp;
516 static struct rx_securityClass *nullServerSecurityClassp;
524 /*int freelanceEnabled;*/
527 int cm_noIPAddr; /* number of client network interfaces */
528 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
529 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
530 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
531 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
534 WSAStartup(0x0101, &WSAjunk);
536 init_et_to_sys_error();
540 /* setup osidebug server at RPC slot 1000 */
541 osi_LongToUID(1000, &debugID);
542 code = osi_InitDebug(&debugID);
543 afsi_log("osi_InitDebug code %d", code);
548 *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment";
553 // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
555 if (code == RPC_S_NO_PROTSEQS)
556 *reasonP = "No RPC Protocol Sequences registered. Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
558 *reasonP = "unknown error";
563 gethostname(cm_HostName, sizeof(cm_HostName));
564 afsi_log("gethostname %s", cm_HostName);
565 thp = gethostbyname(cm_HostName);
566 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
568 /* seed random number generator */
569 srand(ntohl(cm_HostAddr));
571 /* Look up configuration parameters in Registry */
572 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
573 0, KEY_QUERY_VALUE, &parmKey);
574 if (code != ERROR_SUCCESS) {
575 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
576 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
577 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
578 StringCbPrintfA(buf, sizeof(buf),
579 "Failure in configuration while opening Registry: %s",
581 osi_panic(buf, __FILE__, __LINE__);
584 dummyLen = sizeof(dwPriority);
585 code = RegQueryValueEx(parmKey, "PriorityClass", NULL, NULL,
586 (BYTE *) &dwPriority, &dummyLen);
587 if (code != ERROR_SUCCESS || dwPriority == 0) {
588 dwPriority = HIGH_PRIORITY_CLASS;
590 if (dwPriority != GetPriorityClass(GetCurrentProcess()))
591 SetPriorityClass(GetCurrentProcess(), dwPriority);
592 afsi_log("PriorityClass 0x%x", GetPriorityClass(GetCurrentProcess()));
594 dummyLen = sizeof(lockOrderValidation);
595 code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
596 (BYTE *) &lockOrderValidation, &dummyLen);
597 if (code != ERROR_SUCCESS) {
599 lockOrderValidation = 1;
601 lockOrderValidation = 0;
604 osi_SetLockOrderValidation(lockOrderValidation);
605 afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
607 dummyLen = sizeof(maxcpus);
608 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
609 (BYTE *) &maxcpus, &dummyLen);
610 if (code == ERROR_SUCCESS) {
612 DWORD_PTR processAffinityMask, systemAffinityMask;
614 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
615 FALSE, GetCurrentProcessId());
616 if ( hProcess != NULL &&
617 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
620 DWORD_PTR mask, newAffinityMask;
627 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
628 if ( processAffinityMask & mask ) {
629 newAffinityMask |= mask;
635 SetProcessAffinityMask(hProcess, newAffinityMask);
636 CloseHandle(hProcess);
637 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
639 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
643 dummyLen = sizeof(TraceOption);
644 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
645 (BYTE *) &TraceOption, &dummyLen);
646 afsi_log("Trace Options = %lX", TraceOption);
648 dummyLen = sizeof(traceBufSize);
649 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
650 (BYTE *) &traceBufSize, &dummyLen);
651 if (code == ERROR_SUCCESS)
652 afsi_log("Trace Buffer size %d", traceBufSize);
654 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
655 afsi_log("Default trace buffer size %d", traceBufSize);
658 /* setup and enable debug log */
659 afsd_logp = osi_LogCreate("afsd", traceBufSize);
660 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
661 if ((TraceOption & 0x8)
666 osi_LogEnable(afsd_logp);
670 osi_Log0(afsd_logp, "Log init");
672 dummyLen = sizeof(smb_monitorReqs);
673 code = RegQueryValueEx(parmKey, "SMBRequestMonitor", NULL, NULL,
674 (BYTE *) &smb_monitorReqs, &dummyLen);
675 afsi_log("SMB request monitoring is %s", (smb_monitorReqs != 0)? "enabled": "disabled");
677 dummyLen = sizeof(cacheSize);
678 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
679 (BYTE *) &cacheSize, &dummyLen);
680 if (code == ERROR_SUCCESS)
681 afsi_log("Cache size %d", cacheSize);
683 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
684 afsi_log("Default cache size %d", cacheSize);
687 dummyLen = sizeof(logChunkSize);
688 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
689 (BYTE *) &logChunkSize, &dummyLen);
690 if (code == ERROR_SUCCESS) {
691 if (logChunkSize < 12 || logChunkSize > 30) {
692 afsi_log("Invalid chunk size %d, using default",
694 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
697 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
699 cm_logChunkSize = logChunkSize;
700 cm_chunkSize = 1 << logChunkSize;
701 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
703 dummyLen = sizeof(blockSize);
704 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
705 (BYTE *) &blockSize, &dummyLen);
706 if (code == ERROR_SUCCESS) {
708 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
710 afsi_log("Invalid block size %u specified, using default", blockSize);
711 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
714 * if the blockSize is less than 1024 we permit the blockSize to be
715 * specified in multiples of the default blocksize
717 if (blockSize <= 1024)
718 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
721 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
723 if (blockSize > cm_chunkSize) {
724 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
725 blockSize, cm_chunkSize);
726 blockSize = cm_chunkSize;
728 if (cm_chunkSize % blockSize != 0) {
729 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
730 blockSize, cm_chunkSize);
731 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
733 afsi_log("Block size %u", blockSize);
735 dummyLen = sizeof(numBkgD);
736 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
737 (BYTE *) &numBkgD, &dummyLen);
738 if (code == ERROR_SUCCESS) {
739 if (numBkgD > CM_MAX_DAEMONS)
740 numBkgD = CM_MAX_DAEMONS;
741 afsi_log("%d background daemons", numBkgD);
743 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
744 afsi_log("Defaulting to %d background daemons", numBkgD);
747 dummyLen = sizeof(numSvThreads);
748 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
749 (BYTE *) &numSvThreads, &dummyLen);
750 if (code == ERROR_SUCCESS)
751 afsi_log("%d server threads", numSvThreads);
753 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
754 afsi_log("Defaulting to %d server threads", numSvThreads);
757 dummyLen = sizeof(stats);
758 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
759 (BYTE *) &stats, &dummyLen);
760 if (code == ERROR_SUCCESS)
761 afsi_log("Status cache entries: %d", stats);
763 stats = CM_CONFIGDEFAULT_STATS;
764 afsi_log("Default status cache entries: %d", stats);
767 dummyLen = sizeof(volumes);
768 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
769 (BYTE *) &volumes, &dummyLen);
770 if (code == ERROR_SUCCESS)
771 afsi_log("Volumes cache entries: %d", volumes);
773 volumes = CM_CONFIGDEFAULT_STATS / 3;
774 afsi_log("Default volume cache entries: %d", volumes);
777 dummyLen = sizeof(cells);
778 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
779 (BYTE *) &cells, &dummyLen);
780 if (code == ERROR_SUCCESS)
781 afsi_log("Cell cache entries: %d", cells);
783 cells = CM_CONFIGDEFAULT_CELLS;
784 afsi_log("Default cell cache entries: %d", cells);
787 dummyLen = sizeof(ltt);
788 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
789 (BYTE *) <t, &dummyLen);
790 if (code != ERROR_SUCCESS)
792 smb_LogoffTokenTransfer = ltt;
793 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
796 dummyLen = sizeof(ltto);
797 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
798 NULL, NULL, (BYTE *) <to, &dummyLen);
799 if (code != ERROR_SUCCESS)
804 smb_LogoffTransferTimeout = ltto;
805 afsi_log("Logoff token transfer timeout %d seconds", ltto);
807 dummyLen = sizeof(cm_rootVolumeName);
808 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
809 (LPBYTE) cm_rootVolumeName, &dummyLen);
810 if (code == ERROR_SUCCESS)
811 afsi_log("Root volume %s", cm_rootVolumeName);
813 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
814 afsi_log("Default root volume name root.afs");
817 cm_mountRootCLen = sizeof(cm_mountRootC);
818 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
819 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
820 if (code == ERROR_SUCCESS) {
821 afsi_log("Mount root %S", cm_mountRootC);
822 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
824 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
825 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
829 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
830 cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
832 dummyLen = sizeof(buf);
833 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
835 if (code == ERROR_SUCCESS && buf[0]) {
836 if (regType == REG_EXPAND_SZ) {
837 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
838 if (dummyLen > sizeof(cm_CachePath)) {
839 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
840 osi_panic("CachePath too long", __FILE__, __LINE__);
843 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
845 afsi_log("Cache path %s", cm_CachePath);
847 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
848 if (dummyLen > sizeof(cm_CachePath)) {
849 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
850 sizeof(cm_CachePath));
851 osi_panic("CachePath too long", __FILE__, __LINE__);
853 afsi_log("Default cache path %s", cm_CachePath);
856 dummyLen = sizeof(virtualCache);
857 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
858 (LPBYTE)&virtualCache, &dummyLen);
859 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
862 dummyLen = sizeof(cm_ValidateCache);
863 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
864 (LPBYTE)&cm_ValidateCache, &dummyLen);
865 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
866 cm_ValidateCache = 1;
867 switch (cm_ValidateCache) {
869 afsi_log("Cache Validation disabled");
872 afsi_log("Cache Validation on Startup");
875 afsi_log("Cache Validation on Startup and Shutdown");
880 dummyLen = sizeof(traceOnPanic);
881 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
882 (BYTE *) &traceOnPanic, &dummyLen);
883 if (code != ERROR_SUCCESS)
884 traceOnPanic = 1; /* log */
885 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
887 dummyLen = sizeof(reportSessionStartups);
888 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
889 (BYTE *) &reportSessionStartups, &dummyLen);
890 if (code == ERROR_SUCCESS)
891 afsi_log("Session startups %s be recorded in the Event Log",
892 reportSessionStartups ? "will" : "will not");
894 reportSessionStartups = 0;
898 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
899 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
900 cm_sysNameList[i][0] = '\0';
902 cm_sysName = cm_sysNameList[0];
906 clientchar_t * cbuf = (clientchar_t *) buf;
907 dummyLen = sizeof(buf);
908 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
909 if (code != ERROR_SUCCESS || !cbuf[0]) {
911 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
912 #elif defined(_AMD64_)
913 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
914 #else /* assume x86 32-bit */
915 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
918 afsi_log("Sys name %S", cbuf);
920 /* breakup buf into individual search string entries */
921 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
922 if (*p == '\0' || iswspace(*p)) {
923 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
924 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
930 } while (*p == '\0' || isspace(*p));
937 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
939 dummyLen = sizeof(cryptall);
940 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
941 (BYTE *) &cryptall, &dummyLen);
942 if (code == ERROR_SUCCESS) {
943 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
946 afsi_log("Default SecurityLevel is clear");
950 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
951 else if (cryptall == 2)
952 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
954 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
956 dummyLen = sizeof(cryptall);
957 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
958 (BYTE *) &cm_anonvldb, &dummyLen);
959 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
961 dummyLen = sizeof(cm_dnsEnabled);
962 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
963 (BYTE *) &cm_dnsEnabled, &dummyLen);
964 if (code == ERROR_SUCCESS) {
965 afsi_log("DNS %s be used to find AFS cell servers",
966 cm_dnsEnabled ? "will" : "will not");
969 cm_dnsEnabled = 1; /* default on */
970 afsi_log("Default to use DNS to find AFS cell servers");
973 #ifdef AFS_FREELANCE_CLIENT
974 dummyLen = sizeof(cm_freelanceEnabled);
975 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
976 (BYTE *) &cm_freelanceEnabled, &dummyLen);
977 afsi_log("Freelance client feature %s activated",
978 cm_freelanceEnabled ? "is" : "is not");
980 dummyLen = sizeof(cm_freelanceImportCellServDB);
981 code = RegQueryValueEx(parmKey, "FreelanceImportCellServDB", NULL, NULL,
982 (BYTE *) &cm_freelanceImportCellServDB, &dummyLen);
983 afsi_log("Freelance client %s import CellServDB",
984 cm_freelanceImportCellServDB ? "does" : "does not");
985 #endif /* AFS_FREELANCE_CLIENT */
987 dummyLen = sizeof(smb_UseUnicode);
988 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
989 (BYTE *) &smb_UseUnicode, &dummyLen);
990 if (code != ERROR_SUCCESS) {
991 smb_UseUnicode = 1; /* default on */
993 afsi_log("SMB Server Unicode Support is %s",
994 smb_UseUnicode ? "enabled" : "disabled");
996 dummyLen = sizeof(smb_hideDotFiles);
997 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
998 (BYTE *) &smb_hideDotFiles, &dummyLen);
999 if (code != ERROR_SUCCESS) {
1000 smb_hideDotFiles = 1; /* default on */
1002 afsi_log("Dot files/dirs will %sbe marked hidden",
1003 smb_hideDotFiles ? "" : "not ");
1005 dummyLen = sizeof(dwValue);
1006 code = RegQueryValueEx(parmKey, "UnixModeFileDefault", NULL, NULL,
1007 (BYTE *) &dwValue, &dummyLen);
1008 if (code == ERROR_SUCCESS) {
1009 smb_unixModeDefaultFile = (dwValue & 07777);
1011 afsi_log("Default unix mode bits for files is 0%04o", smb_unixModeDefaultFile);
1013 dummyLen = sizeof(dwValue);
1014 code = RegQueryValueEx(parmKey, "UnixModeDirDefault", NULL, NULL,
1015 (BYTE *) &dwValue, &dummyLen);
1016 if (code == ERROR_SUCCESS) {
1017 smb_unixModeDefaultDir = (dwValue & 07777);
1019 afsi_log("Default unix mode bits for directories is 0%04o", smb_unixModeDefaultDir);
1021 dummyLen = sizeof(smb_maxMpxRequests);
1022 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1023 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1024 if (code != ERROR_SUCCESS) {
1025 smb_maxMpxRequests = 50;
1027 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1029 dummyLen = sizeof(smb_maxVCPerServer);
1030 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1031 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1032 if (code != ERROR_SUCCESS) {
1033 smb_maxVCPerServer = 100;
1035 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1037 dummyLen = sizeof(smb_authType);
1038 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1039 (BYTE *) &smb_authType, &dummyLen);
1041 if (code != ERROR_SUCCESS ||
1042 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1043 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1045 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1047 dummyLen = sizeof(rx_max_rwin_size);
1048 code = RegQueryValueEx(parmKey, "RxMaxRecvWinSize", NULL, NULL,
1049 (BYTE *) &rx_max_rwin_size, &dummyLen);
1050 if (code == ERROR_SUCCESS)
1051 rx_SetMaxReceiveWindow(rx_max_rwin_size);
1052 afsi_log("Rx Maximum Receive Window Size is %d", rx_GetMaxReceiveWindow());
1054 dummyLen = sizeof(rx_max_swin_size);
1055 code = RegQueryValueEx(parmKey, "RxMaxSendWinSize", NULL, NULL,
1056 (BYTE *) &rx_max_swin_size, &dummyLen);
1057 if (code == ERROR_SUCCESS)
1058 rx_SetMaxSendWindow(rx_max_swin_size);
1059 afsi_log("Rx Maximum Send Window Size is %d", rx_GetMaxSendWindow());
1061 dummyLen = sizeof(rx_min_peer_timeout);
1062 code = RegQueryValueEx(parmKey, "RxMinPeerTimeout", NULL, NULL,
1063 (BYTE *) &rx_min_peer_timeout, &dummyLen);
1064 if (code == ERROR_SUCCESS)
1065 rx_SetMinPeerTimeout(rx_min_peer_timeout);
1066 afsi_log("Rx Minimum Peer Timeout is %d ms", rx_GetMinPeerTimeout());
1068 dummyLen = sizeof(rx_pmtu_discovery);
1069 code = RegQueryValueEx(parmKey, "RxPMTUDiscovery", NULL, NULL,
1070 (BYTE *) &rx_pmtu_discovery, &dummyLen);
1071 afsi_log("Rx PMTU Discovery is %d ms", rx_pmtu_discovery);
1073 dummyLen = sizeof(rx_nojumbo);
1074 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1075 (BYTE *) &rx_nojumbo, &dummyLen);
1076 if (code != ERROR_SUCCESS) {
1078 dummyLen = sizeof(jumbo);
1079 code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
1080 (BYTE *) &jumbo, &dummyLen);
1081 if (code != ERROR_SUCCESS) {
1084 rx_nojumbo = !jumbo;
1088 afsi_log("RX Jumbograms are disabled");
1090 afsi_log("RX Jumbograms are enabled");
1092 dummyLen = sizeof(rx_extraPackets);
1093 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1094 (BYTE *) &rx_extraPackets, &dummyLen);
1095 if (code != ERROR_SUCCESS) {
1096 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
1098 if (rx_extraPackets)
1099 afsi_log("RX extraPackets is %d", rx_extraPackets);
1101 dummyLen = sizeof(rx_udpbufsize);
1102 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
1103 (BYTE *) &rx_udpbufsize, &dummyLen);
1104 if (code != ERROR_SUCCESS) {
1105 rx_udpbufsize = 256*1024;
1107 if (rx_udpbufsize != -1)
1108 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
1110 dummyLen = sizeof(rx_mtu);
1111 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1112 (BYTE *) &rx_mtu, &dummyLen);
1113 if (code != ERROR_SUCCESS || !rx_mtu) {
1117 afsi_log("RX maximum MTU is %d", rx_mtu);
1119 dummyLen = sizeof(rx_enable_peer_stats);
1120 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1121 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1122 if (code != ERROR_SUCCESS) {
1123 rx_enable_peer_stats = 1;
1125 if (rx_enable_peer_stats)
1126 afsi_log("RX Peer Statistics gathering is enabled");
1128 afsi_log("RX Peer Statistics gathering is disabled");
1130 dummyLen = sizeof(rx_enable_process_stats);
1131 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1132 (BYTE *) &rx_enable_process_stats, &dummyLen);
1133 if (code != ERROR_SUCCESS) {
1134 rx_enable_process_stats = 1;
1136 if (rx_enable_process_stats)
1137 afsi_log("RX Process Statistics gathering is enabled");
1139 afsi_log("RX Process Statistics gathering is disabled");
1141 dummyLen = sizeof(dwValue);
1143 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1144 (BYTE *) &dwValue, &dummyLen);
1145 if (code != ERROR_SUCCESS || dwValue != 0) {
1146 rx_EnableHotThread();
1147 afsi_log("RX Hot Thread is enabled");
1150 afsi_log("RX Hot Thread is disabled");
1152 dummyLen = sizeof(DWORD);
1153 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1154 (BYTE *) &dwValue, &dummyLen);
1155 if (code == ERROR_SUCCESS) {
1156 cm_callbackport = (unsigned short) dwValue;
1158 afsi_log("CM CallBackPort is %u", cm_callbackport);
1160 dummyLen = sizeof(DWORD);
1161 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1162 (BYTE *) &dwValue, &dummyLen);
1163 if (code == ERROR_SUCCESS) {
1164 cm_enableServerLocks = (unsigned short) dwValue;
1166 switch (cm_enableServerLocks) {
1168 afsi_log("EnableServerLocks: never");
1171 afsi_log("EnableServerLocks: always");
1175 afsi_log("EnableServerLocks: server requested");
1179 dummyLen = sizeof(DWORD);
1180 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1181 (BYTE *) &dwValue, &dummyLen);
1182 if (code == ERROR_SUCCESS) {
1183 cm_deleteReadOnly = (unsigned short) dwValue;
1185 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1188 dummyLen = sizeof(DWORD);
1189 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1190 (BYTE *) &dwValue, &dummyLen);
1191 if (code == ERROR_SUCCESS) {
1192 cm_BPlusTrees = (unsigned short) dwValue;
1194 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1196 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1198 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1201 afsi_log("CM BPlusTrees is not supported");
1204 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1205 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1206 (regType == REG_MULTI_SZ))
1209 dummyLen += 3; /* in case the source string is not nul terminated */
1210 pSz = malloc(dummyLen);
1211 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1212 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1213 (regType == REG_MULTI_SZ))
1218 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1220 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1222 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1223 smb_ExecutableExtensions[cnt] = p;
1224 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1226 smb_ExecutableExtensions[cnt] = NULL;
1229 if (!smb_ExecutableExtensions)
1232 if (!smb_ExecutableExtensions)
1233 afsi_log("No PrefetchExecutableExtensions");
1235 dummyLen = sizeof(DWORD);
1236 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1237 (BYTE *) &dwValue, &dummyLen);
1238 if (code == ERROR_SUCCESS) {
1239 cm_OfflineROIsValid = (unsigned short) dwValue;
1241 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_OfflineROIsValid);
1243 dummyLen = sizeof(DWORD);
1244 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1245 (BYTE *) &dwValue, &dummyLen);
1246 if (code == ERROR_SUCCESS) {
1247 cm_giveUpAllCBs = (unsigned short) dwValue;
1249 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1251 dummyLen = sizeof(DWORD);
1252 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1253 (BYTE *) &dwValue, &dummyLen);
1254 if (code == ERROR_SUCCESS) {
1255 cm_followBackupPath = (unsigned short) dwValue;
1257 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1259 dummyLen = sizeof(DWORD);
1260 code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
1261 (BYTE *) &dwValue, &dummyLen);
1262 if (code == ERROR_SUCCESS) {
1263 cm_accessPerFileCheck = (int) dwValue;
1265 afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
1267 dummyLen = sizeof(DWORD);
1268 code = RegQueryValueEx(parmKey, "ReadOnlyVolumeVersioning", NULL, NULL,
1269 (BYTE *) &dwValue, &dummyLen);
1270 if (code == ERROR_SUCCESS) {
1271 cm_readonlyVolumeVersioning = (unsigned short) dwValue;
1273 afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
1275 RegCloseKey (parmKey);
1277 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1279 /* get network related info */
1280 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1281 code = syscfg_GetIFInfo(&cm_noIPAddr,
1282 cm_IPAddr, cm_SubnetMask,
1283 cm_NetMtu, cm_NetFlags);
1285 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1286 afsi_log("syscfg_GetIFInfo error code %d", code);
1288 afsi_log("First Network address %x SubnetMask %x",
1289 cm_IPAddr[0], cm_SubnetMask[0]);
1292 * Save client configuration for GetCacheConfig requests
1294 cm_initParams.nChunkFiles = 0;
1295 cm_initParams.nStatCaches = stats;
1296 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1297 cm_initParams.nVolumeCaches = volumes;
1298 cm_initParams.firstChunkSize = cm_chunkSize;
1299 cm_initParams.otherChunkSize = cm_chunkSize;
1300 cm_initParams.cacheSize = cacheSize;
1301 cm_initParams.setTime = 0;
1302 cm_initParams.memCache = 1;
1304 /* init user daemon, and other packages */
1317 cm_InitNormalization();
1319 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1320 afsi_log("cm_InitMappedMemory code %x", code);
1322 *reasonP = "error initializing cache file";
1326 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1327 if (cm_InitDNS(cm_dnsEnabled) == -1)
1328 cm_dnsEnabled = 0; /* init failed, so deactivate */
1329 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1332 /* Set RX parameters before initializing RX */
1335 afsi_log("rx_SetNoJumbo successful");
1338 if ( rx_mtu != -1 ) {
1339 extern void rx_SetMaxMTU(int);
1341 rx_SetMaxMTU(rx_mtu);
1342 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1345 if ( rx_udpbufsize != -1 ) {
1346 rx_SetUdpBufSize(rx_udpbufsize);
1347 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1350 /* initialize RX, and tell it to listen to the callbackport,
1351 * which is used for callback RPC messages.
1353 code = rx_Init(htons(cm_callbackport));
1355 afsi_log("rx_Init code %x - retrying with a random port number", code);
1358 afsi_log("rx_Init code %x", code);
1360 *reasonP = "afsd: failed to init rx client";
1364 /* create an unauthenticated service #1 for callbacks */
1365 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1366 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1367 RXAFSCB_ExecuteRequest);
1368 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1369 if (serverp == NULL) {
1370 *reasonP = "unknown error";
1373 rx_SetMinProcs(serverp, 2);
1374 rx_SetMaxProcs(serverp, 4);
1375 rx_SetCheckReach(serverp, 1);
1377 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1378 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1379 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1380 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1381 if (serverp == NULL) {
1382 *reasonP = "unknown error";
1385 rx_SetMinProcs(serverp, 2);
1386 rx_SetMaxProcs(serverp, 4);
1388 /* start server threads, *not* donating this one to the pool */
1390 afsi_log("rx_StartServer");
1392 if (rx_enable_peer_stats)
1393 rx_enablePeerRPCStats();
1395 if (rx_enable_process_stats)
1396 rx_enableProcessRPCStats();
1398 code = cm_GetRootCellName(rootCellName);
1399 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1400 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1401 if (code != 0 && !cm_freelanceEnabled)
1403 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1406 else if (cm_freelanceEnabled)
1407 cm_data.rootCellp = NULL;
1409 if (code == 0 && !cm_freelanceEnabled)
1411 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1412 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1413 if (cm_data.rootCellp == NULL)
1415 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1420 #ifdef AFS_FREELANCE_CLIENT
1421 if (cm_freelanceEnabled)
1425 /* Initialize the RPC server for session keys */
1428 /* Initialize the RPC server for pipe services */
1431 afsd_InitServerPreferences();
1433 code = afsd_InitRoot(reasonP);
1438 int afsd_ShutdownCM(void)
1442 cm_ReleaseSCache(cm_data.rootSCachep);
1451 int afsd_InitDaemons(char **reasonP)
1453 cm_InitDaemon(numBkgD);
1454 afsi_log("cm_InitDaemon complete");
1459 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1466 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1467 0, KEY_QUERY_VALUE, &parmKey);
1468 if (code == ERROR_SUCCESS) {
1469 dummyLen = sizeof(DWORD);
1470 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1471 (BYTE *) &dwValue, &dummyLen);
1472 if (code == ERROR_SUCCESS)
1473 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1474 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1476 dummyLen = sizeof(DWORD);
1477 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1478 (BYTE *) &dwValue, &dummyLen);
1479 if (code == ERROR_SUCCESS)
1480 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1481 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1483 dummyLen = sizeof(DWORD);
1484 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1485 (BYTE *) &dwValue, &dummyLen);
1486 if (code == ERROR_SUCCESS) {
1487 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1488 if (dwValue > cm_chunkSize)
1489 smb_AsyncStoreSize = cm_chunkSize;
1490 else if (dwValue < cm_data.buf_blockSize)
1491 smb_AsyncStoreSize = cm_data.buf_blockSize;
1493 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1495 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1496 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1498 RegCloseKey (parmKey);
1501 /* Do this last so that we don't handle requests before init is done.
1502 * Here we initialize the SMB listener.
1504 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1505 afsi_log("smb_Init complete");
1518 #pragma pack( push, before_imagehlp, 8 )
1519 #include <imagehlp.h>
1520 #pragma pack( pop, before_imagehlp )
1522 #define MAXNAMELEN 1024
1524 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1526 HANDLE hProcess = GetCurrentProcess();
1528 #if defined(_AMD64_)
1530 #elif defined(_X86_)
1534 char functionName[MAXNAMELEN];
1536 IMAGEHLP_MODULE Module;
1540 IMAGEHLP_SYMBOL *pSym;
1542 afsi_log_useTimestamp = 0;
1544 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1546 memset( &s, '\0', sizeof s );
1547 if (!SymInitialize(hProcess, NULL, 1) )
1549 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1551 SymCleanup( hProcess );
1557 symOptions = SymGetOptions();
1558 symOptions |= SYMOPT_LOAD_LINES;
1559 symOptions &= ~SYMOPT_UNDNAME;
1560 SymSetOptions( symOptions );
1563 * init STACKFRAME for first call
1564 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1565 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1566 * and good riddance.
1568 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1569 #error The STACKFRAME initialization in afsd_printStack() for this platform
1570 #error must be properly configured
1571 #elif defined(_AMD64_)
1572 s.AddrPC.Offset = c->Rip;
1573 s.AddrPC.Mode = AddrModeFlat;
1574 s.AddrFrame.Offset = c->Rbp;
1575 s.AddrFrame.Mode = AddrModeFlat;
1577 s.AddrPC.Offset = c->Eip;
1578 s.AddrPC.Mode = AddrModeFlat;
1579 s.AddrFrame.Offset = c->Ebp;
1580 s.AddrFrame.Mode = AddrModeFlat;
1583 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1584 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1585 pSym->MaxNameLength = MAXNAMELEN;
1587 memset( &Line, '\0', sizeof Line );
1588 Line.SizeOfStruct = sizeof Line;
1590 memset( &Module, '\0', sizeof Module );
1591 Module.SizeOfStruct = sizeof Module;
1595 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1597 for ( frameNum = 0; ; ++ frameNum )
1600 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1601 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1602 * ERROR_NOACCESS (998), you can assume that either you are done, or
1603 * that the stack is so hosed that the next deeper frame could not be
1606 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1607 NULL, SymFunctionTableAccess, SymGetModuleBase,
1611 /* display its contents */
1612 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1613 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1614 s.AddrPC.Offset, s.AddrReturn.Offset,
1615 s.AddrFrame.Offset, s.AddrStack.Offset );
1617 if ( s.AddrPC.Offset == 0 )
1619 afsi_log("(-nosymbols- PC == 0)" );
1623 /* show procedure info from a valid PC */
1624 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1626 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1628 afsi_log("SymGetSymFromAddr(): errno = %lu",
1634 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1636 afsi_log("%s", functionName );
1640 afsi_log(" %+ld bytes", (long) offset);
1644 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1646 if (GetLastError() != ERROR_INVALID_ADDRESS)
1648 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1654 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1655 Line.LineNumber, offset);
1659 /* no return address means no deeper stackframe */
1660 if (s.AddrReturn.Offset == 0)
1667 if (GetLastError() != 0)
1669 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1672 SymCleanup(hProcess);
1677 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1678 static DWORD afsd_crtDbgBreaks[256];
1681 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1682 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1683 MINIDUMP_TYPE DumpType,
1684 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1685 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1686 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1697 code = GetEnvironmentVariable("TEMP", tmp, sizeof(tmp));
1698 if ( code == 0 || code > sizeof(tmp) )
1700 if (!GetWindowsDirectory(tmp, sizeof(tmp)))
1704 StringCbPrintfA(wd, sizeof(wd),
1705 "%s\\afsd-%04d-%02d-%02d-%02d_%02d_%02d.dmp", tmp,
1706 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
1707 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1708 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1712 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1714 if (IsDebuggerPresent())
1719 // Generate exception to get proper context in dump
1722 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1724 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1730 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1731 HANDLE hFile = NULL;
1732 HMODULE hDbgHelp = NULL;
1734 hDbgHelp = LoadLibrary("Dbghelp.dll");
1735 if ( hDbgHelp == NULL )
1738 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1739 if ( pMiniDumpWriteDump == NULL ) {
1740 FreeLibrary(hDbgHelp);
1744 hFile = OpenDumpFile();
1751 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1753 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1754 0, KEY_QUERY_VALUE, &parmKey);
1755 if (code == ERROR_SUCCESS) {
1756 dummyLen = sizeof(DWORD);
1757 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1758 (BYTE *) &dwValue, &dummyLen);
1759 if (code == ERROR_SUCCESS)
1760 dwMiniDumpType = dwValue;
1761 RegCloseKey (parmKey);
1764 eInfo.ThreadId = GetCurrentThreadId();
1765 eInfo.ExceptionPointers = ep;
1766 eInfo.ClientPointers = FALSE;
1768 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1769 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1774 FreeLibrary(hDbgHelp);
1778 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1782 BOOL allocRequestBrk = FALSE;
1784 HMODULE hLib = NULL;
1786 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1787 ep->ExceptionRecord->ExceptionCode,
1788 ep->ExceptionRecord->ExceptionAddress);
1791 if (afsd_crtDbgBreakCurrent &&
1792 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1794 allocRequestBrk = TRUE;
1795 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1799 /* save context if we want to print the stack information */
1800 context = *ep->ContextRecord;
1802 afsd_printStack(GetCurrentThread(), &context);
1804 GenerateMiniDump(ep);
1806 hLib = LoadLibrary("Faultrep.dll");
1808 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1810 pReportFault(ep, 0);
1814 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1816 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1819 if (allocRequestBrk)
1821 afsd_crtDbgBreakCurrent++;
1822 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1826 ep->ContextRecord->Eip++;
1828 #if defined(_AMD64_)
1829 ep->ContextRecord->Rip++;
1831 return EXCEPTION_CONTINUE_EXECUTION;
1835 return EXCEPTION_CONTINUE_SEARCH;
1839 void afsd_SetUnhandledExceptionFilter()
1842 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1847 void afsd_DbgBreakAllocInit()
1849 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1850 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1853 void afsd_DbgBreakAdd(DWORD requestNumber)
1856 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1858 if (afsd_crtDbgBreaks[i] == -1)
1863 afsd_crtDbgBreaks[i] = requestNumber;
1865 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);