diff options
| author | Lou Berger <lberger@labn.net> | 2018-03-14 12:11:57 -0400 | 
|---|---|---|
| committer | Lou Berger <lberger@labn.net> | 2018-03-28 10:47:34 -0400 | 
| commit | 86b286101b1b4eea804b4ffa3e0c47c23a664ed2 (patch) | |
| tree | 3bc72fb45eb7f7bc9b1a17bd9cc3e4abc32784df /vtysh/vtysh_main.c | |
| parent | 615e608d76bd3e1acf1769c914142210ac88e3f7 (diff) | |
vtysh: add -u/--user flag to run commands without enable
Signed-off-by: Lou Berger <lberger@labn.net>
Diffstat (limited to 'vtysh/vtysh_main.c')
| -rw-r--r-- | vtysh/vtysh_main.c | 22 | 
1 files changed, 16 insertions, 6 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index a3d2f95ec1..b5cc1d21d1 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -60,6 +60,9 @@ static char history_file[MAXPATHLEN];  /* Flag for indicate executing child command. */  int execute_flag = 0; +/* Flag to indicate if in user/unprivileged mode. */ +int user_mode = 0; +  /* For sigsetjmp() & siglongjmp(). */  static sigjmp_buf jmpbuf; @@ -150,6 +153,7 @@ static void usage(int status)  		       "    --vty_socket         Override vty socket path\n"  		       "    --config_dir         Override config directory path\n"  		       "-N  --pathspace          Insert prefix into config & socket paths\n" +		       "-u  --user               Run as an unprivileged user\n"  		       "-w, --writeconfig        Write integrated config (frr.conf) and exit\n"  		       "-h, --help               Display this help and exit\n\n"  		       "Note that multiple commands may be executed from the command\n" @@ -180,6 +184,7 @@ struct option longopts[] = {  	{"mark", no_argument, NULL, 'm'},  	{"writeconfig", no_argument, NULL, 'w'},  	{"pathspace", required_argument, NULL, 'N'}, +	{"user", no_argument, NULL, 'u'},  	{0}};  /* Read a string, and return a pointer to it.  Returns NULL on EOF. */ @@ -318,7 +323,7 @@ int main(int argc, char **argv, char **env)  	/* Option handling. */  	while (1) { -		opt = getopt_long(argc, argv, "be:c:d:nf:mEhCwN:", longopts, 0); +		opt = getopt_long(argc, argv, "be:c:d:nf:mEhCwN:u", longopts, 0);  		if (opt == EOF)  			break; @@ -375,6 +380,9 @@ int main(int argc, char **argv, char **env)  		case 'C':  			dryrun = 1;  			break; +		case 'u': +			user_mode = 1; +			break;  		case 'w':  			writeconfig = 1;  			break; @@ -425,11 +433,13 @@ int main(int argc, char **argv, char **env)  	vty_init_vtysh(); -	/* Read vtysh configuration file before connecting to daemons. -	 * (file may not be readable to calling user in SUID mode) */ -	suid_on(); -	vtysh_read_config(vtysh_config); -	suid_off(); +	if (!user_mode) { +		/* Read vtysh configuration file before connecting to daemons. +		 * (file may not be readable to calling user in SUID mode) */ +		suid_on(); +		vtysh_read_config(vtysh_config); +		suid_off(); +	}  	if (markfile) {  		if (!inputfile) {  | 
