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.
117 int cm_dnsEnabled = 1;
121 static int afsi_log_useTimestamp = 1;
124 afsi_log(char *pattern, ...)
126 char s[256], t[100], d[100], u[512];
129 va_start(ap, pattern);
131 StringCbVPrintfA(s, sizeof(s), pattern, ap);
132 if ( afsi_log_useTimestamp ) {
133 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
134 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
135 StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
136 if (afsi_file != INVALID_HANDLE_VALUE)
137 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
142 if (afsi_file != INVALID_HANDLE_VALUE)
143 WriteFile(afsi_file, s, (DWORD)strlen(s), &zilch, NULL);
151 char t[100], u[100], *p, *path;
157 DWORD maxLogSize = 100 * 1024;
159 afsi_file = INVALID_HANDLE_VALUE;
160 code = GetTempPath(sizeof(wd)-15, wd);
161 if ( code == 0 || code > (sizeof(wd)-15) )
162 return; /* unable to create a log */
164 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
165 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
166 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
167 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
169 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
170 0, KEY_QUERY_VALUE, &parmKey);
171 if (code == ERROR_SUCCESS) {
172 dummyLen = sizeof(maxLogSize);
173 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
174 (BYTE *) &maxLogSize, &dummyLen);
175 RegCloseKey (parmKey);
179 dwLow = GetFileSize( afsi_file, &dwHigh );
180 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
181 CloseHandle(afsi_file);
182 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
183 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
187 SetFilePointer(afsi_file, 0, NULL, FILE_END);
188 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
189 StringCbCatA(t, sizeof(t), ": Create log file\r\n");
190 StringCbCatA(u, sizeof(u), ": Created log file\r\n");
191 WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
192 WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
194 code = GetEnvironmentVariable("PATH", NULL, 0);
196 code = GetEnvironmentVariable("PATH", path, code);
197 WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
198 WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
199 WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
202 /* Initialize C RTL Code Page conversion functions */
203 /* All of the path info obtained from the SMB client is in the OEM code page */
204 afsi_log("OEM Code Page = %d", GetOEMCP());
205 afsi_log("locale = %s", setlocale(LC_ALL,NULL));
207 /* Two things to look into. First, should mbstowcs() be performing
208 * character set translations from OEM to Unicode in smb3.c;
209 * Second, do we need to set this translation in each function
210 * due to multi-threading.
212 afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP"));
213 afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp());
218 * Standard AFSD trace
221 void afsd_ForceTrace(BOOL flush)
230 len = GetTempPath(sizeof(buf)-10, buf);
231 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
232 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
233 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
234 if (handle == INVALID_HANDLE_VALUE) {
236 osi_panic("Cannot create log file", __FILE__, __LINE__);
238 osi_LogPrint(afsd_logp, handle);
240 FlushFileBuffers(handle);
244 static void afsd_InitServerPreferences(void)
247 DWORD dwType, dwSize;
251 DWORD dwHostSize = 256;
253 struct sockaddr_in saddr;
256 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
257 AFSREG_CLT_OPENAFS_SUBKEY "\\Server Preferences\\VLDB",
259 KEY_READ|KEY_QUERY_VALUE,
260 &hkPrefs) == ERROR_SUCCESS) {
262 RegQueryInfoKey( hkPrefs,
265 NULL, /* lpReserved */
266 NULL, /* lpcSubKeys */
267 NULL, /* lpcMaxSubKeyLen */
268 NULL, /* lpcMaxClassLen */
269 &dwPrefs, /* lpcValues */
270 NULL, /* lpcMaxValueNameLen */
271 NULL, /* lpcMaxValueLen */
272 NULL, /* lpcbSecurityDescriptor */
273 NULL /* lpftLastWriteTime */
276 for ( dwIndex = 0 ; dwIndex < dwPrefs; dwIndex++ ) {
278 dwSize = sizeof(DWORD);
281 if (RegEnumValue( hkPrefs, dwIndex, szHost, &dwHostSize, NULL,
282 &dwType, (LPBYTE)&dwRank, &dwSize))
284 afsi_log("RegEnumValue(hkPrefs) failed");
288 afsi_log("VLDB Server Preference: %s = %d",szHost, dwRank);
290 if (isdigit(szHost[0]))
292 if ((saddr.sin_addr.S_un.S_addr = inet_addr (szHost)) == INADDR_NONE)
296 if ((pEntry = gethostbyname (szHost)) == NULL)
299 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
301 saddr.sin_port = htons(7003);
302 saddr.sin_family = AF_INET;
303 dwRank += (rand() & 0x000f);
305 tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
306 if ( tsp ) /* an existing server - ref count increased */
308 lock_ObtainMutex(&tsp->mx);
309 tsp->ipRank = (USHORT)dwRank;
310 tsp->flags |= CM_SERVERFLAG_PREF_SET;
311 lock_ReleaseMutex(&tsp->mx);
313 /* set preferences for an existing vlserver */
314 cm_ChangeRankCellVLServer(tsp);
315 cm_PutServer(tsp); /* decrease refcount */
317 else /* add a new server without a cell */
319 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
320 lock_ObtainMutex(&tsp->mx);
321 tsp->ipRank = (USHORT)dwRank;
322 tsp->flags |= CM_SERVERFLAG_PREF_SET;
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 lock_ReleaseMutex(&tsp->mx);
387 /* find volumes which might have RO copy
388 /* on server and change the ordering of
391 cm_ChangeRankVolume(tsp);
392 cm_PutServer(tsp); /* decrease refcount */
394 else /* add a new server without a cell */
396 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
397 lock_ObtainMutex(&tsp->mx);
398 tsp->ipRank = (USHORT)dwRank;
399 tsp->flags |= CM_SERVERFLAG_PREF_SET;
400 lock_ReleaseMutex(&tsp->mx);
403 if (cm_readonlyVolumeVersioning) {
404 /* Add a matching vol server */
405 tsp = cm_FindServer(&saddr, CM_SERVER_VOL);
406 if ( tsp ) /* an existing server - ref count increased */
408 tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
409 cm_PutServer(tsp); /* decrease refcount */
411 else /* add a new server without a cell */
413 tsp = cm_NewServer(&saddr, CM_SERVER_VOL, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
414 tsp->ipRank = (USHORT)dwRank;
419 RegCloseKey(hkPrefs);
425 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
430 static BOOL bChecked = FALSE;
431 static BOOL bIsWow64 = FALSE;
436 LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
438 h1 = GetModuleHandle("kernel32.dll");
440 (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process");
442 /* If we don't find the fnIsWow64Process function then we
443 * are not running in a broken Wow64
445 if (fnIsWow64Process)
446 fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
456 * AFSD Initialization
460 afsd_InitRoot(char **reasonP)
467 if (cm_freelanceEnabled) {
468 cm_FakeRootFid(&cm_data.rootFid);
472 osi_Log0(afsd_logp, "Loading Root Volume from cell");
474 code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
475 &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
476 afsi_log("cm_FindVolumeByName code %x root vol %x", code,
477 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
478 } while (code && --attempts);
480 *reasonP = "can't find root volume in root cell";
484 /* compute the root fid */
485 cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
488 code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
489 afsi_log("cm_GetSCache code %x scache %x", code,
490 (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
492 *reasonP = "unknown error";
500 afsd_InitCM(char **reasonP)
503 afs_uint64 cacheBlocks;
511 DWORD rx_enable_peer_stats;
512 DWORD rx_enable_process_stats;
513 DWORD rx_udpbufsize = -1;
514 DWORD lockOrderValidation;
519 long virtualCache = 0;
520 fschar_t rootCellName[256];
521 struct rx_service *serverp;
522 static struct rx_securityClass *nullServerSecurityClassp;
530 /*int freelanceEnabled;*/
533 int cm_noIPAddr; /* number of client network interfaces */
534 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
535 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
536 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
537 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
540 WSAStartup(0x0101, &WSAjunk);
542 init_et_to_sys_error();
546 /* setup osidebug server at RPC slot 1000 */
547 osi_LongToUID(1000, &debugID);
548 code = osi_InitDebug(&debugID);
549 afsi_log("osi_InitDebug code %d", code);
554 *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment";
559 // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
561 if (code == RPC_S_NO_PROTSEQS)
562 *reasonP = "No RPC Protocol Sequences registered. Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
564 *reasonP = "unknown error";
569 gethostname(cm_HostName, sizeof(cm_HostName));
570 afsi_log("gethostname %s", cm_HostName);
571 thp = gethostbyname(cm_HostName);
572 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
574 /* seed random number generator */
575 srand(ntohl(cm_HostAddr));
577 /* Look up configuration parameters in Registry */
578 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
579 0, KEY_QUERY_VALUE, &parmKey);
580 if (code != ERROR_SUCCESS) {
581 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
582 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
583 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
584 StringCbPrintfA(buf, sizeof(buf),
585 "Failure in configuration while opening Registry: %s",
587 osi_panic(buf, __FILE__, __LINE__);
590 dummyLen = sizeof(dwPriority);
591 code = RegQueryValueEx(parmKey, "PriorityClass", NULL, NULL,
592 (BYTE *) &dwPriority, &dummyLen);
593 if (code != ERROR_SUCCESS || dwPriority == 0) {
594 dwPriority = HIGH_PRIORITY_CLASS;
596 if (dwPriority != GetPriorityClass(GetCurrentProcess()))
597 SetPriorityClass(GetCurrentProcess(), dwPriority);
598 afsi_log("PriorityClass 0x%x", GetPriorityClass(GetCurrentProcess()));
600 dummyLen = sizeof(lockOrderValidation);
601 code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
602 (BYTE *) &lockOrderValidation, &dummyLen);
603 if (code != ERROR_SUCCESS) {
605 lockOrderValidation = 1;
607 lockOrderValidation = 0;
610 osi_SetLockOrderValidation(lockOrderValidation);
611 afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
613 dummyLen = sizeof(maxcpus);
614 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
615 (BYTE *) &maxcpus, &dummyLen);
616 if (code == ERROR_SUCCESS) {
618 DWORD_PTR processAffinityMask, systemAffinityMask;
620 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
621 FALSE, GetCurrentProcessId());
622 if ( hProcess != NULL &&
623 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
626 DWORD_PTR mask, newAffinityMask;
633 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
634 if ( processAffinityMask & mask ) {
635 newAffinityMask |= mask;
641 SetProcessAffinityMask(hProcess, newAffinityMask);
642 CloseHandle(hProcess);
643 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
645 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
649 dummyLen = sizeof(TraceOption);
650 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
651 (BYTE *) &TraceOption, &dummyLen);
652 afsi_log("Trace Options = %lX", TraceOption);
654 dummyLen = sizeof(traceBufSize);
655 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
656 (BYTE *) &traceBufSize, &dummyLen);
657 if (code == ERROR_SUCCESS)
658 afsi_log("Trace Buffer size %d", traceBufSize);
660 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
661 afsi_log("Default trace buffer size %d", traceBufSize);
664 /* setup and enable debug log */
665 afsd_logp = osi_LogCreate("afsd", traceBufSize);
666 afsi_log("osi_LogCreate log addr %x", PtrToUlong(afsd_logp));
667 if ((TraceOption & 0x8)
672 osi_LogEnable(afsd_logp);
676 osi_Log0(afsd_logp, "Log init");
678 dummyLen = sizeof(cacheSize);
679 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
680 (BYTE *) &cacheSize, &dummyLen);
681 if (code == ERROR_SUCCESS)
682 afsi_log("Cache size %d", cacheSize);
684 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
685 afsi_log("Default cache size %d", cacheSize);
688 dummyLen = sizeof(logChunkSize);
689 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
690 (BYTE *) &logChunkSize, &dummyLen);
691 if (code == ERROR_SUCCESS) {
692 if (logChunkSize < 12 || logChunkSize > 30) {
693 afsi_log("Invalid chunk size %d, using default",
695 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
698 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
700 cm_logChunkSize = logChunkSize;
701 cm_chunkSize = 1 << logChunkSize;
702 afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
704 dummyLen = sizeof(blockSize);
705 code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
706 (BYTE *) &blockSize, &dummyLen);
707 if (code == ERROR_SUCCESS) {
709 (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0)))
711 afsi_log("Invalid block size %u specified, using default", blockSize);
712 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
715 * if the blockSize is less than 1024 we permit the blockSize to be
716 * specified in multiples of the default blocksize
718 if (blockSize <= 1024)
719 blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
722 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
724 if (blockSize > cm_chunkSize) {
725 afsi_log("Block size (%d) cannot be larger than Chunk size (%d).",
726 blockSize, cm_chunkSize);
727 blockSize = cm_chunkSize;
729 if (cm_chunkSize % blockSize != 0) {
730 afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
731 blockSize, cm_chunkSize);
732 blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
734 afsi_log("Block size %u", blockSize);
736 dummyLen = sizeof(numBkgD);
737 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
738 (BYTE *) &numBkgD, &dummyLen);
739 if (code == ERROR_SUCCESS) {
740 if (numBkgD > CM_MAX_DAEMONS)
741 numBkgD = CM_MAX_DAEMONS;
742 afsi_log("%d background daemons", numBkgD);
744 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
745 afsi_log("Defaulting to %d background daemons", numBkgD);
748 dummyLen = sizeof(numSvThreads);
749 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
750 (BYTE *) &numSvThreads, &dummyLen);
751 if (code == ERROR_SUCCESS)
752 afsi_log("%d server threads", numSvThreads);
754 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
755 afsi_log("Defaulting to %d server threads", numSvThreads);
758 dummyLen = sizeof(stats);
759 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
760 (BYTE *) &stats, &dummyLen);
761 if (code == ERROR_SUCCESS)
762 afsi_log("Status cache entries: %d", stats);
764 stats = CM_CONFIGDEFAULT_STATS;
765 afsi_log("Default status cache entries: %d", stats);
768 dummyLen = sizeof(volumes);
769 code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
770 (BYTE *) &volumes, &dummyLen);
771 if (code == ERROR_SUCCESS)
772 afsi_log("Volumes cache entries: %d", volumes);
774 volumes = CM_CONFIGDEFAULT_STATS / 3;
775 afsi_log("Default volume cache entries: %d", volumes);
778 dummyLen = sizeof(cells);
779 code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
780 (BYTE *) &cells, &dummyLen);
781 if (code == ERROR_SUCCESS)
782 afsi_log("Cell cache entries: %d", cells);
784 cells = CM_CONFIGDEFAULT_CELLS;
785 afsi_log("Default cell cache entries: %d", cells);
788 dummyLen = sizeof(ltt);
789 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
790 (BYTE *) <t, &dummyLen);
791 if (code != ERROR_SUCCESS)
793 smb_LogoffTokenTransfer = ltt;
794 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
797 dummyLen = sizeof(ltto);
798 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
799 NULL, NULL, (BYTE *) <to, &dummyLen);
800 if (code != ERROR_SUCCESS)
805 smb_LogoffTransferTimeout = ltto;
806 afsi_log("Logoff token transfer timeout %d seconds", ltto);
808 dummyLen = sizeof(cm_rootVolumeName);
809 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
810 (LPBYTE) cm_rootVolumeName, &dummyLen);
811 if (code == ERROR_SUCCESS)
812 afsi_log("Root volume %s", cm_rootVolumeName);
814 cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
815 afsi_log("Default root volume name root.afs");
818 cm_mountRootCLen = sizeof(cm_mountRootC);
819 code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
820 (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
821 if (code == ERROR_SUCCESS) {
822 afsi_log("Mount root %S", cm_mountRootC);
823 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
825 cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
826 cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
830 cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
831 cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
833 dummyLen = sizeof(buf);
834 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
836 if (code == ERROR_SUCCESS && buf[0]) {
837 if (regType == REG_EXPAND_SZ) {
838 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
839 if (dummyLen > sizeof(cm_CachePath)) {
840 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
841 osi_panic("CachePath too long", __FILE__, __LINE__);
844 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
846 afsi_log("Cache path %s", cm_CachePath);
848 dummyLen = ExpandEnvironmentStrings("%TEMP%\\AFSCache", cm_CachePath, sizeof(cm_CachePath));
849 if (dummyLen > sizeof(cm_CachePath)) {
850 afsi_log("Cache path [%%TEMP%%\\AFSCache] longer than %d after expanding env strings",
851 sizeof(cm_CachePath));
852 osi_panic("CachePath too long", __FILE__, __LINE__);
854 afsi_log("Default cache path %s", cm_CachePath);
857 dummyLen = sizeof(virtualCache);
858 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
859 (LPBYTE)&virtualCache, &dummyLen);
860 afsi_log("Cache type is %s", (virtualCache?"VIRTUAL":"FILE"));
863 dummyLen = sizeof(cm_ValidateCache);
864 code = RegQueryValueEx(parmKey, "ValidateCache", NULL, NULL,
865 (LPBYTE)&cm_ValidateCache, &dummyLen);
866 if ( cm_ValidateCache < 0 || cm_ValidateCache > 2 )
867 cm_ValidateCache = 1;
868 switch (cm_ValidateCache) {
870 afsi_log("Cache Validation disabled");
873 afsi_log("Cache Validation on Startup");
876 afsi_log("Cache Validation on Startup and Shutdown");
881 dummyLen = sizeof(traceOnPanic);
882 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
883 (BYTE *) &traceOnPanic, &dummyLen);
884 if (code != ERROR_SUCCESS)
885 traceOnPanic = 1; /* log */
886 afsi_log("Set to %s on panic", traceOnPanic ? "trap" : "not trap");
888 dummyLen = sizeof(reportSessionStartups);
889 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
890 (BYTE *) &reportSessionStartups, &dummyLen);
891 if (code == ERROR_SUCCESS)
892 afsi_log("Session startups %s be recorded in the Event Log",
893 reportSessionStartups ? "will" : "will not");
895 reportSessionStartups = 0;
899 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
900 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
901 cm_sysNameList[i][0] = '\0';
903 cm_sysName = cm_sysNameList[0];
907 clientchar_t * cbuf = (clientchar_t *) buf;
908 dummyLen = sizeof(buf);
909 code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
910 if (code != ERROR_SUCCESS || !cbuf[0]) {
912 cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
913 #elif defined(_AMD64_)
914 cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
915 #else /* assume x86 32-bit */
916 cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
919 afsi_log("Sys name %S", cbuf);
921 /* breakup buf into individual search string entries */
922 for (p = q = cbuf; p < cbuf + dummyLen; p++) {
923 if (*p == '\0' || iswspace(*p)) {
924 memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
925 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
931 } while (*p == '\0' || isspace(*p));
938 cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
940 dummyLen = sizeof(cryptall);
941 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
942 (BYTE *) &cryptall, &dummyLen);
943 if (code == ERROR_SUCCESS) {
944 afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
947 afsi_log("Default SecurityLevel is clear");
951 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
952 else if (cryptall == 2)
953 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
955 LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
957 dummyLen = sizeof(cryptall);
958 code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
959 (BYTE *) &cm_anonvldb, &dummyLen);
960 afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
963 dummyLen = sizeof(cm_dnsEnabled);
964 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
965 (BYTE *) &cm_dnsEnabled, &dummyLen);
966 if (code == ERROR_SUCCESS) {
967 afsi_log("DNS %s be used to find AFS cell servers",
968 cm_dnsEnabled ? "will" : "will not");
971 cm_dnsEnabled = 1; /* default on */
972 afsi_log("Default to use DNS to find AFS cell servers");
974 #else /* AFS_AFSDB_ENV */
975 afsi_log("AFS not built with DNS support to find AFS cell servers");
976 #endif /* AFS_AFSDB_ENV */
978 #ifdef AFS_FREELANCE_CLIENT
979 dummyLen = sizeof(cm_freelanceEnabled);
980 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
981 (BYTE *) &cm_freelanceEnabled, &dummyLen);
982 if (code == ERROR_SUCCESS) {
983 afsi_log("Freelance client feature %s activated",
984 cm_freelanceEnabled ? "is" : "is not");
987 cm_freelanceEnabled = 1; /* default on */
989 #endif /* AFS_FREELANCE_CLIENT */
991 dummyLen = sizeof(smb_UseUnicode);
992 code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
993 (BYTE *) &smb_UseUnicode, &dummyLen);
994 if (code != ERROR_SUCCESS) {
995 smb_UseUnicode = 1; /* default on */
997 afsi_log("SMB Server Unicode Support is %s",
998 smb_UseUnicode ? "enabled" : "disabled");
1000 dummyLen = sizeof(smb_hideDotFiles);
1001 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
1002 (BYTE *) &smb_hideDotFiles, &dummyLen);
1003 if (code != ERROR_SUCCESS) {
1004 smb_hideDotFiles = 1; /* default on */
1006 afsi_log("Dot files/dirs will %sbe marked hidden",
1007 smb_hideDotFiles ? "" : "not ");
1009 dummyLen = sizeof(smb_maxMpxRequests);
1010 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
1011 (BYTE *) &smb_maxMpxRequests, &dummyLen);
1012 if (code != ERROR_SUCCESS) {
1013 smb_maxMpxRequests = 50;
1015 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
1017 dummyLen = sizeof(smb_maxVCPerServer);
1018 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
1019 (BYTE *) &smb_maxVCPerServer, &dummyLen);
1020 if (code != ERROR_SUCCESS) {
1021 smb_maxVCPerServer = 100;
1023 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
1025 dummyLen = sizeof(smb_authType);
1026 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
1027 (BYTE *) &smb_authType, &dummyLen);
1029 if (code != ERROR_SUCCESS ||
1030 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
1031 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
1033 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
1035 dummyLen = sizeof(rx_nojumbo);
1036 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
1037 (BYTE *) &rx_nojumbo, &dummyLen);
1038 if (code != ERROR_SUCCESS) {
1040 dummyLen = sizeof(jumbo);
1041 code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
1042 (BYTE *) &jumbo, &dummyLen);
1043 if (code != ERROR_SUCCESS) {
1046 rx_nojumbo = !jumbo;
1050 afsi_log("RX Jumbograms are disabled");
1052 afsi_log("RX Jumbograms are enabled");
1054 dummyLen = sizeof(rx_extraPackets);
1055 code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
1056 (BYTE *) &rx_extraPackets, &dummyLen);
1057 if (code != ERROR_SUCCESS) {
1058 rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
1060 if (rx_extraPackets)
1061 afsi_log("RX extraPackets is %d", rx_extraPackets);
1063 dummyLen = sizeof(rx_udpbufsize);
1064 code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
1065 (BYTE *) &rx_udpbufsize, &dummyLen);
1066 if (code != ERROR_SUCCESS) {
1067 rx_udpbufsize = 256*1024;
1069 if (rx_udpbufsize != -1)
1070 afsi_log("RX udpbufsize is %d", rx_udpbufsize);
1072 dummyLen = sizeof(rx_mtu);
1073 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
1074 (BYTE *) &rx_mtu, &dummyLen);
1075 if (code != ERROR_SUCCESS || !rx_mtu) {
1079 afsi_log("RX maximum MTU is %d", rx_mtu);
1081 dummyLen = sizeof(rx_enable_peer_stats);
1082 code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
1083 (BYTE *) &rx_enable_peer_stats, &dummyLen);
1084 if (code != ERROR_SUCCESS) {
1085 rx_enable_peer_stats = 1;
1087 if (rx_enable_peer_stats)
1088 afsi_log("RX Peer Statistics gathering is enabled");
1090 afsi_log("RX Peer Statistics gathering is disabled");
1092 dummyLen = sizeof(rx_enable_process_stats);
1093 code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
1094 (BYTE *) &rx_enable_process_stats, &dummyLen);
1095 if (code != ERROR_SUCCESS) {
1096 rx_enable_process_stats = 1;
1098 if (rx_enable_process_stats)
1099 afsi_log("RX Process Statistics gathering is enabled");
1101 afsi_log("RX Process Statistics gathering is disabled");
1103 dummyLen = sizeof(dwValue);
1105 code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
1106 (BYTE *) &dwValue, &dummyLen);
1107 if (code != ERROR_SUCCESS || dwValue != 0) {
1108 rx_EnableHotThread();
1109 afsi_log("RX Hot Thread is enabled");
1112 afsi_log("RX Hot Thread is disabled");
1114 dummyLen = sizeof(DWORD);
1115 code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
1116 (BYTE *) &dwValue, &dummyLen);
1117 if (code == ERROR_SUCCESS) {
1118 cm_callbackport = (unsigned short) dwValue;
1120 afsi_log("CM CallBackPort is %u", cm_callbackport);
1122 dummyLen = sizeof(DWORD);
1123 code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
1124 (BYTE *) &dwValue, &dummyLen);
1125 if (code == ERROR_SUCCESS) {
1126 cm_enableServerLocks = (unsigned short) dwValue;
1128 switch (cm_enableServerLocks) {
1130 afsi_log("EnableServerLocks: never");
1133 afsi_log("EnableServerLocks: always");
1137 afsi_log("EnableServerLocks: server requested");
1141 dummyLen = sizeof(DWORD);
1142 code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
1143 (BYTE *) &dwValue, &dummyLen);
1144 if (code == ERROR_SUCCESS) {
1145 cm_deleteReadOnly = (unsigned short) dwValue;
1147 afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
1150 dummyLen = sizeof(DWORD);
1151 code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
1152 (BYTE *) &dwValue, &dummyLen);
1153 if (code == ERROR_SUCCESS) {
1154 cm_BPlusTrees = (unsigned short) dwValue;
1156 afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
1158 if (cm_BPlusTrees && !cm_InitBPlusDir()) {
1160 afsi_log("CM BPlusTree initialization failure; disabled for this session");
1163 afsi_log("CM BPlusTrees is not supported");
1166 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0,
1167 ®Type, NULL, &dummyLen) == ERROR_SUCCESS) &&
1168 (regType == REG_MULTI_SZ))
1171 dummyLen += 3; /* in case the source string is not nul terminated */
1172 pSz = malloc(dummyLen);
1173 if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, ®Type,
1174 (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
1175 (regType == REG_MULTI_SZ))
1180 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
1182 smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
1184 for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
1185 smb_ExecutableExtensions[cnt] = p;
1186 afsi_log("PrefetchExecutableExtension: \"%S\"", p);
1188 smb_ExecutableExtensions[cnt] = NULL;
1191 if (!smb_ExecutableExtensions)
1194 if (!smb_ExecutableExtensions)
1195 afsi_log("No PrefetchExecutableExtensions");
1197 dummyLen = sizeof(DWORD);
1198 code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
1199 (BYTE *) &dwValue, &dummyLen);
1200 if (code == ERROR_SUCCESS) {
1201 cm_OfflineROIsValid = (unsigned short) dwValue;
1203 afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
1205 dummyLen = sizeof(DWORD);
1206 code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
1207 (BYTE *) &dwValue, &dummyLen);
1208 if (code == ERROR_SUCCESS) {
1209 cm_giveUpAllCBs = (unsigned short) dwValue;
1211 afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
1213 dummyLen = sizeof(DWORD);
1214 code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
1215 (BYTE *) &dwValue, &dummyLen);
1216 if (code == ERROR_SUCCESS) {
1217 cm_followBackupPath = (unsigned short) dwValue;
1219 afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
1221 dummyLen = sizeof(DWORD);
1222 code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
1223 (BYTE *) &dwValue, &dummyLen);
1224 if (code == ERROR_SUCCESS) {
1225 cm_accessPerFileCheck = (int) dwValue;
1227 afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
1229 dummyLen = sizeof(DWORD);
1230 code = RegQueryValueEx(parmKey, "ReadOnlyVolumeVersioning", NULL, NULL,
1231 (BYTE *) &dwValue, &dummyLen);
1232 if (code == ERROR_SUCCESS) {
1233 cm_readonlyVolumeVersioning = (unsigned short) dwValue;
1235 afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
1237 RegCloseKey (parmKey);
1239 cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
1241 /* get network related info */
1242 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1243 code = syscfg_GetIFInfo(&cm_noIPAddr,
1244 cm_IPAddr, cm_SubnetMask,
1245 cm_NetMtu, cm_NetFlags);
1247 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
1248 afsi_log("syscfg_GetIFInfo error code %d", code);
1250 afsi_log("First Network address %x SubnetMask %x",
1251 cm_IPAddr[0], cm_SubnetMask[0]);
1254 * Save client configuration for GetCacheConfig requests
1256 cm_initParams.nChunkFiles = 0;
1257 cm_initParams.nStatCaches = stats;
1258 cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
1259 cm_initParams.nVolumeCaches = volumes;
1260 cm_initParams.firstChunkSize = cm_chunkSize;
1261 cm_initParams.otherChunkSize = cm_chunkSize;
1262 cm_initParams.cacheSize = cacheSize;
1263 cm_initParams.setTime = 0;
1264 cm_initParams.memCache = 1;
1266 /* init user daemon, and other packages */
1279 cm_InitNormalization();
1281 code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
1282 afsi_log("cm_InitMappedMemory code %x", code);
1284 *reasonP = "error initializing cache file";
1288 #ifdef AFS_AFSDB_ENV
1289 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
1290 if (cm_InitDNS(cm_dnsEnabled) == -1)
1291 cm_dnsEnabled = 0; /* init failed, so deactivate */
1292 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
1296 /* Set RX parameters before initializing RX */
1299 afsi_log("rx_SetNoJumbo successful");
1302 if ( rx_mtu != -1 ) {
1303 extern void rx_SetMaxMTU(int);
1305 rx_SetMaxMTU(rx_mtu);
1306 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
1309 if ( rx_udpbufsize != -1 ) {
1310 rx_SetUdpBufSize(rx_udpbufsize);
1311 afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
1314 /* initialize RX, and tell it to listen to the callbackport,
1315 * which is used for callback RPC messages.
1317 code = rx_Init(htons(cm_callbackport));
1319 afsi_log("rx_Init code %x - retrying with a random port number", code);
1322 afsi_log("rx_Init code %x", code);
1324 *reasonP = "afsd: failed to init rx client";
1328 /* create an unauthenticated service #1 for callbacks */
1329 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1330 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
1331 RXAFSCB_ExecuteRequest);
1332 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1333 if (serverp == NULL) {
1334 *reasonP = "unknown error";
1337 rx_SetMinProcs(serverp, 2);
1338 rx_SetMaxProcs(serverp, 4);
1339 rx_SetCheckReach(serverp, 1);
1341 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
1342 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
1343 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
1344 afsi_log("rx_NewService addr %x", PtrToUlong(serverp));
1345 if (serverp == NULL) {
1346 *reasonP = "unknown error";
1349 rx_SetMinProcs(serverp, 2);
1350 rx_SetMaxProcs(serverp, 4);
1352 /* start server threads, *not* donating this one to the pool */
1354 afsi_log("rx_StartServer");
1356 if (rx_enable_peer_stats)
1357 rx_enablePeerRPCStats();
1359 if (rx_enable_process_stats)
1360 rx_enableProcessRPCStats();
1362 code = cm_GetRootCellName(rootCellName);
1363 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
1364 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
1365 if (code != 0 && !cm_freelanceEnabled)
1367 *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
1370 else if (cm_freelanceEnabled)
1371 cm_data.rootCellp = NULL;
1373 if (code == 0 && !cm_freelanceEnabled)
1375 cm_data.rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
1376 afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
1377 if (cm_data.rootCellp == NULL)
1379 *reasonP = "can't find root cell in " AFS_CELLSERVDB;
1384 #ifdef AFS_FREELANCE_CLIENT
1385 if (cm_freelanceEnabled)
1389 /* Initialize the RPC server for session keys */
1392 /* Initialize the RPC server for pipe services */
1395 afsd_InitServerPreferences();
1397 code = afsd_InitRoot(reasonP);
1402 int afsd_ShutdownCM(void)
1406 cm_ReleaseSCache(cm_data.rootSCachep);
1415 int afsd_InitDaemons(char **reasonP)
1417 cm_InitDaemon(numBkgD);
1418 afsi_log("cm_InitDaemon complete");
1423 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1430 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1431 0, KEY_QUERY_VALUE, &parmKey);
1432 if (code == ERROR_SUCCESS) {
1433 dummyLen = sizeof(DWORD);
1434 code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL,
1435 (BYTE *) &dwValue, &dummyLen);
1436 if (code == ERROR_SUCCESS)
1437 smb_StoreAnsiFilenames = dwValue ? 1 : 0;
1438 afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
1440 dummyLen = sizeof(DWORD);
1441 code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
1442 (BYTE *) &dwValue, &dummyLen);
1443 if (code == ERROR_SUCCESS)
1444 smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
1445 afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
1447 dummyLen = sizeof(DWORD);
1448 code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
1449 (BYTE *) &dwValue, &dummyLen);
1450 if (code == ERROR_SUCCESS) {
1451 /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
1452 if (dwValue > cm_chunkSize)
1453 smb_AsyncStoreSize = cm_chunkSize;
1454 else if (dwValue < cm_data.buf_blockSize)
1455 smb_AsyncStoreSize = cm_data.buf_blockSize;
1457 smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
1459 smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
1460 afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
1462 RegCloseKey (parmKey);
1465 /* Do this last so that we don't handle requests before init is done.
1466 * Here we initialize the SMB listener.
1468 smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
1469 afsi_log("smb_Init complete");
1482 #pragma pack( push, before_imagehlp, 8 )
1483 #include <imagehlp.h>
1484 #pragma pack( pop, before_imagehlp )
1486 #define MAXNAMELEN 1024
1488 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1490 HANDLE hProcess = GetCurrentProcess();
1492 #if defined(_AMD64_)
1494 #elif defined(_X86_)
1498 char functionName[MAXNAMELEN];
1500 IMAGEHLP_MODULE Module;
1504 IMAGEHLP_SYMBOL *pSym;
1506 afsi_log_useTimestamp = 0;
1508 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1510 memset( &s, '\0', sizeof s );
1511 if (!SymInitialize(hProcess, NULL, 1) )
1513 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1515 SymCleanup( hProcess );
1521 symOptions = SymGetOptions();
1522 symOptions |= SYMOPT_LOAD_LINES;
1523 symOptions &= ~SYMOPT_UNDNAME;
1524 SymSetOptions( symOptions );
1527 * init STACKFRAME for first call
1528 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1529 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1530 * and good riddance.
1532 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1533 #error The STACKFRAME initialization in afsd_printStack() for this platform
1534 #error must be properly configured
1535 #elif defined(_AMD64_)
1536 s.AddrPC.Offset = c->Rip;
1537 s.AddrPC.Mode = AddrModeFlat;
1538 s.AddrFrame.Offset = c->Rbp;
1539 s.AddrFrame.Mode = AddrModeFlat;
1541 s.AddrPC.Offset = c->Eip;
1542 s.AddrPC.Mode = AddrModeFlat;
1543 s.AddrFrame.Offset = c->Ebp;
1544 s.AddrFrame.Mode = AddrModeFlat;
1547 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1548 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1549 pSym->MaxNameLength = MAXNAMELEN;
1551 memset( &Line, '\0', sizeof Line );
1552 Line.SizeOfStruct = sizeof Line;
1554 memset( &Module, '\0', sizeof Module );
1555 Module.SizeOfStruct = sizeof Module;
1559 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1561 for ( frameNum = 0; ; ++ frameNum )
1564 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1565 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1566 * ERROR_NOACCESS (998), you can assume that either you are done, or
1567 * that the stack is so hosed that the next deeper frame could not be
1570 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1571 NULL, SymFunctionTableAccess, SymGetModuleBase,
1575 /* display its contents */
1576 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1577 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1578 s.AddrPC.Offset, s.AddrReturn.Offset,
1579 s.AddrFrame.Offset, s.AddrStack.Offset );
1581 if ( s.AddrPC.Offset == 0 )
1583 afsi_log("(-nosymbols- PC == 0)" );
1587 /* show procedure info from a valid PC */
1588 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1590 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1592 afsi_log("SymGetSymFromAddr(): errno = %lu",
1598 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1600 afsi_log("%s", functionName );
1604 afsi_log(" %+ld bytes", (long) offset);
1608 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1610 if (GetLastError() != ERROR_INVALID_ADDRESS)
1612 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1618 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1619 Line.LineNumber, offset);
1623 /* no return address means no deeper stackframe */
1624 if (s.AddrReturn.Offset == 0)
1631 if (GetLastError() != 0)
1633 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1636 SymCleanup(hProcess);
1641 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1642 static DWORD afsd_crtDbgBreaks[256];
1645 static EFaultRepRetVal (WINAPI *pReportFault)(LPEXCEPTION_POINTERS pep, DWORD dwMode) = NULL;
1646 static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,
1647 MINIDUMP_TYPE DumpType,
1648 PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
1649 PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
1650 PMINIDUMP_CALLBACK_INFORMATION CallbackParam) = NULL;
1659 code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
1660 if ( code == 0 || code > sizeof(wd) )
1662 if (!GetWindowsDirectory(wd, sizeof(wd)))
1665 StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
1666 return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
1667 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
1671 GenerateMiniDump(PEXCEPTION_POINTERS ep)
1673 if (IsDebuggerPresent())
1678 // Generate exception to get proper context in dump
1681 RaiseException(DBG_CONTINUE, 0, 0, NULL);
1683 __except(GenerateMiniDump(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION)
1689 MINIDUMP_EXCEPTION_INFORMATION eInfo;
1690 HANDLE hFile = NULL;
1691 HMODULE hDbgHelp = NULL;
1693 hDbgHelp = LoadLibrary("Dbghelp.dll");
1694 if ( hDbgHelp == NULL )
1697 (FARPROC) pMiniDumpWriteDump = GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
1698 if ( pMiniDumpWriteDump == NULL ) {
1699 FreeLibrary(hDbgHelp);
1703 hFile = OpenDumpFile();
1710 DWORD dwMiniDumpType = MiniDumpWithDataSegs;
1712 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
1713 0, KEY_QUERY_VALUE, &parmKey);
1714 if (code == ERROR_SUCCESS) {
1715 dummyLen = sizeof(DWORD);
1716 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
1717 (BYTE *) &dwValue, &dummyLen);
1718 if (code == ERROR_SUCCESS)
1719 dwMiniDumpType = dwValue;
1720 RegCloseKey (parmKey);
1723 eInfo.ThreadId = GetCurrentThreadId();
1724 eInfo.ExceptionPointers = ep;
1725 eInfo.ClientPointers = FALSE;
1727 pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
1728 hFile, dwMiniDumpType, ep ? &eInfo : NULL,
1733 FreeLibrary(hDbgHelp);
1737 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1741 BOOL allocRequestBrk = FALSE;
1743 HMODULE hLib = NULL;
1745 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1746 ep->ExceptionRecord->ExceptionCode,
1747 ep->ExceptionRecord->ExceptionAddress);
1750 if (afsd_crtDbgBreakCurrent &&
1751 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1753 allocRequestBrk = TRUE;
1754 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1758 /* save context if we want to print the stack information */
1759 context = *ep->ContextRecord;
1761 afsd_printStack(GetCurrentThread(), &context);
1763 GenerateMiniDump(ep);
1765 hLib = LoadLibrary("Faultrep.dll");
1767 (FARPROC) pReportFault = GetProcAddress(hLib, "ReportFault");
1769 pReportFault(ep, 0);
1773 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1775 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1778 if (allocRequestBrk)
1780 afsd_crtDbgBreakCurrent++;
1781 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1785 ep->ContextRecord->Eip++;
1787 #if defined(_AMD64_)
1788 ep->ContextRecord->Rip++;
1790 return EXCEPTION_CONTINUE_EXECUTION;
1794 return EXCEPTION_CONTINUE_SEARCH;
1798 void afsd_SetUnhandledExceptionFilter()
1801 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1806 void afsd_DbgBreakAllocInit()
1808 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1809 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1812 void afsd_DbgBreakAdd(DWORD requestNumber)
1815 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1817 if (afsd_crtDbgBreaks[i] == -1)
1822 afsd_crtDbgBreaks[i] = requestNumber;
1824 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);