xref: /openbmc/ipmitool/lib/ipmi_user.c (revision 21151953a5844ccc7c3e1f444d21308028eb08b6)
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 /* _ipmi_get_user_access - Get User Access for given channel. Results are stored
57  * into passed struct.
58  *
59  * @intf - IPMI interface
60  * @user_access_rsp - ptr to user_access_t with UID and Channel set
61  *
62  * returns - negative number means error, positive is a ccode
63  */
64 int
65 _ipmi_get_user_access(struct ipmi_intf *intf,
66 		struct user_access_t *user_access_rsp)
67 {
68 	struct ipmi_rq req = {0};
69 	struct ipmi_rs *rsp;
70 	uint8_t data[2];
71 	if (user_access_rsp == NULL) {
72 		return (-3);
73 	}
74 	data[0] = user_access_rsp->channel & 0x0F;
75 	data[1] = user_access_rsp->user_id & 0x3F;
76 	req.msg.netfn = IPMI_NETFN_APP;
77 	req.msg.cmd = IPMI_GET_USER_ACCESS;
78 	req.msg.data = data;
79 	req.msg.data_len = 2;
80 	rsp = intf->sendrecv(intf, &req);
81 	if (rsp == NULL) {
82 		return (-1);
83 	} else if (rsp->ccode != 0) {
84 		return rsp->ccode;
85 	} else if (rsp->data_len != 4) {
86 		return (-2);
87 	}
88 	user_access_rsp->max_user_ids = rsp->data[0] & 0x3F;
89 	user_access_rsp->enable_status = rsp->data[1] & 0xC0;
90 	user_access_rsp->enabled_user_ids = rsp->data[1] & 0x3F;
91 	user_access_rsp->fixed_user_ids = rsp->data[2] & 0x3F;
92 	user_access_rsp->callin_callback = rsp->data[3] & 0x40;
93 	user_access_rsp->link_auth = rsp->data[3] & 0x20;
94 	user_access_rsp->ipmi_messaging = rsp->data[3] & 0x10;
95 	user_access_rsp->privilege_limit = rsp->data[3] & 0x0F;
96 	return rsp->ccode;
97 }
98 
99 /* _ipmi_get_user_name - Fetch User Name for given User ID. User Name is stored
100  * into passed structure.
101  *
102  * @intf - ipmi interface
103  * @user_name - user_name_t struct with UID set
104  *
105  * returns - negative number means error, positive is a ccode
106  */
107 int
108 _ipmi_get_user_name(struct ipmi_intf *intf, struct user_name_t *user_name_ptr)
109 {
110 	struct ipmi_rq req = {0};
111 	struct ipmi_rs *rsp;
112 	uint8_t data[1];
113 	if (user_name_ptr == NULL) {
114 		return (-3);
115 	}
116 	data[0] = user_name_ptr->user_id & 0x3F;
117 	req.msg.netfn = IPMI_NETFN_APP;
118 	req.msg.cmd = IPMI_GET_USER_NAME;
119 	req.msg.data = data;
120 	req.msg.data_len = 1;
121 	rsp = intf->sendrecv(intf, &req);
122 	if (rsp == NULL) {
123 		return (-1);
124 	} else if (rsp->ccode > 0) {
125 		return rsp->ccode;
126 	} else if (rsp->data_len != 17) {
127 		return (-2);
128 	}
129 	memset(user_name_ptr->user_name, '\0', 17);
130 	memcpy(user_name_ptr->user_name, rsp->data, 16);
131 	return rsp->ccode;
132 }
133 
134 /* _ipmi_set_user_access - Set User Access for given channel.
135  *
136  * @intf - IPMI interface
137  * @user_access_req - ptr to user_access_t with desired User Access.
138  * @change_priv_limit_only - change User's privilege limit only
139  *
140  * returns - negative number means error, positive is a ccode
141  */
142 int
143 _ipmi_set_user_access(struct ipmi_intf *intf,
144 		struct user_access_t *user_access_req,
145 		uint8_t change_priv_limit_only)
146 {
147 	uint8_t data[4];
148 	struct ipmi_rq req = {0};
149 	struct ipmi_rs *rsp;
150 	if (user_access_req == NULL) {
151 		return (-3);
152 	}
153 	data[0] = change_priv_limit_only ? 0x00 : 0x80;
154 	if (user_access_req->callin_callback) {
155 		data[0] |= 0x40;
156 	}
157 	if (user_access_req->link_auth) {
158 		data[0] |= 0x20;
159 	}
160 	if (user_access_req->ipmi_messaging) {
161 		data[0] |= 0x10;
162 	}
163 	data[0] |= (user_access_req->channel & 0x0F);
164 	data[1] = user_access_req->user_id & 0x3F;
165 	data[2] = user_access_req->privilege_limit & 0x0F;
166 	data[3] = user_access_req->session_limit & 0x0F;
167 	req.msg.netfn = IPMI_NETFN_APP;
168 	req.msg.cmd = IPMI_SET_USER_ACCESS;
169 	req.msg.data = data;
170 	req.msg.data_len = 4;
171 	rsp = intf->sendrecv(intf, &req);
172 	if (rsp == NULL) {
173 		return (-1);
174 	} else {
175 		return rsp->ccode;
176 	}
177 }
178 
179 static void
180 dump_user_access(const char *user_name,
181 		struct user_access_t *user_access)
182 {
183 	static int printed_header = 0;
184 	if (!printed_header) {
185 		printf("ID  Name	     Callin  Link Auth	IPMI Msg   "
186 				"Channel Priv Limit\n");
187 		printed_header = 1;
188 	}
189 	printf("%-4d%-17s%-8s%-11s%-11s%-s\n",
190 			user_access->user_id,
191 			user_name,
192 			user_access->callin_callback? "false": "true ",
193 			user_access->link_auth? "true ": "false",
194 			user_access->ipmi_messaging? "true ": "false",
195 			val2str(user_access->privilege_limit,
196 				ipmi_privlvl_vals));
197 }
198 
199 
200 
201 static void
202 dump_user_access_csv(const char *user_name,
203 		struct user_access_t *user_access)
204 {
205 	printf("%d,%s,%s,%s,%s,%s\n",
206 			user_access->user_id,
207 			user_name,
208 			user_access->callin_callback? "false": "true",
209 			user_access->link_auth? "true": "false",
210 			user_access->ipmi_messaging? "true": "false",
211 			val2str(user_access->privilege_limit,
212 				ipmi_privlvl_vals));
213 }
214 
215 /* ipmi_print_user_list - List IPMI Users and their ACLs for given channel.
216  *
217  * @intf - IPMI interface
218  * @channel_number - IPMI channel
219  *
220  * returns - 0 on success, (-1) on error
221  */
222 static int
223 ipmi_print_user_list(struct ipmi_intf *intf, uint8_t channel_number)
224 {
225 	struct user_access_t user_access = {0};
226 	struct user_name_t user_name = {0};
227 	int ccode = 0;
228 	uint8_t current_user_id = 1;
229 	do {
230 		memset(&user_access, 0, sizeof(user_access));
231 		user_access.user_id = current_user_id;
232 		user_access.channel = channel_number;
233 		ccode = _ipmi_get_user_access(intf, &user_access);
234 		if (eval_ccode(ccode) != 0) {
235 			return (-1);
236 		}
237 		memset(&user_name, 0, sizeof(user_name));
238 		user_name.user_id = current_user_id;
239 		ccode = _ipmi_get_user_name(intf, &user_name);
240 		if (eval_ccode(ccode) != 0) {
241 			return (-1);
242 		}
243 		if ((current_user_id == 0)
244 				|| user_access.link_auth
245 				|| user_access.ipmi_messaging
246 				|| strcmp("", (char *)user_name.user_name)) {
247 			if (csv_output) {
248 				dump_user_access_csv((char *)user_name.user_name,
249 						&user_access);
250 			} else {
251 				dump_user_access((char *)user_name.user_name,
252 						&user_access);
253 			}
254 		}
255 		++current_user_id;
256 	} while ((current_user_id <= user_access.max_user_ids)
257 			&& (current_user_id <= IPMI_UID_MAX));
258 	return 0;
259 }
260 
261 /* ipmi_print_user_summary - print User statistics for given channel
262  *
263  * @intf - IPMI interface
264  * @channel_number - channel number
265  *
266  * returns - 0 on success, (-1) on error
267  */
268 static int
269 ipmi_print_user_summary(struct ipmi_intf *intf, uint8_t channel_number)
270 {
271 	struct user_access_t user_access = {0};
272 	int ccode = 0;
273 	user_access.channel = channel_number;
274 	user_access.user_id = 1;
275 	ccode = _ipmi_get_user_access(intf, &user_access);
276 	if (eval_ccode(ccode) != 0) {
277 		return (-1);
278 	}
279 	if (csv_output) {
280 		printf("%" PRIu8 ",%" PRIu8 ",%" PRIu8 "\n",
281 				user_access.max_user_ids,
282 				user_access.enabled_user_ids,
283 				user_access.fixed_user_ids);
284 	} else {
285 		printf("Maximum IDs	    : %" PRIu8 "\n",
286 				user_access.max_user_ids);
287 		printf("Enabled User Count  : %" PRIu8 "\n",
288 				user_access.enabled_user_ids);
289 		printf("Fixed Name Count    : %" PRIu8 "\n",
290 				user_access.fixed_user_ids);
291 	}
292 	return 0;
293 }
294 
295 /*
296  * ipmi_user_set_username
297  */
298 static int
299 ipmi_user_set_username(
300 		       struct ipmi_intf *intf,
301 		       uint8_t user_id,
302 		       const char *name)
303 {
304 	struct ipmi_rs	     * rsp;
305 	struct ipmi_rq	       req;
306 	uint8_t	       msg_data[17];
307 
308 	/*
309 	 * Ensure there is space for the name in the request message buffer
310 	 */
311 	if (strlen(name) >= sizeof(msg_data)) {
312 		return -1;
313 	}
314 
315 	memset(&req, 0, sizeof(req));
316 	req.msg.netfn    = IPMI_NETFN_APP;	     /* 0x06 */
317 	req.msg.cmd	     = IPMI_SET_USER_NAME;   /* 0x45 */
318 	req.msg.data     = msg_data;
319 	req.msg.data_len = sizeof(msg_data);
320 	memset(msg_data, 0, sizeof(msg_data));
321 
322 	/* The channel number will remain constant throughout this function */
323 	msg_data[0] = user_id;
324 	strncpy((char *)(msg_data + 1), name, strlen(name));
325 
326 	rsp = intf->sendrecv(intf, &req);
327 
328 	if (rsp == NULL) {
329 		lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s)",
330 			user_id, name);
331 		return -1;
332 	}
333 	if (rsp->ccode > 0) {
334 		lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s): %s",
335 			user_id, name, val2str(rsp->ccode, completion_code_vals));
336 		return -1;
337 	}
338 
339 	return 0;
340 }
341 
342 /*
343  * ipmi_user_set_password
344  *
345  * This function is responsible for 4 things
346  * Enabling/Disabling users
347  * Setting/Testing passwords
348  */
349 static int
350 ipmi_user_set_password(
351 		       struct ipmi_intf * intf,
352 		       uint8_t user_id,
353 		       uint8_t operation,
354 		       const char *password,
355 		       int is_twenty_byte_password)
356 {
357 	struct ipmi_rs	     * rsp;
358 	struct ipmi_rq	       req;
359 	uint8_t	               msg_data[22];
360 
361 	int password_length = (is_twenty_byte_password? 20 : 16);
362 
363 	memset(&req, 0, sizeof(req));
364 	req.msg.netfn    = IPMI_NETFN_APP;	    /* 0x06 */
365 	req.msg.cmd	 = IPMI_SET_USER_PASSWORD;  /* 0x47 */
366 	req.msg.data     = msg_data;
367 	req.msg.data_len = password_length + 2;
368 
369 
370 	/* The channel number will remain constant throughout this function */
371 	msg_data[0] = user_id;
372 
373 	if (is_twenty_byte_password)
374 		msg_data[0] |= 0x80;
375 
376 	msg_data[1] = operation;
377 
378 	memset(msg_data + 2, 0, password_length);
379 
380 	if (password != NULL)
381 		strncpy((char *)(msg_data + 2), password, password_length);
382 
383 	rsp = intf->sendrecv(intf, &req);
384 
385 	if (rsp == NULL) {
386 		lprintf(LOG_ERR, "Set User Password command failed (user %d)",
387 			user_id);
388 		return -1;
389 	}
390 	if (rsp->ccode > 0) {
391 		lprintf(LOG_ERR, "Set User Password command failed (user %d): %s",
392 			user_id, val2str(rsp->ccode, completion_code_vals));
393 		return rsp->ccode;
394 	}
395 
396 	return 0;
397 }
398 
399 /*
400  * ipmi_user_test_password
401  *
402  * Call ipmi_user_set_password, and interpret the result
403  */
404 static int
405 ipmi_user_test_password(
406 			struct ipmi_intf * intf,
407 			uint8_t      user_id,
408 			const char       * password,
409 			int                is_twenty_byte_password)
410 {
411 	int ret;
412 
413 	ret = ipmi_user_set_password(intf,
414 				     user_id,
415 				     IPMI_PASSWORD_TEST_PASSWORD,
416 				     password,
417 				     is_twenty_byte_password);
418 
419 	switch (ret) {
420 	case 0:
421 		printf("Success\n");
422 		break;
423 	case 0x80:
424 		printf("Failure: password incorrect\n");
425 		break;
426 	case 0x81:
427 		printf("Failure: wrong password size\n");
428 		break;
429 	default:
430 		printf("Unknown error\n");
431 	}
432 
433 	return ((ret == 0) ? 0 : -1);
434 }
435 
436 
437 /*
438  * print_user_usage
439  */
440 static void
441 print_user_usage(void)
442 {
443 	lprintf(LOG_NOTICE,
444 "User Commands:");
445 	lprintf(LOG_NOTICE,
446 "               summary      [<channel number>]");
447 	lprintf(LOG_NOTICE,
448 "               list         [<channel number>]");
449 	lprintf(LOG_NOTICE,
450 "               set name     <user id> <username>");
451 	lprintf(LOG_NOTICE,
452 "               set password <user id> [<password> <16|20>]");
453 	lprintf(LOG_NOTICE,
454 "               disable      <user id>");
455 	lprintf(LOG_NOTICE,
456 "               enable       <user id>");
457 	lprintf(LOG_NOTICE,
458 "               priv         <user id> <privilege level> [<channel number>]");
459 	lprintf(LOG_NOTICE,
460 "                     Privilege levels:");
461 	lprintf(LOG_NOTICE,
462 "                      * 0x1 - Callback");
463 	lprintf(LOG_NOTICE,
464 "                      * 0x2 - User");
465 	lprintf(LOG_NOTICE,
466 "                      * 0x3 - Operator");
467 	lprintf(LOG_NOTICE,
468 "                      * 0x4 - Administrator");
469 	lprintf(LOG_NOTICE,
470 "                      * 0x5 - OEM Proprietary");
471 	lprintf(LOG_NOTICE,
472 "                      * 0xF - No Access");
473 	lprintf(LOG_NOTICE, "");
474 	lprintf(LOG_NOTICE,
475 "               test         <user id> <16|20> [<password]>");
476 	lprintf(LOG_NOTICE, "");
477 }
478 
479 
480 const char *
481 ipmi_user_build_password_prompt(uint8_t user_id)
482 {
483 	static char prompt[128];
484 	memset(prompt, 0, 128);
485 	snprintf(prompt, 128, "Password for user %d: ", user_id);
486 	return prompt;
487 }
488 
489 /* ask_password - ask user for password
490  *
491  * @user_id: User ID which will be built-in into text
492  *
493  * @returns pointer to char with password
494  */
495 char *
496 ask_password(uint8_t user_id)
497 {
498 	const char *password_prompt =
499 		ipmi_user_build_password_prompt(user_id);
500 # ifdef HAVE_GETPASSPHRASE
501 	return getpassphrase(password_prompt);
502 # else
503 	return (char*)getpass(password_prompt);
504 # endif
505 }
506 
507 int
508 ipmi_user_summary(struct ipmi_intf *intf, int argc, char **argv)
509 {
510 	/* Summary*/
511 	uint8_t channel;
512 	if (argc == 1) {
513 		channel = 0x0E; /* Ask about the current channel */
514 	} else if (argc == 2) {
515 		if (is_ipmi_channel_num(argv[1], &channel) != 0) {
516 			return (-1);
517 		}
518 	} else {
519 		print_user_usage();
520 		return (-1);
521 	}
522 	return ipmi_print_user_summary(intf, channel);
523 }
524 
525 int
526 ipmi_user_list(struct ipmi_intf *intf, int argc, char **argv)
527 {
528 	/* List */
529 	uint8_t channel;
530 	if (argc == 1) {
531 		channel = 0x0E; /* Ask about the current channel */
532 	} else if (argc == 2) {
533 		if (is_ipmi_channel_num(argv[1], &channel) != 0) {
534 			return (-1);
535 		}
536 	} else {
537 		print_user_usage();
538 		return (-1);
539 	}
540 	return ipmi_print_user_list(intf, channel);
541 }
542 
543 int
544 ipmi_user_test(struct ipmi_intf *intf, int argc, char **argv)
545 {
546 	/* Test */
547 	char *password = NULL;
548 	int password_length = 0;
549 	uint8_t user_id = 0;
550 	/* a little irritating, isn't it */
551 	if (argc != 3 && argc != 4) {
552 		print_user_usage();
553 		return (-1);
554 	}
555 	if (is_ipmi_user_id(argv[1], &user_id)) {
556 		return (-1);
557 	}
558 	if (str2int(argv[2], &password_length) != 0
559 			|| (password_length != 16 && password_length != 20)) {
560 		lprintf(LOG_ERR,
561 				"Given password length '%s' is invalid.",
562 				argv[2]);
563 		lprintf(LOG_ERR, "Expected value is either 16 or 20.");
564 		return (-1);
565 	}
566 	if (argc == 3) {
567 		/* We need to prompt for a password */
568 		password = ask_password(user_id);
569 		if (password == NULL) {
570 			lprintf(LOG_ERR, "ipmitool: malloc failure");
571 			return (-1);
572 		}
573 	} else {
574 		password = argv[3];
575 	}
576 	return ipmi_user_test_password(intf,
577 					 user_id,
578 					 password,
579 					 password_length == 20);
580 }
581 
582 int
583 ipmi_user_priv(struct ipmi_intf *intf, int argc, char **argv)
584 {
585 	struct user_access_t user_access = {0};
586 	int ccode = 0;
587 
588 	if (argc != 3 && argc != 4) {
589 		print_user_usage();
590 		return (-1);
591 	}
592 	if (argc == 4) {
593 		if (is_ipmi_channel_num(argv[3], &user_access.channel) != 0) {
594 			return (-1);
595 		}
596 	} else {
597 		/* Use channel running on */
598 		user_access.channel = 0x0E;
599 	}
600 	if (is_ipmi_user_priv_limit(argv[2], &user_access.privilege_limit) != 0
601 			|| is_ipmi_user_id(argv[1], &user_access.user_id) != 0) {
602 		return (-1);
603 	}
604 	ccode = _ipmi_set_user_access(intf, &user_access, 1);
605 	if (eval_ccode(ccode) != 0) {
606 		lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
607 				user_access.user_id);
608 		return (-1);
609 	} else {
610 		printf("Set Privilege Level command successful (user %d)",
611 				user_access.user_id);
612 		return 0;
613 	}
614 }
615 
616 int
617 ipmi_user_mod(struct ipmi_intf *intf, int argc, char **argv)
618 {
619 	/* Disable / Enable */
620 	uint8_t user_id;
621 	uint8_t operation;
622 	char null_password[16]; /* Not used, but required */
623 
624 	if (argc != 2) {
625 		print_user_usage();
626 		return (-1);
627 	}
628 	if (is_ipmi_user_id(argv[1], &user_id)) {
629 		return (-1);
630 	}
631 	memset(null_password, 0, sizeof(null_password));
632 	operation = (strncmp(argv[0], "disable", 7) == 0) ?
633 		IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER;
634 
635 	/* Last parameter is ignored */
636 	return ipmi_user_set_password(intf, user_id, operation, null_password, 0);
637 }
638 
639 int
640 ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv)
641 {
642 	char *password = NULL;
643 	uint8_t password_type = 16;
644 	uint8_t user_id = 0;
645 	if (is_ipmi_user_id(argv[2], &user_id)) {
646 		return (-1);
647 	}
648 
649 	if (argc == 3) {
650 		/* We need to prompt for a password */
651 		char *tmp;
652 		password = ask_password(user_id);
653 		if (password == NULL) {
654 			lprintf(LOG_ERR, "ipmitool: malloc failure");
655 			return (-1);
656 		}
657 		tmp = ask_password(user_id);
658 		if (tmp == NULL) {
659 			lprintf(LOG_ERR, "ipmitool: malloc failure");
660 			return (-1);
661 		}
662 		if (strlen(password) != strlen(tmp)
663 				|| strncmp(password, tmp, strlen(tmp))) {
664 			lprintf(LOG_ERR, "Passwords do not match.");
665 			return (-1);
666 		}
667 	} else {
668 		password = argv[3];
669 		if (argc > 4) {
670 			if ((str2uchar(argv[4], &password_type) != 0)
671 					|| (password_type != 16 && password_type != 20)) {
672 				lprintf(LOG_ERR, "Invalid password length '%s'", argv[4]);
673 				return (-1);
674 			}
675 		} else {
676 			password_type = 16;
677 		}
678 	}
679 
680 	if (password == NULL) {
681 		lprintf(LOG_ERR, "Unable to parse password argument.");
682 		return (-1);
683 	} else if (strlen(password) > 20) {
684 		lprintf(LOG_ERR, "Password is too long (> 20 bytes)");
685 		return (-1);
686 	}
687 
688 	return ipmi_user_set_password(intf,
689 					user_id,
690 					IPMI_PASSWORD_SET_PASSWORD,
691 					password,
692 					password_type > 16);
693 }
694 
695 int
696 ipmi_user_name(struct ipmi_intf *intf, int argc, char **argv)
697 {
698 	/* Set Name */
699 	uint8_t user_id = 0;
700 	if (argc != 4) {
701 		print_user_usage();
702 		return (-1);
703 	}
704 	if (is_ipmi_user_id(argv[2], &user_id)) {
705 		return (-1);
706 	}
707 	if (strlen(argv[3]) > 16) {
708 		lprintf(LOG_ERR, "Username is too long (> 16 bytes)");
709 		return (-1);
710 	}
711 
712 	return ipmi_user_set_username(intf, user_id, argv[3]);
713 }
714 
715 /*
716  * ipmi_user_main
717  *
718  * Upon entry to this function argv should contain our arguments
719  * specific to this subcommand
720  */
721 int
722 ipmi_user_main(struct ipmi_intf *intf, int argc, char **argv)
723 {
724 	if (argc == 0) {
725 		lprintf(LOG_ERR, "Not enough parameters given.");
726 		print_user_usage();
727 		return (-1);
728 	}
729 	if (strncmp(argv[0], "help", 4) == 0) {
730 		/* Help */
731 		print_user_usage();
732 		return 0;
733 	} else if (strncmp(argv[0], "summary", 7) == 0) {
734 		return ipmi_user_summary(intf, argc, argv);
735 	} else if (strncmp(argv[0], "list", 4) == 0) {
736 		return ipmi_user_list(intf, argc, argv);
737 	} else if (strncmp(argv[0], "test", 4) == 0) {
738 		return ipmi_user_test(intf, argc, argv);
739 	} else if (strncmp(argv[0], "set", 3) == 0) {
740 		/* Set */
741 		if ((argc >= 3)
742 				&& (strncmp("password", argv[1], 8) == 0)) {
743 			return ipmi_user_password(intf, argc, argv);
744 		} else if ((argc >= 2)
745 				&& (strncmp("name", argv[1], 4) == 0)) {
746 			return ipmi_user_name(intf, argc, argv);
747 		} else {
748 			print_user_usage();
749 			return (-1);
750 		}
751 	} else if (strncmp(argv[0], "priv", 4) == 0) {
752 		return ipmi_user_priv(intf, argc, argv);
753 	} else if ((strncmp(argv[0], "disable", 7) == 0)
754 			|| (strncmp(argv[0], "enable",  6) == 0)) {
755 		return ipmi_user_mod(intf, argc, argv);
756 	} else {
757 		lprintf(LOG_ERR, "Invalid user command: '%s'\n", argv[0]);
758 		print_user_usage();
759 		return (-1);
760 	}
761 }
762