Make user User Privilege Limit is within range

Despite the fact we could leave this up to IPMI stack, we won't do that.
Therefore, is_ipmi_user_priv_limit() is added and user provided value checked.
This commit is contained in:
Zdenek Styblik 2014-12-20 13:57:06 +01:00
parent befb21497f
commit 6e6a04f971
3 changed files with 21 additions and 1 deletions

View File

@ -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_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_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_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); uint16_t str2val(const char * str, const struct valstr * vs);
void print_valstr(const struct valstr * vs, const char * title, int loglevel); void print_valstr(const struct valstr * vs, const char * title, int loglevel);

View File

@ -760,6 +760,24 @@ is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr)
return (-1); 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 uint16_t
ipmi_get_oem_id(struct ipmi_intf *intf) ipmi_get_oem_id(struct ipmi_intf *intf)
{ {

View File

@ -646,7 +646,8 @@ ipmi_user_priv(struct ipmi_intf *intf, int argc, char **argv)
} }
channel = (channel & 0x0f); 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]); lprintf(LOG_ERR, "Invalid privilege level: %s", argv[2]);
return (-1); return (-1);
} }