2 * This file is part of Quagga.
4 * Quagga is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
9 * Quagga is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <lib/version.h>
25 #include "memory_vty.h"
27 zebra_capabilities_t _caps_p
[] = {
28 ZCAP_NET_RAW
, ZCAP_BIND
, ZCAP_NET_ADMIN
, ZCAP_DAC_OVERRIDE
,
31 struct zebra_privs_t test_privs
= {
32 #if defined(FRR_USER) && defined(FRR_GROUP)
36 #if defined(VTY_GROUP)
37 .vty_group
= VTY_GROUP
,
40 .cap_num_p
= array_size(_caps_p
),
43 struct option longopts
[] = {{"help", no_argument
, NULL
, 'h'},
44 {"user", required_argument
, NULL
, 'u'},
45 {"group", required_argument
, NULL
, 'g'},
48 /* Help information display. */
49 static void usage(char *progname
, int status
)
52 fprintf(stderr
, "Try `%s --help' for more information.\n",
55 printf("Usage : %s [OPTION...]\n\
56 Daemon which does 'slow' things.\n\n\
57 -u, --user User to run as\n\
58 -g, --group Group to run as\n\
59 -h, --help Display this help and exit\n\
62 progname
, FRR_BUG_ADDRESS
);
67 struct thread_master
*master
;
69 int main(int argc
, char **argv
)
73 struct zprivs_ids_t ids
;
75 /* Set umask before anything for security */
78 /* get program name */
79 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
84 opt
= getopt_long(argc
, argv
, "hu:g:", longopts
, 0);
93 test_privs
.user
= optarg
;
96 test_privs
.group
= optarg
;
109 zprivs_preinit(&test_privs
);
110 zprivs_init(&test_privs
);
112 #define PRIV_STATE() \
113 ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
115 printf("%s\n", PRIV_STATE());
116 frr_elevate_privs(&test_privs
) {
117 printf("%s\n", PRIV_STATE());
120 printf("%s\n", PRIV_STATE());
121 zprivs_get_ids(&ids
);
123 /* terminate privileges */
124 zprivs_terminate(&test_privs
);
126 /* but these should continue to work... */
127 printf("%s\n", PRIV_STATE());
128 frr_elevate_privs(&test_privs
) {
129 printf("%s\n", PRIV_STATE());
132 printf("%s\n", PRIV_STATE());
133 zprivs_get_ids(&ids
);
135 printf("terminating\n");