Ticket refs #3813: TR-181: Incorrect implementation of some of Device.DHCPv4.and Device.DHCPv6. objects/parameters

Fix Get/Set value of these parameters which has a hexbinary encoded value according to the TR-181 standard
 - Device.DHCPv4.Server.Pool.{i}.Option.{i}.Value
 - Device.DHCPv4.Client.{i}.SentOption.{i}.Value
 - Device.DHCPv4.Relay.Forwarding.{i}.UserClassID
 - Device.DHCPv6.Server.Pool.{i}.VendorClassID
 - Device.DHCPv6.Server.Pool.{i}.UserClassID
 - Device.DHCPv6.Server.Pool.{i}.Option.{i}.Value
This commit is contained in:
Amin Ben Ramdhane 2020-11-18 10:32:01 +01:00
parent 7d8eb62868
commit e24f7bf8ac
4 changed files with 140 additions and 70 deletions

View file

@ -1495,7 +1495,7 @@ static int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *
if (tag_value && *tag_value)
convert_string_to_hex(tag_value, hex);
*value = dmstrdup(hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
@ -1879,13 +1879,20 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi
static int get_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(((struct dhcp_client_option_args *)data)->value);
const char *tag_value = ((struct dhcp_client_option_args *)data)->value;
char hex[256] = {0};
if (tag_value && *tag_value)
convert_string_to_hex(tag_value, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *v, *opttagvalue, *oldopttagvalue;
char res[256] = {0};
switch (action) {
case VALUECHECK:
@ -1896,10 +1903,13 @@ static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, v
dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v);
dmasprintf(&oldopttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value);
remove_elt_from_str_list(&v, oldopttagvalue);
dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, value);
convert_hex_to_string(value, res);
dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, res);
add_elt_to_str_list(&v, opttagvalue);
dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->opt_sect, "option_value", res);
break;
}
return 0;
@ -2133,7 +2143,6 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi
case VALUESET:
dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value);
dmasprintf(&opttagvalue, "%s,%s", value, ((struct dhcp_client_option_args *)data)->value);
dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list);
dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue);
dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value);
@ -2144,7 +2153,13 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi
static int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(((struct dhcp_client_option_args *)data)->value);
const char *tag_value = ((struct dhcp_client_option_args *)data)->value;
char hex[256] = {0};
if (tag_value && *tag_value)
convert_string_to_hex(tag_value, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
@ -2154,28 +2169,30 @@ static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v
size_t length;
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
char res[256] = {0};
switch (action) {
case VALUECHECK:
if (dm_validate_hexBinary(value, RANGE_ARGS{{"0","255"}}, 1))
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list);
if (dhcp_option_list == NULL)
return 0;
convert_hex_to_string(value, res);
uci_foreach_element(dhcp_option_list, e) {
option = strsplit(e->name, ",", &length);
if (strcmp(option[0], value) == 0)
if (strcmp(option[0], res) == 0)
return FAULT_9007;
}
break;
case VALUESET:
dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value);
dmasprintf(&opttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, value);
dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list);
dmasprintf(&opttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, res);
dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue);
dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->opt_sect, "option_value", res);
break;
}
return 0;
@ -2425,21 +2442,29 @@ static int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, v
/*#Device.DHCPv4.Relay.Forwarding.{i}.UserClassID!UCI:network/interface,@i-1/userclass*/
static int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
if(((struct dhcp_client_args *)data)->userclassclassifier)
dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value);
char hex[256] = {0}, *ucid = NULL;
dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", &ucid);
if (ucid && *ucid)
convert_string_to_hex(ucid, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
static int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char res[256] = {0};
switch (action) {
case VALUECHECK:
if (dm_validate_hexBinary(value, RANGE_ARGS{{NULL,"255"}}, 1))
return FAULT_9007;
break;
case VALUESET:
if(((struct dhcp_client_args *)data)->userclassclassifier)
dmuci_set_value_by_section(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value);
convert_hex_to_string(value, res);
dmuci_set_value_by_section(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", res);
break;
}
return 0;
@ -2813,7 +2838,7 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct uci_section *dmmap_sect;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
struct browse_args browse_args = {0};
char *inst, *max_inst = NULL, *v1, *v2, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL;
char *inst, *max_inst = NULL, *tag, *value, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL;
size_t length = 0, lgh2;
int i, j;
@ -2844,11 +2869,11 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "send_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &value);
dhcp_client_opt_args.client_sect = dhcp_client_args->dhcp_client_conf;
dhcp_client_opt_args.option_tag = dmstrdup(v1);
dhcp_client_opt_args.value = dmstrdup(v2);
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup(value);
dhcp_client_opt_args.opt_sect = dmmap_sect;
browse_args.option = "section_name";
@ -2870,7 +2895,7 @@ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_n
struct uci_section *dmmap_sect;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
struct browse_args browse_args = {0};
char *inst, *max_inst = NULL, *v1, **reqtopts = NULL, *v = NULL;
char *inst, *max_inst = NULL, *tag, **reqtopts = NULL, *v = NULL;
size_t length = 0;
int i;
@ -2887,9 +2912,9 @@ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_n
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "req_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dhcp_client_opt_args.client_sect = dhcp_client_args->dhcp_client_conf;
dhcp_client_opt_args.option_tag = dmstrdup(v1);
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup("");
dhcp_client_opt_args.opt_sect = dmmap_sect;
@ -2913,7 +2938,7 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct dhcp_args *curr_dhcp_args = (struct dhcp_args*)prev_data;
struct uci_section *dmmap_sect;
struct browse_args browse_args = {0};
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue = NULL, *tmp, *v1, *v2, *v;
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue = NULL, *tmp, *tag, *value, *v;
size_t length;
int j;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
@ -2941,12 +2966,13 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_value", optionvalue);
}
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &value);
dhcp_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec;
dhcp_client_opt_args.option_tag = dmstrdup(v1);
dhcp_client_opt_args.value = dmstrdup(v2);
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup(value);
dhcp_client_opt_args.opt_sect = dmmap_sect;
browse_args.option = "section_name";
@ -3197,7 +3223,6 @@ DMLEAF tDHCPv4ServerPoolStaticAddressParams[] = {
{0}
};
/* *** Device.DHCPv4.Server.Pool.{i}.Option.{i}. *** */
/* *** Device.DHCPv4.Server.Pool.{i}.Option.{i}. *** */
DMLEAF tDHCPv4ServerPoolOptionParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/

