BUG#: 8696
[tpot/pegasus/.git] / src / Clients / cimconfig / CIMConfigCommand.cpp
1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 #include <Pegasus/Common/Config.h>
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/System.h>
36 #include <Pegasus/Common/FileSystem.h>
37 #include <Pegasus/Common/CIMProperty.h>
38 #include <Pegasus/Common/CIMObjectPath.h>
39 #include <Pegasus/Common/CIMStatusCode.h>
40 #include <Pegasus/Common/Exception.h>
41 #include <Pegasus/Common/PegasusVersion.h>
42 #include <Pegasus/Common/StringConversion.h>
43 #include <Pegasus/getoopt/getoopt.h>
44
45 #include <Pegasus/Client/CIMClient.h>
46 #include <Pegasus/Config/ConfigFileHandler.h>
47 #include "CIMConfigCommand.h"
48
49 #ifdef PEGASUS_OS_PASE
50 # include <ILEWrapper/ILEUtilities.h>
51 #endif
52
53 #ifdef PEGASUS_OS_ZOS
54 #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
55 #endif
56
57 PEGASUS_NAMESPACE_BEGIN
58
59 //l10n
60 /**
61  * The CLI message resource name
62  */
63
64 static const char MSG_PATH []               = "pegasus/pegasusCLI";
65
66 //l10n end
67
68 /**
69     The command name.
70 */
71 static const char COMMAND_NAME []              = "cimconfig";
72
73 /**
74     The usage string for this command.  This string is displayed
75     when an error occurs in parsing or validating the command line.
76 */
77 static const char USAGE []                     = "Usage: ";
78
79 /**
80     This constant represents the getoopt argument designator
81 */
82 static const char GETOPT_ARGUMENT_DESIGNATOR   = ':';
83
84 /*
85     These constants represent the operation modes supported by the CLI.
86     Any new operation should be added here.
87 */
88
89 /**
90     This constant signifies that an operation option has not been recorded
91 */
92 static const Uint32 OPERATION_TYPE_UNINITIALIZED  = 0;
93
94 /**
95     This constant represents a property get operation
96 */
97 static const Uint32 OPERATION_TYPE_GET            = 1;
98
99 /**
100     This constant represents a property set operation
101 */
102 static const Uint32 OPERATION_TYPE_SET            = 2;
103
104 /**
105     This constant represents a property unset operation
106 */
107 static const Uint32 OPERATION_TYPE_UNSET          = 3;
108
109 /**
110     This constant represents a property list operation
111 */
112 static const Uint32 OPERATION_TYPE_LIST           = 4;
113
114 /**
115     This constant represents a help operation
116 */
117 static const Uint32 OPERATION_TYPE_HELP           = 5;
118
119 /**
120     This constant represents a version display operation
121 */
122 static const Uint32 OPERATION_TYPE_VERSION        = 6;
123
124 /**
125     The constants representing the string literals.
126 */
127 static const CIMName PROPERTY_NAME              = CIMName ("PropertyName");
128
129 static const CIMName DEFAULT_VALUE              = CIMName ("DefaultValue");
130
131 static const CIMName CURRENT_VALUE              = CIMName ("CurrentValue");
132
133 static const CIMName PLANNED_VALUE              = CIMName ("PlannedValue");
134
135 static const CIMName DYNAMIC_PROPERTY           = CIMName ("DynamicProperty");
136
137 /**
138     The name of the method that implements the property value update using the
139     timeout period.
140 */
141 static const CIMName METHOD_UPDATE_PROPERTY_VALUE  =
142     CIMName("UpdatePropertyValue");
143
144 /**
145     The input parameter names for the UpdatePropertyValue() method.
146 */
147 static const String PARAM_PROPERTYVALUE = String("PropertyValue");
148 static const String PARAM_RESETVALUE = String("ResetValue");
149 static const String PARAM_UPDATEPLANNEDVALUE = String("SetPlannedValue");
150 static const String PARAM_UPDATECURRENTVALUE = String("SetCurrentValue");
151 static const String PARAM_TIMEOUTPERIOD = String("TimeoutPeriod");
152
153 /**
154     The constants representing the messages.
155 */
156 static const char FILE_NOT_READABLE []         =
157                         "Configuration file not readable.";
158
159 static const char FAILED_TO_GET_PROPERTY []    =
160                         "Failed to get the config property.";
161
162 static const char FAILED_TO_SET_PROPERTY []    =
163                         "Failed to set the config property.";
164
165 static const char FAILED_TO_UNSET_PROPERTY []  =
166                         "Failed to unset the config property.";
167
168 static const char FAILED_TO_LIST_PROPERTIES [] =
169                         "Failed to list the config properties. ";
170
171 static const char CONFIG_SCHEMA_NOT_LOADED []  =
172     "Please restore the internal repository on the CIM Server.";
173
174 static const char PROPERTY_NOT_FOUND []        =
175                         "Specified property name was not found.";
176
177 static const char INVALID_PROPERTY_VALUE []    =
178                         "Specified property value is not valid.";
179
180 static const char PROPERTY_NOT_MODIFIED []     =
181                         "Specified property can not be modified.";
182
183 //l10n default messages and resource keys
184
185 static const char OPTION_INVALID_CIM_RUNNING [] =
186     "Option -$0 is not valid for this command when CIM server is not running.";
187
188 static const char OPTION_INVALID_CIM_RUNNING_KEY [] =
189     "Clients.CIMConfig.CIMConfigCommand.OPTION_INVALID_CIM_RUNNING";
190
191 static const char FILE_NOT_READABLE_KEY [] =
192     "Clients.CIMConfig.CIMConfigCommand.FILE_NOT_READABLE";
193
194 static const char FAILED_TO_GET_PROPERTY_KEY [] =
195     "Clients.CIMConfig.CIMConfigCommand.FAILED_TO_GET_PROPERTY";
196
197 static const char FAILED_TO_SET_PROPERTY_KEY [] =
198     "Clients.CIMConfig.CIMConfigCommand.FAILED_TO_SET_PROPERTY";
199
200 static const char FAILED_TO_UNSET_PROPERTY_KEY [] =
201     "Clients.CIMConfig.CIMConfigCommand.FAILED_TO_UNSET_PROPERTY";
202
203 static const char FAILED_TO_LIST_PROPERTIES_KEY [] =
204     "Clients.CIMConfig.CIMConfigCommand.FAILED_TO_LIST_PROPERTIES";
205
206 static const char CONFIG_SCHEMA_NOT_LOADED_KEY [] =
207     "Clients.CIMConfig.CIMConfigCommand.CONFIG_SCHEMA_NOT_LOADED";
208
209 static const char PROPERTY_NOT_FOUND_KEY [] =
210     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_NOT_FOUND";
211
212 static const char INVALID_PROPERTY_VALUE_KEY [] =
213     "Clients.CIMConfig.CIMConfigCommand.INVALID_PROPERTY_VALUE";
214
215 static const char PROPERTY_NOT_MODIFIED_KEY [] =
216     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_NOT_MODIFIED";
217
218 static const char PLANNED_VALUE_OF_PROPERTY_IS [] =
219     "Planned value for the property $0 is set to \"$1\" in CIMServer.";
220 static const char PLANNED_VALUE_OF_PROPERTY_IS_KEY [] =
221     "Clients.CIMConfig.CIMConfigCommand.PLANNED_VALUE_OF_PROPERTY_IS";
222
223 static const char CURRENT_VALUE_OF_PROPERTY_IS [] =
224     "Current value for the property $0 is set to \"$1\" in CIMServer.";
225 static const char CURRENT_VALUE_OF_PROPERTY_IS_KEY [] =
226     "Clients.CIMConfig.CIMConfigCommand.CURRENT_VALUE_OF_PROPERTY_IS";
227
228 static const char CURRENT_VALUE_OF_PROPERTY_CANNOT_BE_SET [] =
229     "Current value for the property '$0' can not be set because the"
230         " CIM server is not running.";
231 static const char CURRENT_VALUE_OF_PROPERTY_CANNOT_BE_SET_KEY [] =
232     "Clients.CIMConfig.CIMConfigCommand."
233         "CURRENT_VALUE_OF_PROPERTY_CANNOT_BE_SET";
234
235 static const char FAILED_UPDATE_OF_PLANNED_VALUE_IN_FILE [] =
236     "Failed to update the planned value of the Property '$0' in"
237         " configuration file.";
238 static const char FAILED_UPDATE_OF_PLANNED_VALUE_IN_FILE_KEY [] =
239     "Clients.CIMConfig.CIMConfigCommand."
240         "FAILED_UPDATE_OF_PLANNED_VALUE_IN_FILE";
241
242 static const char PROPERTY_UPDATED_IN_FILE [] =
243     "Property '$0' updated in configuration file.";
244
245 static const char PROPERTY_UPDATED_IN_FILE_KEY [] =
246     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_UPDATED_IN_FILE";
247
248 static const char PLANNED_VALUE_IS [] = "Planned value: $0";
249 static const char PLANNED_VALUE_IS_KEY [] =
250     "Clients.CIMConfig.CIMConfigCommand.PLANNED_VALUE_IS";
251
252 static const char CURRENT_VALUE_IS [] = "Current value: $0";
253 static const char CURRENT_VALUE_IS_KEY [] =
254     "Clients.CIMConfig.CIMConfigCommand.CURRENT_VALUE_IS";
255
256
257 static const char DEFAULT_VALUE_IS [] = "Default value: $0";
258 static const char DEFAULT_VALUE_IS_KEY [] =
259     "Clients.CIMConfig.CIMConfigCommand.DEFAULT_VALUE_IS";
260
261 static const char CANNOT_DETERMINE_PLANNED_VALUE_CIM_RUNNING [] =
262     "Planned value can not be determined because the CIM server is not"
263         " running.";
264 static const char CANNOT_DETERMINE_PLANNED_VALUE_CIM_RUNNING_KEY [] =
265     "Clients.CIMConfig.CIMConfigCommand."
266         "CANNOT_DETERMINE_PLANNED_VALUE_CIM_RUNNING";
267
268 static const char CANNOT_DETERMINE_CURRENT_VALUE_CIM_RUNNING [] =
269     "Current value can not be determined because the CIM server is"
270         " not running.";
271 static const char CANNOT_DETERMINE_CURRENT_VALUE_CIM_RUNNING_KEY [] =
272     "Clients.CIMConfig.CIMConfigCommand."
273         "CANNOT_DETERMINE_CURRENT_VALUE_CIM_RUNNING";
274
275 static const char PROPERTY_VALUE_ALREADY_SET_TO [] =
276     "The property '$0' value is already set to '$1'.";
277
278 static const char PROPERTY_VALUE_ALREADY_SET_TO_KEY [] =
279     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_VALUE_ALREADY_SET_TO";
280
281 static const char CURRENT_PROPERTY_SET_TO_DEFAULT [] =
282     "Current value for the property '$0' is set to default value in CIMServer.";
283 static const char CURRENT_PROPERTY_SET_TO_DEFAULT_KEY [] =
284     "Clients.CIMConfig.CIMConfigCommand.CURRENT_PROPERTY_SET_TO_DEFAULT";
285
286 static const char PROPERTY_UNSET_IN_FILE [] =
287     "Property '$0' is unset in the configuration file.";
288
289 static const char PROPERTY_UNSET_IN_FILE_KEY [] =
290     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_UNSET_IN_FILE";
291
292 static const char CURRENT_PROPERTY_CANNOT_BE_UNSET_CIM_NOT_RUNNING [] =
293     "Current value for the property '$0' can not be unset because the"
294         " CIM server is not running.";
295 static const char CURRENT_PROPERTY_CANNOT_BE_UNSET_CIM_NOT_RUNNING_KEY [] =
296     "Clients.CIMConfig.CIMConfigCommand."
297         "CURRENT_PROPERTY_CANNOT_BE_UNSET_CIM_NOT_RUNNING";
298
299 static const char PROPERTY_VALUE_ALREADY_UNSET [] =
300     "The property '$0' value is already unset.";
301
302 static const char PROPERTY_VALUE_ALREADY_UNSET_KEY [] =
303     "Clients.CIMConfig.CIMConfigCommand.PROPERTY_VALUE_ALREADY_UNSET";
304
305 static const char CURRENT_VALUES_CANNOT_BE_LISTED_CIM_NOT_RUNNING [] =
306     "Current value of properties can not be listed because the CIM server"
307         " is not running.";
308 static const char CURRENT_VALUES_CANNOT_BE_LISTED_CIM_NOT_RUNNING_KEY [] =
309     "Clients.CIMConfig.CIMConfigCommand."
310         "CURRENT_VALUES_CANNOT_BE_LISTED_CIM_NOT_RUNNING";
311
312 static const char NO_PROPERTIES_FOUND_IN_FILE [] =
313     "No configuration properties found in the configuration file.";
314
315 static const char NO_PROPERTIES_FOUND_IN_FILE_KEY [] =
316     "Clients.CIMConfig.CIMConfigCommand.NO_PROPERTIES_FOUND_IN_FILE";
317
318 static const char REQUIRED_ARGS_MISSING []        =
319                         "Required arguments missing.";
320
321 static const char REQUIRED_ARGS_MISSING_KEY [] =
322     "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
323
324 static const char ERR_USAGE [] =
325     "Use '--help' to obtain command syntax.";
326
327 static const char ERR_USAGE_KEY [] =
328     "Clients.CIMConfig.CIMConfigCommand.ERR_USAGE";
329
330
331 //l10n end default messages and keys
332
333 /**
334     The option character used to specify get config property.
335 */
336 static const char   OPTION_GET                 = 'g';
337
338 /**
339     The option character used to specify set config property.
340 */
341 static const char   OPTION_SET                 = 's';
342
343 #ifdef PEGASUS_OS_PASE
344 /**
345     The option character used to specify no output to stdout or stderr.
346 */
347      static const char OPTION_QUIET_VALUE      = 'q';
348 #endif
349
350 /**
351     The option character used to specify unset config property.
352 */
353 static const char   OPTION_UNSET               = 'u';
354
355 /**
356     The option character used to specify listing of config properties.
357 */
358 static const char   OPTION_LIST                = 'l';
359
360 /**
361     The option character used to specify the current config value.
362 */
363 static const char   OPTION_CURRENT_VALUE       = 'c';
364
365 /**
366     The option character used to specify the planned config value.
367 */
368 static const char   OPTION_PLANNED_VALUE       = 'p';
369
370 /**
371     The option character used to specify the default config value.
372 */
373 static const char   OPTION_DEFAULT_VALUE       = 'd';
374
375 /**
376     The option character used to specify the timeout value.
377 */
378 static const char   OPTION_TIMEOUT_VALUE       = 't';
379
380 /**
381     The option character used to display help info.
382 */
383 static const char   OPTION_HELP                = 'h';
384
385 /**
386     The option character used to display version info.
387 */
388 static const char   OPTION_VERSION             = 'v';
389
390 static const char   LONG_HELP []  = "help";
391
392 static const char   LONG_VERSION []  = "version";
393
394 /**
395     Constructs a CIMConfigCommand and initializes instance variables.
396 */
397 CIMConfigCommand::CIMConfigCommand ()
398 {
399     /**
400         Initialize the instance variables.
401     */
402     _operationType       = OPERATION_TYPE_UNINITIALIZED;
403     _propertyName        = CIMName ();
404     _currentValueSet     = false;
405     _plannedValueSet     = false;
406     _defaultValueSet     = false;
407 #ifdef PEGASUS_OS_PASE
408     _defaultQuietSet     = false;
409 #endif
410
411     /**
412         Build the usage string for the config command.
413     */
414     usage.reserveCapacity(200);
415     usage.append(USAGE);
416
417     usage.append(COMMAND_NAME);
418
419     usage.append(" -").append(OPTION_GET).append(" name");
420     usage.append(" [ -").append(OPTION_CURRENT_VALUE);
421     usage.append(" ] [ -").append(OPTION_DEFAULT_VALUE);
422     usage.append(" ] [ -").append(OPTION_PLANNED_VALUE).append(" ]\n");
423 #ifdef PEGASUS_OS_PASE
424     usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
425 #endif
426
427     usage.append("                 -").append(OPTION_SET).append(" name=value");
428     usage.append(" [ -").append(OPTION_CURRENT_VALUE);
429     usage.append(" ] [ -").append(OPTION_PLANNED_VALUE);
430     usage.append(" ] [ -").append(OPTION_TIMEOUT_VALUE).append(" ]\n");
431 #ifdef PEGASUS_OS_PASE
432     usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
433 #endif
434
435     usage.append("                 -").append(OPTION_UNSET).append(" name");
436     usage.append(" [ -").append(OPTION_CURRENT_VALUE);
437     usage.append(" ] [ -").append(OPTION_PLANNED_VALUE);
438     usage.append(" ] [ -").append(OPTION_TIMEOUT_VALUE).append(" ]\n");
439 #ifdef PEGASUS_OS_PASE
440     usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
441 #endif
442
443     usage.append("                 -").append(OPTION_LIST);
444     usage.append(" [ -").append(OPTION_CURRENT_VALUE);
445     usage.append(" | -").append(OPTION_PLANNED_VALUE).append(" ]\n");
446
447     usage.append("                 -").append(OPTION_HELP).append("\n");
448     usage.append("                 --").append(LONG_HELP).append("\n");
449     usage.append("                 --").append(LONG_VERSION).append("\n");
450
451     usage.append("Options : \n");
452     usage.append("    -c         - Use current configuration\n");
453     usage.append("    -d         - Use default configuration\n");
454     usage.append("    -g         - Get the value of specified configuration"
455                                     " property\n");
456     usage.append("    -h, --help - Display this help message\n");
457     usage.append("    -l         - Display all the configuration properties\n");
458     usage.append("    -p         - Configuration used on next CIM Server"
459                                     " start\n");
460 #ifdef PEGASUS_OS_PASE
461     usage.append("    -q         - Specify quiet mode,"
462                  "avoiding output to stdout or stderr\n");
463 #endif
464     usage.append("    -s         - Add or Update configuration property"
465                                     " value\n");
466     usage.append("    -u         - Reset configuration property to its"
467                                     " default value\n");
468     usage.append("    -t         - Timeout value in seconds for updating the"
469                                    " current or planned value\n");
470     usage.append("    --version  - Display CIM Server version number\n");
471
472     usage.append("\nUsage note: The cimconfig command can be used to update"
473                                     " the next planned\n");
474     usage.append( "configuration without having the CIM Server running."
475                                     " All other options \n");
476     usage.append("of the cimconfig command require that the CIM Server"
477                                     " is running.");
478
479 //l10n localize usage
480 #ifdef PEGASUS_HAS_ICU
481     MessageLoaderParms menuparms(
482             "Clients.CIMConfig.CIMConfigCommand.MENU.STANDARD",usage);
483     menuparms.msg_src_path = MSG_PATH;
484     usage = MessageLoader::getMessage(menuparms);
485 #endif
486     setUsage (usage);
487 }
488
489 /**
490     Parses the command line, validates the options, and sets instance
491     variables based on the option arguments.
492 */
493 void CIMConfigCommand::setCommand (Uint32 argc, char* argv [])
494 {
495     unsigned int      i                = 0;
496     Uint32            c                = 0;
497     String            property         = String ();
498     String            badOptionString  = String ();
499     String            optString        = String ();
500     Uint32            equalsIndex      = 0;
501
502     //
503     //  Construct optString
504     //
505     optString.append(OPTION_GET);
506     optString.append(GETOPT_ARGUMENT_DESIGNATOR);
507
508     optString.append(OPTION_SET);
509     optString.append(GETOPT_ARGUMENT_DESIGNATOR);
510
511     optString.append(OPTION_UNSET);
512     optString.append(GETOPT_ARGUMENT_DESIGNATOR);
513
514     optString.append(OPTION_TIMEOUT_VALUE);
515     optString.append(GETOPT_ARGUMENT_DESIGNATOR);
516
517
518     optString.append(OPTION_LIST);
519     optString.append(OPTION_CURRENT_VALUE);
520     optString.append(OPTION_PLANNED_VALUE);
521     optString.append(OPTION_DEFAULT_VALUE);
522 #ifdef PEGASUS_OS_PASE
523     optString.append(OPTION_QUIET_VALUE);
524 #endif
525     optString.append(OPTION_HELP);
526
527     //
528     //  Initialize and parse options
529     //
530     getoopt options ("");
531     options.addFlagspec(optString);
532     //PEP#167 - adding long flag for options : 'help' and 'version'
533     options.addLongFlagspec(LONG_HELP,getoopt::NOARG);
534     options.addLongFlagspec(LONG_VERSION,getoopt::NOARG);
535
536     options.parse (argc, argv);
537
538     if (options.hasErrors ())
539     {
540         throw CommandFormatException(options.getErrorStrings()[0]);
541     }
542
543     _operationType = OPERATION_TYPE_UNINITIALIZED;
544     _timeoutSeconds = 0;
545
546     //
547     //  Get options and arguments from the command line
548     //
549     for (i =  options.first (); i <  options.last (); i++)
550     {
551         if (options[i].getType () == Optarg::LONGFLAG)
552         {
553             if (options[i].getopt () == LONG_HELP)
554             {
555                 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
556                 {
557                     //
558                     // More than one operation option was found
559                     //
560                     throw UnexpectedOptionException(String(LONG_HELP));
561                 }
562
563                _operationType = OPERATION_TYPE_HELP;
564             }
565             else if (options[i].getopt () == LONG_VERSION)
566             {
567                 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
568                 {
569                     //
570                     // More than one operation option was found
571                     //
572                     throw UnexpectedOptionException(String(LONG_VERSION));
573                 }
574
575                _operationType = OPERATION_TYPE_VERSION;
576             }
577         }
578         else if (options [i].getType () == Optarg::REGULAR)
579         {
580             //
581             //  The cimconfig command has no non-option argument options
582             //
583             throw UnexpectedArgumentException(options[i].Value());
584         }
585         else /* if (options [i].getType () == Optarg::FLAG) */
586         {
587
588             c = options [i].getopt () [0];
589
590             switch (c)
591         {
592                 case OPTION_GET:
593                 {
594                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
595                     {
596                         //
597                         // More than one operation option was found
598                         //
599                         throw UnexpectedOptionException(OPTION_GET);
600                     }
601
602                     if (options.isSet (OPTION_GET) > 1)
603                     {
604                         //
605                         // More than one get option was found
606                         //
607                         throw DuplicateOptionException(OPTION_GET);
608                     }
609
610                     try
611                     {
612                         _propertyName = options [i].Value ();
613                     }
614                     catch (const InvalidNameException&)
615                     {
616                         throw InvalidOptionArgumentException(
617                             options[i].Value(), OPTION_GET);
618                     }
619
620                     _operationType = OPERATION_TYPE_GET;
621
622                     break;
623                 }
624
625                 case OPTION_SET:
626                 {
627                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
628                     {
629                         //
630                         // More than one operation option was found
631                         //
632                         throw UnexpectedOptionException(OPTION_SET);
633                     }
634
635                     if (options.isSet (OPTION_SET) > 1)
636                     {
637                         //
638                         // More than one set option was found
639                         //
640                         throw DuplicateOptionException(OPTION_SET);
641                     }
642
643                     _operationType = OPERATION_TYPE_SET;
644
645                     property = options [i].Value ();
646
647                     equalsIndex = property.find ('=');
648
649                     if ( equalsIndex == PEG_NOT_FOUND )
650                     {
651                         //
652                         // The property value was not specified
653                         //
654                         throw InvalidOptionArgumentException(
655                             property,
656                             OPTION_SET);
657                     }
658
659                     try
660                     {
661                         _propertyName = CIMName (property.subString
662                             (0, equalsIndex));
663                     }
664                     catch (const InvalidNameException&)
665                     {
666                         throw InvalidOptionArgumentException(
667                             property, OPTION_SET);
668                     }
669
670                     _propertyValue = property.subString( equalsIndex + 1 );
671
672                     break;
673                 }
674
675                 case OPTION_TIMEOUT_VALUE:
676                 {
677                     if (options.isSet (OPTION_TIMEOUT_VALUE) > 1)
678                     {
679                         throw DuplicateOptionException(OPTION_TIMEOUT_VALUE);
680                     }
681
682                     property = options [i].Value ();
683                     Uint64 value = 0;
684                     if (!StringConversion::decimalStringToUint64(
685                         property.getCString(), value) || !value)
686                     {
687                         throw InvalidOptionArgumentException(
688                             property, OPTION_TIMEOUT_VALUE);
689                     }
690                     _timeoutSeconds = (Uint32)value;
691                     break;
692                 }
693
694                 case OPTION_UNSET:
695                 {
696                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
697                     {
698                         //
699                         // More than one operation option was found
700                         //
701                         throw UnexpectedOptionException(OPTION_UNSET);
702                     }
703
704                     if (options.isSet (OPTION_UNSET) > 1)
705                     {
706                         //
707                         // More than one unset option was found
708                         //
709                         throw DuplicateOptionException(OPTION_UNSET);
710                     }
711
712                     try
713                     {
714                         _propertyName = options [i].Value ();
715                     }
716                     catch (const InvalidNameException&)
717                     {
718                         throw InvalidOptionArgumentException(
719                             options[i].Value(), OPTION_UNSET);
720                     }
721
722                     _operationType = OPERATION_TYPE_UNSET;
723
724                     break;
725                 }
726
727                 case OPTION_LIST:
728                 {
729                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
730                     {
731                         //
732                         // More than one operation option was found
733                         //
734                         throw UnexpectedOptionException(OPTION_LIST);
735                     }
736
737                     if (options.isSet (OPTION_LIST) > 1)
738                     {
739                         //
740                         // More than one list option was found
741                         //
742                         throw DuplicateOptionException(OPTION_LIST);
743                     }
744                     _operationType = OPERATION_TYPE_LIST;
745                     break;
746                 }
747
748                 case OPTION_CURRENT_VALUE:
749                 {
750                     if (options.isSet (OPTION_CURRENT_VALUE) > 1)
751                     {
752                         //
753                         // More than one current value option was found
754                         //
755                         throw DuplicateOptionException(OPTION_CURRENT_VALUE);
756                     }
757
758                     _currentValueSet = true;
759                     break;
760                 }
761
762                 case OPTION_PLANNED_VALUE:
763                 {
764                     if (options.isSet (OPTION_PLANNED_VALUE) > 1)
765                     {
766                         //
767                         // More than one planned value option was found
768                         //
769                         throw DuplicateOptionException(OPTION_PLANNED_VALUE);
770                     }
771
772                     _plannedValueSet = true;
773                     break;
774                 }
775
776                 case OPTION_DEFAULT_VALUE:
777                 {
778                     if (options.isSet (OPTION_DEFAULT_VALUE) > 1)
779                     {
780                         //
781                         // More than one default value option was found
782                         //
783                         throw DuplicateOptionException(OPTION_DEFAULT_VALUE);
784                     }
785
786                     _defaultValueSet = true;
787                     break;
788                 }
789
790                 //PEP#167 - 2 new cases added below for HELP and VERSION
791                 case OPTION_HELP:
792                 {
793                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
794                     {
795                         //
796                         // More than one operation option was found
797                         //
798                         throw UnexpectedOptionException(OPTION_HELP);
799                     }
800
801                     if (options.isSet (OPTION_HELP) > 1)
802                     {
803                         //
804                         // More than one list option was found
805                         //
806                         throw DuplicateOptionException(OPTION_HELP);
807                     }
808                     _operationType = OPERATION_TYPE_HELP;
809                     break;
810                 }
811                 case OPTION_VERSION:
812                 {
813                     if (_operationType != OPERATION_TYPE_UNINITIALIZED)
814                     {
815                         //
816                         // More than one operation option was found
817                         //
818                         throw UnexpectedOptionException(OPTION_VERSION);
819                     }
820
821                     if (options.isSet (OPTION_VERSION) > 1)
822                     {
823                         //
824                         // More than one list option was found
825                         //
826                         throw DuplicateOptionException(OPTION_VERSION);
827                     }
828                     _operationType = OPERATION_TYPE_VERSION;
829                     break;
830                 }
831
832 #ifdef PEGASUS_OS_PASE
833                 // check for quiet option
834                 // before processing the rest of the options
835                 case OPTION_QUIET_VALUE:
836                 {
837                     _defaultQuietSet = true;
838                     freopen("/dev/null","w",stdout);
839                     freopen("/dev/null","w",stderr);
840                     break;
841                 }
842 #endif
843
844                 default:
845                     //
846                     // Should never get here
847                     //
848                     break;
849             }
850         }
851     }
852
853     if ( _operationType == OPERATION_TYPE_UNINITIALIZED )
854     {
855         //
856         // No operation type was specified; throw exception
857         // so that usage can be displayed.
858         //
859         throw CommandFormatException(localizeMessage(
860             MSG_PATH, REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING));
861     }
862
863     if ( ( _operationType != OPERATION_TYPE_GET ) && ( _defaultValueSet ) )
864     {
865         //
866         // An invalid option was encountered
867         //
868         throw InvalidOptionException(OPTION_DEFAULT_VALUE);
869     }
870
871     if (_operationType != OPERATION_TYPE_SET &&
872         _operationType != OPERATION_TYPE_UNSET &&  _timeoutSeconds != 0)
873     {
874         //
875         // An invalid option was encountered
876         //
877         throw InvalidOptionException(OPTION_TIMEOUT_VALUE);
878     }
879
880     if (_operationType == OPERATION_TYPE_LIST)
881     {
882         if ( _currentValueSet && _plannedValueSet )
883         {
884             //
885             // An invalid option was encountered
886             //
887             throw InvalidOptionException(OPTION_CURRENT_VALUE);
888         }
889 #ifdef PEGASUS_OS_PASE
890         if( _defaultQuietSet )
891         {
892             //
893             // An invalid option was encountered
894             //
895             throw InvalidOptionException(OPTION_QUIET_VALUE);
896         }
897 #endif
898     }
899     else
900     {
901         //
902         // if no options specified for get, set or unset operations
903         // then set option as _currentValueSet
904         //
905         if ( !_currentValueSet && !_plannedValueSet && !_defaultValueSet )
906         {
907             _currentValueSet = true;
908         }
909     }
910
911 }
912
913 /**
914     Executes the command and writes the results to the PrintWriters.
915 */
916 Uint32 CIMConfigCommand::execute(
917     ostream& outPrintWriter,
918     ostream& errPrintWriter)
919 {
920     Boolean   connected     = false;
921     String    defaultValue;
922     String    currentValue;
923     String    plannedValue;
924     String    pegasusHome;
925     Boolean   gotCurrentValue = false;
926     Boolean   gotPlannedValue = false;
927
928     if (_operationType == OPERATION_TYPE_UNINITIALIZED)
929     {
930         //
931         // The command was not initialized
932         //
933         return RC_ERROR;
934     }
935     else if (_operationType == OPERATION_TYPE_HELP)
936     {
937         cerr << usage << endl;
938         return RC_SUCCESS;
939     }
940     else if (_operationType == OPERATION_TYPE_VERSION)
941     {
942         cerr << "Version " << PEGASUS_PRODUCT_VERSION << endl;
943         return RC_SUCCESS;
944     }
945
946     //
947     // Get local host name
948     //
949     _hostName.assign(System::getHostName());
950
951     try
952     {
953         // Construct the CIMClient and set to request server messages
954         // in the default language of this client process.
955         _client.reset(new CIMClient);
956         _client->setRequestDefaultLanguages();
957     }
958     catch (const Exception& e)
959     {
960         errPrintWriter << e.getMessage() << endl;
961         return RC_ERROR;
962     }
963
964     try
965     {
966         //
967         // Open connection with CIMSever
968         //
969         _client->connectLocal();
970
971         connected = true;
972     }
973     catch (const Exception&)
974     {
975         //
976         // Failed to connect, so process the request offline.
977         //
978         connected = false;
979     }
980
981     if (!connected)
982     {
983         //
984         // Locate the config files
985         //
986         const char* env = getenv("PEGASUS_HOME");
987
988         String currentFile =
989             FileSystem::getAbsolutePath(env, PEGASUS_CURRENT_CONFIG_FILE_PATH);
990         String plannedFile =
991             FileSystem::getAbsolutePath(env, PEGASUS_PLANNED_CONFIG_FILE_PATH);
992
993         try
994         {
995             //
996             // Open default config files and load current config properties
997             //
998             _configFileHandler.reset(
999                 new ConfigFileHandler(currentFile, plannedFile, true));;
1000         }
1001         catch (const NoSuchFile&)
1002         {
1003         }
1004         catch (const FileNotReadable& fnr)
1005         {
1006             errPrintWriter
1007                 << localizeMessage(
1008                        MSG_PATH, FILE_NOT_READABLE_KEY, FILE_NOT_READABLE)
1009                 << fnr.getMessage() << endl;
1010             return RC_ERROR;
1011         }
1012         catch (const ConfigFileSyntaxError& cfse)
1013         {
1014             errPrintWriter << cfse.getMessage() << endl;
1015             return RC_ERROR;
1016         }
1017
1018         //
1019         // When the CIM Server is not running, cimconfig only updates the
1020         // planned config properties.
1021         //
1022         _configFileHandler->loadPlannedConfigProperties();
1023     }
1024
1025     //
1026     // Perform the requested operation
1027     //
1028     switch (_operationType)
1029     {
1030         case OPERATION_TYPE_GET:
1031             try
1032             {
1033                 if (connected)
1034                 {
1035                     Array<String> propertyValues;
1036
1037                     _getPropertiesFromCIMServer( outPrintWriter,
1038                         errPrintWriter, _propertyName, propertyValues);
1039
1040                     defaultValue = propertyValues[1];
1041                     currentValue = propertyValues[2];
1042                     gotCurrentValue = true;
1043                     plannedValue = propertyValues[3];
1044                     gotPlannedValue = true;
1045                 }
1046                 else
1047                 {
1048                     if (_defaultValueSet)
1049                     {
1050                         errPrintWriter << localizeMessage(MSG_PATH,
1051                                              OPTION_INVALID_CIM_RUNNING_KEY,
1052                                              OPTION_INVALID_CIM_RUNNING,
1053                                              String(&OPTION_DEFAULT_VALUE,1))
1054                                        << endl;
1055                         return ( RC_ERROR );
1056                     }
1057                     else
1058                     {
1059                         gotCurrentValue = _configFileHandler->getCurrentValue (
1060                             _propertyName, currentValue );
1061                         gotPlannedValue = _configFileHandler->getPlannedValue (
1062                             _propertyName, plannedValue );
1063                     }
1064                 }
1065             }
1066             catch (const CIMException& e)
1067             {
1068                 CIMStatusCode code = e.getCode();
1069
1070                 if (code == CIM_ERR_NOT_FOUND ||
1071                     code == CIM_ERR_FAILED)
1072                 {
1073                     outPrintWriter << localizeMessage(MSG_PATH,
1074                                                 PROPERTY_NOT_FOUND_KEY,
1075                                                 PROPERTY_NOT_FOUND)
1076                                                  << endl;
1077
1078                     errPrintWriter << e.getMessage() << endl;
1079                 }
1080                 else if (code == CIM_ERR_INVALID_CLASS)
1081                 {
1082                     outPrintWriter << localizeMessage(MSG_PATH,
1083                                                 FAILED_TO_GET_PROPERTY_KEY,
1084                                                 FAILED_TO_GET_PROPERTY)
1085                                    << endl <<
1086                                       localizeMessage(MSG_PATH,
1087                                                 CONFIG_SCHEMA_NOT_LOADED_KEY,
1088                                                 CONFIG_SCHEMA_NOT_LOADED)
1089                                    << endl;
1090                 }
1091                 else
1092                 {
1093                     outPrintWriter
1094                         << localizeMessage(
1095                                 MSG_PATH,
1096                                 FAILED_TO_GET_PROPERTY_KEY,
1097                                 FAILED_TO_GET_PROPERTY)
1098                         << e.getMessage() << endl;
1099
1100                 }
1101                 return ( RC_ERROR );
1102             }
1103             catch (const Exception& e)
1104             {
1105                 outPrintWriter
1106                     << localizeMessage(MSG_PATH,FAILED_TO_GET_PROPERTY_KEY,
1107                                        FAILED_TO_GET_PROPERTY) << endl
1108                     << e.getMessage() << endl;
1109                 return ( RC_ERROR );
1110             }
1111
1112             if( _currentValueSet || ( !_plannedValueSet && !_defaultValueSet ))
1113             {
1114                 if (gotCurrentValue)
1115                 {
1116                     outPrintWriter << localizeMessage(MSG_PATH,
1117                                                       CURRENT_VALUE_IS_KEY,
1118                                                       CURRENT_VALUE_IS,
1119                                                       currentValue) << endl;
1120                 }
1121                 else
1122                 {
1123                     outPrintWriter
1124                         << localizeMessage(MSG_PATH,
1125                                 CANNOT_DETERMINE_CURRENT_VALUE_CIM_RUNNING_KEY,
1126                                 CANNOT_DETERMINE_CURRENT_VALUE_CIM_RUNNING)
1127                         << endl;
1128                     return RC_ERROR;
1129                 }
1130             }
1131
1132             if( _plannedValueSet )
1133             {
1134                 if (gotPlannedValue)
1135                 {
1136                     outPrintWriter << localizeMessage(MSG_PATH,
1137                                                       PLANNED_VALUE_IS_KEY,
1138                                                       PLANNED_VALUE_IS,
1139                                                       plannedValue) << endl;
1140                 }
1141                 else
1142                 {
1143                     outPrintWriter
1144                         << localizeMessage(MSG_PATH,
1145                                CANNOT_DETERMINE_PLANNED_VALUE_CIM_RUNNING_KEY,
1146                                CANNOT_DETERMINE_PLANNED_VALUE_CIM_RUNNING)
1147                         << endl;
1148                     return RC_ERROR;
1149                 }
1150             }
1151
1152             if( _defaultValueSet )
1153             {
1154                 outPrintWriter << localizeMessage(MSG_PATH,
1155                                                   DEFAULT_VALUE_IS_KEY,
1156                                                   DEFAULT_VALUE_IS,
1157                                                   defaultValue) << endl;
1158             }
1159             break;
1160
1161         case OPERATION_TYPE_SET:
1162             //
1163             // send changes to CIMOM if running, else send to config file
1164             //
1165             try
1166             {
1167                 if (connected)
1168                 {
1169                     _updatePropertyInCIMServer( outPrintWriter,
1170                         errPrintWriter, _propertyName, _propertyValue, false);
1171
1172                     if ( _currentValueSet )
1173                     {
1174                        outPrintWriter
1175                            << localizeMessage(MSG_PATH,
1176                                   CURRENT_VALUE_OF_PROPERTY_IS_KEY,
1177                                   CURRENT_VALUE_OF_PROPERTY_IS,
1178                                   _propertyName.getString(),
1179                                   _propertyValue)
1180                            << endl;
1181                     }
1182
1183                     if ( _plannedValueSet )
1184                     {
1185                         outPrintWriter
1186                             << localizeMessage(MSG_PATH,
1187                                    PLANNED_VALUE_OF_PROPERTY_IS_KEY,
1188                                    PLANNED_VALUE_OF_PROPERTY_IS,
1189                                    _propertyName.getString(),
1190                                    _propertyValue)
1191                             << endl;
1192                     }
1193                 }
1194                 else
1195                 {
1196                     if (_currentValueSet)
1197                     {
1198                         outPrintWriter
1199                             << localizeMessage(MSG_PATH,
1200                                   CURRENT_VALUE_OF_PROPERTY_CANNOT_BE_SET_KEY,
1201                                   CURRENT_VALUE_OF_PROPERTY_CANNOT_BE_SET,
1202                                   _propertyName.getString()) << endl;
1203
1204                         return ( RC_ERROR );
1205                     }
1206                     else if (_plannedValueSet)
1207                     {
1208                         if ( !_configFileHandler->updatePlannedValue(
1209                             _propertyName, _propertyValue, false ) )
1210                         {
1211                             outPrintWriter
1212                                 << localizeMessage(MSG_PATH,
1213                                      FAILED_UPDATE_OF_PLANNED_VALUE_IN_FILE_KEY,
1214                                      FAILED_UPDATE_OF_PLANNED_VALUE_IN_FILE,
1215                                      _propertyName.getString())
1216                                 << endl;
1217                             return ( RC_ERROR );
1218                         }
1219                     }
1220                     outPrintWriter
1221                         << localizeMessage(MSG_PATH,
1222                                PROPERTY_UPDATED_IN_FILE_KEY,
1223                                PROPERTY_UPDATED_IN_FILE,
1224                                _propertyName.getString()) << endl;
1225
1226                 }
1227             }
1228             catch (const CIMException& e)
1229             {
1230                 CIMStatusCode code = e.getCode();
1231
1232                 if (code == CIM_ERR_TYPE_MISMATCH)
1233                 {
1234                     outPrintWriter << localizeMessage(MSG_PATH,
1235                                          INVALID_PROPERTY_VALUE_KEY,
1236                                          INVALID_PROPERTY_VALUE) << endl;
1237
1238                     errPrintWriter << e.getMessage() << endl;
1239                 }
1240                 else if (code == CIM_ERR_NOT_FOUND)
1241                 {
1242                     outPrintWriter << localizeMessage(MSG_PATH,
1243                                           PROPERTY_NOT_FOUND_KEY,
1244                                           PROPERTY_NOT_FOUND) << endl;
1245
1246                     errPrintWriter << e.getMessage() << endl;
1247                 }
1248                 else if (code == CIM_ERR_NOT_SUPPORTED)
1249                 {
1250                     outPrintWriter << localizeMessage(MSG_PATH,
1251                                           PROPERTY_NOT_MODIFIED_KEY,
1252                                           PROPERTY_NOT_MODIFIED) << endl;
1253
1254                     errPrintWriter << e.getMessage() << endl;
1255                 }
1256                 else if (code == CIM_ERR_FAILED)
1257                 {
1258                     outPrintWriter << localizeMessage(MSG_PATH,
1259                                           FAILED_TO_SET_PROPERTY_KEY,
1260                                           FAILED_TO_SET_PROPERTY)
1261                                    << e.getMessage() << endl;
1262                 }
1263                 else if (code == CIM_ERR_ALREADY_EXISTS)
1264                 {
1265                     outPrintWriter << localizeMessage(MSG_PATH,
1266                                           PROPERTY_VALUE_ALREADY_SET_TO_KEY,
1267                                           PROPERTY_VALUE_ALREADY_SET_TO,
1268                                           _propertyName.getString(),
1269                                           _propertyValue) << endl;
1270
1271                     errPrintWriter << e.getMessage() << endl;
1272                 }
1273                 else if (code == CIM_ERR_INVALID_CLASS)
1274                 {
1275                     outPrintWriter << localizeMessage(MSG_PATH,
1276                                           FAILED_TO_SET_PROPERTY_KEY,
1277                                           FAILED_TO_SET_PROPERTY)
1278                                           << endl <<
1279                                       localizeMessage(MSG_PATH,
1280                                           CONFIG_SCHEMA_NOT_LOADED_KEY,
1281                                           CONFIG_SCHEMA_NOT_LOADED)
1282                                           << endl;
1283                 }
1284                 else
1285                 {
1286                     errPrintWriter << e.getMessage() << endl;
1287                 }
1288                 return ( RC_ERROR );
1289             }
1290             catch (const Exception& e)
1291             {
1292                 outPrintWriter << localizeMessage(MSG_PATH,
1293                                                   FAILED_TO_SET_PROPERTY_KEY,
1294                                                   FAILED_TO_SET_PROPERTY)
1295                                                   << endl
1296                                                   << e.getMessage() << endl;
1297                 return ( RC_ERROR );
1298             }
1299             break;
1300
1301         case OPERATION_TYPE_UNSET:
1302             //
1303             // send changes to CIMOM if running, else send to config file
1304             //
1305             try
1306             {
1307                 if (connected)
1308                 {
1309                     _propertyValue = String::EMPTY;
1310
1311                     _updatePropertyInCIMServer( outPrintWriter,
1312                         errPrintWriter, _propertyName, _propertyValue, true);
1313
1314                     if ( _currentValueSet )
1315                     {
1316                         outPrintWriter << localizeMessage(MSG_PATH,
1317                                             CURRENT_PROPERTY_SET_TO_DEFAULT_KEY,
1318                                             CURRENT_PROPERTY_SET_TO_DEFAULT,
1319                                             _propertyName.getString())
1320                                             << endl;
1321
1322                     }
1323
1324                     if ( _plannedValueSet )
1325                     {
1326                         outPrintWriter << localizeMessage(MSG_PATH,
1327                                               PROPERTY_UNSET_IN_FILE_KEY,
1328                                               PROPERTY_UNSET_IN_FILE,
1329                                               _propertyName.getString())
1330                                               << endl;
1331                     }
1332                 }
1333                 else
1334                 {
1335                     if (_currentValueSet)
1336                     {
1337                         outPrintWriter << localizeMessage(MSG_PATH,
1338                            CURRENT_PROPERTY_CANNOT_BE_UNSET_CIM_NOT_RUNNING_KEY,
1339                            CURRENT_PROPERTY_CANNOT_BE_UNSET_CIM_NOT_RUNNING,
1340                            _propertyName.getString())
1341                            << endl;
1342
1343
1344                         return ( RC_ERROR );
1345                     }
1346
1347                     if ( !_configFileHandler->updatePlannedValue(
1348                         _propertyName, _propertyValue, true ) )
1349                     {
1350                         return ( RC_ERROR );
1351                     }
1352                     outPrintWriter << localizeMessage(MSG_PATH,
1353                                           PROPERTY_UNSET_IN_FILE_KEY,
1354                                           PROPERTY_UNSET_IN_FILE,
1355                                           _propertyName.getString())
1356                                           << endl;
1357                 }
1358
1359             }
1360             catch (const CIMException& e)
1361             {
1362                 CIMStatusCode code = e.getCode();
1363
1364                 if (code == CIM_ERR_TYPE_MISMATCH)
1365                 {
1366                     outPrintWriter << localizeMessage(MSG_PATH,
1367                                           INVALID_PROPERTY_VALUE_KEY,
1368                                           INVALID_PROPERTY_VALUE)
1369                                           << endl;
1370
1371                     errPrintWriter << e.getMessage() << endl;
1372                 }
1373                 else if (code == CIM_ERR_NOT_FOUND)
1374                 {
1375                     outPrintWriter << localizeMessage(MSG_PATH,
1376                                           PROPERTY_NOT_FOUND_KEY,
1377                                           PROPERTY_NOT_FOUND)
1378                                           << endl;
1379
1380                     errPrintWriter << e.getMessage() << endl;
1381                 }
1382                 else if (code == CIM_ERR_NOT_SUPPORTED)
1383                 {
1384                     outPrintWriter << localizeMessage(MSG_PATH,
1385                                           PROPERTY_NOT_MODIFIED_KEY,
1386                                           PROPERTY_NOT_MODIFIED)
1387                                           << endl;
1388
1389                     errPrintWriter << e.getMessage() << endl;
1390                 }
1391                 else if (code == CIM_ERR_FAILED)
1392                 {
1393                     outPrintWriter << localizeMessage(MSG_PATH,
1394                                           FAILED_TO_UNSET_PROPERTY_KEY,
1395                                           FAILED_TO_UNSET_PROPERTY)
1396                                           << e.getMessage() << endl;
1397                 }
1398                 else if (code == CIM_ERR_ALREADY_EXISTS)
1399                 {
1400                     outPrintWriter << localizeMessage(MSG_PATH,
1401                                           PROPERTY_VALUE_ALREADY_UNSET_KEY,
1402                                           PROPERTY_VALUE_ALREADY_UNSET,
1403                                           _propertyName.getString())
1404                                           << endl;
1405
1406                     errPrintWriter << e.getMessage() << endl;
1407                 }
1408                 else if (code == CIM_ERR_INVALID_CLASS)
1409                 {
1410                     outPrintWriter << localizeMessage(MSG_PATH,
1411                                           FAILED_TO_UNSET_PROPERTY_KEY,
1412                                           FAILED_TO_UNSET_PROPERTY)
1413                                           << endl <<
1414                                       localizeMessage(MSG_PATH,
1415                                           CONFIG_SCHEMA_NOT_LOADED_KEY,
1416                                           CONFIG_SCHEMA_NOT_LOADED)
1417                                           << endl;
1418                 }
1419                 else
1420                 {
1421                     errPrintWriter << e.getMessage() << endl;
1422                 }
1423                 return ( RC_ERROR );
1424             }
1425             catch (const Exception& e)
1426             {
1427                 outPrintWriter << localizeMessage(MSG_PATH,
1428                                       FAILED_TO_UNSET_PROPERTY_KEY,
1429                                       FAILED_TO_UNSET_PROPERTY)
1430                                       << endl << e.getMessage() << endl;
1431                 return ( RC_ERROR );
1432             }
1433             break;
1434
1435         case OPERATION_TYPE_LIST:
1436             //
1437             // send request to CIMOM if running, else send to config file
1438             //
1439             try
1440             {
1441                 Array<CIMName> propertyNames;
1442                 Array<String> propertyValues;
1443
1444                 if (connected)
1445                 {
1446                     _listAllPropertiesInCIMServer(outPrintWriter,
1447                          errPrintWriter, propertyNames, propertyValues);
1448
1449                 }
1450                 else
1451                 {
1452                     if (_plannedValueSet)
1453                     {
1454                         _configFileHandler->getAllPlannedProperties(
1455                             propertyNames, propertyValues);
1456                     }
1457                     else
1458                     {
1459                         outPrintWriter
1460                          << localizeMessage(MSG_PATH,
1461                             CURRENT_VALUES_CANNOT_BE_LISTED_CIM_NOT_RUNNING_KEY,
1462                             CURRENT_VALUES_CANNOT_BE_LISTED_CIM_NOT_RUNNING)
1463                             << endl;
1464                         return RC_ERROR;
1465                     }
1466                 }
1467
1468                 Uint32 valuesSize = propertyValues.size();
1469                 Uint32 namesSize  = propertyNames.size();
1470
1471                 if (namesSize == 0)
1472                 {
1473                     outPrintWriter << localizeMessage(MSG_PATH,
1474                                           NO_PROPERTIES_FOUND_IN_FILE_KEY,
1475                                           NO_PROPERTIES_FOUND_IN_FILE)
1476                                           << endl;
1477                     break;
1478                 }
1479
1480                 for ( Uint32 i = 0; i < namesSize; i++ )
1481                 {
1482                     outPrintWriter << propertyNames[i].getString();
1483                     if ( ( _currentValueSet || _plannedValueSet ) &&
1484                          ( valuesSize == namesSize) )
1485                     {
1486                         outPrintWriter << "=" << propertyValues[i];
1487                     }
1488                     outPrintWriter << endl;
1489                 }
1490                 break;
1491             }
1492             catch (const CIMException& e)
1493             {
1494                 CIMStatusCode code = e.getCode();
1495
1496                 if (code == CIM_ERR_NOT_FOUND || code == CIM_ERR_INVALID_CLASS)
1497                 {
1498                     outPrintWriter << localizeMessage(MSG_PATH,
1499                                           FAILED_TO_LIST_PROPERTIES_KEY,
1500                                           FAILED_TO_LIST_PROPERTIES)
1501                                           << endl <<
1502                                       localizeMessage(MSG_PATH,
1503                                           CONFIG_SCHEMA_NOT_LOADED_KEY,
1504                                           CONFIG_SCHEMA_NOT_LOADED)
1505                                           << endl;
1506                 }
1507                 else if (code == CIM_ERR_FAILED)
1508                 {
1509                     outPrintWriter << localizeMessage(MSG_PATH,
1510                                           FAILED_TO_LIST_PROPERTIES_KEY,
1511                                           FAILED_TO_LIST_PROPERTIES)
1512                                    << e.getMessage() << endl;
1513                 }
1514                 else
1515                 {
1516                     errPrintWriter << e.getMessage() << endl;
1517                 }
1518
1519                 return ( RC_ERROR );
1520             }
1521             catch (const Exception& e)
1522             {
1523                 outPrintWriter << localizeMessage(MSG_PATH,
1524                                       FAILED_TO_LIST_PROPERTIES_KEY,
1525                                       FAILED_TO_LIST_PROPERTIES)
1526                                << endl << e.getMessage() << endl;
1527                 return ( RC_ERROR );
1528             }
1529
1530         default:
1531             //
1532             // Should never get here
1533             //
1534             break;
1535     }
1536
1537     return (RC_SUCCESS);
1538 }
1539
1540 /**
1541     Get property values for the specified property from the CIM Server.
1542 */
1543 void CIMConfigCommand::_getPropertiesFromCIMServer
1544     (
1545     ostream&    outPrintWriter,
1546     ostream&    errPrintWriter,
1547     const CIMName&    propName,
1548     Array <String>&    propValues
1549     )
1550 {
1551     CIMProperty prop;
1552
1553     Array<CIMKeyBinding> kbArray;
1554     CIMKeyBinding        kb;
1555
1556     kb.setName(PROPERTY_NAME);
1557     kb.setValue(propName.getString());
1558     kb.setType(CIMKeyBinding::STRING);
1559
1560     kbArray.append(kb);
1561
1562     CIMObjectPath reference(
1563         _hostName, PEGASUS_NAMESPACENAME_CONFIG,
1564         PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);
1565
1566     CIMInstance cimInstance =
1567         _client->getInstance(PEGASUS_NAMESPACENAME_CONFIG, reference);
1568
1569     Uint32 pos = cimInstance.findProperty(PROPERTY_NAME);
1570     prop = (CIMProperty)cimInstance.getProperty(pos);
1571     propValues.append(prop.getValue().toString());
1572
1573     pos = cimInstance.findProperty(DEFAULT_VALUE);
1574     prop = (CIMProperty)cimInstance.getProperty(pos);
1575     propValues.append(prop.getValue().toString());
1576
1577     pos = cimInstance.findProperty(CURRENT_VALUE);
1578     prop = (CIMProperty)cimInstance.getProperty(pos);
1579     propValues.append(prop.getValue().toString());
1580
1581     pos = cimInstance.findProperty(PLANNED_VALUE);
1582     prop = (CIMProperty)cimInstance.getProperty(pos);
1583     propValues.append(prop.getValue().toString());
1584
1585     pos = cimInstance.findProperty(DYNAMIC_PROPERTY);
1586     prop = (CIMProperty)cimInstance.getProperty(pos);
1587     propValues.append(prop.getValue().toString());
1588 }
1589
1590 /**
1591     Send an updated property value to the CIM Server.
1592  */
1593 void CIMConfigCommand::_updatePropertyInCIMServer
1594     (
1595     ostream&    outPrintWriter,
1596     ostream&    errPrintWriter,
1597     const CIMName&   propName,
1598     const String&   propValue,
1599     Boolean     isUnsetOperation
1600     )
1601 {
1602     Array<CIMKeyBinding> kbArray;
1603     CIMKeyBinding        kb;
1604
1605     kb.setName(PROPERTY_NAME);
1606     kb.setValue(propName.getString());
1607     kb.setType(CIMKeyBinding::STRING);
1608
1609     kbArray.append(kb);
1610
1611     CIMObjectPath reference(
1612         _hostName, PEGASUS_NAMESPACENAME_CONFIG,
1613         PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);
1614
1615     if (_timeoutSeconds == 0)
1616     {
1617         _timeoutSeconds = (PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS / 1000);
1618     }
1619
1620     Array<CIMParamValue> inParams;
1621     Array<CIMParamValue> outParams;
1622
1623     inParams.append(
1624         CIMParamValue(PARAM_PROPERTYVALUE, CIMValue(propValue)));
1625
1626     inParams.append(
1627         CIMParamValue(
1628             PARAM_RESETVALUE,
1629             CIMValue(isUnsetOperation)));
1630
1631     inParams.append(
1632         CIMParamValue(
1633             PARAM_UPDATEPLANNEDVALUE,
1634             CIMValue(_plannedValueSet)));
1635
1636     inParams.append(
1637         CIMParamValue(
1638             PARAM_UPDATECURRENTVALUE,
1639             CIMValue(_currentValueSet)));
1640
1641     inParams.append(
1642         CIMParamValue(
1643             PARAM_TIMEOUTPERIOD,
1644             CIMValue(_timeoutSeconds)));
1645
1646     // Set timeout and add some grace time.
1647     _client->setTimeout( (_timeoutSeconds + 10) * 1000);
1648
1649     _client->invokeMethod(
1650         PEGASUS_NAMESPACENAME_CONFIG,
1651         reference,
1652         METHOD_UPDATE_PROPERTY_VALUE,
1653         inParams,
1654         outParams);
1655 }
1656
1657
1658 /**
1659     get a list of all property names and value from the CIM Server.
1660  */
1661 void CIMConfigCommand::_listAllPropertiesInCIMServer
1662     (
1663     ostream&    outPrintWriter,
1664     ostream&    errPrintWriter,
1665     Array <CIMName>&   propNames,
1666     Array <String>&   propValues
1667     )
1668 {
1669     Array<CIMInstance> configNamedInstances;
1670
1671     if ( _currentValueSet ||  _plannedValueSet )
1672     {
1673         //
1674         // get all the instances of class PG_ConfigSetting
1675         //
1676         configNamedInstances =
1677             _client->enumerateInstances(
1678                 PEGASUS_NAMESPACENAME_CONFIG,
1679                 PEGASUS_CLASSNAME_CONFIGSETTING);
1680
1681         //
1682         // copy all the property names and values
1683         //
1684         for (Uint32 i = 0; i < configNamedInstances.size(); i++)
1685         {
1686             CIMInstance& configInstance =
1687                 configNamedInstances[i];
1688
1689             Uint32 pos = configInstance.findProperty
1690                 (CIMName ("PropertyName"));
1691             CIMProperty prop = (CIMProperty)configInstance.getProperty(pos);
1692             propNames.append(prop.getValue().toString());
1693
1694             if (_currentValueSet)
1695             {
1696                 //
1697                 // get current value
1698                 //
1699                 pos = configInstance.findProperty(CIMName ("CurrentValue"));
1700                 prop = (CIMProperty)configInstance.getProperty(pos);
1701                 propValues.append(prop.getValue().toString());
1702             }
1703             else if (_plannedValueSet)
1704             {
1705                 //
1706                 // get planned value
1707                 //
1708                 pos = configInstance.findProperty(CIMName ("PlannedValue"));
1709                 prop = (CIMProperty)configInstance.getProperty(pos);
1710                 propValues.append(prop.getValue().toString());
1711             }
1712         }
1713     }
1714     else
1715     {
1716         //
1717         // call enumerateInstanceNames
1718         //
1719         Array<CIMObjectPath> instanceNames =
1720             _client->enumerateInstanceNames(
1721                 PEGASUS_NAMESPACENAME_CONFIG,
1722                 PEGASUS_CLASSNAME_CONFIGSETTING);
1723         //
1724         // copy all the property names
1725         //
1726         for (Uint32 i = 0; i < instanceNames.size(); i++)
1727         {
1728             Array<CIMKeyBinding> kbArray =
1729                 instanceNames[i].getKeyBindings();
1730
1731             if (kbArray.size() > 0)
1732             {
1733                 propNames.append(kbArray[0].getValue());
1734             }
1735         }
1736      }
1737 }
1738
1739 PEGASUS_NAMESPACE_END
1740
1741 //
1742 // exclude main from the Pegasus Namespace
1743 //
1744 PEGASUS_USING_PEGASUS;
1745
1746 PEGASUS_USING_STD;
1747
1748 ///////////////////////////////////////////////////////////////////////////////
1749 /**
1750     Parses the command line, and execute the command.
1751
1752     @param   args  the string array containing the command line arguments
1753 */
1754 ///////////////////////////////////////////////////////////////////////////////
1755
1756 int main (int argc, char* argv [])
1757 {
1758 #ifdef PEGASUS_OS_PASE
1759     // Allow user group name larger than 8 chars in PASE environemnt
1760     setenv("PASE_USRGRP_LIMITED","N",1);
1761 #endif
1762     AutoPtr<CIMConfigCommand> command;
1763     Uint32               returnCode;
1764
1765     //l10n set message loading to process locale
1766     MessageLoader::_useProcessLocale = true;
1767     MessageLoader::setPegasusMsgHomeRelative(argv[0]);
1768
1769 #ifdef PEGASUS_OS_PASE
1770     // Check special authorities in PASE environment
1771     if (!umeCheckCmdAuthorities(false))
1772         return Command::RC_ERROR;
1773 #endif
1774
1775 #ifdef PEGASUS_OS_ZOS
1776     // for z/OS set stdout and stderr to EBCDIC
1777     setEBCDICEncoding(STDOUT_FILENO);
1778     setEBCDICEncoding(STDERR_FILENO);
1779 #endif
1780
1781     command.reset(new CIMConfigCommand ());
1782
1783     try
1784     {
1785         command->setCommand (argc, argv);
1786     }
1787     catch (const CommandFormatException& cfe)
1788     {
1789         cerr << COMMAND_NAME << ": " << cfe.getMessage() << endl;
1790
1791         MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE);
1792         parms.msg_src_path = MSG_PATH;
1793         cerr << COMMAND_NAME <<
1794             ": " << MessageLoader::getMessage(parms) << endl;
1795         exit (Command::RC_ERROR);
1796     }
1797
1798     returnCode = command->execute (cout, cerr);
1799     command.reset();
1800
1801     exit (returnCode);
1802     return 0;
1803 }