Fixed: Fail on return errors when reading from datastore

This commit is contained in:
Olof hagsand 2024-04-24 13:48:06 +02:00
parent aba5c68fe2
commit bd290e4594
10 changed files with 87 additions and 20 deletions

View file

@ -388,14 +388,17 @@ clixon_stats_datastore_get(clixon_handle h,
uint64_t nr = 0;
size_t sz = 0;
cxobj *xn = NULL;
int ret;
clixon_debug(CLIXON_DBG_BACKEND | CLIXON_DBG_DETAIL, "%s", dbname);
/* This is the db cache */
if ((xt = xmldb_cache_get(h, dbname)) == NULL){
/* Trigger cache if no exist (trick to ensure cache is present) */
if (xmldb_get(h, dbname, NULL, "/", &xn) < 0)
if ((ret = xmldb_get0(h, dbname, YB_MODULE, NULL, "/", 1, 0, &xn, NULL, NULL)) < 0)
//goto done;
goto ok;
if (ret == 0)
goto ok;
xt = xmldb_cache_get(h, dbname);
}
if (xt != NULL){
@ -1416,6 +1419,7 @@ from_client_stats(clixon_handle h,
yang_stmt *yspec;
yang_stmt *ymodext;
cxobj *xt = NULL;
int ret;
if ((str = xml_find_body(xe, "modules")) != NULL)
modules = strcmp(str, "true") == 0;
@ -1470,8 +1474,12 @@ from_client_stats(clixon_handle h,
cprintf(cbret, "</module-set>");
/* Mountpoints */
if ((ymodext = yang_find(yspec, Y_MODULE, "ietf-yang-schema-mount")) != NULL){
if (xmldb_get(h, "running", NULL, "/", &xt) < 0)
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 1, 0, &xt, NULL, NULL)) < 0)
goto done;
if (ret == 0){
clixon_err(OE_DB, 0, "Error when reading from running, unknown error");
goto done;
}
if (xt && yang_schema_mount_statistics(h, xt, modules, cbret) < 0)
goto done;
}
@ -1793,12 +1801,15 @@ from_client_msg(clixon_handle h,
xnacm = NULL;
/* NACM intial pre- access control enforcements. Retval:
* 0: Use NACM validation and xnacm is set.
* 1: Permit, skip NACM
* 0: nacm declaration error
* 1: Use NACM validation and xnacm is set.
* 2: Permit, skip NACM
* Therefore, xnacm=NULL means no NACM checks needed.
*/
if ((ret = nacm_access_pre(h, ce->ce_username, username, &xnacm)) < 0)
if ((ret = nacm_access_pre(h, ce->ce_username, username, &xnacm, cbret)) < 0)
goto done;
if (ret == 2)
goto reply;
/* Cache XML NACM tree here. Use with caution, only valid on from_client_msg stack
*/
if (clicon_nacm_cache_set(h, xnacm) < 0)

View file

@ -974,9 +974,9 @@ from_client_restart_one(clixon_handle h,
if ((td = transaction_new()) == NULL)
goto done;
/* This is the state we are going to */
if (xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, 0, &td->td_target, NULL, NULL) < 0)
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, 0, &td->td_target, NULL, &xerr)) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, td->td_target, &xerr)) < 0)
if (ret == 1 && (ret = xml_yang_validate_all_top(h, td->td_target, &xerr)) < 0)
goto done;
if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)

View file

@ -541,12 +541,12 @@ get_list_pagination(clixon_handle h,
cbuf *cbmsg = NULL; /* For error msg */
cxobj *xret = NULL;
char *xpath2; /* With optional pagination predicate */
int ret;
uint32_t iddb; /* DBs lock, if any */
int locked;
cbuf *cberr = NULL;
cxobj **xvec = NULL;
size_t xlen;
int ret;
#ifdef NOTYET
cxobj *x;
char *direction = NULL;
@ -651,7 +651,7 @@ get_list_pagination(clixon_handle h,
/* Append predicate to original xpath and replace it */
xpath2 = cbuf_get(cbpath);
/* specific xpath */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, wdef, &xret, NULL, NULL) < 0) {
if ((ret = xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, wdef, &xret, NULL, &xerr)) < 0) {
if ((cbmsg = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -661,6 +661,12 @@ get_list_pagination(clixon_handle h,
goto done;
goto ok;
}
if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
goto done;
goto ok;
}
break;
case CONTENT_NONCONFIG: /* state data only */
if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */
@ -885,7 +891,7 @@ get_common(clixon_handle h,
switch (content){
case CONTENT_CONFIG: /* config data only */
/* specific xpath. with-default gets masked in get_nacm_and_reply */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, NULL) < 0) {
if ((ret = xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, &xerr)) < 0) {
if ((cbmsg = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -895,12 +901,17 @@ get_common(clixon_handle h,
goto done;
goto ok;
}
if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
goto done;
goto ok;
}
break;
case CONTENT_ALL: /* both config and state */
case CONTENT_NONCONFIG: /* state data only */
if (clicon_option_bool(h, "CLICON_VALIDATE_STATE_XML")){
/* Whole config tree, for validate debug */
if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, NULL) < 0) {
if ((ret = xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, &xerr)) < 0) {
if ((cbmsg = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -910,10 +921,15 @@ get_common(clixon_handle h,
goto done;
goto ok;
}
if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
goto done;
goto ok;
}
}
else if (content == CONTENT_ALL){
/* specific xpath */
if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, NULL) < 0) {
if ((ret = xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, WITHDEFAULTS_REPORT_ALL, &xret, NULL, &xerr)) < 0) {
if ((cbmsg = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -923,6 +939,11 @@ get_common(clixon_handle h,
goto done;
goto ok;
}
if (ret == 0){
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
goto done;
goto ok;
}
}
/* CONTENT_NONCONFIG */
else if ((xret = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)/* Only top tree */

View file

@ -202,6 +202,7 @@ restconf_rpc_wrapper(clixon_handle h,
{
int retval = -1;
cxobj *xt = NULL;
int ret;
clixon_debug(CLIXON_DBG_BACKEND, "");
switch (*operation){
@ -211,8 +212,12 @@ restconf_rpc_wrapper(clixon_handle h,
case PROC_OP_START:
/* RPC op is start & enable is true, then start the service,
& enable is false, error or ignore it */
if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0)
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/restconf", 1, 0, &xt, NULL, NULL)) < 0)
goto done;
if (ret == 0){
clixon_err(OE_DB, 0, "Error when reading from running, unknown error");
goto done;
}
if (xt != NULL &&
xpath_first(xt, NULL, "/restconf[enable='false']") != NULL) {
*operation = PROC_OP_NONE;

View file

@ -309,8 +309,12 @@ startup_extraxml(clixon_handle h,
* It should be empty if extra-xml is null and reset plugins did nothing
* then skip validation.
*/
if (xmldb_get(h, tmp_db, NULL, NULL, &xt0) < 0)
if ((ret = xmldb_get0(h, tmp_db, YB_MODULE, NULL, NULL, 1, 0, &xt0, NULL, NULL)) < 0)
goto done;
if (ret == 0){
clixon_err(OE_DB, 0, "Error when reading from %s, unknown error", tmp_db);
goto done;
}
if ((ret = xmldb_empty_get(h, tmp_db)) < 0)
goto done;
if (ret == 1)