diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h index b6ee7fa..98cf459 100644 --- a/include/ipmitool/helper.h +++ b/include/ipmitool/helper.h @@ -86,6 +86,7 @@ int str2uchar(const char * str, uint8_t * uchr_ptr); int is_fru_id(const char *argv_ptr, uint8_t *fru_id_ptr); int is_ipmi_channel_num(const char *argv_ptr, uint8_t *channel_ptr); int is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr); +int is_ipmi_user_priv_limit(uint8_t priv_limit); uint16_t str2val(const char * str, const struct valstr * vs); void print_valstr(const struct valstr * vs, const char * title, int loglevel); diff --git a/lib/helper.c b/lib/helper.c index 6d093c8..605f866 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -760,6 +760,24 @@ is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr) return (-1); } +/* is_ipmi_user_priv_limit - check whether given value is valid User Privilege + * Limit, eg. IPMI v2 spec, 22.27 Get User Access Command. + * + * @priv_limit: User Privilege Limit + * + * returns 0 if Priv Limit is valid + * returns (-1) when Priv Limit is invalid + */ +int +is_ipmi_user_priv_limit(uint8_t priv_limit) +{ + if (0x00 < priv_limit && priv_limit < 0x06 || priv_limit == 0x0f) { + return 0; + } else { + return (-1); + } +} + uint16_t ipmi_get_oem_id(struct ipmi_intf *intf) { diff --git a/lib/ipmi_user.c b/lib/ipmi_user.c index 3731f63..06117ad 100644 --- a/lib/ipmi_user.c +++ b/lib/ipmi_user.c @@ -646,7 +646,8 @@ ipmi_user_priv(struct ipmi_intf *intf, int argc, char **argv) } channel = (channel & 0x0f); } - if (str2uchar(argv[2], &priv_level) != 0) { + if ((str2uchar(argv[2], &priv_level) != 0) + || is_ipmi_user_priv_limit(priv_level) != 0) { lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]); return (-1); }