Ejemplo n.º 1
0
/**
    Get all current property names.
*/
void ConfigFileHandler::getAllCurrentPropertyNames (Array<CIMName>& propertyNames)
{
    propertyNames.clear();

    if (_currentFileExist)
    {
        for (Table::Iterator i = _currentConfig->table.start(); i; i++)
        {
            propertyNames.append(i.key());
        }
    }
}
Ejemplo n.º 2
0
/**
    Get all planned config property names and values.
*/
void ConfigFileHandler::getAllPlannedProperties(
    Array<CIMName>& propertyNames,
    Array<String>& propertyValues)
{
    propertyNames.clear();
    propertyValues.clear();

    if (_plannedFileExist)
    {
        for (Table::Iterator i = _plannedConfig->table.start(); i; i++)
        {
            propertyNames.append(i.key());
            propertyValues.append(i.value());
        }
    }
}
Ejemplo n.º 3
0
/** 
    Save the properties to the config file.
*/
void ConfigFile::save (ConfigTable* confTable)
{
    //
    // Delete the backup configuration file
    //
    if (FileSystem::exists(_configBackupFile))
    {
        FileSystem::removeFile(_configBackupFile);
    }

    //
    // Rename the configuration file as a backup file
    //
    if (FileSystem::exists(_configFile))
    {
        if (!FileSystem::renameFile(_configFile, _configBackupFile))
        {
            throw CannotRenameFile(_configFile);
        }
    }

    //
    // Open the config file for writing
    //
#if defined(PEGASUS_OS_OS400)
    ofstream ofs(_configFile.getCString(), PEGASUS_STD(_CCSID_T(1208)));
#else
    ofstream ofs(_configFile.getCString());
#endif
    ofs.clear();

#if !defined(PEGASUS_OS_TYPE_WINDOWS)
    //
    // Set permissions on the config file to 0644
    //
    if ( !FileSystem::changeFilePermissions(_configFile,
        (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) )    // set 0644 
    {
        throw CannotOpenFile(_configFile);
    }
#endif

    //
    // Write config file header information
    //
    for (int index = 0; index < HEADER_SIZE; index++)
    {
        ofs << ConfigHeader[index] << endl;
    }

    ofs << endl;

    //
    // Save config properties and values to the file
    //
    for (Table::Iterator i = confTable->table.start(); i; i++)
    {
        ofs << i.key() << "=" << i.value() << endl;
    }

    ofs.close();
}
Ejemplo n.º 4
0
/**
    Save the properties to the config file.
*/
void ConfigFile::save(ConfigTable* confTable)
{
    //
    // Delete the backup configuration file
    //
    if (FileSystem::exists(_configBackupFile))
    {
        Executor::removeFile(_configBackupFile.getCString());
    }

    //
    // Rename the configuration file as a backup file
    //

    if (FileSystem::exists(_configFile))
    {
        if (Executor::renameFile(
            _configFile.getCString(), _configBackupFile.getCString()) != 0)
        {
            throw CannotRenameFile(_configFile);
        }
    }

    //
    // Open the config file for writing
    //

    FILE* ofs = Executor::openFile(_configFile.getCString(), 'w');

    if (!ofs)
    {
        throw CannotOpenFile(_configFile);
    }

    //
    // Write config file header information
    //

    for (int index = 0; index < HEADER_SIZE; index++)
    {
        fputs(ConfigHeader[index], ofs);
        fputc('\n', ofs);
    }

    //
    // Save config properties and values to the file
    //

    for (Table::Iterator i = confTable->table.start(); i; i++)
    {
        CString key = i.key().getCString();
        CString value = i.value().getCString();
        fprintf(ofs, "%s=%s\n", (const char*)key, (const char*)value);
    }

    fclose(ofs);

#if !defined(PEGASUS_OS_TYPE_WINDOWS)
    // Note:  The Executor process sets the permissions to 0644 when it
    // opens the config file for writing.
    if (Executor::detectExecutor() != 0)
    {
        //
        // Set permissions on the config file to 0644
        //
        if (!FileSystem::changeFilePermissions(
                _configFile,
                (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)))    // set 0644
        {
            throw CannotChangeFilePerm(_configFile);
        }
    }
#endif
}