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 kumpf 1.13 #include <Pegasus/Common/ArrayInternal.h>
|
48 kumpf 1.1 #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 kumpf 1.14 #include <Pegasus/Common/ResponseHandler.h>
|
59 kumpf 1.1
60 PEGASUS_USING_STD;
61
62 PEGASUS_NAMESPACE_BEGIN
63
64 /**
65 The constants representing the string literals.
66 */
67 static const char PROPERTY_NAME [] = "PropertyName";
68
69 static const char DEFAULT_VALUE [] = "DefaultValue";
70
71 static const char CURRENT_VALUE [] = "CurrentValue";
72
73 static const char PLANNED_VALUE [] = "PlannedValue";
74
75 static const char DYNAMIC_PROPERTY [] = "DynamicProperty";
76
77 /**
78 The constant represeting the config setting class name
79 */
80 kumpf 1.1 static const char PG_CONFIG_SETTING [] = "PG_ConfigSetting";
81
82
83 void ConfigSettingProvider::getInstance(
84 const OperationContext & context,
|
85 kumpf 1.6 const CIMObjectPath& instanceName,
|
86 kumpf 1.15 const Boolean includeQualifiers,
87 const Boolean includeClassOrigin,
|
88 kumpf 1.2 const CIMPropertyList& propertyList,
|
89 kumpf 1.14 InstanceResponseHandler & handler)
|
90 kumpf 1.1 {
91 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::getInstance()");
92
93 Array<String> propertyInfo;
|
94 kumpf 1.16 CIMKeyBinding kb;
|
95 kumpf 1.1 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.16 Array<CIMKeyBinding> 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 kumpf 1.15 const Boolean includeQualifiers,
|
170 kumpf 1.2 const CIMPropertyList& propertyList,
|
171 kumpf 1.14 ResponseHandler & 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 kumpf 1.16 Array<CIMKeyBinding> kbArray = instanceReference.getKeyBindings();
|
215 kumpf 1.5 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 }
|
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.15 const Boolean includeQualifiers,
372 const Boolean includeClassOrigin,
|
373 kumpf 1.2 const CIMPropertyList& propertyList,
|
374 kumpf 1.14 InstanceResponseHandler & handler)
|
375 kumpf 1.1 {
376 PEG_METHOD_ENTER(TRC_CONFIG, "ConfigSettingProvider::enumerateInstances()");
377
378 Array<CIMInstance> instanceArray;
379 Array<String> propertyNames;
380
381 //
382 // check if the class name requested is PG_ConfigSetting
383 //
|
384 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, ref.getClassName()))
|
385 kumpf 1.1 {
386 PEG_METHOD_EXIT();
|
387 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
388 ref.getClassName());
|
389 kumpf 1.1 }
390
391 // begin processing the request
392 handler.processing();
393
394 try
395 {
396 _configManager->getAllPropertyNames(propertyNames);
397
398 for (Uint32 i = 0; i < propertyNames.size(); i++)
399 {
400 Array<String> propertyInfo;
401
402 CIMInstance instance(PG_CONFIG_SETTING);
403
404 propertyInfo.clear();
405
406 _configManager->getPropertyInfo(propertyNames[i], propertyInfo);
407
|
408 kumpf 1.16 Array<CIMKeyBinding> keyBindings;
409 keyBindings.append(CIMKeyBinding(PROPERTY_NAME, propertyInfo[0],
410 CIMKeyBinding::STRING));
|
411 kumpf 1.6 CIMObjectPath instanceName(ref.getHost(), ref.getNameSpace(),
|
412 kumpf 1.1 PG_CONFIG_SETTING, keyBindings);
413
414 // construct the instance
415 instance.addProperty(CIMProperty(PROPERTY_NAME, propertyInfo[0]));
416 instance.addProperty(CIMProperty(DEFAULT_VALUE, propertyInfo[1]));
417 instance.addProperty(CIMProperty(CURRENT_VALUE, propertyInfo[2]));
418 instance.addProperty(CIMProperty(PLANNED_VALUE, propertyInfo[3]));
419 instance.addProperty(CIMProperty(DYNAMIC_PROPERTY,
420 Boolean(propertyInfo[4]=="true"?true:false)));
421
|
422 kumpf 1.8 instance.setPath(instanceName);
|
423 kumpf 1.1 instanceArray.append(instance);
424 }
425 }
426 catch(Exception& e)
427 {
428 PEG_METHOD_EXIT();
429 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
430 }
431
432 handler.deliver(instanceArray);
433
434 // complete processing the request
435 handler.complete();
436
437 PEG_METHOD_EXIT();
438 }
439
440 void ConfigSettingProvider::enumerateInstanceNames(
441 const OperationContext & context,
|
442 kumpf 1.6 const CIMObjectPath & classReference,
|
443 kumpf 1.14 ObjectPathResponseHandler & handler)
|
444 kumpf 1.1 {
445 PEG_METHOD_ENTER(TRC_CONFIG,
446 "ConfigSettingProvider::enumerateInstanceNames()");
447
|
448 kumpf 1.6 Array<CIMObjectPath> instanceRefs;
|
449 kumpf 1.1 Array<String> propertyNames;
|
450 kumpf 1.16 Array<CIMKeyBinding> keyBindings;
451 CIMKeyBinding kb;
|
452 kumpf 1.1 String hostName;
453
454 hostName.assign(System::getHostName());
455
456 const String& className = classReference.getClassName();
457 const String& nameSpace = classReference.getNameSpace();
458
|
459 kumpf 1.5 if (!String::equalNoCase(PG_CONFIG_SETTING, className))
|
460 kumpf 1.1 {
461 PEG_METHOD_EXIT();
|
462 kumpf 1.5 throw PEGASUS_CIM_EXCEPTION( CIM_ERR_NOT_SUPPORTED, className );
|
463 kumpf 1.1 }
464
465 // begin processing the request
466 handler.processing();
467
468 try
469 {
470 _configManager->getAllPropertyNames(propertyNames);
471
472 Uint32 size = propertyNames.size();
473
474 for (Uint32 i = 0; i < size; i++)
475 {
|
476 kumpf 1.16 keyBindings.append(CIMKeyBinding(PROPERTY_NAME, propertyNames[i],
477 CIMKeyBinding::STRING));
|
478 kumpf 1.1
479 //
480 // Convert instance names to References
481 //
|
482 kumpf 1.6 CIMObjectPath ref(hostName, nameSpace, className, keyBindings);
|
483 kumpf 1.1
484 instanceRefs.append(ref);
485 keyBindings.clear();
486 }
487 }
488 catch(Exception& e)
489 {
490 PEG_METHOD_EXIT();
491 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
492 }
493
494 handler.deliver(instanceRefs);
495
496 // complete processing the request
497 handler.complete();
|
498 kumpf 1.7
499 PEG_METHOD_EXIT();
500 }
501
502 //
503 // Verify user authorization
504 //
505 void ConfigSettingProvider::_verifyAuthorization(const String& userName)
506 {
507 PEG_METHOD_ENTER(TRC_CONFIG,
508 "ConfigSettingProvider::_verifyAuthorization()");
509
510 if ( System::isPrivilegedUser(userName) == false )
511 {
512 PEG_METHOD_EXIT();
|
513 chip 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED,
|
514 kumpf 1.7 "Must be a privileged user to do this CIM operation.");
515 }
|
516 kumpf 1.1
517 PEG_METHOD_EXIT();
518 }
519
520 PEGASUS_NAMESPACE_END
521
|