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;
85 char cm_HostName[200];
87 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
89 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "NOT.YET.SET";
90 clientchar_t cm_NetbiosNameC[MAX_NB_NAME_LENGTH] = _C("NOT.YET.SET");
92 char cm_CachePath[MAX_PATH];
93 DWORD cm_ValidateCache = 1;
95 BOOL reportSessionStartups = FALSE;
97 cm_initparams_v1 cm_initParams;
99 clientchar_t *cm_sysName = 0;
100 unsigned int cm_sysNameCount = 0;
101 clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
103 DWORD TraceOption = 0;
106 * AFSD Initialization Log
108 * This is distinct from the regular debug logging facility.
109 * Log items go directly to a file, not to an array in memory, so that even
110 * if AFSD crashes, the log can be inspected.
116 int cm_dnsEnabled = 1;
120 static int afsi_log_useTimestamp = 1;
123 afsi_log(char *pattern, ...)
125 char s[256], t[100], d[100], u[512];
128 va_start(ap, pattern);
130 StringCbVPrintfA(s, sizeof(s), pattern, ap);
131 if ( afsi_log_useTimestamp ) {
132 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
133 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
134 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
135 if (afsi_file != INVALID_HANDLE_VALUE)
136 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
141 if (afsi_file != INVALID_HANDLE_VALUE)
142 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
150 char t[100], u[100], *p, *path;
156 DWORD maxLogSize = 100 * 1024;
158 afsi_file = INVALID_HANDLE_VALUE;
159 code = GetTempPath(sizeof(wd)-15, wd);
160 if ( code == 0 || code > (sizeof(wd)-15) )
161 return; /* unable to create a log */
163 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
164 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
165 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
166 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
168 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
169 0, KEY_QUERY_VALUE, &parmKey);
170 if (code == ERROR_SUCCESS) {
171 dummyLen = sizeof(maxLogSize);
172 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
173 (BYTE *) &maxLogSize, &dummyLen);
174 RegCloseKey (parmKey);
178 dwLow = GetFileSize( afsi_file, &dwHigh );
179 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
180 CloseHandle(afsi_file);
181 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
182 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
186 SetFilePointer(afsi_file, 0, NULL, FILE_END);
187 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
188 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
189 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
190 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
191 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
193 code = GetEnvironmentVariable("PATH", NULL, 0);
195 code = GetEnvironmentVariable("PATH", path, code);
196 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
197 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
198 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
201 /* Initialize C RTL Code Page conversion functions */
202 /* All of the path info obtained from the SMB client is in the OEM code page */
203 afsi_log("OEM Code Page = %d", GetOEMCP());
204 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
206 /* Two things to look into. First, should mbstowcs() be performing
207 * character set translations from OEM to Unicode in smb3.c;
208 * Second, do we need to set this translation in each function
209 * due to multi-threading.
211 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
212 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
217 * Standard AFSD trace
220 void afsd_ForceTrace(BOOL flush)
229 len = GetTempPath(sizeof(buf)-10, buf);
230 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
231 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
232 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
233 if (handle == INVALID_HANDLE_VALUE) {
235 osi_panic("Cannot create log file", __FILE__, __LINE__);
237 osi_LogPrint(afsd_logp, handle);
239 FlushFileBuffers(handle);
243 static void afsd_InitServerPreferences(void)
246 DWORD dwType, dwSize;
250 DWORD dwHostSize = 256;
252 struct sockaddr_in saddr;
255 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
256 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
258 KEY_READ|KEY_QUERY_VALUE,
259 &hkPrefs) == ERROR_SUCCESS) {
261 RegQueryInfoKey( hkPrefs,
264 NULL, /* lpReserved */
265 NULL, /* lpcSubKeys */
266 NULL, /* lpcMaxSubKeyLen */
267 NULL, /* lpcMaxClassLen */
268 &dwPrefs, /* lpcValues */
269 NULL, /* lpcMaxValueNameLen */
270 NULL, /* lpcMaxValueLen */
271 NULL, /* lpcbSecurityDescriptor */
272 NULL /* lpftLastWriteTime */
275 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
277 dwSize = sizeof(DWORD);
280 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
281 &dwType, (LPBYTE)&dwRank, &dwSize))
283 afsi_log("RegEnumValue(hkPrefs) failed");
287 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
289 if (isdigit(szHost[0]))
291 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
295 if ((pEntry = gethostbyname (szHost)) == NULL)
298 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
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 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
308 /* set preferences for an existing vlserver */
309 cm_ChangeRankCellVLServer(tsp);
310 cm_PutServer(tsp); /* decrease refcount */
312 else /* add a new server without a cell */
314 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
315 tsp->ipRank = (USHORT)dwRank;
319 RegCloseKey(hkPrefs);
322 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
323 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\File",
325 KEY_READ|KEY_QUERY_VALUE,
326 &hkPrefs) == ERROR_SUCCESS) {
328 RegQueryInfoKey( hkPrefs,
331 NULL, /* lpReserved */
332 NULL, /* lpcSubKeys */
333 NULL, /* lpcMaxSubKeyLen */
334 NULL, /* lpcMaxClassLen */
335 &dwPrefs, /* lpcValues */
336 NULL, /* lpcMaxValueNameLen */
337 NULL, /* lpcMaxValueLen */
338 NULL, /* lpcbSecurityDescriptor */
339 NULL /* lpftLastWriteTime */
342 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
344 dwSize = sizeof(DWORD);
347 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
348 &dwType, (LPBYTE)&dwRank, &dwSize))
350 afsi_log("RegEnumValue(hkPrefs) failed");
354 afsi_log("File Server Preference: %s = %d",szHost, dwRank);
356 if (isdigit(szHost[0]))
358 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
362 if ((pEntry = gethostbyname (szHost)) == NULL)
365 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
367 saddr.sin_family = AF_INET;
368 dwRank += (rand() & 0x000f);
370 tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
371 if ( tsp ) /* an existing server - ref count increased */
373 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
375 /* find volumes which might have RO copy
376 /* on server and change the ordering of
379 cm_ChangeRankVolume(tsp);
380 cm_PutServer(tsp); /* decrease refcount */
382 else /* add a new server without a cell */
384 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
385 tsp->ipRank = (USHORT)dwRank;
389 RegCloseKey(hkPrefs);
395 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
400 static BOOL bChecked = FALSE;
401 static BOOL bIsWow64 = FALSE;
406 LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
408 h1 = GetModuleHandle("kernel32.dll");
410 (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process");
412 /* If we don't find the fnIsWow64Process function then we
413 * are not running in a broken Wow64
415 if (fnIsWow64Process)
416 fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
426 * AFSD Initialization
429 int afsd_InitCM(char **reasonP)
432 afs_uint64 cacheBlocks;
440 DWORD rx_enable_peer_stats;
441 DWORD rx_enable_process_stats;
442 DWORD rx_udpbufsize = -1;
443 DWORD lockOrderValidation;
448 long virtualCache = 0;
449 fschar_t rootCellName[256];
450 struct rx_service *serverp;
451 static struct rx_securityClass *nullServerSecurityClassp;
459 /*int freelanceEnabled;*/
462 int cm_noIPAddr; /* number of client network interfaces */
463 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
464 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
465 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
466 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
469 WSAStartup(0x0101, &WSAjunk);
471 init_et_to_sys_error();
473 /* setup osidebug server at RPC slot 1000 */
474 osi_LongToUID(1000, &debugID);
475 code = osi_InitDebug(&debugID);
476 afsi_log("osi_InitDebug code %d", code);
481 *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment";
486 // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
488 if (code == RPC_S_NO_PROTSEQS)
489 *reasonP = "No RPC Protocol Sequences registered. Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
491 *reasonP = "unknown error";
496 gethostname(cm_HostName, sizeof(cm_HostName));
497 afsi_log("gethostname %s", cm_HostName);
498 thp = gethostbyname(cm_HostName);
499 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
501 /* seed random number generator */
502 srand(ntohl(cm_HostAddr));
504 /* Look up configuration parameters in Registry */
505 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
506 0, KEY_QUERY_VALUE, &parmKey);
507 if (code != ERROR_SUCCESS) {
508 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
509 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
510 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
511 StringCbPrintfA(buf, sizeof(buf),
512 "Failure in configuration while opening Registry: %s",
514 osi_panic(buf, __FILE__, __LINE__);
517 dummyLen = sizeof(dwPriority);
518 code = RegQueryValueEx(parmKey, "PriorityClass", NULL, NULL,
519 (BYTE *) &dwPriority, &dummyLen);
520 if (code != ERROR_SUCCESS || dwPriority == 0) {
521 dwPriority = HIGH_PRIORITY_CLASS;
523 if (dwPriority != GetPriorityClass(GetCurrentProcess()))
524 SetPriorityClass(GetCurrentProcess(), dwPriority);
525 afsi_log("PriorityClass 0x%x", GetPriorityClass(GetCurrentProcess()));
527 dummyLen = sizeof(lockOrderValidation);
528 code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
529 (BYTE *) &lockOrderValidation, &dummyLen);
530 if (code != ERROR_SUCCESS) {
532 lockOrderValidation = 1;
534 lockOrderValidation = 0;
537 osi_SetLockOrderValidation(lockOrderValidation);
538 afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
540 dummyLen = sizeof(maxcpus);
541 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
542 (BYTE *) &maxcpus, &dummyLen);
543 if (code == ERROR_SUCCESS) {
545 DWORD_PTR processAffinityMask, systemAffinityMask;
547 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
548 FALSE, GetCurrentProcessId());
549 if ( hProcess != NULL &&
550 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
553 DWORD_PTR mask, newAffinityMask;
560 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
561 if ( processAffinityMask & mask ) {
562 newAffinityMask |= mask;
568 SetProcessAffinityMask(hProcess, newAffinityMask);
569 CloseHandle(hProcess);
570 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
572 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
576 dummyLen = sizeof(TraceOption);
577 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
578 (BYTE *) &TraceOption, &dummyLen);
579 afsi_log("Trace Options = %lX", TraceOption);
581 dummyLen = sizeof(traceBufSize);
582 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
583 (BYTE *) &traceBufSize, &dummyLen);
584 if (code == ERROR_SUCCESS)
585 afsi_log("Trace Buffer size %d", traceBufSize);
587 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
588 afsi_log("Default trace buffer size %d", traceBufSize);
591 /* setup and enable debug log */
592 afsd_logp = osi_LogCreate("afsd", traceBufSize);
593 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
594 if ((TraceOption & 0x8)
599 osi_LogEnable(afsd_logp);
603 osi_Log0(afsd_logp, "Log init");
605 dummyLen = sizeof(cacheSize);
606 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
607 (BYTE *) &cacheSize, &dummyLen);
608 if (code == ERROR_SUCCESS)
609 afsi_log("Cache size %d", cacheSize);
611 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
612 afsi_log("Default cache size %d", cacheSize);
615 dummyLen = sizeof(logChunkSize);
616 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
617 (BYTE *) &logChunkSize, &dummyLen);
618 if (code == ERROR_SUCCESS) {
619 if (logChunkSize < 12 || logChunkSize > 30) {
620 afsi_log("Invalid chunk size %d, using default",
622 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
625 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
627 cm_logChunkSize = logChunkSize;
628 cm_chunkSize = 1 << logChunkSize;
629 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
631 dummyLen = sizeof(blockSize);
632 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
633 (BYTE *) &blockSize, &dummyLen);
634 if (code == ERROR_SUCCESS) {
636 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
638 afsi_log("Invalid block size %u specified, using default", blockSize);
639 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
642 * if the blockSize is less than 1024 we permit the blockSize to be
643 * specified in multiples of the default blocksize
645 if (blockSize <= 1024)
646 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
649 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
651 if (blockSize > cm_chunkSize) {
652 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
653 blockSize, cm_chunkSize);
654 blockSize = cm_chunkSize;
656 if (cm_chunkSize % blockSize != 0) {
657 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
658 blockSize, cm_chunkSize);
659 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
661 afsi_log("Block size %u", blockSize);
663 dummyLen = sizeof(numBkgD);
664 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
665 (BYTE *) &numBkgD, &dummyLen);
666 if (code == ERROR_SUCCESS) {
667 if (numBkgD > CM_MAX_DAEMONS)
668 numBkgD = CM_MAX_DAEMONS;
669 afsi_log("%d background daemons", numBkgD);
671 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
672 afsi_log("Defaulting to %d background daemons", numBkgD);
675 dummyLen = sizeof(numSvThreads);
676 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
677 (BYTE *) &numSvThreads, &dummyLen);
678 if (code == ERROR_SUCCESS)
679 afsi_log("%d server threads", numSvThreads);
681 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
682 afsi_log("Defaulting to %d server threads", numSvThreads);
685 dummyLen = sizeof(stats);
686 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
687 (BYTE *) &stats, &dummyLen);
688 if (code == ERROR_SUCCESS)
689 afsi_log("Status cache entries: %d", stats);
691 stats = CM_CONFIGDEFAULT_STATS;
692 afsi_log("Default status cache entries: %d", stats);
695 dummyLen = sizeof(volumes);
696 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
697 (BYTE *) &volumes, &dummyLen);
698 if (code == ERROR_SUCCESS)
699 afsi_log("Volumes cache entries: %d", volumes);
701 volumes = CM_CONFIGDEFAULT_STATS / 3;
702 afsi_log("Default volume cache entries: %d", volumes);
705 dummyLen = sizeof(cells);
706 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
707 (BYTE *) &cells, &dummyLen);
708 if (code == ERROR_SUCCESS)
709 afsi_log("Cell cache entries: %d", cells);
711 cells = CM_CONFIGDEFAULT_CELLS;
712 afsi_log("Default cell cache entries: %d", cells);
715 dummyLen = sizeof(ltt);
716 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
717 (BYTE *) <t, &dummyLen);
718 if (code != ERROR_SUCCESS)
720 smb_LogoffTokenTransfer = ltt;
721 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
724 dummyLen = sizeof(ltto);
725 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
726 NULL, NULL, (BYTE *) <to, &dummyLen);
727 if (code != ERROR_SUCCESS)
732 smb_LogoffTransferTimeout = ltto;
733 afsi_log("Logoff token transfer timeout %d seconds", ltto);
735 dummyLen = sizeof(cm_rootVolumeName);
736 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
737 (LPBYTE) cm_rootVolumeName, &dummyLen);
738 if (code == ERROR_SUCCESS)
739 afsi_log("Root volume %s", cm_rootVolumeName);
741 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
742 afsi_log("Default root volume name root.afs");
745 cm_mountRootCLen = sizeof(cm_mountRootC);
746 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
747 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
748 if (code == ERROR_SUCCESS) {
749 afsi_log("Mount root %S", cm_mountRootC);
750 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
752 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
753 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
757 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
758 cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
760 dummyLen = sizeof(buf);
761 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
763 if (code == ERROR_SUCCESS && buf[0]) {
764 if (regType == REG_EXPAND_SZ) {
765 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
766 if (dummyLen > sizeof(cm_CachePath)) {
767 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
768 osi_panic("CachePath too long", __FILE__, __LINE__);
771 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
773 afsi_log("Cache path %s", cm_CachePath);
775 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
776 if (dummyLen > sizeof(cm_CachePath)) {
777 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
778 sizeof(cm_CachePath));
779 osi_panic("CachePath too long", __FILE__, __LINE__);
781 afsi_log("Default cache path %s", cm_CachePath);
784 dummyLen = sizeof(virtualCache);
785 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
786 (LPBYTE)&virtualCache, &dummyLen);
787 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
790 dummyLen = sizeof(cm_ValidateCache);
791 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
792 (LPBYTE)&cm_ValidateCache, &dummyLen);
793 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
794 cm_ValidateCache = 1;
795 switch (cm_ValidateCache) {
797 afsi_log("Cache Validation disabled");
800 afsi_log("Cache Validation on Startup");
803 afsi_log("Cache Validation on Startup and Shutdown");
808 dummyLen = sizeof(traceOnPanic);
809 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
810 (BYTE *) &traceOnPanic, &dummyLen);
811 if (code != ERROR_SUCCESS)
812 traceOnPanic = 1; /* log */
813 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
815 dummyLen = sizeof(reportSessionStartups);
816 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
817 (BYTE *) &reportSessionStartups, &dummyLen);
818 if (code == ERROR_SUCCESS)
819 afsi_log("Session startups %s be recorded in the Event Log",
820 reportSessionStartups ? "will" : "will not");
822 reportSessionStartups = 0;
826 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
827 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
828 cm_sysNameList[i][0] = '\0';
830 cm_sysName = cm_sysNameList[0];
834 clientchar_t * cbuf = (clientchar_t *) buf;
835 dummyLen = sizeof(buf);
836 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
837 if (code != ERROR_SUCCESS || !cbuf[0]) {
839 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
840 #elif defined(_AMD64_)
841 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
842 #else /* assume x86 32-bit */
843 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
846 afsi_log("Sys name %S", cbuf);
848 /* breakup buf into individual search string entries */
849 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
850 if (*p == '\0' || iswspace(*p)) {
851 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
852 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
858 } while (*p == '\0' || isspace(*p));
865 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
867 dummyLen = sizeof(cryptall);
868 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
869 (BYTE *) &cryptall, &dummyLen);
870 if (code == ERROR_SUCCESS) {
871 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
874 afsi_log("Default SecurityLevel is clear");
878 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
879 else if (cryptall == 2)
880 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
882 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
884 dummyLen = sizeof(cryptall);
885 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
886 (BYTE *) &cm_anonvldb, &dummyLen);
887 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
890 dummyLen = sizeof(cm_dnsEnabled);
891 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
892 (BYTE *) &cm_dnsEnabled, &dummyLen);
893 if (code == ERROR_SUCCESS) {
894 afsi_log("DNS %s be used to find AFS cell servers",
895 cm_dnsEnabled ? "will" : "will not");
898 cm_dnsEnabled = 1; /* default on */
899 afsi_log("Default to use DNS to find AFS cell servers");
901 #else /* AFS_AFSDB_ENV */
902 afsi_log("AFS not built with DNS support to find AFS cell servers");
903 #endif /* AFS_AFSDB_ENV */
905 #ifdef AFS_FREELANCE_CLIENT
906 dummyLen = sizeof(cm_freelanceEnabled);
907 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
908 (BYTE *) &cm_freelanceEnabled, &dummyLen);
909 if (code == ERROR_SUCCESS) {
910 afsi_log("Freelance client feature %s activated",
911 cm_freelanceEnabled ? "is" : "is not");
914 cm_freelanceEnabled = 1; /* default on */
916 #endif /* AFS_FREELANCE_CLIENT */
918 dummyLen = sizeof(smb_UseUnicode);
919 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
920 (BYTE *) &smb_UseUnicode, &dummyLen);
921 if (code != ERROR_SUCCESS) {
922 smb_UseUnicode = 1; /* default on */
924 afsi_log("SMB Server Unicode Support is %s",
925 smb_UseUnicode ? "enabled" : "disabled");
927 dummyLen = sizeof(smb_hideDotFiles);
928 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
929 (BYTE *) &smb_hideDotFiles, &dummyLen);
930 if (code != ERROR_SUCCESS) {
931 smb_hideDotFiles = 1; /* default on */
933 afsi_log("Dot files/dirs will %sbe marked hidden",
934 smb_hideDotFiles ? "" : "not ");
936 dummyLen = sizeof(smb_maxMpxRequests);
937 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
938 (BYTE *) &smb_maxMpxRequests, &dummyLen);
939 if (code != ERROR_SUCCESS) {
940 smb_maxMpxRequests = 50;
942 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
944 dummyLen = sizeof(smb_maxVCPerServer);
945 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
946 (BYTE *) &smb_maxVCPerServer, &dummyLen);
947 if (code != ERROR_SUCCESS) {
948 smb_maxVCPerServer = 100;
950 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
952 dummyLen = sizeof(smb_authType);
953 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
954 (BYTE *) &smb_authType, &dummyLen);
956 if (code != ERROR_SUCCESS ||
957 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
958 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
960 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
962 dummyLen = sizeof(rx_nojumbo);
963 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
964 (BYTE *) &rx_nojumbo, &dummyLen);
965 if (code != ERROR_SUCCESS) {
967 dummyLen = sizeof(jumbo);
968 code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
969 (BYTE *) &jumbo, &dummyLen);
970 if (code != ERROR_SUCCESS) {
977 afsi_log("RX Jumbograms are disabled");
979 afsi_log("RX Jumbograms are enabled");
981 dummyLen = sizeof(rx_extraPackets);
982 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
983 (BYTE *) &rx_extraPackets, &dummyLen);
984 if (code != ERROR_SUCCESS) {
985 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
988 afsi_log("RX extraPackets is %d", rx_extraPackets);
990 dummyLen = sizeof(rx_udpbufsize);
991 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
992 (BYTE *) &rx_udpbufsize, &dummyLen);
993 if (code != ERROR_SUCCESS) {
994 rx_udpbufsize = 256*1024;
996 if (rx_udpbufsize != -1)
997 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
999 dummyLen = sizeof(rx_mtu);
1000 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1001 (BYTE *) &rx_mtu, &dummyLen);
1002 if (code != ERROR_SUCCESS || !rx_mtu) {
1006 afsi_log("RX maximum MTU is %d", rx_mtu);
1008 dummyLen = sizeof(rx_enable_peer_stats);
1009 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1010 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1011 if (code != ERROR_SUCCESS) {
1012 rx_enable_peer_stats = 1;
1014 if (rx_enable_peer_stats)
1015 afsi_log("RX Peer Statistics gathering is enabled");
1017 afsi_log("RX Peer Statistics gathering is disabled");
1019 dummyLen = sizeof(rx_enable_process_stats);
1020 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1021 (BYTE *) &rx_enable_process_stats, &dummyLen);
1022 if (code != ERROR_SUCCESS) {
1023 rx_enable_process_stats = 1;
1025 if (rx_enable_process_stats)
1026 afsi_log("RX Process Statistics gathering is enabled");
1028 afsi_log("RX Process Statistics gathering is disabled");
1030 dummyLen = sizeof(dwValue);
1032 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1033 (BYTE *) &dwValue, &dummyLen);
1034 if (code != ERROR_SUCCESS || dwValue != 0) {
1035 rx_EnableHotThread();
1036 afsi_log("RX Hot Thread is enabled");
1039 afsi_log("RX Hot Thread is disabled");
1041 dummyLen = sizeof(DWORD);
1042 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1043 (BYTE *) &dwValue, &dummyLen);
1044 if (code == ERROR_SUCCESS) {
1045 cm_callbackport = (unsigned short) dwValue;
1047 afsi_log("CM CallBackPort is %u", cm_callbackport);
1049 dummyLen = sizeof(DWORD);
1050 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1051 (BYTE *) &dwValue, &dummyLen);
1052 if (code == ERROR_SUCCESS) {
1053 cm_enableServerLocks = (unsigned short) dwValue;
1055 switch (cm_enableServerLocks) {
1057 afsi_log("EnableServerLocks: never");
1060 afsi_log("EnableServerLocks: always");
1064 afsi_log("EnableServerLocks: server requested");
1068 dummyLen = sizeof(DWORD);
1069 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1070 (BYTE *) &dwValue, &dummyLen);
1071 if (code == ERROR_SUCCESS) {
1072 cm_deleteReadOnly = (unsigned short) dwValue;
1074 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1077 dummyLen = sizeof(DWORD);
1078 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1079 (BYTE *) &dwValue, &dummyLen);
1080 if (code == ERROR_SUCCESS) {
1081 cm_BPlusTrees = (unsigned short) dwValue;
1083 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1085 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1087 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1090 afsi_log("CM BPlusTrees is not supported");
1093 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1094 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1095 (regType == REG_MULTI_SZ))
1098 dummyLen += 3; /* in case the source string is not nul terminated */
1099 pSz = malloc(dummyLen);
1100 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1101 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1102 (regType == REG_MULTI_SZ))
1107 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1109 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1111 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1112 smb_ExecutableExtensions[cnt] = p;
1113 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1115 smb_ExecutableExtensions[cnt] = NULL;
1118 if (!smb_ExecutableExtensions)
1121 if (!smb_ExecutableExtensions)
1122 afsi_log("No PrefetchExecutableExtensions");
1124 dummyLen = sizeof(DWORD);
1125 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1126 (BYTE *) &dwValue, &dummyLen);
1127 if (code == ERROR_SUCCESS) {
1128 cm_OfflineROIsValid = (unsigned short) dwValue;
1130 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1132 dummyLen = sizeof(DWORD);
1133 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1134 (BYTE *) &dwValue, &dummyLen);
1135 if (code == ERROR_SUCCESS) {
1136 cm_giveUpAllCBs = (unsigned short) dwValue;
1138 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1140 dummyLen = sizeof(DWORD);
1141 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1142 (BYTE *) &dwValue, &dummyLen);
1143 if (code == ERROR_SUCCESS) {
1144 cm_followBackupPath = (unsigned short) dwValue;
1146 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1148 dummyLen = sizeof(DWORD);
1149 code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
1150 (BYTE *) &dwValue, &dummyLen);
1151 if (code == ERROR_SUCCESS) {
1152 cm_accessPerFileCheck = (int) dwValue;
1154 afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
1156 RegCloseKey (parmKey);
1158 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1160 /* get network related info */
1161 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1162 code = syscfg_GetIFInfo(&cm_noIPAddr,
1163 cm_IPAddr, cm_SubnetMask,
1164 cm_NetMtu, cm_NetFlags);
1166 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1167 afsi_log("syscfg_GetIFInfo error code %d", code);
1169 afsi_log("First Network address %x SubnetMask %x",
1170 cm_IPAddr[0], cm_SubnetMask[0]);
1173 * Save client configuration for GetCacheConfig requests
1175 cm_initParams.nChunkFiles = 0;
1176 cm_initParams.nStatCaches = stats;
1177 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1178 cm_initParams.nVolumeCaches = volumes;
1179 cm_initParams.firstChunkSize = cm_chunkSize;
1180 cm_initParams.otherChunkSize = cm_chunkSize;
1181 cm_initParams.cacheSize = cacheSize;
1182 cm_initParams.setTime = 0;
1183 cm_initParams.memCache = 1;
1185 /* init user daemon, and other packages */
1198 cm_InitNormalization();
1200 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1201 afsi_log("cm_InitMappedMemory code %x", code);
1203 *reasonP = "error initializing cache file";
1207 #ifdef AFS_AFSDB_ENV
1208 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1209 if (cm_InitDNS(cm_dnsEnabled) == -1)
1210 cm_dnsEnabled = 0; /* init failed, so deactivate */
1211 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1215 /* Set RX parameters before initializing RX */
1218 afsi_log("rx_SetNoJumbo successful");
1221 if ( rx_mtu != -1 ) {
1222 extern void rx_SetMaxMTU(int);
1224 rx_SetMaxMTU(rx_mtu);
1225 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1228 if ( rx_udpbufsize != -1 ) {
1229 rx_SetUdpBufSize(rx_udpbufsize);
1230 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1233 /* initialize RX, and tell it to listen to the callbackport,
1234 * which is used for callback RPC messages.
1236 code = rx_Init(htons(cm_callbackport));
1238 afsi_log("rx_Init code %x - retrying with a random port number", code);
1241 afsi_log("rx_Init code %x", code);
1243 *reasonP = "afsd: failed to init rx client";
1247 /* create an unauthenticated service #1 for callbacks */
1248 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1249 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1250 RXAFSCB_ExecuteRequest);
1251 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1252 if (serverp == NULL) {
1253 *reasonP = "unknown error";
1256 rx_SetMinProcs(serverp, 2);
1257 rx_SetMaxProcs(serverp, 4);
1258 rx_SetCheckReach(serverp, 1);
1260 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1261 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1262 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1263 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1264 if (serverp == NULL) {
1265 *reasonP = "unknown error";
1268 rx_SetMinProcs(serverp, 2);
1269 rx_SetMaxProcs(serverp, 4);
1271 /* start server threads, *not* donating this one to the pool */
1273 afsi_log("rx_StartServer");
1275 if (rx_enable_peer_stats)
1276 rx_enablePeerRPCStats();
1278 if (rx_enable_process_stats)
1279 rx_enableProcessRPCStats();
1281 code = cm_GetRootCellName(rootCellName);
1282 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1283 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1284 if (code != 0 && !cm_freelanceEnabled)
1286 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1289 else if (cm_freelanceEnabled)
1290 cm_data.rootCellp = NULL;
1292 if (code == 0 && !cm_freelanceEnabled)
1294 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1295 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1296 if (cm_data.rootCellp == NULL)
1298 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1303 #ifdef AFS_FREELANCE_CLIENT
1304 if (cm_freelanceEnabled)
1308 /* Initialize the RPC server for session keys */
1311 /* Initialize the RPC server for pipe services */
1314 afsd_InitServerPreferences();
1318 int afsd_ShutdownCM(void)
1322 cm_ReleaseSCache(cm_data.rootSCachep);
1329 int afsd_InitDaemons(char **reasonP)
1336 /* this should really be in an init daemon from here on down */
1338 if (!cm_freelanceEnabled) {
1341 osi_Log0(afsd_logp, "Loading Root Volume from cell");
1343 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
1344 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
1345 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
1346 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
1347 } while (code && --attempts);
1349 *reasonP = "can't find root volume in root cell";
1354 /* compute the root fid */
1355 if (!cm_freelanceEnabled) {
1356 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
1359 cm_FakeRootFid(&cm_data.rootFid);
1361 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
1362 afsi_log("cm_GetSCache code %x scache %x", code,
1363 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
1365 *reasonP = "unknown error";
1369 cm_InitDaemon(numBkgD);
1370 afsi_log("cm_InitDaemon complete");
1375 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1382 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1383 0, KEY_QUERY_VALUE, &parmKey);
1384 if (code == ERROR_SUCCESS) {
1385 dummyLen = sizeof(DWORD);
1386 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1387 (BYTE *) &dwValue, &dummyLen);
1388 if (code == ERROR_SUCCESS)
1389 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1390 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1392 dummyLen = sizeof(DWORD);
1393 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1394 (BYTE *) &dwValue, &dummyLen);
1395 if (code == ERROR_SUCCESS)
1396 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1397 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1399 dummyLen = sizeof(DWORD);
1400 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1401 (BYTE *) &dwValue, &dummyLen);
1402 if (code == ERROR_SUCCESS) {
1403 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1404 if (dwValue > cm_chunkSize)
1405 smb_AsyncStoreSize = cm_chunkSize;
1406 else if (dwValue < cm_data.buf_blockSize)
1407 smb_AsyncStoreSize = cm_data.buf_blockSize;
1409 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1411 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1412 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1414 RegCloseKey (parmKey);
1417 /* Do this last so that we don't handle requests before init is done.
1418 * Here we initialize the SMB listener.
1420 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1421 afsi_log("smb_Init complete");
1434 #pragma pack( push, before_imagehlp, 8 )
1435 #include <imagehlp.h>
1436 #pragma pack( pop, before_imagehlp )
1438 #define MAXNAMELEN 1024
1440 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1442 HANDLE hProcess = GetCurrentProcess();
1444 #if defined(_AMD64_)
1446 #elif defined(_X86_)
1450 char functionName[MAXNAMELEN];
1452 IMAGEHLP_MODULE Module;
1456 IMAGEHLP_SYMBOL *pSym;
1458 afsi_log_useTimestamp = 0;
1460 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1462 memset( &s, '\0', sizeof s );
1463 if (!SymInitialize(hProcess, NULL, 1) )
1465 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1467 SymCleanup( hProcess );
1473 symOptions = SymGetOptions();
1474 symOptions |= SYMOPT_LOAD_LINES;
1475 symOptions &= ~SYMOPT_UNDNAME;
1476 SymSetOptions( symOptions );
1479 * init STACKFRAME for first call
1480 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1481 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1482 * and good riddance.
1484 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1485 #error The STACKFRAME initialization in afsd_printStack() for this platform
1486 #error must be properly configured
1487 #elif defined(_AMD64_)
1488 s.AddrPC.Offset = c->Rip;
1489 s.AddrPC.Mode = AddrModeFlat;
1490 s.AddrFrame.Offset = c->Rbp;
1491 s.AddrFrame.Mode = AddrModeFlat;
1493 s.AddrPC.Offset = c->Eip;
1494 s.AddrPC.Mode = AddrModeFlat;
1495 s.AddrFrame.Offset = c->Ebp;
1496 s.AddrFrame.Mode = AddrModeFlat;
1499 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1500 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1501 pSym->MaxNameLength = MAXNAMELEN;
1503 memset( &Line, '\0', sizeof Line );
1504 Line.SizeOfStruct = sizeof Line;
1506 memset( &Module, '\0', sizeof Module );
1507 Module.SizeOfStruct = sizeof Module;
1511 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1513 for ( frameNum = 0; ; ++ frameNum )
1516 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1517 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1518 * ERROR_NOACCESS (998), you can assume that either you are done, or
1519 * that the stack is so hosed that the next deeper frame could not be
1522 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1523 NULL, SymFunctionTableAccess, SymGetModuleBase,
1527 /* display its contents */
1528 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1529 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1530 s.AddrPC.Offset, s.AddrReturn.Offset,
1531 s.AddrFrame.Offset, s.AddrStack.Offset );
1533 if ( s.AddrPC.Offset == 0 )
1535 afsi_log("(-nosymbols- PC == 0)" );
1539 /* show procedure info from a valid PC */
1540 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1542 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1544 afsi_log("SymGetSymFromAddr(): errno = %lu",
1550 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1552 afsi_log("%s", functionName );
1556 afsi_log(" %+ld bytes", (long) offset);
1560 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1562 if (GetLastError() != ERROR_INVALID_ADDRESS)
1564 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1570 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1571 Line.LineNumber, offset);
1575 /* no return address means no deeper stackframe */
1576 if (s.AddrReturn.Offset == 0)
1583 if (GetLastError() != 0)
1585 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1588 SymCleanup(hProcess);
1593 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1594 static DWORD afsd_crtDbgBreaks[256];
1597 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1598 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1599 MINIDUMP_TYPE DumpType,
1600 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1601 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1602 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1611 code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
1612 if ( code == 0 || code > sizeof(wd) )
1614 if (!GetWindowsDirectory(wd, sizeof(wd)))
1617 StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
1618 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1619 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1623 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1625 if (IsDebuggerPresent())
1630 // Generate exception to get proper context in dump
1633 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1635 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1641 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1642 HANDLE hFile = NULL;
1643 HMODULE hDbgHelp = NULL;
1645 hDbgHelp = LoadLibrary("Dbghelp.dll");
1646 if ( hDbgHelp == NULL )
1649 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1650 if ( pMiniDumpWriteDump == NULL ) {
1651 FreeLibrary(hDbgHelp);
1655 hFile = OpenDumpFile();
1662 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1664 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1665 0, KEY_QUERY_VALUE, &parmKey);
1666 if (code == ERROR_SUCCESS) {
1667 dummyLen = sizeof(DWORD);
1668 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1669 (BYTE *) &dwValue, &dummyLen);
1670 if (code == ERROR_SUCCESS)
1671 dwMiniDumpType = dwValue;
1672 RegCloseKey (parmKey);
1675 eInfo.ThreadId = GetCurrentThreadId();
1676 eInfo.ExceptionPointers = ep;
1677 eInfo.ClientPointers = FALSE;
1679 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1680 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1685 FreeLibrary(hDbgHelp);
1689 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1693 BOOL allocRequestBrk = FALSE;
1695 HMODULE hLib = NULL;
1697 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1698 ep->ExceptionRecord->ExceptionCode,
1699 ep->ExceptionRecord->ExceptionAddress);
1702 if (afsd_crtDbgBreakCurrent &&
1703 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1705 allocRequestBrk = TRUE;
1706 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1710 /* save context if we want to print the stack information */
1711 context = *ep->ContextRecord;
1713 afsd_printStack(GetCurrentThread(), &context);
1715 GenerateMiniDump(ep);
1717 hLib = LoadLibrary("Faultrep.dll");
1719 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1721 pReportFault(ep, 0);
1725 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1727 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1730 if (allocRequestBrk)
1732 afsd_crtDbgBreakCurrent++;
1733 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1737 ep->ContextRecord->Eip++;
1739 #if defined(_AMD64_)
1740 ep->ContextRecord->Rip++;
1742 return EXCEPTION_CONTINUE_EXECUTION;
1746 return EXCEPTION_CONTINUE_SEARCH;
1750 void afsd_SetUnhandledExceptionFilter()
1753 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1758 void afsd_DbgBreakAllocInit()
1760 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1761 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1764 void afsd_DbgBreakAdd(DWORD requestNumber)
1767 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1769 if (afsd_crtDbgBreaks[i] == -1)
1774 afsd_crtDbgBreaks[i] = requestNumber;
1776 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);