STDMETHODIMP CShellExt::XToolTipExt::GetInfoTip(DWORD dwFlags, LPWSTR *ppwszTip) { METHOD_PROLOGUE(CShellExt, ToolTipExt); if ((_tcslen(pThis->m_szFile) == 0)||(!IsPathInAfs(pThis->m_szFile))) { *ppwszTip=NULL; return S_OK; } bool bIsSymlink = !!IsSymlink(pThis->m_szFile); bool bIsMountpoint = !!IsMountPoint(pThis->m_szFile); if ((!bIsSymlink) && (!bIsMountpoint)) { *ppwszTip=NULL; return S_OK; } USES_CONVERSION; // dwFlags is currently unused. CString sInfo; if (bIsSymlink) sInfo = GetSymlink(pThis->m_szFile); else if (bIsMountpoint) sInfo = GetMountpoint(pThis->m_szFile); *ppwszTip = (WCHAR*) (pThis->m_pAlloc)->Alloc((1+sInfo.GetLength())*sizeof(WCHAR)); if (*ppwszTip) wcscpy(*ppwszTip, (WCHAR*)T2COLE((LPCTSTR)sInfo)); return S_OK; }
void CMakeSymbolicLinkDlg::OnOK() { char space[64]; UINT code; int i; UpdateData(TRUE); CString strName; CString strTarget; m_Name.GetWindowText(strName); m_Dir.GetWindowText(strTarget); if (!IsPathInAfs(m_sBase)) { MessageBeep((UINT)-1); strTarget+=" - Path is not in AFS directory"; AfxMessageBox(strTarget,MB_OK); return; } if (m_sBase.GetLength()>MAX_PATH-2) { MessageBeep((UINT)-1); ShowMessageBox(IDS_CURRENT_DIRECTORY_PATH_TOO_LONG,MB_OK,IDS_CURRENT_DIRECTORY_PATH_TOO_LONG); } if (!SetCurrentDirectory(m_sBase)) { MessageBeep((UINT)-1); ShowMessageBox(IDS_UNABLE_TO_SET_CURRENT_DIRECTORY,MB_OK,IDS_UNABLE_TO_SET_CURRENT_DIRECTORY); return; } if ((code=MakeSymbolicLink(strName,strTarget))!=0){ MessageBeep((UINT)-1); ShowMessageBox(IDS_UNABLE_TO_CREATE_SYMBOLIC_LINK,MB_OK,IDS_UNABLE_TO_CREATE_SYMBOLIC_LINK,code); return; } CDialog::OnOK(); }
STDMETHODIMP CShellExt::XIconExt::IsMemberOf(LPCWSTR pwszPath,DWORD dwAttrib) { METHOD_PROLOGUE(CShellExt, IconExt); TCHAR szPath[MAX_PATH]; #ifdef UNICODE _tcscpy(szPath, pwszPath); #else WideCharToMultiByte( CP_ACP,0,pwszPath,-1,szPath,MAX_PATH,NULL,NULL); #endif if (!IsPathInAfs(szPath)) return S_FALSE; if ((pThis->GetOverlayObject() == 0)&&(IsSymlink(szPath))) { return S_OK; } if ((pThis->GetOverlayObject() == 1)&&(IsMountPoint(szPath))) { return S_OK; } return S_FALSE; }
///////////////////////////////////////////////////////////////////////////// // IShellInit Functions ///////////////////////////////////////////////////////////////////////////// STDMETHODIMP CShellExt::XShellInit::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdobj, HKEY hkeyProgID) { METHOD_PROLOGUE(CShellExt, ShellInit); HRESULT hres = E_FAIL; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; STGMEDIUM medium; // We must have a data object if ((pdobj == NULL) && (pidlFolder == NULL)) return E_FAIL; pThis->m_bIsSymlink=false; pThis->m_bIsMountpoint=false; pThis->m_bIsPathInAFS=false; pThis->m_bDirSelected=false; if (pdobj) { // Use the given IDataObject to get a list of filenames (CF_HDROP) hres = pdobj->GetData(&fmte, &medium); if (FAILED(hres)) { return E_FAIL; } int nNumFiles = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); if (nNumFiles == 0) hres = E_FAIL; else { pThis->m_bDirSelected = FALSE; for (int ii = 0; ii < nNumFiles; ii++) { CString strFileName; // Get the size of the file name string int nNameLen = DragQueryFile((HDROP)medium.hGlobal, ii, 0, 0); // Make room for it in our string object LPTSTR pszFileNameBuf = strFileName.GetBuffer(nNameLen + 1); // +1 for the terminating NULL ASSERT(pszFileNameBuf); // Get the file name DragQueryFile((HDROP)medium.hGlobal, ii, pszFileNameBuf, nNameLen + 1); strFileName.ReleaseBuffer(); if (!IsPathInAfs(strFileName)) { pThis->m_astrFileNames.RemoveAll(); pThis->m_bIsPathInAFS=false; break; } else { pThis->m_bIsSymlink=pThis->m_bIsSymlink||IsSymlink(strFileName); pThis->m_bIsMountpoint=pThis->m_bIsMountpoint||IsMountPoint(strFileName); pThis->m_bIsPathInAFS=true; } if (IsADir(strFileName)) pThis->m_bDirSelected = TRUE; pThis->m_astrFileNames.Add(strFileName); } // Release the data ReleaseStgMedium(&medium); } } if ((pThis->m_astrFileNames.GetSize() == 0)&&(pidlFolder)) { // if there are no valid files selected, try the folder background IShellFolder *parentFolder = NULL; STRRET name; TCHAR * szDisplayName = NULL; hres = ::SHGetDesktopFolder(&parentFolder); if (FAILED(hres)) return hres; hres = parentFolder->GetDisplayNameOf(pidlFolder, SHGDN_NORMAL | SHGDN_FORPARSING, &name); if (FAILED(hres)) { parentFolder->Release(); return hres; } hres = StrRetToStr (&name, pidlFolder, &szDisplayName); if (FAILED(hres)) return hres; parentFolder->Release(); if (szDisplayName) { pThis->m_bDirSelected = TRUE; CString strFileName = CString(szDisplayName); if (IsPathInAfs(strFileName)) { pThis->m_bIsSymlink=IsSymlink(strFileName); pThis->m_bIsMountpoint=IsMountPoint(strFileName); pThis->m_bIsPathInAFS=true; pThis->m_astrFileNames.Add(strFileName); } CoTaskMemFree(szDisplayName); } } if (pThis->m_astrFileNames.GetSize() > 0) hres = NOERROR; else hres = E_FAIL; return hres; }
VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo ) { DWORD code; TCHAR profileDir[1024] = TEXT(""); DWORD len = 1024; PTOKEN_USER tokenUser = NULL; DWORD retLen; DWORD LSPtype, LSPsize; HKEY NPKey; DWORD LogoffPreserveTokens = 0; LogonOptions_t opt; /* Make sure the AFS Libraries are initialized */ AfsLogonInit(); DebugEvent0("AFS_Logoff_Event - Start"); (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY, 0, KEY_QUERY_VALUE, &NPKey); LSPsize=sizeof(LogoffPreserveTokens); RegQueryValueEx(NPKey, REG_CLIENT_LOGOFF_TOKENS_PARM, NULL, &LSPtype, (LPBYTE)&LogoffPreserveTokens, &LSPsize); RegCloseKey (NPKey); if (!LogoffPreserveTokens) { memset(&opt, 0, sizeof(LogonOptions_t)); if (pInfo->UserName && pInfo->Domain) { char username[MAX_USERNAME_LENGTH] = ""; char domain[MAX_DOMAIN_LENGTH] = ""; size_t szlen = 0; StringCchLengthW(pInfo->UserName, MAX_USERNAME_LENGTH, &szlen); WideCharToMultiByte(CP_UTF8, 0, pInfo->UserName, szlen, username, sizeof(username), NULL, NULL); StringCchLengthW(pInfo->Domain, MAX_DOMAIN_LENGTH, &szlen); WideCharToMultiByte(CP_UTF8, 0, pInfo->Domain, szlen, domain, sizeof(domain), NULL, NULL); GetDomainLogonOptions(NULL, username, domain, &opt); } if (ISREMOTE(opt.flags)) { if (!GetTokenInformation(pInfo->hToken, TokenUser, NULL, 0, &retLen)) { if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) { tokenUser = (PTOKEN_USER) LocalAlloc(LPTR, retLen); if (!GetTokenInformation(pInfo->hToken, TokenUser, tokenUser, retLen, &retLen)) { DebugEvent("AFS_Logoff_Event - GetTokenInformation failed: GLE = %lX", GetLastError()); } } } /* 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 (tokenUser && QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) { WCHAR Domain[64]=L""; GetLocalShortDomain(Domain, sizeof(Domain)); if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) { if (NetUserGetProfilePath(pInfo->Domain, pInfo->UserName, profileDir, len)) GetUserProfileDirectory(pInfo->hToken, profileDir, &len); } } if (strlen(profileDir)) { DebugEvent("AFS_Logoff_Event - Profile Directory: %s", profileDir); if (!IsPathInAfs(profileDir)) { if (code = ktc_ForgetAllTokens()) DebugEvent("AFS_Logoff_Event - ForgetAllTokens failed [%lX]",code); else DebugEvent0("AFS_Logoff_Event - ForgetAllTokens succeeded"); } else { DebugEvent0("AFS_Logoff_Event - Tokens left in place; profile in AFS"); } } else { DebugEvent0("AFS_Logoff_Event - Unable to load profile"); } if ( tokenUser ) LocalFree(tokenUser); } else { DebugEvent0("AFS_Logoff_Event - Local Logon"); if (code = ktc_ForgetAllTokens()) DebugEvent("AFS_Logoff_Event - ForgetAllTokens failed [%lX]",code); else DebugEvent0("AFS_Logoff_Event - ForgetAllTokens succeeded"); } } else { DebugEvent0("AFS_Logoff_Event - Preserving Tokens"); } DebugEvent0("AFS_Logoff_Event - End"); }
///////////////////////////////////////////////////////////////////////////// // IShellInit Functions ///////////////////////////////////////////////////////////////////////////// STDMETHODIMP CShellExt::XShellInit::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdobj, HKEY hkeyProgID) { METHOD_PROLOGUE(CShellExt, ShellInit); HRESULT hres = E_FAIL; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; STGMEDIUM medium; // We must have a data object if (pdobj == NULL) return E_FAIL; // Use the given IDataObject to get a list of filenames (CF_HDROP) hres = pdobj->GetData(&fmte, &medium); if (FAILED(hres)) { return E_FAIL; } int nNumFiles = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); if (nNumFiles == 0) hres = E_FAIL; else { pThis->m_bDirSelected = FALSE; for (int ii = 0; ii < nNumFiles; ii++) { CString strFileName; // Get the size of the file name string int nNameLen = DragQueryFile((HDROP)medium.hGlobal, ii, 0, 0); // Make room for it in our string object LPTSTR pszFileNameBuf = strFileName.GetBuffer(nNameLen + 1); // +1 for the terminating NULL ASSERT(pszFileNameBuf); // Get the file name DragQueryFile((HDROP)medium.hGlobal, ii, pszFileNameBuf, nNameLen + 1); strFileName.ReleaseBuffer(); if (!IsPathInAfs(strFileName)) { pThis->m_astrFileNames.RemoveAll(); break; } else { pThis->m_bIsSymlink=IsSymlink(strFileName); } if (IsADir(strFileName)) pThis->m_bDirSelected = TRUE; pThis->m_astrFileNames.Add(strFileName); } if (pThis->m_astrFileNames.GetSize() > 0) hres = NOERROR; else hres = E_FAIL; } // Release the data ReleaseStgMedium(&medium); return hres; }