Merge branch 'master' of https://github.com/clicon/clixon
This commit is contained in:
commit
4021d65d7a
15 changed files with 2168 additions and 1984 deletions
|
|
@ -567,22 +567,27 @@ nacm_datanode_read(cxobj *xt,
|
|||
/* User's group */
|
||||
if (xpath_vec(xnacm, "groups/group[user-name='%s']", &gvec, &glen, username) < 0)
|
||||
goto done;
|
||||
/* 4. If no groups are found, continue with step 9. */
|
||||
if (glen == 0)
|
||||
goto step9;
|
||||
/* 4. If no groups are found (glen=0), continue and check read-default
|
||||
in step 11. */
|
||||
/* 5. Process all rule-list entries, in the order they appear in the
|
||||
configuration. If a rule-list's "group" leaf-list does not
|
||||
match any of the user's groups, proceed to the next rule-list
|
||||
entry. */
|
||||
if (xpath_vec(xnacm, "rule-list", &rlistvec, &rlistlen) < 0)
|
||||
goto done;
|
||||
/* read-default has default permit so should never be NULL */
|
||||
if ((read_default = xml_find_body(xnacm, "read-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No nacm read-default rule");
|
||||
goto done;
|
||||
}
|
||||
for (i=0; i<xrlen; i++){ /* Loop through requested nodes */
|
||||
xr = xrvec[i]; /* requested node XR */
|
||||
/* Loop through rule-list (steps 5,6,7) to find match of requested node
|
||||
*/
|
||||
xrule = NULL;
|
||||
if (nacm_data_read_xr(xt, xr, gvec, glen, rlistvec, rlistlen,
|
||||
&xrule) < 0)
|
||||
/* Skip if no groups */
|
||||
if (glen && nacm_data_read_xr(xt, xr, gvec, glen, rlistvec, rlistlen,
|
||||
&xrule) < 0)
|
||||
goto done;
|
||||
if (xrule){ /* xrule match requested node xr */
|
||||
if ((action = xml_find_body(xrule, "action")) == NULL)
|
||||
|
|
@ -601,8 +606,7 @@ nacm_datanode_read(cxobj *xt,
|
|||
to "permit", then include the requested data node in the reply;
|
||||
otherwise, do not include the requested data node or any of its
|
||||
descendants in the reply.*/
|
||||
read_default = xml_find_body(xnacm, "read-default");
|
||||
if (read_default == NULL || strcmp(read_default, "deny")==0)
|
||||
if (strcmp(read_default, "deny")==0)
|
||||
if (xml_purge(xr) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -668,7 +672,7 @@ nacm_datanode_write(cxobj *xt,
|
|||
cxobj *xrule;
|
||||
int match = 0;
|
||||
char *action;
|
||||
char *write_default;
|
||||
char *write_default = NULL;
|
||||
|
||||
if (xnacm == NULL)
|
||||
goto permit;
|
||||
|
|
@ -747,8 +751,12 @@ nacm_datanode_write(cxobj *xt,
|
|||
/*12. For a "write" access operation, if the "write-default" leaf is
|
||||
set to "permit", then permit the data node access request;
|
||||
otherwise, deny the request.*/
|
||||
write_default = xml_find_body(xnacm, "write-default");
|
||||
if (write_default == NULL || strcmp(write_default, "permit") != 0){
|
||||
/* write-default has default permit so should never be NULL */
|
||||
if ((write_default = xml_find_body(xnacm, "write-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No nacm write-default rule");
|
||||
goto done;
|
||||
}
|
||||
if (strcmp(write_default, "permit") != 0){
|
||||
if (netconf_access_denied(cbret, "application", "default deny") < 0)
|
||||
goto done;
|
||||
goto deny;
|
||||
|
|
|
|||
|
|
@ -730,8 +730,7 @@ match_base_child(cxobj *x0,
|
|||
goto ok;
|
||||
if ((b = xml_body(xb)) == NULL)
|
||||
goto ok;
|
||||
// if ((b = xml_find_body(x1c, keyname)) == NULL)
|
||||
// goto ok; /* not found */
|
||||
|
||||
keyval[i] = b;
|
||||
if (xml_cv_cache(xb, &keycvec[i]) < 0) /* error case */
|
||||
goto done;
|
||||
|
|
@ -741,9 +740,7 @@ match_base_child(cxobj *x0,
|
|||
default:
|
||||
break;
|
||||
}
|
||||
/* Get match. Sorting mode(optimized) or not?
|
||||
* This conditional is a mystery , but test_yang_namespace.sh breaks if set to (0)
|
||||
*/
|
||||
/* Get match. */
|
||||
yorder = yang_order(yc);
|
||||
x0c = xml_search(x0, xml_name(x1c), yorder, yc->ys_keyword, keynr, keyvec, keyval, keycvec);
|
||||
ok:
|
||||
|
|
|
|||
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Utility debug tool
|
||||
* Static Compile: gcc -Wall json_xpath.c -o json_xpath -l clixon
|
||||
gcc -O2 -o json_xpath json_xpath.c clixon_log.o clixon_err.o clixon_json.o clixon_xml.o clixon_xsl.o clixon_json_parse.tab.o clixon_xml_parse.tab.o lex.clixon_json_parse.o lex.clixon_xml_parse.o ../../../cligen/cligen_buf.o ../../../cligen/cligen_var.o ../../../cligen/cligen_gen.o ../../../cligen/cligen_cvec.o ../../../cligen/cligen_handle.o ../../../cligen/getline.o ../../../cligen/cligen_read.o ../../../cligen/cligen_match.o ../../../cligen/cligen_expand.o ../../../cligen/cligen_print.o
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
static int
|
||||
usage(char *argv0)
|
||||
{
|
||||
fprintf(stderr, "usage:%s <xpath> # XML/JSON expected on stdin\n"
|
||||
"\t-h Help\n"
|
||||
"\t-b Strip to body value (eg \"<a>val</a>\" --> \"val\"\n"
|
||||
"\t-j json input (not xml)\n",
|
||||
argv0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
cxobj **xv;
|
||||
cxobj *x;
|
||||
cxobj *xn;
|
||||
cxobj *xb;
|
||||
char *xpath;
|
||||
int body = 0;
|
||||
int json = 0;
|
||||
size_t xlen = 0;
|
||||
size_t len;
|
||||
size_t buflen = 128;
|
||||
char *buf;
|
||||
char *p;
|
||||
int retval;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "?hbj")) != -1)
|
||||
switch (c) {
|
||||
case '?':
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
break;
|
||||
case 'b':
|
||||
body++;
|
||||
break;
|
||||
case 'j':
|
||||
json++;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
if (optind >= argc)
|
||||
usage(argv[0]);
|
||||
xpath=argv[optind];
|
||||
|
||||
clicon_log_init("xpath", 0, CLICON_LOG_STDERR);
|
||||
if ((buf = malloc(buflen)) == NULL){
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
/* |---------------|-------------|
|
||||
* buf p buf+buflen
|
||||
*/
|
||||
p = buf;
|
||||
memset(p, 0, buflen);
|
||||
while (1){
|
||||
if ((retval = read(0, p, buflen-(p-buf))) < 0){
|
||||
perror("read");
|
||||
return -1;
|
||||
}
|
||||
if (retval == 0)
|
||||
break;
|
||||
p += retval;
|
||||
len = p-buf;
|
||||
|
||||
if (buf+buflen-p < 10){ /* allocate more */
|
||||
buflen *= 2;
|
||||
if ((buf = realloc(buf, buflen)) == NULL){
|
||||
perror("realloc");
|
||||
return -1;
|
||||
}
|
||||
p = buf+len;
|
||||
memset(p, 0, (buf+buflen)-p);
|
||||
}
|
||||
}
|
||||
if (json){
|
||||
if (json_parse_str(buf, &x) < 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
if (xml_parse_string(buf, &x) < 0)
|
||||
return -1;
|
||||
|
||||
if (xpath_vec(x, xpath, &xv, &xlen) < 0)
|
||||
return -1;
|
||||
if (xv){
|
||||
for (i=0; i<xlen; i++){
|
||||
xn = xv[i];
|
||||
if (body)
|
||||
xb = xml_find(xn, "body");
|
||||
else
|
||||
xb = xn;
|
||||
if (xb){
|
||||
// xml2json(stdout, xb, 0);
|
||||
clicon_xml2file(stdout, xb, 0, 0);
|
||||
fprintf(stdout,"\n");
|
||||
}
|
||||
}
|
||||
free(xv);
|
||||
}
|
||||
if (x)
|
||||
xml_free(x);
|
||||
if (buf)
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue