windows-aclent-remove-extraneous-code-20071024
[openafs.git] / src / WINNT / afsd / afsd_init.c
index 56523dd..f75679f 100644 (file)
@@ -38,6 +38,11 @@ extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
 extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
 
 extern afs_int32 cryptall;
+extern int cm_enableServerLocks;
+extern int cm_deleteReadOnly;
+extern afs_int32 cm_BPlusTrees;
+extern afs_int32 cm_OfflineROIsValid;
+extern const char **smb_ExecutableExtensions;
 
 osi_log_t *afsd_logp;
 
@@ -66,6 +71,7 @@ int logReady = 0;
 
 char cm_HostName[200];
 long cm_HostAddr;
+unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
 
 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
 
@@ -73,8 +79,6 @@ char cm_CachePath[MAX_PATH];
 DWORD cm_CachePathLen;
 DWORD cm_ValidateCache = 1;
 
-BOOL isGateway = FALSE;
-
 BOOL reportSessionStartups = FALSE;
 
 cm_initparams_v1 cm_initParams;
@@ -114,7 +118,7 @@ afsi_log(char *pattern, ...)
     if ( afsi_log_useTimestamp ) {
         GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
         GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
-        StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
+        StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
         if (afsi_file != INVALID_HANDLE_VALUE)
             WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
 #ifdef NOTSERVICE
@@ -135,7 +139,7 @@ void afsd_initUpperCaseTable()
 void
 afsi_start()
 {
-    char wd[256];
+    char wd[MAX_PATH+1];
     char t[100], u[100], *p, *path;
     int zilch;
     DWORD code;
@@ -145,13 +149,10 @@ afsi_start()
     DWORD maxLogSize = 100 * 1024;
 
     afsi_file = INVALID_HANDLE_VALUE;
-    code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
-    if ( code == 0 || code > sizeof(wd) )
-    {
-        code = GetWindowsDirectory(wd, sizeof(wd));
-        if (code == 0) 
-            return;
-    }
+    code = GetTempPath(sizeof(wd)-15, wd);
+    if ( code == 0 || code > (sizeof(wd)-15) )
+        return;         /* unable to create a log */
+
     StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
     GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
     afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
@@ -177,8 +178,8 @@ afsi_start()
 
     SetFilePointer(afsi_file, 0, NULL, FILE_END);
     GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
-    StringCbCatA(t, sizeof(t), ": Create log file\n");
-    StringCbCatA(u, sizeof(u), ": Created log file\n");
+    StringCbCatA(t, sizeof(t), ": Create log file\r\n");
+    StringCbCatA(u, sizeof(u), ": Created log file\r\n");
     WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
     WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
     p = "PATH=";
@@ -187,7 +188,7 @@ afsi_start()
     code = GetEnvironmentVariable("PATH", path, code);
     WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
     WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
-    WriteFile(afsi_file, "\n", (DWORD)1, &zilch, NULL);
+    WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
     free(path);
 
     /* Initialize C RTL Code Page conversion functions */
@@ -268,7 +269,7 @@ configureBackConnectionHostNames(void)
     HKEY hkMSV10;
     HKEY hkClient;
     DWORD dwType;
-    DWORD dwSize;
+    DWORD dwSize, dwAllocSize;
     DWORD dwValue;
     PBYTE pHostNames = NULL, pName = NULL;
     BOOL  bNameFound = FALSE;   
@@ -279,32 +280,41 @@ configureBackConnectionHostNames(void)
                        KEY_READ|KEY_WRITE,
                        &hkMSV10) == ERROR_SUCCESS )
     {
-        if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) {
-            pHostNames = malloc(dwSize + strlen(cm_NetbiosName) + 1);
-            RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, pHostNames, &dwSize);
-
-            for (pName = pHostNames; *pName ; pName += strlen(pName) + 1)
+        if ((RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, 
+                            &dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
+            (dwType == REG_MULTI_SZ)) 
+        {
+           dwAllocSize += 1 /* in case the source string is not nul terminated */
+               + strlen(cm_NetbiosName) + 2;
+           pHostNames = malloc(dwAllocSize);
+           dwSize = dwAllocSize;
+            if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, 
+                                pHostNames, &dwSize) == ERROR_SUCCESS) 
             {
-                if ( !stricmp(pName, cm_NetbiosName) ) {
-                    bNameFound = TRUE;
-                    break;
-                }   
-            }
+               for (pName = pHostNames; 
+                    (pName - pHostNames < dwSize) && *pName ; 
+                    pName += strlen(pName) + 1)
+               {
+                   if ( !stricmp(pName, cm_NetbiosName) ) {
+                       bNameFound = TRUE;
+                       break;
+                   }   
+               }
+           }
         }
              
         if ( !bNameFound ) {
             size_t size = strlen(cm_NetbiosName) + 2;
             if ( !pHostNames ) {
                 pHostNames = malloc(size);
-                dwSize = 1;
+               pName = pHostNames;
             }
-            pName = pHostNames;
             StringCbCopyA(pName, size, cm_NetbiosName);
             pName += size - 1;
             *pName = '\0';  /* add a second nul terminator */
 
             dwType = REG_MULTI_SZ;
-            dwSize += (DWORD)strlen(cm_NetbiosName) + 1;
+           dwSize = pName - pHostNames + 1;
             RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
 
             if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
@@ -370,9 +380,12 @@ configureBackConnectionHostNames(void)
         }
         RegCloseKey(hkMSV10);
     }
