mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-07-02 18:53:45 +00:00
Compare commits
11 Commits
IPMITOOL_1
...
IPMITOOL_1
Author | SHA1 | Date | |
---|---|---|---|
5d58a9e2e5 | |||
b60c6cea30 | |||
c72e3333eb | |||
ac931daa86 | |||
3d4acbd829 | |||
3d790edc6e | |||
4e025b3e0e | |||
62f52f0598 | |||
f874a93ccb | |||
1f7ba3dd66 | |||
e298b0b99f |
@ -3,7 +3,7 @@ dnl autoconf for ipmitool
|
||||
dnl
|
||||
AC_INIT([src/ipmitool.c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
AM_INIT_AUTOMAKE([ipmitool], [1.6.0])
|
||||
AM_INIT_AUTOMAKE([ipmitool], [1.6.1])
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AC_CONFIG_SRCDIR([src/ipmitool.c])
|
||||
AC_PREREQ(2.50)
|
||||
@ -72,25 +72,33 @@ AC_SUBST(PSTAMP, $host)
|
||||
AC_SUBST(BASEDIR, $prefix)
|
||||
|
||||
dnl check for OpenSSL functionality
|
||||
AC_ARG_ENABLE([internal-md5],
|
||||
[AC_HELP_STRING([--enable-internal-md5],
|
||||
[enable internal MD5 library [default=no]])],
|
||||
[], [enable_internal_md5=no])
|
||||
|
||||
AC_CHECK_LIB([crypto], [EVP_aes_128_cbc],
|
||||
[have_crypto=yes; LIBS="$LIBS -lcrypto"],
|
||||
[have_crypto=no], [-lcrypto])
|
||||
[if test "x$enable_internal_md5" != "xyes"; then
|
||||
have_crypto=yes; LIBS="$LIBS -lcrypto"
|
||||
fi], [have_crypto=no], [-lcrypto])
|
||||
|
||||
AC_CHECK_LIB([crypto], [MD5_Init],
|
||||
[if test "x$have_crypto" != "xyes"; then
|
||||
LIBS="$LIBS -lcrypto"
|
||||
have_md5=yes
|
||||
fi
|
||||
AC_DEFINE(HAVE_CRYPTO_MD5, [1], [Define to 1 if libcrypto supports MD5.])],
|
||||
[], [-lcrypto])
|
||||
[if test "x$enable_internal_md5" != "xyes"; then
|
||||
if test "x$have_crypto" != "xyes"; then
|
||||
LIBS="$LIBS -lcrypto"
|
||||
have_md5=yes
|
||||
fi
|
||||
AC_DEFINE(HAVE_CRYPTO_MD5, [1], [Define to 1 if libcrypto supports MD5.])
|
||||
fi], [], [-lcrypto])
|
||||
|
||||
AC_CHECK_LIB([crypto], [MD2_Init],
|
||||
[if test "x$have_crypto" != "xyes" && test "x$have_md5" != "xyes"; then
|
||||
LIBS="$LIBS -lcrypto"
|
||||
have_md2=yes
|
||||
fi
|
||||
AC_DEFINE(HAVE_CRYPTO_MD2, [1], [Define to 1 if libcrypto supports MD2.])],
|
||||
[], [-lcrypto])
|
||||
[if test "x$enable_internal_md5" != "xyes"; then
|
||||
if test "x$have_crypto" != "xyes" && test "x$have_md5" != "xyes"; then
|
||||
LIBS="$LIBS -lcrypto"
|
||||
have_md2=yes
|
||||
fi
|
||||
AC_DEFINE(HAVE_CRYPTO_MD2, [1], [Define to 1 if libcrypto supports MD2.])
|
||||
fi], [], [-lcrypto])
|
||||
|
||||
dnl enable IPMIv1.5 LAN interface
|
||||
AC_ARG_ENABLE([intf-lan],
|
||||
@ -124,6 +132,8 @@ if test "x$enable_intf_lanplus" = "xyes"; then
|
||||
AC_SUBST(INTF_LANPLUS, [lanplus])
|
||||
AC_SUBST(INTF_LANPLUS_LIB, [libintf_lanplus.la])
|
||||
IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB lanplus/libintf_lanplus.la"
|
||||
else
|
||||
enable_intf_lanplus=no
|
||||
fi
|
||||
|
||||
dnl look for OpenIPMI header files
|
||||
|
@ -61,14 +61,14 @@ enum LANPLUS_SESSION_STATE {
|
||||
};
|
||||
|
||||
|
||||
#define IPMI_AUTHCODE_BUFFER_SIZE 16
|
||||
#define IPMI_AUTHCODE_BUFFER_SIZE 20
|
||||
#define IPMI_SIK_BUFFER_SIZE 20
|
||||
#define IPMI_KG_BUFFER_SIZE 21 /* key plus null byte */
|
||||
|
||||
struct ipmi_session {
|
||||
unsigned char hostname[64];
|
||||
unsigned char username[16];
|
||||
unsigned char authcode[IPMI_AUTHCODE_BUFFER_SIZE];
|
||||
unsigned char authcode[IPMI_AUTHCODE_BUFFER_SIZE + 1];
|
||||
unsigned char challenge[16];
|
||||
unsigned char authtype;
|
||||
unsigned char authtype_set;
|
||||
|
@ -107,6 +107,12 @@ set_lan_param_wait(struct ipmi_intf * intf, unsigned char chan, int param, unsig
|
||||
|
||||
for (;;) {
|
||||
p = get_lan_param(intf, chan, param);
|
||||
if (!p) {
|
||||
sleep(timeout);
|
||||
if (!retry--)
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
if (verbose > 1)
|
||||
printbuf(p->data, p->data_len, "READ DATA");
|
||||
if (p->data_len != len) {
|
||||
@ -158,8 +164,9 @@ __set_lan_param(struct ipmi_intf * intf, unsigned char chan, int param, unsigned
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode && wait) {
|
||||
printf("Warning: Set Lan Parameter failed: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
if (verbose)
|
||||
printf("Warning: Set Lan Parameter failed: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
if (rsp->ccode == 0xcc) {
|
||||
/* retry hack for invalid data field ccode */
|
||||
int timeout = 3; /* 3 second timeout */
|
||||
|
@ -146,6 +146,8 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned short e, f;
|
||||
int pctfull = 0;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
||||
@ -165,10 +167,18 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
printf("SEL Information\n");
|
||||
printf("Version : %x%x\n",
|
||||
(rsp->data[0] & 0xf0) >> 4, rsp->data[0] & 0xf);
|
||||
printf("Entries : %d\n",
|
||||
buf2short(rsp->data + 1));
|
||||
printf("Free Space : %d\n",
|
||||
buf2short(rsp->data + 3));
|
||||
|
||||
e = buf2short(rsp->data + 1);
|
||||
f = buf2short(rsp->data + 3);
|
||||
printf("Entries : %d\n", e);
|
||||
printf("Free Space : %d\n", f);
|
||||
if (e) {
|
||||
e *= 16;
|
||||
f += e;
|
||||
pctfull = (int)(100 * ( (double)e / (double)f ));
|
||||
}
|
||||
printf("Percent Used : %d%%\n", pctfull);
|
||||
|
||||
printf("Last Add Time : %s\n",
|
||||
ipmi_sel_timestamp(buf2long(rsp->data + 5)));
|
||||
printf("Last Del Time : %s\n",
|
||||
@ -241,8 +251,9 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, unsigned short id, struct sel_ev
|
||||
|
||||
|
||||
if (rsp->data[4] >= 0xc0) {
|
||||
printf("Not a standard SEL Entry!\n");
|
||||
return 0;
|
||||
if (verbose)
|
||||
printf("Entry %04xh not a standard SEL entry!\n", id);
|
||||
return (rsp->data[1] << 8) | rsp->data[0];
|
||||
}
|
||||
|
||||
memset(evt, 0, sizeof(*evt));
|
||||
@ -394,7 +405,7 @@ ipmi_sel_list_entries(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned short next_id = 0;
|
||||
unsigned short next_id = 0, curr_id = 0;
|
||||
struct sel_event_record evt;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
@ -431,13 +442,14 @@ ipmi_sel_list_entries(struct ipmi_intf * intf)
|
||||
}
|
||||
|
||||
while (next_id != 0xffff) {
|
||||
curr_id = next_id;
|
||||
if (verbose > 1)
|
||||
printf("SEL Next ID: %04x\n", next_id);
|
||||
printf("SEL Next ID: %04x\n", curr_id);
|
||||
|
||||
next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
|
||||
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
||||
if (!next_id) {
|
||||
/* retry */
|
||||
next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
|
||||
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
||||
if (!next_id)
|
||||
break;
|
||||
}
|
||||
|
@ -706,6 +706,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
||||
{
|
||||
data[2] = 0x00;
|
||||
}
|
||||
else if (!strcmp(value, "9.6"))
|
||||
{
|
||||
data[2] = 0x06;
|
||||
}
|
||||
else if (!strcmp(value, "19.2"))
|
||||
{
|
||||
data[2] = 0x07;
|
||||
@ -727,7 +731,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
||||
printf("Invalid value \"%s\" for parameter \"%s\"\n",
|
||||
value,
|
||||
param);
|
||||
printf("Valid values are serial, 19.2, 38.4, 57.6 and 115.2\n");
|
||||
printf("Valid values are serial, 9.6 19.2, 38.4, 57.6 and 115.2\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -745,6 +749,10 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
||||
{
|
||||
data[2] = 0x00;
|
||||
}
|
||||
else if (!strcmp(value, "9.6"))
|
||||
{
|
||||
data[2] = 0x06;
|
||||
}
|
||||
else if (!strcmp(value, "19.2"))
|
||||
{
|
||||
data[2] = 0x07;
|
||||
@ -766,7 +774,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
|
||||
printf("Invalid value \"%s\" for parameter \"%s\"\n",
|
||||
value,
|
||||
param);
|
||||
printf("Valid values are serial, 19.2, 38.4, 57.6 and 115.2\n");
|
||||
printf("Valid values are serial, 9.6 19.2, 38.4, 57.6 and 115.2\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1254,7 +1262,7 @@ ipmi_sol_activate(struct ipmi_intf * intf)
|
||||
* This command is only available over RMCP+ (the lanplus
|
||||
* interface).
|
||||
*/
|
||||
if (strncmp(intf->name, "intf_lanplus", 12))
|
||||
if (strncmp(intf->name, "lanplus", 7))
|
||||
{
|
||||
printf("Error: This command is only available over the "
|
||||
"lanplus interface\n");
|
||||
@ -1392,9 +1400,9 @@ print_sol_set_usage()
|
||||
printf(" retry-count N\n");
|
||||
printf(" retry-interval <in 10 ms increments>\n");
|
||||
printf(" non-volatile-bit-rate "
|
||||
"serial | 19.2 | 38.4 | 57.6 | 115.2\n");
|
||||
"serial | 9.6 | 19.2 | 38.4 | 57.6 | 115.2\n");
|
||||
printf(" volatile-bit-rate "
|
||||
"serial | 19.2 | 38.4 | 57.6 | 115.2\n");
|
||||
"serial | 9.6 | 19.2 | 38.4 | 57.6 | 115.2\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
@ -65,29 +65,29 @@ extern int csv_output;
|
||||
/*
|
||||
* ipmi_get_user_access
|
||||
*
|
||||
* param intf [in]
|
||||
* param intf [in]
|
||||
* param channel_number [in]
|
||||
* param user_id [in]
|
||||
* param user_access [out]
|
||||
* param user_id [in]
|
||||
* param user_access [out]
|
||||
*
|
||||
* return 0 on succes
|
||||
* 1 on failure
|
||||
* 1 on failure
|
||||
*/
|
||||
static int
|
||||
ipmi_get_user_access(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number,
|
||||
unsigned char user_id,
|
||||
struct user_access_rsp * user_access)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number,
|
||||
unsigned char user_id,
|
||||
struct user_access_rsp * user_access)
|
||||
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[2];
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[2];
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_GET_USER_ACCESS; /* 0x44 */
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_GET_USER_ACCESS; /* 0x44 */
|
||||
req.msg.data = msg_data;
|
||||
req.msg.data_len = 2;
|
||||
|
||||
@ -101,13 +101,13 @@ ipmi_get_user_access(
|
||||
if (!rsp || rsp->ccode)
|
||||
{
|
||||
printf("Error:%x Get User Access Command (user 0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, msg_data[1]);
|
||||
rsp ? rsp->ccode : 0, msg_data[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(user_access,
|
||||
rsp->data,
|
||||
sizeof(struct user_access_rsp));
|
||||
rsp->data,
|
||||
sizeof(struct user_access_rsp));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -117,28 +117,28 @@ ipmi_get_user_access(
|
||||
/*
|
||||
* ipmi_get_user_name
|
||||
*
|
||||
* param intf [in]
|
||||
* param intf [in]
|
||||
* param channel_number [in]
|
||||
* param user_id [in]
|
||||
* param user_name [out]
|
||||
* param user_id [in]
|
||||
* param user_name [out]
|
||||
*
|
||||
* return 0 on succes
|
||||
* 1 on failure
|
||||
* 1 on failure
|
||||
*/
|
||||
static int
|
||||
ipmi_get_user_name(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
char * user_name)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
char * user_name)
|
||||
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[1];
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[1];
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_GET_USER_NAME; /* 0x45 */
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_GET_USER_NAME; /* 0x45 */
|
||||
req.msg.data = msg_data;
|
||||
req.msg.data_len = 1;
|
||||
|
||||
@ -149,7 +149,7 @@ ipmi_get_user_name(
|
||||
if (!rsp || rsp->ccode)
|
||||
{
|
||||
printf("Error:%x Get User Name Command (user 0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, msg_data[0]);
|
||||
rsp ? rsp->ccode : 0, msg_data[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -163,54 +163,54 @@ ipmi_get_user_name(
|
||||
|
||||
static void
|
||||
dump_user_access(
|
||||
unsigned char user_id,
|
||||
const char * user_name,
|
||||
struct user_access_rsp * user_access)
|
||||
unsigned char user_id,
|
||||
const char * user_name,
|
||||
struct user_access_rsp * user_access)
|
||||
{
|
||||
static int printed_header = 0;
|
||||
|
||||
if (! printed_header)
|
||||
{
|
||||
printf("ID Name Callin Link Auth IPMI Msg "
|
||||
"Channel Priv Limit\n");
|
||||
printf("ID Name Callin Link Auth IPMI Msg "
|
||||
"Channel Priv Limit\n");
|
||||
printed_header = 1;
|
||||
}
|
||||
|
||||
|
||||
printf("%-4d%-17s%-8s%-11s%-11s%-s\n",
|
||||
user_id,
|
||||
user_name,
|
||||
user_access->no_callin_access? "false": "true ",
|
||||
user_access->link_auth_access? "true ": "false",
|
||||
user_access->ipmi_messaging_access? "true ": "false",
|
||||
val2str(user_access->channel_privilege_limit,
|
||||
ipmi_privlvl_vals));
|
||||
user_id,
|
||||
user_name,
|
||||
user_access->no_callin_access? "false": "true ",
|
||||
user_access->link_auth_access? "true ": "false",
|
||||
user_access->ipmi_messaging_access? "true ": "false",
|
||||
val2str(user_access->channel_privilege_limit,
|
||||
ipmi_privlvl_vals));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
dump_user_access_csv(
|
||||
unsigned char user_id,
|
||||
const char * user_name,
|
||||
struct user_access_rsp * user_access)
|
||||
unsigned char user_id,
|
||||
const char * user_name,
|
||||
struct user_access_rsp * user_access)
|
||||
{
|
||||
printf("%d,%s,%s,%s,%s,%s\n",
|
||||
user_id,
|
||||
user_name,
|
||||
user_access->no_callin_access? "false": "true",
|
||||
user_access->link_auth_access? "true": "false",
|
||||
user_access->ipmi_messaging_access? "true": "false",
|
||||
val2str(user_access->channel_privilege_limit,
|
||||
ipmi_privlvl_vals));
|
||||
user_id,
|
||||
user_name,
|
||||
user_access->no_callin_access? "false": "true",
|
||||
user_access->link_auth_access? "true": "false",
|
||||
user_access->ipmi_messaging_access? "true": "false",
|
||||
val2str(user_access->channel_privilege_limit,
|
||||
ipmi_privlvl_vals));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
ipmi_print_user_list(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number)
|
||||
{
|
||||
/* This is where you were! */
|
||||
char user_name[17];
|
||||
@ -221,33 +221,36 @@ ipmi_print_user_list(
|
||||
do
|
||||
{
|
||||
if (ipmi_get_user_access(intf,
|
||||
channel_number,
|
||||
current_user_id,
|
||||
&user_access))
|
||||
channel_number,
|
||||
current_user_id,
|
||||
&user_access))
|
||||
return -1;
|
||||
|
||||
|
||||
if (ipmi_get_user_name(intf,
|
||||
current_user_id,
|
||||
user_name))
|
||||
current_user_id,
|
||||
user_name))
|
||||
return -1;
|
||||
|
||||
|
||||
if ((current_user_id == 0) ||
|
||||
user_access.link_auth_access ||
|
||||
user_access.ipmi_messaging_access ||
|
||||
strcmp("", user_name))
|
||||
if ((current_user_id == 0) ||
|
||||
user_access.link_auth_access ||
|
||||
user_access.ipmi_messaging_access ||
|
||||
strcmp("", user_name))
|
||||
{
|
||||
if (csv_output)
|
||||
dump_user_access_csv(current_user_id, user_name, &user_access);
|
||||
dump_user_access_csv(current_user_id,
|
||||
user_name, &user_access);
|
||||
else
|
||||
dump_user_access(current_user_id, user_name, &user_access);
|
||||
dump_user_access(current_user_id,
|
||||
user_name,
|
||||
&user_access);
|
||||
}
|
||||
|
||||
|
||||
++current_user_id;
|
||||
} while((current_user_id < user_access.maximum_ids) &&
|
||||
(current_user_id < 63)); /* Absolute maximum allowed by spec */
|
||||
(current_user_id < 63)); /* Absolute maximum allowed by spec */
|
||||
|
||||
|
||||
return 0;
|
||||
@ -257,32 +260,32 @@ ipmi_print_user_list(
|
||||
|
||||
static int
|
||||
ipmi_print_user_summary(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char channel_number)
|
||||
{
|
||||
struct user_access_rsp user_access;
|
||||
|
||||
if (ipmi_get_user_access(intf,
|
||||
channel_number,
|
||||
1,
|
||||
&user_access))
|
||||
channel_number,
|
||||
1,
|
||||
&user_access))
|
||||
return -1;
|
||||
|
||||
if (csv_output)
|
||||
{
|
||||
printf("%d,%d,%d\n",
|
||||
user_access.maximum_ids,
|
||||
user_access.enabled_user_count,
|
||||
user_access.fixed_name_count);
|
||||
user_access.maximum_ids,
|
||||
user_access.enabled_user_count,
|
||||
user_access.fixed_name_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Maximum IDs : %d\n",
|
||||
user_access.maximum_ids);
|
||||
printf("Maximum IDs : %d\n",
|
||||
user_access.maximum_ids);
|
||||
printf("Enabled User Count : %d\n",
|
||||
user_access.enabled_user_count);
|
||||
user_access.enabled_user_count);
|
||||
printf("Fixed Name Count : %d\n",
|
||||
user_access.fixed_name_count);
|
||||
user_access.fixed_name_count);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -295,17 +298,17 @@ ipmi_print_user_summary(
|
||||
*/
|
||||
static int
|
||||
ipmi_user_set_username(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
const char * name)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
const char * name)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[17];
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[17];
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_SET_USER_NAME; /* 0x45 */
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_SET_USER_NAME; /* 0x45 */
|
||||
req.msg.data = msg_data;
|
||||
req.msg.data_len = 17;
|
||||
|
||||
@ -320,7 +323,7 @@ ipmi_user_set_username(
|
||||
if (!rsp || rsp->ccode)
|
||||
{
|
||||
printf("Error:%x Set User Name Command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
rsp ? rsp->ccode : 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -339,46 +342,91 @@ ipmi_user_set_username(
|
||||
*/
|
||||
static int
|
||||
ipmi_user_set_password(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
unsigned char operation,
|
||||
const char * password)
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
unsigned char operation,
|
||||
const char * password,
|
||||
int is_twenty_byte_password)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[18];
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
char * msg_data;
|
||||
int ret = 0;
|
||||
|
||||
int password_length = (is_twenty_byte_password? 20 : 16);
|
||||
|
||||
msg_data = (char*)malloc(password_length + 2);
|
||||
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_SET_USER_PASSWORD; /* 0x47 */
|
||||
req.msg.netfn = IPMI_NETFN_APP; /* 0x06 */
|
||||
req.msg.cmd = IPMI_SET_USER_PASSWORD; /* 0x47 */
|
||||
req.msg.data = msg_data;
|
||||
req.msg.data_len = 18;
|
||||
req.msg.data_len = password_length + 2;
|
||||
|
||||
|
||||
/* The channel number will remain constant throughout this function */
|
||||
msg_data[0] = user_id;
|
||||
|
||||
if (is_twenty_byte_password)
|
||||
msg_data[0] |= 0x80;
|
||||
|
||||
msg_data[1] = operation;
|
||||
|
||||
memset(msg_data + 2, 0, 16);
|
||||
memset(msg_data + 2, 0, password_length);
|
||||
|
||||
if (password)
|
||||
strcpy(msg_data + 2, password);
|
||||
strncpy(msg_data + 2, password, password_length);
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode)
|
||||
{
|
||||
printf("Error:%x Set User Password Command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
return -1;
|
||||
rsp ? rsp->ccode : 0);
|
||||
ret = (rsp? rsp->ccode : -1);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ipmi_user_test_password
|
||||
*
|
||||
* Call ipmi_user_set_password, and interpret the result
|
||||
*/
|
||||
static int
|
||||
ipmi_user_test_password(
|
||||
struct ipmi_intf * intf,
|
||||
unsigned char user_id,
|
||||
const char * password,
|
||||
int is_twenty_byte_password)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ipmi_user_set_password(intf,
|
||||
user_id,
|
||||
IPMI_PASSWORD_TEST_PASSWORD,
|
||||
password,
|
||||
is_twenty_byte_password);
|
||||
|
||||
if (! ret)
|
||||
printf("Success\n");
|
||||
else if (ret == 0x80)
|
||||
printf("Failure: password incorrect\n");
|
||||
else if (ret == 0x81)
|
||||
printf("Failure: wrong password size\n");
|
||||
else
|
||||
printf("Unknown error\n");
|
||||
|
||||
return (ret ? -1 : 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* print_user_usage
|
||||
*/
|
||||
@ -387,29 +435,17 @@ print_user_usage()
|
||||
{
|
||||
printf("\n");
|
||||
printf("User Commands: summary [<channel number>]\n");
|
||||
printf(" list [<channel number>]\n");
|
||||
printf(" set name <user id> <username>\n");
|
||||
printf(" set password <user id> [<password>]\n");
|
||||
printf(" disable <user id> [<channel number>]\n");
|
||||
printf(" enable <user id> [<channel number>]\n");
|
||||
|
||||
printf(" list [<channel number>]\n");
|
||||
printf(" set name <user id> <username>\n");
|
||||
printf(" set password <user id> [<password>]\n");
|
||||
printf(" disable <user id> [<channel number>]\n");
|
||||
printf(" enable <user id> [<channel number>]\n");
|
||||
printf(" test <user id> <16|20> [<password]>\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void
|
||||
print_user_set_usage()
|
||||
{
|
||||
printf("\nUser set parameters and values: \n\n");
|
||||
printf(" name <character string (max 16 chars)>\n");
|
||||
printf(" password <password string (max 16 chars)>\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
ipmi_user_build_password_prompt(unsigned char user_id)
|
||||
@ -462,7 +498,7 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
/*
|
||||
* List
|
||||
*/
|
||||
else if (!strncmp(argv[0], "list", 4)) {
|
||||
else if (!strncmp(argv[0], "list", 4)) {
|
||||
unsigned char channel;
|
||||
|
||||
if (argc == 1)
|
||||
@ -478,6 +514,67 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
retval = ipmi_print_user_list(intf, channel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Test
|
||||
*/
|
||||
else if (!strncmp(argv[0], "test", 4))
|
||||
{
|
||||
// a little fucking irritating, isn't it
|
||||
if ((argc == 3 || argc == 4) &&
|
||||
((!strncmp(argv[2], "16", 2)) ||
|
||||
(!strncmp(argv[2], "20", 2))))
|
||||
{
|
||||
char * password = NULL;
|
||||
int password_length = atoi(argv[2]);
|
||||
unsigned char user_id = (unsigned char)strtol(argv[1],
|
||||
NULL,
|
||||
0);
|
||||
if (! user_id)
|
||||
{
|
||||
printf("Error. Invalid user ID: %d\n", user_id);
|
||||
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
|
||||
if ((tmp = getpassphrase (password_prompt)))
|
||||
#else
|
||||
if ((tmp = (char*)getpass(password_prompt)))
|
||||
#endif
|
||||
{
|
||||
password = strdup(tmp);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
password = argv[3];
|
||||
|
||||
|
||||
retval = ipmi_user_test_password(intf,
|
||||
user_id,
|
||||
password,
|
||||
password_length == 20);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set
|
||||
@ -487,13 +584,13 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
/*
|
||||
* Set Password
|
||||
*/
|
||||
if ((argc >= 3) &&
|
||||
(! strcmp("password", argv[1])))
|
||||
if ((argc >= 3) &&
|
||||
(! strcmp("password", argv[1])))
|
||||
{
|
||||
char * password = NULL;
|
||||
unsigned char user_id = (unsigned char)strtol(argv[2],
|
||||
NULL,
|
||||
0);
|
||||
NULL,
|
||||
0);
|
||||
if (! user_id)
|
||||
{
|
||||
printf("Error. Invalid user ID: %d\n", user_id);
|
||||
@ -520,23 +617,32 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
#ifdef HAVE_GETPASSPHRASE
|
||||
if ((tmp = getpassphrase (password_prompt)))
|
||||
#else
|
||||
if ((tmp = (char*)getpass (password_prompt)))
|
||||
if ((tmp = (char*)getpass (password_prompt)))
|
||||
#endif
|
||||
{
|
||||
if (strcmp(password, tmp))
|
||||
{
|
||||
printf("Error. Passwords to not match.\n");
|
||||
return -1;
|
||||
if (strcmp(password, tmp))
|
||||
{
|
||||
printf("Error. Passwords to not match.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
password = argv[3];
|
||||
|
||||
if (strlen(password) > 20)
|
||||
{
|
||||
printf("Error. Password is too long (> 20 bytes).\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
retval = ipmi_user_set_password(intf,
|
||||
user_id,
|
||||
IPMI_PASSWORD_SET_PASSWORD,
|
||||
argc == 4? argv[3]: password);
|
||||
user_id,
|
||||
IPMI_PASSWORD_SET_PASSWORD,
|
||||
password,
|
||||
strlen(password) > 16);
|
||||
}
|
||||
|
||||
|
||||
@ -544,23 +650,23 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
* Set Name
|
||||
*/
|
||||
else if ((argc >= 2) &&
|
||||
(! strcmp("name", argv[1])))
|
||||
(! strcmp("name", argv[1])))
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
print_user_set_usage();
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = ipmi_user_set_username(intf,
|
||||
(unsigned char)strtol(argv[2],
|
||||
NULL,
|
||||
0),
|
||||
argv[3]);
|
||||
(unsigned char)strtol(argv[2],
|
||||
NULL,
|
||||
0),
|
||||
argv[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print_user_set_usage();
|
||||
print_user_usage();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -570,7 +676,7 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
* Disable / Enable
|
||||
*/
|
||||
else if ((!strncmp(argv[0], "disable", 7)) ||
|
||||
(!strncmp(argv[0], "enable", 6)))
|
||||
(!strncmp(argv[0], "enable", 6)))
|
||||
{
|
||||
unsigned char user_id;
|
||||
unsigned char operation;
|
||||
@ -585,8 +691,8 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
|
||||
user_id = (unsigned char)strtol(argv[1],
|
||||
NULL,
|
||||
0);
|
||||
NULL,
|
||||
0);
|
||||
if (! user_id)
|
||||
{
|
||||
printf("Error. Invalid user ID: %d\n", user_id);
|
||||
@ -598,12 +704,14 @@ ipmi_user_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
IPMI_PASSWORD_DISABLE_USER: IPMI_PASSWORD_ENABLE_USER;
|
||||
|
||||
retval = ipmi_user_set_password(intf,
|
||||
user_id,
|
||||
operation,
|
||||
null_password);
|
||||
user_id,
|
||||
operation,
|
||||
null_password,
|
||||
0); /* This field is ignored */
|
||||
}
|
||||
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
print_user_usage();
|
||||
|
@ -146,11 +146,13 @@ void ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
|
||||
void ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
|
||||
{
|
||||
if (intf && intf->session) {
|
||||
memset(intf->session->authcode, 0, 16);
|
||||
memset(intf->session->authcode, 0, sizeof(intf->session->authcode));
|
||||
intf->session->password = 0;
|
||||
if (password) {
|
||||
intf->session->password = 1;
|
||||
memcpy(intf->session->authcode, password, min(strlen(password), 16));
|
||||
memcpy(intf->session->authcode,
|
||||
password,
|
||||
min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user