(file) Return to ProviderDirPropertyOwner.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Config

  1 karl  1.5 //%2004////////////////////////////////////////////////////////////////////////
  2 konrad.r 1.2 //
  3 karl     1.5 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4              // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5              // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 konrad.r 1.2 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl     1.5 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8              // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 konrad.r 1.2 //
 10              // Permission is hereby granted, free of charge, to any person obtaining a copy
 11              // of this software and associated documentation files (the "Software"), to
 12              // deal in the Software without restriction, including without limitation the
 13              // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14              // sell copies of the Software, and to permit persons to whom the Software is
 15              // furnished to do so, subject to the following conditions:
 16              // 
 17              // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18              // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19              // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20              // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21              // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22              // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23              // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24              // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25              //
 26              //==============================================================================
 27              //
 28              // Author: Konrad Rzeszutek <konradr@us.ibm.com>
 29              //
 30 konrad.r 1.2 //
 31              //%/////////////////////////////////////////////////////////////////////////////
 32              
 33              
 34              ///////////////////////////////////////////////////////////////////////////////
 35              // 
 36              // This file has implementation for the providerDir property owner class.
 37              //
 38              ///////////////////////////////////////////////////////////////////////////////
 39              
 40              #include <Pegasus/Common/Config.h>
 41              #include <Pegasus/Common/Tracer.h>
 42              #include <Pegasus/Common/FileSystem.h>
 43              #include <Pegasus/Config/ConfigManager.h>
 44              #include "ProviderDirPropertyOwner.h"
 45              
 46              
 47              PEGASUS_NAMESPACE_BEGIN
 48              
 49              ///////////////////////////////////////////////////////////////////////////////
 50              //  ProviderDirPropertyOwner
 51 konrad.r 1.2 //
 52              //  When a new ProviderDir property is added, make sure to add the property name
 53              //  and the default attributes of that property in the table below.
 54              ///////////////////////////////////////////////////////////////////////////////
 55              
 56              static struct ConfigPropertyRow properties[] =
 57              {
 58 konrad.r 1.3 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
 59                  {"providerDir", "lib;bin", 0, 0, 0, 1},
 60              #else
 61 konrad.r 1.2     {"providerDir", "lib", 0, 0, 0, 1},
 62 konrad.r 1.3 #endif
 63 konrad.r 1.2 };
 64              
 65              const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 66              
 67              
 68              /** Constructors  */
 69              ProviderDirPropertyOwner::ProviderDirPropertyOwner()
 70              {
 71                  _providerDir = new ConfigProperty;
 72              }
 73              
 74              /** Destructor  */
 75              ProviderDirPropertyOwner::~ProviderDirPropertyOwner()
 76              {
 77                  delete _providerDir;
 78              }
 79              
 80              /**
 81              Checks if the given directory is existing and writable
 82              */
 83              Boolean isProviderDirValid(const String& dirName)
 84 konrad.r 1.2 {
 85                    String temp = dirName;
 86                    String path = String::EMPTY;
 87                    Uint32 pos =0;
 88                    Uint32 token=0;
 89              
 90                    do {
 91 konrad.r 1.3 	if (( pos = temp.find(FileSystem::getPathDelimiter())) == PEG_NOT_FOUND) {
 92 konrad.r 1.2 		pos = temp.size();
 93              		token = 0;
 94              	}
 95              	else {
 96              		token = 1;
 97              	}
 98              	path = temp.subString(0,pos);
 99              	if (FileSystem::canWrite(path)) {
100              		Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
101                                      Logger::WARNING,
102                                      "$0 is writeable! Possible security risk.",
103                                      path);
104              	}
105              	if ( !FileSystem::isDirectory(path)  ||
106              	     !FileSystem::canRead(path)) {
107              		if (!FileSystem::isDirectory(path)) {
108               			Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
109                                      Logger::SEVERE,
110                                      "$0 is not a directory!",
111                                      path);
112              		}
113 konrad.r 1.2 		if (!FileSystem::canRead(path)) {
114              		 	Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
115                                      Logger::SEVERE,
116                                      "Cannot $0 is not readable!",
117                                      path);
118              		}
119              		//cerr << "Not a good directory.\n";
120              		return false;
121              	}	
122              	temp.remove(0,pos+token);	
123                    }
124                    while ( temp.size() > 0 );	
125                    
126                  return true;
127              }
128               
129              /**
130              Initialize the config properties.
131              */
132              void ProviderDirPropertyOwner::initialize()
133              {
134 konrad.r 1.2     for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
135                  {
136                      //
137                      // Initialize the properties with default values
138                      //
139                      if (String::equalNoCase(properties[i].propertyName, "providerDir"
140              ))
141                      {
142                          _providerDir->propertyName = properties[i].propertyName;
143                          _providerDir->defaultValue = properties[i].defaultValue;
144                          _providerDir->currentValue = properties[i].defaultValue;
145                          _providerDir->plannedValue = properties[i].defaultValue;
146                          _providerDir->dynamic = properties[i].dynamic;
147                          _providerDir->domain = properties[i].domain;
148                          _providerDir->domainSize = properties[i].domainSize;
149                          _providerDir->externallyVisible = properties[i].externallyVisible;
150                      }
151                  }
152              }
153              
154              struct ConfigProperty* ProviderDirPropertyOwner::_lookupConfigProperty(
155 konrad.r 1.2     const String& name)
156              {
157                  if (String::equalNoCase(_providerDir->propertyName, name))
158                  {
159                      return _providerDir;
160                  }
161                  else
162                  {
163                      throw UnrecognizedConfigProperty(name);
164                  }
165              }
166              
167              /** 
168              Get information about the specified property.
169              */
170              void ProviderDirPropertyOwner::getPropertyInfo(
171                  const String& name, 
172                  Array<String>& propertyInfo)
173              {
174                  propertyInfo.clear();
175              
176 konrad.r 1.2     struct ConfigProperty* configProperty = _lookupConfigProperty(name);
177              
178                  propertyInfo.append(configProperty->propertyName);
179                  propertyInfo.append(configProperty->defaultValue);
180                  propertyInfo.append(configProperty->currentValue);
181                  propertyInfo.append(configProperty->plannedValue);
182                  if (configProperty->dynamic)
183                  {
184                      propertyInfo.append(STRING_TRUE);
185                  }
186                  else
187                  {
188                      propertyInfo.append(STRING_FALSE);
189                  }
190                  if (configProperty->externallyVisible)
191                  {
192                      propertyInfo.append(STRING_TRUE);
193                  }
194                  else
195                  {
196                      propertyInfo.append(STRING_FALSE);
197 konrad.r 1.2     }
198              }
199              
200              
201              /**
202              Get default value of the specified property.
203              */
204              const String ProviderDirPropertyOwner::getDefaultValue(const String& name)
205              {
206                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
207                  return configProperty->defaultValue;
208              }
209              
210              /** 
211              Get current value of the specified property.
212              */
213              const String ProviderDirPropertyOwner::getCurrentValue(const String& name)
214              {
215                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
216                  return configProperty->currentValue;
217              }
218 konrad.r 1.2 
219              /** 
220              Get planned value of the specified property.
221              */
222              const String ProviderDirPropertyOwner::getPlannedValue(const String& name)
223              {
224                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
225                  return configProperty->plannedValue;
226              }
227              
228              /** 
229              Init current value of the specified property to the specified value.
230              */
231              void ProviderDirPropertyOwner::initCurrentValue(
232                  const String& name, 
233                  const String& value)
234              {
235                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
236                  configProperty->currentValue = value;
237              }
238              
239 konrad.r 1.2 
240              /** 
241              Init planned value of the specified property to the specified value.
242              */
243              void ProviderDirPropertyOwner::initPlannedValue(
244                  const String& name, 
245                  const String& value)
246              {
247                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
248                  configProperty->plannedValue = value;
249              }
250              
251              /** 
252              Update current value of the specified property to the specified value.
253              */
254              void ProviderDirPropertyOwner::updateCurrentValue(
255                  const String& name, 
256                  const String& value) 
257              {
258                  //
259                  // make sure the property is dynamic before updating the value.
260 konrad.r 1.2     //
261                  if (!isDynamic(name))
262                  {
263                      throw NonDynamicConfigProperty(name); 
264                  }
265              
266                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
267                  configProperty->currentValue = value;
268              }
269              
270              
271              /** 
272              Update planned value of the specified property to the specified value.
273              */
274              void ProviderDirPropertyOwner::updatePlannedValue(
275                  const String& name, 
276                  const String& value)
277              {
278                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
279                  configProperty->plannedValue = value;
280              }
281 konrad.r 1.2 
282              /** 
283              Checks to see if the given value is valid or not.
284              */
285              Boolean ProviderDirPropertyOwner::isValid(const String& name, const String& value)
286              {
287              
288                  if (!isProviderDirValid( value ))
289                  {
290                      throw InvalidPropertyValue(name, value);
291                  }
292               
293                  return true;
294              }
295              
296              /** 
297              Checks to see if the specified property is dynamic or not.
298              */
299              Boolean ProviderDirPropertyOwner::isDynamic(const String& name)
300              {
301                  struct ConfigProperty* configProperty = _lookupConfigProperty(name);
302 konrad.r 1.2     return configProperty->dynamic;
303              }
304              
305              
306              PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2