+
+    if (pHostNames)
+       free(pHostNames);
 }
 
-#if !defined(DJGPP)
+
 static void afsd_InitServerPreferences(void)
 {
     HKEY hkPrefs = 0;
@@ -522,7 +535,6 @@ static void afsd_InitServerPreferences(void)
         RegCloseKey(hkPrefs);
     }
 }
-#endif /* DJGPP */
 
 /*
  * AFSD Initialization
@@ -533,8 +545,10 @@ int afsd_InitCM(char **reasonP)
     osi_uid_t debugID;
     afs_uint64 cacheBlocks;
     DWORD cacheSize;
+    DWORD blockSize;
     long logChunkSize;
     DWORD stats;
+    DWORD dwValue;
     DWORD rx_enable_peer_stats = 0;
     DWORD rx_enable_process_stats = 0;
     long traceBufSize;
@@ -554,7 +568,6 @@ int afsd_InitCM(char **reasonP)
     long code;
     /*int freelanceEnabled;*/
     WSADATA WSAjunk;
-    lana_number_t lanaNum;
     int i;
     char *p, *q; 
     int cm_noIPAddr;         /* number of client network interfaces */
@@ -573,9 +586,12 @@ int afsd_InitCM(char **reasonP)
     code = osi_InitDebug(&debugID);
     afsi_log("osi_InitDebug code %d", code);
 
-    // osi_LockTypeSetDefault("stat"); /* comment this out for speed *
+    // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
     if (code != 0) {
-        *reasonP = "unknown error";
+        if (code == RPC_S_NO_PROTSEQS)
+            *reasonP = "No RPC Protocol Sequences registered.  Check HKLM\\SOFTWARE\\Microsoft\\RPC\\ClientProtocols";
+        else
+            *reasonP = "unknown error";
         return -1;
     }
 
@@ -685,13 +701,44 @@ int afsd_InitCM(char **reasonP)
                       logChunkSize);
             logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
         }
-        afsi_log("Chunk size %d", logChunkSize);
     } else {
         logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
-        afsi_log("Default chunk size %d", logChunkSize);
     }
     cm_logChunkSize = logChunkSize;
     cm_chunkSize = 1 << logChunkSize;
+    afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
+
+    dummyLen = sizeof(blockSize);
+    code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
+                            (BYTE *) &blockSize, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        if (blockSize < 1 || 
+            (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0))) 
+        {
+            afsi_log("Invalid block size %u specified, using default", blockSize);
+            blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+        } else {
+            /* 
+             * if the blockSize is less than 1024 we permit the blockSize to be
+             * specified in multiples of the default blocksize
+             */
+            if (blockSize <= 1024)
+                blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
+        }
+    } else {
+        blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+    }
+    if (blockSize > cm_chunkSize) {
+        afsi_log("Block size (%d) cannot be larger than Chunk size (%d).", 
+                  blockSize, cm_chunkSize);
+        blockSize = cm_chunkSize;
+    }
+    if (cm_chunkSize % blockSize != 0) {
+        afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
+                  blockSize, cm_chunkSize);
+        blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+    }
+    afsi_log("Block size %u", blockSize);
 
     dummyLen = sizeof(numBkgD);
     code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