View file

@ -209,7 +209,7 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args*)prev_data;
struct uci_section *dmmap_sect;
struct browse_args browse_args = {0};
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue= NULL, *tmp, *v1, *v2, *v;
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue= NULL, *tmp, *tag, *value, *v;
size_t length;
int j;
struct dhcpv6_client_option_args dhcp_client_opt_args = {0};
@ -229,21 +229,22 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
for (j = 2; j < length; j++){
tmp=dmstrdup(optionvalue);
dmfree(optionvalue);
optionvalue= NULL;
optionvalue = NULL;
dmasprintf(&optionvalue, "%s,%s", tmp, tagvalue[j]);
dmfree(tmp);
tmp= NULL;
tmp = NULL;
}
}
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_value", optionvalue);
}
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &value);
dhcp_client_opt_args.client_sect= curr_dhcp_args->dhcp_sec;
dhcp_client_opt_args.option_tag = dmstrdup(v1);
dhcp_client_opt_args.value = dmstrdup(v2);
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup(value);
dhcp_client_opt_args.opt_sect = dmmap_sect;
browse_args.option = "section_name";
@ -931,17 +932,24 @@ static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, voi
}
/*#Device.DHCPv6.Server.Pool.{i}.VendorClassID!UCI:dhcp/dhcp,@i-1/vendorclass*/
static int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) //TODO return wrong value
static int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char hex[256] = {0}, *vcid = NULL;
struct uci_section *vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface);
if (vendorclassidclassifier)
dmuci_get_value_by_section_string(vendorclassidclassifier, "vendorclass", value);
dmuci_get_value_by_section_string(vendorclassidclassifier, "vendorclass", &vcid);
if (vcid && *vcid)
convert_string_to_hex(vcid, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
static int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *vendorclassidclassifier = NULL;
char *name, res[256] = {0};
switch (action) {
case VALUECHECK:
@ -949,9 +957,14 @@ static int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx,
return FAULT_9007;
break;
case VALUESET:
convert_hex_to_string(value, res);
vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface);
if (vendorclassidclassifier)
dmuci_set_value_by_section(vendorclassidclassifier, "vendorclass", value);
if (!vendorclassidclassifier) {
dmuci_add_section("dhcp", "vendorclass", &vendorclassidclassifier, &name);
dmuci_set_value_by_section(vendorclassidclassifier, "networkid", ((struct dhcpv6_args *)data)->interface);
}
dmuci_set_value_by_section(vendorclassidclassifier, "vendorclass", res);
break;
}
return 0;
@ -960,15 +973,22 @@ static int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx,
/*#Device.DHCPv6.Server.Pool.{i}.UserClassID!UCI:dhcp/dhcp,@i-1/userclass*/
static int get_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface);
if (userclassidclassifier)
dmuci_get_value_by_section_string(userclassidclassifier, "userclass", value);
char hex[256] = {0}, *ucid = NULL;
struct uci_section *userclassidclassifier = get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface);
dmuci_get_value_by_section_string(userclassidclassifier, "userclass", &ucid);
if (ucid && *ucid)
convert_string_to_hex(ucid, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *userclassidclassifier;
struct uci_section *userclassidclassifier = NULL;
char *name, res[256] = {0};
switch (action) {
case VALUECHECK:
@ -976,9 +996,14 @@ static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, v
return FAULT_9007;
break;
case VALUESET:
userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface);
if (userclassidclassifier)
dmuci_set_value_by_section(userclassidclassifier, "userclass", value);
convert_hex_to_string(value, res);
userclassidclassifier = get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface);
if (!userclassidclassifier) {
dmuci_add_section("dhcp", "userclass", &userclassidclassifier, &name);
dmuci_set_value_by_section(userclassidclassifier, "networkid", ((struct dhcpv6_args *)data)->interface);
}
dmuci_set_value_by_section(userclassidclassifier, "userclass", res);
break;
}
return 0;
@ -993,7 +1018,7 @@ static int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx,
macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (macaddrclassifier == NULL) {
*value= "";
*value = "";
return 0;
}
dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac);
@ -1039,7 +1064,7 @@ static int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *
macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (macaddrclassifier == NULL) {
*value= "";
*value = "";
return 0;
}
dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac);
@ -1397,7 +1422,13 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi
static int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value= dmstrdup(((struct dhcpv6_client_option_args *)data)->value);
const char *tag_value = ((struct dhcpv6_client_option_args *)data)->value;
char hex[256] = {0};
if (tag_value && *tag_value)
convert_string_to_hex(tag_value, hex);
*value = (*hex) ? dmstrdup(hex) : "";
return 0;
}
@ -1407,29 +1438,30 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v
size_t length;
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
char res[256] = {0};
switch (action) {
case VALUECHECK:
if (dm_validate_hexBinary(value, RANGE_ARGS{{"0","65535"}}, 1))
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list);
if (dhcp_option_list == NULL)
return 0;
convert_hex_to_string(value, res);
uci_foreach_element(dhcp_option_list, e) {
option = strsplit(e->name, ",", &length);
if (strcmp(option[0], value) == 0)
if (strcmp(option[0], res) == 0)
return FAULT_9007;
}
break;
case VALUESET:
dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value);
dmasprintf(&opttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, value);
dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list);
dmasprintf(&opttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, res);
dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue);
dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue);
dmuci_set_value_by_section_bbfdm(((struct dhcpv6_client_option_args *)data)->opt_sect, "option_value", value);
dmuci_set_value_by_section_bbfdm(((struct dhcpv6_client_option_args *)data)->opt_sect, "option_value", res);
break;
}
return 0;

