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"
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;
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[200];
74 DWORD cm_CachePathLen;
76 BOOL isGateway = FALSE;
78 BOOL reportSessionStartups = FALSE;
80 cm_initparams_v1 cm_initParams;
83 int cm_sysNameCount = 0;
84 char *cm_sysNameList[MAXNUMSYSNAMES];
87 * AFSD Initialization Log
89 * This is distinct from the regular debug logging facility.
90 * Log items go directly to a file, not to an array in memory, so that even
91 * if AFSD crashes, the log can be inspected.
97 int cm_dnsEnabled = 1;
100 char cm_NetBiosName[32];
102 extern initUpperCaseTable();
103 void afsd_initUpperCaseTable()
105 initUpperCaseTable();
112 char t[100], u[100], *p, *path;
116 afsi_file = INVALID_HANDLE_VALUE;
119 StringCbCopyA(wd, sizeof(wd), getenv("TEMP"));
123 code = GetWindowsDirectory(wd, sizeof(wd));
124 if (code == 0) return;
126 StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
127 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
128 afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
129 OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
130 SetFilePointer(afsi_file, 0, NULL, FILE_END);
131 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
132 StringCbCatA(t, sizeof(t), ": Create log file\n");
133 StringCbCatA(u, sizeof(u), ": Created log file\n");
134 WriteFile(afsi_file, t, strlen(t), &zilch, NULL);
135 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
137 path = getenv("PATH");
138 WriteFile(afsi_file, p, strlen(p), &zilch, NULL);
139 WriteFile(afsi_file, path, strlen(path), &zilch, NULL);
140 WriteFile(afsi_file, "\n", 1, &zilch, NULL);
143 static int afsi_log_useTimestamp = 1;
146 afsi_log(char *pattern, ...)
148 char s[256], t[100], d[100], u[512];
151 va_start(ap, pattern);
153 StringCbVPrintfA(s, sizeof(s), pattern, ap);
154 if ( afsi_log_useTimestamp ) {
155 GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
156 GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
157 StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
158 if (afsi_file != INVALID_HANDLE_VALUE)
159 WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
164 if (afsi_file != INVALID_HANDLE_VALUE)
165 WriteFile(afsi_file, s, strlen(s), &zilch, NULL);
170 * Standard AFSD trace
173 void afsd_ForceTrace(BOOL flush)
182 len = GetTempPath(sizeof(buf)-10, buf);
183 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
184 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
185 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
186 if (handle == INVALID_HANDLE_VALUE) {
188 osi_panic("Cannot create log file", __FILE__, __LINE__);
190 osi_LogPrint(afsd_logp, handle);
192 FlushFileBuffers(handle);
197 * AFSD Initialization
200 int afsd_InitCM(char **reasonP)
210 long rx_mtu, rx_nojumbo;
211 char rootCellName[256];
212 struct rx_service *serverp;
213 static struct rx_securityClass *nullServerSecurityClassp;
220 /*int freelanceEnabled;*/
222 lana_number_t lanaNum;
225 WSAStartup(0x0101, &WSAjunk);
227 afsd_initUpperCaseTable();
229 /* setup osidebug server at RPC slot 1000 */
230 osi_LongToUID(1000, &debugID);
231 code = osi_InitDebug(&debugID);
232 afsi_log("osi_InitDebug code %d", code);
234 // osi_LockTypeSetDefault("stat"); /* comment this out for speed *
236 *reasonP = "unknown error";
241 gethostname(cm_HostName, sizeof(cm_HostName));
242 afsi_log("gethostname %s", cm_HostName);
243 thp = gethostbyname(cm_HostName);
244 memcpy(&cm_HostAddr, thp->h_addr_list[0], 4);
246 /* seed random number generator */
247 srand(ntohl(cm_HostAddr));
249 /* Look up configuration parameters in Registry */
250 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
251 0, KEY_QUERY_VALUE, &parmKey);
252 if (code != ERROR_SUCCESS) {
253 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
254 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
255 NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
256 StringCbPrintfA(buf, sizeof(buf),
257 "Failure in configuration while opening Registry: %s",
259 osi_panic(buf, __FILE__, __LINE__);
262 dummyLen = sizeof(maxcpus);
263 code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
264 (BYTE *) &maxcpus, &dummyLen);
265 if (code == ERROR_SUCCESS) {
267 DWORD_PTR processAffinityMask, systemAffinityMask;
269 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
270 FALSE, GetCurrentProcessId());
271 if ( hProcess != NULL &&
272 GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
275 DWORD_PTR mask, newAffinityMask;
282 for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
283 if ( processAffinityMask & mask ) {
284 newAffinityMask |= mask;
290 SetProcessAffinityMask(hProcess, newAffinityMask);
291 CloseHandle(hProcess);
292 afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
294 afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
298 dummyLen = sizeof(traceBufSize);
299 code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
300 (BYTE *) &traceBufSize, &dummyLen);
301 if (code == ERROR_SUCCESS)
302 afsi_log("Trace Buffer size %d", traceBufSize);
304 traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE;
305 afsi_log("Default trace buffer size %d", traceBufSize);
308 /* setup and enable debug log */
309 afsd_logp = osi_LogCreate("afsd", traceBufSize);
310 afsi_log("osi_LogCreate log addr %x", (int)afsd_logp);
311 osi_LogEnable(afsd_logp);
314 osi_Log0(afsd_logp, "Log init");
316 dummyLen = sizeof(cacheSize);
317 code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
318 (BYTE *) &cacheSize, &dummyLen);
319 if (code == ERROR_SUCCESS)
320 afsi_log("Cache size %d", cacheSize);
322 cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
323 afsi_log("Default cache size %d", cacheSize);
326 dummyLen = sizeof(logChunkSize);
327 code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL,
328 (BYTE *) &logChunkSize, &dummyLen);
329 if (code == ERROR_SUCCESS) {
330 if (logChunkSize < 12 || logChunkSize > 30) {
331 afsi_log("Invalid chunk size %d, using default",
333 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
335 afsi_log("Chunk size %d", logChunkSize);
337 logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
338 afsi_log("Default chunk size %d", logChunkSize);
340 cm_logChunkSize = logChunkSize;
341 cm_chunkSize = 1 << logChunkSize;
343 dummyLen = sizeof(numBkgD);
344 code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
345 (BYTE *) &numBkgD, &dummyLen);
346 if (code == ERROR_SUCCESS)
347 afsi_log("%d background daemons", numBkgD);
349 numBkgD = CM_CONFIGDEFAULT_DAEMONS;
350 afsi_log("Defaulting to %d background daemons", numBkgD);
353 dummyLen = sizeof(numSvThreads);
354 code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL,
355 (BYTE *) &numSvThreads, &dummyLen);
356 if (code == ERROR_SUCCESS)
357 afsi_log("%d server threads", numSvThreads);
359 numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
360 afsi_log("Defaulting to %d server threads", numSvThreads);
363 dummyLen = sizeof(stats);
364 code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
365 (BYTE *) &stats, &dummyLen);
366 if (code == ERROR_SUCCESS)
367 afsi_log("Status cache size %d", stats);
369 stats = CM_CONFIGDEFAULT_STATS;
370 afsi_log("Default status cache size %d", stats);
373 dummyLen = sizeof(ltt);
374 code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
375 (BYTE *) <t, &dummyLen);
376 if (code == ERROR_SUCCESS)
377 afsi_log("Logoff token transfer %s", (ltt ? "on" : "off"));
380 afsi_log("Logoff token transfer on by default");
382 smb_LogoffTokenTransfer = ltt;
385 dummyLen = sizeof(ltto);
386 code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
387 NULL, NULL, (BYTE *) <to, &dummyLen);
388 if (code == ERROR_SUCCESS)
389 afsi_log("Logoff token tranfer timeout %d seconds",
393 afsi_log("Default logoff token transfer timeout 10 seconds");
398 smb_LogoffTransferTimeout = ltto;
400 dummyLen = sizeof(cm_rootVolumeName);
401 code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
402 cm_rootVolumeName, &dummyLen);
403 if (code == ERROR_SUCCESS)
404 afsi_log("Root volume %s", cm_rootVolumeName);
406 StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
407 afsi_log("Default root volume name root.afs");
410 cm_mountRootLen = sizeof(cm_mountRoot);
411 code = RegQueryValueEx(parmKey, "Mountroot", NULL, NULL,
412 cm_mountRoot, &cm_mountRootLen);
413 if (code == ERROR_SUCCESS) {
414 afsi_log("Mount root %s", cm_mountRoot);
415 cm_mountRootLen = strlen(cm_mountRoot);
417 StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
422 dummyLen = sizeof(cm_CachePath);
423 code = RegQueryValueEx(parmKey, "CachePath", NULL, NULL,
424 cm_CachePath, &dummyLen);
425 if (code == ERROR_SUCCESS)
426 afsi_log("Cache path %s", cm_CachePath);
428 GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath));
429 cm_CachePath[2] = 0; /* get drive letter only */
430 StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache");
431 afsi_log("Default cache path %s", cm_CachePath);
434 dummyLen = sizeof(traceOnPanic);
435 code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
436 (BYTE *) &traceOnPanic, &dummyLen);
437 if (code == ERROR_SUCCESS)
438 afsi_log("Set to %s on panic",
439 traceOnPanic ? "trap" : "not trap");
445 dummyLen = sizeof(reportSessionStartups);
446 code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL,
447 (BYTE *) &reportSessionStartups, &dummyLen);
448 if (code == ERROR_SUCCESS)
449 afsi_log("Session startups %s be recorded in the Event Log",
450 reportSessionStartups ? "will" : "will not");
452 reportSessionStartups = 0;
456 for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
457 cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
458 cm_sysNameList[i][0] = '\0';
460 cm_sysName = cm_sysNameList[0];
462 dummyLen = MAXSYSNAME;
463 code = RegQueryValueEx(parmKey, "SysName", NULL, NULL,
464 cm_sysName, &dummyLen);
465 if (code == ERROR_SUCCESS)
466 afsi_log("Sys name %s", cm_sysName);
468 StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40");
469 afsi_log("Default sys name %s", cm_sysName);
473 dummyLen = sizeof(cryptall);
474 code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
475 (BYTE *) &cryptall, &dummyLen);
476 if (code == ERROR_SUCCESS)
477 afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
479 cryptall = rxkad_clear;
480 afsi_log("Default SecurityLevel is clear");
484 dummyLen = sizeof(cm_dnsEnabled);
485 code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
486 (BYTE *) &cm_dnsEnabled, &dummyLen);
487 if (code == ERROR_SUCCESS) {
488 afsi_log("DNS %s be used to find AFS cell servers",
489 cm_dnsEnabled ? "will" : "will not");
492 cm_dnsEnabled = 1; /* default on */
493 afsi_log("Default to use DNS to find AFS cell servers");
495 #else /* AFS_AFSDB_ENV */
496 afsi_log("AFS not built with DNS support to find AFS cell servers");
497 #endif /* AFS_AFSDB_ENV */
499 #ifdef AFS_FREELANCE_CLIENT
500 dummyLen = sizeof(cm_freelanceEnabled);
501 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
502 (BYTE *) &cm_freelanceEnabled, &dummyLen);
503 if (code == ERROR_SUCCESS) {
504 afsi_log("Freelance client feature %s activated",
505 cm_freelanceEnabled ? "is" : "is not");
508 cm_freelanceEnabled = 0; /* default off */
510 #endif /* AFS_FREELANCE_CLIENT */
512 dummyLen = sizeof(buf);
513 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
514 (BYTE *) &buf, &dummyLen);
515 if (code == ERROR_SUCCESS) {
516 DWORD len = ExpandEnvironmentStrings(buf, cm_NetBiosName, MAX_NB_NAME_LENGTH);
517 if ( len > 0 && len <= MAX_NB_NAME_LENGTH ) {
518 afsi_log("Explicit NetBios name is used %s", cm_NetBiosName);
520 afsi_log("Unable to Expand Explicit NetBios name: %s", buf);
521 cm_NetBiosName[0] = 0; /* turn it off */
525 cm_NetBiosName[0] = 0; /* default off */
528 dummyLen = sizeof(smb_hideDotFiles);
529 code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
530 (BYTE *) &smb_hideDotFiles, &dummyLen);
531 if (code != ERROR_SUCCESS) {
532 smb_hideDotFiles = 1; /* default on */
534 afsi_log("Dot files/dirs will %sbe marked hidden",
535 smb_hideDotFiles ? "" : "not ");
537 dummyLen = sizeof(smb_maxMpxRequests);
538 code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
539 (BYTE *) &smb_maxMpxRequests, &dummyLen);
540 if (code != ERROR_SUCCESS) {
541 smb_maxMpxRequests = 50;
543 afsi_log("Maximum number of multiplexed sessions is %d", smb_maxMpxRequests);
545 dummyLen = sizeof(smb_maxVCPerServer);
546 code = RegQueryValueEx(parmKey, "MaxVCPerServer", NULL, NULL,
547 (BYTE *) &smb_maxVCPerServer, &dummyLen);
548 if (code != ERROR_SUCCESS) {
549 smb_maxVCPerServer = 100;
551 afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
553 dummyLen = sizeof(smb_authType);
554 code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
555 (BYTE *) &smb_authType, &dummyLen);
557 if (code != ERROR_SUCCESS ||
558 (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
559 smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
561 afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
563 dummyLen = sizeof(rx_nojumbo);
564 code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
565 (BYTE *) &rx_nojumbo, &dummyLen);
566 if (code != ERROR_SUCCESS) {
570 afsi_log("RX Jumbograms are disabled");
572 dummyLen = sizeof(rx_mtu);
573 code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
574 (BYTE *) &rx_mtu, &dummyLen);
575 if (code != ERROR_SUCCESS || !rx_mtu) {
579 afsi_log("RX maximum MTU is %d", rx_mtu);
581 dummyLen = sizeof(ConnDeadtimeout);
582 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
583 (BYTE *) &ConnDeadtimeout, &dummyLen);
584 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
586 dummyLen = sizeof(HardDeadtimeout);
587 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
588 (BYTE *) &HardDeadtimeout, &dummyLen);
589 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
591 RegCloseKey (parmKey);
593 /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
594 if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
595 LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
598 afsi_log("LAN adapter number %d", LANadapter);
600 afsi_log("LAN adapter number not determined");
603 afsi_log("Set for gateway service");
605 afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
607 /* something went horribly wrong. We can't proceed without a netbios name */
608 StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
609 osi_panic(buf, __FILE__, __LINE__);
612 /* setup early variables */
613 /* These both used to be configurable. */
615 buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE;
617 /* turn from 1024 byte units into memory blocks */
618 cacheBlocks = (cacheSize * 1024) / buf_bufferSize;
620 /* get network related info */
621 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
622 code = syscfg_GetIFInfo(&cm_noIPAddr,
623 cm_IPAddr, cm_SubnetMask,
624 cm_NetMtu, cm_NetFlags);
626 if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
627 afsi_log("syscfg_GetIFInfo error code %d", code);
629 afsi_log("First Network address %x SubnetMask %x",
630 cm_IPAddr[0], cm_SubnetMask[0]);
633 * Save client configuration for GetCacheConfig requests
635 cm_initParams.nChunkFiles = 0;
636 cm_initParams.nStatCaches = stats;
637 cm_initParams.nDataCaches = 0;
638 cm_initParams.nVolumeCaches = 0;
639 cm_initParams.firstChunkSize = cm_chunkSize;
640 cm_initParams.otherChunkSize = cm_chunkSize;
641 cm_initParams.cacheSize = cacheSize;
642 cm_initParams.setTime = 0;
643 cm_initParams.memCache = 0;
645 /* Set RX parameters before initializing RX */
648 afsi_log("rx_SetNoJumbo successful");
651 if ( rx_mtu != -1 ) {
652 rx_SetMaxMTU(rx_mtu);
653 afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
656 /* Open Microsoft Firewall to allow in port 7001 */
660 TCHAR* value = TEXT("7001:UDP:*:Enabled:AFS Cache Manager Callback");
661 if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
662 "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\\GloballyOpenP",
663 0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
665 RegSetValueEx (hk, TEXT("7001:UDP"), 0, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value)));
668 if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
669 "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\GloballyOpenP",
670 0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
672 RegSetValueEx (hk, TEXT("7001:UDP"), 0, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value)));
677 /* initialize RX, and tell it to listen to port 7001, which is used for
678 * callback RPC messages.
680 code = rx_Init(htons(7001));
681 afsi_log("rx_Init code %x", code);
683 *reasonP = "afsd: failed to init rx client on port 7001";
687 /* Initialize the RPC server for session keys */
690 /* create an unauthenticated service #1 for callbacks */
691 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
692 serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1,
693 RXAFSCB_ExecuteRequest);
694 afsi_log("rx_NewService addr %x", (int)serverp);
695 if (serverp == NULL) {
696 *reasonP = "unknown error";
700 nullServerSecurityClassp = rxnull_NewServerSecurityObject();
701 serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
702 &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest);
703 afsi_log("rx_NewService addr %x", (int)serverp);
704 if (serverp == NULL) {
705 *reasonP = "unknown error";
709 /* start server threads, *not* donating this one to the pool */
711 afsi_log("rx_StartServer");
713 /* init user daemon, and other packages */
716 cm_InitACLCache(2*stats);
732 cm_InitSCache(stats);
734 code = cm_InitDCache(0, cacheBlocks);
735 afsi_log("cm_InitDCache code %x", code);
737 *reasonP = "error initializing cache";
742 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
743 if (cm_InitDNS(cm_dnsEnabled) == -1)
744 cm_dnsEnabled = 0; /* init failed, so deactivate */
745 afsi_log("cm_InitDNS %d", cm_dnsEnabled);
749 code = cm_GetRootCellName(rootCellName);
750 afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s",
751 code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
752 if (code != 0 && !cm_freelanceEnabled)
754 *reasonP = "can't find root cell name in afsd.ini";
757 else if (cm_freelanceEnabled)
760 if (code == 0 && !cm_freelanceEnabled)
762 cm_rootCellp = cm_GetCell(rootCellName, CM_FLAG_CREATE);
763 afsi_log("cm_GetCell addr %x", (int)cm_rootCellp);
764 if (cm_rootCellp == NULL)
766 *reasonP = "can't find root cell in afsdcell.ini";
771 #ifdef AFS_FREELANCE_CLIENT
772 if (cm_freelanceEnabled)
779 int afsd_InitDaemons(char **reasonP)
786 /* this should really be in an init daemon from here on down */
788 if (!cm_freelanceEnabled) {
789 osi_Log0(afsd_logp, "Loading Root Volume from cell");
790 code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
791 &req, CM_FLAG_CREATE, &cm_rootVolumep);
792 afsi_log("cm_GetVolumeByName code %x root vol %x", code,
793 (code ? (cm_volume_t *)-1 : cm_rootVolumep));
795 *reasonP = "can't find root volume in root cell";
800 /* compute the root fid */
801 if (!cm_freelanceEnabled) {
802 cm_rootFid.cell = cm_rootCellp->cellID;
803 cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep);
804 cm_rootFid.vnode = 1;
805 cm_rootFid.unique = 1;
808 cm_FakeRootFid(&cm_rootFid);
810 code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req);
811 afsi_log("cm_GetSCache code %x scache %x", code,
812 (code ? (cm_scache_t *)-1 : cm_rootSCachep));
814 *reasonP = "unknown error";
818 cm_InitDaemon(numBkgD);
819 afsi_log("cm_InitDaemon");
824 int afsd_InitSMB(char **reasonP, void *aMBfunc)
826 /* Do this last so that we don't handle requests before init is done.
827 * Here we initialize the SMB listener.
829 smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
830 afsi_log("smb_Init");
843 #pragma pack( push, before_imagehlp, 8 )
844 #include <imagehlp.h>
845 #pragma pack( pop, before_imagehlp )
847 #define MAXNAMELEN 1024
849 void afsd_printStack(HANDLE hThread, CONTEXT *c)
851 HANDLE hProcess = GetCurrentProcess();
855 char functionName[MAXNAMELEN];
857 IMAGEHLP_MODULE Module;
861 IMAGEHLP_SYMBOL *pSym;
863 afsi_log_useTimestamp = 0;
865 pSym = (IMAGEHLP_SYMBOL *) GlobalAlloc(0, sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN);
867 memset( &s, '\0', sizeof s );
868 if (!SymInitialize(hProcess, NULL, 1) )
870 afsi_log("SymInitialize(): GetLastError() = %lu\n", GetLastError() );
872 SymCleanup( hProcess );
878 symOptions = SymGetOptions();
879 symOptions |= SYMOPT_LOAD_LINES;
880 symOptions &= ~SYMOPT_UNDNAME;
881 SymSetOptions( symOptions );
884 * init STACKFRAME for first call
885 * Notes: AddrModeFlat is just an assumption. I hate VDM debugging.
886 * Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway,
889 #if defined (_ALPHA_) || defined (_MIPS_) || defined (_PPC_)
890 #error The STACKFRAME initialization in afsd_printStack() for this platform
891 #error must be properly configured
893 s.AddrPC.Offset = c->Eip;
894 s.AddrPC.Mode = AddrModeFlat;
895 s.AddrFrame.Offset = c->Ebp;
896 s.AddrFrame.Mode = AddrModeFlat;
899 memset( pSym, '\0', sizeof (IMAGEHLP_SYMBOL) + MAXNAMELEN );
900 pSym->SizeOfStruct = sizeof (IMAGEHLP_SYMBOL);
901 pSym->MaxNameLength = MAXNAMELEN;
903 memset( &Line, '\0', sizeof Line );
904 Line.SizeOfStruct = sizeof Line;
906 memset( &Module, '\0', sizeof Module );
907 Module.SizeOfStruct = sizeof Module;
911 afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
913 for ( frameNum = 0; ; ++ frameNum )
916 * get next stack frame (StackWalk(), SymFunctionTableAccess(),
917 * SymGetModuleBase()). if this returns ERROR_INVALID_ADDRESS (487) or
918 * ERROR_NOACCESS (998), you can assume that either you are done, or
919 * that the stack is so hosed that the next deeper frame could not be
922 if ( ! StackWalk( IMAGE_FILE_MACHINE_I386, hProcess, hThread, &s, c,
923 NULL, SymFunctionTableAccess, SymGetModuleBase,
927 /* display its contents */
928 afsi_log("\n%3d %c%c %08lx %08lx %08lx %08lx ",
929 frameNum, s.Far? 'F': '.', s.Virtual? 'V': '.',
930 s.AddrPC.Offset, s.AddrReturn.Offset,
931 s.AddrFrame.Offset, s.AddrStack.Offset );
933 if ( s.AddrPC.Offset == 0 )
935 afsi_log("(-nosymbols- PC == 0)" );
939 /* show procedure info from a valid PC */
940 if (!SymGetSymFromAddr(hProcess, s.AddrPC.Offset, &offset, pSym))
942 if ( GetLastError() != ERROR_INVALID_ADDRESS )
944 afsi_log("SymGetSymFromAddr(): errno = %lu",
950 UnDecorateSymbolName(pSym->Name, functionName, MAXNAMELEN,
952 afsi_log("%s", functionName );
956 afsi_log(" %+ld bytes", (long) offset);
960 if (!SymGetLineFromAddr(hProcess, s.AddrPC.Offset, &offset, &Line))
962 if (GetLastError() != ERROR_INVALID_ADDRESS)
964 afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
970 afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
971 Line.LineNumber, offset);
975 /* no return address means no deeper stackframe */
976 if (s.AddrReturn.Offset == 0)
983 if (GetLastError() != 0)
985 afsi_log("\nStackWalk(): errno = %lu\n", GetLastError());
988 SymCleanup(hProcess);
993 static DWORD *afsd_crtDbgBreakCurrent = NULL;
994 static DWORD afsd_crtDbgBreaks[256];
997 LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
1001 BOOL allocRequestBrk = FALSE;
1004 afsi_log("UnhandledException : code : 0x%x, address: 0x%x\n",
1005 ep->ExceptionRecord->ExceptionCode,
1006 ep->ExceptionRecord->ExceptionAddress);
1009 if (afsd_crtDbgBreakCurrent &&
1010 *afsd_crtDbgBreakCurrent == _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent))
1012 allocRequestBrk = TRUE;
1013 afsi_log("Breaking on alloc request # %d\n", *afsd_crtDbgBreakCurrent);
1017 /* save context if we want to print the stack information */
1018 context = *ep->ContextRecord;
1020 afsd_printStack(GetCurrentThread(), &context);
1022 if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
1024 afsi_log("\nEXCEPTION_BREAKPOINT - continue execution ...\n");
1027 if (allocRequestBrk)
1029 afsd_crtDbgBreakCurrent++;
1030 _CrtSetBreakAlloc(*afsd_crtDbgBreakCurrent);
1034 ep->ContextRecord->Eip++;
1035 return EXCEPTION_CONTINUE_EXECUTION;
1039 return EXCEPTION_CONTINUE_SEARCH;
1043 void afsd_SetUnhandledExceptionFilter()
1045 SetUnhandledExceptionFilter(afsd_ExceptionFilter);
1049 void afsd_DbgBreakAllocInit()
1051 memset(afsd_crtDbgBreaks, -1, sizeof(afsd_crtDbgBreaks));
1052 afsd_crtDbgBreakCurrent = afsd_crtDbgBreaks;
1055 void afsd_DbgBreakAdd(DWORD requestNumber)
1058 for (i = 0; i < sizeof(afsd_crtDbgBreaks) - 1; i++)
1060 if (afsd_crtDbgBreaks[i] == -1)
1065 afsd_crtDbgBreaks[i] = requestNumber;
1067 _CrtSetBreakAlloc(afsd_crtDbgBreaks[0]);