* State callbacks provided by user are validated. If they are invalid an internal error is returned.
* Fixed multi-namespace for augmented state which was not covered in 4.2.0. * The multi-namespace augment state may rearrange the XML namespace attributes. * Mandatory variables can no longer be deleted.
This commit is contained in:
parent
728fe9c6ac
commit
835f9030d2
20 changed files with 299 additions and 229 deletions
|
|
@ -170,7 +170,7 @@ client_get_capabilities(clicon_handle h,
|
|||
int retval = -1;
|
||||
cxobj *xrstate = NULL; /* xml restconf-state node */
|
||||
cxobj *xcap = NULL; /* xml capabilities node */
|
||||
|
||||
|
||||
if ((xrstate = xpath_first(*xret, "restconf-state")) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "restconf-state not found in config node");
|
||||
goto done;
|
||||
|
|
@ -321,7 +321,7 @@ client_statedata(clicon_handle h,
|
|||
if (ret == 0)
|
||||
goto fail;
|
||||
/* Code complex to filter out anything that is outside of xpath
|
||||
* Actually this is a safety catch, should realy be done in plugins
|
||||
* Actually this is a safety catch, should really be done in plugins
|
||||
* and modules_state functions.
|
||||
*/
|
||||
if (xpath_vec_nsc(*xret, nsc, "%s", &xvec, &xlen, xpath?xpath:"/") < 0)
|
||||
|
|
|
|||
|
|
@ -118,10 +118,14 @@ generic_validate(clicon_handle h,
|
|||
for (i=0; i<td->td_dlen; i++){
|
||||
x1 = td->td_dvec[i];
|
||||
ys = xml_spec(x1);
|
||||
if (ys && yang_mandatory(ys) && yang_config(ys)==0){
|
||||
if (netconf_missing_element_xml(xret, "protocol", xml_name(x1), "Missing mandatory variable") < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
if (ys && yang_mandatory(ys) && yang_config(ys)==1){
|
||||
yang_stmt *yp =yang_parent_get(ys);
|
||||
if (yp== NULL ||
|
||||
(yang_keyword_get(yp)!=Y_MODULE && yang_keyword_get(yp)!=Y_SUBMODULE)){
|
||||
if (netconf_missing_element_xml(xret, "protocol", xml_name(x1), "May not remove mandatory variable") < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* added entries */
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
int ret;
|
||||
cxobj *xerr = NULL;
|
||||
cxobj *x = NULL;
|
||||
clixon_plugin *cp = NULL;
|
||||
plgstatedata_t *fn; /* Plugin statedata fn */
|
||||
|
|
@ -124,6 +125,31 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
goto fail; /* Dont quit here on user callbacks */
|
||||
if (xml_apply(x, CX_ELMNT, xml_spec_populate, yspec) < 0)
|
||||
goto done;
|
||||
/* Check XML from state callback by validating it. return internal
|
||||
* error with error cause
|
||||
*/
|
||||
if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
cbuf *cberr = NULL; /* XXX Cumbersome, try to fold into one cb */
|
||||
cbuf *cberr2 = NULL;
|
||||
if (netconf_err2cb(xpath_first(xerr, "rpc-error"), &cberr) < 0)
|
||||
goto done;
|
||||
if ((cberr2 = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr2, "Internal error: state callback returned invalid XML: %s", cbuf_get(cberr));
|
||||
if (netconf_operation_failed_xml(xret, "application", cbuf_get(cberr2))< 0)
|
||||
goto done;
|
||||
if (cberr)
|
||||
cbuf_free(cberr);
|
||||
if (cberr2)
|
||||
cbuf_free(cberr2);
|
||||
goto fail;
|
||||
}
|
||||
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
|
|
@ -137,6 +163,8 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
done:
|
||||
if (x)
|
||||
xml_free(x);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue