Code cleanup in ipmi_user_main()

This is just a tip of an iceberg, really.
This commit is contained in:
Zdenek Styblik 2014-12-09 18:48:20 +01:00 committed by Zdenek Styblik
parent 3c34aa0e1d
commit 2aa5d8c902

View File

@ -520,7 +520,12 @@ int
ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv) ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
{ {
int retval = 0; int retval = 0;
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) { if (argc == 0) {
lprintf(LOG_ERR, "Not enough parameters given.");
print_user_usage();
return 1;
}
if (strncmp(argv[0], "help", 4) == 0) {
/* Help */ /* Help */
print_user_usage(); print_user_usage();
} else if (strncmp(argv[0], "summary", 7) == 0) { } else if (strncmp(argv[0], "summary", 7) == 0) {
@ -528,8 +533,7 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
uint8_t channel; uint8_t channel;
if (argc == 1) { if (argc == 1) {
channel = 0x0E; /* Ask about the current channel */ channel = 0x0E; /* Ask about the current channel */
} } else if (argc == 2) {
else if (argc == 2) {
if (str2uchar(argv[1], &channel) != 0) { if (str2uchar(argv[1], &channel) != 0) {
lprintf(LOG_ERR, "Invalid channel: %s", argv[1]); lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
return (-1); return (-1);
@ -556,11 +560,14 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
retval = ipmi_print_user_list(intf, channel); retval = ipmi_print_user_list(intf, channel);
} else if (strncmp(argv[0], "test", 4) == 0) { } else if (strncmp(argv[0], "test", 4) == 0) {
/* Test */ /* Test */
/* a little irritating, isn't it */ char *password = NULL;
if (argc == 3 || argc == 4) {
char * password = NULL;
int password_length = 0; int password_length = 0;
uint8_t user_id = 0; uint8_t user_id = 0;
/* a little irritating, isn't it */
if (argc != 3 && argc != 4) {
print_user_usage();
return -1;
}
if (is_ipmi_user_id(argv[1], &user_id)) { if (is_ipmi_user_id(argv[1], &user_id)) {
return (-1); return (-1);
} }
@ -572,12 +579,10 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_ERR, "Expected value is either 16 or 20."); lprintf(LOG_ERR, "Expected value is either 16 or 20.");
return (-1); return (-1);
} }
if (argc == 3) { if (argc == 3) {
/* We need to prompt for a password */ /* We need to prompt for a password */
char *tmp;
char * tmp; const char *password_prompt =
const char * password_prompt =
ipmi_user_build_password_prompt(user_id); ipmi_user_build_password_prompt(user_id);
# ifdef HAVE_GETPASSPHRASE # ifdef HAVE_GETPASSPHRASE
tmp = getpassphrase (password_prompt); tmp = getpassphrase (password_prompt);
@ -603,10 +608,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
free(password); free(password);
password = NULL; password = NULL;
} }
} else {
print_user_usage();
return -1;
}
} else if (strncmp(argv[0], "set", 3) == 0) { } else if (strncmp(argv[0], "set", 3) == 0) {
/* Set */ /* Set */
if ((argc >= 3) if ((argc >= 3)
@ -704,7 +705,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
print_user_usage(); print_user_usage();
return -1; return -1;
} }
if (argc == 4) { if (argc == 4) {
if (str2uchar(argv[3], &channel) != 0) { if (str2uchar(argv[3], &channel) != 0) {
lprintf(LOG_ERR, "Invalid channel: %s", argv[3]); lprintf(LOG_ERR, "Invalid channel: %s", argv[3]);
@ -712,17 +712,14 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
} }
channel = (channel & 0x0f); channel = (channel & 0x0f);
} }
if (str2uchar(argv[2], &priv_level) != 0) { if (str2uchar(argv[2], &priv_level) != 0) {
lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]); lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]);
return (-1); return (-1);
} }
priv_level = (priv_level & 0x0f);
if (is_ipmi_user_id(argv[1], &user_id)) { if (is_ipmi_user_id(argv[1], &user_id)) {
return (-1); return (-1);
} }
priv_level = (priv_level & 0x0f);
retval = ipmi_user_set_userpriv(intf,channel,user_id,priv_level); retval = ipmi_user_set_userpriv(intf,channel,user_id,priv_level);
} else if ((strncmp(argv[0], "disable", 7) == 0) } else if ((strncmp(argv[0], "disable", 7) == 0)
|| (strncmp(argv[0], "enable", 6) == 0)) { || (strncmp(argv[0], "enable", 6) == 0)) {
@ -731,17 +728,14 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
uint8_t operation; uint8_t operation;
char null_password[16]; /* Not used, but required */ char null_password[16]; /* Not used, but required */
memset(null_password, 0, sizeof(null_password));
if (argc != 2) { if (argc != 2) {
print_user_usage(); print_user_usage();
return -1; return -1;
} }
if (is_ipmi_user_id(argv[1], &user_id)) { if (is_ipmi_user_id(argv[1], &user_id)) {
return (-1); return (-1);
} }
memset(null_password, 0, sizeof(null_password));
operation = (strncmp(argv[0], "disable", 7) == 0) ? operation = (strncmp(argv[0], "disable", 7) == 0) ?
IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER; IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER;