mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
fix segfault and channel problem with user priv command
This commit is contained in:
parent
533582e9e3
commit
520aa05c07
@ -72,11 +72,10 @@ extern int csv_output;
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ipmi_get_user_access(
|
ipmi_get_user_access(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf *intf,
|
||||||
uint8_t channel_number,
|
uint8_t channel_number,
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
struct user_access_rsp * user_access)
|
struct user_access_rsp *user_access)
|
||||||
|
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
@ -129,10 +128,9 @@ ipmi_get_user_access(
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ipmi_get_user_name(
|
ipmi_get_user_name(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf *intf,
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
char * user_name)
|
char *user_name)
|
||||||
|
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
@ -141,8 +139,8 @@ ipmi_get_user_name(
|
|||||||
memset(user_name, 0, 17);
|
memset(user_name, 0, 17);
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||||
req.msg.cmd = IPMI_GET_USER_NAME; /* 0x45 */
|
req.msg.cmd = IPMI_GET_USER_NAME; /* 0x45 */
|
||||||
req.msg.data = msg_data;
|
req.msg.data = msg_data;
|
||||||
req.msg.data_len = 1;
|
req.msg.data_len = 1;
|
||||||
|
|
||||||
@ -186,7 +184,6 @@ dump_user_access(
|
|||||||
printed_header = 1;
|
printed_header = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("%-4d%-17s%-8s%-11s%-11s%-s\n",
|
printf("%-4d%-17s%-8s%-11s%-11s%-s\n",
|
||||||
user_id,
|
user_id,
|
||||||
user_name,
|
user_name,
|
||||||
@ -201,9 +198,9 @@ dump_user_access(
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
dump_user_access_csv(
|
dump_user_access_csv(
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
const char * user_name,
|
const char *user_name,
|
||||||
struct user_access_rsp * user_access)
|
struct user_access_rsp *user_access)
|
||||||
{
|
{
|
||||||
printf("%d,%s,%s,%s,%s,%s\n",
|
printf("%d,%s,%s,%s,%s,%s\n",
|
||||||
user_id,
|
user_id,
|
||||||
@ -219,8 +216,8 @@ dump_user_access_csv(
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
ipmi_print_user_list(
|
ipmi_print_user_list(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf *intf,
|
||||||
uint8_t channel_number)
|
uint8_t channel_number)
|
||||||
{
|
{
|
||||||
/* This is where you were! */
|
/* This is where you were! */
|
||||||
char user_name[17];
|
char user_name[17];
|
||||||
@ -242,7 +239,6 @@ ipmi_print_user_list(
|
|||||||
user_name))
|
user_name))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
if ((current_user_id == 0) ||
|
if ((current_user_id == 0) ||
|
||||||
user_access.link_auth_access ||
|
user_access.link_auth_access ||
|
||||||
user_access.ipmi_messaging_access ||
|
user_access.ipmi_messaging_access ||
|
||||||
@ -308,9 +304,9 @@ ipmi_print_user_summary(
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ipmi_user_set_username(
|
ipmi_user_set_username(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf *intf,
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
const char * name)
|
const char *name)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
@ -344,25 +340,23 @@ ipmi_user_set_username(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ipmi_user_set_userpriv(
|
ipmi_user_set_userpriv(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf *intf,
|
||||||
uint8_t channel,
|
uint8_t channel,
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
const unsigned char privLevel)
|
const unsigned char privLevel)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs *rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
uint8_t msg_data[3];
|
uint8_t msg_data[3];
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||||
req.msg.cmd = IPMI_SET_USER_ACCESS; /* 0x43 */
|
req.msg.cmd = IPMI_SET_USER_ACCESS; /* 0x43 */
|
||||||
req.msg.data = msg_data;
|
req.msg.data = msg_data;
|
||||||
req.msg.data_len = 3;
|
req.msg.data_len = 3;
|
||||||
|
|
||||||
|
|
||||||
/* The channel number will remain constant throughout this function */
|
/* The channel number will remain constant throughout this function */
|
||||||
msg_data[0] = (channel & 0x0f); /* Do not change any bytes */
|
msg_data[0] = (channel & 0x0f); /* Do not change any bytes */
|
||||||
msg_data[1] = (user_id & 0x3f);
|
msg_data[1] = (user_id & 0x3f);
|
||||||
@ -371,13 +365,13 @@ ipmi_user_set_userpriv(
|
|||||||
rsp = intf->sendrecv(intf, &req);
|
rsp = intf->sendrecv(intf, &req);
|
||||||
|
|
||||||
if (rsp == NULL)
|
if (rsp == NULL)
|
||||||
{
|
{
|
||||||
lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
|
lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
|
||||||
user_id);
|
user_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (rsp->ccode > 0)
|
if (rsp->ccode > 0)
|
||||||
{
|
{
|
||||||
lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
|
lprintf(LOG_ERR, "Set Privilege Level command failed (user %d)",
|
||||||
user_id);
|
user_id);
|
||||||
return -1;
|
return -1;
|
||||||
@ -386,7 +380,6 @@ ipmi_user_set_userpriv(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ipmi_user_set_password
|
* ipmi_user_set_password
|
||||||
*
|
*
|
||||||
@ -397,10 +390,10 @@ ipmi_user_set_userpriv(
|
|||||||
static int
|
static int
|
||||||
ipmi_user_set_password(
|
ipmi_user_set_password(
|
||||||
struct ipmi_intf * intf,
|
struct ipmi_intf * intf,
|
||||||
uint8_t user_id,
|
uint8_t user_id,
|
||||||
uint8_t operation,
|
uint8_t operation,
|
||||||
const char * password,
|
const char *password,
|
||||||
int is_twenty_byte_password)
|
int is_twenty_byte_password)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
@ -487,7 +480,6 @@ ipmi_user_test_password(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print_user_usage
|
* print_user_usage
|
||||||
*/
|
*/
|
||||||
@ -590,8 +582,8 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
char * password = NULL;
|
char * password = NULL;
|
||||||
int password_length = atoi(argv[2]);
|
int password_length = atoi(argv[2]);
|
||||||
uint8_t user_id = (uint8_t)strtol(argv[1],
|
uint8_t user_id = (uint8_t)strtol(argv[1],
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
if (user_id == 0)
|
if (user_id == 0)
|
||||||
{
|
{
|
||||||
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
||||||
@ -606,7 +598,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
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);
|
||||||
#else
|
#else
|
||||||
@ -637,7 +628,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set
|
* Set
|
||||||
*/
|
*/
|
||||||
@ -651,8 +641,8 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
{
|
{
|
||||||
char * password = NULL;
|
char * password = NULL;
|
||||||
uint8_t user_id = (uint8_t)strtol(argv[2],
|
uint8_t user_id = (uint8_t)strtol(argv[2],
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
if (user_id == 0)
|
if (user_id == 0)
|
||||||
{
|
{
|
||||||
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
||||||
@ -710,7 +700,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
retval = ipmi_user_set_password(intf,
|
retval = ipmi_user_set_password(intf,
|
||||||
user_id,
|
user_id,
|
||||||
IPMI_PASSWORD_SET_PASSWORD,
|
IPMI_PASSWORD_SET_PASSWORD,
|
||||||
@ -718,7 +707,6 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
strlen(password) > 16);
|
strlen(password) > 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set Name
|
* Set Name
|
||||||
*/
|
*/
|
||||||
@ -733,8 +721,8 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
|
|
||||||
retval = ipmi_user_set_username(intf,
|
retval = ipmi_user_set_username(intf,
|
||||||
(uint8_t)strtol(argv[2],
|
(uint8_t)strtol(argv[2],
|
||||||
NULL,
|
NULL,
|
||||||
0),
|
0),
|
||||||
argv[3]);
|
argv[3]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -742,31 +730,29 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
print_user_usage();
|
print_user_usage();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strncmp(argv[0], "priv", 4) == 0)
|
else if (strncmp(argv[0], "priv", 4) == 0)
|
||||||
{
|
{
|
||||||
uint8_t user_id;
|
uint8_t user_id;
|
||||||
uint8_t priv_level;
|
uint8_t priv_level;
|
||||||
uint8_t channel = 0x0e; /* Use channel running on */
|
uint8_t channel = 0x0e; /* Use channel running on */
|
||||||
|
|
||||||
if (
|
if (argc != 3 && argc != 4)
|
||||||
(argc != 3) &&
|
{
|
||||||
(argc != 4)
|
print_user_usage();
|
||||||
)
|
return -1;
|
||||||
|
}
|
||||||
|
if (argc == 4)
|
||||||
if (argc == 4)
|
{
|
||||||
{
|
channel = (uint8_t)strtol(argv[3], NULL, 0);
|
||||||
channel = (uint8_t)strtol(argv[3], NULL, 0);
|
channel = (channel & 0x0f);
|
||||||
channel = (channel & 0x0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user_id = (uint8_t)strtol(argv[1], NULL, 0);
|
user_id = (uint8_t)strtol(argv[1], NULL, 0);
|
||||||
|
|
||||||
priv_level = (uint8_t)strtol(argv[2], NULL, 0);
|
priv_level = (uint8_t)strtol(argv[2], NULL, 0);
|
||||||
priv_level = (priv_level & 0x0f);
|
priv_level = (priv_level & 0x0f);
|
||||||
|
|
||||||
if (user_id == 0)
|
if (user_id == 0)
|
||||||
{
|
{
|
||||||
@ -775,7 +761,7 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
retval = ipmi_user_set_userpriv(intf,channel,user_id,priv_level);
|
retval = ipmi_user_set_userpriv(intf,channel,user_id,priv_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disable / Enable
|
* Disable / Enable
|
||||||
@ -796,8 +782,8 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
user_id = (uint8_t)strtol(argv[1],
|
user_id = (uint8_t)strtol(argv[1],
|
||||||
NULL,
|
NULL,
|
||||||
0);
|
0);
|
||||||
if (user_id == 0)
|
if (user_id == 0)
|
||||||
{
|
{
|
||||||
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
lprintf(LOG_ERR, "Invalid user ID: %d", user_id);
|
||||||
@ -814,14 +800,12 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
null_password,
|
null_password,
|
||||||
0); /* This field is ignored */
|
0); /* This field is ignored */
|
||||||
}
|
}
|
||||||
|
else
|
||||||
else
|
{
|
||||||
{
|
retval = -1;
|
||||||
retval = -1;
|
lprintf(LOG_ERR, "Invalid user command: '%s'\n", argv[0]);
|
||||||
lprintf(LOG_ERR, "Invalid user command: '%s'\n", argv[0]);
|
print_user_usage();
|
||||||
print_user_usage();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user