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(cacheSize);
669 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
670 (BYTE *) &cacheSize, &dummyLen);
671 if (code == ERROR_SUCCESS)
672 afsi_log("Cache size %d", cacheSize);
674 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
675 afsi_log("Default cache size %d", cacheSize);
678 dummyLen = sizeof(logChunkSize);
679 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
680 (BYTE *) &logChunkSize, &dummyLen);
681 if (code == ERROR_SUCCESS) {
682 if (logChunkSize < 12 || logChunkSize > 30) {
683 afsi_log("Invalid chunk size %d, using default",
685 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
688 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
690 cm_logChunkSize = logChunkSize;
691 cm_chunkSize = 1 << logChunkSize;
692 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
694 dummyLen = sizeof(blockSize);
695 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
696 (BYTE *) &blockSize, &dummyLen);
697 if (code == ERROR_SUCCESS) {
699 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
701 afsi_log("Invalid block size %u specified, using default", blockSize);
702 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
705 * if the blockSize is less than 1024 we permit the blockSize to be
706 * specified in multiples of the default blocksize
708 if (blockSize <= 1024)
709 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
712 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
714 if (blockSize > cm_chunkSize) {
715 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
716 blockSize, cm_chunkSize);
717 blockSize = cm_chunkSize;
719 if (cm_chunkSize % blockSize != 0) {
720 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
721 blockSize, cm_chunkSize);
722 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
724 afsi_log("Block size %u", blockSize);
726 dummyLen = sizeof(numBkgD);
727 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
728 (BYTE *) &numBkgD, &dummyLen);
729 if (code == ERROR_SUCCESS) {
730 if (numBkgD > CM_MAX_DAEMONS)
731 numBkgD = CM_MAX_DAEMONS;
732 afsi_log("%d background daemons", numBkgD);
734 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
735 afsi_log("Defaulting to %d background daemons", numBkgD);
738 dummyLen = sizeof(numSvThreads);
739 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
740 (BYTE *) &numSvThreads, &dummyLen);
741 if (code == ERROR_SUCCESS)
742 afsi_log("%d server threads", numSvThreads);
744 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
745 afsi_log("Defaulting to %d server threads", numSvThreads);
748 dummyLen = sizeof(stats);
749 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
750 (BYTE *) &stats, &dummyLen);
751 if (code == ERROR_SUCCESS)
752 afsi_log("Status cache entries: %d", stats);
754 stats = CM_CONFIGDEFAULT_STATS;
755 afsi_log("Default status cache entries: %d", stats);
758 dummyLen = sizeof(volumes);
759 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
760 (BYTE *) &volumes, &dummyLen);
761 if (code == ERROR_SUCCESS)
762 afsi_log("Volumes cache entries: %d", volumes);
764 volumes = CM_CONFIGDEFAULT_STATS / 3;
765 afsi_log("Default volume cache entries: %d", volumes);
768 dummyLen = sizeof(cells);
769 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
770 (BYTE *) &cells, &dummyLen);
771 if (code == ERROR_SUCCESS)
772 afsi_log("Cell cache entries: %d", cells);
774 cells = CM_CONFIGDEFAULT_CELLS;
775 afsi_log("Default cell cache entries: %d", cells);
778 dummyLen = sizeof(ltt);
779 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
780 (BYTE *) <t, &dummyLen);
781 if (code != ERROR_SUCCESS)
783 smb_LogoffTokenTransfer = ltt;
784 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
787 dummyLen = sizeof(ltto);
788 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
789 NULL, NULL, (BYTE *) <to, &dummyLen);
790 if (code != ERROR_SUCCESS)
795 smb_LogoffTransferTimeout = ltto;
796 afsi_log("Logoff token transfer timeout %d seconds", ltto);
798 dummyLen = sizeof(cm_rootVolumeName);
799 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
800 (LPBYTE) cm_rootVolumeName, &dummyLen);
801 if (code == ERROR_SUCCESS)
802 afsi_log("Root volume %s", cm_rootVolumeName);
804 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
805 afsi_log("Default root volume name root.afs");
808 cm_mountRootCLen = sizeof(cm_mountRootC);
809 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
810 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
811 if (code == ERROR_SUCCESS) {
812 afsi_log("Mount root %S", cm_mountRootC);
813 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
815 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
816 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
820 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
821 cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
823 dummyLen = sizeof(buf);
824 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
826 if (code == ERROR_SUCCESS && buf[0]) {
827 if (regType == REG_EXPAND_SZ) {
828 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
829 if (dummyLen > sizeof(cm_CachePath)) {
830 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
831 osi_panic("CachePath too long", __FILE__, __LINE__);
834 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
836 afsi_log("Cache path %s", cm_CachePath);
838 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
839 if (dummyLen > sizeof(cm_CachePath)) {
840 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
841 sizeof(cm_CachePath));
842 osi_panic("CachePath too long", __FILE__, __LINE__);
844 afsi_log("Default cache path %s", cm_CachePath);
847 dummyLen = sizeof(virtualCache);
848 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
849 (LPBYTE)&virtualCache, &dummyLen);
850 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
853 dummyLen = sizeof(cm_ValidateCache);
854 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
855 (LPBYTE)&cm_ValidateCache, &dummyLen);
856 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
857 cm_ValidateCache = 1;
858 switch (cm_ValidateCache) {
860 afsi_log("Cache Validation disabled");
863 afsi_log("Cache Validation on Startup");
866 afsi_log("Cache Validation on Startup and Shutdown");
871 dummyLen = sizeof(traceOnPanic);
872 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
873 (BYTE *) &traceOnPanic, &dummyLen);
874 if (code != ERROR_SUCCESS)
875 traceOnPanic = 1; /* log */
876 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
878 dummyLen = sizeof(reportSessionStartups);
879 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
880 (BYTE *) &reportSessionStartups, &dummyLen);
881 if (code == ERROR_SUCCESS)
882 afsi_log("Session startups %s be recorded in the Event Log",
883 reportSessionStartups ? "will" : "will not");
885 reportSessionStartups = 0;
889 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
890 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
891 cm_sysNameList[i][0] = '\0';
893 cm_sysName = cm_sysNameList[0];
897 clientchar_t * cbuf = (clientchar_t *) buf;
898 dummyLen = sizeof(buf);
899 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
900 if (code != ERROR_SUCCESS || !cbuf[0]) {
902 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
903 #elif defined(_AMD64_)
904 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
905 #else /* assume x86 32-bit */
906 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
909 afsi_log("Sys name %S", cbuf);
911 /* breakup buf into individual search string entries */
912 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
913 if (*p == '\0' || iswspace(*p)) {
914 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
915 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
921 } while (*p == '\0' || isspace(*p));
928 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
930 dummyLen = sizeof(cryptall);
931 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
932 (BYTE *) &cryptall, &dummyLen);
933 if (code == ERROR_SUCCESS) {
934 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
937 afsi_log("Default SecurityLevel is clear");
941 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
942 else if (cryptall == 2)
943 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
945 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
947 dummyLen = sizeof(cryptall);
948 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
949 (BYTE *) &cm_anonvldb, &dummyLen);
950 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
952 dummyLen = sizeof(cm_dnsEnabled);
953 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
954 (BYTE *) &cm_dnsEnabled, &dummyLen);
955 if (code == ERROR_SUCCESS) {
956 afsi_log("DNS %s be used to find AFS cell servers",
957 cm_dnsEnabled ? "will" : "will not");
960 cm_dnsEnabled = 1; /* default on */
961 afsi_log("Default to use DNS to find AFS cell servers");
964 #ifdef AFS_FREELANCE_CLIENT
965 dummyLen = sizeof(cm_freelanceEnabled);
966 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
967 (BYTE *) &cm_freelanceEnabled, &dummyLen);
968 if (code == ERROR_SUCCESS) {
969 afsi_log("Freelance client feature %s activated",
970 cm_freelanceEnabled ? "is" : "is not");
973 cm_freelanceEnabled = 1; /* default on */
975 #endif /* AFS_FREELANCE_CLIENT */
977 dummyLen = sizeof(smb_UseUnicode);
978 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
979 (BYTE *) &smb_UseUnicode, &dummyLen);
980 if (code != ERROR_SUCCESS) {
981 smb_UseUnicode = 1; /* default on */
983 afsi_log("SMB Server Unicode Support is %s",
984 smb_UseUnicode ? "enabled" : "disabled");
986 dummyLen = sizeof(smb_hideDotFiles);
987 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
988 (BYTE *) &smb_hideDotFiles, &dummyLen);
989 if (code != ERROR_SUCCESS) {
990 smb_hideDotFiles = 1; /* default on */
992 afsi_log("Dot files/dirs will %sbe marked hidden",
993 smb_hideDotFiles ? "" : "not ");
995 dummyLen = sizeof(dwValue);
996 code = RegQueryValueEx(parmKey, "UnixModeFileDefault", NULL, NULL,
997 (BYTE *) &dwValue, &dummyLen);
998 if (code == ERROR_SUCCESS) {
999 smb_unixModeDefaultFile = (dwValue & 07777);
1001 afsi_log("Default unix mode bits for files is 0%04o", smb_unixModeDefaultFile);
1003 dummyLen = sizeof(dwValue);
1004 code = RegQueryValueEx(parmKey, "UnixModeDirDefault", NULL, NULL,
1005 (BYTE *) &dwValue, &dummyLen);
1006 if (code == ERROR_SUCCESS) {
1007 smb_unixModeDefaultDir = (dwValue & 07777);
1009 afsi_log("Default unix mode bits for directories is 0%04o", smb_unixModeDefaultDir);
1011 dummyLen = sizeof(smb_maxMpxRequests);
1012 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1013 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1014 if (code != ERROR_SUCCESS) {
1015 smb_maxMpxRequests = 50;
1017 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1019 dummyLen = sizeof(smb_maxVCPerServer);
1020 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1021 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1022 if (code != ERROR_SUCCESS) {
1023 smb_maxVCPerServer = 100;
1025 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1027 dummyLen = sizeof(smb_authType);
1028 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1029 (BYTE *) &smb_authType, &dummyLen);
1031 if (code != ERROR_SUCCESS ||
1032 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1033 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1035 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1037 dummyLen = sizeof(rx_max_rwin_size);
1038 code = RegQueryValueEx(parmKey, "RxMaxRecvWinSize", NULL, NULL,
1039 (BYTE *) &rx_max_rwin_size, &dummyLen);
1040 if (code == ERROR_SUCCESS)
1041 rx_SetMaxReceiveWindow(rx_max_rwin_size);
1042 afsi_log("Rx Maximum Receive Window Size is %d", rx_GetMaxReceiveWindow());
1044 dummyLen = sizeof(rx_max_swin_size);
1045 code = RegQueryValueEx(parmKey, "RxMaxSendWinSize", NULL, NULL,
1046 (BYTE *) &rx_max_swin_size, &dummyLen);
1047 if (code == ERROR_SUCCESS)
1048 rx_SetMaxSendWindow(rx_max_swin_size);
1049 afsi_log("Rx Maximum Send Window Size is %d", rx_GetMaxSendWindow());
1051 dummyLen = sizeof(rx_min_peer_timeout);
1052 code = RegQueryValueEx(parmKey, "RxMinPeerTimeout", NULL, NULL,
1053 (BYTE *) &rx_min_peer_timeout, &dummyLen);
1054 if (code == ERROR_SUCCESS)
1055 rx_SetMinPeerTimeout(rx_min_peer_timeout);
1056 afsi_log("Rx Minimum Peer Timeout is %d ms", rx_GetMinPeerTimeout());
1058 dummyLen = sizeof(rx_nojumbo);
1059 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1060 (BYTE *) &rx_nojumbo, &dummyLen);
1061 if (code != ERROR_SUCCESS) {
1063 dummyLen = sizeof(jumbo);
1064 code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
1065 (BYTE *) &jumbo, &dummyLen);
1066 if (code != ERROR_SUCCESS) {
1069 rx_nojumbo = !jumbo;
1073 afsi_log("RX Jumbograms are disabled");
1075 afsi_log("RX Jumbograms are enabled");
1077 dummyLen = sizeof(rx_extraPackets);
1078 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1079 (BYTE *) &rx_extraPackets, &dummyLen);
1080 if (code != ERROR_SUCCESS) {
1081 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
1083 if (rx_extraPackets)
1084 afsi_log("RX extraPackets is %d", rx_extraPackets);
1086 dummyLen = sizeof(rx_udpbufsize);
1087 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
1088 (BYTE *) &rx_udpbufsize, &dummyLen);
1089 if (code != ERROR_SUCCESS) {
1090 rx_udpbufsize = 256*1024;
1092 if (rx_udpbufsize != -1)
1093 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
1095 dummyLen = sizeof(rx_mtu);
1096 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1097 (BYTE *) &rx_mtu, &dummyLen);
1098 if (code != ERROR_SUCCESS || !rx_mtu) {
1102 afsi_log("RX maximum MTU is %d", rx_mtu);
1104 dummyLen = sizeof(rx_enable_peer_stats);
1105 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1106 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1107 if (code != ERROR_SUCCESS) {
1108 rx_enable_peer_stats = 1;
1110 if (rx_enable_peer_stats)
1111 afsi_log("RX Peer Statistics gathering is enabled");
1113 afsi_log("RX Peer Statistics gathering is disabled");
1115 dummyLen = sizeof(rx_enable_process_stats);
1116 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1117 (BYTE *) &rx_enable_process_stats, &dummyLen);
1118 if (code != ERROR_SUCCESS) {
1119 rx_enable_process_stats = 1;
1121 if (rx_enable_process_stats)
1122 afsi_log("RX Process Statistics gathering is enabled");
1124 afsi_log("RX Process Statistics gathering is disabled");
1126 dummyLen = sizeof(dwValue);
1128 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1129 (BYTE *) &dwValue, &dummyLen);
1130 if (code != ERROR_SUCCESS || dwValue != 0) {
1131 rx_EnableHotThread();
1132 afsi_log("RX Hot Thread is enabled");
1135 afsi_log("RX Hot Thread is disabled");
1137 dummyLen = sizeof(DWORD);
1138 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1139 (BYTE *) &dwValue, &dummyLen);
1140 if (code == ERROR_SUCCESS) {
1141 cm_callbackport = (unsigned short) dwValue;
1143 afsi_log("CM CallBackPort is %u", cm_callbackport);
1145 dummyLen = sizeof(DWORD);
1146 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1147 (BYTE *) &dwValue, &dummyLen);
1148 if (code == ERROR_SUCCESS) {
1149 cm_enableServerLocks = (unsigned short) dwValue;
1151 switch (cm_enableServerLocks) {
1153 afsi_log("EnableServerLocks: never");
1156 afsi_log("EnableServerLocks: always");
1160 afsi_log("EnableServerLocks: server requested");
1164 dummyLen = sizeof(DWORD);
1165 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1166 (BYTE *) &dwValue, &dummyLen);
1167 if (code == ERROR_SUCCESS) {
1168 cm_deleteReadOnly = (unsigned short) dwValue;
1170 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1173 dummyLen = sizeof(DWORD);
1174 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1175 (BYTE *) &dwValue, &dummyLen);
1176 if (code == ERROR_SUCCESS) {
1177 cm_BPlusTrees = (unsigned short) dwValue;
1179 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1181 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1183 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1186 afsi_log("CM BPlusTrees is not supported");
1189 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1190 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1191 (regType == REG_MULTI_SZ))
1194 dummyLen += 3; /* in case the source string is not nul terminated */
1195 pSz = malloc(dummyLen);
1196 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1197 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1198 (regType == REG_MULTI_SZ))
1203 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1205 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1207 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1208 smb_ExecutableExtensions[cnt] = p;
1209 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1211 smb_ExecutableExtensions[cnt] = NULL;
1214 if (!smb_ExecutableExtensions)
1217 if (!smb_ExecutableExtensions)
1218 afsi_log("No PrefetchExecutableExtensions");
1220 dummyLen = sizeof(DWORD);
1221 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1222 (BYTE *) &dwValue, &dummyLen);
1223 if (code == ERROR_SUCCESS) {
1224 cm_OfflineROIsValid = (unsigned short) dwValue;
1226 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1228 dummyLen = sizeof(DWORD);
1229 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1230 (BYTE *) &dwValue, &dummyLen);
1231 if (code == ERROR_SUCCESS) {
1232 cm_giveUpAllCBs = (unsigned short) dwValue;
1234 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1236 dummyLen = sizeof(DWORD);
1237 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1238 (BYTE *) &dwValue, &dummyLen);
1239 if (code == ERROR_SUCCESS) {
1240 cm_followBackupPath = (unsigned short) dwValue;
1242 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1244 dummyLen = sizeof(DWORD);
1245 code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
1246 (BYTE *) &dwValue, &dummyLen);
1247 if (code == ERROR_SUCCESS) {
1248 cm_accessPerFileCheck = (int) dwValue;
1250 afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
1252 dummyLen = sizeof(DWORD);
1253 code = RegQueryValueEx(parmKey, "ReadOnlyVolumeVersioning", NULL, NULL,
1254 (BYTE *) &dwValue, &dummyLen);
1255 if (code == ERROR_SUCCESS) {
1256 cm_readonlyVolumeVersioning = (unsigned short) dwValue;
1258 afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
1260 RegCloseKey (parmKey);
1262 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1264 /* get network related info */
1265 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1266 code = syscfg_GetIFInfo(&cm_noIPAddr,
1267 cm_IPAddr, cm_SubnetMask,
1268 cm_NetMtu, cm_NetFlags);
1270 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1271 afsi_log("syscfg_GetIFInfo error code %d", code);
1273 afsi_log("First Network address %x SubnetMask %x",
1274 cm_IPAddr[0], cm_SubnetMask[0]);
1277 * Save client configuration for GetCacheConfig requests
1279 cm_initParams.nChunkFiles = 0;
1280 cm_initParams.nStatCaches = stats;
1281 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1282 cm_initParams.nVolumeCaches = volumes;
1283 cm_initParams.firstChunkSize = cm_chunkSize;
1284 cm_initParams.otherChunkSize = cm_chunkSize;
1285 cm_initParams.cacheSize = cacheSize;
1286 cm_initParams.setTime = 0;
1287 cm_initParams.memCache = 1;
1289 /* init user daemon, and other packages */
1302 cm_InitNormalization();
1304 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1305 afsi_log("cm_InitMappedMemory code %x", code);
1307 *reasonP = "error initializing cache file";
1311 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1312 if (cm_InitDNS(cm_dnsEnabled) == -1)
1313 cm_dnsEnabled = 0; /* init failed, so deactivate */
1314 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1317 /* Set RX parameters before initializing RX */
1320 afsi_log("rx_SetNoJumbo successful");
1323 if ( rx_mtu != -1 ) {
1324 extern void rx_SetMaxMTU(int);
1326 rx_SetMaxMTU(rx_mtu);
1327 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1330 if ( rx_udpbufsize != -1 ) {
1331 rx_SetUdpBufSize(rx_udpbufsize);
1332 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1335 /* initialize RX, and tell it to listen to the callbackport,
1336 * which is used for callback RPC messages.
1338 code = rx_Init(htons(cm_callbackport));
1340 afsi_log("rx_Init code %x - retrying with a random port number", code);
1343 afsi_log("rx_Init code %x", code);
1345 *reasonP = "afsd: failed to init rx client";
1349 /* create an unauthenticated service #1 for callbacks */
1350 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1351 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1352 RXAFSCB_ExecuteRequest);
1353 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1354 if (serverp == NULL) {
1355 *reasonP = "unknown error";
1358 rx_SetMinProcs(serverp, 2);
1359 rx_SetMaxProcs(serverp, 4);
1360 rx_SetCheckReach(serverp, 1);
1362 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1363 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1364 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1365 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1366 if (serverp == NULL) {
1367 *reasonP = "unknown error";
1370 rx_SetMinProcs(serverp, 2);
1371 rx_SetMaxProcs(serverp, 4);
1373 /* start server threads, *not* donating this one to the pool */
1375 afsi_log("rx_StartServer");
1377 if (rx_enable_peer_stats)
1378 rx_enablePeerRPCStats();
1380 if (rx_enable_process_stats)
1381 rx_enableProcessRPCStats();
1383 code = cm_GetRootCellName(rootCellName);
1384 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1385 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1386 if (code != 0 && !cm_freelanceEnabled)
1388 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1391 else if (cm_freelanceEnabled)
1392 cm_data.rootCellp = NULL;
1394 if (code == 0 && !cm_freelanceEnabled)
1396 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1397 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1398 if (cm_data.rootCellp == NULL)
1400 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1405 #ifdef AFS_FREELANCE_CLIENT
1406 if (cm_freelanceEnabled)
1410 /* Initialize the RPC server for session keys */
1413 /* Initialize the RPC server for pipe services */
1416 afsd_InitServerPreferences();
1418 code = afsd_InitRoot(reasonP);
1423 int afsd_ShutdownCM(void)
1427 cm_ReleaseSCache(cm_data.rootSCachep);
1436 int afsd_InitDaemons(char **reasonP)
1438 cm_InitDaemon(numBkgD);
1439 afsi_log("cm_InitDaemon complete");
1444 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1451 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1452 0, KEY_QUERY_VALUE, &parmKey);
1453 if (code == ERROR_SUCCESS) {
1454 dummyLen = sizeof(DWORD);
1455 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1456 (BYTE *) &dwValue, &dummyLen);
1457 if (code == ERROR_SUCCESS)
1458 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1459 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1461 dummyLen = sizeof(DWORD);
1462 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1463 (BYTE *) &dwValue, &dummyLen);
1464 if (code == ERROR_SUCCESS)
1465 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1466 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1468 dummyLen = sizeof(DWORD);
1469 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1470 (BYTE *) &dwValue, &dummyLen);
1471 if (code == ERROR_SUCCESS) {
1472 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1473 if (dwValue > cm_chunkSize)
1474 smb_AsyncStoreSize = cm_chunkSize;
1475 else if (dwValue < cm_data.buf_blockSize)
1476 smb_AsyncStoreSize = cm_data.buf_blockSize;
1478 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1480 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1481 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1483 RegCloseKey (parmKey);
1486 /* Do this last so that we don't handle requests before init is done.
1487 * Here we initialize the SMB listener.
1489 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1490 afsi_log("smb_Init complete");
1503 #pragma pack( push, before_imagehlp, 8 )
1504 #include <imagehlp.h>
1505 #pragma pack( pop, before_imagehlp )
1507 #define MAXNAMELEN 1024
1509 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1511 HANDLE hProcess = GetCurrentProcess();
1513 #if defined(_AMD64_)
1515 #elif defined(_X86_)
1519 char functionName[MAXNAMELEN];
1521 IMAGEHLP_MODULE Module;
1525 IMAGEHLP_SYMBOL *pSym;
1527 afsi_log_useTimestamp = 0;
1529 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1531 memset( &s, '\0', sizeof s );
1532 if (!SymInitialize(hProcess, NULL, 1) )
1534 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1536 SymCleanup( hProcess );
1542 symOptions = SymGetOptions();
1543 symOptions |= SYMOPT_LOAD_LINES;
1544 symOptions &= ~SYMOPT_UNDNAME;
1545 SymSetOptions( symOptions );
1548 * init STACKFRAME for first call
1549 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1550 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1551 * and good riddance.
1553 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1554 #error The STACKFRAME initialization in afsd_printStack() for this platform
1555 #error must be properly configured
1556 #elif defined(_AMD64_)
1557 s.AddrPC.Offset = c->Rip;
1558 s.AddrPC.Mode = AddrModeFlat;
1559 s.AddrFrame.Offset = c->Rbp;
1560 s.AddrFrame.Mode = AddrModeFlat;
1562 s.AddrPC.Offset = c->Eip;
1563 s.AddrPC.Mode = AddrModeFlat;
1564 s.AddrFrame.Offset = c->Ebp;
1565 s.AddrFrame.Mode = AddrModeFlat;
1568 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1569 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1570 pSym->MaxNameLength = MAXNAMELEN;
1572 memset( &Line, '\0', sizeof Line );
1573 Line.SizeOfStruct = sizeof Line;
1575 memset( &Module, '\0', sizeof Module );
1576 Module.SizeOfStruct = sizeof Module;
1580 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1582 for ( frameNum = 0; ; ++ frameNum )
1585 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1586 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1587 * ERROR_NOACCESS (998), you can assume that either you are done, or
1588 * that the stack is so hosed that the next deeper frame could not be
1591 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1592 NULL, SymFunctionTableAccess, SymGetModuleBase,
1596 /* display its contents */
1597 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1598 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1599 s.AddrPC.Offset, s.AddrReturn.Offset,
1600 s.AddrFrame.Offset, s.AddrStack.Offset );
1602 if ( s.AddrPC.Offset == 0 )
1604 afsi_log("(-nosymbols- PC == 0)" );
1608 /* show procedure info from a valid PC */
1609 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1611 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1613 afsi_log("SymGetSymFromAddr(): errno = %lu",
1619 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1621 afsi_log("%s", functionName );
1625 afsi_log(" %+ld bytes", (long) offset);
1629 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1631 if (GetLastError() != ERROR_INVALID_ADDRESS)
1633 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1639 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1640 Line.LineNumber, offset);
1644 /* no return address means no deeper stackframe */
1645 if (s.AddrReturn.Offset == 0)
1652 if (GetLastError() != 0)
1654 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1657 SymCleanup(hProcess);
1662 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1663 static DWORD afsd_crtDbgBreaks[256];
1666 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1667 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1668 MINIDUMP_TYPE DumpType,
1669 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1670 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1671 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1680 code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
1681 if ( code == 0 || code > sizeof(wd) )
1683 if (!GetWindowsDirectory(wd, sizeof(wd)))
1686 StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
1687 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1688 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1692 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1694 if (IsDebuggerPresent())
1699 // Generate exception to get proper context in dump
1702 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1704 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1710 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1711 HANDLE hFile = NULL;
1712 HMODULE hDbgHelp = NULL;
1714 hDbgHelp = LoadLibrary("Dbghelp.dll");
1715 if ( hDbgHelp == NULL )
1718 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1719 if ( pMiniDumpWriteDump == NULL ) {
1720 FreeLibrary(hDbgHelp);
1724 hFile = OpenDumpFile();
1731 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1733 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1734 0, KEY_QUERY_VALUE, &parmKey);
1735 if (code == ERROR_SUCCESS) {
1736 dummyLen = sizeof(DWORD);
1737 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1738 (BYTE *) &dwValue, &dummyLen);
1739 if (code == ERROR_SUCCESS)
1740 dwMiniDumpType = dwValue;
1741 RegCloseKey (parmKey);
1744 eInfo.ThreadId = GetCurrentThreadId();
1745 eInfo.ExceptionPointers = ep;
1746 eInfo.ClientPointers = FALSE;
1748 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1749 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1754 FreeLibrary(hDbgHelp);
1758 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1762 BOOL allocRequestBrk = FALSE;
1764 HMODULE hLib = NULL;
1766 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1767 ep->ExceptionRecord->ExceptionCode,
1768 ep->ExceptionRecord->ExceptionAddress);
1771 if (afsd_crtDbgBreakCurrent &&
1772 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1774 allocRequestBrk = TRUE;
1775 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1779 /* save context if we want to print the stack information */
1780 context = *ep->ContextRecord;
1782 afsd_printStack(GetCurrentThread(), &context);
1784 GenerateMiniDump(ep);
1786 hLib = LoadLibrary("Faultrep.dll");
1788 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1790 pReportFault(ep, 0);
1794 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1796 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1799 if (allocRequestBrk)
1801 afsd_crtDbgBreakCurrent++;
1802 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1806 ep->ContextRecord->Eip++;
1808 #if defined(_AMD64_)
1809 ep->ContextRecord->Rip++;
1811 return EXCEPTION_CONTINUE_EXECUTION;
1815 return EXCEPTION_CONTINUE_SEARCH;
1819 void afsd_SetUnhandledExceptionFilter()
1822 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1827 void afsd_DbgBreakAllocInit()
1829 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1830 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1833 void afsd_DbgBreakAdd(DWORD requestNumber)
1836 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1838 if (afsd_crtDbgBreaks[i] == -1)
1843 afsd_crtDbgBreaks[i] = requestNumber;
1845 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);