@@ -726,30 +773,22 @@ int afsd_InitCM(char **reasonP)
     dummyLen = sizeof(ltt);
     code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL,
                             (BYTE *) &ltt, &dummyLen);
-    if (code == ERROR_SUCCESS)
-        afsi_log("Logoff token transfer %s",  (ltt ? "on" : "off"));
-    else {
+    if (code != ERROR_SUCCESS)
         ltt = 1;
-        afsi_log("Logoff token transfer on by default");
-    }
     smb_LogoffTokenTransfer = ltt;
-    afsi_log("Logoff token transfer is currently ignored");
+    afsi_log("Logoff token transfer %s",  (ltt ? "on" : "off"));
 
     if (ltt) {
         dummyLen = sizeof(ltto);
         code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout",
                                 NULL, NULL, (BYTE *) &ltto, &dummyLen);
-        if (code == ERROR_SUCCESS)
-            afsi_log("Logoff token tranfer timeout %d seconds", ltto);
-        else {
-            ltto = 10;
-            afsi_log("Default logoff token transfer timeout 10 seconds");
-        }
+        if (code != ERROR_SUCCESS)
+            ltto = 120;
     } else {
         ltto = 0;
     }   
     smb_LogoffTransferTimeout = ltto;
-    afsi_log("Default logoff token is currently ignored");
+    afsi_log("Logoff token transfer timeout %d seconds", ltto);
 
     dummyLen = sizeof(cm_rootVolumeName);
     code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
@@ -850,8 +889,8 @@ int afsd_InitCM(char **reasonP)
     if (code != ERROR_SUCCESS || !buf[0]) {
 #if defined(_IA64_)
         StringCbCopyA(buf, sizeof(buf), "ia64_win64");
-#elif defined(_AMD64)
-        StringCbCopyA(buf, sizeof(buf), "amd64_win64");
+#elif defined(_AMD64_)
+        StringCbCopyA(buf, sizeof(buf), "amd64_win64 x86_win32 i386_w2k");
 #else /* assume x86 32-bit */
         StringCbCopyA(buf, sizeof(buf), "x86_win32 i386_w2k i386_nt40");
 #endif
@@ -888,6 +927,11 @@ int afsd_InitCM(char **reasonP)
         afsi_log("Default SecurityLevel is clear");
     }
 
+    if (cryptall)
+       LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
+    else
+       LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
+
 #ifdef AFS_AFSDB_ENV
     dummyLen = sizeof(cm_dnsEnabled);
     code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
@@ -913,29 +957,10 @@ int afsd_InitCM(char **reasonP)
                   cm_freelanceEnabled ? "is" : "is not");
     }       
     else {
-        cm_freelanceEnabled = 0;  /* default off */
+        cm_freelanceEnabled = 1;  /* default on */
     }
 #endif /* AFS_FREELANCE_CLIENT */
 
-#ifdef COMMENT
-    /* The netbios name is looked up in lana_GetUNCServerNameEx */
-    dummyLen = sizeof(buf);
-    code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
-                           (BYTE *) &buf, &dummyLen);
-    if (code == ERROR_SUCCESS) {
-        DWORD len = ExpandEnvironmentStrings(buf, cm_NetbiosName, MAX_NB_NAME_LENGTH);
-        if ( len > 0 && len <= MAX_NB_NAME_LENGTH ) {
-            afsi_log("Explicit NetBios name is used %s", cm_NetbiosName);
-        } else {
-            afsi_log("Unable to Expand Explicit NetBios name: %s", buf);
-            cm_NetbiosName[0] = 0;  /* turn it off */
-        }
-    }
-    else {
-        cm_NetbiosName[0] = 0;   /* default off */
-    }
-#endif
-
     dummyLen = sizeof(smb_hideDotFiles);
     code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
                            (BYTE *) &smb_hideDotFiles, &dummyLen);
@@ -1007,38 +1032,92 @@ int afsd_InitCM(char **reasonP)
     if (rx_enable_process_stats)
         afsi_log("RX Process Statistics gathering is enabled");
 
-    dummyLen = sizeof(ConnDeadtimeout);
-    code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
-                           (BYTE *) &ConnDeadtimeout, &dummyLen);
-    afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_callbackport = (unsigned short) dwValue;
+    }
+    afsi_log("CM CallBackPort is %u", cm_callbackport);
 
