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