2 * $Id: test-privs.c,v 1.1 2005/10/11 03:48:28 paul Exp $
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include <lib/version.h>
29 zebra_capabilities_t _caps_p
[] =
37 struct zebra_privs_t test_privs
=
39 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
41 .group
= QUAGGA_GROUP
,
43 #if defined(VTY_GROUP)
44 .vty_group
= VTY_GROUP
,
47 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
51 struct option longopts
[] =
53 { "help", no_argument
, NULL
, 'h'},
54 { "user", required_argument
, NULL
, 'u'},
55 { "group", required_argument
, NULL
, 'g'},
59 /* Help information display. */
61 usage (char *progname
, int status
)
64 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
67 printf ("Usage : %s [OPTION...]\n\
68 Daemon which does 'slow' things.\n\n\
69 -u, --user User to run as\n\
70 -g, --group Group to run as\n\
71 -h, --help Display this help and exit\n\
73 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
78 struct thread_master
*master
;
81 main (int argc
, char **argv
)
85 struct zprivs_ids_t ids
;
87 /* Set umask before anything for security */
90 /* get program name */
91 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
97 opt
= getopt_long (argc
, argv
, "hu:g:", longopts
, 0);
107 test_privs
.user
= optarg
;
110 test_privs
.group
= optarg
;
123 zprivs_init (&test_privs
);
125 #define PRIV_STATE() \
126 ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
128 printf ("%s\n", PRIV_STATE());
129 test_privs
.change(ZPRIVS_RAISE
);
131 printf ("%s\n", PRIV_STATE());
132 test_privs
.change(ZPRIVS_LOWER
);
134 printf ("%s\n", PRIV_STATE());
135 zprivs_get_ids (&ids
);
137 /* terminate privileges */
138 zprivs_terminate(&test_privs
);
140 /* but these should continue to work... */
141 printf ("%s\n", PRIV_STATE());
142 test_privs
.change(ZPRIVS_RAISE
);
144 printf ("%s\n", PRIV_STATE());
145 test_privs
.change(ZPRIVS_LOWER
);
147 printf ("%s\n", PRIV_STATE());
148 zprivs_get_ids (&ids
);
150 printf ("terminating\n");