// FIXME: DEPRECATED! HACKish function that needs to be deprecated! BOOLEAN DoesFileExist_2( IN PCWSTR PathName OPTIONAL, IN PCWSTR FileName) { WCHAR FullName[MAX_PATH]; CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName); return DoesFileExist(NULL, FullName); }
static LPWSTR GetPathFullPath(HWND hwndTV, LPWSTR path) { LPWSTR parts[2]; LPWSTR ret; parts[0] = GetPathRoot(hwndTV, 0, TRUE); parts[1] = path; ret = CombinePaths((LPCWSTR*)parts, 2); HeapFree(GetProcessHeap(), 0, parts[0]); return ret; }
LPWSTR GetItemFullPath(HWND hwndTV, HTREEITEM hItem, BOOL bFull) { LPWSTR parts[2]; LPWSTR ret; HKEY hRootKey = NULL; parts[0] = GetPathRoot(hwndTV, hItem, bFull); parts[1] = GetItemPath(hwndTV, hItem, &hRootKey); ret = CombinePaths((LPCWSTR *)parts, 2); HeapFree(GetProcessHeap(), 0, parts[0]); HeapFree(GetProcessHeap(), 0, parts[1]); return ret; }
static LPWSTR GetPathRoot(HWND hwndTV, HTREEITEM hItem, BOOL bFull) { LPCWSTR parts[2] = {0,0}; WCHAR text[260]; HKEY hRootKey = NULL; if (!hItem) hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0); HeapFree(GetProcessHeap(), 0, GetItemPath(hwndTV, hItem, &hRootKey)); if (!bFull && !hRootKey) return NULL; if (hRootKey) parts[1] = GetRootKeyName(hRootKey); if (bFull) { DWORD dwSize = sizeof(text)/sizeof(WCHAR); GetComputerNameW(text, &dwSize); parts[0] = text; } return CombinePaths(parts, 2); }
BOOLEAN FindSshAndConfig( PCSTR pSshOrSshd, PSTR *ppSshBinary, PSTR *ppSshConfig, LWException **ppExc) { DWORD ceError = ERROR_SUCCESS; /* Mac OS X stores the configuration in /etc */ /* CSW ssh on Solaris uses /opt/csw/etc/ssh */ const PCSTR ppSshConfigPaths[] = { "/etc/ssh", "/opt/ssh/etc", "/usr/local/etc", "/etc", "/etc/openssh", "/usr/openssh/etc", "/opt/csw/etc/ssh", NULL }; DWORD foundConfigCount = 0; PSTR* ppFoundConfigs = NULL; /* Solaris Sparc 10 stores sshd in /usr/lib/ssh */ /* Experian says their sshd is at /usr/openssh/sbin/sshd */ /* CSW ssh on Solaris uses /opt/csw/sbin/sshd */ const PCSTR ppSshBinaryPaths[] = { "/usr/sbin", "/opt/ssh/sbin", "/usr/local/sbin", "/usr/bin", "/opt/ssh/bin", "/usr/local/bin", "/usr/lib/ssh", "/usr/openssh/sbin", "/usr/openssh/bin", "/opt/csw/sbin", "/opt/csw/bin", "/opt/ssh/hpux64/sbin", NULL }; DWORD foundBinaryCount = 0; PSTR* ppFoundBinaries = NULL; PSTR pConfigFilename = NULL; PSTR pBinaryFilename = NULL; PSTR pFoundConfigList = NULL; PSTR pFoundBinaryList = NULL; DWORD index = 0; *ppSshBinary = NULL; *ppSshConfig = NULL; LW_CLEANUP_CTERR(ppExc, CTAllocateStringPrintf( &pConfigFilename, "%s_config", pSshOrSshd)); LW_CLEANUP_CTERR(ppExc, CTAllocateStringPrintf( &pBinaryFilename, "%s", pSshOrSshd)); ceError = LwFindFilesInPaths( pConfigFilename, LWFILE_REGULAR, ppSshConfigPaths, &foundConfigCount, &ppFoundConfigs); LW_CLEANUP_CTERR(ppExc, ceError); ceError = LwRemoveDuplicateInodes( &foundConfigCount, ppFoundConfigs); LW_CLEANUP_CTERR(ppExc, ceError); ceError = LwFindFilesInPaths( pBinaryFilename, LWFILE_REGULAR, ppSshBinaryPaths, &foundBinaryCount, &ppFoundBinaries); LW_CLEANUP_CTERR(ppExc, ceError); ceError = LwRemoveDuplicateInodes( &foundBinaryCount, ppFoundBinaries); LW_CLEANUP_CTERR(ppExc, ceError); // Ssh version A.04.40.005 on HP-UX Itanimum has these paths: // /opt/ssh/hpux64/sbin/sshd (ELF-64 IA64) // /opt/ssh/sbin/sshd (ELF-32 IA64) // /usr/sbin/sshd (symlink to /opt/ssh/hpux64/sbin/sshd) // // Ssh version A.04.30.007 on HP-UX Itanimum has these paths: // /opt/ssh/hpux64/sbin/sshd (ELF-64 IA64) // /opt/ssh/sbin/sshd (ELF-32 IA64) // /usr/sbin/sshd (symlink to /opt/ssh/sbin/sshd) // // Both files point to the same config path. An exception must exist for // this case since the inodes are different for the two architectures. // // The symlink at /usr/sbin/sshd wins the duplication removal process. So // if it is found, the other path must be removed. for (index = 0; index < foundBinaryCount; index++) { if (!strcmp(ppFoundBinaries[index], "/usr/sbin/sshd")) { // Remove /opt/ssh/sbin/sshd or /opt/ssh/hpux64/sbin/sshd if they // are in the list for (index = 0; index < foundBinaryCount; index++) { if (!strcmp(ppFoundBinaries[index], "/opt/ssh/sbin/sshd") || !strcmp(ppFoundBinaries[index], "/opt/ssh/hpux64/sbin/sshd")) { LW_SAFE_FREE_STRING(ppFoundBinaries[index]); memmove(&ppFoundBinaries[index], &ppFoundBinaries[index+1], (foundBinaryCount - index - 1) * sizeof(ppFoundBinaries[index])); foundBinaryCount--; break; } } break; } } if ((foundConfigCount | foundBinaryCount) > 0 && foundConfigCount != foundBinaryCount) { ceError = CombinePaths( foundConfigCount, ppFoundConfigs, &pFoundConfigList); LW_CLEANUP_CTERR(ppExc, ceError); ceError = CombinePaths( foundBinaryCount, ppFoundBinaries, &pFoundBinaryList); LW_CLEANUP_CTERR(ppExc, ceError); if ((foundConfigCount | foundBinaryCount) == 1) { ceError = ERROR_FILE_NOT_FOUND; } else { ceError = ERROR_DUPLICATE_SERVICE_NAME; } LW_RAISE_EX(ppExc, ceError, "Unable to find ssh binary", "A %s config file was at %s, and a %s binary file was found at %s. Exactly one config file and one binary must exist on the system in a standard location. Uninstall any unused copies of ssh.", pSshOrSshd, pFoundConfigList, pSshOrSshd, pFoundBinaryList); } if (foundConfigCount == 1) { DJ_LOG_INFO("Found config file %s", ppFoundConfigs[0]); *ppSshConfig = ppFoundConfigs[0]; ppFoundConfigs[0] = NULL; } if (foundBinaryCount == 1) { DJ_LOG_INFO("Found binary %s", ppFoundBinaries[0]); *ppSshBinary = ppFoundBinaries[0]; ppFoundBinaries[0] = NULL; } cleanup: if (ppFoundConfigs) { LwFreeStringArray( ppFoundConfigs, foundConfigCount); } if (ppFoundBinaries) { LwFreeStringArray( ppFoundBinaries, foundBinaryCount); } LW_SAFE_FREE_STRING(pConfigFilename); LW_SAFE_FREE_STRING(pBinaryFilename); LW_SAFE_FREE_STRING(pFoundConfigList); LW_SAFE_FREE_STRING(pFoundBinaryList); return (foundConfigCount == 1); }
VOID CheckIncludeForWarning( IN LPCSTR CompilandDir, IN LPCSTR CompilandName, IN LPCSTR IncluderDir, IN LPCSTR IncluderName, IN LPCSTR IncludeeDir, IN LPCSTR IncludeeName ) { CHAR CompilandFullName[ MAX_PATH ]; CHAR IncluderFullName[ MAX_PATH ]; CHAR IncludeeFullName[ MAX_PATH ]; assert( CompilandDir ); assert( CompilandName ); assert( IncluderDir ); assert( IncluderName ); assert( IncludeeDir ); assert( IncludeeName ); CombinePaths( CompilandDir, CompilandName, CompilandFullName ); CombinePaths( IncluderDir, IncluderName, IncluderFullName ); CombinePaths( IncludeeDir, IncludeeName, IncludeeFullName ); _strlwr( CompilandFullName ); _strlwr( IncluderFullName ); _strlwr( IncludeeFullName ); EnterCriticalSection(&LogFileCriticalSection); if ( IncFile ) { fprintf( IncFile, "%s includes %s" EOL, IncluderFullName, IncludeeFullName ); } LeaveCriticalSection(&LogFileCriticalSection); if ( ShouldWarnInclude( CompilandFullName, IncludeeFullName )) { if ( strcmp( IncluderFullName, CompilandFullName ) == 0 ) { EnterCriticalSection(&LogFileCriticalSection); if ( WrnFile ) { fprintf( WrnFile, "WARNING: %s includes %s\n", CompilandFullName, IncludeeFullName ); } LeaveCriticalSection(&LogFileCriticalSection); if ( fShowWarningsOnScreen ) { BuildMsgRaw( "WARNING: %s includes %s\n", CompilandFullName, IncludeeFullName ); } } else { EnterCriticalSection(&LogFileCriticalSection); if ( WrnFile ) { fprintf( WrnFile, "WARNING: %s includes %s through %s\n", CompilandFullName, IncludeeFullName, IncluderFullName ); } LeaveCriticalSection(&LogFileCriticalSection); if ( fShowWarningsOnScreen ) { BuildMsgRaw( "WARNING: %s includes %s through %s\n", CompilandFullName, IncludeeFullName, IncluderFullName ); } } } }