1 karl 1.41 //%2006////////////////////////////////////////////////////////////////////////
|
2 karl 1.25 //
|
3 karl 1.30 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.25 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.30 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.36 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.41 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 karl 1.25 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.41 //
|
21 karl 1.25 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
|
31 a.arora 1.29 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/Constants.h>
36 #include <iostream>
37 #include <Clients/cliutils/Command.h>
38 #include <Clients/cliutils/CommandException.h>
39 #include <Pegasus/getoopt/getoopt.h>
40 #include <Pegasus/Client/CIMClient.h>
41 #include <Pegasus/Common/CIMProperty.h>
42 #include <Pegasus/Common/CIMObjectPath.h>
43 #include <Pegasus/Common/CIMStatusCode.h>
44 #include <Pegasus/Common/String.h>
45 #include <Pegasus/Common/System.h>
46 #include <Pegasus/Common/PegasusVersion.h>
47 #include <Pegasus/Common/AutoPtr.h>
48
49 PEGASUS_USING_STD;
50
51 PEGASUS_NAMESPACE_BEGIN
52 a.arora 1.29
53 //l10n
54 /**
55 * The CLI message resource name
56 */
57
|
58 kumpf 1.38 static const char MSG_PATH [] = "pegasus/pegasusCLI";
|
59 a.arora 1.29
60 /**
61 The command name.
62 */
63 static const char COMMAND_NAME [] = "cimuser";
64
65 /**
66 This constant represents the name of the User name property in the schema
67 */
68 static const CIMName PROPERTY_NAME_USER_NAME = CIMName ("Username");
69
70 /**
71 This constant represents the name of the Password property in the schema
72 */
73 static const CIMName PROPERTY_NAME_PASSWORD = CIMName ("Password");
74
75 /**
76 The usage string for this command. This string is displayed
77 when an error occurs in parsing or validating the command line.
78 */
|
79 alagaraja 1.31 static const char USAGE [] = "Usage: ";
|
80 a.arora 1.29
81 /**
82 This constant represents the getoopt argument designator
83 */
84 static const char GETOPT_ARGUMENT_DESIGNATOR = ':';
85
86 /*
87 These constants represent the operation modes supported by the CLI.
88 Any new operation should be added here.
89 */
90
91 /**
92 This constant signifies that an operation option has not been recorded
93 */
94 static const Uint32 OPERATION_TYPE_UNINITIALIZED = 0;
95
96 /**
97 This constant represents a add user operation
98 */
99 static const Uint32 OPERATION_TYPE_ADD = 1;
100
101 a.arora 1.29 /**
102 This constant represents a add user operation
103 */
104 static const Uint32 OPERATION_TYPE_MODIFY = 2;
105
106 /**
107 This constant represents a remove user operation
108 */
109 static const Uint32 OPERATION_TYPE_REMOVE = 3;
110
111 /**
112 This constant represents a list operation
113 */
114 static const Uint32 OPERATION_TYPE_LIST = 4;
115
|
116 alagaraja 1.31 /**
117 This constant represents a help operation
118 */
119 static const Uint32 OPERATION_TYPE_HELP = 5;
120
121 /**
122 This constant represents a version display operation
123 */
124 static const Uint32 OPERATION_TYPE_VERSION = 6;
|
125 a.arora 1.29
126 /**
127 The constants representing the messages.
128 */
129
130 //l10n
131
|
132 kumpf 1.38 static const char NOT_PRIVILEGED_USER [] =
133 "You must have superuser privilege to run this command.";
|
134 a.arora 1.29
|
135 kumpf 1.38 static const char NOT_PRIVILEGED_USER_KEY [] =
136 "Clients.cimuser.CIMUserCommand.NOT_PRIVILEGED_USER";
|
137 a.arora 1.29
|
138 kumpf 1.38 static const char CIMOM_NOT_RUNNING [] =
139 "CIM Server may not be running.";
|
140 a.arora 1.29
|
141 kumpf 1.38 static const char CIMOM_NOT_RUNNING_KEY [] =
142 "Clients.cimuser.CIMUserCommand.CIMOM_NOT_RUNNING";
|
143 a.arora 1.29
|
144 kumpf 1.38 static const char ADD_USER_FAILURE [] =
145 "Failed to add user.";
|
146 a.arora 1.29
|
147 kumpf 1.38 static const char ADD_USER_FAILURE_KEY [] =
148 "Clients.cimuser.CIMUserCommand.ADD_USER_FAILURE";
|
149 a.arora 1.29
|
150 kumpf 1.38 static const char REMOVE_USER_FAILURE [] =
151 "Failed to remove user.";
|
152 a.arora 1.29
|
153 kumpf 1.38 static const char REMOVE_USER_FAILURE_KEY [] =
154 "Clients.cimuser.CIMUserCommand.REMOVE_USER_FAILURE";
|
155 a.arora 1.29
|
156 kumpf 1.38 static const char CHANGE_PASSWORD_FAILURE [] =
157 "Failed to change password.";
|
158 a.arora 1.29
|
159 kumpf 1.38 static const char CHANGE_PASSWORD_FAILURE_KEY [] =
160 "Clients.cimuser.CIMUserCommand.CHANGE_PASSWORD_FAILURE";
|
161 a.arora 1.29
|
162 kumpf 1.38 static const char LIST_USERS_FAILURE [] =
163 "Failed to list the users. ";
|
164 a.arora 1.29
|
165 kumpf 1.38 static const char LIST_USERS_FAILURE_KEY [] =
166 "Clients.cimuser.CIMUserCommand.LIST_USERS_FAILURE";
|
167 a.arora 1.29
|
168 kumpf 1.38 static const char ADD_USER_SUCCESS [] =
169 "User added successfully.";
|
170 a.arora 1.29
|
171 kumpf 1.38 static const char ADD_USER_SUCCESS_KEY [] =
172 "Clients.cimuser.CIMUserCommand.ADD_USER_SUCCESS";
|
173 a.arora 1.29
|
174 kumpf 1.38 static const char REMOVE_USER_SUCCESS[] =
175 "User removed successfully.";
|
176 a.arora 1.29
|
177 kumpf 1.38 static const char REMOVE_USER_SUCCESS_KEY[] =
178 "Clients.cimuser.CIMUserCommand.REMOVE_USER_SUCCESS";
|
179 a.arora 1.29
|
180 kumpf 1.38 static const char CHANGE_PASSWORD_SUCCESS [] =
181 "Password changed successfully.";
|
182 a.arora 1.29
|
183 kumpf 1.38 static const char CHANGE_PASSWORD_SUCCESS_KEY [] =
184 "Clients.cimuser.CIMUserCommand.CHANGE_PASSWORD_SUCCESS";
|
185 a.arora 1.29
|
186 kumpf 1.38 static const char PASSWORD_BLANK [] =
187 "Password cannot be blank. Please re-enter your password.";
|
188 a.arora 1.29
|
189 kumpf 1.38 static const char PASSWORD_BLANK_KEY [] =
190 "Clients.cimuser.CIMUserCommand.PASSWORD_BLANK";
|
191 a.arora 1.29
192 static const char NO_USERS_FOUND[] =
|
193 kumpf 1.38 "No users found for listing.";
|
194 a.arora 1.29
|
195 kumpf 1.38 static const char NO_USERS_FOUND_KEY[] =
196 "Clients.cimuser.CIMUserCommand.NO_USERS_FOUND";
|
197 a.arora 1.29
|
198 kumpf 1.38 static const char AUTH_SCHEMA_NOT_LOADED [] =
|
199 a.arora 1.29 "Please restore the internal repository on the CIM Server.";
200
|
201 kumpf 1.38 static const char AUTH_SCHEMA_NOT_LOADED_KEY [] =
202 "Clients.cimuser.CIMUserCommand.AUTH_SCHEMA_NOT_LOADED";
|
203 a.arora 1.29
|
204 kumpf 1.38 static const char REQUIRED_ARGS_MISSING [] =
205 "Required arguments missing.";
|
206 a.arora 1.29
|
207 kumpf 1.38 static const char REQUIRED_ARGS_MISSING_KEY [] =
208 "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
|
209 a.arora 1.29
|
210 kumpf 1.38 static const char INVALID_ARGS [] =
211 "Invalid arguments.";
|
212 a.arora 1.29
|
213 kumpf 1.38 static const char INVALID_ARGS_KEY [] =
214 "Clients.cimuser.CIMUserCommand.INVALID_ARGS";
|
215 a.arora 1.29
|
216 kumpf 1.38 static const char USER_ALREADY_EXISTS [] =
217 "Specified user name already exist.";
|
218 a.arora 1.29
|
219 kumpf 1.38 static const char USER_ALREADY_EXISTS_KEY [] =
220 "Clients.cimuser.CIMUserCommand.USER_ALREADY_EXISTS";
|
221 a.arora 1.29
|
222 kumpf 1.38 static const char USER_NOT_FOUND [] =
223 "Specified user name was not found.";
|
224 a.arora 1.29
|
225 kumpf 1.38 static const char USER_NOT_FOUND_KEY [] =
226 "Clients.cimuser.CIMUserCommand.USER_NOT_FOUND";
|
227 a.arora 1.29
|
228 kumpf 1.38 static const char USERNAME_REQUIRED [] =
229 "User name is required.";
|
230 a.arora 1.29
|
231 kumpf 1.38 static const char USERNAME_REQUIRED_KEY [] =
232 "Clients.cimuser.CIMUserCommand.USERNAME_REQUIRED";
|
233 a.arora 1.29
234 /**
235 The option character used to specify add user.
236 */
237 static const char OPTION_ADD = 'a';
238
239 /**
240 The option character used to specify modify user.
241 */
242 static const char OPTION_MODIFY = 'm';
243
244 /**
245 The option character used to specify user name.
246 */
247 static const char OPTION_USER_NAME = 'u';
248
249 /**
250 The option character used to specify password.
251 */
252 static const char OPTION_PASSWORD = 'w';
253
254 a.arora 1.29 /**
255 The option character used to specify new password.
256 */
257 static const char OPTION_NEW_PASSWORD = 'n';
258
259 /**
260 The option character used to specify remove user.
261 */
262 static const char OPTION_REMOVE = 'r';
263
264 /**
265 The option character used to specify listing of users.
266 */
267 static const char OPTION_LIST = 'l';
268
269 /**
|
270 alagaraja 1.31 The option character used to display help info.
271 */
272 static const char OPTION_HELP = 'h';
273
274 /**
275 The option character used to display version info.
276 */
277 static const char OPTION_VERSION = 'v';
278
279 /**
|
280 a.arora 1.29 The name of the Method that implements modify password
281 */
282 static const CIMName MODIFY_METHOD = CIMName ("modifyPassword");
283
284 /**
|
285 kumpf 1.38 The input parameter name for old password
|
286 a.arora 1.29 */
287 static const char OLD_PASS_PARAM[] = "OldPassword";
288
289 /**
|
290 kumpf 1.38 The input parameter name for new password
|
291 a.arora 1.29 */
292 static const char NEW_PASS_PARAM[] = "NewPassword";
293
294
295 static const char PASSWORD_PROMPT [] =
296 "Please enter your password: ";
297
298 static const char PASSWORD_PROMPT_KEY [] = "Clients.cimuser.CIMUserCommand.PASSWORD_PROMPT";
299
300 static const char OLD_PASSWORD_PROMPT [] =
301 "Please enter your old password: ";
302
303 static const char OLD_PASSWORD_PROMPT_KEY [] ="Clients.cimuser.CIMUserCommand.OLD_PASSWORD_PROMPT";
304
305 static const char RE_ENTER_PROMPT [] =
306 "Please re-enter your password: ";
307
308 static const char RE_ENTER_PROMPT_KEY [] ="Clients.cimuser.CIMUserCommand.RE_ENTER_PROMPT";
309
310 static const char NEW_PASSWORD_PROMPT [] =
311 "Please enter your new password: ";
312 a.arora 1.29
313 static const char NEW_PASSWORD_PROMPT_KEY [] ="Clients.cimuser.CIMUserCommand.NEW_PASSWORD_PROMPT";
314
315 static const char PASSWORD_DOES_NOT_MATCH [] =
316 "Passwords do not match. Please Re-enter.";
317
318 static const char PASSWORD_DOES_NOT_MATCH_KEY [] = "Clients.cimuser.CIMUserCommand.PASSWORD_DOES_NOT_MATCH";
319
320 static const char PASSWORD_SAME_ERROR [] =
321 "Error, new and old passwords cannot be same.";
|
322 kumpf 1.38
|
323 a.arora 1.29 static const char PASSWORD_SAME_ERROR_KEY [] = "Clients.cimuser.CIMUserCommand.PASSWORD_SAME_ERROR";
|
324 alagaraja 1.31
|
325 joyce.j 1.37 static const char ERR_OPTION_NOT_SUPPORTED [] = "Invalid option. Use '--help' to obtain command syntax.";
326
327 static const char ERR_OPTION_NOT_SUPPORTED_KEY [] = "Clients.cimuser.CIMUserCommand.ERR_OPTION_NOT_SUPPORTED";
328
329 static const char ERR_USAGE [] = "Incorrect usage. Use '--help' to obtain command syntax.";
330
331 static const char ERR_USAGE_KEY [] = "Clients.cimuser.CIMUserCommand.ERR_USAGE";
332
|
333 alagaraja 1.31 static const char LONG_HELP [] = "help";
334
335 static const char LONG_VERSION [] = "version";
|
336 a.arora 1.29 /**
|
337 kumpf 1.38 This is a CLI used to manage users of the CIM Server. This command supports
338 operations to add, modify, list and remove users.
|
339 a.arora 1.29
340 @author Sushma Fernandes, Hewlett-Packard Company
341 */
342
|
343 kumpf 1.38 class CIMUserCommand : public Command
|
344 a.arora 1.29 {
345
346 public:
347
|
348 kumpf 1.38 /**
|
349 a.arora 1.29 Constructs a CIMUserCommand and initializes instance variables.
350 */
|
351 chuck 1.26 CIMUserCommand ();
352
|
353 kumpf 1.38
|
354 a.arora 1.29 //
355 // Overrides the virtual function setCommand from Command class
|
356 kumpf 1.38 // This is defined as an empty function.
|
357 a.arora 1.29 //
358 void setCommand (
|
359 kumpf 1.38 Uint32 argc,
360 char* argv[])
|
361 a.arora 1.29 {
|
362 kumpf 1.38 // Empty function
|
363 a.arora 1.29 }
364
365 /**
|
366 kumpf 1.38 Parses the command line, validates the options, and sets instance
|
367 a.arora 1.29 variables based on the option arguments. This implementation of
|
368 kumpf 1.38 setCommand includes the parameters for output and error stream.
|
369 a.arora 1.29
370 @param ostream The stream to which command output is written.
371 @param ostream The stream to which command errors are written.
372 @param args The string array containing the command line arguments
373 @param argc The int containing the arguments count
374
375 @throws CommandFormatException if an error is encountered in parsing
376 the command line
377 */
378 void setCommand (
|
379 kumpf 1.38 ostream& outPrintWriter,
380 ostream& errPrintWriter,
381 Uint32 argc,
382 char* argv[]);
|
383 a.arora 1.29
384 /**
385 Executes the command and writes the results to the output streams.
386
387 @param ostream The stream to which command output is written.
388 @param ostream The stream to which command errors are written.
389 @return 0 if the command is successful
390 1 if an error occurs in executing the command
391 */
|
392 kumpf 1.38 Uint32 execute (
393 ostream& outPrintWriter,
394 ostream& errPrintWriter);
|
395 a.arora 1.29
396
397 private:
398
399 //
400 // Add a new user to the CIM Server
401 //
402 // @param ostream The stream to which command output is written.
403 // @param ostream The stream to which command errors are written.
|
404 kumpf 1.38 //
|
405 a.arora 1.29 // @exception Exception if failed to add user
406 //
407 void _AddUser
408 (
|
409 kumpf 1.38 ostream& outPrintWriter,
410 ostream& errPrintWriter
411 );
|
412 a.arora 1.29
413 //
414 // Modify an existing user's password.
415 //
416 // @param ostream The stream to which command output is written.
417 // @param ostream The stream to which command errors are written.
|
418 kumpf 1.38 //
|
419 a.arora 1.29 // @exception Exception if failed to modify password
420 //
421 void _ModifyUser
422 (
423 ostream& outPrintWriter,
424 ostream& errPrintWriter
425 );
426
427 //
|
428 kumpf 1.38 // Remove an existing user from the CIM Server
429 //
|
430 a.arora 1.29 // @param ostream The stream to which command output is written.
431 // @param ostream The stream to which command errors are written.
432 //
433 // @exception Exception if failed to remove user
434 //
435 void _RemoveUser
436 (
|
437 kumpf 1.38 ostream& outPrintWriter,
438 ostream& errPrintWriter
439 );
|
440 a.arora 1.29
441 //
|
442 kumpf 1.38 // List all users.
443 //
|
444 a.arora 1.29 // @param ostream The stream to which command output is written.
445 // @param ostream The stream to which command errors are written.
446 //
447 void _ListUsers
448 (
|
449 kumpf 1.38 ostream& outPrintWriter,
450 ostream& errPrintWriter
|
451 a.arora 1.29 );
452
453 //
454 // The CIM Client reference
455 //
456
|
457 kumpf 1.38 AutoPtr<CIMClient> _client; //PEP101
|
458 a.arora 1.29
459 //
|
460 kumpf 1.38 // The host name.
|
461 a.arora 1.29 //
|
462 kumpf 1.38 String _hostName;
|
463 a.arora 1.29
464 //
465 // The name of the user.
466 //
|
467 kumpf 1.38 String _userName;
|
468 a.arora 1.29
469 //
|
470 kumpf 1.38 // The password of the user.
|
471 a.arora 1.29 //
|
472 kumpf 1.38 String _password;
|
473 a.arora 1.29
474 //
|
475 kumpf 1.38 // The new password of the user.
|
476 a.arora 1.29 //
|
477 kumpf 1.38 String _newpassword;
|
478 a.arora 1.29
479 //
|
480 kumpf 1.38 // The type of operation specified on the command line.
|
481 a.arora 1.29 //
|
482 kumpf 1.38 Uint32 _operationType;
|
483 a.arora 1.29
484 //
485 // Flags for command options
486 //
|
487 kumpf 1.38 Boolean _userNameSet;
488 Boolean _passwordSet;
489 Boolean _newpasswordSet;
|
490 a.arora 1.29
|
491 alagaraja 1.31 String usage;
492
|
493 a.arora 1.29 };
494
495 /**
496 Constructs a CIMUserCommand and initializes instance variables.
497 */
498 CIMUserCommand::CIMUserCommand ()
499 {
500 /**
501 Initialize the instance variables.
502 */
503 _operationType = OPERATION_TYPE_UNINITIALIZED;
504 _passwordSet = false;
505 _newpasswordSet = false;
|
506 chuck 1.26 _userNameSet = false;
|
507 kumpf 1.38
|
508 a.arora 1.29 /**
|
509 kumpf 1.38 Build the usage string for the config command.
|
510 a.arora 1.29 */
511 usage.reserveCapacity(200);
512 usage.append(USAGE);
513 usage.append(COMMAND_NAME);
514
|
515 a.arora 1.32 usage.append(" -").append(OPTION_ADD);
|
516 a.arora 1.29 usage.append(" -").append(OPTION_USER_NAME).append(" username");
517 usage.append(" [ -").append(OPTION_PASSWORD).append(" password")
|
518 a.arora 1.32 .append(" ] \n");
|
519 a.arora 1.29
|
520 a.arora 1.32 usage.append(" -").append(OPTION_MODIFY);
|
521 a.arora 1.29 usage.append(" -").append(OPTION_USER_NAME).append(" username");
|
522 a.arora 1.32 usage.append(" [ -").append(OPTION_PASSWORD).append(" old password")
|
523 a.arora 1.29 .append(" ]");
|
524 a.arora 1.32 usage.append(" [ -").append(OPTION_NEW_PASSWORD).append(" new password")
525 .append(" ] \n");
|
526 a.arora 1.29
|
527 a.arora 1.32 usage.append(" -").append(OPTION_REMOVE);
528 usage.append(" -").append(OPTION_USER_NAME).append(" username \n");
|
529 a.arora 1.29
|
530 a.arora 1.32 usage.append(" -").append(OPTION_LIST).append(" \n");
531 usage.append(" -").append(OPTION_HELP).append(" \n");
532 usage.append(" --").append(LONG_HELP).append(" \n");
533 usage.append(" --").append(LONG_VERSION).append(" \n");
|
534 alagaraja 1.31
535
536 usage.append("Options : \n");
537 usage.append(" -a - Add a new CIM user\n");
538 usage.append(" -h, --help - Display this help message\n");
539 usage.append(" -l - List the names of CIM users\n");
540 usage.append(" -m - Modify a CIM user's password\n");
541 usage.append(" -n - Supply a new password for the specified user name\n");
542 usage.append(" -r - Remove the specified CIM user\n");
543 usage.append(" -u - Specify a CIM user name\n");
544 usage.append(" --version - Display CIM Server version number\n");
545 usage.append(" -w - Supply a password for the specified user name\n");
|
546 kumpf 1.38
|
547 alagaraja 1.31 usage.append("\nUsage note: The cimuser command requires that the CIM Server is running.\n");
|
548 a.arora 1.29 setUsage (usage);
549 }
|
550 chuck 1.26
551 /**
|
552 kumpf 1.38 Parses the command line, validates the options, and sets instance
|
553 a.arora 1.29 variables based on the option arguments.
|
554 chuck 1.26 */
|
555 a.arora 1.29 void CIMUserCommand::setCommand (
|
556 kumpf 1.38 ostream& outPrintWriter,
557 ostream& errPrintWriter,
558 Uint32 argc,
559 char* argv[])
|
560 chuck 1.26 {
|
561 a.arora 1.29 Uint32 i = 0;
562 Uint32 c = 0;
563 String badOptionString = String ();
564 String optString = String ();
565
566 //
567 // Construct optString
568 //
569 optString.append(OPTION_ADD);
570 optString.append(OPTION_USER_NAME);
571 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
572 optString.append(OPTION_PASSWORD);
573 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
574 optString.append(OPTION_MODIFY);
575 optString.append(OPTION_USER_NAME);
576 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
577 optString.append(OPTION_PASSWORD);
578 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
579 optString.append(OPTION_NEW_PASSWORD);
580 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
581 optString.append(OPTION_REMOVE);
582 a.arora 1.29 optString.append(OPTION_USER_NAME);
583 optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
584 optString.append(OPTION_LIST);
|
585 alagaraja 1.31 optString.append(OPTION_HELP);
|
586 a.arora 1.29
587 //
588 // Initialize and parse options
589 //
590 getoopt options ("");
591 options.addFlagspec(optString);
592
|
593 alagaraja 1.31 //PEP#167 - adding long flag for options : 'help' and 'version'
594 options.addLongFlagspec(LONG_HELP,getoopt::NOARG);
595 options.addLongFlagspec(LONG_VERSION,getoopt::NOARG);
596
597
|
598 a.arora 1.29 options.parse (argc, argv);
599 if (options.hasErrors ())
600 {
|
601 kumpf 1.38 throw CommandFormatException(options.getErrorStrings()[0]);
|
602 a.arora 1.29 }
603 _operationType = OPERATION_TYPE_UNINITIALIZED;
604
605 //
606 // Get options and arguments from the command line
607 //
608 for (i = options.first (); i < options.last (); i++)
609 {
|
610 a.arora 1.34 if (options[i].getType () == Optarg::LONGFLAG)
|
611 a.arora 1.29 {
|
612 a.arora 1.34 if (options[i].getopt () == LONG_HELP)
613 {
614 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
615 {
616 String param = String (LONG_HELP);
617 //
618 // More than one operation option was found
619 //
|
620 kumpf 1.38 throw UnexpectedOptionException(param);
|
621 a.arora 1.34 }
|
622 alagaraja 1.31
623 _operationType = OPERATION_TYPE_HELP;
|
624 a.arora 1.34 }
625 else if (options[i].getopt () == LONG_VERSION)
626 {
627 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
628 {
629 String param = String (LONG_VERSION);
630 //
631 // More than one operation option was found
632 //
|
633 kumpf 1.38 throw UnexpectedOptionException(param);
|
634 a.arora 1.34 }
635
|
636 alagaraja 1.31 _operationType = OPERATION_TYPE_VERSION;
|
637 a.arora 1.34 }
638 }
|
639 a.arora 1.29 else if (options [i].getType () == Optarg::REGULAR)
640 {
641 //
642 // The cimuser command has no non-option argument options
643 //
|
644 kumpf 1.38 throw UnexpectedArgumentException(options[i].Value());
645 }
|
646 a.arora 1.29 else /* if (options [i].getType () == Optarg::FLAG) */
647 {
648
649 c = options [i].getopt () [0];
650
|
651 kumpf 1.38 switch (c)
|
652 a.arora 1.29 {
|
653 kumpf 1.38 case OPTION_ADD:
|
654 a.arora 1.29 {
655 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
656 {
657 //
658 // More than one operation option was found
659 //
|
660 kumpf 1.38 throw UnexpectedOptionException(OPTION_ADD);
|
661 a.arora 1.29 }
662
663 if (options.isSet (OPTION_ADD) > 1)
664 {
665 //
666 // More than one add user option was found
667 //
|
668 kumpf 1.38 throw DuplicateOptionException(OPTION_ADD);
|
669 a.arora 1.29 }
670
671 _operationType = OPERATION_TYPE_ADD;
672
673 break;
674 }
675 case OPTION_MODIFY:
676 {
677 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
678 {
679 //
680 // More than one operation option was found
681 //
|
682 kumpf 1.38 throw UnexpectedOptionException(OPTION_MODIFY);
|
683 a.arora 1.29 }
684
685 if (options.isSet (OPTION_MODIFY) > 1)
686 {
687 //
688 // More than one modify user option was found
689 //
|
690 kumpf 1.38 throw DuplicateOptionException(OPTION_MODIFY);
|
691 a.arora 1.29 }
692
693 _operationType = OPERATION_TYPE_MODIFY;
694
695 break;
696 }
697 case OPTION_USER_NAME:
698 {
699 if (options.isSet (OPTION_USER_NAME) > 1)
700 {
701 //
702 // More than one username option was found
703 //
|
704 kumpf 1.38 throw DuplicateOptionException(OPTION_USER_NAME);
|
705 a.arora 1.29 }
706
707 _userName = options [i].Value ();
708
|
709 kumpf 1.38 _userNameSet = true;
|
710 a.arora 1.29
711 break;
712 }
713 case OPTION_PASSWORD:
714 {
715 if (options.isSet (OPTION_PASSWORD) > 1)
716 {
717 //
718 // More than one password option was found
719 //
|
720 kumpf 1.38 throw DuplicateOptionException(OPTION_PASSWORD);
|
721 a.arora 1.29 }
722
723 String password = options [i].Value ();
724 _password = password.subString(0,8);
725
|
726 kumpf 1.38 _passwordSet = true;
|
727 a.arora 1.29
728 break;
729 }
730 case OPTION_NEW_PASSWORD:
731 {
732 if (options.isSet (OPTION_NEW_PASSWORD) > 1)
733 {
734 //
735 // More than one new password option was found
736 //
|
737 kumpf 1.38 throw DuplicateOptionException(OPTION_NEW_PASSWORD);
|
738 a.arora 1.29 }
739
740 String newpassword = options [i].Value ();
741 _newpassword = newpassword.subString(0,8);
742
|
743 kumpf 1.38 _newpasswordSet = true;
|
744 a.arora 1.29
745 break;
746 }
|
747 kumpf 1.38 case OPTION_REMOVE:
|
748 a.arora 1.29 {
749 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
750 {
751 //
752 // More than one operation option was found
753 //
|
754 kumpf 1.38 throw UnexpectedOptionException(OPTION_REMOVE);
|
755 a.arora 1.29 }
756
757 if (options.isSet (OPTION_REMOVE) > 1)
758 {
759 //
760 // More than one remove user option was found
761 //
|
762 kumpf 1.38 throw DuplicateOptionException(OPTION_REMOVE);
|
763 a.arora 1.29 }
764
765 _operationType = OPERATION_TYPE_REMOVE;
766
767 break;
768 }
769
|
770 kumpf 1.38 case OPTION_LIST:
|
771 a.arora 1.29 {
772 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
773 {
774 //
775 // More than one operation option was found
776 //
|
777 kumpf 1.38 throw UnexpectedOptionException(OPTION_LIST);
|
778 a.arora 1.29 }
779
780 if (options.isSet (OPTION_LIST) > 1)
781 {
782 //
783 // More than one list option was found
784 //
|
785 kumpf 1.38 throw DuplicateOptionException(OPTION_LIST);
|
786 a.arora 1.29 }
787 _operationType = OPERATION_TYPE_LIST;
788 break;
789 }
|
790 alagaraja 1.31 //PEP#167 - 2 new cases added below for HELP and VERSION
|
791 kumpf 1.38 case OPTION_HELP:
|
792 alagaraja 1.31 {
793 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
794 {
795 //
796 // More than one operation option was found
797 //
|
798 kumpf 1.38 throw UnexpectedOptionException(OPTION_HELP);
|
799 alagaraja 1.31 }
800
801 if (options.isSet (OPTION_HELP) > 1)
802 {
803 //
804 // More than one list option was found
805 //
|
806 kumpf 1.38 throw DuplicateOptionException(OPTION_HELP);
|
807 alagaraja 1.31 }
808 _operationType = OPERATION_TYPE_HELP;
809 break;
810 }
|
811 kumpf 1.38 case OPTION_VERSION:
|
812 alagaraja 1.31 {
813 if (_operationType != OPERATION_TYPE_UNINITIALIZED)
814 {
815 //
816 // More than one operation option was found
817 //
|
818 kumpf 1.38 throw UnexpectedOptionException(OPTION_VERSION);
|
819 alagaraja 1.31 }
820
821 if (options.isSet (OPTION_VERSION) > 1)
822 {
823 //
824 // More than one list option was found
825 //
|
826 kumpf 1.38 throw DuplicateOptionException(OPTION_VERSION);
|
827 alagaraja 1.31 }
828 _operationType = OPERATION_TYPE_VERSION;
829 break;
830 }
|
831 a.arora 1.29
832 default:
|
833 kumpf 1.38 {
834 //
835 // Should never get here
836 //
837 break;
|
838 a.arora 1.29 }
839 }
840 }
841 }
842
|
843 kumpf 1.38 //
|
844 a.arora 1.29 // Some more validations
845 //
|
846 kumpf 1.38 if (_operationType == OPERATION_TYPE_UNINITIALIZED)
|
847 a.arora 1.29 {
848 //
|
849 kumpf 1.38 // No operation type was specified
850 // Show the usage
|
851 a.arora 1.29 //
|
852 kumpf 1.38 //l10n
853 //CommandFormatException e (REQUIRED_ARGS_MISSING);
854 throw CommandFormatException(localizeMessage(
855 MSG_PATH, REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING));
856 }
857
858 if (_operationType == OPERATION_TYPE_LIST &&
859 (_userNameSet || _passwordSet || _newpasswordSet))
860 {
861 //l10n
862 MessageLoaderParms parms("Clients.cimuser.CIMUserCommand.UNEXPECTED_OPTION",
863 "Unexpected Option.");
864 //CommandFormatException e("Unexpected Option.");
865 throw CommandFormatException(parms);
|
866 a.arora 1.29 }
|
867 kumpf 1.38
|
868 a.arora 1.29 if (_operationType == OPERATION_TYPE_ADD)
869 {
|
870 kumpf 1.38 if (_newpasswordSet)
871 {
|
872 a.arora 1.29 //
873 // An invalid option was encountered
874 //
|
875 kumpf 1.38 throw UnexpectedOptionException(OPTION_NEW_PASSWORD);
|
876 a.arora 1.29 }
|
877 kumpf 1.38 if (!_userNameSet)
|
878 a.arora 1.29 {
879 //
880 // An invalid option was encountered
881 //
|
882 kumpf 1.38 throw MissingOptionException(OPTION_USER_NAME);
|
883 a.arora 1.29 }
|
884 kumpf 1.38 if (!_passwordSet)
|
885 a.arora 1.29 {
886 //
887 // Password is not set, prompt for the password
888 //
|
889 kumpf 1.42 String pw;
|
890 a.arora 1.29 do
891 {
|
892 kumpf 1.38 pw = System::getPassword(PASSWORD_PROMPT);
|
893 a.arora 1.29
|
894 kumpf 1.42 if (pw == String::EMPTY)
|
895 kumpf 1.38 {
|
896 kumpf 1.42 errPrintWriter << localizeMessage(
897 MSG_PATH, PASSWORD_BLANK_KEY, PASSWORD_BLANK) << endl;
|
898 kumpf 1.38 continue;
|
899 a.arora 1.29 }
|
900 kumpf 1.38 if (pw != System::getPassword(RE_ENTER_PROMPT))
|
901 a.arora 1.29 {
|
902 kumpf 1.42 errPrintWriter <<
903 localizeMessage(
904 MSG_PATH,
905 PASSWORD_DOES_NOT_MATCH_KEY,
906 PASSWORD_DOES_NOT_MATCH_KEY) <<
907 endl;
|
908 kumpf 1.38 pw = String::EMPTY;
|
909 a.arora 1.29 }
910 }
|
911 kumpf 1.38 while (pw == String::EMPTY);
|
912 a.arora 1.29
913 _password = pw ;
914 }
915 }
916
917 if (_operationType == OPERATION_TYPE_MODIFY)
918 {
|
919 kumpf 1.38 if (!_userNameSet)
|
920 a.arora 1.29 {
921 //
922 // An invalid option was encountered
923 //
|
924 kumpf 1.38 throw MissingOptionException(OPTION_USER_NAME);
|
925 a.arora 1.29 }
|
926 kumpf 1.38 if (_passwordSet && _newpasswordSet)
927 {
928 if (_newpassword == _password)
929 {
930 //l10n
931 //cerr << PASSWORD_SAME_ERROR << endl;
932 cerr << localizeMessage(MSG_PATH,PASSWORD_SAME_ERROR_KEY,PASSWORD_SAME_ERROR) << endl;
933 exit (1);
|
934 a.arora 1.29 }
935 }
|
936 kumpf 1.38 if (!_passwordSet)
|
937 a.arora 1.29 {
938 //
939 // Password is not set, prompt for the old password once
940 //
|
941 kumpf 1.42 String pw;
|
942 kumpf 1.38 do
943 {
944 pw = System::getPassword(OLD_PASSWORD_PROMPT);
|
945 kumpf 1.42 if (pw == String::EMPTY)
|
946 kumpf 1.38 {
|
947 kumpf 1.42 errPrintWriter << localizeMessage(
948 MSG_PATH, PASSWORD_BLANK_KEY, PASSWORD_BLANK) << endl;
|
949 kumpf 1.38 continue;
|
950 a.arora 1.29 }
951 }
|
952 kumpf 1.38 while (pw == String::EMPTY);
|
953 a.arora 1.29 _password = pw ;
954 }
|
955 kumpf 1.38 if (!_newpasswordSet)
|
956 a.arora 1.29 {
957 //
958 // Password is not set, prompt for the new password twice
959 //
|
960 kumpf 1.42 String newPw;
|
961 a.arora 1.29 do
962 {
|
963 kumpf 1.38 newPw = System::getPassword(NEW_PASSWORD_PROMPT);
|
964 kumpf 1.42 if (newPw == String::EMPTY)
|
965 kumpf 1.38 {
|
966 kumpf 1.42 errPrintWriter << localizeMessage(
967 MSG_PATH, PASSWORD_BLANK_KEY, PASSWORD_BLANK) << endl;
|
968 kumpf 1.38 continue;
969 }
970
971 if (newPw != System::getPassword(RE_ENTER_PROMPT))
972 {
|
973 kumpf 1.42 errPrintWriter <<
974 localizeMessage(
975 MSG_PATH,
976 PASSWORD_DOES_NOT_MATCH_KEY,
977 PASSWORD_DOES_NOT_MATCH) <<
978 endl;
|
979 kumpf 1.38 newPw = String::EMPTY;
|
980 a.arora 1.29 }
981 }
|
982 kumpf 1.38 while (newPw == String::EMPTY);
|
983 a.arora 1.29 _newpassword = newPw ;
|
984 kumpf 1.38 if (_newpassword == _password)
985 {
|
986 kumpf 1.42 cerr << localizeMessage(
987 MSG_PATH, PASSWORD_SAME_ERROR_KEY, PASSWORD_SAME_ERROR) <<
988 endl;
|
989 a.arora 1.29 exit (-1);
990 }
991 }
992 }
993
994 if (_operationType == OPERATION_TYPE_REMOVE)
995 {
|
996 kumpf 1.38 if (!_userNameSet)
|
997 a.arora 1.29 {
998 //
999 // An invalid option was encountered
1000 //
|
1001 kumpf 1.38 throw MissingOptionException(OPTION_USER_NAME);
|
1002 a.arora 1.29 }
|
1003 kumpf 1.38 if (_passwordSet)
|
1004 a.arora 1.29 {
1005 //
1006 // An invalid option was encountered
1007 //
|
1008 kumpf 1.38 throw UnexpectedOptionException(OPTION_PASSWORD);
|
1009 a.arora 1.29 }
|
1010 kumpf 1.38 if (_newpasswordSet)
|
1011 a.arora 1.29 {
1012 //
1013 // An invalid option was encountered
1014 //
|
1015 kumpf 1.38 throw UnexpectedOptionException(OPTION_NEW_PASSWORD);
|
1016 a.arora 1.29 }
1017 }
|
1018 chuck 1.26 }
|
1019 a.arora 1.29
1020 /**
1021 Executes the command and writes the results to the PrintWriters.
1022 */
1023 Uint32 CIMUserCommand::execute (
|
1024 kumpf 1.38 ostream& outPrintWriter,
|
1025 a.arora 1.29 ostream& errPrintWriter)
1026 {
|
1027 kumpf 1.38 if (_operationType == OPERATION_TYPE_UNINITIALIZED)
|
1028 a.arora 1.29 {
1029 //
1030 // The command was not initialized
1031 //
1032 return 1;
1033 }
|
1034 alagaraja 1.31 //PEP#167 - Added Options HELP and VERSION
1035 //PEP#167 - CIMServer need not be running for these to work
1036 else if (_operationType == OPERATION_TYPE_HELP)
1037 {
1038 cerr << usage << endl;
1039 return (RC_SUCCESS);
1040 }
1041 else if(_operationType == OPERATION_TYPE_VERSION)
1042 {
|
1043 kumpf 1.35 cerr << "Version " << PEGASUS_PRODUCT_VERSION << endl;
|
1044 alagaraja 1.31 return (RC_SUCCESS);
1045 }
|
1046 a.arora 1.29
|
1047 kumpf 1.38 //
|
1048 a.arora 1.29 // Get local host name
1049 //
1050 _hostName.assign(System::getHostName());
|
1051 chuck 1.26
1052 try
1053 {
1054 // Construct the CIMClient and set to request server messages
1055 // in the default language of this client process.
|
1056 a.arora 1.29 _client.reset(new CIMClient);
|
1057 chuck 1.26 _client->setRequestDefaultLanguages(); //l10n
1058 }
1059 catch (Exception & e)
1060 {
1061 errPrintWriter << e.getMessage() << endl;
|
1062 kumpf 1.38 return (RC_ERROR);
|
1063 chuck 1.26 }
|
1064 a.arora 1.29
1065 try
1066 {
1067 //
1068 // Open connection with CIMSever
1069 //
1070 _client->connectLocal();
1071 }
|
1072 david.dillard 1.39 catch(const Exception&)
|
1073 a.arora 1.29 {
|
1074 kumpf 1.38 //l10n
|
1075 a.arora 1.29 //outPrintWriter << CIMOM_NOT_RUNNING << endl;
|
1076 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CIMOM_NOT_RUNNING_KEY,CIMOM_NOT_RUNNING) << endl;
1077 return 1;
|
1078 a.arora 1.29 }
1079
1080 //
1081 // Perform the requested operation
1082 //
|
1083 kumpf 1.38 switch (_operationType)
|
1084 a.arora 1.29 {
1085 case OPERATION_TYPE_ADD:
1086 try
1087 {
|
1088 kumpf 1.38 _AddUser(outPrintWriter, errPrintWriter);
|
1089 a.arora 1.29 }
1090 catch (CIMException& e)
1091 {
1092 CIMStatusCode code = e.getCode();
1093
1094 if (code == CIM_ERR_FAILED)
1095 {
|
1096 kumpf 1.38 //l10n
1097 //outPrintWriter << ADD_USER_FAILURE << endl;
1098 outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl;
|
1099 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1100 }
|
1101 kumpf 1.38 else if (code == CIM_ERR_NOT_SUPPORTED)
1102 {
1103 //l10n
1104 //outPrintWriter << ADD_USER_FAILURE << endl;
1105 outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl;
1106 errPrintWriter << e.getMessage() << endl;
1107 }
1108 else if (code == CIM_ERR_ALREADY_EXISTS)
1109 {
1110 //l10n
1111 //outPrintWriter << ADD_USER_FAILURE << endl;
1112 outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl;
1113 //outPrintWriter << USER_ALREADY_EXISTS << endl;
1114 outPrintWriter << localizeMessage(MSG_PATH,USER_ALREADY_EXISTS_KEY,USER_ALREADY_EXISTS) << endl;
1115 errPrintWriter << e.getMessage() << endl;
1116 }
|
1117 a.arora 1.29 else if (code == CIM_ERR_INVALID_CLASS)
1118 {
|
1119 kumpf 1.38 //l10n
1120 //outPrintWriter << ADD_USER_FAILURE << endl;
1121 outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl;
1122 //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl;
1123 outPrintWriter << localizeMessage(MSG_PATH,AUTH_SCHEMA_NOT_LOADED_KEY,AUTH_SCHEMA_NOT_LOADED) << endl;
|
1124 a.arora 1.29 }
1125 else
1126 {
|
1127 kumpf 1.38 errPrintWriter << e.getMessage() << endl;
|
1128 a.arora 1.29 }
|
1129 kumpf 1.38 return (RC_ERROR);
|
1130 a.arora 1.29 }
1131 catch (Exception& e)
1132 {
|
1133 kumpf 1.38 //l10n
|
1134 a.arora 1.29 //outPrintWriter << ADD_USER_FAILURE << endl <<
1135 //e.getMessage() << endl;
|
1136 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) <<
1137 endl << e.getMessage() << endl;
1138 return (RC_ERROR);
|
1139 a.arora 1.29 }
|
1140 kumpf 1.38 break;
|
1141 a.arora 1.29
1142 case OPERATION_TYPE_MODIFY:
1143 try
1144 {
|
1145 kumpf 1.38 _ModifyUser(outPrintWriter, errPrintWriter);
|
1146 a.arora 1.29 }
1147 catch (CIMException& e)
1148 {
1149 CIMStatusCode code = e.getCode();
1150 if (code == CIM_ERR_FAILED)
1151 {
|
1152 kumpf 1.38 //l10n
|
1153 a.arora 1.29 //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;
|
1154 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;
|
1155 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1156 }
1157 else if (code == CIM_ERR_NOT_SUPPORTED)
1158 {
|
1159 kumpf 1.38 //l10n
|
1160 a.arora 1.29 //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;
|
1161 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;
|
1162 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1163 }
1164 else if (code == CIM_ERR_NOT_FOUND)
1165 {
|
1166 kumpf 1.38 //l10n
|
1167 a.arora 1.29 //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;
|
1168 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;
1169 //outPrintWriter << USER_NOT_FOUND << endl;
1170 outPrintWriter << localizeMessage(MSG_PATH,USER_NOT_FOUND_KEY,USER_NOT_FOUND) << endl;
|
1171 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1172 }
1173 else if (code == CIM_ERR_INVALID_CLASS)
1174 {
|
1175 kumpf 1.38 //l10n
|
1176 a.arora 1.29 //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;
|
1177 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;
|
1178 a.arora 1.29 //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl;
|
1179 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,AUTH_SCHEMA_NOT_LOADED_KEY,AUTH_SCHEMA_NOT_LOADED) << endl;
|
1180 a.arora 1.29 }
1181 else
1182 {
1183 errPrintWriter << e.getMessage() << endl;
1184 }
|
1185 kumpf 1.38 return (RC_ERROR);
|
1186 a.arora 1.29 }
1187 catch (Exception& e)
1188 {
|
1189 kumpf 1.38 //l10n
|
1190 a.arora 1.29 //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl <<
1191 //e.getMessage() << endl;
|
1192 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) <<
1193 endl << e.getMessage() << endl;
1194 return (RC_ERROR);
|
1195 a.arora 1.29 }
1196 break;
1197
1198 case OPERATION_TYPE_REMOVE:
1199 try
1200 {
|
1201 kumpf 1.38 _RemoveUser(outPrintWriter, errPrintWriter);
|
1202 a.arora 1.29 }
1203 catch (CIMException& e)
1204 {
1205 CIMStatusCode code = e.getCode();
1206 if (code == CIM_ERR_FAILED)
1207 {
|
1208 kumpf 1.38 //l10n
|
1209 a.arora 1.29 //outPrintWriter << REMOVE_USER_FAILURE << endl;
|
1210 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;
|
1211 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1212 }
1213 else if (code == CIM_ERR_NOT_SUPPORTED)
1214 {
|
1215 kumpf 1.38 //l10n
|
1216 a.arora 1.29 //outPrintWriter << REMOVE_USER_FAILURE << endl;
|
1217 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;
|
1218 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1219 }
1220 else if (code == CIM_ERR_NOT_FOUND)
1221 {
|
1222 kumpf 1.38 //l10n
|
1223 a.arora 1.29 //outPrintWriter << REMOVE_USER_FAILURE << endl;
|
1224 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;
1225 //outPrintWriter << USER_NOT_FOUND << endl;
1226 outPrintWriter << localizeMessage(MSG_PATH,USER_NOT_FOUND_KEY,USER_NOT_FOUND) << endl;
|
1227 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1228 }
1229 else if (code == CIM_ERR_INVALID_CLASS)
1230 {
|
1231 kumpf 1.38 //l10n
|
1232 a.arora 1.29 //outPrintWriter << REMOVE_USER_FAILURE << endl;
|
1233 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;
|
1234 a.arora 1.29 //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl;
|
1235 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,AUTH_SCHEMA_NOT_LOADED_KEY,AUTH_SCHEMA_NOT_LOADED) << endl;
|
1236 a.arora 1.29 }
1237 else
1238 {
1239 errPrintWriter << e.getMessage() << endl;
1240 }
|
1241 kumpf 1.38 return (RC_ERROR);
|
1242 a.arora 1.29 }
1243 catch (Exception& e)
1244 {
|
1245 kumpf 1.38 //l10n
|
1246 a.arora 1.29 //outPrintWriter << REMOVE_USER_FAILURE << endl <<
1247 //e.getMessage() << endl;
|
1248 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) <<
1249 endl << e.getMessage() << endl;
1250 return (RC_ERROR);
|
1251 a.arora 1.29 }
1252 break;
1253
1254 case OPERATION_TYPE_LIST:
1255 try
1256 {
1257 _ListUsers(outPrintWriter, errPrintWriter);
1258 }
1259 catch (CIMException& e)
1260 {
1261 CIMStatusCode code = e.getCode();
1262 if (code == CIM_ERR_FAILED)
1263 {
|
1264 kumpf 1.38 //l10n
|
1265 a.arora 1.29 //outPrintWriter << LIST_USERS_FAILURE << endl;
|
1266 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;
|
1267 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1268 }
1269 else if (code == CIM_ERR_NOT_SUPPORTED)
1270 {
|
1271 kumpf 1.38 //l10n
|
1272 a.arora 1.29 //outPrintWriter << LIST_USERS_FAILURE << endl;
|
1273 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;
|
1274 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1275 }
1276 else if (code == CIM_ERR_ALREADY_EXISTS)
1277 {
|
1278 kumpf 1.38 //l10n
|
1279 a.arora 1.29 //outPrintWriter << LIST_USERS_FAILURE << endl;
|
1280 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;
|
1281 a.arora 1.29 errPrintWriter << e.getMessage() << endl;
1282 }
1283 else if (code == CIM_ERR_INVALID_CLASS)
1284 {
|
1285 kumpf 1.38 //l10n
|
1286 a.arora 1.29 //outPrintWriter << LIST_USERS_FAILURE << endl;
|
1287 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;
|
1288 a.arora 1.29 //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl;
|
1289 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,AUTH_SCHEMA_NOT_LOADED_KEY,AUTH_SCHEMA_NOT_LOADED) << endl;
|
1290 a.arora 1.29 }
1291 else
1292 {
1293 errPrintWriter << e.getMessage() << endl;
1294 }
|
1295 kumpf 1.38 return (RC_ERROR);
|
1296 a.arora 1.29 }
1297 catch (Exception& e)
1298 {
|
1299 kumpf 1.38 //l10n
|
1300 a.arora 1.29 //outPrintWriter << LIST_USERS_FAILURE << endl <<
1301 //e.getMessage() << endl;
|
1302 kumpf 1.38 outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) <<
1303 endl << e.getMessage() << endl;
1304 return (RC_ERROR);
|
1305 a.arora 1.29 }
1306 break;
1307
1308 default:
1309 //
1310 // Should never get here
1311 //
1312 break;
1313 }
1314
1315 return (RC_SUCCESS);
1316 }
1317
1318 /**
1319 Add the user to the CIM Server.
1320 */
1321 void CIMUserCommand::_AddUser
1322 (
|
1323 kumpf 1.38 ostream& outPrintWriter,
1324 ostream& errPrintWriter
1325 )
|
1326 a.arora 1.29 {
1327 CIMProperty prop;
1328
|
1329 kumpf 1.38 CIMInstance newInstance(PEGASUS_CLASSNAME_USER);
1330 newInstance.addProperty(
1331 CIMProperty(PROPERTY_NAME_USER_NAME, _userName));
1332 newInstance.addProperty(
1333 CIMProperty(PROPERTY_NAME_PASSWORD , _password));
1334
1335 _client->createInstance(PEGASUS_NAMESPACENAME_USER, newInstance);
1336 //l10n
1337 //outPrintWriter << ADD_USER_SUCCESS << endl;
1338 outPrintWriter <<
1339 localizeMessage(MSG_PATH,ADD_USER_SUCCESS_KEY,ADD_USER_SUCCESS) << endl;
|
1340 a.arora 1.29 }
1341
1342 //
1343 // Modify the password for a user
1344 //
1345 void CIMUserCommand::_ModifyUser
1346 (
|
1347 kumpf 1.38 ostream& outPrintWriter,
1348 ostream& errPrintWriter
1349 )
|
1350 a.arora 1.29 {
|
1351 kumpf 1.38 Array<CIMKeyBinding> kbArray;
1352 CIMKeyBinding kb;
1353 Array<CIMParamValue> inParams;
1354 Array<CIMParamValue> outParams;
1355
1356 //
1357 // Build the input params
1358 //
1359 inParams.append(CIMParamValue(OLD_PASS_PARAM,
1360 CIMValue(_password)));
1361 inParams.append(CIMParamValue(NEW_PASS_PARAM,
1362 CIMValue(_newpassword)));
1363
1364 kb.setName(CIMName ("Username"));
1365 kb.setValue(_userName);
1366 kb.setType(CIMKeyBinding::STRING);
1367
1368 kbArray.append(kb);
1369
1370 CIMObjectPath reference(
1371 _hostName, PEGASUS_NAMESPACENAME_USER,
1372 kumpf 1.38 PEGASUS_CLASSNAME_USER, kbArray);
1373
1374 //
1375 // Call the invokeMethod with the input parameters
1376 //
1377
1378 //
1379 // Not checking for return code as all error conditions will
1380 // throw exceptions and will be handled by the catch block. If new
1381 // return codes are added in future, they need to be handled here.
1382 //
1383 CIMValue retValue = _client->invokeMethod(
1384 PEGASUS_NAMESPACENAME_USER,
1385 reference,
1386 MODIFY_METHOD,
1387 inParams,
1388 outParams);
1389 //l10n
1390 //outPrintWriter << CHANGE_PASSWORD_SUCCESS << endl;
1391 outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_SUCCESS_KEY,CHANGE_PASSWORD_SUCCESS) << endl;
|
1392 a.arora 1.29 }
1393
1394 //
|
1395 kumpf 1.38 // Remove a user
|
1396 a.arora 1.29 //
1397 void CIMUserCommand::_RemoveUser
1398 (
|
1399 kumpf 1.38 ostream& outPrintWriter,
1400 ostream& errPrintWriter
1401 )
|
1402 a.arora 1.29 {
|
1403 kumpf 1.38 Array<CIMKeyBinding> kbArray;
1404 CIMKeyBinding kb;
|
1405 a.arora 1.29
|
1406 kumpf 1.38 kb.setName(PROPERTY_NAME_USER_NAME);
1407 kb.setValue(_userName);
1408 kb.setType(CIMKeyBinding::STRING);
1409
1410 kbArray.append(kb);
1411
1412 CIMObjectPath reference(
1413 _hostName, PEGASUS_NAMESPACENAME_USER,
1414 PEGASUS_CLASSNAME_USER, kbArray);
1415
1416 _client->deleteInstance(PEGASUS_NAMESPACENAME_USER, reference);
1417 //l10n
1418 //outPrintWriter << REMOVE_USER_SUCCESS << endl;
1419 outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_SUCCESS_KEY,REMOVE_USER_SUCCESS) << endl;
|
1420 a.arora 1.29 }
1421
1422
1423 /**
1424 get a list of all user names from the CIM Server.
1425 */
1426 void CIMUserCommand::_ListUsers
|
1427 kumpf 1.38 (
1428 ostream& outPrintWriter,
1429 ostream& errPrintWriter
|
1430 a.arora 1.29 )
1431 {
|
1432 kumpf 1.38 //
1433 // get all the instances of class PG_User
1434 //
1435 Array<CIMObjectPath> instanceNames =
1436 _client->enumerateInstanceNames(
1437 PEGASUS_NAMESPACENAME_USER,
1438 PEGASUS_CLASSNAME_USER);
1439
1440 if (instanceNames.size() == 0)
1441 {
1442 //l10n
1443 //outPrintWriter << NO_USERS_FOUND << endl;
1444 outPrintWriter <<
1445 localizeMessage(MSG_PATH,NO_USERS_FOUND_KEY,NO_USERS_FOUND) <<
1446 endl;
1447 }
1448 else
|
1449 a.arora 1.29 {
1450 //
|
1451 kumpf 1.38 // List all the users.
|
1452 a.arora 1.29 //
|
1453 kumpf 1.38 for (Uint32 i = 0; i < instanceNames.size(); i++)
1454 {
1455 Array<CIMKeyBinding> kbArray = instanceNames[i].getKeyBindings();
|
1456 a.arora 1.29
|
1457 kumpf 1.38 if (kbArray.size() > 0)
|
1458 a.arora 1.29 {
|
1459 kumpf 1.38 outPrintWriter << kbArray[0].getValue() << endl;
|
1460 a.arora 1.29 }
1461 }
1462 }
1463 }
1464
1465 PEGASUS_NAMESPACE_END
1466
1467 //
1468 // exclude main from the Pegasus Namespace
1469 //
1470 PEGASUS_USING_PEGASUS;
1471
1472 PEGASUS_USING_STD;
1473
1474 ///////////////////////////////////////////////////////////////////////////////
1475 /**
1476 Parses the command line, and execute the command.
1477
1478 @param args the string array containing the command line arguments
1479 */
1480 ///////////////////////////////////////////////////////////////////////////////
1481 a.arora 1.29
|
1482 kumpf 1.38 int main (int argc, char* argv[])
|
1483 a.arora 1.29 {
1484 AutoPtr<CIMUserCommand> command;
1485 Uint32 retCode;
1486
|
1487 kumpf 1.38 MessageLoader::_useProcessLocale = true; //l10n set message loading to process locale
|
1488 joyce.j 1.40 MessageLoader::setPegasusMsgHomeRelative(argv[0]);
|
1489 a.arora 1.29
1490 //
1491 // Check if root is issuing the command
1492 //
|
1493 kumpf 1.38 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
1494 a.arora 1.29 {
|
1495 joyce.j 1.37 MessageLoaderParms parms(NOT_PRIVILEGED_USER_KEY, NOT_PRIVILEGED_USER);
1496 parms.msg_src_path = MSG_PATH;
1497 cerr << MessageLoader::getMessage(parms) << endl;
1498 return 1;
|
1499 a.arora 1.29 }
|
1500 kumpf 1.38
|
1501 a.arora 1.29 command.reset(new CIMUserCommand ());
1502
|
1503 kumpf 1.38 try
|
1504 a.arora 1.29 {
1505 command->setCommand ( cout, cerr, argc, argv);
|
1506 kumpf 1.38 }
1507 catch (CommandFormatException& cfe)
|
1508 a.arora 1.29 {
|
1509 a.arora 1.33 String msg(cfe.getMessage());
1510
1511 cerr << COMMAND_NAME << ": " << msg << endl;
1512
1513 if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
|
1514 joyce.j 1.37 {
1515 MessageLoaderParms parms(ERR_OPTION_NOT_SUPPORTED_KEY,ERR_OPTION_NOT_SUPPORTED);
1516 parms.msg_src_path = MSG_PATH;
1517 cerr << COMMAND_NAME <<
1518 ": " << MessageLoader::getMessage(parms) << endl;
1519 }
|
1520 a.arora 1.33 else
|
1521 joyce.j 1.37 {
1522 MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE);
1523 parms.msg_src_path = MSG_PATH;
1524 cerr << COMMAND_NAME <<
1525 ": " << MessageLoader::getMessage(parms) << endl;
1526 }
|
1527 alagaraja 1.31
|
1528 a.arora 1.29 return 1;
1529 }
1530
|
1531 chuck 1.26 retCode = command->execute (cout, cerr);
1532
|
1533 kumpf 1.38
|
1534 a.arora 1.29 return (retCode);
1535 }
1536
|