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>
25 #include <rx\rx_null.h>
27 #include <WINNT/syscfg.h>
31 #include "lanahelper.h"
34 extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
35 extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
37 extern afs_int32 cryptall;
39 char AFSConfigKeyName[] =
40 "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters";
44 char cm_rootVolumeName[64];
45 DWORD cm_rootVolumeNameLen;
46 cm_volume_t *cm_rootVolumep = NULL;
47 cm_cell_t *cm_rootCellp = NULL;
49 cm_scache_t *cm_rootSCachep;
50 char cm_mountRoot[1024];
51 DWORD cm_mountRootLen;
54 #ifdef AFS_FREELANCE_CLIENT
56 #endif /* freelance */
69 char cm_HostName[200];
72 char cm_NetbiosName[MAX_NB_NAME_LENGTH];
74 char cm_CachePath[200];
75 DWORD cm_CachePathLen;
77 BOOL isGateway = FALSE;
79 BOOL reportSessionStartups = FALSE;
81 cm_initparams_v1 cm_initParams;
84 int cm_sysNameCount = 0;
85 char *cm_sysNameList[MAXNUMSYSNAMES];
87 DWORD TraceOption = 0;
90 * AFSD Initialization Log
92 * This is distinct from the regular debug logging facility.
93 * Log items go directly to a file, not to an array in memory, so that even
94 * if AFSD crashes, the log can be inspected.
100 int cm_dnsEnabled = 1;
103 char cm_NetBiosName[32];
105 extern initUpperCaseTable();
106 void afsd_initUpperCaseTable()
108 initUpperCaseTable();
115 char t[100], u[100], *p, *path;
121 DWORD maxLogSize = 100 * 1024;
123 afsi_file = INVALID_HANDLE_VALUE;
126 StringCbCopyA(wd, sizeof(wd), getenv("TEMP"));
130 code = GetWindowsDirectory(wd, sizeof(wd));
131 if (code == 0) return;
133 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
134 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
135 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
136 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
138 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
139 0, KEY_QUERY_VALUE, &parmKey);
140 if (code == ERROR_SUCCESS) {
141 dummyLen = sizeof(maxLogSize);
142 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
143 (BYTE *) &maxLogSize, &dummyLen);
144 RegCloseKey (parmKey);
148 dwLow = GetFileSize( afsi_file, &dwHigh );
149 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
150 CloseHandle(afsi_file);
151 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
152 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
156 SetFilePointer(afsi_file, 0, NULL, FILE_END);
157 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
158 StringCbCatA(t, sizeof(t), ": Create log file\n");
159 StringCbCatA(u, sizeof(u), ": Created log file\n");
160 WriteFile(afsi_file, t, strlen(t), &zilch, NULL);
161 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
163 path = getenv("PATH");
164 WriteFile(afsi_file, p, strlen(p), &zilch, NULL);
165 WriteFile(afsi_file, path, strlen(path), &zilch, NULL);
166 WriteFile(afsi_file, "\n", 1, &zilch, NULL);
169 static int afsi_log_useTimestamp = 1;
172 afsi_log(char *pattern, ...)
174 char s[256], t[100], d[100], u[512];
177 va_start(ap, pattern);
179 StringCbVPrintfA(s, sizeof(s), pattern, ap);
180 if ( afsi_log_useTimestamp ) {
181 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
182 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
183 StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
184 if (afsi_file != INVALID_HANDLE_VALUE)
185 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
190 if (afsi_file != INVALID_HANDLE_VALUE)
191 WriteFile(afsi_file, s, strlen(s), &zilch, NULL);
196 * Standard AFSD trace
199 void afsd_ForceTrace(BOOL flush)
208 len = GetTempPath(sizeof(buf)-10, buf);
209 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
210 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
211 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
212 if (handle == INVALID_HANDLE_VALUE) {
214 osi_panic("Cannot create log file", __FILE__, __LINE__);
216 osi_LogPrint(afsd_logp, handle);
218 FlushFileBuffers(handle);
223 configureBackConnectionHostNames(void)
225 /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
226 * there is a restriction on the use of SMB authentication on loopback connections.
227 * There are two work arounds available:
229 * (1) We can disable the check for matching host names. This does not
231 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
232 * "DisableLoopbackCheck"=dword:00000001
234 * (2) We can add the AFS SMB/CIFS service name to an approved list. This
235 * does require a reboot:
236 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
237 * "BackConnectionHostNames"=multi-sz
239 * The algorithm will be:
240 * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
241 * (2a) If not, add it to the list. (This will not take effect until the next reboot.)
242 * (2b1) and check to see if DisableLoopbackCheck is set.
243 * (2b2) If not set, set the DisableLoopbackCheck value to 0x1
244 * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck
245 * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
246 * check for the UnsetDisableLoopbackCheck value.
247 * If set, set the DisableLoopbackCheck flag to 0x0
248 * and delete the UnsetDisableLoopbackCheck value
256 PBYTE pHostNames = NULL, pName;
257 BOOL bNameFound = FALSE;
259 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
260 "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
263 &hkMSV10) == ERROR_SUCCESS )
265 if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) {
266 pHostNames = malloc(dwSize + strlen(cm_NetbiosName) + 1);
267 RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, pHostNames, &dwSize);
269 for (pName = pHostNames; *pName ; pName += strlen(pName) + 1)
271 if ( !stricmp(pName, cm_NetbiosName) ) {
280 pName = pHostNames = malloc(strlen(cm_NetbiosName) + 2);
283 strcpy(pName, cm_NetbiosName);
284 pName += strlen(cm_NetbiosName) + 1;
285 *pName = '\0'; /* add a second nul terminator */
287 dwType = REG_MULTI_SZ;
288 dwSize += strlen(cm_NetbiosName) + 1;
289 RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
291 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
292 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
295 &hkLsa) == ERROR_SUCCESS )
297 dwSize = sizeof(DWORD);
298 if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) != ERROR_SUCCESS ||
301 dwSize = sizeof(DWORD);
303 RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
305 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
306 "SOFTWARE\\OpenAFS\\Client",
309 REG_OPTION_NON_VOLATILE,
313 NULL) == ERROR_SUCCESS) {
316 dwSize = sizeof(DWORD);
318 RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
319 RegCloseKey(hkClient);
325 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
326 "SOFTWARE\\OpenAFS\\Client",
329 REG_OPTION_NON_VOLATILE,
333 NULL) == ERROR_SUCCESS) {
335 dwSize = sizeof(DWORD);
336 if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) == ERROR_SUCCESS &&
338 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
339 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
342 &hkLsa) == ERROR_SUCCESS )
344 RegDeleteValue(hkLsa, "DisableLoopbackCheck");
348 RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
349 RegCloseKey(hkClient);
352 RegCloseKey(hkMSV10);
358 * AFSD Initialization
361 int afsd_InitCM(char **reasonP)
371 long rx_mtu, rx_nojumbo;
373 char rootCellName[256];
374 struct rx_service *serverp;
375 static struct rx_securityClass *nullServerSecurityClassp;
383 /*int freelanceEnabled;*/
385 lana_number_t lanaNum;
388 WSAStartup(0x0101, &WSAjunk);
390 afsd_initUpperCaseTable();
392 /* setup osidebug server at RPC slot 1000 */
393 osi_LongToUID(1000, &debugID);
394 code = osi_InitDebug(&debugID);
395 afsi_log("osi_InitDebug code %d", code);
397 // osi_LockTypeSetDefault("stat"); /* comment this out for speed *
399 *reasonP = "unknown error";
404 gethostname(cm_HostName, sizeof(cm_HostName));
405 afsi_log("gethostname %s", cm_HostName);
406 thp = gethostbyname(cm_HostName);
407 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
409 /* seed random number generator */
410 srand(ntohl(cm_HostAddr));
412 /* Look up configuration parameters in Registry */
413 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
414 0, KEY_QUERY_VALUE, &parmKey);
415 if (code != ERROR_SUCCESS) {
416 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
417 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
418 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
419 StringCbPrintfA(buf, sizeof(buf),
420 "Failure in configuration while opening Registry: %s",
422 osi_panic(buf, __FILE__, __LINE__);
425 dummyLen = sizeof(maxcpus);
426 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
427 (BYTE *) &maxcpus, &dummyLen);
428 if (code == ERROR_SUCCESS) {
430 DWORD_PTR processAffinityMask, systemAffinityMask;
432 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
433 FALSE, GetCurrentProcessId());
434 if ( hProcess != NULL &&
435 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
438 DWORD_PTR mask, newAffinityMask;
445 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
446 if ( processAffinityMask & mask ) {
447 newAffinityMask |= mask;
453 SetProcessAffinityMask(hProcess, newAffinityMask);
454 CloseHandle(hProcess);
455 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
457 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
461 dummyLen = sizeof(TraceOption);
462 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
463 (BYTE *) &TraceOption, &dummyLen);
464 afsi_log("Event Log Tracing = %lX", TraceOption);
466 dummyLen = sizeof(traceBufSize);
467 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
468 (BYTE *) &traceBufSize, &dummyLen);
469 if (code == ERROR_SUCCESS)
470 afsi_log("Trace Buffer size %d", traceBufSize);
472 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
473 afsi_log("Default trace buffer size %d", traceBufSize);
476 /* setup and enable debug log */
477 afsd_logp = osi_LogCreate("afsd", traceBufSize);
478 afsi_log("osi_LogCreate log addr %x", (int)afsd_logp);
479 osi_LogEnable(afsd_logp);
482 osi_Log0(afsd_logp, "Log init");
484 dummyLen = sizeof(cacheSize);
485 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
486 (BYTE *) &cacheSize, &dummyLen);
487 if (code == ERROR_SUCCESS)
488 afsi_log("Cache size %d", cacheSize);
490 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
491 afsi_log("Default cache size %d", cacheSize);
494 dummyLen = sizeof(logChunkSize);
495 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
496 (BYTE *) &logChunkSize, &dummyLen);
497 if (code == ERROR_SUCCESS) {
498 if (logChunkSize < 12 || logChunkSize > 30) {
499 afsi_log("Invalid chunk size %d, using default",
501 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
503 afsi_log("Chunk size %d", logChunkSize);
505 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
506 afsi_log("Default chunk size %d", logChunkSize);
508 cm_logChunkSize = logChunkSize;
509 cm_chunkSize = 1 << logChunkSize;
511 dummyLen = sizeof(numBkgD);
512 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
513 (BYTE *) &numBkgD, &dummyLen);
514 if (code == ERROR_SUCCESS)
515 afsi_log("%d background daemons", numBkgD);
517 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
518 afsi_log("Defaulting to %d background daemons", numBkgD);
521 dummyLen = sizeof(numSvThreads);
522 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
523 (BYTE *) &numSvThreads, &dummyLen);
524 if (code == ERROR_SUCCESS)
525 afsi_log("%d server threads", numSvThreads);
527 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
528 afsi_log("Defaulting to %d server threads", numSvThreads);
531 dummyLen = sizeof(stats);
532 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
533 (BYTE *) &stats, &dummyLen);
534 if (code == ERROR_SUCCESS)
535 afsi_log("Status cache size %d", stats);
537 stats = CM_CONFIGDEFAULT_STATS;
538 afsi_log("Default status cache size %d", stats);
541 dummyLen = sizeof(ltt);
542 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
543 (BYTE *) <t, &dummyLen);
544 if (code == ERROR_SUCCESS)
545 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
548 afsi_log("Logoff token transfer on by default");
550 smb_LogoffTokenTransfer = ltt;
551 afsi_log("Logoff token transfer is currently ignored");
554 dummyLen = sizeof(ltto);
555 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
556 NULL, NULL, (BYTE *) <to, &dummyLen);
557 if (code == ERROR_SUCCESS)
558 afsi_log("Logoff token tranfer timeout %d seconds",
562 afsi_log("Default logoff token transfer timeout 10 seconds");
567 smb_LogoffTransferTimeout = ltto;
568 afsi_log("Default logoff token is currently ignored");
570 dummyLen = sizeof(cm_rootVolumeName);
571 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
572 cm_rootVolumeName, &dummyLen);
573 if (code == ERROR_SUCCESS)
574 afsi_log("Root volume %s", cm_rootVolumeName);
576 StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
577 afsi_log("Default root volume name root.afs");
580 cm_mountRootLen = sizeof(cm_mountRoot);
581 code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
582 cm_mountRoot, &cm_mountRootLen);
583 if (code == ERROR_SUCCESS) {
584 afsi_log("Mount root %s", cm_mountRoot);
585 cm_mountRootLen = strlen(cm_mountRoot);
587 StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
592 dummyLen = sizeof(buf);
593 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
595 if (code == ERROR_SUCCESS && buf[0]) {
596 if(regType == REG_EXPAND_SZ) {
597 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
598 if(dummyLen > sizeof(cm_CachePath)) {
599 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
600 osi_panic("CachePath too long", __FILE__, __LINE__);
603 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
605 afsi_log("Cache path %s", cm_CachePath);
607 GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath));
608 cm_CachePath[2] = 0; /* get drive letter only */
609 StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache");
610 afsi_log("Default cache path %s", cm_CachePath);
613 dummyLen = sizeof(virtualCache);
614 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
615 &virtualCache, &dummyLen);
616 if (code == ERROR_SUCCESS && virtualCache) {
617 buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL;
619 buf_cacheType = CM_BUF_CACHETYPE_FILE;
621 afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL"));
623 dummyLen = sizeof(traceOnPanic);
624 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
625 (BYTE *) &traceOnPanic, &dummyLen);
626 if (code == ERROR_SUCCESS)
627 afsi_log("Set to %s on panic",
628 traceOnPanic ? "trap" : "not trap");
634 dummyLen = sizeof(reportSessionStartups);
635 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
636 (BYTE *) &reportSessionStartups, &dummyLen);
637 if (code == ERROR_SUCCESS)
638 afsi_log("Session startups %s be recorded in the Event Log",
639 reportSessionStartups ? "will" : "will not");
641 reportSessionStartups = 0;
645 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
646 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
647 cm_sysNameList[i][0] = '\0';
649 cm_sysName = cm_sysNameList[0];
651 dummyLen = MAXSYSNAME;
652 code = RegQueryValueEx(parmKey, "SysName", NULL, NULL,
653 cm_sysName, &dummyLen);
654 if (code == ERROR_SUCCESS)
655 afsi_log("Sys name %s", cm_sysName);
657 StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40");
658 afsi_log("Default sys name %s", cm_sysName);
662 dummyLen = sizeof(cryptall);
663 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
664 (BYTE *) &cryptall, &dummyLen);
665 if (code == ERROR_SUCCESS)
666 afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
668 cryptall = rxkad_clear;
669 afsi_log("Default SecurityLevel is clear");
673 dummyLen = sizeof(cm_dnsEnabled);
674 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
675 (BYTE *) &cm_dnsEnabled, &dummyLen);
676 if (code == ERROR_SUCCESS) {
677 afsi_log("DNS %s be used to find AFS cell servers",
678 cm_dnsEnabled ? "will" : "will not");
681 cm_dnsEnabled = 1; /* default on */
682 afsi_log("Default to use DNS to find AFS cell servers");
684 #else /* AFS_AFSDB_ENV */
685 afsi_log("AFS not built with DNS support to find AFS cell servers");
686 #endif /* AFS_AFSDB_ENV */
688 #ifdef AFS_FREELANCE_CLIENT
689 dummyLen = sizeof(cm_freelanceEnabled);
690 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
691 (BYTE *) &cm_freelanceEnabled, &dummyLen);
692 if (code == ERROR_SUCCESS) {
693 afsi_log("Freelance client feature %s activated",
694 cm_freelanceEnabled ? "is" : "is not");
697 cm_freelanceEnabled = 0; /* default off */
699 #endif /* AFS_FREELANCE_CLIENT */
701 dummyLen = sizeof(buf);
702 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
703 (BYTE *) &buf, &dummyLen);
704 if (code == ERROR_SUCCESS) {
705 DWORD len = ExpandEnvironmentStrings(buf, cm_NetBiosName, MAX_NB_NAME_LENGTH);
706 if ( len > 0 && len <= MAX_NB_NAME_LENGTH ) {
707 afsi_log("Explicit NetBios name is used %s", cm_NetBiosName);
709 afsi_log("Unable to Expand Explicit NetBios name: %s", buf);
710 cm_NetBiosName[0] = 0; /* turn it off */
714 cm_NetBiosName[0] = 0; /* default off */
717 dummyLen = sizeof(smb_hideDotFiles);
718 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
719 (BYTE *) &smb_hideDotFiles, &dummyLen);
720 if (code != ERROR_SUCCESS) {
721 smb_hideDotFiles = 1; /* default on */
723 afsi_log("Dot files/dirs will %sbe marked hidden",
724 smb_hideDotFiles ? "" : "not ");
726 dummyLen = sizeof(smb_maxMpxRequests);
727 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
728 (BYTE *) &smb_maxMpxRequests, &dummyLen);
729 if (code != ERROR_SUCCESS) {
730 smb_maxMpxRequests = 50;
732 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
734 dummyLen = sizeof(smb_maxVCPerServer);
735 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
736 (BYTE *) &smb_maxVCPerServer, &dummyLen);
737 if (code != ERROR_SUCCESS) {
738 smb_maxVCPerServer = 100;
740 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
742 dummyLen = sizeof(smb_authType);
743 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
744 (BYTE *) &smb_authType, &dummyLen);
746 if (code != ERROR_SUCCESS ||
747 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
748 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
750 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
752 dummyLen = sizeof(rx_nojumbo);
753 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
754 (BYTE *) &rx_nojumbo, &dummyLen);
755 if (code != ERROR_SUCCESS) {
759 afsi_log("RX Jumbograms are disabled");
761 dummyLen = sizeof(rx_mtu);
762 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
763 (BYTE *) &rx_mtu, &dummyLen);
764 if (code != ERROR_SUCCESS || !rx_mtu) {
768 afsi_log("RX maximum MTU is %d", rx_mtu);
770 dummyLen = sizeof(ConnDeadtimeout);
771 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
772 (BYTE *) &ConnDeadtimeout, &dummyLen);
773 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
775 dummyLen = sizeof(HardDeadtimeout);
776 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
777 (BYTE *) &HardDeadtimeout, &dummyLen);
778 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
780 RegCloseKey (parmKey);
782 /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
783 if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
784 LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
787 afsi_log("LAN adapter number %d", LANadapter);
789 afsi_log("LAN adapter number not determined");
792 afsi_log("Set for gateway service");
794 afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
796 /* something went horribly wrong. We can't proceed without a netbios name */
797 StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
798 osi_panic(buf, __FILE__, __LINE__);
801 /* setup early variables */
802 /* These both used to be configurable. */
804 buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE;
806 /* turn from 1024 byte units into memory blocks */
807 cacheBlocks = (cacheSize * 1024) / buf_bufferSize;
809 /* get network related info */
810 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
811 code = syscfg_GetIFInfo(&cm_noIPAddr,
812 cm_IPAddr, cm_SubnetMask,
813 cm_NetMtu, cm_NetFlags);
815 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
816 afsi_log("syscfg_GetIFInfo error code %d", code);
818 afsi_log("First Network address %x SubnetMask %x",
819 cm_IPAddr[0], cm_SubnetMask[0]);
822 * Save client configuration for GetCacheConfig requests
824 cm_initParams.nChunkFiles = 0;
825 cm_initParams.nStatCaches = stats;
826 cm_initParams.nDataCaches = 0;
827 cm_initParams.nVolumeCaches = 0;
828 cm_initParams.firstChunkSize = cm_chunkSize;
829 cm_initParams.otherChunkSize = cm_chunkSize;
830 cm_initParams.cacheSize = cacheSize;
831 cm_initParams.setTime = 0;
832 cm_initParams.memCache = 0;
834 /* Set RX parameters before initializing RX */
837 afsi_log("rx_SetNoJumbo successful");
840 if ( rx_mtu != -1 ) {
841 rx_SetMaxMTU(rx_mtu);
842 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
845 /* Open Microsoft Firewall to allow in port 7001 */
846 icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT);
848 /* Ensure the AFS Netbios Name is registered to allow loopback access */
849 configureBackConnectionHostNames();
851 /* initialize RX, and tell it to listen to port 7001, which is used for
852 * callback RPC messages.
854 code = rx_Init(htons(7001));
855 afsi_log("rx_Init code %x", code);
857 *reasonP = "afsd: failed to init rx client on port 7001";
861 /* Initialize the RPC server for session keys */
864 /* create an unauthenticated service #1 for callbacks */
865 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
866 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
867 RXAFSCB_ExecuteRequest);
868 afsi_log("rx_NewService addr %x", (int)serverp);
869 if (serverp == NULL) {
870 *reasonP = "unknown error";
874 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
875 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
876 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
877 afsi_log("rx_NewService addr %x", (int)serverp);
878 if (serverp == NULL) {
879 *reasonP = "unknown error";
883 /* start server threads, *not* donating this one to the pool */
885 afsi_log("rx_StartServer");
887 /* init user daemon, and other packages */
890 cm_InitACLCache(2*stats);
906 cm_InitSCache(stats);
908 code = cm_InitDCache(0, cacheBlocks);
909 afsi_log("cm_InitDCache code %x", code);
911 *reasonP = "error initializing cache";
916 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
917 if (cm_InitDNS(cm_dnsEnabled) == -1)
918 cm_dnsEnabled = 0; /* init failed, so deactivate */
919 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
923 code = cm_GetRootCellName(rootCellName);
924 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
925 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
926 if (code != 0 && !cm_freelanceEnabled)
928 *reasonP = "can't find root cell name in afsd.ini";
931 else if (cm_freelanceEnabled)
934 if (code == 0 && !cm_freelanceEnabled)
936 cm_rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
937 afsi_log("cm_GetCell addr %x", (int)cm_rootCellp);
938 if (cm_rootCellp == NULL)
940 *reasonP = "can't find root cell in afsdcell.ini";
945 #ifdef AFS_FREELANCE_CLIENT
946 if (cm_freelanceEnabled)
953 int afsd_InitDaemons(char **reasonP)
960 /* this should really be in an init daemon from here on down */
962 if (!cm_freelanceEnabled) {
963 osi_Log0(afsd_logp, "Loading Root Volume from cell");
964 code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
965 &req, CM_FLAG_CREATE, &cm_rootVolumep);
966 afsi_log("cm_GetVolumeByName code %x root vol %x", code,
967 (code ? (cm_volume_t *)-1 : cm_rootVolumep));
969 *reasonP = "can't find root volume in root cell";
974 /* compute the root fid */
975 if (!cm_freelanceEnabled) {
976 cm_rootFid.cell = cm_rootCellp->cellID;
977 cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep);
978 cm_rootFid.vnode = 1;
979 cm_rootFid.unique = 1;
982 cm_FakeRootFid(&cm_rootFid);
984 code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req);
985 afsi_log("cm_GetSCache code %x scache %x", code,
986 (code ? (cm_scache_t *)-1 : cm_rootSCachep));
988 *reasonP = "unknown error";
992 cm_InitDaemon(numBkgD);
993 afsi_log("cm_InitDaemon");
998 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1000 /* Do this last so that we don't handle requests before init is done.
1001 * Here we initialize the SMB listener.
1003 smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
1004 afsi_log("smb_Init");
1017 #pragma pack( push, before_imagehlp, 8 )
1018 #include <imagehlp.h>
1019 #pragma pack( pop, before_imagehlp )
1021 #define MAXNAMELEN 1024
1023 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1025 HANDLE hProcess = GetCurrentProcess();
1029 char functionName[MAXNAMELEN];
1031 IMAGEHLP_MODULE Module;
1035 IMAGEHLP_SYMBOL *pSym;
1037 afsi_log_useTimestamp = 0;
1039 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1041 memset( &s, '\0', sizeof s );
1042 if (!SymInitialize(hProcess, NULL, 1) )
1044 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1046 SymCleanup( hProcess );
1052 symOptions = SymGetOptions();
1053 symOptions |= SYMOPT_LOAD_LINES;
1054 symOptions &= ~SYMOPT_UNDNAME;
1055 SymSetOptions( symOptions );
1058 * init STACKFRAME for first call
1059 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1060 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1061 * and good riddance.
1063 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1064 #error The STACKFRAME initialization in afsd_printStack() for this platform
1065 #error must be properly configured
1067 s.AddrPC.Offset = c->Eip;
1068 s.AddrPC.Mode = AddrModeFlat;
1069 s.AddrFrame.Offset = c->Ebp;
1070 s.AddrFrame.Mode = AddrModeFlat;
1073 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1074 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1075 pSym->MaxNameLength = MAXNAMELEN;
1077 memset( &Line, '\0', sizeof Line );
1078 Line.SizeOfStruct = sizeof Line;
1080 memset( &Module, '\0', sizeof Module );
1081 Module.SizeOfStruct = sizeof Module;
1085 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1087 for ( frameNum = 0; ; ++ frameNum )
1090 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1091 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1092 * ERROR_NOACCESS (998), you can assume that either you are done, or
1093 * that the stack is so hosed that the next deeper frame could not be
1096 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1097 NULL, SymFunctionTableAccess, SymGetModuleBase,
1101 /* display its contents */
1102 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1103 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1104 s.AddrPC.Offset, s.AddrReturn.Offset,
1105 s.AddrFrame.Offset, s.AddrStack.Offset );
1107 if ( s.AddrPC.Offset == 0 )
1109 afsi_log("(-nosymbols- PC == 0)" );
1113 /* show procedure info from a valid PC */
1114 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1116 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1118 afsi_log("SymGetSymFromAddr(): errno = %lu",
1124 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1126 afsi_log("%s", functionName );
1130 afsi_log(" %+ld bytes", (long) offset);
1134 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1136 if (GetLastError() != ERROR_INVALID_ADDRESS)
1138 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1144 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1145 Line.LineNumber, offset);
1149 /* no return address means no deeper stackframe */
1150 if (s.AddrReturn.Offset == 0)
1157 if (GetLastError() != 0)
1159 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1162 SymCleanup(hProcess);
1167 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1168 static DWORD afsd_crtDbgBreaks[256];
1171 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1175 BOOL allocRequestBrk = FALSE;
1178 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1179 ep->ExceptionRecord->ExceptionCode,
1180 ep->ExceptionRecord->ExceptionAddress);
1183 if (afsd_crtDbgBreakCurrent &&
1184 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1186 allocRequestBrk = TRUE;
1187 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1191 /* save context if we want to print the stack information */
1192 context = *ep->ContextRecord;
1194 afsd_printStack(GetCurrentThread(), &context);
1196 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1198 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1201 if (allocRequestBrk)
1203 afsd_crtDbgBreakCurrent++;
1204 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1208 ep->ContextRecord->Eip++;
1209 return EXCEPTION_CONTINUE_EXECUTION;
1213 return EXCEPTION_CONTINUE_SEARCH;
1217 void afsd_SetUnhandledExceptionFilter()
1219 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1223 void afsd_DbgBreakAllocInit()
1225 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1226 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1229 void afsd_DbgBreakAdd(DWORD requestNumber)
1232 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1234 if (afsd_crtDbgBreaks[i] == -1)
1239 afsd_crtDbgBreaks[i] = requestNumber;
1241 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);