From: Zdenek S. <st...@us...> - 2016-07-31 07:03:56
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "ipmitool". The branch, master has been updated via 2c99bf69ec4398f4281d7e670837f8a2395de57f (commit) via 34711329c2fa7a5f97a7e8770497027dae5701c4 (commit) via 2f76ab3d3aaf3aa3b9e567d6e4328b8927110d92 (commit) via 7f8d37493facde42c4f953061c6dee7227d6ddde (commit) via f9211f8ed977f20c4601f00d0cc56724ebdff04a (commit) via ea46724878894fbe06130b1cd3824e3582d1020a (commit) via 9a6ba646511b6290214158f96ce93340db90f7a1 (commit) via f8a711b9e8a06bd73c8565634be69bc37066683d (commit) via fcf7445bcebdda167a561a54f598b1480b1bfabd (commit) from a3bec1d3658c67f366e1f584abcb5d7a4b5fdce6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2c99bf69ec4398f4281d7e670837f8a2395de57f Author: Zdenek Styblik <st...@tu...> Date: Sun Jul 31 08:56:38 2016 +0200 Fix missing `goto out_free;` when ipmi_parse_hex() returns (-1) diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c index 2ea3c26..811c80b 100644 --- a/lib/ipmi_main.c +++ b/lib/ipmi_main.c @@ -499,10 +499,11 @@ ipmi_main(int argc, char ** argv, break; case 'y': memset(kgkey, 0, sizeof(kgkey)); - rc = ipmi_parse_hex(optarg, kgkey, sizeof(kgkey) - 1); + rc = ipmi_parse_hex(optarg, kgkey, sizeof(kgkey) - 1); if (rc == -1) { lprintf(LOG_ERR, "Number of Kg key characters is not even"); + goto out_free; } else if (rc == -3) { lprintf(LOG_ERR, "Kg key is not hexadecimal number"); goto out_free; commit 34711329c2fa7a5f97a7e8770497027dae5701c4 Author: Dmitry Rakhchev <rd...@pi...> Date: Mon Jul 4 18:28:21 2016 +0300 Add mac2str() and str2mac() to print/parse MAC address diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h index 81b8825..bfaf284 100644 --- a/include/ipmitool/helper.h +++ b/include/ipmitool/helper.h @@ -100,6 +100,8 @@ uint32_t buf2long(uint8_t * buf); #define BUF2STR_MAXIMUM_OUTPUT_SIZE (3*1024 + 1) const char * buf2str_extended(const uint8_t *buf, int len, const char *sep); const char * buf2str(const uint8_t *buf, int len); +int str2mac(const char *arg, uint8_t *buf); +const char * mac2str(const uint8_t *buf); int ipmi_parse_hex(const char *str, uint8_t *out, int size); void printbuf(const uint8_t * buf, int len, const char * desc); uint8_t ipmi_csum(uint8_t * d, int s); diff --git a/lib/helper.c b/lib/helper.c index ad5a898..de91438 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -234,6 +234,53 @@ void printbuf(const uint8_t * buf, int len, const char * desc) fprintf(stderr, "\n"); } +/* str2mac - parse-out MAC address from given string and store it + * into buffer. + * + * @arg: string to be parsed. + * @buf: buffer of 6 to hold parsed MAC address. + * + * returns zero on success, (-1) on error and error message is printed-out. + */ +int +str2mac(const char *arg, uint8_t *buf) +{ + unsigned int m1 = 0; + unsigned int m2 = 0; + unsigned int m3 = 0; + unsigned int m4 = 0; + unsigned int m5 = 0; + unsigned int m6 = 0; + if (sscanf(arg, "%02x:%02x:%02x:%02x:%02x:%02x", + &m1, &m2, &m3, &m4, &m5, &m6) != 6) { + lprintf(LOG_ERR, "Invalid MAC address: %s", arg); + return -1; + } + if (m1 > UINT8_MAX || m2 > UINT8_MAX + || m3 > UINT8_MAX || m4 > UINT8_MAX + || m5 > UINT8_MAX || m6 > UINT8_MAX) { + lprintf(LOG_ERR, "Invalid MAC address: %s", arg); + return -1; + } + buf[0] = (uint8_t)m1; + buf[1] = (uint8_t)m2; + buf[2] = (uint8_t)m3; + buf[3] = (uint8_t)m4; + buf[4] = (uint8_t)m5; + buf[5] = (uint8_t)m6; + return 0; +} + +/* mac2str -- return MAC address as a string + * + * @buf: buffer of 6 to hold parsed MAC address. + */ +const char * +mac2str(const uint8_t *buf) +{ + return buf2str_extended(buf, 6, ":"); +} + const char * val2str(uint16_t val, const struct valstr *vs) { static char un_str[32]; diff --git a/lib/ipmi_delloem.c b/lib/ipmi_delloem.c index b253e3e..bc78c1d 100644 --- a/lib/ipmi_delloem.c +++ b/lib/ipmi_delloem.c @@ -1652,11 +1652,7 @@ ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum) printf("\niDRAC6 MAC Address "); } - for (j = 0; j < 5; j++) { - printf("%02x:", VirtualMacAddress[j]); - } - printf("%02x", VirtualMacAddress[j]); - printf("\n"); + printf("%s\n", mac2str(VirtualMacAddress)); return 0; } /* @@ -1724,11 +1720,7 @@ ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum) printf("\niDRAC6 MAC Address "); } - for (j = 0; j < 5; j++) { - printf("%02x:", iDRAC6MacAddressByte[j]); - } - printf("%02x", iDRAC6MacAddressByte[j]); - printf("\n"); + printf("%s\n", mac2str(iDRAC6MacAddressByte)); return 0; } /* @@ -1786,13 +1778,8 @@ ipmi_macinfo_10g(struct ipmi_intf* intf, uint8_t NicNum) for (i = 0; i < Total_No_NICs; i++) { if ((0xff == NicNum) || (i == NicNum)) { printf("\n%d",i); - printf("\t\t"); - for (j = 0 ; j < 5; j++) { - printf("%02x:", - EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte[j]); - } - printf("%02x", - EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte[j]); + printf("\t\t%s", + mac2str(EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte)); } } printf("\n"); @@ -1889,13 +1876,7 @@ ipmi_macinfo_11g(struct ipmi_intf* intf, uint8_t NicNum) if ((0xff==NicNum) || (NicNum == EmbeddedNICMacAddress.LOMMacAddress[i].NICNumber)) { printf("\n%d",EmbeddedNICMacAddress.LOMMacAddress[i].NICNumber); - printf("\t\t"); - for (j = 0; j < 5; j++) { - printf("%02x:", - EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte[j]); - } - printf("%02x", - EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte[j]); + printf("\t\t%s", mac2str(EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte)); if (LOM_ETHERNET_ENABLED == EmbeddedNICMacAddress.LOMMacAddress[i].EthernetStatus) { diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c index ce6af4a..16a3a3e 100644 --- a/lib/ipmi_lanp.c +++ b/lib/ipmi_lanp.c @@ -704,8 +704,7 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) if (p == NULL) return -1; if (p->data != NULL) - printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc, - p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]); + printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING); if (p == NULL) @@ -744,8 +743,7 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) if (p == NULL) return -1; if (p->data != NULL) - printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc, - p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]); + printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP); if (p == NULL) @@ -758,8 +756,7 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) if (p == NULL) return -1; if (p->data != NULL) - printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc, - p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]); + printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID); if (p != NULL && p->data != NULL) { @@ -1103,42 +1100,6 @@ ipmi_set_user_access(struct ipmi_intf *intf, uint8_t channel, uint8_t user_id) } } -/* get_cmdline_macaddr - parse-out MAC address from given string and store it - * into buffer. - * - * @arg: string to be parsed. - * @buf: buffer of 6 to hold parsed MAC address. - * - * returns zero on success, (-1) on error and error message is printed-out. - */ -static int -get_cmdline_macaddr(char *arg, uint8_t *buf) -{ - uint32_t m1 = 0; - uint32_t m2 = 0; - uint32_t m3 = 0; - uint32_t m4 = 0; - uint32_t m5 = 0; - uint32_t m6 = 0; - if (sscanf(arg, "%02x:%02x:%02x:%02x:%02x:%02x", - &m1, &m2, &m3, &m4, &m5, &m6) != 6) { - lprintf(LOG_ERR, "Invalid MAC address: %s", arg); - return -1; - } - if (m1 > UINT8_MAX || m2 > UINT8_MAX - || m3 > UINT8_MAX || m4 > UINT8_MAX - || m5 > UINT8_MAX || m6 > UINT8_MAX) { - lprintf(LOG_ERR, "Invalid MAC address: %s", arg); - return -1; - } - buf[0] = (uint8_t)m1; - buf[1] = (uint8_t)m2; - buf[2] = (uint8_t)m3; - buf[3] = (uint8_t)m4; - buf[4] = (uint8_t)m5; - buf[5] = (uint8_t)m6; - return 0; -} static int @@ -1540,11 +1501,11 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv) print_lan_set_usage(); return -1; } - rc = get_cmdline_macaddr(argv[2], data); + rc = str2mac(argv[2], data); if (rc == 0) { - printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n", - ipmi_lan_params[IPMI_LANP_MAC_ADDR].desc, - data[0], data[1], data[2], data[3], data[4], data[5]); + printf("Setting LAN %s to %s\n", + ipmi_lan_params[IPMI_LANP_MAC_ADDR].desc, + mac2str(data)); rc = set_lan_param(intf, chan, IPMI_LANP_MAC_ADDR, data, 6); } } @@ -1566,10 +1527,10 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv) rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP, data, 4); } else if ((strncmp(argv[2], "macaddr", 7) == 0) && - (get_cmdline_macaddr(argv[3], data) == 0)) { - printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n", - ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc, - data[0], data[1], data[2], data[3], data[4], data[5]); + (str2mac(argv[3], data) == 0)) { + printf("Setting LAN %s to %s\n", + ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc, + mac2str(data)); rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC, data, 6); } else { @@ -1595,10 +1556,10 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv) rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP, data, 4); } else if ((strncmp(argv[2], "macaddr", 7) == 0) && - (get_cmdline_macaddr(argv[3], data) == 0)) { - printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n", - ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc, - data[0], data[1], data[2], data[3], data[4], data[5]); + (str2mac(argv[3], data) == 0)) { + printf("Setting LAN %s to %s\n", + ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc, + mac2str(data)); rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC, data, 6); } else { @@ -1776,9 +1737,8 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert) printf("%-24s: %d.%d.%d.%d\n", "Alert IP Address", paddr[3], paddr[4], paddr[5], paddr[6]); - printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", "Alert MAC Address", - paddr[7], paddr[8], paddr[9], - paddr[10], paddr[11], paddr[12]); + printf("%-24s: %s\n", "Alert MAC Address", + mac2str(&paddr[7])); printf("\n"); return 0; @@ -1843,7 +1803,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, } /* alert destination mac address */ else if (strncasecmp(argv[0], "macaddr", 7) == 0 && - (get_cmdline_macaddr(argv[1], temp) == 0)) { + (str2mac(argv[1], temp) == 0)) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert); if (p == NULL) { @@ -1853,8 +1813,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, /* set new macaddr */ memcpy(data+7, temp, 6); printf("Setting LAN Alert %d MAC Address to " - "%02x:%02x:%02x:%02x:%02x:%02x\n", alert, - data[7], data[8], data[9], data[10], data[11], data[12]); + "%s\n", alert, mac2str(&data[7])); rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len); } /* alert destination gateway selector */ diff --git a/lib/ipmi_pef.c b/lib/ipmi_pef.c index 2f7e483..bbf25f2 100644 --- a/lib/ipmi_pef.c +++ b/lib/ipmi_pef.c @@ -720,10 +720,7 @@ ipmi_pef_print_lan_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest) pinfo->ip[0], pinfo->ip[1], pinfo->ip[2], pinfo->ip[3]); ipmi_pef_print_str("IP address", buf); - sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", - pinfo->mac[0], pinfo->mac[1], pinfo->mac[2], - pinfo->mac[3], pinfo->mac[4], pinfo->mac[5]); - ipmi_pef_print_str("MAC address", buf); + ipmi_pef_print_str("MAC address", mac2str(pinfo->mac)); } } diff --git a/lib/ipmi_session.c b/lib/ipmi_session.c index 4855bc4..141f0f4 100644 --- a/lib/ipmi_session.c +++ b/lib/ipmi_session.c @@ -99,13 +99,8 @@ print_session_info_csv(const struct get_session_info_rsp * session_info, buffer, 16)); - printf(",%02x:%02x:%02x:%02x:%02x:%02x", - session_info->channel_data.lan_data.console_mac[0], - session_info->channel_data.lan_data.console_mac[1], - session_info->channel_data.lan_data.console_mac[2], - session_info->channel_data.lan_data.console_mac[3], - session_info->channel_data.lan_data.console_mac[4], - session_info->channel_data.lan_data.console_mac[5]); + printf(",%s", mac2str( + session_info->channel_data.lan_data.console_mac)); console_port_tmp = session_info->channel_data.lan_data.console_port; #if WORDS_BIGENDIAN @@ -187,13 +182,8 @@ print_session_info_verbose(const struct get_session_info_rsp * session_info, buffer, 16)); - printf("console mac : %02x:%02x:%02x:%02x:%02x:%02x\n", - session_info->channel_data.lan_data.console_mac[0], - session_info->channel_data.lan_data.console_mac[1], - session_info->channel_data.lan_data.console_mac[2], - session_info->channel_data.lan_data.console_mac[3], - session_info->channel_data.lan_data.console_mac[4], - session_info->channel_data.lan_data.console_mac[5]); + printf("console mac : %s\n", mac2str( + session_info->channel_data.lan_data.console_mac)); console_port_tmp = session_info->channel_data.lan_data.console_port; #if WORDS_BIGENDIAN commit 2f76ab3d3aaf3aa3b9e567d6e4328b8927110d92 Author: Dmitry Rakhchev <rd...@pi...> Date: Fri Jul 1 12:20:22 2016 +0300 Export find_lan_channel() as global diff --git a/include/ipmitool/ipmi_lanp.h b/include/ipmitool/ipmi_lanp.h index 7f7d653..0972544 100644 --- a/include/ipmitool/ipmi_lanp.h +++ b/include/ipmitool/ipmi_lanp.h @@ -132,4 +132,6 @@ static struct lan_param { int ipmi_lanp_main(struct ipmi_intf *, int, char **); +uint8_t find_lan_channel(struct ipmi_intf *intf, uint8_t start); + #endif /*IPMI_LANP_H*/ diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c index ecd313a..ce6af4a 100644 --- a/lib/ipmi_lanp.c +++ b/lib/ipmi_lanp.c @@ -104,7 +104,7 @@ is_lan_channel(struct ipmi_intf * intf, uint8_t chan) * @intf: ipmi interface handle * @start: channel number to start searching from */ -static uint8_t +uint8_t find_lan_channel(struct ipmi_intf * intf, uint8_t start) { uint8_t chan = 0; commit 7f8d37493facde42c4f953061c6dee7227d6ddde Author: Dmitry Rakhchev <rd...@pi...> Date: Fri Jul 1 11:19:30 2016 +0300 Rewrite code with the notion that Kg is binary data, not string - use uint8_t as the storage type - allocate kgkey on stack - do not treat incoming kgkey as 0-trminated string in ipmi_intf_session_set_kgkey() diff --git a/include/ipmitool/ipmi_intf.h b/include/ipmitool/ipmi_intf.h index 9285baa..982f645 100644 --- a/include/ipmitool/ipmi_intf.h +++ b/include/ipmitool/ipmi_intf.h @@ -220,7 +220,7 @@ void ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, uint8_t privlvl); void ipmi_intf_session_set_lookupbit(struct ipmi_intf * intf, uint8_t lookupbit); void ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, uint8_t cipher_suite_id); void ipmi_intf_session_set_sol_escape_char(struct ipmi_intf * intf, char sol_escape_char); -void ipmi_intf_session_set_kgkey(struct ipmi_intf * intf, char * kgkey); +void ipmi_intf_session_set_kgkey(struct ipmi_intf *intf, const uint8_t *kgkey); void ipmi_intf_session_set_port(struct ipmi_intf * intf, int port); void ipmi_intf_session_set_authtype(struct ipmi_intf * intf, uint8_t authtype); void ipmi_intf_session_set_timeout(struct ipmi_intf * intf, uint32_t timeout); diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c index d029d0a..2ea3c26 100644 --- a/lib/ipmi_main.c +++ b/lib/ipmi_main.c @@ -291,42 +291,6 @@ void ipmi_catch_sigint() exit(-1); } -/* ipmi_parse_hex_KG - get hexadecimal key value - * Input string must be composed of two-characer - * hexadecimal numbers. - * There is no separator between the numbers. Each number - * results in one byte of the converted string. - * - * Example: ipmi_parse_hex("50415353574F5244") - * returns 'PASSWORD' - * - * @param str: input string. It must contain only even number - * of '0'-'9','a'-'f' and 'A-F' characters. - * @returns obtained key or NULL on error - */ -static uint8_t * -ipmi_parse_hex_KG(const char *str) -{ - int rc; - uint8_t *out; - - out = calloc(IPMI_KG_BUFFER_SIZE, sizeof(uint8_t)); - rc = ipmi_parse_hex(str, out, IPMI_KG_BUFFER_SIZE - 1); - - if (rc == -1) { - lprintf(LOG_ERR, "Number of hex_kg characters is not even"); - } else if (rc == -2) { - lprintf(LOG_ERR, "malloc failure"); - } else if (rc == -3) { - lprintf(LOG_ERR, "Kg_hex is not hexadecimal number"); - } else if (rc > (IPMI_KG_BUFFER_SIZE-1)) { - lprintf(LOG_ERR, "Kg key is too long"); - free(out); - out = NULL; - } - return (unsigned char *)out; -} - static uint8_t ipmi_acquire_ipmb_address(struct ipmi_intf * intf) { @@ -379,7 +343,7 @@ ipmi_main(int argc, char ** argv, char * progname = NULL; char * oemtype = NULL; char * sdrcache = NULL; - unsigned char * kgkey = NULL; + uint8_t kgkey[IPMI_KG_BUFFER_SIZE]; char * seloem = NULL; int port = 0; int devnum = 0; @@ -394,6 +358,7 @@ ipmi_main(int argc, char ** argv, progname = strrchr(argv[0], '/'); progname = ((progname == NULL) ? argv[0] : progname+1); signal(SIGINT, ipmi_catch_sigint); + memset(kgkey, 0, sizeof(kgkey)); while ((argflag = getopt(argc, (char **)argv, OPTION_STRING)) != -1) { @@ -520,38 +485,29 @@ ipmi_main(int argc, char ** argv, } break; case 'k': - if (kgkey) { - free(kgkey); - kgkey = NULL; - } - kgkey = strdup(optarg); - if (kgkey == NULL) { - lprintf(LOG_ERR, "%s: malloc failure", progname); - goto out_free; - } + memset(kgkey, 0, sizeof(kgkey)); + strncpy((char *)kgkey, optarg, sizeof(kgkey) - 1); break; case 'K': if ((tmp_env = getenv("IPMI_KGKEY"))) { - if (kgkey) { - free(kgkey); - kgkey = NULL; - } - kgkey = strdup(tmp_env); - if (kgkey == NULL) { - lprintf(LOG_ERR, "%s: malloc failure", progname); - goto out_free; - } + memset(kgkey, 0, sizeof(kgkey)); + strncpy((char *)kgkey, tmp_env, + sizeof(kgkey) - 1); } else { lprintf(LOG_WARN, "Unable to read kgkey from environment"); } break; case 'y': - if (kgkey) { - free(kgkey); - kgkey = NULL; - } - kgkey = ipmi_parse_hex_KG(optarg); - if (kgkey == NULL) { + memset(kgkey, 0, sizeof(kgkey)); + rc = ipmi_parse_hex(optarg, kgkey, sizeof(kgkey) - 1); + + if (rc == -1) { + lprintf(LOG_ERR, "Number of Kg key characters is not even"); + } else if (rc == -3) { + lprintf(LOG_ERR, "Kg key is not hexadecimal number"); + goto out_free; + } else if (rc > (IPMI_KG_BUFFER_SIZE-1)) { + lprintf(LOG_ERR, "Kg key is too long"); goto out_free; } break; @@ -562,16 +518,10 @@ ipmi_main(int argc, char ** argv, tmp_pass = getpass("Key: "); #endif if (tmp_pass != NULL) { - if (kgkey) { - free(kgkey); - kgkey = NULL; - } - kgkey = strdup(tmp_pass); + memset(kgkey, 0, sizeof(kgkey)); + strncpy((char *)kgkey, tmp_pass, + sizeof(kgkey) - 1); tmp_pass = NULL; - if (kgkey == NULL) { - lprintf(LOG_ERR, "%s: malloc failure", progname); - goto out_free; - } } break; case 'U': @@ -901,8 +851,7 @@ ipmi_main(int argc, char ** argv, ipmi_intf_session_set_username(ipmi_main_intf, username); if (password != NULL) ipmi_intf_session_set_password(ipmi_main_intf, password); - if (kgkey != NULL) - ipmi_intf_session_set_kgkey(ipmi_main_intf, kgkey); + ipmi_intf_session_set_kgkey(ipmi_main_intf, kgkey); if (port > 0) ipmi_intf_session_set_port(ipmi_main_intf, port); if (authtype >= 0) @@ -1096,10 +1045,6 @@ ipmi_main(int argc, char ** argv, free(seloem); seloem = NULL; } - if (kgkey != NULL) { - free(kgkey); - kgkey = NULL; - } if (sdrcache != NULL) { free(sdrcache); sdrcache = NULL; diff --git a/src/plugins/ipmi_intf.c b/src/plugins/ipmi_intf.c index 6cf0553..9225a34 100644 --- a/src/plugins/ipmi_intf.c +++ b/src/plugins/ipmi_intf.c @@ -264,15 +264,9 @@ ipmi_intf_session_set_sol_escape_char(struct ipmi_intf * intf, char sol_escape_c } void -ipmi_intf_session_set_kgkey(struct ipmi_intf * intf, char * kgkey) +ipmi_intf_session_set_kgkey(struct ipmi_intf *intf, const uint8_t *kgkey) { - memset(intf->ssn_params.kg, 0, IPMI_KG_BUFFER_SIZE); - - if (kgkey == NULL) - return; - - memcpy(intf->ssn_params.kg, kgkey, - __min(strlen(kgkey), IPMI_KG_BUFFER_SIZE)); + memcpy(intf->ssn_params.kg, kgkey, IPMI_KG_BUFFER_SIZE); } void commit f9211f8ed977f20c4601f00d0cc56724ebdff04a Author: Dmitry Rakhchev <rd...@pi...> Date: Thu Jun 30 21:25:25 2016 +0300 Moved ipmi_parse_hex() to helper.c diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h index 41a3fa5..81b8825 100644 --- a/include/ipmitool/helper.h +++ b/include/ipmitool/helper.h @@ -100,6 +100,7 @@ uint32_t buf2long(uint8_t * buf); #define BUF2STR_MAXIMUM_OUTPUT_SIZE (3*1024 + 1) const char * buf2str_extended(const uint8_t *buf, int len, const char *sep); const char * buf2str(const uint8_t *buf, int len); +int ipmi_parse_hex(const char *str, uint8_t *out, int size); void printbuf(const uint8_t * buf, int len, const char * desc); uint8_t ipmi_csum(uint8_t * d, int s); FILE * ipmi_open_file(const char * file, int rw); diff --git a/lib/helper.c b/lib/helper.c index 04a5e0d..ad5a898 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -51,6 +51,7 @@ #include <fcntl.h> #include <errno.h> #include <assert.h> +#include <ctype.h> #if HAVE_CONFIG_H # include <config.h> @@ -140,6 +141,80 @@ buf2str(const uint8_t *buf, int len) return buf2str_extended(buf, len, NULL); } +/* ipmi_parse_hex - convert hexadecimal numbers to ascii string + * Input string must be composed of two-characer + * hexadecimal numbers. + * There is no separator between the numbers. Each number + * results in one byte of the converted string. + * + * Example: ipmi_parse_hex("50415353574F5244") + * returns 'PASSWORD' + * + * @param str: input string. It must contain only even number + * of '0'-'9','a'-'f' and 'A-F' characters. + * @param out: pointer to output data + * @param size: size of the output buffer + * @returns 0 for empty input string + * -1 for string with odd length + * -2 if out is NULL + * -3 if there is non-hexadecimal char in string + * >0 length of resulting binary data even if it is > size + */ +int +ipmi_parse_hex(const char *str, uint8_t *out, int size) +{ + const char *p; + uint8_t *q; + uint8_t d = 0; + uint8_t b = 0; + int shift = 4; + int len; + + len = strlen(str); + if (len == 0) { + return 0; + } + + if (len % 2 != 0) { + return -1; + } + + len /= 2; /* out bytes */ + if (out == NULL) { + return -2; + } + + for (p = str, q = out; *p; p++) { + if (!isxdigit(*p)) { + return -3; + } + + if (*p < 'A') { + /* it must be 0-9 */ + d = *p - '0'; + } else { + /* it's A-F or a-f */ + /* convert to lowercase and to 10-15 */ + d = (*p | 0x20) - 'a' + 10; + } + + if (q < (out + size)) { + /* there is space, store */ + b += d << shift; + if (shift) { + shift = 0; + } else { + shift = 4; + *q = b; + b = 0; + q++; + } + } + } + + return len; +} + void printbuf(const uint8_t * buf, int len, const char * desc) { int i; diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c index e6f96f6..d029d0a 100644 --- a/lib/ipmi_main.c +++ b/lib/ipmi_main.c @@ -291,67 +291,40 @@ void ipmi_catch_sigint() exit(-1); } -/* ipmi_parse_hex - convert hexadecimal numbers to ascii string - * Input string must be composed of two-characer hexadecimal numbers. - * There is no separator between the numbers. Each number results in one character - * of the converted string. +/* ipmi_parse_hex_KG - get hexadecimal key value + * Input string must be composed of two-characer + * hexadecimal numbers. + * There is no separator between the numbers. Each number + * results in one byte of the converted string. * - * Example: ipmi_parse_hex("50415353574F5244") returns 'PASSWORD' + * Example: ipmi_parse_hex("50415353574F5244") + * returns 'PASSWORD' * - * @param str: input string. It must contain only even number of '0'-'9','a'-'f' and 'A-F' characters. - * @returns converted ascii string - * @returns NULL on error + * @param str: input string. It must contain only even number + * of '0'-'9','a'-'f' and 'A-F' characters. + * @returns obtained key or NULL on error */ -static unsigned char * -ipmi_parse_hex(const char *str) +static uint8_t * +ipmi_parse_hex_KG(const char *str) { - const char * p; - unsigned char * out, *q; - unsigned char b = 0; - int shift = 4; + int rc; + uint8_t *out; - if (strlen(str) == 0) - return NULL; + out = calloc(IPMI_KG_BUFFER_SIZE, sizeof(uint8_t)); + rc = ipmi_parse_hex(str, out, IPMI_KG_BUFFER_SIZE - 1); - if (strlen(str) % 2 != 0) { + if (rc == -1) { lprintf(LOG_ERR, "Number of hex_kg characters is not even"); - return NULL; - } - - if (strlen(str) > (IPMI_KG_BUFFER_SIZE-1)*2) { - lprintf(LOG_ERR, "Kg key is too long"); - return NULL; - } - - out = calloc(IPMI_KG_BUFFER_SIZE, sizeof(unsigned char)); - if (out == NULL) { + } else if (rc == -2) { lprintf(LOG_ERR, "malloc failure"); - return NULL; - } - - for (p = str, q = out; *p; p++) { - if (!isxdigit(*p)) { - lprintf(LOG_ERR, "Kg_hex is not hexadecimal number"); - free(out); - out = NULL; - return NULL; - } - - if (*p < 'A') /* it must be 0-9 */ - b = *p - '0'; - else /* it's A-F or a-f */ - b = (*p | 0x20) - 'a' + 10; /* convert to lowercase and to 10-15 */ - - *q = *q + (b << shift); - if (shift) - shift = 0; - else { - shift = 4; - q++; - } + } else if (rc == -3) { + lprintf(LOG_ERR, "Kg_hex is not hexadecimal number"); + } else if (rc > (IPMI_KG_BUFFER_SIZE-1)) { + lprintf(LOG_ERR, "Kg key is too long"); + free(out); + out = NULL; } - - return out; + return (unsigned char *)out; } static uint8_t @@ -577,7 +550,7 @@ ipmi_main(int argc, char ** argv, free(kgkey); kgkey = NULL; } - kgkey = ipmi_parse_hex(optarg); + kgkey = ipmi_parse_hex_KG(optarg); if (kgkey == NULL) { goto out_free; } commit ea46724878894fbe06130b1cd3824e3582d1020a Author: Dmitry Rakhchev <rd...@pi...> Date: Fri Jul 1 11:48:29 2016 +0300 Fix warning for buf2str argument diff --git a/src/plugins/serial/serial_basic.c b/src/plugins/serial/serial_basic.c index a53bbd9..21a239a 100644 --- a/src/plugins/serial/serial_basic.c +++ b/src/plugins/serial/serial_basic.c @@ -130,7 +130,7 @@ struct serial_bm_parse_ctx{ * Receiving context */ struct serial_bm_recv_ctx { - char buffer[SERIAL_BM_MAX_BUFFER_SIZE]; + uint8_t buffer[SERIAL_BM_MAX_BUFFER_SIZE]; size_t buffer_size; size_t max_buffer_size; }; commit 9a6ba646511b6290214158f96ce93340db90f7a1 Author: Dmitry Rakhchev <rd...@pi...> Date: Thu Jul 21 16:52:55 2016 +0300 Extend buf2str to allow separator diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h index b7ad628..41a3fa5 100644 --- a/include/ipmitool/helper.h +++ b/include/ipmitool/helper.h @@ -97,7 +97,9 @@ void print_valstr_2col(const struct valstr * vs, const char * title, int logleve uint16_t buf2short(uint8_t * buf); uint32_t buf2long(uint8_t * buf); -const char * buf2str(uint8_t * buf, int len); +#define BUF2STR_MAXIMUM_OUTPUT_SIZE (3*1024 + 1) +const char * buf2str_extended(const uint8_t *buf, int len, const char *sep); +const char * buf2str(const uint8_t *buf, int len); void printbuf(const uint8_t * buf, int len, const char * desc); uint8_t ipmi_csum(uint8_t * d, int s); FILE * ipmi_open_file(const char * file, int rw); diff --git a/lib/helper.c b/lib/helper.c index 022a9c9..04a5e0d 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -79,24 +79,67 @@ uint16_t buf2short(uint8_t * buf) return (uint16_t)(buf[1] << 8 | buf[0]); } -const char * buf2str(uint8_t * buf, int len) +/* buf2str_extended - convert sequence of bytes to hexadecimal string with + * optional separator + * + * @param buf - data to convert + * @param len - size of data + * @param sep - optional separator (can be NULL) + * + * @returns buf representation in hex, possibly truncated to fit + * allocated static memory + */ +const char * +buf2str_extended(const uint8_t *buf, int len, const char *sep) { - static char str[2049]; + static char str[BUF2STR_MAXIMUM_OUTPUT_SIZE]; + char *cur; int i; - - if (len <= 0 || len > 1024) - return NULL; - - memset(str, 0, 2049); - - for (i=0; i<len; i++) - sprintf(str+i+i, "%2.2x", buf[i]); - - str[len*2] = '\0'; + int sz; + int left; + int sep_len; + + if (buf == NULL) { + snprintf(str, sizeof(str), "<NULL>"); + return (const char *)str; + } + cur = str; + left = sizeof(str); + if (sep) { + sep_len = strlen(sep); + } else { + sep_len = 0; + } + for (i = 0; i < len; i++) { + /* may return more than 2, depending on locale */ + sz = snprintf(cur, left, "%2.2x", buf[i]); + if (sz >= left) { + /* buffer overflow, truncate */ + break; + } + cur += sz; + left -= sz; + /* do not write separator after last byte */ + if (sep && i != (len - 1)) { + if (sep_len >= left) { + break; + } + strncpy(cur, sep, left - sz); + cur += sep_len; + left -= sep_len; + } + } + *cur = '\0'; return (const char *)str; } +const char * +buf2str(const uint8_t *buf, int len) +{ + return buf2str_extended(buf, len, NULL); +} + void printbuf(const uint8_t * buf, int len, const char * desc) { int i; commit f8a711b9e8a06bd73c8565634be69bc37066683d Author: Bjoern Spruck <bs...@un...> Date: Wed Jul 27 09:51:19 2016 +0200 ID:452 - Add PICMG extension 5.x for PICMG extension check PICMG extension 5(UTCA, MicroTCA) is not detected as valid extension. The following patch fixes that at one place. In the second place the board type is detected in a similar way, but it isn't clear if a patch is needed there, too. diff --git a/lib/ipmi_picmg.c b/lib/ipmi_picmg.c index e5b79e7..c7d9c8e 100644 --- a/lib/ipmi_picmg.c +++ b/lib/ipmi_picmg.c @@ -2336,6 +2336,7 @@ picmg_discover(struct ipmi_intf *intf) { * PICMG Extension Version 2.0 (PICMG 3.0 Revision 1.0 ATCA) to * PICMG Extension Version 2.3 (PICMG 3.0 Revision 3.0 ATCA) * PICMG Extension Version 4.1 (PICMG 3.0 Revision 3.0 AMC) + * PICMG Extension Version 5.0 (MTCA.0 R1.0) */ /* First, check if PICMG extension is available and supported */ @@ -2366,8 +2367,9 @@ picmg_discover(struct ipmi_intf *intf) { } else if (rsp->data[0] != 0) { lprintf(LOG_INFO,"Invalid Get PICMG Properties group extension %#x", rsp->data[0]); - } else if ((rsp->data[1] & 0x0F) != PICMG_ATCA_MAJOR_VERSION - && (rsp->data[1] & 0x0F) != PICMG_AMC_MAJOR_VERSION) { + } else if ((rsp->data[1] & 0x0F) != PICMG_EXTENSION_ATCA_MAJOR_VERSION + && (rsp->data[1] & 0x0F) != PICMG_EXTENSION_AMC0_MAJOR_VERSION + && (rsp->data[1] & 0x0F) != PICMG_EXTENSION_UTCA_MAJOR_VERSION) { lprintf(LOG_INFO,"Unknown PICMG Extension Version %d.%d", (rsp->data[1] & 0x0F), (rsp->data[1] >> 4)); } else { commit fcf7445bcebdda167a561a54f598b1480b1bfabd Author: KC Li <kc...@su...> Date: Mon Jul 25 11:36:08 2016 +0800 ID:451 - Modify the memory ecc error display of SEL for new supermicro motherboards. diff --git a/include/ipmitool/ipmi_sel_supermicro.h b/include/ipmitool/ipmi_sel_supermicro.h index a058a8c..1679bd8 100644 --- a/include/ipmitool/ipmi_sel_supermicro.h +++ b/include/ipmitool/ipmi_sel_supermicro.h @@ -34,6 +34,18 @@ #ifndef IPMI_SEL_SUPERMICRO_H # define IPMI_SEL_SUPERMICRO_H +static uint16_t supermicro_x10OBi[] = { + 0x0923, 0xFFFF +}; + +static uint16_t supermicro_x10QRH_X10QBL[] = { + 0x0872, 0x0853, 0xFFFF +}; + +static uint16_t supermicro_brickland[] = { + 0x0726, 0x083A, 0xFFFF +}; + static uint16_t supermicro_x9dal[] = { 0x0635, 0xFFFF }; diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c index 953e746..0c07cf4 100644 --- a/lib/ipmi_sel.c +++ b/lib/ipmi_sel.c @@ -620,6 +620,24 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) break; } } + for (i = 0; supermicro_brickland[i] != 0xFFFF; i++) { + if (oem_id == supermicro_brickland[i]) { + chipset_type = 3; + break; + } + } + for (i = 0; supermicro_x10QRH_X10QBL[i] != 0xFFFF; i++) { + if (oem_id == supermicro_x10QRH_X10QBL[i]) { + chipset_type = 4; + break; + } + } + for (i = 0; supermicro_x10OBi[i] != 0xFFFF; i++) { + if (oem_id == supermicro_x10OBi[i]) { + chipset_type = 5; + break; + } + } if (chipset_type == 0) { snprintf(desc, SIZE_OF_DESC, "@DIMM%2X(CPU%x)", data2, @@ -632,6 +650,21 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", (data2 >> 4) + 0x40 + (data3 & 0x3) * 3, (data2 & 0xf) + 0x27, (data3 & 0x03) + 1); + } else if (chipset_type == 3) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%d(P%dM%d)", + ((data2 & 0xf) >> 4) > 4 + ? '@' - 4 + ((data2 & 0xff) >> 4) + : '@' + ((data2 & 0xff) >> 4), + (data2 & 0xf) - 0x09, (data3 & 0x0f) + 1, + (data2 & 0xff) >> 4 > 4 ? 2 : 1); + } else if (chipset_type == 4) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", + (data2 >> 4) + 0x40, + (data2 & 0xf) + 0x27, (data3 & 0x03) + 1); + } else if (chipset_type == 5) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", + (data2 >> 4) + 0x40, + (data2 & 0xf) + 0x27, (data3 & 0x07) + 1); } else { /* No description. */ desc[0] = '\0'; ----------------------------------------------------------------------- Summary of changes: include/ipmitool/helper.h | 7 +- include/ipmitool/ipmi_intf.h | 2 +- include/ipmitool/ipmi_lanp.h | 2 + include/ipmitool/ipmi_sel_supermicro.h | 12 ++ lib/helper.c | 183 ++++++++++++++++++++++++++++++-- lib/ipmi_delloem.c | 29 +---- lib/ipmi_lanp.c | 81 ++++----------- lib/ipmi_main.c | 125 ++++------------------ lib/ipmi_pef.c | 5 +- lib/ipmi_picmg.c | 6 +- lib/ipmi_sel.c | 33 ++++++ lib/ipmi_session.c | 18 +--- src/plugins/ipmi_intf.c | 10 +-- src/plugins/serial/serial_basic.c | 2 +- 14 files changed, 287 insertions(+), 228 deletions(-) hooks/post-receive -- ipmitool |