xref: /openbmc/ipmitool/lib/ipmi_user.c (revision 50bd7d01a81ae82626281c470169544e86c360ce)
1 /*
2  * Copyright (c) 2003 Sun Microsystems, Inc.  All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistribution of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistribution in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * Neither the name of Sun Microsystems, Inc. or the names of
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * This software is provided "AS IS," without a warranty of any kind.
20  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23  * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
24  * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25  * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
26  * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27  * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28  * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29  * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  */
32 
33 #include <stdlib.h>
34 #include <string.h>
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <sys/select.h>
38 #include <sys/time.h>
39 #include <signal.h>
40 #include <unistd.h>
41 
42 #include <ipmitool/helper.h>
43 #include <ipmitool/log.h>
44 #include <ipmitool/ipmi.h>
45 #include <ipmitool/ipmi_intf.h>
46 #include <ipmitool/ipmi_user.h>
47 #include <ipmitool/ipmi_constants.h>
48 #include <ipmitool/ipmi_strings.h>
49 #include <ipmitool/bswap.h>
50 
51 
52 extern int verbose;
53 extern int csv_output;
54 
55 
56 #define IPMI_PASSWORD_DISABLE_USER  0x00
57 #define IPMI_PASSWORD_ENABLE_USER   0x01
58 #define IPMI_PASSWORD_SET_PASSWORD  0x02
59 #define IPMI_PASSWORD_TEST_PASSWORD 0x03
60 
61 /*
62  * ipmi_get_user_access
63  *
64  * param intf		[in]
65  * param channel_number [in]
66  * param user_id	[in]
67  * param user_access	[out]
68  *
69  * return 0 on succes
70  *	  1 on failure
71  */
72 static int
73 ipmi_get_user_access(
74 		     struct ipmi_intf *intf,
75 		     uint8_t channel_number,
76 		     uint8_t user_id,
77 		     struct user_access_rsp *user_access)
78 {
79 	struct ipmi_rs	     * rsp;
80 	struct ipmi_rq	       req;
81 	uint8_t	       msg_data[2];
82 
83 	memset(&req, 0, sizeof(req));
84 	req.msg.netfn    = IPMI_NETFN_APP;	     /* 0x06 */
85 	req.msg.cmd	     = IPMI_GET_USER_ACCESS; /* 0x44 */
86 	req.msg.data     = msg_data;
87 	req.msg.data_len = 2;
88 
89 
90 	/* The channel number will remain constant throughout this function */
91 	msg_data[0] = channel_number;
92 	msg_data[1] = user_id;
93 
94 	rsp = intf->sendrecv(intf, &req);
95 
96 	if (rsp == NULL) {
97 		lprintf(LOG_ERR, "Get User Access command failed "
98 			"(channel %d, user %d)", channel_number, user_id);
99 		return -1;
100 	}
101 	if (rsp->ccode > 0) {
102 		lprintf(LOG_ERR, "Get User Access command failed "
103 			"(channel %d, user %d): %s", channel_number, user_id,
104 			val2str(rsp->ccode, completion_code_vals));
105 		return -1;
106 	}
107 
108 	memcpy(user_access,
109 	       rsp->data,
110 	       sizeof(struct user_access_rsp));
111 
112 	return 0;
113 }
114 
115 
116 
117 /*
118  * ipmi_get_user_name
119  *
120  * param intf		[in]
121  * param channel_number [in]
122  * param user_id	[in]
123  * param user_name	[out]
124  *
125  * return 0 on succes
126  *	  1 on failure
127  */
128 static int
129 ipmi_get_user_name(
130 		   struct ipmi_intf *intf,
131 		   uint8_t user_id,
132 		   char	*user_name)
133 {
134 	struct ipmi_rs	     * rsp;
135 	struct ipmi_rq	       req;
136 	uint8_t	       msg_data[1];
137 
138 	memset(user_name, 0, 17);
139 
140 	memset(&req, 0, sizeof(req));
141 	req.msg.netfn    = IPMI_NETFN_APP;     /* 0x06 */
142 	req.msg.cmd      = IPMI_GET_USER_NAME; /* 0x45 */
143 	req.msg.data     = msg_data;
144 	req.msg.data_len = 1;
145 
146 	msg_data[0] = user_id;
147 
148 	rsp = intf->sendrecv(intf, &req);
149 
150 	if (rsp == NULL) {
151 		lprintf(LOG_ERR, "Get User Name command failed (user %d)",
152 			user_id);
153 		return -1;
154 	}
155 	if (rsp->ccode > 0) {
156 		if (rsp->ccode == 0xcc)
157 			return 0;
158 		lprintf(LOG_ERR, "Get User Name command failed (user %d): %s",
159 			user_id, val2str(rsp->ccode, completion_code_vals));
160 		return -1;
161 	}
162 
163 	memcpy(user_name, rsp->data, 16);
164 
165 	return 0;
166 }
167 
168 
169 
170 
171 static void
172 dump_user_access(
173 		 uint8_t		  user_id,
174 		 const		   char * user_name,
175 		 struct user_access_rsp * user_access)
176 {
177 	static int printed_header = 0;
178 
179 	if (! printed_header)
180 	{
181 		printf("ID  Name	     Callin  Link Auth	IPMI Msg   "
182 		       "Channel Priv Limit\n");
183 		printed_header = 1;
184 	}
185 
186 	printf("%-4d%-17s%-8s%-11s%-11s%-s\n",
187 	       user_id,
188 	       user_name,
189 	       user_access->no_callin_access? "false": "true ",
190 	       user_access->link_auth_access? "true ": "false",
191 	       user_access->ipmi_messaging_access? "true ": "false",
192 	       val2str(user_access->channel_privilege_limit,
193 		       ipmi_privlvl_vals));
194 }
195 
196 
197 
198 static void
199 dump_user_access_csv(
200 		     uint8_t user_id,
201 		     const char *user_name,
202 		     struct user_access_rsp *user_access)
203 {
204 	printf("%d,%s,%s,%s,%s,%s\n",
205 	       user_id,
206 	       user_name,
207 	       user_access->no_callin_access? "false": "true",
208 	       user_access->link_auth_access? "true": "false",
209 	       user_access->ipmi_messaging_access? "true": "false",
210 	       val2str(user_access->channel_privilege_limit,
211 		       ipmi_privlvl_vals));
212 }
213 
214 static int
215 ipmi_print_user_list(
216 		     struct ipmi_intf *intf,
217 		     uint8_t channel_number)
218 {
219 	/* This is where you were! */
220 	char user_name[17];
221 	struct user_access_rsp  user_access;
222 	uint8_t current_user_id = 1;
223 
224 
225 	do
226 	{
227 		if (ipmi_get_user_access(intf,
228 					 channel_number,
229 					 current_user_id,
230 					 &user_access))
231 			return -1;
232 
233 
234 		if (ipmi_get_user_name(intf,
235 				       current_user_id,
236 				       user_name))
237 			return -1;
238 
239 		if ((current_user_id == 0)	      ||
240 		    user_access.link_auth_access      ||
241 		    user_access.ipmi_messaging_access ||
242 		    strcmp("", user_name))
243 		{
244 			if (csv_output)
245 				dump_user_access_csv(current_user_id,
246 						     user_name, &user_access);
247 			else
248 				dump_user_access(current_user_id,
249 						 user_name,
250 						 &user_access);
251 		}
252 
253 
254 		++current_user_id;
255 	} while((current_user_id <= user_access.maximum_ids) &&
256 			(current_user_id <= IPMI_UID_MAX)); /* Absolute maximum allowed by spec */
257 
258 
259 	return 0;
260 }
261 
262 
263 
264 static int
265 ipmi_print_user_summary(
266 			struct ipmi_intf * intf,
267 			uint8_t	   channel_number)
268 {
269 	struct user_access_rsp     user_access;
270 
271 	if (ipmi_get_user_access(intf,
272 				 channel_number,
273 				 1,
274 				 &user_access))
275 		return -1;
276 
277 	if (csv_output)
278 	{
279 		printf("%d,%d,%d\n",
280 		       user_access.maximum_ids,
281 		       user_access.enabled_user_count,
282 		       user_access.fixed_name_count);
283 	}
284 	else
285 	{
286 		printf("Maximum IDs	    : %d\n",
287 		       user_access.maximum_ids);
288 		printf("Enabled User Count  : %d\n",
289 		       user_access.enabled_user_count);
290 		printf("Fixed Name Count    : %d\n",
291 		       user_access.fixed_name_count);
292 	}
293 
294 	return 0;
295 }
296 
297 
298 
299 /*
300  * ipmi_user_set_username
301  */
302 static int
303 ipmi_user_set_username(
304 		       struct ipmi_intf *intf,
305 		       uint8_t user_id,
306 		       const char *name)
307 {
308 	struct ipmi_rs	     * rsp;
309 	struct ipmi_rq	       req;
310 	uint8_t	       msg_data[17];
311 
312 	/*
313 	 * Ensure there is space for the name in the request message buffer
314 	 */
315 	if (strlen(name) >= sizeof(msg_data)) {
316 		return -1;
317 	}
318 
319 	memset(&req, 0, sizeof(req));
320 	req.msg.netfn    = IPMI_NETFN_APP;	     /* 0x06 */
321 	req.msg.cmd	     = IPMI_SET_USER_NAME;   /* 0x45 */
322 	req.msg.data     = msg_data;
323 	req.msg.data_len = sizeof(msg_data);
324 	memset(msg_data, 0, sizeof(msg_data));
325 
326 	/* The channel number will remain constant throughout this function */
327 	msg_data[0] = user_id;
328 	strncpy((char *)(msg_data + 1), name, strlen(name));
329 
330 	rsp = intf->sendrecv(intf, &req);
331 
332 	if (rsp == NULL) {
333 		lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s)",
334 			user_id, name);
335 		return -1;
336 	}
337 	if (rsp->ccode > 0) {
338 		lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s): %s",
339 			user_id, name, val2str(rsp->ccode, completion_code_vals));
340 		return -1;
341 	}
342 
343 	return 0;
344 }
345 
346 static int
347 ipmi_user_set_userpriv(
348 		       struct ipmi_intf *intf,
349 		       uint8_t channel,
350 		       uint8_t user_id,
351 		       const unsigned char privLevel)
352 {
353 	struct ipmi_rs *rsp;
354 	struct ipmi_rq req;
355 	uint8_t msg_data[4] = {0, 0, 0, 0};
356 
357 	memset(&req, 0, sizeof(req));
358 	req.msg.netfn    = IPMI_NETFN_APP;         /* 0x06 */
359 	req.msg.cmd      = IPMI_SET_USER_ACCESS;   /* 0x43 */
360 	req.msg.data     = msg_data;
361 	req.msg.data_len = 4;
362 
363 	/* The channel number will remain constant throughout this function */
364 	msg_data[0] = (channel   & 0x0f);
365 	msg_data[1] = (user_id   & 0x3f);
366 	msg_data[2] = (privLevel & 0x0f);
367 	msg_data[3] = 0;
368 
369 	rsp = intf->sendrecv(intf, &req);
370 
371 	if (rsp == NULL)
372 	{
373 		lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
374 			user_id);
375 		return -1;
376 	}
377 	if (rsp->ccode > 0)
378 	{
379 		lprintf(LOG_ERR, "Set Privilege Level command failed (user %d): %s",
380 			user_id, val2str(rsp->ccode, completion_code_vals));
381 		return -1;
382 	}
383 
384 	return 0;
385 }
386 
387 /*
388  * ipmi_user_set_password
389  *
390  * This function is responsible for 4 things
391  * Enabling/Disabling users
392  * Setting/Testing passwords
393  */
394 static int
395 ipmi_user_set_password(
396 		       struct ipmi_intf * intf,
397 		       uint8_t user_id,
398 		       uint8_t operation,
399 		       const char *password,
400 		       int is_twenty_byte_password)
401 {
402 	struct ipmi_rs	     * rsp;
403 	struct ipmi_rq	       req;
404 	uint8_t	               msg_data[22];
405 
406 	int password_length = (is_twenty_byte_password? 20 : 16);
407 
408 	memset(&req, 0, sizeof(req));
409 	req.msg.netfn    = IPMI_NETFN_APP;	    /* 0x06 */
410 	req.msg.cmd	 = IPMI_SET_USER_PASSWORD;  /* 0x47 */
411 	req.msg.data     = msg_data;
412 	req.msg.data_len = password_length + 2;
413 
414 
415 	/* The channel number will remain constant throughout this function */
416 	msg_data[0] = user_id;
417 
418 	if (is_twenty_byte_password)
419 		msg_data[0] |= 0x80;
420 
421 	msg_data[1] = operation;
422 
423 	memset(msg_data + 2, 0, password_length);
424 
425 	if (password != NULL)
426 		strncpy((char *)(msg_data + 2), password, password_length);
427 
428 	rsp = intf->sendrecv(intf, &req);
429 
430 	if (rsp == NULL) {
431 		lprintf(LOG_ERR, "Set User Password command failed (user %d)",
432 			user_id);
433 		return -1;
434 	}
435 	if (rsp->ccode > 0) {
436 		lprintf(LOG_ERR, "Set User Password command failed (user %d): %s",
437 			user_id, val2str(rsp->ccode, completion_code_vals));
438 		return rsp->ccode;
439 	}
440 
441 	return 0;
442 }
443 
444 
445 
446 /*
447  * ipmi_user_test_password
448  *
449  * Call ipmi_user_set_password, and interpret the result
450  */
451 static int
452 ipmi_user_test_password(
453 			struct ipmi_intf * intf,
454 			uint8_t      user_id,
455 			const char       * password,
456 			int                is_twenty_byte_password)
457 {
458 	int ret;
459 
460 	ret = ipmi_user_set_password(intf,
461 				     user_id,
462 				     IPMI_PASSWORD_TEST_PASSWORD,
463 				     password,
464 				     is_twenty_byte_password);
465 
466 	switch (ret) {
467 	case 0:
468 		printf("Success\n");
469 		break;
470 	case 0x80:
471 		printf("Failure: password incorrect\n");
472 		break;
473 	case 0x81:
474 		printf("Failure: wrong password size\n");
475 		break;
476 	default:
477 		printf("Unknown error\n");
478 	}
479 
480 	return ((ret == 0) ? 0 : -1);
481 }
482 
483 
484 /*
485  * print_user_usage
486  */
487 static void
488 print_user_usage(void)
489 {
490 	lprintf(LOG_NOTICE, "User Commands:");
491 	lprintf(LOG_NOTICE, "		   summary      [<channel number>]");
492 	lprintf(LOG_NOTICE, "		   list         [<channel number>]");
493 	lprintf(LOG_NOTICE, "		   set name     <user id> <username>");
494 	lprintf(LOG_NOTICE, "		   set password <user id> [<password>]");
495 	lprintf(LOG_NOTICE, "		   disable      <user id>");
496 	lprintf(LOG_NOTICE, "		   enable       <user id>");
497 	lprintf(LOG_NOTICE,
498 			"		   priv         <user id> <privilege level> [<channel number>]");
499 	lprintf(LOG_NOTICE, "		   test         <user id> <16|20> [<password]>\n");
500 }
501 
502 
503 const char *
504 ipmi_user_build_password_prompt(uint8_t user_id)
505 {
506 	static char prompt[128];
507 	memset(prompt, 0, 128);
508 	snprintf(prompt, 128, "Password for user %d: ", user_id);
509 	return prompt;
510 }
511 
512 int
513 ipmi_user_summary(struct ipmi_intf *intf, int argc, char **argv)
514 {
515 	/* Summary*/
516 	uint8_t channel;
517 	if (argc == 1) {
518 		channel = 0x0E; /* Ask about the current channel */
519 	} else if (argc == 2) {
520 		if (str2uchar(argv[1], &channel) != 0) {
521 			lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
522 			return (-1);
523 		}
524 	} else {
525 		print_user_usage();
526 		return (-1);
527 	}
528 	return ipmi_print_user_summary(intf, channel);
529 }
530 
531 int
532 ipmi_user_list(struct ipmi_intf *intf, int argc, char **argv)
533 {
534 	/* List */
535 	uint8_t channel;
536 	if (argc == 1) {
537 		channel = 0x0E; /* Ask about the current channel */
538 	} else if (argc == 2) {
539 		if (str2uchar(argv[1], &channel) != 0) {
540 			lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
541 			return (-1);
542 		}
543 	} else {
544 		print_user_usage();
545 		return (-1);
546 	}
547 	return ipmi_print_user_list(intf, channel);
548 }
549 
550 int
551 ipmi_user_test(struct ipmi_intf *intf, int argc, char **argv)
552 {
553 	/* Test */
554 	int retval = 0;
555 	char *password = NULL;
556 	int password_length = 0;
557 	uint8_t user_id = 0;
558 	/* a little irritating, isn't it */
559 	if (argc != 3 && argc != 4) {
560 		print_user_usage();
561 		return (-1);
562 	}
563 	if (is_ipmi_user_id(argv[1], &user_id)) {
564 		return (-1);
565 	}
566 	if (str2int(argv[2], &password_length) != 0
567 			|| (password_length != 16 && password_length != 20)) {
568 		lprintf(LOG_ERR,
569 				"Given password length '%s' is invalid.",
570 				argv[2]);
571 		lprintf(LOG_ERR, "Expected value is either 16 or 20.");
572 		return (-1);
573 	}
574 	if (argc == 3) {
575 		/* We need to prompt for a password */
576 		const char *password_prompt =
577 			ipmi_user_build_password_prompt(user_id);
578 # ifdef HAVE_GETPASSPHRASE
579 		password = getpassphrase(password_prompt);
580 # else
581 		password = (char*)getpass(password_prompt);
582 # endif
583 		if (password == NULL) {
584 			lprintf(LOG_ERR, "ipmitool: malloc failure");
585 			return (-1);
586 		}
587 	} else {
588 		password = strdup(argv[3]);
589 	}
590 	retval = ipmi_user_test_password(intf,
591 					 user_id,
592 					 password,
593 					 password_length == 20);
594 	if (password != NULL) {
595 		free(password);
596 		password = NULL;
597 	}
598 	return retval;
599 }
600 
601 int
602 ipmi_user_priv(struct ipmi_intf *intf, int argc, char **argv)
603 {
604 	uint8_t user_id;
605 	uint8_t priv_level;
606 	uint8_t channel = 0x0e; /* Use channel running on */
607 
608 	if (argc != 3 && argc != 4) {
609 		print_user_usage();
610 		return (-1);
611 	}
612 	if (argc == 4) {
613 		if (str2uchar(argv[3], &channel) != 0) {
614 			lprintf(LOG_ERR, "Invalid channel: %s", argv[3]);
615 			return (-1);
616 		}
617 		channel = (channel & 0x0f);
618 	}
619 	if (str2uchar(argv[2], &priv_level) != 0) {
620 		lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]);
621 		return (-1);
622 	}
623 	if (is_ipmi_user_id(argv[1], &user_id)) {
624 		return (-1);
625 	}
626 	priv_level = (priv_level & 0x0f);
627 	return ipmi_user_set_userpriv(intf,channel,user_id,priv_level);
628 }
629 
630 int
631 ipmi_user_mod(struct ipmi_intf *intf, int argc, char **argv)
632 {
633 	/* Disable / Enable */
634 	uint8_t user_id;
635 	uint8_t operation;
636 	char null_password[16]; /* Not used, but required */
637 
638 	if (argc != 2) {
639 		print_user_usage();
640 		return (-1);
641 	}
642 	if (is_ipmi_user_id(argv[1], &user_id)) {
643 		return (-1);
644 	}
645 	memset(null_password, 0, sizeof(null_password));
646 	operation = (strncmp(argv[0], "disable", 7) == 0) ?
647 		IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER;
648 
649 	/* Last parameter is ignored */
650 	return ipmi_user_set_password(intf, user_id, operation, null_password, 0);
651 }
652 
653 int
654 ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv)
655 {
656 	char *password = NULL;
657 	int retval = 0;
658 	uint8_t user_id = 0;
659 	if (is_ipmi_user_id(argv[2], &user_id)) {
660 		return (-1);
661 	}
662 
663 	if (argc == 3) {
664 		/* We need to prompt for a password */
665 		char *tmp;
666 		const char *password_prompt =
667 			ipmi_user_build_password_prompt(user_id);
668 # ifdef HAVE_GETPASSPHRASE
669 		tmp = getpassphrase(password_prompt);
670 # else
671 		tmp = (char*)getpass(password_prompt);
672 # endif
673 		if (tmp != NULL) {
674 			password = strdup(tmp);
675 			tmp = NULL;
676 		}
677 		if (password == NULL) {
678 			lprintf(LOG_ERR, "ipmitool: malloc failure");
679 			return (-1);
680 		}
681 # ifdef HAVE_GETPASSPHRASE
682 		tmp = getpassphrase(password_prompt);
683 # else
684 		tmp = (char*)getpass(password_prompt);
685 # endif
686 		if (tmp == NULL) {
687 			lprintf(LOG_ERR, "ipmitool: malloc failure");
688 			return (-1);
689 		}
690 		if (strlen(password) != strlen(tmp)
691 				|| strncmp(password, tmp, strlen(tmp))) {
692 			lprintf(LOG_ERR, "Passwords do not match.");
693 			free(password);
694 			password = NULL;
695 			return (-1);
696 		}
697 		tmp = NULL;
698 	} else {
699 		password = strdup(argv[3]);
700 	}
701 
702 	if (password == NULL) {
703 		lprintf(LOG_ERR, "Unable to parse password argument.");
704 		return (-1);
705 	} else if (strlen(password) > 20) {
706 		lprintf(LOG_ERR, "Password is too long (> 20 bytes)");
707 		return (-1);
708 	}
709 
710 	retval = ipmi_user_set_password(intf,
711 					user_id,
712 					IPMI_PASSWORD_SET_PASSWORD,
713 					password,
714 					strlen(password) > 16);
715 	if (password != NULL) {
716 		free(password);
717 		password = NULL;
718 	}
719 	return retval;
720 }
721 
722 int
723 ipmi_user_name(struct ipmi_intf *intf, int argc, char **argv)
724 {
725 	/* Set Name */
726 	uint8_t user_id = 0;
727 	if (argc != 4) {
728 		print_user_usage();
729 		return (-1);
730 	}
731 	if (is_ipmi_user_id(argv[2], &user_id)) {
732 		return (-1);
733 	}
734 	if (strlen(argv[3]) > 16) {
735 		lprintf(LOG_ERR, "Username is too long (> 16 bytes)");
736 		return (-1);
737 	}
738 
739 	return ipmi_user_set_username(intf, user_id, argv[3]);
740 }
741 
742 /*
743  * ipmi_user_main
744  *
745  * Upon entry to this function argv should contain our arguments
746  * specific to this subcommand
747  */
748 int
749 ipmi_user_main(struct ipmi_intf *intf, int argc, char **argv)
750 {
751 	if (argc == 0) {
752 		lprintf(LOG_ERR, "Not enough parameters given.");
753 		print_user_usage();
754 		return (-1);
755 	}
756 	if (strncmp(argv[0], "help", 4) == 0) {
757 		/* Help */
758 		print_user_usage();
759 		return 0;
760 	} else if (strncmp(argv[0], "summary", 7) == 0) {
761 		return ipmi_user_summary(intf, argc, argv);
762 	} else if (strncmp(argv[0], "list", 4) == 0) {
763 		return ipmi_user_list(intf, argc, argv);
764 	} else if (strncmp(argv[0], "test", 4) == 0) {
765 		return ipmi_user_test(intf, argc, argv);
766 	} else if (strncmp(argv[0], "set", 3) == 0) {
767 		/* Set */
768 		if ((argc >= 3)
769 				&& (strncmp("password", argv[1], 8) == 0)) {
770 			return ipmi_user_password(intf, argc, argv);
771 		} else if ((argc >= 2)
772 				&& (strncmp("name", argv[1], 4) == 0)) {
773 			return ipmi_user_name(intf, argc, argv);
774 		} else {
775 			print_user_usage();
776 			return (-1);
777 		}
778 	} else if (strncmp(argv[0], "priv", 4) == 0) {
779 		return ipmi_user_priv(intf, argc, argv);
780 	} else if ((strncmp(argv[0], "disable", 7) == 0)
781 			|| (strncmp(argv[0], "enable",  6) == 0)) {
782 		return ipmi_user_mod(intf, argc, argv);
783 	} else {
784 		lprintf(LOG_ERR, "Invalid user command: '%s'\n", argv[0]);
785 		print_user_usage();
786 		return (-1);
787 	}
788 }
789