diff options
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/Makefile.am | 3 | ||||
-rw-r--r-- | vtysh/vtysh.c | 34 | ||||
-rw-r--r-- | vtysh/vtysh.h | 5 | ||||
-rw-r--r-- | vtysh/vtysh_main.c | 22 |
4 files changed, 42 insertions, 22 deletions
diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 791d95dd..5597251f 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -1,7 +1,6 @@ ## Process this file with Automake to create Makefile.in INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib -DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" LIBS = @LIBS@ @CURSES@ @LIBPAM@ @@ -32,7 +31,7 @@ vtysh_cmd_FILES = $(top_srcdir)/bgpd/*.c $(top_srcdir)/isisd/*.c \ $(top_srcdir)/zebra/irdp_interface.c \ $(top_srcdir)/zebra/rtadv.c $(top_srcdir)/zebra/zebra_vty.c \ $(top_srcdir)/zebra/zserv.c $(top_srcdir)/zebra/router-id.c \ - $(top_srcdir)/zebra/zebra_routemap.c + $(top_srcdir)/zebra/zebra_routemap.c $(top_srcdir)/pimd/pim_cmd.c vtysh_cmd.c: $(vtysh_cmd_FILES) ./$(EXTRA_DIST) $(vtysh_cmd_FILES) > vtysh_cmd.c diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 3f189adb..fbd1b16c 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -34,6 +34,7 @@ #include "memory.h" #include "vtysh/vtysh.h" #include "log.h" +#include "paths.h" #include "bgpd/bgp_vty.h" /* Struct VTY. */ @@ -48,16 +49,16 @@ struct vtysh_client int fd; const char *name; int flag; - const char *path; } vtysh_client[] = { - { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH}, - { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH}, - { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH}, - { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH}, - { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH}, - { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH}, - { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH}, + { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA}, + { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD}, + { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD}, + { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD}, + { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D}, + { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD}, + { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD}, + { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD}, }; #define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0])) @@ -2103,13 +2104,17 @@ vtysh_connect (struct vtysh_client *vclient) int sock, len; struct sockaddr_un addr; struct stat s_stat; + char path[MAXPATHLEN]; + + /* figure out path to daemon VTY socket */ + snprintf (path, sizeof(path), "%s.vty", path_state (vclient->name)); /* Stat socket to see if we have permission to access it. */ - ret = stat (vclient->path, &s_stat); + ret = stat (path, &s_stat); if (ret < 0 && errno != ENOENT) { fprintf (stderr, "vtysh_connect(%s): stat = %s\n", - vclient->path, safe_strerror(errno)); + path, safe_strerror(errno)); exit(1); } @@ -2117,8 +2122,7 @@ vtysh_connect (struct vtysh_client *vclient) { if (! S_ISSOCK(s_stat.st_mode)) { - fprintf (stderr, "vtysh_connect(%s): Not a socket\n", - vclient->path); + fprintf (stderr, "vtysh_connect(%s): Not a socket\n", path); exit (1); } @@ -2128,7 +2132,7 @@ vtysh_connect (struct vtysh_client *vclient) if (sock < 0) { #ifdef DEBUG - fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path, + fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path, safe_strerror(errno)); #endif /* DEBUG */ return -1; @@ -2136,7 +2140,7 @@ vtysh_connect (struct vtysh_client *vclient) memset (&addr, 0, sizeof (struct sockaddr_un)); addr.sun_family = AF_UNIX; - strncpy (addr.sun_path, vclient->path, strlen (vclient->path)); + strncpy (addr.sun_path, path, sizeof (addr.sun_path)); #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN len = addr.sun_len = SUN_LEN(&addr); #else @@ -2147,7 +2151,7 @@ vtysh_connect (struct vtysh_client *vclient) if (ret < 0) { #ifdef DEBUG - fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path, + fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path, safe_strerror(errno)); #endif /* DEBUG */ close (sock); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index e711d593..620d35a3 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -29,9 +29,10 @@ #define VTYSH_OSPF6D 0x10 #define VTYSH_BGPD 0x20 #define VTYSH_ISISD 0x40 -#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD +#define VTYSH_PIMD 0x80 +#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD #define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD -#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD +#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD /* vtysh local configuration file. */ #define VTYSH_DEFAULT_CONFIG "vtysh.conf" 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) |