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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2