Stricter incoming RPC sanity checking, error messages may have changed
This commit is contained in:
parent
f9998c441c
commit
ac5637a46a
30 changed files with 163 additions and 99 deletions
|
|
@ -1570,12 +1570,16 @@ from_client_msg(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
/* Decode msg from client -> xml top (ct) and session id */
|
||||
if (clicon_msg_decode(msg, yspec, &id, &xt) < 0){
|
||||
if (netconf_malformed_message(cbret, "XML parse error")< 0)
|
||||
if ((ret = clicon_msg_decode(msg, yspec, &id, &xt, &xret)) < 0){
|
||||
if (netconf_malformed_message(cbret, "XML parse error") < 0)
|
||||
goto done;
|
||||
goto reply;
|
||||
}
|
||||
if (ret == 0){
|
||||
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
|
||||
goto done;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
if ((x = xpath_first(xt, NULL, "/rpc")) == NULL){
|
||||
if ((x = xpath_first(xt, NULL, "/hello")) != NULL){
|
||||
if ((ret = from_client_hello(h, x, ce, cbret)) <0)
|
||||
|
|
@ -1589,12 +1593,6 @@ from_client_msg(clicon_handle h,
|
|||
}
|
||||
}
|
||||
ce->ce_id = id;
|
||||
/* Populate incoming XML tree with yang -
|
||||
* should really have been dealt with by decode above
|
||||
* but it still is needed - test_cli debug test fails
|
||||
*/
|
||||
if (xml_bind_yang_rpc(x, yspec, NULL) < 0)
|
||||
goto done;
|
||||
if ((ret = xml_yang_validate_rpc(h, x, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
|
|
|
|||
|
|
@ -509,8 +509,6 @@ from_validate_common(clicon_handle h,
|
|||
* @retval -1 Error - or validation failed
|
||||
* @retval 0 Validation failed (with cbret set)
|
||||
* @retval 1 Validation OK
|
||||
* @note Need to differentiate between error and validation fail
|
||||
* (only done for validate_common)
|
||||
*/
|
||||
int
|
||||
candidate_commit(clicon_handle h,
|
||||
|
|
|
|||
|
|
@ -977,7 +977,8 @@ cli_notification_cb(int s,
|
|||
cxobj *xt = NULL;
|
||||
cxobj *xe;
|
||||
cxobj *x;
|
||||
enum format_enum format = (enum format_enum)arg;
|
||||
enum format_enum format = (enum format_enum)arg;
|
||||
int ret;
|
||||
|
||||
/* get msg (this is the reason this function is called) */
|
||||
if (clicon_msg_rcv(s, &reply, &eof) < 0)
|
||||
|
|
@ -989,8 +990,13 @@ cli_notification_cb(int s,
|
|||
event_unreg_fd(s, cli_notification_cb);
|
||||
goto done;
|
||||
}
|
||||
if (clicon_msg_decode(reply, NULL, NULL, &xt) < 0) /* XXX pass yang_spec */
|
||||
/* XXX pass yang_spec and use xerr*/
|
||||
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){ /* will not happen since no yspec ^*/
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
goto done;
|
||||
}
|
||||
if ((xe = xpath_first(xt, NULL, "//event")) != NULL){
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xe, x, -1)) != NULL) {
|
||||
|
|
|
|||
|
|
@ -425,6 +425,8 @@ netconf_notification_cb(int s,
|
|||
clicon_handle h = (clicon_handle)arg;
|
||||
yang_stmt *yspec = NULL;
|
||||
cvec *nsc = NULL;
|
||||
int ret;
|
||||
cxobj *xerr = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
/* get msg (this is the reason this function is called) */
|
||||
|
|
@ -439,9 +441,12 @@ netconf_notification_cb(int s,
|
|||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if (clicon_msg_decode(reply, yspec, NULL, &xt) < 0)
|
||||
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
|
||||
if (ret == 0){ /* XXX use xerr */
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
goto done;
|
||||
}
|
||||
if ((nsc = xml_nsctx_init(NULL, NOTIFICATION_RFC5277_NAMESPACE)) == NULL)
|
||||
goto done;
|
||||
if ((xn = xpath_first(xt, nsc, "notification")) == NULL)
|
||||
|
|
@ -467,6 +472,8 @@ netconf_notification_cb(int s,
|
|||
xml_nsctx_free(nsc);
|
||||
if (xt != NULL)
|
||||
xml_free(xt);
|
||||
if (xerr != NULL)
|
||||
xml_free(xerr);
|
||||
if (reply)
|
||||
free(reply);
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -847,8 +847,17 @@ api_operations_post(clicon_handle h,
|
|||
clicon_log_xml(LOG_DEBUG, xtop, "%s 5. Translate input args:", __FUNCTION__);
|
||||
#endif
|
||||
/* 6. Validate outgoing RPC and fill in defaults */
|
||||
if (xml_bind_yang_rpc(xtop, yspec, NULL) < 0) /* */
|
||||
if ((ret = xml_bind_yang_rpc(xtop, yspec, &xret)) < 0) /* */
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((xe = xpath_first(xret, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto ok;
|
||||
}
|
||||
if (api_return_err(h, r, xe, pretty, media_out, 0) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
if ((ret = xml_yang_validate_rpc(h, xtop, &xret)) < 0)
|
||||
goto done;
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ restconf_stream_cb(int s,
|
|||
cxobj *xn; /* notification xml */
|
||||
cbuf *cb = NULL;
|
||||
int pretty = 0; /* XXX should be via arg */
|
||||
int ret;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
/* get msg (this is the reason this function is called) */
|
||||
|
|
@ -180,8 +181,12 @@ restconf_stream_cb(int s,
|
|||
clicon_exit_set();
|
||||
goto done;
|
||||
}
|
||||
if (clicon_msg_decode(reply, NULL, NULL, &xtop) < 0) /* XXX pass yang_spec */
|
||||
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EFAULT, "Invalid notification");
|
||||
goto done;
|
||||
}
|
||||
/* create event */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue