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 extern initUpperCaseTable();
104 void afsd_initUpperCaseTable()
106 initUpperCaseTable();
113 char t[100], u[100], *p, *path;
119 DWORD maxLogSize = 100 * 1024;
121 afsi_file = INVALID_HANDLE_VALUE;
124 StringCbCopyA(wd, sizeof(wd), getenv("TEMP"));
128 code = GetWindowsDirectory(wd, sizeof(wd));
129 if (code == 0) return;
131 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
132 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
133 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
134 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
136 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
137 0, KEY_QUERY_VALUE, &parmKey);
138 if (code == ERROR_SUCCESS) {
139 dummyLen = sizeof(maxLogSize);
140 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
141 (BYTE *) &maxLogSize, &dummyLen);
142 RegCloseKey (parmKey);
146 dwLow = GetFileSize( afsi_file, &dwHigh );
147 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
148 CloseHandle(afsi_file);
149 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
150 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
154 SetFilePointer(afsi_file, 0, NULL, FILE_END);
155 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
156 StringCbCatA(t, sizeof(t), ": Create log file\n");
157 StringCbCatA(u, sizeof(u), ": Created log file\n");
158 WriteFile(afsi_file, t, strlen(t), &zilch, NULL);
159 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
161 path = getenv("PATH");
162 WriteFile(afsi_file, p, strlen(p), &zilch, NULL);
163 WriteFile(afsi_file, path, strlen(path), &zilch, NULL);
164 WriteFile(afsi_file, "\n", 1, &zilch, NULL);
167 static int afsi_log_useTimestamp = 1;
170 afsi_log(char *pattern, ...)
172 char s[256], t[100], d[100], u[512];
175 va_start(ap, pattern);
177 StringCbVPrintfA(s, sizeof(s), pattern, ap);
178 if ( afsi_log_useTimestamp ) {
179 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
180 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
181 StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
182 if (afsi_file != INVALID_HANDLE_VALUE)
183 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
188 if (afsi_file != INVALID_HANDLE_VALUE)
189 WriteFile(afsi_file, s, strlen(s), &zilch, NULL);
194 * Standard AFSD trace
197 void afsd_ForceTrace(BOOL flush)
206 len = GetTempPath(sizeof(buf)-10, buf);
207 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
208 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
209 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
210 if (handle == INVALID_HANDLE_VALUE) {
212 osi_panic("Cannot create log file", __FILE__, __LINE__);
214 osi_LogPrint(afsd_logp, handle);
216 FlushFileBuffers(handle);
221 configureBackConnectionHostNames(void)
223 /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
224 * there is a restriction on the use of SMB authentication on loopback connections.
225 * There are two work arounds available:
227 * (1) We can disable the check for matching host names. This does not
229 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
230 * "DisableLoopbackCheck"=dword:00000001
232 * (2) We can add the AFS SMB/CIFS service name to an approved list. This
233 * does require a reboot:
234 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
235 * "BackConnectionHostNames"=multi-sz
237 * The algorithm will be:
238 * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
239 * (2a) If not, add it to the list. (This will not take effect until the next reboot.)
240 * (2b1) and check to see if DisableLoopbackCheck is set.
241 * (2b2) If not set, set the DisableLoopbackCheck value to 0x1
242 * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck
243 * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
244 * check for the UnsetDisableLoopbackCheck value.
245 * If set, set the DisableLoopbackCheck flag to 0x0
246 * and delete the UnsetDisableLoopbackCheck value
254 PBYTE pHostNames = NULL, pName;
255 BOOL bNameFound = FALSE;
257 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
258 "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
261 &hkMSV10) == ERROR_SUCCESS )
263 if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) {
264 pHostNames = malloc(dwSize + strlen(cm_NetbiosName) + 1);
265 RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, pHostNames, &dwSize);
267 for (pName = pHostNames; *pName ; pName += strlen(pName) + 1)
269 if ( !stricmp(pName, cm_NetbiosName) ) {
278 pName = pHostNames = malloc(strlen(cm_NetbiosName) + 2);
281 strcpy(pName, cm_NetbiosName);
282 pName += strlen(cm_NetbiosName) + 1;
283 *pName = '\0'; /* add a second nul terminator */
285 dwType = REG_MULTI_SZ;
286 dwSize += strlen(cm_NetbiosName) + 1;
287 RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
289 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
290 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
293 &hkLsa) == ERROR_SUCCESS )
295 dwSize = sizeof(DWORD);
296 if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) != ERROR_SUCCESS ||
299 dwSize = sizeof(DWORD);
301 RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
303 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
304 "SOFTWARE\\OpenAFS\\Client",
307 REG_OPTION_NON_VOLATILE,
311 NULL) == ERROR_SUCCESS) {
314 dwSize = sizeof(DWORD);
316 RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
317 RegCloseKey(hkClient);
323 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
324 "SOFTWARE\\OpenAFS\\Client",
327 REG_OPTION_NON_VOLATILE,
331 NULL) == ERROR_SUCCESS) {
333 dwSize = sizeof(DWORD);
334 if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) == ERROR_SUCCESS &&
336 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
337 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
340 &hkLsa) == ERROR_SUCCESS )
342 RegDeleteValue(hkLsa, "DisableLoopbackCheck");
346 RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
347 RegCloseKey(hkClient);
350 RegCloseKey(hkMSV10);
356 * AFSD Initialization
359 int afsd_InitCM(char **reasonP)
369 long rx_mtu, rx_nojumbo;
371 char rootCellName[256];
372 struct rx_service *serverp;
373 static struct rx_securityClass *nullServerSecurityClassp;
381 /*int freelanceEnabled;*/
383 lana_number_t lanaNum;
386 WSAStartup(0x0101, &WSAjunk);
388 afsd_initUpperCaseTable();
390 /* setup osidebug server at RPC slot 1000 */
391 osi_LongToUID(1000, &debugID);
392 code = osi_InitDebug(&debugID);
393 afsi_log("osi_InitDebug code %d", code);
395 // osi_LockTypeSetDefault("stat"); /* comment this out for speed *
397 *reasonP = "unknown error";
402 gethostname(cm_HostName, sizeof(cm_HostName));
403 afsi_log("gethostname %s", cm_HostName);
404 thp = gethostbyname(cm_HostName);
405 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
407 /* seed random number generator */
408 srand(ntohl(cm_HostAddr));
410 /* Look up configuration parameters in Registry */
411 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
412 0, KEY_QUERY_VALUE, &parmKey);
413 if (code != ERROR_SUCCESS) {
414 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
415 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
416 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
417 StringCbPrintfA(buf, sizeof(buf),
418 "Failure in configuration while opening Registry: %s",
420 osi_panic(buf, __FILE__, __LINE__);
423 dummyLen = sizeof(maxcpus);
424 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
425 (BYTE *) &maxcpus, &dummyLen);
426 if (code == ERROR_SUCCESS) {
428 DWORD_PTR processAffinityMask, systemAffinityMask;
430 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
431 FALSE, GetCurrentProcessId());
432 if ( hProcess != NULL &&
433 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
436 DWORD_PTR mask, newAffinityMask;
443 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
444 if ( processAffinityMask & mask ) {
445 newAffinityMask |= mask;
451 SetProcessAffinityMask(hProcess, newAffinityMask);
452 CloseHandle(hProcess);
453 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
455 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
459 dummyLen = sizeof(TraceOption);
460 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
461 (BYTE *) &TraceOption, &dummyLen);
462 afsi_log("Event Log Tracing = %lX", TraceOption);
464 dummyLen = sizeof(traceBufSize);
465 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
466 (BYTE *) &traceBufSize, &dummyLen);
467 if (code == ERROR_SUCCESS)
468 afsi_log("Trace Buffer size %d", traceBufSize);
470 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
471 afsi_log("Default trace buffer size %d", traceBufSize);
474 /* setup and enable debug log */
475 afsd_logp = osi_LogCreate("afsd", traceBufSize);
476 afsi_log("osi_LogCreate log addr %x", (int)afsd_logp);
477 osi_LogEnable(afsd_logp);
480 osi_Log0(afsd_logp, "Log init");
482 dummyLen = sizeof(cacheSize);
483 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
484 (BYTE *) &cacheSize, &dummyLen);
485 if (code == ERROR_SUCCESS)
486 afsi_log("Cache size %d", cacheSize);
488 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
489 afsi_log("Default cache size %d", cacheSize);
492 dummyLen = sizeof(logChunkSize);
493 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
494 (BYTE *) &logChunkSize, &dummyLen);
495 if (code == ERROR_SUCCESS) {
496 if (logChunkSize < 12 || logChunkSize > 30) {
497 afsi_log("Invalid chunk size %d, using default",
499 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
501 afsi_log("Chunk size %d", logChunkSize);
503 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
504 afsi_log("Default chunk size %d", logChunkSize);
506 cm_logChunkSize = logChunkSize;
507 cm_chunkSize = 1 << logChunkSize;
509 dummyLen = sizeof(numBkgD);
510 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
511 (BYTE *) &numBkgD, &dummyLen);
512 if (code == ERROR_SUCCESS)
513 afsi_log("%d background daemons", numBkgD);
515 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
516 afsi_log("Defaulting to %d background daemons", numBkgD);
519 dummyLen = sizeof(numSvThreads);
520 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
521 (BYTE *) &numSvThreads, &dummyLen);
522 if (code == ERROR_SUCCESS)
523 afsi_log("%d server threads", numSvThreads);
525 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
526 afsi_log("Defaulting to %d server threads", numSvThreads);
529 dummyLen = sizeof(stats);
530 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
531 (BYTE *) &stats, &dummyLen);
532 if (code == ERROR_SUCCESS)
533 afsi_log("Status cache size %d", stats);
535 stats = CM_CONFIGDEFAULT_STATS;
536 afsi_log("Default status cache size %d", stats);
539 dummyLen = sizeof(ltt);
540 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
541 (BYTE *) <t, &dummyLen);
542 if (code == ERROR_SUCCESS)
543 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
546 afsi_log("Logoff token transfer on by default");
548 smb_LogoffTokenTransfer = ltt;
549 afsi_log("Logoff token transfer is currently ignored");
552 dummyLen = sizeof(ltto);
553 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
554 NULL, NULL, (BYTE *) <to, &dummyLen);
555 if (code == ERROR_SUCCESS)
556 afsi_log("Logoff token tranfer timeout %d seconds",
560 afsi_log("Default logoff token transfer timeout 10 seconds");
565 smb_LogoffTransferTimeout = ltto;
566 afsi_log("Default logoff token is currently ignored");
568 dummyLen = sizeof(cm_rootVolumeName);
569 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
570 cm_rootVolumeName, &dummyLen);
571 if (code == ERROR_SUCCESS)
572 afsi_log("Root volume %s", cm_rootVolumeName);
574 StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
575 afsi_log("Default root volume name root.afs");
578 cm_mountRootLen = sizeof(cm_mountRoot);
579 code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
580 cm_mountRoot, &cm_mountRootLen);
581 if (code == ERROR_SUCCESS) {
582 afsi_log("Mount root %s", cm_mountRoot);
583 cm_mountRootLen = strlen(cm_mountRoot);
585 StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
590 dummyLen = sizeof(buf);
591 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
593 if (code == ERROR_SUCCESS && buf[0]) {
594 if(regType == REG_EXPAND_SZ) {
595 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
596 if(dummyLen > sizeof(cm_CachePath)) {
597 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
598 osi_panic("CachePath too long", __FILE__, __LINE__);
601 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
603 afsi_log("Cache path %s", cm_CachePath);
605 GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath));
606 cm_CachePath[2] = 0; /* get drive letter only */
607 StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache");
608 afsi_log("Default cache path %s", cm_CachePath);
611 dummyLen = sizeof(virtualCache);
612 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
613 &virtualCache, &dummyLen);
614 if (code == ERROR_SUCCESS && virtualCache) {
615 buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL;
617 buf_cacheType = CM_BUF_CACHETYPE_FILE;
619 afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL"));
621 dummyLen = sizeof(traceOnPanic);
622 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
623 (BYTE *) &traceOnPanic, &dummyLen);
624 if (code == ERROR_SUCCESS)
625 afsi_log("Set to %s on panic",
626 traceOnPanic ? "trap" : "not trap");
632 dummyLen = sizeof(reportSessionStartups);
633 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
634 (BYTE *) &reportSessionStartups, &dummyLen);
635 if (code == ERROR_SUCCESS)
636 afsi_log("Session startups %s be recorded in the Event Log",
637 reportSessionStartups ? "will" : "will not");
639 reportSessionStartups = 0;
643 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
644 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
645 cm_sysNameList[i][0] = '\0';
647 cm_sysName = cm_sysNameList[0];
649 dummyLen = MAXSYSNAME;
650 code = RegQueryValueEx(parmKey, "SysName", NULL, NULL,
651 cm_sysName, &dummyLen);
652 if (code == ERROR_SUCCESS)
653 afsi_log("Sys name %s", cm_sysName);
655 StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40");
656 afsi_log("Default sys name %s", cm_sysName);
660 dummyLen = sizeof(cryptall);
661 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
662 (BYTE *) &cryptall, &dummyLen);
663 if (code == ERROR_SUCCESS)
664 afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
666 cryptall = rxkad_clear;
667 afsi_log("Default SecurityLevel is clear");
671 dummyLen = sizeof(cm_dnsEnabled);
672 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
673 (BYTE *) &cm_dnsEnabled, &dummyLen);
674 if (code == ERROR_SUCCESS) {
675 afsi_log("DNS %s be used to find AFS cell servers",
676 cm_dnsEnabled ? "will" : "will not");
679 cm_dnsEnabled = 1; /* default on */
680 afsi_log("Default to use DNS to find AFS cell servers");
682 #else /* AFS_AFSDB_ENV */
683 afsi_log("AFS not built with DNS support to find AFS cell servers");
684 #endif /* AFS_AFSDB_ENV */
686 #ifdef AFS_FREELANCE_CLIENT
687 dummyLen = sizeof(cm_freelanceEnabled);
688 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
689 (BYTE *) &cm_freelanceEnabled, &dummyLen);
690 if (code == ERROR_SUCCESS) {
691 afsi_log("Freelance client feature %s activated",
692 cm_freelanceEnabled ? "is" : "is not");
695 cm_freelanceEnabled = 0; /* default off */
697 #endif /* AFS_FREELANCE_CLIENT */
700 /* The netbios name is looked up in lana_GetUNCServerNameEx */
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 */
718 dummyLen = sizeof(smb_hideDotFiles);
719 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
720 (BYTE *) &smb_hideDotFiles, &dummyLen);
721 if (code != ERROR_SUCCESS) {
722 smb_hideDotFiles = 1; /* default on */
724 afsi_log("Dot files/dirs will %sbe marked hidden",
725 smb_hideDotFiles ? "" : "not ");
727 dummyLen = sizeof(smb_maxMpxRequests);
728 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
729 (BYTE *) &smb_maxMpxRequests, &dummyLen);
730 if (code != ERROR_SUCCESS) {
731 smb_maxMpxRequests = 50;
733 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
735 dummyLen = sizeof(smb_maxVCPerServer);
736 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
737 (BYTE *) &smb_maxVCPerServer, &dummyLen);
738 if (code != ERROR_SUCCESS) {
739 smb_maxVCPerServer = 100;
741 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
743 dummyLen = sizeof(smb_authType);
744 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
745 (BYTE *) &smb_authType, &dummyLen);
747 if (code != ERROR_SUCCESS ||
748 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
749 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
751 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
753 dummyLen = sizeof(rx_nojumbo);
754 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
755 (BYTE *) &rx_nojumbo, &dummyLen);
756 if (code != ERROR_SUCCESS) {
760 afsi_log("RX Jumbograms are disabled");
762 dummyLen = sizeof(rx_mtu);
763 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
764 (BYTE *) &rx_mtu, &dummyLen);
765 if (code != ERROR_SUCCESS || !rx_mtu) {
769 afsi_log("RX maximum MTU is %d", rx_mtu);
771 dummyLen = sizeof(ConnDeadtimeout);
772 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
773 (BYTE *) &ConnDeadtimeout, &dummyLen);
774 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
776 dummyLen = sizeof(HardDeadtimeout);
777 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
778 (BYTE *) &HardDeadtimeout, &dummyLen);
779 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
781 RegCloseKey (parmKey);
783 /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
784 if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
785 LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
788 afsi_log("LAN adapter number %d", LANadapter);
790 afsi_log("LAN adapter number not determined");
793 afsi_log("Set for gateway service");
795 afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
797 /* something went horribly wrong. We can't proceed without a netbios name */
798 StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
799 osi_panic(buf, __FILE__, __LINE__);
802 /* setup early variables */
803 /* These both used to be configurable. */
805 buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE;
807 /* turn from 1024 byte units into memory blocks */
808 cacheBlocks = (cacheSize * 1024) / buf_bufferSize;
810 /* get network related info */
811 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
812 code = syscfg_GetIFInfo(&cm_noIPAddr,
813 cm_IPAddr, cm_SubnetMask,
814 cm_NetMtu, cm_NetFlags);
816 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
817 afsi_log("syscfg_GetIFInfo error code %d", code);
819 afsi_log("First Network address %x SubnetMask %x",
820 cm_IPAddr[0], cm_SubnetMask[0]);
823 * Save client configuration for GetCacheConfig requests
825 cm_initParams.nChunkFiles = 0;
826 cm_initParams.nStatCaches = stats;
827 cm_initParams.nDataCaches = 0;
828 cm_initParams.nVolumeCaches = 0;
829 cm_initParams.firstChunkSize = cm_chunkSize;
830 cm_initParams.otherChunkSize = cm_chunkSize;
831 cm_initParams.cacheSize = cacheSize;
832 cm_initParams.setTime = 0;
833 cm_initParams.memCache = 0;
835 /* Set RX parameters before initializing RX */
838 afsi_log("rx_SetNoJumbo successful");
841 if ( rx_mtu != -1 ) {
842 rx_SetMaxMTU(rx_mtu);
843 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
846 /* Open Microsoft Firewall to allow in port 7001 */
847 icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT);
849 /* Ensure the AFS Netbios Name is registered to allow loopback access */
850 configureBackConnectionHostNames();
852 /* initialize RX, and tell it to listen to port 7001, which is used for
853 * callback RPC messages.
855 code = rx_Init(htons(7001));
856 afsi_log("rx_Init code %x", code);
858 *reasonP = "afsd: failed to init rx client on port 7001";
862 /* Initialize the RPC server for session keys */
865 /* create an unauthenticated service #1 for callbacks */
866 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
867 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
868 RXAFSCB_ExecuteRequest);
869 afsi_log("rx_NewService addr %x", (int)serverp);
870 if (serverp == NULL) {
871 *reasonP = "unknown error";
875 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
876 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
877 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
878 afsi_log("rx_NewService addr %x", (int)serverp);
879 if (serverp == NULL) {
880 *reasonP = "unknown error";
884 /* start server threads, *not* donating this one to the pool */
886 afsi_log("rx_StartServer");
888 /* init user daemon, and other packages */
891 cm_InitACLCache(2*stats);
907 cm_InitSCache(stats);
909 code = cm_InitDCache(0, cacheBlocks);
910 afsi_log("cm_InitDCache code %x", code);
912 *reasonP = "error initializing cache";
917 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
918 if (cm_InitDNS(cm_dnsEnabled) == -1)
919 cm_dnsEnabled = 0; /* init failed, so deactivate */
920 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
924 code = cm_GetRootCellName(rootCellName);
925 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
926 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
927 if (code != 0 && !cm_freelanceEnabled)
929 *reasonP = "can't find root cell name in afsd.ini";
932 else if (cm_freelanceEnabled)
935 if (code == 0 && !cm_freelanceEnabled)
937 cm_rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
938 afsi_log("cm_GetCell addr %x", (int)cm_rootCellp);
939 if (cm_rootCellp == NULL)
941 *reasonP = "can't find root cell in afsdcell.ini";
946 #ifdef AFS_FREELANCE_CLIENT
947 if (cm_freelanceEnabled)
954 int afsd_InitDaemons(char **reasonP)
961 /* this should really be in an init daemon from here on down */
963 if (!cm_freelanceEnabled) {
964 osi_Log0(afsd_logp, "Loading Root Volume from cell");
965 code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
966 &req, CM_FLAG_CREATE, &cm_rootVolumep);
967 afsi_log("cm_GetVolumeByName code %x root vol %x", code,
968 (code ? (cm_volume_t *)-1 : cm_rootVolumep));
970 *reasonP = "can't find root volume in root cell";
975 /* compute the root fid */
976 if (!cm_freelanceEnabled) {
977 cm_rootFid.cell = cm_rootCellp->cellID;
978 cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep);
979 cm_rootFid.vnode = 1;
980 cm_rootFid.unique = 1;
983 cm_FakeRootFid(&cm_rootFid);
985 code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req);
986 afsi_log("cm_GetSCache code %x scache %x", code,
987 (code ? (cm_scache_t *)-1 : cm_rootSCachep));
989 *reasonP = "unknown error";
993 cm_InitDaemon(numBkgD);
994 afsi_log("cm_InitDaemon");
999 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1001 /* Do this last so that we don't handle requests before init is done.
1002 * Here we initialize the SMB listener.
1004 smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
1005 afsi_log("smb_Init");
1018 #pragma pack( push, before_imagehlp, 8 )
1019 #include <imagehlp.h>
1020 #pragma pack( pop, before_imagehlp )
1022 #define MAXNAMELEN 1024
1024 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1026 HANDLE hProcess = GetCurrentProcess();
1030 char functionName[MAXNAMELEN];
1032 IMAGEHLP_MODULE Module;
1036 IMAGEHLP_SYMBOL *pSym;
1038 afsi_log_useTimestamp = 0;
1040 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1042 memset( &s, '\0', sizeof s );
1043 if (!SymInitialize(hProcess, NULL, 1) )
1045 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1047 SymCleanup( hProcess );
1053 symOptions = SymGetOptions();
1054 symOptions |= SYMOPT_LOAD_LINES;
1055 symOptions &= ~SYMOPT_UNDNAME;
1056 SymSetOptions( symOptions );
1059 * init STACKFRAME for first call
1060 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1061 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1062 * and good riddance.
1064 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1065 #error The STACKFRAME initialization in afsd_printStack() for this platform
1066 #error must be properly configured
1068 s.AddrPC.Offset = c->Eip;
1069 s.AddrPC.Mode = AddrModeFlat;
1070 s.AddrFrame.Offset = c->Ebp;
1071 s.AddrFrame.Mode = AddrModeFlat;
1074 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1075 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1076 pSym->MaxNameLength = MAXNAMELEN;
1078 memset( &Line, '\0', sizeof Line );
1079 Line.SizeOfStruct = sizeof Line;
1081 memset( &Module, '\0', sizeof Module );
1082 Module.SizeOfStruct = sizeof Module;
1086 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1088 for ( frameNum = 0; ; ++ frameNum )
1091 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1092 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1093 * ERROR_NOACCESS (998), you can assume that either you are done, or
1094 * that the stack is so hosed that the next deeper frame could not be
1097 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1098 NULL, SymFunctionTableAccess, SymGetModuleBase,
1102 /* display its contents */
1103 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1104 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1105 s.AddrPC.Offset, s.AddrReturn.Offset,
1106 s.AddrFrame.Offset, s.AddrStack.Offset );
1108 if ( s.AddrPC.Offset == 0 )
1110 afsi_log("(-nosymbols- PC == 0)" );
1114 /* show procedure info from a valid PC */
1115 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1117 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1119 afsi_log("SymGetSymFromAddr(): errno = %lu",
1125 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1127 afsi_log("%s", functionName );
1131 afsi_log(" %+ld bytes", (long) offset);
1135 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1137 if (GetLastError() != ERROR_INVALID_ADDRESS)
1139 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1145 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1146 Line.LineNumber, offset);
1150 /* no return address means no deeper stackframe */
1151 if (s.AddrReturn.Offset == 0)
1158 if (GetLastError() != 0)
1160 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1163 SymCleanup(hProcess);
1168 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1169 static DWORD afsd_crtDbgBreaks[256];
1172 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1176 BOOL allocRequestBrk = FALSE;
1179 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1180 ep->ExceptionRecord->ExceptionCode,
1181 ep->ExceptionRecord->ExceptionAddress);
1184 if (afsd_crtDbgBreakCurrent &&
1185 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1187 allocRequestBrk = TRUE;
1188 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1192 /* save context if we want to print the stack information */
1193 context = *ep->ContextRecord;
1195 afsd_printStack(GetCurrentThread(), &context);
1197 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1199 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1202 if (allocRequestBrk)
1204 afsd_crtDbgBreakCurrent++;
1205 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1209 ep->ContextRecord->Eip++;
1210 return EXCEPTION_CONTINUE_EXECUTION;
1214 return EXCEPTION_CONTINUE_SEARCH;
1218 void afsd_SetUnhandledExceptionFilter()
1220 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1224 void afsd_DbgBreakAllocInit()
1226 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1227 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1230 void afsd_DbgBreakAdd(DWORD requestNumber)
1233 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1235 if (afsd_crtDbgBreaks[i] == -1)
1240 afsd_crtDbgBreaks[i] = requestNumber;
1242 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);