dont exit cli when expand gets auth denied from backend

This commit is contained in:
Olof hagsand 2018-06-03 20:18:43 +02:00
parent 7e4e1d6deb
commit 39538461c2
4 changed files with 25 additions and 21 deletions

View file

@ -444,6 +444,8 @@ cli_handler_err(FILE *f)
/*! Evaluate a matched command
* @param[in] h Clicon handle
* @param[in] cmd The command string
* @retval int If there is a callback, the return value of the callback is returned,
* @retval 0 otherwise
*/
int
clicon_eval(clicon_handle h,
@ -451,10 +453,12 @@ clicon_eval(clicon_handle h,
cg_obj *match_obj,
cvec *cvv)
{
int retval = 0;
cli_output_reset();
if (!cligen_exiting(cli_cligen(h))) {
clicon_err_reset();
if (cligen_eval(cli_cligen(h), match_obj, cvv) < 0) {
if ((retval = cligen_eval(cli_cligen(h), match_obj, cvv)) < 0) {
#if 0 /* This is removed since we get two error messages on failure.
But maybe only sometime?
Both a real log when clicon_err is called, and the here again.
@ -463,11 +467,10 @@ clicon_eval(clicon_handle h,
#endif
}
}
return 0;
return retval;
}
/*! Given a command string, parse and evaluate.
/*! Given a command string, parse and if match single command, eval it.
* Parse and evaluate the string according to
* the syntax parse tree of the syntax mode specified by *mode.
* If there is no match in the tree for the command, the parse hook
@ -478,20 +481,25 @@ clicon_eval(clicon_handle h,
* @param[in] h Clicon handle
* @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] result -2 On eof (shouldnt happen)
* @param[out] evalres Evaluation result if retval=1
* -2 On eof (shouldnt happen)
* -1 On parse error
* >=0 Number of matches
* @retval 0 XXX How does this relate to result???
* @retval -2 Eof CG_EOF
* @retval -1 Error CG_ERROR
* @retval 0 No match CG_NOMATCH
* @retval 1 Exactly one match CG_MATCH
* @retval 2+ Multiple matches
*/
int
clicon_parse(clicon_handle h,
char *cmd,
char **modenamep,
int *result)
int *evalres)
{
int retval = -1;
char *modename;
char *modename0;
int retval = -1;
int r;
cli_syntax_t *stx = NULL;
cli_syntaxmode_t *smode;
@ -515,8 +523,7 @@ clicon_parse(clicon_handle h,
goto done;
}
}
if (smode)
while(1) {
if (smode){
modename0 = NULL;
if ((pt = cligen_tree_active_get(cli_cligen(h))) != NULL)
modename0 = pt->pt_name;
@ -543,13 +550,12 @@ clicon_parse(clicon_handle h,
case CG_EOF: /* eof */
case CG_ERROR:
cli_output(f, "CLI parse error: %s\n", cmd);
goto done;
break;
case CG_NOMATCH: /* no match */
/* clicon_err(OE_CFG, 0, "CLI syntax error: \"%s\": %s",
cmd, cli_nomatch(h));*/
cli_output(f, "CLI syntax error: \"%s\": %s\n",
cmd, cli_nomatch(h));
goto done;
break;
case CG_MATCH:
if (strcmp(modename, *modenamep)){ /* Command in different mode */
@ -559,16 +565,14 @@ clicon_parse(clicon_handle h,
if ((r = clicon_eval(h, cmd, match_obj, cvv)) < 0)
cli_handler_err(stdout);
pt_expand_cleanup_1(pt); /* XXX change to pt_expand_treeref_cleanup */
if (result)
*result = r;
goto done;
if (evalres)
*evalres = r;
break;
default:
cli_output(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
goto done;
break;
} /* switch retval */
} /* while smode */
}
done:
if (cvv)
cvec_free(cvv);