View file

@ -1371,11 +1371,24 @@ void convert_string_to_hex(const char *str, char *hex)
int i, j, len = strlen(str);
for (i = 0, j = 0; i < len; i++, j += 2) {
sprintf((char *)hex+j, "%02X", str[i]);
sprintf((char *)hex + j, "%02X", str[i]);
}
hex[j] = '\0';
}
void convert_hex_to_string(const char *hex, char *str)
{
int i, j, len = strlen(hex);
char buf[3] = {0};
for (i = 0, j = 0; i < len; i += 2, j++) {
strncpy(buf, &hex[i], 2);
buf[2] = '\0';
sprintf((char *)str + j, "%c", (char)strtol(buf, NULL, 16));
}
str[j] = '\0';
}
bool match(const char *string, const char *pattern)
{
regex_t re;
@ -1433,8 +1446,10 @@ int dm_validate_string(char *value, int min_length, int max_length, char *enumer
int dm_validate_boolean(char *value)
{
/* check format */
if ((value[0] == '1' && value[1] == '\0') || (value[0] == '0' && value[1] == '\0')
|| !strcasecmp(value, "true") || !strcasecmp(value, "false")) {
if ((value[0] == '1' && value[1] == '\0') ||
(value[0] == '0' && value[1] == '\0') ||
!strcasecmp(value, "true") ||
!strcasecmp(value, "false")) {
return 0;
}
return -1;
@ -1444,9 +1459,6 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
{
int i;
if (value[0] == '-')
return -1;
/* check size for each range */
for (i = 0; i < r_args_size; i++) {
unsigned long val = 0, minval = 0, maxval = 0;
@ -1460,7 +1472,7 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
val = strtoul(value, &endval, 10);
if ((*endval != 0) || (errno != 0)) return -1;
if ((*value == '-') || (*endval != 0) || (errno != 0)) return -1;
if (r_args[i].min && r_args[i].max && minval == maxval) {
@ -1525,7 +1537,7 @@ int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args
val = strtoul(value, &endval, 10);
if ((*endval != 0) || (errno != 0)) return -1;
if ((*value == '-') || (*endval != 0) || (errno != 0)) return -1;
/* check size */
if ((r_args[i].min && val < minval) || (r_args[i].max && val > maxval) || (val < 0) || (val > (unsigned long)ULONG_MAX))
@ -1595,8 +1607,8 @@ int dm_validate_hexBinary(char *value, struct range_args r_args[], int r_args_si
continue;
}
if ((r_args[i].min && !r_args[i].max && (strlen(value) < atoi(r_args[i].min))) ||
(!r_args[i].min && r_args[i].max && (strlen(value) > atoi(r_args[i].max)))) {
if ((r_args[i].min && (strlen(value) < atoi(r_args[i].min))) ||
(r_args[i].max && (strlen(value) > atoi(r_args[i].max)))) {
return -1;
}
}

View file

@ -312,6 +312,7 @@ int get_net_device_sysfs(const char *uci_iface, const char *name, char **value);
char *get_device_from_wifi_iface(const char *wifi_iface, const char *wifi_section);
int dm_time_format(time_t ts, char **dst);
void convert_string_to_hex(const char *str, char *hex);
void convert_hex_to_string(const char *hex, char *str);
bool match(const char *string, const char *pattern);
int dm_validate_string(char *value, int min_length, int max_length, char *enumeration[], int enumeration_size, char *pattern[], int pattern_size);
int dm_validate_boolean(char *value);