ticket-6077-20040804
authorJeffrey Altman <jaltman@mit.edu>
Wed, 4 Aug 2004 20:30:03 +0000 (20:30 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 4 Aug 2004 20:30:03 +0000 (20:30 +0000)
FIXES 6077

Patch from Joe Buehler modified by Asanka

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/afslogon.c
src/WINNT/afsd/afslogon.h
src/WINNT/afsd/logon_ad.cpp

index 96cccf0..348c86d 100644 (file)
@@ -69,7 +69,7 @@ int logReady = 0;
 char cm_HostName[200];
 long cm_HostAddr;
 
-char cm_NetbiosName[MAX_NB_NAME_LENGTH];
+char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
 
 char cm_CachePath[200];
 DWORD cm_CachePathLen;
@@ -100,8 +100,6 @@ HANDLE afsi_file;
 int cm_dnsEnabled = 1;
 #endif
 
-char cm_NetBiosName[32];
-
 extern initUpperCaseTable();
 void afsd_initUpperCaseTable() 
 {
@@ -698,21 +696,24 @@ int afsd_InitCM(char **reasonP)
        }
 #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);
+        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);
+            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 */
+            cm_NetbiosName[0] = 0;  /* turn it off */
         }
     }
     else {
-        cm_NetBiosName[0] = 0;   /* default off */
+        cm_NetbiosName[0] = 0;   /* default off */
     }
+#endif
 
     dummyLen = sizeof(smb_hideDotFiles);
     code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
index 7216f68..15feb9b 100644 (file)
@@ -853,7 +853,7 @@ VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo )
      */
     if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) {
         WCHAR Domain[64]=L"";
-        GetLocalShortDomain(Domain);
+        GetLocalShortDomain(Domain, sizeof(Domain));
         if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain))
             GetUserProfileDirectory(pInfo->hToken, profileDir, &len);
     }
index dc1d4f6..d222642 100644 (file)
@@ -120,7 +120,7 @@ void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, Log
 DWORD GetFileCellName(char * path, char * cell, size_t cellLen);
 DWORD GetAdHomePath(char * homePath, size_t homePathLen, PLUID lpLogonId, LogonOptions_t * opt);
 DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid, PWSTR domain);
-BOOL GetLocalShortDomain(PWSTR Domain);
+BOOL GetLocalShortDomain(PWSTR Domain, DWORD cbDomain);
 
 #ifdef __cplusplus
 }
index 6705cfa..2041471 100644 (file)
@@ -244,9 +244,15 @@ DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid, PWS
                     BSTR bstr;
 
                     hr = pNto->Get(ADS_NAME_TYPE_1779, &bstr);
-                    wcscpy(adsPath, bstr);
-
-                    SysFreeString(bstr);
+                    if(SUCCEEDED(hr)) {
+                        hr = StringCchCopyW(adsPath, MAX_PATH, bstr);
+                        if(FAILED(hr)) {
+                            DebugEvent("Overflow while copying ADS path");
+                            adsPath[0] = L'\0';
+                        }
+
+                        SysFreeString(bstr);
+                    }
                 }
             }
             pNto->Release();
@@ -349,7 +355,7 @@ DWORD GetAdHomePath(char * homePath, size_t homePathLen, PLUID lpLogonId, LogonO
        }
 }
 
-BOOL GetLocalShortDomain(PWSTR Domain)
+BOOL GetLocalShortDomain(PWSTR Domain, DWORD cbDomain)
 {
     HRESULT hr;
     IADsADSystemInfo *pADsys;
@@ -370,9 +376,11 @@ BOOL GetLocalShortDomain(PWSTR Domain)
 
         hr = pADsys->get_DomainShortName(&bstr);
         if ( !FAILED(hr) ) {
-            wcscpy( Domain, bstr );
+            hr = StringCbCopyW( Domain, cbDomain, bstr );
+            if(SUCCEEDED(hr)) {
+                retval = TRUE;
+            }
             SysFreeString(bstr);
-            retval = TRUE;
         }
         pADsys->Release();
     }