static DWORD DJFlushCache( ) { DWORD ceError = ERROR_SUCCESS; int i; const char* cacheUtils[] = { "/usr/sbin/lookupd", /* Before Mac OS X 10.5 */ "/usr/bin/dscacheutil" /* On Mac OS X 10.5 */ }; DJ_LOG_INFO("Flushing dns cache"); for (i = 0; i < (sizeof(cacheUtils) / sizeof(cacheUtils[0])); i++) { const char* command = cacheUtils[i]; BOOLEAN exists; /* Sanity check */ if (!command) { continue; } ceError = CTCheckFileExists(command, &exists); BAIL_ON_CENTERIS_ERROR(ceError); if (!exists) { continue; } ceError = CTShell("%command -flushcache", CTSHELL_STRING(command, command)); /* Bail regardless */ goto error; } DJ_LOG_ERROR("Could not locate cache flush utility"); ceError = ERROR_FILE_NOT_FOUND; error: return ceError; }
static void FixNetworkInterfaces( PSTR pszComputerName, LWException **exc ) { DWORD ceError = ERROR_SUCCESS; int EE = 0; BOOLEAN bFileExists = FALSE; BOOLEAN bDirExists = FALSE; PSTR* ppszPaths = NULL; DWORD nPaths = 0; DWORD iPath = 0; CHAR szBuf[1024]; PSTR pszPathifcfg = NULL; BOOLEAN bDHCPHost = FALSE; PSTR pszMachineSID = NULL; PCSTR networkConfigPath = "/etc/sysconfig/network"; LW_CLEANUP_CTERR(exc, DJGetMachineSID(&pszMachineSID)); /* * fixup HOSTNAME variable in /etc/sysconfig/network file if it exists * note that 'network' is a *directory* on some dists (ie SUSE), * is a *file* on others (ie Redhat). weird. */ LW_CLEANUP_CTERR(exc, CTCheckFileExists(networkConfigPath, &bFileExists)); if (bFileExists) { sprintf(szBuf, "s/^.*\\(HOSTNAME\\).*=.*$/\\1=%s/", pszComputerName); LW_CLEANUP_CTERR(exc, CTRunSedOnFile(networkConfigPath, networkConfigPath, FALSE, szBuf)); } LW_CLEANUP_CTERR(exc, CTCheckDirectoryExists("/etc/sysconfig/network", &bDirExists)); if (!bDirExists) { LW_CLEANUP_CTERR(exc, CTCheckDirectoryExists("/etc/sysconfig/network-scripts", &bDirExists)); } if (bDirExists) { struct { PCSTR dir; PCSTR glob; } const searchPaths[] = { {"/etc/sysconfig/network", "ifcfg-eth-id-[^.]*$"}, {"/etc/sysconfig/network", "ifcfg-eth0[^.]*$"}, {"/etc/sysconfig/network", "ifcfg-eth[^.]*$"}, {"/etc/sysconfig/network", "ifcfg-eth-bus[^.]*$"}, //SLES 10.1 on zSeries uses one of: // /etc/sysconfig/network/ifcfg-qeth-bus-ccw-0.0.0500 // /etc/sysconfig/network/ifcfg-ctc-bus-ccw-0.0.0004 {"/etc/sysconfig/network", "ifcfg-qeth-bus.*\\.[0-9]\\+$"}, {"/etc/sysconfig/network", "ifcfg-ctc-bus.*\\.[0-9]\\+$"}, // Redhat uses /etc/sysconfig/network-scripts/ifcfg-eth<number> {"/etc/sysconfig/network-scripts", "ifcfg-eth[^.]*$"}, // RHEL 6 uses this {"/etc/sysconfig/network-scripts", "ifcfg-Auto_eth[^.]*$"}, // ESX 3.5 and 4.0 use // /etc/sysconfig/network-scripts/ifcfg-vswif<number> {"/etc/sysconfig/network-scripts", "ifcfg-vswif[^.]*$"}, // RHEL 7: network interface naming seems to be ensXX or enoXXXX, etc. {"/etc/sysconfig/network-scripts", "ifcfg-en[^.]*$"}, {NULL, NULL} }; // Find the ifcfg file pszPathifcfg = NULL; for(iPath = 0; searchPaths[iPath].dir != NULL && pszPathifcfg == NULL; iPath++) { if (ppszPaths) { CTFreeStringArray(ppszPaths, nPaths); ppszPaths = NULL; } ceError = CTGetMatchingFilePathsInFolder(searchPaths[iPath].dir, searchPaths[iPath].glob, &ppszPaths, &nPaths); if(ceError == ERROR_DIRECTORY) { ceError = ERROR_SUCCESS; continue; } LW_CLEANUP_CTERR(exc, ceError); if(nPaths > 0) { LW_CLEANUP_CTERR(exc, CTAllocateString(ppszPaths[0], &pszPathifcfg)); } } if (IsNullOrEmptyString(pszPathifcfg)) { LW_CLEANUP_CTERR(exc, ERROR_FILE_NOT_FOUND); } DJ_LOG_INFO("Found ifcfg file at %s", pszPathifcfg); LW_CLEANUP_CTERR(exc, DJCheckIfDHCPHost(pszPathifcfg, &bDHCPHost)); if (bDHCPHost) { LW_CLEANUP_CTERR(exc, DJFixDHCPHost(pszPathifcfg, pszComputerName)); } } ceError = CTShell("/bin/hostname %hostname >/dev/null", CTSHELL_STRING(hostname, pszComputerName)); LW_CLEANUP_CTERR(exc, ceError); // Only DHCP boxes need to restart their networks if (bDHCPHost) { LW_CLEANUP_CTERR(exc, DJConfigureDHCPService(pszComputerName)); } cleanup: // This ensures that we do not change the SID after a machine name // change. The issue here is that Samba implements its SAM such that // a machine name change changes the seeding used for the machine SID. // Therefore, we must re-store the old SID with the new machine name // seed. if (pszMachineSID) { if (*pszMachineSID != '\0') DJSetMachineSID(pszMachineSID); CTFreeString(pszMachineSID); } if (ppszPaths) CTFreeStringArray(ppszPaths, nPaths); if (pszPathifcfg) CTFreeString(pszPathifcfg); DJ_LOG_VERBOSE("FixNetworkInterfaces LEAVE -> 0x%08x (EE = %d)", ceError, EE); }
static DWORD DJFixNetworkManagerOnlineTimeout( ) { DWORD ceError = ERROR_SUCCESS; PSTR pszFilePath = "/etc/sysconfig/network/config"; DWORD dwTimeout = 60; int EE = 0; BOOLEAN bFileExists = FALSE; char *isEnabled = NULL; char *currentTimeout = NULL; char *sedExpression = NULL; long currentTimeoutLong; char *conversionEnd; ceError = CTCheckFileExists(pszFilePath, &bFileExists); CLEANUP_ON_DWORD_EE(ceError, EE); if(!bFileExists) goto cleanup; ceError = CTShell(". %pszFilePath; echo \"$NETWORKMANAGER\" >%enabled; echo \"$NM_ONLINE_TIMEOUT\" >%timeout", CTSHELL_STRING (pszFilePath, pszFilePath), CTSHELL_BUFFER (enabled, &isEnabled), CTSHELL_BUFFER (timeout, ¤tTimeout)); CLEANUP_ON_DWORD_EE(ceError, EE); CTStripTrailingWhitespace(isEnabled); CTStripTrailingWhitespace(currentTimeout); DJ_LOG_VERBOSE("Network manager enabled [%s] network manager timeout [%s]", isEnabled, currentTimeout); if(strcasecmp(isEnabled, "yes")) { DJ_LOG_INFO("Network manager is not enabled"); goto cleanup; } currentTimeoutLong = strtol(currentTimeout, &conversionEnd, 10); if(*conversionEnd != '\0') { DJ_LOG_INFO("Unable to convert network manager timeout to long"); currentTimeoutLong = 0; } if(currentTimeoutLong < dwTimeout) { DJ_LOG_INFO("Setting network manager timeout to %d", dwTimeout); ceError = CTAllocateStringPrintf(&sedExpression, "s/^\\([ \t]*NM_ONLINE_TIMEOUT[ \t]*=[ \t]*\\).*$/\\1%d/", dwTimeout); CLEANUP_ON_DWORD_EE(ceError, EE); ceError = CTRunSedOnFile(pszFilePath, pszFilePath, FALSE, sedExpression); CLEANUP_ON_DWORD_EE(ceError, EE); } cleanup: DJ_LOG_VERBOSE("DJFixNetworkManagerOnlineTimeout LEAVE -> 0x%08x (EE = %d)", ceError, EE); CT_SAFE_FREE_STRING(isEnabled); CT_SAFE_FREE_STRING(currentTimeout); CT_SAFE_FREE_STRING(sedExpression); return ceError; }