isisd: fix --enable-isis-topology for 64-bit Linux
[jleu-quagga.git] / tests / test-privs.c
bloba888ea0fc6d89a5212fe157d6e4c356203358c04
1 /*
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
9 * later version.
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
19 * 02111-1307, USA.
22 #include <zebra.h>
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "privs.h"
27 #include "memory.h"
29 zebra_capabilities_t _caps_p [] =
31 ZCAP_NET_RAW,
32 ZCAP_BIND,
33 ZCAP_NET_ADMIN,
34 ZCAP_DAC_OVERRIDE,
37 struct zebra_privs_t test_privs =
39 #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
40 .user = QUAGGA_USER,
41 .group = QUAGGA_GROUP,
42 #endif
43 #if defined(VTY_GROUP)
44 .vty_group = VTY_GROUP,
45 #endif
46 .caps_p = _caps_p,
47 .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
48 .cap_num_i = 0
51 struct option longopts[] =
53 { "help", no_argument, NULL, 'h'},
54 { "user", required_argument, NULL, 'u'},
55 { "group", required_argument, NULL, 'g'},
56 { 0 }
59 /* Help information display. */
60 static void
61 usage (char *progname, int status)
63 if (status != 0)
64 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
65 else
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\
72 \n\
73 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
75 exit (status);
78 struct thread_master *master;
79 /* main routine. */
80 int
81 main (int argc, char **argv)
83 char *p;
84 char *progname;
85 struct zprivs_ids_t ids;
87 /* Set umask before anything for security */
88 umask (0027);
90 /* get program name */
91 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
93 while (1)
95 int opt;
97 opt = getopt_long (argc, argv, "hu:g:", longopts, 0);
99 if (opt == EOF)
100 break;
102 switch (opt)
104 case 0:
105 break;
106 case 'u':
107 test_privs.user = optarg;
108 break;
109 case 'g':
110 test_privs.group = optarg;
111 break;
112 case 'h':
113 usage (progname, 0);
114 break;
115 default:
116 usage (progname, 1);
117 break;
121 /* Library inits. */
122 memory_init ();
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");
151 return 0;