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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2