* Added -U <user> command line to clixon_cli and clixon_netconf for NACM pseudo-user tests
This commit is contained in:
parent
de69b253dc
commit
5cabc11bfb
15 changed files with 132 additions and 48 deletions
|
|
@ -803,7 +803,7 @@ from_client_debug(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Match nacm access operations according to RFC8321 3.4.4.
|
||||
/*! Match nacm access operations according to RFC8341 3.4.4.
|
||||
* Incoming RPC Message Validation Step 7 (c)
|
||||
* The rule's "access-operations" leaf has the "exec" bit set or
|
||||
* has the special value "*".
|
||||
|
|
@ -832,7 +832,7 @@ nacm_match_access(char *access_operations,
|
|||
* @retval 0 Matching rule AND Not access and cbret set
|
||||
* @retval 1 Matchung rule AND Access
|
||||
* @retval 2 No matching rule Goto step 10
|
||||
* From RFC8321 3.4.4. Incoming RPC Message Validation
|
||||
* From RFC8341 3.4.4. Incoming RPC Message Validation
|
||||
+---------+-----------------+---------------------+-----------------+
|
||||
| Method | Resource class | NETCONF operation | Access |
|
||||
| | | | operation |
|
||||
|
|
@ -911,7 +911,7 @@ nacm_match_rule(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
* @retval 0 Not access and cbret set
|
||||
* @retval 1 Access
|
||||
* From RFC8321 3.4.4. Incoming RPC Message Validation
|
||||
* From RFC8341 3.4.4. Incoming RPC Message Validation
|
||||
*/
|
||||
static int
|
||||
nacm_access(clicon_handle h,
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@ backend_sig_term(int arg)
|
|||
/*! usage
|
||||
*/
|
||||
static void
|
||||
usage(char *argv0, clicon_handle h)
|
||||
usage(clicon_handle h,
|
||||
char *argv0)
|
||||
{
|
||||
char *plgdir = clicon_backend_dir(h);
|
||||
char *confsock = clicon_sock(h);
|
||||
|
|
@ -581,11 +582,11 @@ main(int argc,
|
|||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &debug) != 1)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* config file */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
}
|
||||
|
|
@ -602,7 +603,7 @@ main(int argc,
|
|||
/* Find and read configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
if (help)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
return -1;
|
||||
}
|
||||
/* External NACM file? */
|
||||
|
|
@ -621,12 +622,12 @@ main(int argc,
|
|||
break; /* see above */
|
||||
case 'd': /* Plugin directory */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_BACKEND_DIR", optarg);
|
||||
break;
|
||||
case 'b': /* XMLDB database directory */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_XMLDB_DIR", optarg);
|
||||
break;
|
||||
case 'F' : /* foreground */
|
||||
|
|
@ -640,7 +641,7 @@ main(int argc,
|
|||
break;
|
||||
case 'u': /* config unix domain path / ip address */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_SOCK", optarg);
|
||||
break;
|
||||
case 'P': /* pidfile */
|
||||
|
|
@ -650,7 +651,7 @@ main(int argc,
|
|||
clicon_option_str_set(h, "CLICON_STARTUP_MODE", optarg);
|
||||
if (clicon_startup_mode(h) < 0){
|
||||
fprintf(stderr, "Invalid startup mode: %s\n", optarg);
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
}
|
||||
break;
|
||||
case 'c': /* Load application config */
|
||||
|
|
@ -668,7 +669,7 @@ main(int argc,
|
|||
break;
|
||||
}
|
||||
default:
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -677,7 +678,7 @@ main(int argc,
|
|||
|
||||
/* Defer: Wait to the last minute to print help message */
|
||||
if (help)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
|
||||
/* Check pid-file, if zap kil the old daemon, else return here */
|
||||
if ((pidfile = clicon_backend_pidfile(h)) == NULL){
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
if (reason){
|
||||
while ((xc = xml_child_i(*xtop, 0)) != NULL)
|
||||
xml_purge(xc);
|
||||
clicon_log(LOG_NOTICE, "%s: Plugin '%s' state callback failed",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
if (netconf_operation_failed_xml(xtop, "rpc", reason)< 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
#include "cli_handle.h"
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define CLI_OPTS "hD:f:xl:F:1u:d:m:qpGLy:c:"
|
||||
#define CLI_OPTS "hD:f:xl:F:1u:d:m:qpGLy:c:U:"
|
||||
|
||||
/*! terminate cli application */
|
||||
static int
|
||||
|
|
@ -194,7 +194,8 @@ dump_configfile_xml_fn(FILE *fout,
|
|||
}
|
||||
|
||||
static void
|
||||
usage(char *argv0, clicon_handle h)
|
||||
usage(clicon_handle h,
|
||||
char *argv0)
|
||||
{
|
||||
char *confsock = clicon_sock(h);
|
||||
char *plgdir = clicon_cli_dir(h);
|
||||
|
|
@ -217,7 +218,8 @@ usage(char *argv0, clicon_handle h)
|
|||
"\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
|
||||
"\t-l <s|e|o> \tLog on (s)yslog, std(e)rr or std(o)ut (stderr is default)\n"
|
||||
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
"\t-c <file>\tSpecify cli spec file.\n",
|
||||
"\t-c <file>\tSpecify cli spec file.\n"
|
||||
"\t-U <user>\tOver-ride unix user with a pseudo user for NACM.\n",
|
||||
argv0,
|
||||
confsock ? confsock : "none",
|
||||
plgdir ? plgdir : "none"
|
||||
|
|
@ -256,7 +258,9 @@ main(int argc, char **argv)
|
|||
/* Initiate CLICON handle */
|
||||
if ((h = cli_handle_init()) == NULL)
|
||||
goto done;
|
||||
/* Set username to clicon handle. Use in all communication to backend */
|
||||
/* Set username to clicon handle. Use in all communication to backend
|
||||
* Note, can be overridden by -U
|
||||
*/
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
|
|
@ -283,11 +287,11 @@ main(int argc, char **argv)
|
|||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &debug) != 1)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* config file */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'x': /* dump config file as xml (migration from .conf file)*/
|
||||
|
|
@ -305,9 +309,9 @@ main(int argc, char **argv)
|
|||
logdst = CLICON_LOG_STDOUT;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
|
|
@ -327,7 +331,7 @@ main(int argc, char **argv)
|
|||
/* Find and read configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
if (help)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -352,17 +356,17 @@ main(int argc, char **argv)
|
|||
break;
|
||||
case 'u': /* config unix domain path/ ip host */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_SOCK", optarg);
|
||||
break;
|
||||
case 'd': /* Plugin directory: overrides configfile */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CLI_DIR", optarg);
|
||||
break;
|
||||
case 'm': /* CLI syntax mode */
|
||||
if (!strlen(optarg))
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CLI_MODE", optarg);
|
||||
break;
|
||||
case 'q' : /* Quiet mode */
|
||||
|
|
@ -385,8 +389,14 @@ main(int argc, char **argv)
|
|||
clicon_option_str_set(h, "CLICON_CLISPEC_FILE", optarg);
|
||||
break;
|
||||
}
|
||||
case 'U': /* Clixon 'pseudo' user */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_username_set(h, optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -395,7 +405,7 @@ main(int argc, char **argv)
|
|||
|
||||
/* Defer: Wait to the last minute to print help message */
|
||||
if (help)
|
||||
usage(argv[0], h);
|
||||
usage(h, argv[0]);
|
||||
|
||||
/* Setup signal handlers */
|
||||
cli_signal_init(h);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
#include "netconf_rpc.h"
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define NETCONF_OPTS "hDqf:d:Sy:"
|
||||
#define NETCONF_OPTS "hDqf:d:Sy:U:"
|
||||
|
||||
/*! Process incoming packet
|
||||
* @param[in] h Clicon handle
|
||||
|
|
@ -292,7 +292,8 @@ usage(clicon_handle h,
|
|||
"\t-f <file>\tConfiguration file (mandatory)\n"
|
||||
"\t-d <dir>\tSpecify netconf plugin directory dir (default: %s)\n"
|
||||
"\t-S\t\tLog on syslog\n"
|
||||
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n",
|
||||
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
"\t-U <user>\tOver-ride unix user with a pseudo user for NACM.\n",
|
||||
argv0,
|
||||
clicon_netconf_dir(h)
|
||||
);
|
||||
|
|
@ -379,6 +380,12 @@ main(int argc,
|
|||
clicon_option_str_set(h, "CLICON_YANG_MODULE_MAIN", optarg);
|
||||
break;
|
||||
}
|
||||
case 'U': /* Clixon 'pseudo' user */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_username_set(h, optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue