(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 aruran.ms 1.8 // Modified By:  Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3614
 33 vijay.eli 1.9 //              Vijay Eli, IBM, (vijayeli@in.ibm.com) for Bug# 3613
 34 aruran.ms 1.10 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3613
 35 konrad.r  1.2  //
 36                //%/////////////////////////////////////////////////////////////////////////////
 37                
 38                
 39                ///////////////////////////////////////////////////////////////////////////////
 40                // 
 41                // This file has implementation for the providerDir property owner class.
 42                //
 43                ///////////////////////////////////////////////////////////////////////////////
 44                
 45                #include <Pegasus/Common/Config.h>
 46                #include <Pegasus/Common/Tracer.h>
 47                #include <Pegasus/Common/FileSystem.h>
 48                #include <Pegasus/Config/ConfigManager.h>
 49                #include "ProviderDirPropertyOwner.h"
 50                
 51                
 52                PEGASUS_NAMESPACE_BEGIN
 53                
 54                ///////////////////////////////////////////////////////////////////////////////
 55                //  ProviderDirPropertyOwner
 56 konrad.r  1.2  //
 57                //  When a new ProviderDir property is added, make sure to add the property name
 58                //  and the default attributes of that property in the table below.
 59                ///////////////////////////////////////////////////////////////////////////////
 60                
 61                static struct ConfigPropertyRow properties[] =
 62                {
 63 konrad.r  1.3  #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
 64 konrad.r  1.6      {"providerDir", "lib;bin", IS_STATIC, 0, 0, IS_VISIBLE},
 65 marek     1.11 #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 66                    {"providerDir", "lib:provider", IS_STATIC, 0, 0, IS_VISIBLE},
 67 konrad.r  1.3  #else
 68 konrad.r  1.6      {"providerDir", "lib", IS_STATIC, 0, 0, IS_VISIBLE},
 69 konrad.r  1.3  #endif
 70 konrad.r  1.2  };
 71                
 72                const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 73                
 74                
 75                /** Constructors  */
 76                ProviderDirPropertyOwner::ProviderDirPropertyOwner()
 77                {
 78                    _providerDir = new ConfigProperty;
 79                }
 80                
 81                /** Destructor  */
 82                ProviderDirPropertyOwner::~ProviderDirPropertyOwner()
 83                {
 84                    delete _providerDir;
 85                }
 86                
 87                /**
 88                Checks if the given directory is existing and writable
 89                */
 90                Boolean isProviderDirValid(const String& dirName)
 91 konrad.r  1.2  {
 92                      String temp = dirName;
 93                      String path = String::EMPTY;
 94                      Uint32 pos =0;
 95                      Uint32 token=0;
 96                
 97                      do {
 98 konrad.r  1.3  	if (( pos = temp.find(FileSystem::getPathDelimiter())) == PEG_NOT_FOUND) {
 99 konrad.r  1.2  		pos = temp.size();
100                		token = 0;
101                	}
102                	else {
103                		token = 1;
104                	}
105                	path = temp.subString(0,pos);
106 marek     1.11 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
107                    path.assign(ConfigManager::getHomedPath(path));
108                #endif
109 konrad.r  1.2  	if (FileSystem::canWrite(path)) {
110                		Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
111                                        Logger::WARNING,
112                                        "$0 is writeable! Possible security risk.",
113                                        path);
114                	}
115                	if ( !FileSystem::isDirectory(path)  ||
116                	     !FileSystem::canRead(path)) {
117                		if (!FileSystem::isDirectory(path)) {
118                 			Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
119                                        Logger::SEVERE,
120                                        "$0 is not a directory!",
121                                        path);
122                		}
123                		if (!FileSystem::canRead(path)) {
124                		 	Logger::put_l(Logger::ERROR_LOG,System::CIMSERVER,
125                                        Logger::SEVERE,
126                                        "Cannot $0 is not readable!",
127                                        path);
128                		}
129                		//cerr << "Not a good directory.\n";
130 konrad.r  1.2  		return false;
131                	}	
132                	temp.remove(0,pos+token);	
133                      }
134                      while ( temp.size() > 0 );	
135                      
136                    return true;
137                }
138                 
139                /**
140                Initialize the config properties.
141                */
142                void ProviderDirPropertyOwner::initialize()
143                {
144                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
145                    {
146                        //
147                        // Initialize the properties with default values
148                        //
149                        if (String::equalNoCase(properties[i].propertyName, "providerDir"
150                ))
151 konrad.r  1.2          {
152                            _providerDir->propertyName = properties[i].propertyName;
153                            _providerDir->defaultValue = properties[i].defaultValue;
154                            _providerDir->currentValue = properties[i].defaultValue;
155                            _providerDir->plannedValue = properties[i].defaultValue;
156                            _providerDir->dynamic = properties[i].dynamic;
157                            _providerDir->domain = properties[i].domain;
158                            _providerDir->domainSize = properties[i].domainSize;
159                            _providerDir->externallyVisible = properties[i].externallyVisible;
160                        }
161                    }
162                }
163                
164                struct ConfigProperty* ProviderDirPropertyOwner::_lookupConfigProperty(
165 aruran.ms 1.10     const String& name) const
166 konrad.r  1.2  {
167                    if (String::equalNoCase(_providerDir->propertyName, name))
168                    {
169                        return _providerDir;
170                    }
171                    else
172                    {
173                        throw UnrecognizedConfigProperty(name);
174                    }
175                }
176                
177                /** 
178                Get information about the specified property.
179                */
180                void ProviderDirPropertyOwner::getPropertyInfo(
181                    const String& name, 
182 vijay.eli 1.9      Array<String>& propertyInfo) const
183 konrad.r  1.2  {
184                    propertyInfo.clear();
185 aruran.ms 1.10     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
186 konrad.r  1.2  
187                    propertyInfo.append(configProperty->propertyName);
188                    propertyInfo.append(configProperty->defaultValue);
189                    propertyInfo.append(configProperty->currentValue);
190                    propertyInfo.append(configProperty->plannedValue);
191                    if (configProperty->dynamic)
192                    {
193                        propertyInfo.append(STRING_TRUE);
194                    }
195                    else
196                    {
197                        propertyInfo.append(STRING_FALSE);
198                    }
199                    if (configProperty->externallyVisible)
200                    {
201                        propertyInfo.append(STRING_TRUE);
202                    }
203                    else
204                    {
205                        propertyInfo.append(STRING_FALSE);
206                    }
207 konrad.r  1.2  }
208                
209                
210                /**
211                Get default value of the specified property.
212                */
213 vijay.eli 1.9  String ProviderDirPropertyOwner::getDefaultValue(const String& name) const
214 konrad.r  1.2  {
215 aruran.ms 1.10     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
216 vijay.eli 1.9  
217 konrad.r  1.2      return configProperty->defaultValue;
218                }
219                
220                /** 
221                Get current value of the specified property.
222                */
223 vijay.eli 1.9  String ProviderDirPropertyOwner::getCurrentValue(const String& name) const
224 konrad.r  1.2  {
225 aruran.ms 1.10     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
226 vijay.eli 1.9  
227 konrad.r  1.2      return configProperty->currentValue;
228                }
229                
230                /** 
231                Get planned value of the specified property.
232                */
233 vijay.eli 1.9  String ProviderDirPropertyOwner::getPlannedValue(const String& name) const
234 konrad.r  1.2  {
235 aruran.ms 1.10    struct ConfigProperty * configProperty = _lookupConfigProperty(name);
236 vijay.eli 1.9  
237 konrad.r  1.2      return configProperty->plannedValue;
238                }
239                
240                /** 
241                Init current value of the specified property to the specified value.
242                */
243                void ProviderDirPropertyOwner::initCurrentValue(
244                    const String& name, 
245                    const String& value)
246                {
247                    struct ConfigProperty* configProperty = _lookupConfigProperty(name);
248                    configProperty->currentValue = value;
249                }
250                
251                
252                /** 
253                Init planned value of the specified property to the specified value.
254                */
255                void ProviderDirPropertyOwner::initPlannedValue(
256                    const String& name, 
257                    const String& value)
258 konrad.r  1.2  {
259                    struct ConfigProperty* configProperty = _lookupConfigProperty(name);
260                    configProperty->plannedValue = value;
261                }
262                
263                /** 
264                Update current value of the specified property to the specified value.
265                */
266                void ProviderDirPropertyOwner::updateCurrentValue(
267                    const String& name, 
268                    const String& value) 
269                {
270                    //
271                    // make sure the property is dynamic before updating the value.
272                    //
273                    if (!isDynamic(name))
274                    {
275                        throw NonDynamicConfigProperty(name); 
276                    }
277                
278                    struct ConfigProperty* configProperty = _lookupConfigProperty(name);
279 konrad.r  1.2      configProperty->currentValue = value;
280                }
281                
282                
283                /** 
284                Update planned value of the specified property to the specified value.
285                */
286                void ProviderDirPropertyOwner::updatePlannedValue(
287                    const String& name, 
288                    const String& value)
289                {
290                    struct ConfigProperty* configProperty = _lookupConfigProperty(name);
291                    configProperty->plannedValue = value;
292                }
293                
294                /** 
295                Checks to see if the given value is valid or not.
296                */
297 vijay.eli 1.9  Boolean ProviderDirPropertyOwner::isValid(const String& name, 
298                                                const String& value) const
299 konrad.r  1.2  {
300                
301                    if (!isProviderDirValid( value ))
302                    {
303                        throw InvalidPropertyValue(name, value);
304                    }
305                 
306                    return true;
307                }
308                
309                /** 
310                Checks to see if the specified property is dynamic or not.
311                */
312 vijay.eli 1.9  Boolean ProviderDirPropertyOwner::isDynamic(const String& name) const
313 konrad.r  1.2  {
314 aruran.ms 1.10     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
315 vijay.eli 1.9  
316 konrad.r  1.6      return (configProperty->dynamic==IS_DYNAMIC);
317 konrad.r  1.2  }
318                
319                
320                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2