mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
Code cleanup in ipmi_user_main()
This is just a tip of an iceberg, really.
This commit is contained in:
parent
3c34aa0e1d
commit
2aa5d8c902
112
lib/ipmi_user.c
112
lib/ipmi_user.c
@ -520,7 +520,12 @@ int
|
||||
ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
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 */
|
||||
print_user_usage();
|
||||
} 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;
|
||||
if (argc == 1) {
|
||||
channel = 0x0E; /* Ask about the current channel */
|
||||
}
|
||||
else if (argc == 2) {
|
||||
} else if (argc == 2) {
|
||||
if (str2uchar(argv[1], &channel) != 0) {
|
||||
lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
|
||||
return (-1);
|
||||
@ -556,57 +560,54 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
retval = ipmi_print_user_list(intf, channel);
|
||||
} else if (strncmp(argv[0], "test", 4) == 0) {
|
||||
/* Test */
|
||||
char *password = NULL;
|
||||
int password_length = 0;
|
||||
uint8_t user_id = 0;
|
||||
/* a little irritating, isn't it */
|
||||
if (argc == 3 || argc == 4) {
|
||||
char * password = NULL;
|
||||
int password_length = 0;
|
||||
uint8_t user_id = 0;
|
||||
if (is_ipmi_user_id(argv[1], &user_id)) {
|
||||
return (-1);
|
||||
}
|
||||
if (str2int(argv[2], &password_length) != 0
|
||||
|| (password_length != 16 && password_length != 20)) {
|
||||
lprintf(LOG_ERR,
|
||||
"Given password length '%s' is invalid.",
|
||||
argv[2]);
|
||||
lprintf(LOG_ERR, "Expected value is either 16 or 20.");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (argc == 3) {
|
||||
/* We need to prompt for a password */
|
||||
|
||||
char * tmp;
|
||||
const char * password_prompt =
|
||||
ipmi_user_build_password_prompt(user_id);
|
||||
# ifdef HAVE_GETPASSPHRASE
|
||||
tmp = getpassphrase (password_prompt);
|
||||
# else
|
||||
tmp = (char*)getpass (password_prompt);
|
||||
# endif
|
||||
if (tmp != NULL) {
|
||||
password = strdup(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
password = strdup(argv[3]);
|
||||
}
|
||||
retval = ipmi_user_test_password(intf,
|
||||
user_id,
|
||||
password,
|
||||
password_length == 20);
|
||||
if (password != NULL) {
|
||||
free(password);
|
||||
password = NULL;
|
||||
}
|
||||
} else {
|
||||
if (argc != 3 && argc != 4) {
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
if (is_ipmi_user_id(argv[1], &user_id)) {
|
||||
return (-1);
|
||||
}
|
||||
if (str2int(argv[2], &password_length) != 0
|
||||
|| (password_length != 16 && password_length != 20)) {
|
||||
lprintf(LOG_ERR,
|
||||
"Given password length '%s' is invalid.",
|
||||
argv[2]);
|
||||
lprintf(LOG_ERR, "Expected value is either 16 or 20.");
|
||||
return (-1);
|
||||
}
|
||||
if (argc == 3) {
|
||||
/* We need to prompt for a password */
|
||||
char *tmp;
|
||||
const char *password_prompt =
|
||||
ipmi_user_build_password_prompt(user_id);
|
||||
# ifdef HAVE_GETPASSPHRASE
|
||||
tmp = getpassphrase (password_prompt);
|
||||
# else
|
||||
tmp = (char*)getpass (password_prompt);
|
||||
# endif
|
||||
if (tmp != NULL) {
|
||||
password = strdup(tmp);
|
||||
tmp = NULL;
|
||||
}
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
password = strdup(argv[3]);
|
||||
}
|
||||
retval = ipmi_user_test_password(intf,
|
||||
user_id,
|
||||
password,
|
||||
password_length == 20);
|
||||
if (password != NULL) {
|
||||
free(password);
|
||||
password = NULL;
|
||||
}
|
||||
} else if (strncmp(argv[0], "set", 3) == 0) {
|
||||
/* Set */
|
||||
if ((argc >= 3)
|
||||
@ -704,7 +705,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
if (str2uchar(argv[3], &channel) != 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (str2uchar(argv[2], &priv_level) != 0) {
|
||||
lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]);
|
||||
return (-1);
|
||||
}
|
||||
priv_level = (priv_level & 0x0f);
|
||||
|
||||
if (is_ipmi_user_id(argv[1], &user_id)) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
priv_level = (priv_level & 0x0f);
|
||||
retval = ipmi_user_set_userpriv(intf,channel,user_id,priv_level);
|
||||
} else if ((strncmp(argv[0], "disable", 7) == 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;
|
||||
char null_password[16]; /* Not used, but required */
|
||||
|
||||
memset(null_password, 0, sizeof(null_password));
|
||||
|
||||
if (argc != 2) {
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_ipmi_user_id(argv[1], &user_id)) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
memset(null_password, 0, sizeof(null_password));
|
||||
operation = (strncmp(argv[0], "disable", 7) == 0) ?
|
||||
IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user