diff --git a/dmdiagnostics.c b/dmdiagnostics.c index 41a7586c..20716ce9 100644 --- a/dmdiagnostics.c +++ b/dmdiagnostics.c @@ -64,18 +64,14 @@ void set_diagnostics_interface_option(struct dmctx *ctx, char *sec_name, char *v { char *linker = NULL; - if (value[0] == 0) + if (!value) return; - if (strncmp(value, "Device.IP.Interface.", 20) != 0) + if (*value && strncmp(value, "Device.IP.Interface.", 20) != 0) return; adm_entry_get_linker_value(ctx, value, &linker); - - if (linker && *linker) { - set_diagnostics_option(sec_name, "interface", linker); - dmfree(linker); - } + set_diagnostics_option(sec_name, "interface", linker ? linker : ""); } static bool get_response_code_status(const char *url, int response_code) diff --git a/dmentry.c b/dmentry.c index 896b5e59..199b1cf7 100644 --- a/dmentry.c +++ b/dmentry.c @@ -361,9 +361,13 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1) int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value) { struct dmctx dmctx = {0}; + *value = ""; + + if (!param || !linker) + return 0; dm_ctx_init_sub(&dmctx, ctx->instance_mode); - dmctx.in_param = param ? param : ""; + dmctx.in_param = param; dmctx.linker = linker; dm_entry_get_linker(&dmctx); @@ -394,6 +398,28 @@ int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value) return 0; } +int dm_entry_validate_allowed_objects(struct dmctx *ctx, char *value, char *objects[]) +{ + if (!value || !objects) + return -1; + + if (*value == '\0') + return 0; + + for (; *objects; objects++) { + + if (strncmp(value, *objects, strlen(*objects)) == 0) { + char *linker = NULL; + + adm_entry_get_linker_value(ctx, value, &linker); + if (linker && *linker) + return 0; + } + } + + return -1; +} + int dm_entry_manage_services(struct blob_buf *bb, bool restart) { struct package_change *pc = NULL; diff --git a/dmtree/tr104/servicesvoiceservicecallcontrol.c b/dmtree/tr104/servicesvoiceservicecallcontrol.c index c2c138e7..6d9133dc 100644 --- a/dmtree/tr104/servicesvoiceservicecallcontrol.c +++ b/dmtree/tr104/servicesvoiceservicecallcontrol.c @@ -33,8 +33,7 @@ static int get_voice_service_callcontrol_linker(char *refparam, struct dmctx *dm **************************************************************/ static int set_CallControl_Line(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char callcontrol_line[64] = "Device.Services.VoiceService.1.CallControl.Line."; - size_t line_len = strlen(callcontrol_line); + char *allowed_objects[] = {"Device.Services.VoiceService.1.CallControl.Line.", NULL}; char *linker = NULL; switch (action) { @@ -42,16 +41,13 @@ static int set_CallControl_Line(char *refparam, struct dmctx *ctx, void *data, c if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (strncmp(value, callcontrol_line, line_len) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "line", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "line", linker ? linker : ""); break; } return 0; @@ -59,8 +55,7 @@ static int set_CallControl_Line(char *refparam, struct dmctx *ctx, void *data, c static int set_CallControl_Group(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char callcontrol_extension[64] = "Device.Services.VoiceService.1.CallControl.Group."; - size_t extension_len = strlen(callcontrol_extension); + char *allowed_objects[] = {"Device.Services.VoiceService.1.CallControl.Group.", NULL}; char *linker = NULL; switch (action) { @@ -68,16 +63,13 @@ static int set_CallControl_Group(char *refparam, struct dmctx *ctx, void *data, if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (strncmp(value, callcontrol_extension, extension_len) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "extension", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "extension", linker ? linker : ""); break; } return 0; @@ -85,8 +77,7 @@ static int set_CallControl_Group(char *refparam, struct dmctx *ctx, void *data, static int set_CallControl_CallingFeaturesSet(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char feature_set[64] = "Device.Services.VoiceService.1.CallControl.CallingFeatures.Set."; - size_t set_len = strlen(feature_set); + char *allowed_objects[] = {"Device.Services.VoiceService.1.CallControl.CallingFeatures.Set.", NULL}; char *linker = NULL; switch (action) { @@ -94,16 +85,13 @@ static int set_CallControl_CallingFeaturesSet(char *refparam, struct dmctx *ctx, if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (strncmp(value, feature_set, set_len) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "calling_features", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "calling_features", linker ? linker : ""); break; } return 0; @@ -111,8 +99,7 @@ static int set_CallControl_CallingFeaturesSet(char *refparam, struct dmctx *ctx, static int set_SIP_Client(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char sip_client[64] = "Device.Services.VoiceService.1.SIP.Client."; - size_t client_len = strlen(sip_client); + char *allowed_objects[] = {"Device.Services.VoiceService.1.SIP.Client.", NULL}; char *linker = NULL; switch (action) { @@ -120,16 +107,13 @@ static int set_SIP_Client(char *refparam, struct dmctx *ctx, void *data, char *i if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (strncmp(value, sip_client, client_len) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "provider", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "provider", linker ? linker : ""); break; } return 0; @@ -610,8 +594,6 @@ static int get_ServicesVoiceServiceCallControlLine_Provider(char *refparam, stru dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "provider", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -627,8 +609,6 @@ static int get_ServicesVoiceServiceCallControlLine_CallingFeatures(char *refpara dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "calling_features", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -668,8 +648,6 @@ static int get_ServicesVoiceServiceCallControlIncomingMap_Line(char *refparam, s dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "line", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -707,8 +685,6 @@ static int get_ServicesVoiceServiceCallControlIncomingMap_Extension(char *refpar dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "extension", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -769,8 +745,6 @@ static int get_ServicesVoiceServiceCallControlOutgoingMap_Line(char *refparam, s dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "line", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -786,8 +760,6 @@ static int get_ServicesVoiceServiceCallControlOutgoingMap_Extension(char *refpar dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "extension", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -813,7 +785,7 @@ static int get_ServicesVoiceServiceCallControlGroup_Extensions(char *refparam, s char *linker = NULL; adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", e->name, &linker); - if (linker) + if (linker && *linker) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", linker); } @@ -827,8 +799,7 @@ static int get_ServicesVoiceServiceCallControlGroup_Extensions(char *refparam, s static int set_ServicesVoiceServiceCallControlGroup_Extensions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char callcontrol_extension[64] = "Device.Services.VoiceService.1.CallControl.Extension."; - size_t extension_len = strlen(callcontrol_extension); + char *allowed_objects[] = {"Device.Services.VoiceService.1.CallControl.Extension.", NULL}; char *pch = NULL, *spch = NULL; char value_buf[512] = {0}; @@ -840,13 +811,8 @@ static int set_ServicesVoiceServiceCallControlGroup_Extensions(char *refparam, s return FAULT_9007; for (pch = strtok_r(value_buf, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { - char *linker = NULL; - if (strncmp(pch, callcontrol_extension, extension_len) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, pch, &linker); - if (linker == NULL) + if (dm_entry_validate_allowed_objects(ctx, pch, allowed_objects)) return FAULT_9007; } @@ -920,17 +886,18 @@ static int get_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "provider", &provider_string); if (strlen(provider_string)) { unsigned pos = 0; - char *ptr = NULL, *spch = NULL; + char *ptr = NULL, *spch = NULL; buf[0] = 0; - char *provider = dmstrdup(provider_string); - ptr = strtok_r(provider, ",", &spch); - while(ptr != NULL){ + char *provider = dmstrdup(provider_string); + ptr = strtok_r(provider, ",", &spch); + while (ptr != NULL) { char *linker = NULL; adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", !strcmp(type, "fxs") ? section_name(((struct dmmap_dup *)data)->config_section) : ptr, &linker); - if (linker) + if (linker && *linker) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", linker); - ptr = strtok_r(NULL, ",", &spch); + + ptr = strtok_r(NULL, ",", &spch); } if (pos) @@ -950,8 +917,9 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, char *pch = NULL, *spch = NULL; char value_buf[512] = {0}; char *type; - char buf[512] = {0}; - unsigned pos = 0; + char buf[512] = {0}; + unsigned pos = 0; + DM_STRNCPY(value_buf, value, sizeof(value_buf)); switch (action) { @@ -959,6 +927,9 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, if (dm_validate_string_list(value_buf, -1, -1, -1, -1, -1, NULL, NULL)) return FAULT_9007; + if (value_buf[0] == 0) + break; + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type); for (pch = strtok_r(value_buf, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { @@ -977,15 +948,17 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "provider", ""); for (pch = strtok_r(value_buf, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { char *linker = NULL; - if(pos != 0) - pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", ","); + + if (pos != 0) + pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", ","); + adm_entry_get_linker_value(ctx, pch, &linker); if(!strcmp(linker, "extension3")) - pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs1"); + pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs1"); else if(!strcmp(linker, "extension4")) - pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs2"); + pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs2"); else - pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", linker); + pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", linker); } dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "provider", buf); break; @@ -1000,8 +973,6 @@ static int get_ServicesVoiceServiceCallControlExtension_CallingFeatures(char *re dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "calling_features", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr104/servicesvoiceservicecodecprofile.c b/dmtree/tr104/servicesvoiceservicecodecprofile.c index 6753cc7d..f4b28698 100644 --- a/dmtree/tr104/servicesvoiceservicecodecprofile.c +++ b/dmtree/tr104/servicesvoiceservicecodecprofile.c @@ -18,12 +18,10 @@ /*#Device.Services.VoiceService.{i}.CodecProfile.{i}.Codec!UCI:asterisk/codec_profile,@i-1/name*/ static int get_ServicesVoiceServiceCodecProfile_Codec(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker; + char *linker = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &linker); adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr143/diagnostics.c b/dmtree/tr143/diagnostics.c index ccd29e3e..0e5b3549 100644 --- a/dmtree/tr143/diagnostics.c +++ b/dmtree/tr143/diagnostics.c @@ -58,17 +58,21 @@ static int get_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, { char *linker = get_diagnostics_option("ipping", "interface"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: IPPING_STOP @@ -291,17 +295,21 @@ static int get_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *c { char *linker = get_diagnostics_option("traceroute", "interface"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: TRACEROUTE_STOP @@ -533,18 +541,22 @@ static int set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, static int get_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker = get_diagnostics_option("download", "interface"); - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); return 0; } static int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: DOWNLOAD_DIAGNOSTIC_STOP @@ -859,18 +871,22 @@ static int set_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, s static int get_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker = get_diagnostics_option("upload", "interface"); - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); return 0; } static int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: UPLOAD_DIAGNOSTIC_STOP @@ -1203,17 +1219,21 @@ static int get_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct { char *linker = get_diagnostics_option("udpechodiag", "interface"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: UDPECHO_STOP; @@ -1462,17 +1482,21 @@ static int get_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, { char *linker = get_diagnostics_option("serverselection", "interface"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: SERVERSELECTION_STOP diff --git a/dmtree/tr181/atm.c b/dmtree/tr181/atm.c index be8cc070..2e9566e6 100644 --- a/dmtree/tr181/atm.c +++ b/dmtree/tr181/atm.c @@ -269,8 +269,7 @@ static int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch char atm_file[128]; dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->dmmap_section, "atm_ll_link", &linker); - if (linker != NULL) - adm_entry_get_linker_param(ctx, "Device.DSL.Channel.", linker, value); + adm_entry_get_linker_param(ctx, "Device.DSL.Channel.", linker, value); if (*value != NULL && (*value)[0] != '\0') return 0; diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index b80a993d..60bedf9d 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -975,7 +975,7 @@ static void remove_vlanid_from_ifname_list(struct uci_section *bridge_sec, char } } -static void set_lowerlayers_management_port(struct dmctx *ctx, void *data, char *value) +static int set_lowerlayers_management_port(struct dmctx *ctx, void *data, char *value) { char *pch = NULL, *spch = NULL, new_device[1024] = { 0, 0 }; unsigned pos = 0; @@ -994,6 +994,8 @@ static void set_lowerlayers_management_port(struct dmctx *ctx, void *data, char continue; pos += snprintf(&new_device[pos], sizeof(new_device) - pos, "%s,", linker); + } else { + return FAULT_9007; } } @@ -1001,6 +1003,7 @@ static void set_lowerlayers_management_port(struct dmctx *ctx, void *data, char new_device[pos - 1] = 0; dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "port", new_device); + return 0; } static void update_device_management_port(char *old_name, char *new_name, char *br_inst) @@ -2167,7 +2170,8 @@ static int get_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, lbuf[0] = 0; for (pch = strtok_r(port_device, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { adm_entry_get_linker_param(ctx, "Device.Bridging.Bridge.", pch, value); - pos += snprintf(&lbuf[pos], sizeof(lbuf) - pos, "%s,", *value ? *value : ""); + if (*value && (*value)[0] != 0) + pos += snprintf(&lbuf[pos], sizeof(lbuf) - pos, "%s,", *value); } if (pos) @@ -2185,21 +2189,24 @@ static int get_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, } adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", port_device ? port_device : "", value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", port_device ? port_device : "", value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.ATM.Link.", port_device ? port_device : "", value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PTM.Link.", port_device ? port_device : "", value); - - if (*value == NULL) - *value = ""; } return 0; } static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = { + "Device.Ethernet.Interface.", + "Device.WiFi.SSID.", + "Device.ATM.Link.", + "Device.PTM.Link.", + NULL}; char *management = NULL, *linker = NULL; dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); @@ -2212,27 +2219,25 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, if (management && strcmp(management, "1") == 0) break; - if (strncmp(value, "Device.Ethernet.Interface.", 26) != 0 && - strncmp(value, "Device.WiFi.SSID.", 17) != 0 && - strncmp(value, "Device.ATM.Link.", 16) != 0 && - strncmp(value, "Device.PTM.Link.", 16) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL || *linker == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; return 0; case VALUESET: if (management && strcmp(management, "1") == 0) { /* Management Port ==> true */ - set_lowerlayers_management_port(ctx, data, value); + return set_lowerlayers_management_port(ctx, data, value); } else { /* Management Port ==> false */ bool is_wireless_config = false; adm_entry_get_linker_value(ctx, value, &linker); + if (!linker || *linker == 0) { + dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "port", ""); + return 0; + } + // Update config section on dmmap_bridge_port if the linker is wirelss port or network port if (strncmp(value, "Device.WiFi.SSID.", 17) == 0) { dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "config", "wireless"); @@ -2770,23 +2775,28 @@ static int get_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo /* Get linker */ snprintf(linker, sizeof(linker),"br_%s:vlan_%s", ((struct bridge_vlanport_args *)data)->br_inst, vid); adm_entry_get_linker_param(ctx, "Device.Bridging.Bridge.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char lower_layer_path[256] = {0}; + char *allowed_objects[] = { + lower_layer_path, + NULL}; + + snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.VLAN.", ((struct bridge_vlanport_args *)data)->br_inst); switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: - snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.VLAN.", ((struct bridge_vlanport_args *)data)->br_inst); - /* Check the path object is correct or no */ if (strncmp(value, lower_layer_path, strlen(lower_layer_path)) == 0) { /* Check linker exist */ @@ -2878,25 +2888,29 @@ static int get_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo dmuci_get_value_by_section_string(((struct bridge_vlanport_args *)data)->bridge_vlanport_dmmap_sec, "port_name", &port_name); snprintf(linker, sizeof(linker), "br_%s:%s+%s", ((struct bridge_vlanport_args *)data)->br_inst, port_name, name); - adm_entry_get_linker_param(ctx, "Device.Bridging.Bridge.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char lower_layer_path[256] = {0}; + char *allowed_objects[] = { + lower_layer_path, + NULL}; + + snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.Port.", ((struct bridge_vlanport_args *)data)->br_inst); switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: - snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.Port.", ((struct bridge_vlanport_args *)data)->br_inst); - if (strncmp(value, lower_layer_path, strlen(lower_layer_path)) == 0) { char *linker = NULL; @@ -3079,20 +3093,16 @@ static int get_BridgingBridgeProviderBridge_SVLANcomponent(char *refparam, struc static int set_BridgingBridgeProviderBridge_SVLANcomponent(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *bridge_linker = NULL; + char *allowed_objects[] = {"Device.Bridging.Bridge.", NULL}; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (strncmp(value, "Device.Bridging.Bridge.", 23) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; - adm_entry_get_linker_value(ctx, value, &bridge_linker); - if (bridge_linker == NULL) - return FAULT_9005; - break; case VALUESET: set_Provider_bridge_component(refparam, ctx, data, instance, value, "SVLAN"); @@ -3127,8 +3137,8 @@ static int get_BridgingBridgeProviderBridge_CVLANcomponents(char *refparam, stru static int set_BridgingBridgeProviderBridge_CVLANcomponents(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.Bridging.Bridge.", NULL}; char *pch = NULL, *pchr = NULL; - char *bridge_linker = NULL; char buf[512] = {0}; DM_STRNCPY(buf, value, sizeof(buf)); @@ -3142,12 +3152,8 @@ static int set_BridgingBridgeProviderBridge_CVLANcomponents(char *refparam, stru for (pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) { // Parse each Bridge path and validate: - if (strncmp(pch, "Device.Bridging.Bridge.", 23) != 0) + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; - - adm_entry_get_linker_value(ctx, pch, &bridge_linker); - if (bridge_linker == NULL) - return FAULT_9005; } break; diff --git a/dmtree/tr181/deviceinfo.c b/dmtree/tr181/deviceinfo.c index 8f08216e..2a3a27d9 100644 --- a/dmtree/tr181/deviceinfo.c +++ b/dmtree/tr181/deviceinfo.c @@ -260,8 +260,6 @@ static int get_device_active_fwimage(char *refparam, struct dmctx *ctx, void *da snprintf(linker, sizeof(linker), "fw_image:%s", id ? id : ""); adm_entry_get_linker_param(ctx, "Device.DeviceInfo.FirmwareImage.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -283,13 +281,12 @@ static int get_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data snprintf(linker, sizeof(linker), "fw_image:%s", id ? id : ""); adm_entry_get_linker_param(ctx, "Device.DeviceInfo.FirmwareImage.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.DeviceInfo.FirmwareImage.", NULL}; char *linker = NULL; switch (action) { @@ -297,11 +294,7 @@ static int set_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data if (dm_validate_string(value, -1, -1, NULL, NULL)) return FAULT_9007; - if (strncmp(value, "Device.DeviceInfo.FirmwareImage.", 32) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL || *linker == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index 8f678949..d395f596 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -177,6 +177,7 @@ int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *config_s, struct uci_section *dmmap_s, char *dmmap_name, char *proto, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL, *added_by_controller = NULL, *curr_proto = NULL; struct uci_section *interface_s = NULL; @@ -185,14 +186,7 @@ int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *confi if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (value == NULL || *value == '\0') - break; - - if (strncmp(value, "Device.IP.Interface.", 20) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL || linker[0] == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; @@ -1328,27 +1322,26 @@ static int get_DHCPv4ServerPool_Interface(char *refparam, struct dmctx *ctx, voi { char *linker = dmstrdup(((struct dhcp_args *)data)->interface); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; - dmfree(linker); return 0; } static int set_DHCPv4ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section((((struct dhcp_args *)data)->sections)->config_section, "interface", linker); - dmfree(linker); - } + dmuci_set_value_by_section((((struct dhcp_args *)data)->sections)->config_section, "interface", linker ? linker : ""); return 0; } return 0; @@ -2032,8 +2025,6 @@ static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d char *linker = dmstrdup(dhcp_s ? section_name(dhcp_s) : ""); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr181/dhcpv6.c b/dmtree/tr181/dhcpv6.c index a09ed05e..b3c7b6fa 100644 --- a/dmtree/tr181/dhcpv6.c +++ b/dmtree/tr181/dhcpv6.c @@ -488,8 +488,6 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d char *linker = dmstrdup(parent_s ? parent_s + 1 : dhcpv6_s ? section_name(dhcpv6_s) : ""); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -730,30 +728,28 @@ static int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *d static int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker; - linker = dmstrdup(((struct dhcpv6_args *)data)->interface); + char *linker = dmstrdup(((struct dhcpv6_args *)data)->interface); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; - dmfree(linker); return 0; } static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "interface", linker); - dmfree(linker); - } + dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "interface", linker ? linker : ""); break; } return 0; diff --git a/dmtree/tr181/dns.c b/dmtree/tr181/dns.c index a9fda54c..9cde4b90 100644 --- a/dmtree/tr181/dns.c +++ b/dmtree/tr181/dns.c @@ -250,12 +250,10 @@ static int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data, static int get_dns_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker; + char *linker = NULL; dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &linker); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -336,8 +334,6 @@ static int get_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, { char *linker = get_diagnostics_option("nslookup", "interface"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -521,29 +517,38 @@ static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *i static int set_dns_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *str, *interface, *ip, *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL || linker[0] == '\0') + dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); + dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip); + + if (!linker || linker[0] == 0) { + dmuci_del_list_value("network", interface, "dns", ip); + return 0; + } else if (strcmp(interface, linker) == 0) return 0; - dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); - if (strcmp(interface, linker) == 0) - return 0; dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str); if (str[0] == '1') return 0; - dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip); + dmuci_del_list_value("network", interface, "dns", ip); dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str); if (str[0] == '1') dmuci_add_list_value("network", linker, "dns", ip); + dmuci_set_value_by_section((struct uci_section *)data, "interface", interface); break; } @@ -601,10 +606,16 @@ static int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmct static int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; + switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: NSLOOKUP_STOP diff --git a/dmtree/tr181/dsl.c b/dmtree/tr181/dsl.c index e82cdae7..308dc023 100644 --- a/dmtree/tr181/dsl.c +++ b/dmtree/tr181/dsl.c @@ -998,10 +998,9 @@ static int get_DSLChannel_Name(char *refparam, struct dmctx *ctx, void *data, ch static int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char linker[8]; + snprintf(linker, sizeof(linker), "line_%s", ((struct dsl_line_args *)data)->id); - adm_entry_get_linker_param(ctx, "Device.DSL.Line.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.DSL.Line.", linker, value); return 0; } diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index d0a646f6..cbda1195 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -425,29 +425,30 @@ static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, voi /*#Device.DynamicDNS.Client.{i}.Server!UCI:ddns/service,@i-1/service_name*/ static int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *service_name; + char *service_name = NULL; + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "service_name", &service_name); adm_entry_get_linker_param(ctx, "Device.DynamicDNS.Server.", service_name, value); - if (*value == NULL) - *value = ""; return 0; } static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.DynamicDNS.Server.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "service_name", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "service_name", linker ? linker : ""); break; } return 0; @@ -456,29 +457,30 @@ static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void * /*#Device.DynamicDNS.Client.{i}.Interface!UCI:ddns/service,@i-1/interface*/ static int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *interface; + char *interface = NULL; + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface", &interface); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", interface, value); - if (*value == NULL) - *value = ""; return 0; } static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker ? linker : ""); break; } return 0; diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index b0739a7b..b6836631 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -78,7 +78,7 @@ static void get_bridge_port_linker(struct dmctx *ctx, char *device_s_name, char { struct uci_section *dmmap_section = NULL, *bridge_port = NULL; - *value = NULL; + *value = ""; get_dmmap_section_of_config_section("dmmap_bridge", "device", device_s_name, &dmmap_section); if (dmmap_section != NULL) { char *br_inst = NULL; @@ -946,48 +946,66 @@ static int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void * static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker = NULL; - char *device_s_type = NULL; + dmuci_get_value_by_section_string((struct uci_section *)data, "LowerLayers", value); - dmuci_get_value_by_section_string((struct uci_section *)data, "device", &linker); - if (!linker || *linker == '\0') - return 0; + if ((*value)[0] == '\0') { + char *linker = NULL; + char *device_s_type = NULL; - // get device section mapped to this device name - struct uci_section *br_device_s = ethernet___get_device_section(linker); + dmuci_get_value_by_section_string((struct uci_section *)data, "device", &linker); + if (!linker || *linker == '\0') + return 0; - if (br_device_s) dmuci_get_value_by_section_string(br_device_s, "type", &device_s_type); + // get device section mapped to this device name + struct uci_section *br_device_s = ethernet___get_device_section(linker); - if (br_device_s && strcmp(device_s_type, "bridge") == 0) { - get_bridge_port_linker(ctx, section_name(br_device_s), value); - } else { - char *vid = strchr(linker, '.'); - if (vid) *vid = '\0'; - char *macvlan = strchr(linker, '_'); - if (macvlan) *macvlan = '\0'; - adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); + if (br_device_s) dmuci_get_value_by_section_string(br_device_s, "type", &device_s_type); + + if (br_device_s && strcmp(device_s_type, "bridge") == 0) { + get_bridge_port_linker(ctx, section_name(br_device_s), value); + } else { + char *vid = strchr(linker, '.'); + if (vid) *vid = '\0'; + char *macvlan = strchr(linker, '_'); + if (macvlan) *macvlan = '\0'; + adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); + } } - - if (*value == NULL) - *value = ""; return 0; } static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char eth_interface[64] = "Device.Ethernet.Interface."; + char bridge_port[64] = "Device.Bridging.Bridge."; + char atm_link[32] = "Device.ATM.Link."; + char ptm_link[32] = "Device.PTM.Link."; + char *allowed_objects[] = { + eth_interface, + bridge_port, + atm_link, + ptm_link, + NULL}; char *link_linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &link_linker); - if (link_linker == NULL || *link_linker == '\0') - return -1; - if (strncmp(value, "Device.Ethernet.Interface.", 26) == 0) { + // Store LowerLayers value under dmmap section + dmuci_set_value_by_section((struct uci_section *)data, "LowerLayers", value); + + if (!link_linker || link_linker[0] == 0) { + dmuci_set_value_by_section((struct uci_section *)data, "device", ""); + } else if (strncmp(value, eth_interface, strlen(eth_interface)) == 0) { struct uci_section *s = NULL; char *int_name = NULL; @@ -1000,7 +1018,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void break; } } - } else if (strncmp(value, "Device.Bridging.Bridge.", 23) == 0) { + } else if (strncmp(value, bridge_port, strlen(bridge_port)) == 0) { char br_linker[250] = {0}; DM_STRNCPY(br_linker, link_linker, sizeof(br_linker)); @@ -1256,31 +1274,40 @@ static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx adm_entry_get_linker_param(ctx, "Device.Ethernet.VLANTermination.", dev_name, value); } else { adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", name, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", ifname, value); } - if (*value == NULL) - *value = ""; - return 0; } static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char eth_vlan_term[64] = "Device.Ethernet.VLANTermination."; + char eth_link[32] = "Device.Ethernet.Link."; + char *allowed_objects[] = { + eth_vlan_term, + eth_link, + NULL}; char *vlan_linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &vlan_linker); - if (vlan_linker == NULL || *vlan_linker == '\0') - return -1; - if (strncmp(value, "Device.Ethernet.Link.", 21) == 0) { + if (!vlan_linker || vlan_linker[0] == 0) { + // Set ifname and name options of device section to empty value + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", ""); + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", ""); + } else if (strncmp(value, eth_link, strlen(eth_link)) == 0) { char new_name[16] = {0}, *type; // Get type option from device section @@ -1335,7 +1362,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", vlan_linker); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", new_name); - } else if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) == 0) { + } else if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) { struct uci_section *ss = NULL; char *dev_name, *inner_vid, *vid, new_name[16] = {0}; @@ -1614,12 +1641,10 @@ static int get_EthernetRMONStats_Name(char *refparam, struct dmctx *ctx, void *d static int get_EthernetRMONStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *linker; + char *linker = NULL; dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "ifname", &linker); adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr181/firewall.c b/dmtree/tr181/firewall.c index 26aa9095..d5985c17 100644 --- a/dmtree/tr181/firewall.c +++ b/dmtree/tr181/firewall.c @@ -395,7 +395,7 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da src_iface[0] = 0; uci_foreach_element(net_list, e) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); - if (ifaceobj) + if (ifaceobj && *ifaceobj) pos += snprintf(&src_iface[pos], sizeof(src_iface) - pos, "%s,", ifaceobj); } @@ -403,7 +403,7 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da src_iface[pos - 1] = 0; } else { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", src, &ifaceobj); - if (ifaceobj) + if (ifaceobj && *ifaceobj) DM_STRNCPY(src_iface, ifaceobj, sizeof(src_iface)); } @@ -450,7 +450,7 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data dst_iface[0] = 0; uci_foreach_element(net_list, e) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); - if (ifaceobj) + if (ifaceobj && *ifaceobj) pos += snprintf(&dst_iface[pos], sizeof(dst_iface) - pos, "%s,", ifaceobj); } @@ -458,7 +458,7 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data dst_iface[pos - 1] = 0; } else { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", dest, &ifaceobj); - if (ifaceobj) + if (ifaceobj && *ifaceobj) DM_STRNCPY(dst_iface, ifaceobj, sizeof(dst_iface)); } @@ -943,6 +943,7 @@ static int set_rule_log(char *refparam, struct dmctx *ctx, void *data, char *ins static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *iface = NULL, *option = NULL; switch (action) { @@ -950,11 +951,7 @@ static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *v if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (*value == '\0') - break; - - adm_entry_get_linker_value(ctx, value, &iface); - if (iface == NULL || iface[0] == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; diff --git a/dmtree/tr181/hosts.c b/dmtree/tr181/hosts.c index de9eca03..890079ca 100644 --- a/dmtree/tr181/hosts.c +++ b/dmtree/tr181/hosts.c @@ -98,8 +98,6 @@ static int get_HostsHost_DHCPClient(char *refparam, struct dmctx *ctx, void *dat { char *linker = dmjson_get_value((json_object *)data, 1, "macaddr"); adm_entry_get_linker_param(ctx, "Device.DHCPv4.Server.Pool.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -107,8 +105,6 @@ static int get_HostsHost_AssociatedDevice(char *refparam, struct dmctx *ctx, voi { char *linker = dmjson_get_value((json_object *)data, 1, "macaddr"); adm_entry_get_linker_param(ctx, "Device.WiFi.AccessPoint.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -120,8 +116,6 @@ static int get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", linker, value); else adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -129,8 +123,6 @@ static int get_HostsHost_Layer3Interface(char *refparam, struct dmctx *ctx, void { char *linker = dmjson_get_value((json_object *)data, 1, "network"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr181/ieee1905.c b/dmtree/tr181/ieee1905.c index 40b34b91..f5eeb3dd 100644 --- a/dmtree/tr181/ieee1905.c +++ b/dmtree/tr181/ieee1905.c @@ -1365,8 +1365,6 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceNonIEEE1905Neighbor_LocalI { char *linker = ((struct ieee1905_device_nonieee1905neighbor_args *)data)->mac_addr; adm_entry_get_linker_param(ctx, "Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -1402,8 +1400,6 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceIEEE1905Neighbor_LocalInte { char *linker = dmjson_get_value((json_object *)data, 1, "macaddress"); adm_entry_get_linker_param(ctx, "Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.", linker, value); - if (*value == NULL) - *value = ""; return 0; } @@ -1496,8 +1492,6 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceBridgingTuple_InterfaceLis { char *linker = dmjson_get_value((json_object *)data, 1, "macaddress"); adm_entry_get_linker_param(ctx, "Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.", linker, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index c9bec85e..1d1248ac 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -1236,50 +1236,67 @@ static int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *d static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char linker[64] = {0}; - char *proto; + struct uci_section *dmmap_section = NULL; - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - if (strstr(proto, "ppp")) { - snprintf(linker, sizeof(linker), "%s", section_name((struct uci_section *)data)); - adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", linker, value); - if (*value != NULL) - return 0; - } + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "LowerLayers", value); - char *device = get_device(section_name((struct uci_section *)data)); + if ((*value)[0] == '\0') { + char linker[64] = {0}; + char *proto; - /* If the device value is empty, then get its value directly from device option */ - if (*device == '\0') - dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device); + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strstr(proto, "ppp")) { + snprintf(linker, sizeof(linker), "%s", section_name((struct uci_section *)data)); + adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", linker, value); + if (*value != NULL && (*value)[0] != 0) + return 0; + } - if (device[0] != '\0') { - adm_entry_get_linker_param(ctx, "Device.Ethernet.VLANTermination.", device, value); - if (*value != NULL) - return 0; - } + char *device = get_device(section_name((struct uci_section *)data)); - if (device[0] != '\0') { - DM_STRNCPY(linker, device, sizeof(linker)); - char *vid = strchr(linker, '.'); - if (vid) *vid = '\0'; + /* If the device value is empty, then get its value directly from device option */ + if (*device == '\0') + dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device); + + if (device[0] != '\0') { + adm_entry_get_linker_param(ctx, "Device.Ethernet.VLANTermination.", device, value); + if (*value != NULL && (*value)[0] != 0) + return 0; + } + + if (device[0] != '\0') { + DM_STRNCPY(linker, device, sizeof(linker)); + char *vid = strchr(linker, '.'); + if (vid) *vid = '\0'; + } else { + struct uci_section *s = NULL; + + get_dmmap_section_of_config_section_eq("dmmap", "link", "section_name", section_name((struct uci_section *)data), &s); + dmuci_get_value_by_section_string(s, "linker", &device); + DM_STRNCPY(linker, device, sizeof(linker)); + } + + adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", linker, value); } else { - struct uci_section *s = NULL; + char *linker = NULL; - get_dmmap_section_of_config_section_eq("dmmap", "link", "section_name", section_name((struct uci_section *)data), &s); - dmuci_get_value_by_section_string(s, "linker", &device); - DM_STRNCPY(linker, device, sizeof(linker)); + adm_entry_get_linker_value(ctx, *value, &linker); + if (!linker || *linker == 0) + *value = ""; } - - adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", linker, value); - if (*value == NULL) - *value = ""; - return 0; } static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *dmmap_section = NULL; + char eth_vlan_term[64] = "Device.Ethernet.VLANTermination."; + char eth_link[32] = "Device.Ethernet.Link."; + char *allowed_objects[] = { + eth_vlan_term, + eth_link, + NULL}; char linker_buf[32] = {0}; char *ip_linker = NULL; @@ -1288,21 +1305,26 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; - if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) != 0 && - strncmp(value, "Device.Ethernet.Link.", 21) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &ip_linker); - if (ip_linker == NULL || *ip_linker == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &ip_linker); + // Store LowerLayers value under dmmap_network section + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "LowerLayers", value); + + if (!ip_linker || *ip_linker == 0) { + // Update device option + dmuci_set_value_by_section((struct uci_section *)data, "device", ""); + return 0; + } + DM_STRNCPY(linker_buf, ip_linker, sizeof(linker_buf)); - if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) == 0) { + if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) { struct uci_section *s = NULL, *stmp = NULL; // Remove the device section corresponding to this interface if exists @@ -1341,7 +1363,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * // Update device option dmuci_set_value_by_section((struct uci_section *)data, "device", linker_buf); - } else if (strncmp(value, "Device.Ethernet.Link.", 21) == 0) { + } else if (strncmp(value, eth_link, strlen(eth_link)) == 0) { // Get interface name from Ethernet.Link. object struct uci_section *eth_link_s = NULL; @@ -2020,10 +2042,7 @@ static int get_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx * char *linker = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "address", &linker); - if (linker && *linker) - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); return 0; } diff --git a/dmtree/tr181/nat.c b/dmtree/tr181/nat.c index 05f7f202..a69cd719 100644 --- a/dmtree/tr181/nat.c +++ b/dmtree/tr181/nat.c @@ -234,7 +234,7 @@ static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx uci_foreach_element(v, e) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN - if (ifaceobj) + if (ifaceobj && *ifaceobj) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", ifaceobj); } } @@ -249,22 +249,24 @@ static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *iface, *pch, *pchr, buf[256] = ""; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: DM_STRNCPY(buf, value, sizeof(buf)); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "network", ""); for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) { adm_entry_get_linker_value(ctx, pch, &iface); - if (iface && *iface) { - dmuci_add_list_value_by_section(((struct dmmap_dup *)data)->config_section, "network", iface); - dmfree(iface); - } + dmuci_add_list_value_by_section(((struct dmmap_dup *)data)->config_section, "network", iface); } return 0; } @@ -372,7 +374,7 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi uci_foreach_element(v, e) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN - if (ifaceobj) + if (ifaceobj && *ifaceobj) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", ifaceobj); } } @@ -387,12 +389,17 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *iface = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &iface); @@ -424,6 +431,8 @@ static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi } } dmfree(iface); + } else { + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src", ""); } break; } diff --git a/dmtree/tr181/ppp.c b/dmtree/tr181/ppp.c index 86761ddc..bca13c47 100644 --- a/dmtree/tr181/ppp.c +++ b/dmtree/tr181/ppp.c @@ -776,32 +776,37 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch } adm_entry_get_linker_param(ctx, "Device.ATM.Link.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PTM.Link.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", ifname, value); - if (*value == NULL) - *value = ""; return 0; } static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = { + "Device.Ethernet.Interface.", + "Device.ATM.Link.", + "Device.PTM.Link.", + "Device.WiFi.SSID.", + NULL}; char *ppp_linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: adm_entry_get_linker_value(ctx, value, &ppp_linker); - if (ppp_linker && *ppp_linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "device", ppp_linker); - dmfree(ppp_linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "device", ppp_linker ? ppp_linker : ""); return 0; } return 0; diff --git a/dmtree/tr181/ptm.c b/dmtree/tr181/ptm.c index 956fa01f..985a9070 100644 --- a/dmtree/tr181/ptm.c +++ b/dmtree/tr181/ptm.c @@ -193,10 +193,7 @@ static int find_lower_layer_by_dmmap_link(struct dmctx *ctx, void *data, char* d char *linker = NULL; dmuci_get_value_by_section_string((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", &linker); - if (linker != NULL) - adm_entry_get_linker_param(ctx, dm_object, linker, value); - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, dm_object, linker, value); return 0; } diff --git a/dmtree/tr181/qos.c b/dmtree/tr181/qos.c index 900b10a1..011e81b5 100644 --- a/dmtree/tr181/qos.c +++ b/dmtree/tr181/qos.c @@ -341,33 +341,38 @@ static int get_QInterface(char *refparam, struct dmctx *ctx, void *data, char *i dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ifname", &ifname); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", ifname, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", ifname, value); - if (*value == NULL) - *value = ""; return 0; } static int set_QInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = { + "Device.IP.Interface.", + "Device.PPP.Interface.", + "Device.Ethernet.Interface.", + "Device.WiFi.Radio.", + NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", linker ? linker : ""); break; } return 0; @@ -1533,40 +1538,30 @@ static int set_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data static int get_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *queue_link; + char *queue_link = NULL; + dmuci_get_value_by_section_string((struct uci_section *)data, "queue", &queue_link); adm_entry_get_linker_param(ctx, "Device.QoS.Queue.", queue_link, value); - if (*value == NULL) - *value = ""; return 0; } static int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *queue_link = NULL; + char *allowed_objects[] = {"Device.QoS.Queue.", NULL}; + char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (value == NULL || *value == '\0') - break; - - if (strncmp(value, "Device.QoS.Queue.", 17) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &queue_link); - if (queue_link == NULL || *queue_link == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: - if (value == NULL || *value == '\0') - break; - - adm_entry_get_linker_value(ctx, value, &queue_link); - dmuci_set_value_by_section((struct uci_section *)data, "queue", queue_link); + adm_entry_get_linker_value(ctx, value, &linker); + dmuci_set_value_by_section((struct uci_section *)data, "queue", linker ? linker : ""); break; } return 0; @@ -1574,41 +1569,39 @@ static int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data static int get_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *intf_link; + char *intf_link = NULL; + dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &intf_link); adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", intf_link, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.IP.Interface.", intf_link, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", intf_link, value); - if (*value == NULL) - *value = ""; + return 0; } static int set_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *intf_link = NULL; + char *allowed_objects[] = { + "Device.Ethernet.Interface.", + "Device.IP.Interface.", + "Device.PPP.Interface.", + NULL}; + char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (value == NULL || *value == '\0') - break; - - adm_entry_get_linker_value(ctx, value, &intf_link); - if (intf_link == NULL || *intf_link == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: - if (value == NULL || *value == '\0') - break; - - adm_entry_get_linker_value(ctx, value, &intf_link); - dmuci_set_value_by_section((struct uci_section *)data, "interface", intf_link); + adm_entry_get_linker_value(ctx, value, &linker); + dmuci_set_value_by_section((struct uci_section *)data, "interface", linker ? linker : ""); break; } return 0; diff --git a/dmtree/tr181/routeradvertisement.c b/dmtree/tr181/routeradvertisement.c index cdd7ad59..72b2ac33 100644 --- a/dmtree/tr181/routeradvertisement.c +++ b/dmtree/tr181/routeradvertisement.c @@ -283,26 +283,26 @@ static int get_RouterAdvertisementInterfaceSetting_Interface(char *refparam, str dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface", &linker); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); - if (*value == NULL) - *value = ""; return 0; } static int set_RouterAdvertisementInterfaceSetting_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, -1, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker ? linker : ""); break; } return 0; diff --git a/dmtree/tr181/routing.c b/dmtree/tr181/routing.c index 57e8ae72..a7534ab2 100644 --- a/dmtree/tr181/routing.c +++ b/dmtree/tr181/routing.c @@ -674,29 +674,27 @@ static int get_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *c char *linker = NULL; dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "interface", &linker); - if (linker && linker[0] != '\0') { - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - } + adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } static int set_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); - if (linker && *linker) { - dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker); - dmfree(linker); - } + dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker ? linker : ""); return 0; } return 0; @@ -957,11 +955,9 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, } } - if (iface[0] != '\0') { + if (iface && *iface != 0) adm_entry_get_linker_param(ctx, "Device.IP.Interface.", iface, value); - if (*value == NULL) - *value = ""; - } + return 0; } diff --git a/dmtree/tr181/upnp.c b/dmtree/tr181/upnp.c index 89261bf5..25537f88 100644 --- a/dmtree/tr181/upnp.c +++ b/dmtree/tr181/upnp.c @@ -504,10 +504,8 @@ static int get_UPnPDiscoveryService_Location(char *refparam, struct dmctx *ctx, static int get_UPnPDiscoveryService_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.RootDevice.", ((struct upnpdiscovery *)data)->uuid, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.Device.", ((struct upnpdiscovery *)data)->uuid, value); - if (*value == NULL) - *value = ""; return 0; } @@ -549,25 +547,23 @@ static int get_UPnPDescriptionDeviceInstance_UDN(char *refparam, struct dmctx *c static int get_UPnPDescriptionDeviceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { adm_entry_get_linker_param(ctx, "Device.UPnP.Description.DeviceInstance.", ((struct upnp_device_inst *)data)->parentudn, value); - if (*value == NULL) - *value = ""; return 0; } static int get_UPnPDescriptionDeviceInstance_DiscoveryDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data; - char **udnarray = NULL; - size_t length; if (upnpdevinst->udn && upnpdevinst->udn[0]) { + char **udnarray = NULL; + size_t length = 0; + udnarray = strsplit(upnpdevinst->udn, ":", &length); adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.RootDevice.", udnarray[1], value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.Device.", udnarray[1], value); } - if (*value == NULL) - *value = ""; + return 0; } @@ -651,8 +647,6 @@ static int get_UPnPDescriptionDeviceInstance_PresentationURL(char *refparam, str static int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { adm_entry_get_linker_param(ctx, "Device.UPnP.Description.DeviceInstance.", ((struct upnp_service_inst *)data)->parentudn, value); - if (*value == NULL) - *value = ""; return 0; } @@ -665,14 +659,10 @@ static int get_UPnPDescriptionServiceInstance_ServiceId(char *refparam, struct d static int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *usn = NULL; + char usn[64] = {0}; - dmasprintf(&usn, "%s::%s", ((struct upnp_service_inst *)data)->parentudn, ((struct upnp_service_inst *)data)->servicetype); - if (usn && usn[0]) { - adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.Service.", usn, value); - if (*value == NULL) - *value = ""; - } + snprintf(usn, sizeof(usn), "%s::%s", ((struct upnp_service_inst *)data)->parentudn, ((struct upnp_service_inst *)data)->servicetype); + adm_entry_get_linker_param(ctx, "Device.UPnP.Discovery.Service.", usn, value); return 0; } diff --git a/dmtree/tr181/usb.c b/dmtree/tr181/usb.c index ef24d6a5..b2ec2737 100644 --- a/dmtree/tr181/usb.c +++ b/dmtree/tr181/usb.c @@ -895,7 +895,7 @@ out: static int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct usb_port *port= (struct usb_port *)data; + struct usb_port *port = (struct usb_port *)data; adm_entry_get_linker_param(ctx, "Device.USB.Port.", port->folder_name, value); return 0; } @@ -912,15 +912,15 @@ static int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, v regex_t regex1 = {}; regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - if(regexec(®ex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL){ + if (regexec(®ex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL) { *value = ""; goto out; } + dmuci_get_value_by_section_string(port->dmsect, "usb_host_instance", &host_inst); snprintf(usb_host_path, sizeof(usb_host_path), "Device.USB.USBHosts.Host.%s.Device.", host_inst); adm_entry_get_linker_param(ctx, usb_host_path, port->folder_name, value); - if (*value == NULL) - *value = ""; + out: regfree(®ex1); return 0; diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index 312f6e4b..8a0315a8 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -2448,9 +2448,7 @@ static int set_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, static int get_WiFiEndPoint_SSIDReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", ((struct wifi_enp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", ((struct wifi_enp_args *)data)->ifname, value); return 0; } @@ -2854,29 +2852,27 @@ static int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, static int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - if (data && ((struct wifi_ssid_args *)data)->linker[0] != '\0') { - adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", ((struct wifi_ssid_args *)data)->linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - } + adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", ((struct wifi_ssid_args *)data)->linker, value); return 0; } static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *ssid_linker = NULL; + char *allowed_objects[] = {"Device.WiFi.Radio.", NULL}; + char *linker = NULL; switch (action) { case VALUECHECK: if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + return 0; case VALUESET: - adm_entry_get_linker_value(ctx, value, &ssid_linker); - if (ssid_linker && *ssid_linker) { - dmuci_set_value_by_section((((struct wifi_ssid_args *)data)->sections)->config_section, "device", ssid_linker); - dmfree(ssid_linker); - } + adm_entry_get_linker_value(ctx, value, &linker); + dmuci_set_value_by_section((((struct wifi_ssid_args *)data)->sections)->config_section, "device", linker ? linker : ""); return 0; } return 0; @@ -2884,14 +2880,13 @@ static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, c static int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", ((struct wifi_acp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; + adm_entry_get_linker_param(ctx, "Device.WiFi.SSID.", ((struct wifi_acp_args *)data)->ifname, value); return 0; } static int set_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.WiFi.SSID.", NULL}; struct uci_section *s = NULL, *ssid_dmmap_s = NULL; char *linker = NULL; @@ -2900,14 +2895,7 @@ static int set_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char * if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; - if (*value == '\0') - break; - - if (strncmp(value, "Device.WiFi.SSID.", 17) != 0) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL || linker[0] == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; diff --git a/dmtree/vendor/iopsys/tr181/times.c b/dmtree/vendor/iopsys/tr181/times.c index f34b6b97..8122791f 100644 --- a/dmtree/vendor/iopsys/tr181/times.c +++ b/dmtree/vendor/iopsys/tr181/times.c @@ -23,27 +23,23 @@ static int get_time_source_interface(char *refparam, struct dmctx *ctx, void *da char *iface = NULL; dmuci_get_option_value_string("system", "ntp", "interface", &iface); - if (*iface == '\0' || strlen(iface) == 0) - return 0; adm_entry_get_linker_param(ctx, "Device.IP.Interface.", iface, value); - if (*value == NULL) - *value = ""; return 0; } static int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *iface = NULL; switch (action) { case VALUECHECK: - adm_entry_get_linker_value(ctx, value, &iface); - if (iface == NULL || iface[0] == '\0') + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) return FAULT_9007; break; case VALUESET: adm_entry_get_linker_value(ctx, value, &iface); - dmuci_set_value("system", "ntp", "interface", iface); + dmuci_set_value("system", "ntp", "interface", iface ? iface : ""); return 0; } return 0; diff --git a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c index 369ed59a..3ccc0ffd 100644 --- a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c +++ b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c @@ -1353,20 +1353,14 @@ static int get_igmp_cgrp_assoc_dev_no_of_entries(char *refparam, struct dmctx *c static int get_igmp_cgrp_adev_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *ifname = dmjson_get_value((json_object *)data, 1, "device"); - adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", ifname, value); - if (*value == NULL) - *value = ""; return 0; } static int get_igmp_cgrp_adev_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *ipaddr = dmjson_get_value((json_object *)data, 1, "ipaddr"); - adm_entry_get_linker_param(ctx, "Device.Hosts.Host.", ipaddr, value); - if (*value == NULL) - *value = ""; return 0; } @@ -1737,6 +1731,7 @@ static void set_igmpp_iface_val(void *data, char *instance, char *linker, char * static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL, *interface_linker = NULL; char ifname[16] = {0}; char *if_type = NULL; @@ -1747,6 +1742,10 @@ static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: // First check if this is a bridge type interface @@ -1770,6 +1769,8 @@ static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da } break; } + } else { + interface_linker = ""; } } @@ -1833,16 +1834,11 @@ static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da } else { // in case its a L3 interface, the ifname would be section name of network file in the dmmap file, // which infact is the linker, just use that directly. - if (igmpp_ifname == NULL) - goto end; adm_entry_get_linker_param(ctx, "Device.IP.Interface.", igmpp_ifname, value); } end: - if (*value == NULL) - *value = ""; - return 0; } diff --git a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c index 039a0805..42b135ff 100644 --- a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c +++ b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c @@ -436,6 +436,7 @@ static int get_mldp_cgrp_stats_lrcvd(char *refparam, struct dmctx *ctx, void *da static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *allowed_objects[] = {"Device.IP.Interface.", NULL}; char *linker = NULL, *interface_linker = NULL; char ifname[16]; char *up, *f_inst, *if_type; @@ -446,6 +447,10 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat case VALUECHECK: if (dm_validate_string(value, -1, 256, NULL, NULL)) return FAULT_9007; + + if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) + return FAULT_9007; + break; case VALUESET: // First check if this is a bridge type interface @@ -465,8 +470,11 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat dmuci_get_value_by_section_string(s, "device", &interface_linker); break; } + } else { + interface_linker = ""; } } + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); @@ -551,16 +559,10 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat } } - if (tmp_linker == NULL) - goto end; - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", tmp_linker, value); } end: - if (*value == NULL) - *value = ""; - return 0; } diff --git a/dmtree/vendor/openwrt/tr181/qos.c b/dmtree/vendor/openwrt/tr181/qos.c index e0942f2c..d1d0d2c9 100644 --- a/dmtree/vendor/openwrt/tr181/qos.c +++ b/dmtree/vendor/openwrt/tr181/qos.c @@ -262,12 +262,10 @@ static int openwrt__get_QoSClassification_Interface(char *refparam, struct dmctx dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", section_name(s), value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", section_name(s), value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", section_name(s), value); - if (*value == NULL) - *value = ""; } } return 0; @@ -485,14 +483,12 @@ static int openwrt__get_QoSQueueStats_Interface(char *refparam, struct dmctx *ct struct queuestats *qts = (struct queuestats*)data; adm_entry_get_linker_param(ctx, "Device.IP.Interface.", qts->dev, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", qts->dev, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", qts->dev, value); - if (*value == NULL) + if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", qts->dev, value); - if (*value == NULL) - *value = ""; return 0; } diff --git a/libbbf_api/dmbbf.c b/libbbf_api/dmbbf.c index fe6e13da..8e86957f 100644 --- a/libbbf_api/dmbbf.c +++ b/libbbf_api/dmbbf.c @@ -1773,9 +1773,13 @@ static int get_linker_value_check_obj(DMOBJECT_ARGS) return FAULT_9005; if (strcmp(node->current_object, dmctx->in_param) == 0) { - char *link_val; + char *link_val = NULL; + + if (!data || !instance) + return FAULT_9005; + get_linker(node->current_object, dmctx, data, instance, &link_val); - dmctx->linker = dmstrdup(link_val); + dmctx->linker = link_val ? dmstrdup(link_val) : ""; dmctx->stop = true; return 0; } diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index 52faa5ff..6c31731c 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -228,6 +228,7 @@ void get_dmmap_section_of_config_section_cont(char* dmmap_package, char* section void get_config_section_of_dmmap_section(char* package, char* section_type, char *section_name, struct uci_section **config_section); int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value); int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value); +int dm_entry_validate_allowed_objects(struct dmctx *ctx, char *value, char *objects[]); char *check_create_dmmap_package(const char *dmmap_package); __attribute__ ((deprecated)) int is_section_unnamed(char *section_name); __attribute__ ((deprecated)) void delete_sections_save_next_sections(char* dmmap_package, char *section_type, char *instancename, char *section_name, int instance, struct list_head *dup_list); diff --git a/tools/convert_dm_json_to_c.py b/tools/convert_dm_json_to_c.py index 20a4def8..9a2372a7 100755 --- a/tools/convert_dm_json_to_c.py +++ b/tools/convert_dm_json_to_c.py @@ -583,8 +583,6 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par get_value += " char *linker = dmstrdup(*value);\n" get_value += " adm_entry_get_linker_param(ctx, \"%s\", linker, value);\n" % res7 get_value += " dmfree(linker);\n" - get_value += " if (*value == NULL)\n" - get_value += " *value = \"\";" elif res6 is not None: get_value += " *value = dmuci_get_value_by_path(\"%s\", \"%s\", \"%s\", \"%s\");" % ( res6, res1, res3, res5)