diff options
Diffstat (limited to 'ospf6d/ospf6_main.c')
-rw-r--r-- | ospf6d/ospf6_main.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 5ab517f3..7ed0030e 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -27,6 +27,7 @@ #include "command.h" #include "vty.h" #include "memory.h" +#include "privs.h" #include "ospf6d.h" #include "ospf6_network.h" @@ -43,6 +44,26 @@ extern int ospf6_sock; /* Default port values. */ #define OSPF6_VTY_PORT 2606 +/* ospf6d privileges */ +zebra_capabilities_t _caps_p [] = +{ + ZCAP_RAW, + ZCAP_BIND +}; + +struct zebra_privs_t ospf6d_privs = +{ +#if defined(ZEBRA_USER) + .user = ZEBRA_USER, +#endif +#if defined ZEBRA_GROUP + .group = ZEBRA_GROUP, +#endif + .caps_p = _caps_p, + .cap_num_p = 2, + .cap_num_i = 0 +}; + /* ospf6d options, we use GNU getopt library. */ struct option longopts[] = { @@ -51,6 +72,7 @@ struct option longopts[] = { "pid_file", required_argument, NULL, 'i'}, { "vty_addr", required_argument, NULL, 'A'}, { "vty_port", required_argument, NULL, 'P'}, + { "user", required_argument, NULL, 'u'}, { "version", no_argument, NULL, 'v'}, { "help", no_argument, NULL, 'h'}, { 0 } @@ -93,6 +115,7 @@ Daemon which manages OSPF version 3.\n\n\ -i, --pid_file Set process identifier file name\n\ -A, --vty_addr Set vty's bind address\n\ -P, --vty_port Set vty's port number\n\ +-u, --user User and group to run as\n\ -v, --version Print program version\n\ -h, --help Display this help and exit\n\ \n\ @@ -206,7 +229,7 @@ main (int argc, char *argv[], char *envp[]) char *p; int opt; char *vty_addr = NULL; - int vty_port = 0; + int vty_port = OSPF6_VTY_PORT; char *config_file = NULL; char *progname; struct thread thread; @@ -231,7 +254,7 @@ main (int argc, char *argv[], char *envp[]) /* Command line argument treatment. */ while (1) { - opt = getopt_long (argc, argv, "df:hp:A:P:v", longopts, 0); + opt = getopt_long (argc, argv, "df:hp:A:P:u:v", longopts, 0); if (opt == EOF) break; @@ -253,7 +276,18 @@ main (int argc, char *argv[], char *envp[]) pid_file = optarg; break; case 'P': + /* Deal with atoi() returning 0 on failure, and ospf6d not + listening on ospf6d port... */ + if (strcmp(optarg, "0") == 0) + { + vty_port = 0; + break; + } vty_port = atoi (optarg); + vty_port = (vty_port ? vty_port : OSPF6_VTY_PORT); + break; + case 'u': + ospf6d_privs.user = ospf6d_privs.group = optarg; break; case 'v': print_version (progname); @@ -280,6 +314,7 @@ main (int argc, char *argv[], char *envp[]) zlog_default = openzlog (progname, flag, ZLOG_OSPF6, LOG_CONS|LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON); + zprivs_init (&ospf6d_privs); signal_init (); cmd_init (1); vty_init (); @@ -305,8 +340,7 @@ main (int argc, char *argv[], char *envp[]) thread_add_read (master, ospf6_receive, NULL, ospf6_sock); /* Make ospf vty socket. */ - vty_serv_sock (vty_addr, - vty_port ? vty_port : OSPF6_VTY_PORT, OSPF6_VTYSH_PATH); + vty_serv_sock (vty_addr, vty_port, OSPF6_VTYSH_PATH); /* Print start message */ zlog_notice ("OSPF6d (Zebra-%s ospf6d-%s) starts", |