-    dummyLen = sizeof(HardDeadtimeout);
-    code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
-                           (BYTE *) &HardDeadtimeout, &dummyLen);
-    afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "EnableServerLocks", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_enableServerLocks = (unsigned short) dwValue;
+    } 
+    switch (cm_enableServerLocks) {
+    case 0:
+       afsi_log("EnableServerLocks: never");
+       break;
+    case 2:
+       afsi_log("EnableServerLocks: always");
+       break;
+    case 1:
+    default:
+       afsi_log("EnableServerLocks: server requested");
+       break;
+    }
 
-    RegCloseKey (parmKey);
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_deleteReadOnly = (unsigned short) dwValue;
+    } 
+    afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
+    
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_BPlusTrees = (unsigned short) dwValue;
+    } 
+    afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
 
-    /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
-    if (SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
-        LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
+    if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, 
+                          &regType, NULL, &dummyLen) == ERROR_SUCCESS) &&
+         (regType == REG_MULTI_SZ)) 
+    {
+        char * pSz;
+        dummyLen += 3; /* in case the source string is not nul terminated */
+        pSz = malloc(dummyLen);
+        if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, &regType, 
+                             pSz, &dummyLen) == ERROR_SUCCESS) &&
+             (regType == REG_MULTI_SZ))
+        {
+            int cnt;
+            char * p;
 
-        if (LANadapter != -1)
-            afsi_log("LAN adapter number %d", LANadapter);
-        else
-            afsi_log("LAN adapter number not determined");
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1);
 
-        if (isGateway)
-            afsi_log("Set for gateway service");
+            smb_ExecutableExtensions = malloc(sizeof(char *) * (cnt+1));
 
-        afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
-    } else {
-        /* something went horribly wrong.  We can't proceed without a netbios name */
-        StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
-        osi_panic(buf, __FILE__, __LINE__);
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1)
+            {
+                smb_ExecutableExtensions[cnt] = p;
+                afsi_log("PrefetchExecutableExtension: \"%s\"", p);
+            }
+            smb_ExecutableExtensions[cnt] = NULL;
+        }
+        
+        if (!smb_ExecutableExtensions)
+            free(pSz);
     }
+    if (!smb_ExecutableExtensions)
+        afsi_log("No PrefetchExecutableExtensions");
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_OfflineROIsValid = (unsigned short) dwValue;
+    } 
+    afsi_log("CM OfflineReadOnlyIsValid is %u", cm_deleteReadOnly);
+    
+    RegCloseKey (parmKey);
 
-    cacheBlocks = ((afs_uint64)cacheSize * 1024) / CM_CONFIGDEFAULT_BLOCKSIZE;
+    cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
         
     /* get network related info */
     cm_noIPAddr = CM_MAXINTERFACE_ADDR;
@@ -1081,7 +1160,7 @@ int afsd_InitCM(char **reasonP)
         
     cm_InitCallback();
         
-    code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, cm_chunkSize, cacheBlocks);
+    code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, cm_chunkSize, cacheBlocks, blockSize);
     afsi_log("cm_InitMappedMemory code %x", code);
     if (code != 0) {
         *reasonP = "error initializing cache file";
@@ -1107,13 +1186,17 @@ int afsd_InitCM(char **reasonP)
         afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
     }
 
-    /* initialize RX, and tell it to listen to port 7001, which is used for
-     * callback RPC messages.
+    /* initialize RX, and tell it to listen to the callbackport, 
+     * which is used for callback RPC messages.
      */
-    code = rx_Init(htons(7001));
+    code = rx_Init(htons(cm_callbackport));
+    if (code != 0) {
+       afsi_log("rx_Init code %x - retrying with a random port number", code);
+       code = rx_Init(0);
+    }
     afsi_log("rx_Init code %x", code);
     if (code != 0) {
-        *reasonP = "afsd: failed to init rx client on port 7001";
+        *reasonP = "afsd: failed to init rx client";
         return -1;
     }
 
@@ -1151,7 +1234,7 @@ int afsd_InitCM(char **reasonP)
               code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
     if (code != 0 && !cm_freelanceEnabled) 
     {
-        *reasonP = "can't find root cell name in afsd.ini";
+        *reasonP = "can't find root cell name in CellServDB";
         return -1;
     }   
     else if (cm_freelanceEnabled)
