diff options
Diffstat (limited to 'vtysh/vtysh_main.c')
-rw-r--r-- | vtysh/vtysh_main.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 4a315a5c..bdff22de 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -33,6 +33,7 @@ #include "getopt.h" #include "command.h" #include "memory.h" +#include "paths.h" #include "vtysh/vtysh.h" #include "vtysh/vtysh_user.h" @@ -41,7 +42,6 @@ char *progname; /* Configuration file name and directory. */ -char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; char history_file[MAXPATHLEN]; /* Flag for indicate executing child command. */ @@ -143,6 +143,7 @@ usage (int status) "-d, --daemon Connect only to the specified daemon\n" \ "-E, --echo Echo prompt and command in -c mode\n" \ "-C, --dryrun Check configuration for validity and exit\n" \ + "-N, --namespace Use prefixed daemon socket names\n" \ "-h, --help Display this help and exit\n\n" \ "Note that multiple commands may be executed from the command\n" \ "line by passing multiple -c args, or by embedding linefeed\n" \ @@ -162,6 +163,7 @@ struct option longopts[] = { "daemon", required_argument, NULL, 'd'}, { "echo", no_argument, NULL, 'E'}, { "dryrun", no_argument, NULL, 'C'}, + { "namespace", required_argument, NULL, 'N'}, { "help", no_argument, NULL, 'h'}, { "noerror", no_argument, NULL, 'n'}, { 0 } @@ -237,7 +239,7 @@ main (int argc, char **argv, char **env) /* Option handling. */ while (1) { - opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0); + opt = getopt_long (argc, argv, "be:c:d:nEhCN:", longopts, 0); if (opt == EOF) break; @@ -278,6 +280,20 @@ main (int argc, char **argv, char **env) case 'h': usage (0); break; + case 'N': + /* we're using this as a path component, so... + * for the daemons we can assume no malicious tampering + * with the cmdline, but for vtysh we have to check + */ + if (strchr (optarg, '/') || optarg[0] == '.') + { + fprintf (stderr, "The namespace argument may not include " + "slashes or start with a dot.\n"); + break; + } + + path_set_namespace (optarg); + break; default: usage (1); break; @@ -302,7 +318,7 @@ main (int argc, char **argv, char **env) sort_node (); /* Read vtysh configuration file before connecting to daemons. */ - vtysh_read_config (config_default); + vtysh_read_config (path_config (VTYSH_DEFAULT_CONFIG)); /* Start execution only if not in dry-run mode */ if(dryrun) |