1 kumpf 1.9 //%/////////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 kumpf 1.9 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
|
4 kumpf 1.1 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
|
12 chip 1.10 //
|
13 kumpf 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
|
22 kumpf 1.9 //==============================================================================
|
23 kumpf 1.1 //
24 // Author: Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
25 //
26 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
27 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
28 chip 1.10 // Sushma Fernandes, Hewlett-Packard Company
|
29 kumpf 1.1 // (sushma_fernandes@hp.com)
30 //
31 //%////////////////////////////////////////////////////////////////////////////
32
33
34 ///////////////////////////////////////////////////////////////////////////////
35 // ConfigSetting Provider
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/Config.h>
|
39 kumpf 1.4 #include <Pegasus/Common/PegasusVersion.h>
|
40 kumpf 1.1
41 #include <cctype>
42 #include <iostream>
43
44 #include "ConfigSettingProvider.h"
45 #include <Pegasus/Common/String.h>
46 #include <Pegasus/Common/System.h>
47 #include <Pegasus/Common/Array.h>
48 #include <Pegasus/Common/CIMType.h>
49 #include <Pegasus/Common/CIMInstance.h>
|
50 kumpf 1.6 #include <Pegasus/Common/CIMObjectPath.h>
|
51 kumpf 1.12 #include <Pegasus/Common/InternalException.h>
|
52 kumpf 1.1 #include <Pegasus/Common/CIMStatusCode.h>
53 #include <Pegasus/Common/Tracer.h>
54 #include <Pegasus/Config/ConfigManager.h>
55
56 #include <Pegasus/Repository/CIMRepository.h>
57 #include <Pegasus/Provider/CIMInstanceProvider.h>
58 #include <Pegasus/Provider/SimpleResponseHandler.h>
59 #include <Pegasus/Provider/OperationFlag.h>
60
61 PEGASUS_USING_STD;
62
63 PEGASUS_NAMESPACE_BEGIN
64
65 /**
66 The constants representing the string literals.
67 */
68 static const char PROPERTY_NAME [] = "PropertyName";
69
70 static const char DEFAULT_VALUE [] = "DefaultValue";
71
72 static const char CURRENT_VALUE [] = "CurrentValue";
73 kumpf 1.1
74 static const char PLANNED_VALUE [] = "PlannedValue";
75
76 static const char DYNAMIC_PROPERTY [] = "DynamicProperty";
77
78 /**
79 The constant represeting the config setting class name
80 */
81 static const char PG_CONFIG_SETTING [] = "PG_ConfigSetting";
82
83
84 void ConfigSettingProvider::getInstance(
85 const OperationContext & context,
|
86 kumpf 1.6 const CIMObjectPath& instanceName,
|
87 kumpf 1.1 const Uint32 flags,
|
88 kumpf 1.2 const CIMPropertyList& propertyList,
|
89 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
90 {
91 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::getInstance()");
92
93 Array<String> propertyInfo;
94 KeyBinding kb;
95 String keyName;
96 String keyValue;
97
|
98 kumpf 1.5 //
99 // check if the class name requested is PG_ConfigSetting
100 //
101 if (!String::equalNoCase(PG_CONFIG_SETTING, instanceName.getClassName()))
102 {
103 PEG_METHOD_EXIT();
104 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
105 instanceName.getClassName());
106 }
|
107 kumpf 1.1
|
108 kumpf 1.5 //
109 // validate key bindings
110 //
|
111 kumpf 1.1 Array<KeyBinding> kbArray = instanceName.getKeyBindings();
|
112 kumpf 1.5 if ( (kbArray.size() != 1) ||
113 (!String::equalNoCase(kbArray[0].getName(), PROPERTY_NAME)) )
|
114 kumpf 1.1 {
115 PEG_METHOD_EXIT();
116 throw PEGASUS_CIM_EXCEPTION(
|
117 kumpf 1.5 CIM_ERR_INVALID_PARAMETER,
118 "Invalid instance name");
|
119 kumpf 1.1 }
120
|
121 kumpf 1.5 keyValue.assign(kbArray[0].getValue());
122
|
123 kumpf 1.1 // begin processing the request
124 handler.processing();
125
|
126 kumpf 1.5 //
127 // Get values for the property
128 //
129 try
130 {
131 _configManager->getPropertyInfo(keyValue, propertyInfo);
132 }
133 catch (UnrecognizedConfigProperty& ucp)
134 {
135 PEG_METHOD_EXIT();
136 throw PEGASUS_CIM_EXCEPTION(
137 CIM_ERR_NOT_FOUND,
138 String("Configuration property \"") + keyValue + "\"");
139 }
|
140 kumpf 1.1
|
141 kumpf 1.5 if (propertyInfo.size() >= 5)
|
142 kumpf 1.1 {
|
143 kumpf 1.5 CIMInstance instance(PG_CONFIG_SETTING);
144
|
145 kumpf 1.1 //
|
146 kumpf 1.5 // construct the instance
|
147 kumpf 1.1 //
|
148 kumpf 1.5 instance.addProperty(CIMProperty(PROPERTY_NAME, propertyInfo[0]));
149 instance.addProperty(CIMProperty(DEFAULT_VALUE, propertyInfo[1]));
150 instance.addProperty(CIMProperty(CURRENT_VALUE, propertyInfo[2]));
151 instance.addProperty(CIMProperty(PLANNED_VALUE, propertyInfo[3]));
152 instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
153 Boolean(propertyInfo[4]=="true"?true:false)));
|
154 kumpf 1.1
|
155 kumpf 1.5 handler.deliver(instance);
|
156 kumpf 1.1
|
157 kumpf 1.5 // complete processing the request
158 handler.complete();
|
159 kumpf 1.1
|
160 kumpf 1.5 PEG_METHOD_EXIT();
161 return ;
|
162 kumpf 1.1 }
163 }
164
165 void ConfigSettingProvider::modifyInstance(
166 const OperationContext & context,
|
167 kumpf 1.6 const CIMObjectPath & instanceReference,
|
168 kumpf 1.1 const CIMInstance& modifiedIns,
169 const Uint32 flags,
|
170 kumpf 1.2 const CIMPropertyList& propertyList,
|
171 chip 1.10 ResponseHandler<void> & handler)
|
172 kumpf 1.1 {
173 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::modifyInstance()");
174
|
175 kumpf 1.7 //
|
176 chip 1.10 // get userName
|
177 kumpf 1.7 //
178 String userName;
179 try
180 {
181 IdentityContainer container = context.get(CONTEXT_IDENTITY);
182 userName = container.getUserName();
183 }
184 catch (...)
185 {
186 userName = String::EMPTY;
187 }
188
189 //
190 // verify user authorizations
191 //
192 if ( userName != String::EMPTY || userName != "" )
193 {
194 _verifyAuthorization(userName);
195 }
196
|
197 kumpf 1.5 // NOTE: Qualifiers are not processed by this provider, so the
198 // IncludeQualifiers flag is ignored.
199
200 //
201 // check if the class name requested is PG_ConfigSetting
202 //
203 if (!String::equalNoCase(PG_CONFIG_SETTING,
204 instanceReference.getClassName()))
|
205 kumpf 1.1 {
206 PEG_METHOD_EXIT();
|
207 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
208 instanceReference.getClassName());
|
209 kumpf 1.1 }
210
|
211 kumpf 1.5 //
212 // validate key bindings
213 //
214 Array<KeyBinding> kbArray = instanceReference.getKeyBindings();
215 if ( (kbArray.size() != 1) ||
216 (!String::equalNoCase(kbArray[0].getName(), PROPERTY_NAME)) )
217 {
218 PEG_METHOD_EXIT();
219 throw PEGASUS_CIM_EXCEPTION(
220 CIM_ERR_INVALID_PARAMETER,
221 "Invalid instance name");
222 }
223
224 String configPropertyName = kbArray[0].getValue();
225
226 // Modification of the entire instance is not supported by this provider
227 if (propertyList.isNull())
228 {
229 PEG_METHOD_EXIT();
230 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
231 "Modification of entire instance");
232 kumpf 1.5 }
|
233 kumpf 1.1
234 Boolean currentValueModified = false;
235 Boolean plannedValueModified = false;
236
|
237 kumpf 1.11 for (Uint32 i=0; i<propertyList.size(); i++)
|
238 kumpf 1.5 {
|
239 kumpf 1.11 String propertyName = propertyList[i];
|
240 kumpf 1.5 if (String::equalNoCase(propertyName, CURRENT_VALUE))
241 {
242 currentValueModified = true;
243 }
244 else if (String::equalNoCase(propertyName, PLANNED_VALUE))
245 {
246 plannedValueModified = true;
247 }
248 else
249 {
250 PEG_METHOD_EXIT();
251 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
252 String("Modification of property \"") + propertyName + "\"");
253 }
254 }
255
256 String currentValue = String::EMPTY;
257 String plannedValue = String::EMPTY;
258 Boolean currentValueIsNull = false;
259 Boolean plannedValueIsNull = false;
|
260 kumpf 1.1
261 // begin processing the request
262 handler.processing();
263
|
264 kumpf 1.5 //
265 // Get the current value from the instance
266 //
267 Uint32 pos = modifiedIns.findProperty(CURRENT_VALUE);
268 if (pos == PEG_NOT_FOUND)
269 {
270 currentValueIsNull = true;
271 }
272 else
|
273 kumpf 1.1 {
|
274 kumpf 1.5 CIMConstProperty prop = modifiedIns.getProperty(pos);
275 try
|
276 kumpf 1.1 {
|
277 kumpf 1.5 prop.getValue().get(currentValue);
|
278 kumpf 1.1 }
|
279 kumpf 1.5 catch (Exception& e)
|
280 kumpf 1.1 {
|
281 kumpf 1.5 PEG_METHOD_EXIT();
282 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
283 }
284 }
|
285 kumpf 1.1
|
286 kumpf 1.5 //
287 // Get the planned value from the instance
288 //
289 pos = modifiedIns.findProperty(PLANNED_VALUE);
290 if (pos == PEG_NOT_FOUND)
291 {
292 plannedValueIsNull = true;
|
293 kumpf 1.1 }
|
294 kumpf 1.5 else
|
295 kumpf 1.1 {
|
296 kumpf 1.5 CIMConstProperty prop = modifiedIns.getProperty(pos);
297 try
298 {
299 prop.getValue().get(plannedValue);
300 }
301 catch (Exception& e)
302 {
303 PEG_METHOD_EXIT();
304 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
305 }
|
306 kumpf 1.1 }
307
308 try
309 {
|
310 kumpf 1.5 //
311 // Update the current value, if requested
312 //
|
313 kumpf 1.1 if (currentValueModified)
314 {
|
315 kumpf 1.5 if ( !_configManager->updateCurrentValue(
316 configPropertyName, currentValue, currentValueIsNull) )
|
317 kumpf 1.1 {
|
318 kumpf 1.5 handler.complete();
|
319 kumpf 1.1 PEG_METHOD_EXIT();
320 throw PEGASUS_CIM_EXCEPTION(
321 CIM_ERR_FAILED,
322 "Failed to update the current value.");
323 }
324 }
325
|
326 kumpf 1.5 //
327 // Update the planned value, if requested
328 //
|
329 kumpf 1.1 if (plannedValueModified)
330 {
|
331 kumpf 1.5 if ( !_configManager->updatePlannedValue(
332 configPropertyName, plannedValue, plannedValueIsNull) )
|
333 kumpf 1.1 {
|
334 kumpf 1.5 handler.complete();
|
335 kumpf 1.1 PEG_METHOD_EXIT();
336 throw PEGASUS_CIM_EXCEPTION(
337 CIM_ERR_FAILED,
338 "Failed to update the planned value.");
339 }
340 }
341 }
342 catch (NonDynamicConfigProperty& ndcp)
343 {
344 PEG_METHOD_EXIT();
345 throw PEGASUS_CIM_EXCEPTION(
346 CIM_ERR_NOT_SUPPORTED, ndcp.getMessage());
347 }
348 catch (InvalidPropertyValue& ipv)
349 {
350 PEG_METHOD_EXIT();
351 throw PEGASUS_CIM_EXCEPTION(
|
352 kumpf 1.5 CIM_ERR_FAILED, ipv.getMessage());
|
353 kumpf 1.1 }
354 catch (UnrecognizedConfigProperty& ucp)
355 {
356 PEG_METHOD_EXIT();
357 throw PEGASUS_CIM_EXCEPTION(
|
358 kumpf 1.3 CIM_ERR_NOT_FOUND,
|
359 kumpf 1.5 String("Configuration property \"") +
360 configPropertyName + "\"");
|
361 kumpf 1.1 }
362
|
363 kumpf 1.5 handler.complete();
|
364 kumpf 1.1 PEG_METHOD_EXIT();
|
365 kumpf 1.5 return;
|
366 kumpf 1.1 }
367
368 void ConfigSettingProvider::enumerateInstances(
369 const OperationContext & context,
|
370 kumpf 1.6 const CIMObjectPath & ref,
|
371 kumpf 1.1 const Uint32 flags,
|
372 kumpf 1.2 const CIMPropertyList& propertyList,
|
373 kumpf 1.1 ResponseHandler<CIMInstance> & handler)
374 {
375 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::enumerateInstances()");
376
377 Array<CIMInstance> instanceArray;
378 Array<String> propertyNames;
379
380 //
381 // check if the class name requested is PG_ConfigSetting
382 //
|
383 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, ref.getClassName()))
|
384 kumpf 1.1 {
385 PEG_METHOD_EXIT();
|
386 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
387 ref.getClassName());
|
388 kumpf 1.1 }
389
390 // begin processing the request
391 handler.processing();
392
393 try
394 {
395 _configManager->getAllPropertyNames(propertyNames);
396
397 for (Uint32 i = 0; i < propertyNames.size(); i++)
398 {
399 Array<String> propertyInfo;
400
401 CIMInstance instance(PG_CONFIG_SETTING);
402
403 propertyInfo.clear();
404
405 _configManager->getPropertyInfo(propertyNames[i], propertyInfo);
406
407 Array<KeyBinding> keyBindings;
408 keyBindings.append(KeyBinding(PROPERTY_NAME, propertyInfo[0],
409 kumpf 1.1 KeyBinding::STRING));
|
410 kumpf 1.6 CIMObjectPath instanceName(ref.getHost(), ref.getNameSpace(),
|
411 kumpf 1.1 PG_CONFIG_SETTING, keyBindings);
412
413 // construct the instance
414 instance.addProperty(CIMProperty(PROPERTY_NAME, propertyInfo[0]));
415 instance.addProperty(CIMProperty(DEFAULT_VALUE, propertyInfo[1]));
416 instance.addProperty(CIMProperty(CURRENT_VALUE, propertyInfo[2]));
417 instance.addProperty(CIMProperty(PLANNED_VALUE, propertyInfo[3]));
418 instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
419 Boolean(propertyInfo[4]=="true"?true:false)));
420
|
421 kumpf 1.8 instance.setPath(instanceName);
|
422 kumpf 1.1 instanceArray.append(instance);
423 }
424 }
425 catch(Exception& e)
426 {
427 PEG_METHOD_EXIT();
428 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
429 }
430
431 handler.deliver(instanceArray);
432
433 // complete processing the request
434 handler.complete();
435
436 PEG_METHOD_EXIT();
437 }
438
439 void ConfigSettingProvider::enumerateInstanceNames(
440 const OperationContext & context,
|
441 kumpf 1.6 const CIMObjectPath & classReference,
442 ResponseHandler<CIMObjectPath> & handler)
|
443 kumpf 1.1 {
444 PEG_METHOD_ENTER(TRC_CONFIG,
445 "ConfigSettingProvider::enumerateInstanceNames()");
446
|
447 kumpf 1.6 Array<CIMObjectPath> instanceRefs;
|
448 kumpf 1.1 Array<String> propertyNames;
449 Array<KeyBinding> keyBindings;
450 KeyBinding kb;
451 String hostName;
452
453 hostName.assign(System::getHostName());
454
455 const String& className = classReference.getClassName();
456 const String& nameSpace = classReference.getNameSpace();
457
|
458 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, className))
|
459 kumpf 1.1 {
460 PEG_METHOD_EXIT();
|
461 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION( CIM_ERR_NOT_SUPPORTED, className );
|
462 kumpf 1.1 }
463
464 // begin processing the request
465 handler.processing();
466
467 try
468 {
469 _configManager->getAllPropertyNames(propertyNames);
470
471 Uint32 size = propertyNames.size();
472
473 for (Uint32 i = 0; i < size; i++)
474 {
475 keyBindings.append(KeyBinding(PROPERTY_NAME, propertyNames[i],
476 KeyBinding::STRING));
477
478 //
479 // Convert instance names to References
480 //
|
481 kumpf 1.6 CIMObjectPath ref(hostName, nameSpace, className, keyBindings);
|
482 kumpf 1.1
483 instanceRefs.append(ref);
484 keyBindings.clear();
485 }
486 }
487 catch(Exception& e)
488 {
489 PEG_METHOD_EXIT();
490 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
491 }
492
493 handler.deliver(instanceRefs);
494
495 // complete processing the request
496 handler.complete();
|
497 kumpf 1.7
498 PEG_METHOD_EXIT();
499 }
500
501 //
502 // Verify user authorization
503 //
504 void ConfigSettingProvider::_verifyAuthorization(const String& userName)
505 {
506 PEG_METHOD_ENTER(TRC_CONFIG,
507 "ConfigSettingProvider::_verifyAuthorization()");
508
509 if ( System::isPrivilegedUser(userName) == false )
510 {
511 PEG_METHOD_EXIT();
|
512 chip 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED,
|
513 kumpf 1.7 "Must be a privileged user to do this CIM operation.");
514 }
|
515 kumpf 1.1
516 PEG_METHOD_EXIT();
517 }
518
519 PEGASUS_NAMESPACE_END
520
|