@@ -1176,9 +1259,14 @@ int afsd_InitCM(char **reasonP)
     /* Initialize the RPC server for session keys */
     RpcInit();
 
-#if !defined(DJGPP)
     afsd_InitServerPreferences();
-#endif
+    return 0;
+}
+
+int afsd_ShutdownCM(void)
+{
+    cm_ReleaseSCache(cm_data.rootSCachep);
+
     return 0;
 }
 
@@ -1192,11 +1280,15 @@ int afsd_InitDaemons(char **reasonP)
     /* this should really be in an init daemon from here on down */
 
     if (!cm_freelanceEnabled) {
+       int attempts = 10;
+
         osi_Log0(afsd_logp, "Loading Root Volume from cell");
-        code = cm_GetVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
-                                  &req, CM_FLAG_CREATE, &cm_data.rootVolumep);
-        afsi_log("cm_GetVolumeByName code %x root vol %x", code,
-                 (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
+       do {
+           code = cm_GetVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
+                                      &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
+           afsi_log("cm_GetVolumeByName code %x root vol %x", code,
+                     (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
+       } while (code && --attempts);
         if (code != 0) {
             *reasonP = "can't find root volume in root cell";
             return -1;
@@ -1248,7 +1340,7 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
     /* Do this last so that we don't handle requests before init is done.
      * Here we initialize the SMB listener.
      */
-    smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
+    smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
     afsi_log("smb_Init complete");
 
     return 0;
@@ -1270,7 +1362,6 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
 
 void afsd_printStack(HANDLE hThread, CONTEXT *c)
 {
-#if defined(_X86_)
     HANDLE hProcess = GetCurrentProcess();
     int frameNum;
 #if defined(_AMD64_)
@@ -1317,9 +1408,9 @@ void afsd_printStack(HANDLE hThread, CONTEXT *c)
 #error The STACKFRAME initialization in afsd_printStack() for this platform
 #error must be properly configured
 #elif defined(_AMD64_)
-    s.AddrPC.Offset = 0;
+    s.AddrPC.Offset = c->Rip;
     s.AddrPC.Mode = AddrModeFlat;
-    s.AddrFrame.Offset = 0;
+    s.AddrFrame.Offset = c->Rbp;
     s.AddrFrame.Mode = AddrModeFlat;
 #else
     s.AddrPC.Offset = c->Eip;
@@ -1419,7 +1510,6 @@ void afsd_printStack(HANDLE hThread, CONTEXT *c)
   
     SymCleanup(hProcess);
     GlobalFree(pSym);
-#endif /* _X86_ */
 }
 
 #ifdef _DEBUG
@@ -1455,6 +1545,9 @@ OpenDumpFile(void)
 void 
 GenerateMiniDump(PEXCEPTION_POINTERS ep)
 {
+       if (IsDebuggerPresent())
+               return;
+
     if (ep == NULL) 
     {
         // Generate exception to get proper context in dump
@@ -1489,7 +1582,7 @@ GenerateMiniDump(PEXCEPTION_POINTERS ep)
             DWORD dummyLen;
             DWORD dwValue;
             DWORD code;
-            DWORD dwMiniDumpType = MiniDumpNormal;
+            DWORD dwMiniDumpType = MiniDumpWithDataSegs;
 
             code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
                                  0, KEY_QUERY_VALUE, &parmKey);
@@ -1498,7 +1591,7 @@ GenerateMiniDump(PEXCEPTION_POINTERS ep)
                 code = RegQueryValueEx(parmKey, "MiniDumpType", NULL, NULL,
                                         (BYTE *) &dwValue, &dummyLen);
                 if (code == ERROR_SUCCESS)
-                    dwMiniDumpType = dwValue ? 1 : 0;
+                    dwMiniDumpType = dwValue;
                 RegCloseKey (parmKey);
             }
 
@@ -1566,6 +1659,9 @@ LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
 #if defined(_X86)    
         ep->ContextRecord->Eip++;
 #endif
+#if defined(_AMD64_)
+        ep->ContextRecord->Rip++;
+#endif
         return EXCEPTION_CONTINUE_EXECUTION;
     }
     else