1 // SPDX-License-Identifier: GPL-2.0-or-later
7 #include <lib/version.h>
13 zebra_capabilities_t _caps_p
[] = {
14 ZCAP_NET_RAW
, ZCAP_BIND
, ZCAP_NET_ADMIN
, ZCAP_DAC_OVERRIDE
,
17 struct zebra_privs_t test_privs
= {
18 #if defined(FRR_USER) && defined(FRR_GROUP)
22 #if defined(VTY_GROUP)
23 .vty_group
= VTY_GROUP
,
26 .cap_num_p
= array_size(_caps_p
),
29 struct option longopts
[] = {{"help", no_argument
, NULL
, 'h'},
30 {"user", required_argument
, NULL
, 'u'},
31 {"group", required_argument
, NULL
, 'g'},
34 /* Help information display. */
35 static void usage(char *progname
, int status
)
38 fprintf(stderr
, "Try `%s --help' for more information.\n",
41 printf("Usage : %s [OPTION...]\n\
42 Daemon which does 'slow' things.\n\n\
43 -u, --user User to run as\n\
44 -g, --group Group to run as\n\
45 -h, --help Display this help and exit\n\
48 progname
, FRR_BUG_ADDRESS
);
53 struct event_loop
*master
;
55 int main(int argc
, char **argv
)
59 struct zprivs_ids_t ids
;
61 /* Set umask before anything for security */
64 /* get program name */
65 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
70 opt
= getopt_long(argc
, argv
, "hu:g:", longopts
, 0);
79 test_privs
.user
= optarg
;
82 test_privs
.group
= optarg
;
95 zprivs_preinit(&test_privs
);
96 zprivs_init(&test_privs
);
98 #define PRIV_STATE() \
99 ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
101 printf("%s\n", PRIV_STATE());
102 frr_with_privs(&test_privs
) {
103 printf("%s\n", PRIV_STATE());
106 printf("%s\n", PRIV_STATE());
107 zprivs_get_ids(&ids
);
109 /* terminate privileges */
110 zprivs_terminate(&test_privs
);
112 /* but these should continue to work... */
113 printf("%s\n", PRIV_STATE());
114 frr_with_privs(&test_privs
) {
115 printf("%s\n", PRIV_STATE());
118 printf("%s\n", PRIV_STATE());
119 zprivs_get_ids(&ids
);
121 printf("terminating\n");