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>
24 #include <rx\rx_null.h>
25 #include <WINNT/syscfg.h>
29 #include "lanahelper.h"
33 extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
34 extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
36 extern afs_int32 cryptall;
38 char AFSConfigKeyName[] =
39 "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters";
43 char cm_rootVolumeName[64];
44 DWORD cm_rootVolumeNameLen;
45 cm_volume_t *cm_rootVolumep = NULL;
46 cm_cell_t *cm_rootCellp = NULL;
48 cm_scache_t *cm_rootSCachep = NULL;
49 char cm_mountRoot[1024];
50 DWORD cm_mountRootLen;
53 #ifdef AFS_FREELANCE_CLIENT
55 #endif /* freelance */
68 char cm_HostName[200];
71 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
73 char cm_CachePath[MAX_PATH];
74 DWORD cm_CachePathLen;
76 BOOL isGateway = FALSE;
78 BOOL reportSessionStartups = FALSE;
80 cm_initparams_v1 cm_initParams;
83 unsigned int cm_sysNameCount = 0;
84 char *cm_sysNameList[MAXNUMSYSNAMES];
86 DWORD TraceOption = 0;
89 * AFSD Initialization Log
91 * This is distinct from the regular debug logging facility.
92 * Log items go directly to a file, not to an array in memory, so that even
93 * if AFSD crashes, the log can be inspected.
99 int cm_dnsEnabled = 1;
102 extern initUpperCaseTable();
103 void afsd_initUpperCaseTable()
105 initUpperCaseTable();
112 char t[100], u[100], *p, *path;
118 DWORD maxLogSize = 100 * 1024;
120 afsi_file = INVALID_HANDLE_VALUE;
123 StringCbCopyA(wd, sizeof(wd), getenv("TEMP"));
127 code = GetWindowsDirectory(wd, sizeof(wd));
128 if (code == 0) return;
130 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
131 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
132 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
133 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
135 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
136 0, KEY_QUERY_VALUE, &parmKey);
137 if (code == ERROR_SUCCESS) {
138 dummyLen = sizeof(maxLogSize);
139 code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL,
140 (BYTE *) &maxLogSize, &dummyLen);
141 RegCloseKey (parmKey);
145 dwLow = GetFileSize( afsi_file, &dwHigh );
146 if ( dwHigh > 0 || dwLow >= maxLogSize ) {
147 CloseHandle(afsi_file);
148 afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
149 CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
153 SetFilePointer(afsi_file, 0, NULL, FILE_END);
154 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
155 StringCbCatA(t, sizeof(t), ": Create log file\n");
156 StringCbCatA(u, sizeof(u), ": Created log file\n");
157 WriteFile(afsi_file, t, strlen(t), &zilch, NULL);
158 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
160 path = getenv("PATH");
161 WriteFile(afsi_file, p, strlen(p), &zilch, NULL);
162 WriteFile(afsi_file, path, strlen(path), &zilch, NULL);
163 WriteFile(afsi_file, "\n", 1, &zilch, NULL);
166 static int afsi_log_useTimestamp = 1;
169 afsi_log(char *pattern, ...)
171 char s[256], t[100], d[100], u[512];
174 va_start(ap, pattern);
176 StringCbVPrintfA(s, sizeof(s), pattern, ap);
177 if ( afsi_log_useTimestamp ) {
178 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
179 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
180 StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
181 if (afsi_file != INVALID_HANDLE_VALUE)
182 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
187 if (afsi_file != INVALID_HANDLE_VALUE)
188 WriteFile(afsi_file, s, strlen(s), &zilch, NULL);
193 * Standard AFSD trace
196 void afsd_ForceTrace(BOOL flush)
205 len = GetTempPath(sizeof(buf)-10, buf);
206 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
207 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
208 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
209 if (handle == INVALID_HANDLE_VALUE) {
211 osi_panic("Cannot create log file", __FILE__, __LINE__);
213 osi_LogPrint(afsd_logp, handle);
215 FlushFileBuffers(handle);
220 configureBackConnectionHostNames(void)
222 /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
223 * there is a restriction on the use of SMB authentication on loopback connections.
224 * There are two work arounds available:
226 * (1) We can disable the check for matching host names. This does not
228 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
229 * "DisableLoopbackCheck"=dword:00000001
231 * (2) We can add the AFS SMB/CIFS service name to an approved list. This
232 * does require a reboot:
233 * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
234 * "BackConnectionHostNames"=multi-sz
236 * The algorithm will be:
237 * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
238 * (2a) If not, add it to the list. (This will not take effect until the next reboot.)
239 * (2b1) and check to see if DisableLoopbackCheck is set.
240 * (2b2) If not set, set the DisableLoopbackCheck value to 0x1
241 * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck
242 * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
243 * check for the UnsetDisableLoopbackCheck value.
244 * If set, set the DisableLoopbackCheck flag to 0x0
245 * and delete the UnsetDisableLoopbackCheck value
253 PBYTE pHostNames = NULL, pName;
254 BOOL bNameFound = FALSE;
256 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
257 "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
260 &hkMSV10) == ERROR_SUCCESS )
262 if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) {
263 pHostNames = malloc(dwSize + strlen(cm_NetbiosName) + 1);
264 RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, pHostNames, &dwSize);
266 for (pName = pHostNames; *pName ; pName += strlen(pName) + 1)
268 if ( !stricmp(pName, cm_NetbiosName) ) {
277 pName = pHostNames = malloc(strlen(cm_NetbiosName) + 2);
280 strcpy(pName, cm_NetbiosName);
281 pName += strlen(cm_NetbiosName) + 1;
282 *pName = '\0'; /* add a second nul terminator */
284 dwType = REG_MULTI_SZ;
285 dwSize += strlen(cm_NetbiosName) + 1;
286 RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
288 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
289 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
292 &hkLsa) == ERROR_SUCCESS )
294 dwSize = sizeof(DWORD);
295 if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) != ERROR_SUCCESS ||
298 dwSize = sizeof(DWORD);
300 RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
302 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
303 "SOFTWARE\\OpenAFS\\Client",
306 REG_OPTION_NON_VOLATILE,
310 NULL) == ERROR_SUCCESS) {
313 dwSize = sizeof(DWORD);
315 RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, &dwValue, dwSize);
316 RegCloseKey(hkClient);
322 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
323 "SOFTWARE\\OpenAFS\\Client",
326 REG_OPTION_NON_VOLATILE,
330 NULL) == ERROR_SUCCESS) {
332 dwSize = sizeof(DWORD);
333 if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) == ERROR_SUCCESS &&
335 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
336 "SYSTEM\\CurrentControlSet\\Control\\Lsa",
339 &hkLsa) == ERROR_SUCCESS )
341 RegDeleteValue(hkLsa, "DisableLoopbackCheck");
345 RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
346 RegCloseKey(hkClient);
349 RegCloseKey(hkMSV10);
355 * AFSD Initialization
358 int afsd_InitCM(char **reasonP)
368 long rx_mtu, rx_nojumbo;
370 char rootCellName[256];
371 struct rx_service *serverp;
372 static struct rx_securityClass *nullServerSecurityClassp;
380 /*int freelanceEnabled;*/
382 lana_number_t lanaNum;
385 WSAStartup(0x0101, &WSAjunk);
387 afsd_initUpperCaseTable();
389 /* setup osidebug server at RPC slot 1000 */
390 osi_LongToUID(1000, &debugID);
391 code = osi_InitDebug(&debugID);
392 afsi_log("osi_InitDebug code %d", code);
394 // osi_LockTypeSetDefault("stat"); /* comment this out for speed *
396 *reasonP = "unknown error";
401 gethostname(cm_HostName, sizeof(cm_HostName));
402 afsi_log("gethostname %s", cm_HostName);
403 thp = gethostbyname(cm_HostName);
404 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
406 /* seed random number generator */
407 srand(ntohl(cm_HostAddr));
409 /* Look up configuration parameters in Registry */
410 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
411 0, KEY_QUERY_VALUE, &parmKey);
412 if (code != ERROR_SUCCESS) {
413 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
414 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
415 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
416 StringCbPrintfA(buf, sizeof(buf),
417 "Failure in configuration while opening Registry: %s",
419 osi_panic(buf, __FILE__, __LINE__);
422 dummyLen = sizeof(maxcpus);
423 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
424 (BYTE *) &maxcpus, &dummyLen);
425 if (code == ERROR_SUCCESS) {
427 DWORD_PTR processAffinityMask, systemAffinityMask;
429 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
430 FALSE, GetCurrentProcessId());
431 if ( hProcess != NULL &&
432 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
435 DWORD_PTR mask, newAffinityMask;
442 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
443 if ( processAffinityMask & mask ) {
444 newAffinityMask |= mask;
450 SetProcessAffinityMask(hProcess, newAffinityMask);
451 CloseHandle(hProcess);
452 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
454 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
458 dummyLen = sizeof(TraceOption);
459 code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
460 (BYTE *) &TraceOption, &dummyLen);
461 afsi_log("Event Log Tracing = %lX", TraceOption);
463 dummyLen = sizeof(traceBufSize);
464 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
465 (BYTE *) &traceBufSize, &dummyLen);
466 if (code == ERROR_SUCCESS)
467 afsi_log("Trace Buffer size %d", traceBufSize);
469 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
470 afsi_log("Default trace buffer size %d", traceBufSize);
473 /* setup and enable debug log */
474 afsd_logp = osi_LogCreate("afsd", traceBufSize);
475 afsi_log("osi_LogCreate log addr %x", (int)afsd_logp);
476 osi_LogEnable(afsd_logp);
479 osi_Log0(afsd_logp, "Log init");
481 dummyLen = sizeof(cacheSize);
482 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
483 (BYTE *) &cacheSize, &dummyLen);
484 if (code == ERROR_SUCCESS)
485 afsi_log("Cache size %d", cacheSize);
487 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
488 afsi_log("Default cache size %d", cacheSize);
491 dummyLen = sizeof(logChunkSize);
492 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
493 (BYTE *) &logChunkSize, &dummyLen);
494 if (code == ERROR_SUCCESS) {
495 if (logChunkSize < 12 || logChunkSize > 30) {
496 afsi_log("Invalid chunk size %d, using default",
498 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
500 afsi_log("Chunk size %d", logChunkSize);
502 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
503 afsi_log("Default chunk size %d", logChunkSize);
505 cm_logChunkSize = logChunkSize;
506 cm_chunkSize = 1 << logChunkSize;
508 dummyLen = sizeof(numBkgD);
509 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
510 (BYTE *) &numBkgD, &dummyLen);
511 if (code == ERROR_SUCCESS)
512 afsi_log("%d background daemons", numBkgD);
514 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
515 afsi_log("Defaulting to %d background daemons", numBkgD);
518 dummyLen = sizeof(numSvThreads);
519 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
520 (BYTE *) &numSvThreads, &dummyLen);
521 if (code == ERROR_SUCCESS)
522 afsi_log("%d server threads", numSvThreads);
524 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
525 afsi_log("Defaulting to %d server threads", numSvThreads);
528 dummyLen = sizeof(stats);
529 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
530 (BYTE *) &stats, &dummyLen);
531 if (code == ERROR_SUCCESS)
532 afsi_log("Status cache size %d", stats);
534 stats = CM_CONFIGDEFAULT_STATS;
535 afsi_log("Default status cache size %d", stats);
538 dummyLen = sizeof(ltt);
539 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
540 (BYTE *) <t, &dummyLen);
541 if (code == ERROR_SUCCESS)
542 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
545 afsi_log("Logoff token transfer on by default");
547 smb_LogoffTokenTransfer = ltt;
548 afsi_log("Logoff token transfer is currently ignored");
551 dummyLen = sizeof(ltto);
552 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
553 NULL, NULL, (BYTE *) <to, &dummyLen);
554 if (code == ERROR_SUCCESS)
555 afsi_log("Logoff token tranfer timeout %d seconds", ltto);
558 afsi_log("Default logoff token transfer timeout 10 seconds");
563 smb_LogoffTransferTimeout = ltto;
564 afsi_log("Default logoff token is currently ignored");
566 dummyLen = sizeof(cm_rootVolumeName);
567 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
568 cm_rootVolumeName, &dummyLen);
569 if (code == ERROR_SUCCESS)
570 afsi_log("Root volume %s", cm_rootVolumeName);
572 StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
573 afsi_log("Default root volume name root.afs");
576 cm_mountRootLen = sizeof(cm_mountRoot);
577 code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
578 cm_mountRoot, &cm_mountRootLen);
579 if (code == ERROR_SUCCESS) {
580 afsi_log("Mount root %s", cm_mountRoot);
581 cm_mountRootLen = strlen(cm_mountRoot);
583 StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
588 dummyLen = sizeof(buf);
589 code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type,
591 if (code == ERROR_SUCCESS && buf[0]) {
592 if (regType == REG_EXPAND_SZ) {
593 dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
594 if(dummyLen > sizeof(cm_CachePath)) {
595 afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath));
596 osi_panic("CachePath too long", __FILE__, __LINE__);
599 StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf);
601 afsi_log("Cache path %s", cm_CachePath);
603 GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath));
604 cm_CachePath[2] = 0; /* get drive letter only */
605 StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache");
606 afsi_log("Default cache path %s", cm_CachePath);
609 dummyLen = sizeof(virtualCache);
610 code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
611 &virtualCache, &dummyLen);
612 if (code == ERROR_SUCCESS && virtualCache) {
613 buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL;
615 buf_cacheType = CM_BUF_CACHETYPE_FILE;
617 afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL"));
619 dummyLen = sizeof(traceOnPanic);
620 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
621 (BYTE *) &traceOnPanic, &dummyLen);
622 if (code == ERROR_SUCCESS)
623 afsi_log("Set to %s on panic",
624 traceOnPanic ? "trap" : "not trap");
630 dummyLen = sizeof(reportSessionStartups);
631 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
632 (BYTE *) &reportSessionStartups, &dummyLen);
633 if (code == ERROR_SUCCESS)
634 afsi_log("Session startups %s be recorded in the Event Log",
635 reportSessionStartups ? "will" : "will not");
637 reportSessionStartups = 0;
641 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
642 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
643 cm_sysNameList[i][0] = '\0';
645 cm_sysName = cm_sysNameList[0];
647 dummyLen = sizeof(buf);
648 code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, buf, &dummyLen);
649 if (code == ERROR_SUCCESS && buf[0]) {
651 afsi_log("Sys name %s", buf);
653 for (p = q = buf; p < buf + dummyLen; p++)
655 if (*p == '\0' || isspace(*p)) {
656 memcpy(cm_sysNameList[cm_sysNameCount],q,p-q);
657 cm_sysNameList[cm_sysNameCount][p-q] = '\0';
665 } while (*p == '\0' || isspace(*p));
671 StringCbCopyA(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
674 StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40");
675 StringCbCopyA(cm_sysNameList[0], MAXSYSNAME, "i386_nt40");
676 afsi_log("Default sys name %s", cm_sysName);
679 dummyLen = sizeof(cryptall);
680 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
681 (BYTE *) &cryptall, &dummyLen);
682 if (code == ERROR_SUCCESS) {
683 afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
686 afsi_log("Default SecurityLevel is clear");
690 dummyLen = sizeof(cm_dnsEnabled);
691 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
692 (BYTE *) &cm_dnsEnabled, &dummyLen);
693 if (code == ERROR_SUCCESS) {
694 afsi_log("DNS %s be used to find AFS cell servers",
695 cm_dnsEnabled ? "will" : "will not");
698 cm_dnsEnabled = 1; /* default on */
699 afsi_log("Default to use DNS to find AFS cell servers");
701 #else /* AFS_AFSDB_ENV */
702 afsi_log("AFS not built with DNS support to find AFS cell servers");
703 #endif /* AFS_AFSDB_ENV */
705 #ifdef AFS_FREELANCE_CLIENT
706 dummyLen = sizeof(cm_freelanceEnabled);
707 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
708 (BYTE *) &cm_freelanceEnabled, &dummyLen);
709 if (code == ERROR_SUCCESS) {
710 afsi_log("Freelance client feature %s activated",
711 cm_freelanceEnabled ? "is" : "is not");
714 cm_freelanceEnabled = 0; /* default off */
716 #endif /* AFS_FREELANCE_CLIENT */
719 /* The netbios name is looked up in lana_GetUNCServerNameEx */
720 dummyLen = sizeof(buf);
721 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
722 (BYTE *) &buf, &dummyLen);
723 if (code == ERROR_SUCCESS) {
724 DWORD len = ExpandEnvironmentStrings(buf, cm_NetbiosName, MAX_NB_NAME_LENGTH);
725 if ( len > 0 && len <= MAX_NB_NAME_LENGTH ) {
726 afsi_log("Explicit NetBios name is used %s", cm_NetbiosName);
728 afsi_log("Unable to Expand Explicit NetBios name: %s", buf);
729 cm_NetbiosName[0] = 0; /* turn it off */
733 cm_NetbiosName[0] = 0; /* default off */
737 dummyLen = sizeof(smb_hideDotFiles);
738 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
739 (BYTE *) &smb_hideDotFiles, &dummyLen);
740 if (code != ERROR_SUCCESS) {
741 smb_hideDotFiles = 1; /* default on */
743 afsi_log("Dot files/dirs will %sbe marked hidden",
744 smb_hideDotFiles ? "" : "not ");
746 dummyLen = sizeof(smb_maxMpxRequests);
747 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
748 (BYTE *) &smb_maxMpxRequests, &dummyLen);
749 if (code != ERROR_SUCCESS) {
750 smb_maxMpxRequests = 50;
752 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
754 dummyLen = sizeof(smb_maxVCPerServer);
755 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
756 (BYTE *) &smb_maxVCPerServer, &dummyLen);
757 if (code != ERROR_SUCCESS) {
758 smb_maxVCPerServer = 100;
760 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
762 dummyLen = sizeof(smb_authType);
763 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
764 (BYTE *) &smb_authType, &dummyLen);
766 if (code != ERROR_SUCCESS ||
767 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
768 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
770 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
772 dummyLen = sizeof(rx_nojumbo);
773 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
774 (BYTE *) &rx_nojumbo, &dummyLen);
775 if (code != ERROR_SUCCESS) {
779 afsi_log("RX Jumbograms are disabled");
781 dummyLen = sizeof(rx_mtu);
782 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
783 (BYTE *) &rx_mtu, &dummyLen);
784 if (code != ERROR_SUCCESS || !rx_mtu) {
788 afsi_log("RX maximum MTU is %d", rx_mtu);
790 dummyLen = sizeof(ConnDeadtimeout);
791 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
792 (BYTE *) &ConnDeadtimeout, &dummyLen);
793 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
795 dummyLen = sizeof(HardDeadtimeout);
796 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
797 (BYTE *) &HardDeadtimeout, &dummyLen);
798 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
800 RegCloseKey (parmKey);
802 /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
803 if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
804 LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
806 if (LANadapter != -1)
807 afsi_log("LAN adapter number %d", LANadapter);
809 afsi_log("LAN adapter number not determined");
812 afsi_log("Set for gateway service");
814 afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
816 /* something went horribly wrong. We can't proceed without a netbios name */
817 StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
818 osi_panic(buf, __FILE__, __LINE__);
821 /* setup early variables */
822 /* These both used to be configurable. */
824 buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE;
826 /* turn from 1024 byte units into memory blocks */
827 cacheBlocks = (cacheSize * 1024) / buf_bufferSize;
829 /* get network related info */
830 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
831 code = syscfg_GetIFInfo(&cm_noIPAddr,
832 cm_IPAddr, cm_SubnetMask,
833 cm_NetMtu, cm_NetFlags);
835 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
836 afsi_log("syscfg_GetIFInfo error code %d", code);
838 afsi_log("First Network address %x SubnetMask %x",
839 cm_IPAddr[0], cm_SubnetMask[0]);
842 * Save client configuration for GetCacheConfig requests
844 cm_initParams.nChunkFiles = 0;
845 cm_initParams.nStatCaches = stats;
846 cm_initParams.nDataCaches = 0;
847 cm_initParams.nVolumeCaches = 0;
848 cm_initParams.firstChunkSize = cm_chunkSize;
849 cm_initParams.otherChunkSize = cm_chunkSize;
850 cm_initParams.cacheSize = cacheSize;
851 cm_initParams.setTime = 0;
852 cm_initParams.memCache = 0;
854 /* Set RX parameters before initializing RX */
857 afsi_log("rx_SetNoJumbo successful");
860 if ( rx_mtu != -1 ) {
861 rx_SetMaxMTU(rx_mtu);
862 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
865 /* Open Microsoft Firewall to allow in port 7001 */
866 icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT);
868 /* Ensure the AFS Netbios Name is registered to allow loopback access */
869 configureBackConnectionHostNames();
871 /* initialize RX, and tell it to listen to port 7001, which is used for
872 * callback RPC messages.
874 code = rx_Init(htons(7001));
875 afsi_log("rx_Init code %x", code);
877 *reasonP = "afsd: failed to init rx client on port 7001";
881 /* Initialize the RPC server for session keys */
884 /* create an unauthenticated service #1 for callbacks */
885 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
886 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
887 RXAFSCB_ExecuteRequest);
888 afsi_log("rx_NewService addr %x", (int)serverp);
889 if (serverp == NULL) {
890 *reasonP = "unknown error";
894 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
895 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
896 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
897 afsi_log("rx_NewService addr %x", (int)serverp);
898 if (serverp == NULL) {
899 *reasonP = "unknown error";
903 /* start server threads, *not* donating this one to the pool */
905 afsi_log("rx_StartServer");
907 /* init user daemon, and other packages */
910 cm_InitACLCache(2*stats);
926 cm_InitSCache(stats);
928 code = cm_InitDCache(0, cacheBlocks);
929 afsi_log("cm_InitDCache code %x", code);
931 *reasonP = "error initializing cache";
936 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
937 if (cm_InitDNS(cm_dnsEnabled) == -1)
938 cm_dnsEnabled = 0; /* init failed, so deactivate */
939 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
943 code = cm_GetRootCellName(rootCellName);
944 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
945 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
946 if (code != 0 && !cm_freelanceEnabled)
948 *reasonP = "can't find root cell name in afsd.ini";
951 else if (cm_freelanceEnabled)
954 if (code == 0 && !cm_freelanceEnabled)
956 cm_rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
957 afsi_log("cm_GetCell addr %x", (int)cm_rootCellp);
958 if (cm_rootCellp == NULL)
960 *reasonP = "can't find root cell in afsdcell.ini";
965 #ifdef AFS_FREELANCE_CLIENT
966 if (cm_freelanceEnabled)
972 int afsd_InitDaemons(char **reasonP)
979 /* this should really be in an init daemon from here on down */
981 if (!cm_freelanceEnabled) {
982 osi_Log0(afsd_logp, "Loading Root Volume from cell");
983 code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
984 &req, CM_FLAG_CREATE, &cm_rootVolumep);
985 afsi_log("cm_GetVolumeByName code %x root vol %x", code,
986 (code ? (cm_volume_t *)-1 : cm_rootVolumep));
988 *reasonP = "can't find root volume in root cell";
993 /* compute the root fid */
994 if (!cm_freelanceEnabled) {
995 cm_rootFid.cell = cm_rootCellp->cellID;
996 cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep);
997 cm_rootFid.vnode = 1;
998 cm_rootFid.unique = 1;
1001 cm_FakeRootFid(&cm_rootFid);
1003 code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req);
1004 afsi_log("cm_GetSCache code %x scache %x", code,
1005 (code ? (cm_scache_t *)-1 : cm_rootSCachep));
1007 *reasonP = "unknown error";
1011 cm_InitDaemon(numBkgD);
1012 afsi_log("cm_InitDaemon");
1017 int afsd_InitSMB(char **reasonP, void *aMBfunc)
1019 /* Do this last so that we don't handle requests before init is done.
1020 * Here we initialize the SMB listener.
1022 smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
1023 afsi_log("smb_Init");
1036 #pragma pack( push, before_imagehlp, 8 )
1037 #include <imagehlp.h>
1038 #pragma pack( pop, before_imagehlp )
1040 #define MAXNAMELEN 1024
1042 void afsd_printStack(HANDLE hThread, CONTEXT *c)
1044 HANDLE hProcess = GetCurrentProcess();
1048 char functionName[MAXNAMELEN];
1050 IMAGEHLP_MODULE Module;
1054 IMAGEHLP_SYMBOL *pSym;
1056 afsi_log_useTimestamp = 0;
1058 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
1060 memset( &s, '\0', sizeof s );
1061 if (!SymInitialize(hProcess, NULL, 1) )
1063 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
1065 SymCleanup( hProcess );
1071 symOptions = SymGetOptions();
1072 symOptions |= SYMOPT_LOAD_LINES;
1073 symOptions &= ~SYMOPT_UNDNAME;
1074 SymSetOptions( symOptions );
1077 * init STACKFRAME for first call
1078 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
1079 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
1080 * and good riddance.
1082 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
1083 #error The STACKFRAME initialization in afsd_printStack() for this platform
1084 #error must be properly configured
1086 s.AddrPC.Offset = c->Eip;
1087 s.AddrPC.Mode = AddrModeFlat;
1088 s.AddrFrame.Offset = c->Ebp;
1089 s.AddrFrame.Mode = AddrModeFlat;
1092 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
1093 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
1094 pSym->MaxNameLength = MAXNAMELEN;
1096 memset( &Line, '\0', sizeof Line );
1097 Line.SizeOfStruct = sizeof Line;
1099 memset( &Module, '\0', sizeof Module );
1100 Module.SizeOfStruct = sizeof Module;
1104 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
1106 for ( frameNum = 0; ; ++ frameNum )
1109 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
1110 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
1111 * ERROR_NOACCESS (998), you can assume that either you are done, or
1112 * that the stack is so hosed that the next deeper frame could not be
1115 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
1116 NULL, SymFunctionTableAccess, SymGetModuleBase,
1120 /* display its contents */
1121 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
1122 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
1123 s.AddrPC.Offset, s.AddrReturn.Offset,
1124 s.AddrFrame.Offset, s.AddrStack.Offset );
1126 if ( s.AddrPC.Offset == 0 )
1128 afsi_log("(-nosymbols- PC == 0)" );
1132 /* show procedure info from a valid PC */
1133 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
1135 if ( GetLastError() != ERROR_INVALID_ADDRESS )
1137 afsi_log("SymGetSymFromAddr(): errno = %lu",
1143 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
1145 afsi_log("%s", functionName );
1149 afsi_log(" %+ld bytes", (long) offset);
1153 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
1155 if (GetLastError() != ERROR_INVALID_ADDRESS)
1157 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
1163 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
1164 Line.LineNumber, offset);
1168 /* no return address means no deeper stackframe */
1169 if (s.AddrReturn.Offset == 0)
1176 if (GetLastError() != 0)
1178 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
1181 SymCleanup(hProcess);
1186 static DWORD *afsd_crtDbgBreakCurrent = NULL;
1187 static DWORD afsd_crtDbgBreaks[256];
1190 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1194 BOOL allocRequestBrk = FALSE;
1197 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1198 ep->ExceptionRecord->ExceptionCode,
1199 ep->ExceptionRecord->ExceptionAddress);
1202 if (afsd_crtDbgBreakCurrent &&
1203 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1205 allocRequestBrk = TRUE;
1206 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1210 /* save context if we want to print the stack information */
1211 context = *ep->ContextRecord;
1213 afsd_printStack(GetCurrentThread(), &context);
1215 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1217 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1220 if (allocRequestBrk)
1222 afsd_crtDbgBreakCurrent++;
1223 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1227 ep->ContextRecord->Eip++;
1228 return EXCEPTION_CONTINUE_EXECUTION;
1232 return EXCEPTION_CONTINUE_SEARCH;
1236 void afsd_SetUnhandledExceptionFilter()
1238 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1242 void afsd_DbgBreakAllocInit()
1244 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1245 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1248 void afsd_DbgBreakAdd(DWORD requestNumber)
1251 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1253 if (afsd_crtDbgBreaks[i] == -1)
1258 afsd_crtDbgBreaks[i] = requestNumber;
1260 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);