From 1a5fbdb9432add6f5acad22d7ee787d567c00fca Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 22 Jul 2004 23:15:37 +0000 Subject: [PATCH] afslogon-20040722 the procedure used to obtain the profile directory failed in Domains which were not Forests. If ADS_NAME_INITTYPE_GC fails, we must try ADS_NAME_INITTYPE_DOMAIN which requires the Domain. Added a Domain parameter to QueryAdHomePathFromSid. This was easy to obtain in the NPLogonNotify since the logon domain is provided as a parameter. Unfortunately, the domain provided to the winlogon event notification routine is the user authentication domain, not the logon domain for the local machine. Needed to create a GetLocalShortDomain function which uses the IADsADSystemInfo COM interface to obtain the local short domain. With this in place, we can now properly detect the profile directory in all cases. Document MaxLogSize in registry.txt --- doc/txt/winnotes/registry.txt | 10 ++++++++ src/WINNT/afsd/NTMakefile | 1 - src/WINNT/afsd/afslogon.c | 11 ++++++-- src/WINNT/afsd/afslogon.h | 3 ++- src/WINNT/afsd/logon_ad.cpp | 58 +++++++++++++++++++++++++++++++++++++++---- 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/doc/txt/winnotes/registry.txt b/doc/txt/winnotes/registry.txt index 062e503..2012897 100644 --- a/doc/txt/winnotes/registry.txt +++ b/doc/txt/winnotes/registry.txt @@ -312,6 +312,16 @@ Default : 2 2 = Extended (GSS SPNEGO) authentication required The default is Extended authentication +Value : MaxLogSize +Type : DWORD {0 .. MAXDWORD} +Default : 100K + + This entry determines the maximum size of the %WINDIR%\TEMP\afsd_init.log + file. If the file is larger than this value when afsd_service.exe starts + the file will be reset to 0 bytes. If this value is 0, it means the file + should be allowed to grow indefinitely. + + Regkey: [HKLM\SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters\GlobalAutoMapper] diff --git a/src/WINNT/afsd/NTMakefile b/src/WINNT/afsd/NTMakefile index 088162b..44c012e 100644 --- a/src/WINNT/afsd/NTMakefile +++ b/src/WINNT/afsd/NTMakefile @@ -218,7 +218,6 @@ LOGON_DLLLIBS =\ $(DESTDIR)\lib\libafsconf.lib \ $(DESTDIR)\lib\afsrxkad.lib \ $(DESTDIR)\lib\afsdes.lib \ - $(DESTDIR)\lib\lanahelper.lib \ $(AFSKFWLIB) LOGON_DLLSDKLIBS =\ diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index 5f73ceb..32e358d 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -849,8 +849,15 @@ VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo ) } } - if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid)) - GetUserProfileDirectory(pInfo->hToken, profileDir, &len); + /* We can't use pInfo->Domain for the domain since in the cross realm case + * this is source domain and not the destination domain. + */ + if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) { + WCHAR Domain[64]=L""; + GetLocalShortDomain(Domain); + if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) + GetUserProfileDirectory(pInfo->hToken, profileDir, &len); + } if (strlen(profileDir)) { DebugEvent("Profile Directory: %s", profileDir); diff --git a/src/WINNT/afsd/afslogon.h b/src/WINNT/afsd/afslogon.h index 24565e1..dc1d4f6 100644 --- a/src/WINNT/afsd/afslogon.h +++ b/src/WINNT/afsd/afslogon.h @@ -119,7 +119,8 @@ static BOOL WINAPI UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOu void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ); 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); +DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid, PWSTR domain); +BOOL GetLocalShortDomain(PWSTR Domain); #ifdef __cplusplus } diff --git a/src/WINNT/afsd/logon_ad.cpp b/src/WINNT/afsd/logon_ad.cpp index 39a9741..13a6690 100644 --- a/src/WINNT/afsd/logon_ad.cpp +++ b/src/WINNT/afsd/logon_ad.cpp @@ -194,15 +194,20 @@ ghp_0: return code; } -DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid) { +DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid, PWSTR domain) { DWORD code = 1; /* default is failure */ NTSTATUS rv = 0; HRESULT hr = S_OK; LPWSTR p = NULL; WCHAR adsPath[MAX_PATH] = L""; BOOL coInitialized = FALSE; + CHAR ansidomain[256], *a; homePath[0] = '\0'; + + /* I trust this is an ASCII domain name */ + for ( p=domain, a=ansidomain; *a = (CHAR)*p; p++, a++); + DebugEvent("Domain: %s", ansidomain); if(ConvertSidToStringSidW(psid,&p)) { IADsNameTranslate *pNto; @@ -221,11 +226,16 @@ DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid) { if(FAILED(hr)) { DebugEvent("Can't create nametranslate object"); } else { - hr = pNto->Init(ADS_NAME_INITTYPE_GC,L""); //,clientUpn/*IL->UserName.Buffer*/,IL->LogonDomainName.Buffer,IL->Password.Buffer); + hr = pNto->Init(ADS_NAME_INITTYPE_GC,L""); if (FAILED(hr)) { - DebugEvent("NameTranslate Init failed [%ld]", hr); + DebugEvent("NameTranslate Init GC failed [%ld]", hr); + hr = pNto->Init(ADS_NAME_INITTYPE_DOMAIN,domain); + if (FAILED(hr)) { + DebugEvent("NameTranslate Init Domain failed [%ld]", hr); + } } - else { + + if (!FAILED(hr)) { hr = pNto->Set(ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME, p); if(FAILED(hr)) { DebugEvent("Can't set sid string"); } else { @@ -311,10 +321,17 @@ DWORD GetAdHomePath(char * homePath, size_t homePathLen, PLUID lpLogonId, LogonO rv = LsaGetLogonSessionData(lpLogonId, &plsd); if(rv == 0) { - if(!QueryAdHomePathFromSid(homePath,homePathLen,plsd->Sid)) { + PWSTR domain; + + domain = (PWSTR)malloc(sizeof(WCHAR) * (plsd->LogonDomain.Length+1)); + memcpy(domain, plsd->LogonDomain.Buffer, sizeof(WCHAR) * (plsd->LogonDomain.Length)); + domain[plsd->LogonDomain.Length] = 0; + + if(!QueryAdHomePathFromSid(homePath,homePathLen,plsd->Sid,domain)) { DebugEvent("Returned home path [%s]",homePath); opt->flags |= LOGON_FLAG_AD_REALM; } + free(domain); LsaFreeReturnBuffer(plsd); } else { DebugEvent("LsaGetLogonSessionData failed [%lX]", rv); @@ -329,3 +346,34 @@ DWORD GetAdHomePath(char * homePath, size_t homePathLen, PLUID lpLogonId, LogonO return code; } } + +BOOL GetLocalShortDomain(PWSTR Domain) +{ + HRESULT hr; + IADsADSystemInfo *pADsys; + BOOL coInitialized = FALSE; + BOOL retval = FALSE; + + hr = CoInitialize(NULL); + if(SUCCEEDED(hr)) + coInitialized = TRUE; + + hr = CoCreateInstance(CLSID_ADSystemInfo, + NULL, + CLSCTX_INPROC_SERVER, + IID_IADsADSystemInfo, + (void**)&pADsys); + if ( !FAILED(hr) ) { + BSTR bstr; + + hr = pADsys->get_DomainShortName(&bstr); + wcscpy( Domain, bstr ); + pADsys->Release(); + retval = TRUE; + } + + if(coInitialized) + CoUninitialize(); + + return retval; +} -- 1.9.4