]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-10-11 Paul Jakma <paul.jakma@sun.com>
authorpaul <paul>
Tue, 11 Oct 2005 03:48:28 +0000 (03:48 +0000)
committerpaul <paul>
Tue, 11 Oct 2005 03:48:28 +0000 (03:48 +0000)
* test-privs.c: Privileges unit test.
* Makefile.am: build testprivs
* aspath_test.c: fix a few sign warnings

tests/ChangeLog
tests/Makefile.am
tests/aspath_test.c
tests/test-privs.c [new file with mode: 0644]

index 99d09c8b23252028450a9ea1d6d25d04b5f60583..1264bf0ad3f297d7b73a73ad7953d25b7872886c 100644 (file)
@@ -1,3 +1,9 @@
+2005-10-11 Paul Jakma <paul.jakma@sun.com>
+
+       * test-privs.c: Privileges unit test.
+       * Makefile.am: build testprivs
+       * aspath_test.c: fix a few sign warnings
+
 2005-09-06 Paul Jakma <paul@dishone.st>
 
        * aspath_test.c: Test bgp_aspath functionality.
index 1449014d2b5bafefde44c570b39d32f77102bb7e..4240ec116e9533c32a216196b805028dc7583ec1 100644 (file)
@@ -2,10 +2,11 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
 DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\"
 
 noinst_PROGRAMS = testsig testbuffer testmemory heavy heavywq heavythread \
-               aspathtest
+               aspathtest testprivs
 testsig_SOURCES = test-sig.c
 testbuffer_SOURCES = test-buffer.c
 testmemory_SOURCES = test-memory.c
+testprivs_SOURCES = test-privs.c
 heavy_SOURCES = heavy.c main.c
 heavywq_SOURCES = heavy-wq.c main.c
 heavythread_SOURCES = heavy-thread.c main.c
@@ -14,6 +15,7 @@ aspathtest_SOURCES = aspath_test.c
 testsig_LDADD = ../lib/libzebra.la @LIBCAP@
 testbuffer_LDADD = ../lib/libzebra.la @LIBCAP@
 testmemory_LDADD = ../lib/libzebra.la @LIBCAP@
+testprivs_LDADD = ../lib/libzebra.la @LIBCAP@
 heavy_LDADD = ../lib/libzebra.la @LIBCAP@ -lm
 heavywq_LDADD = ../lib/libzebra.la @LIBCAP@ -lm
 heavythread_LDADD = ../lib/libzebra.la @LIBCAP@ -lm
index f9e0a74fe88a5a05b27a7e8933329f9648c7d02f..f025cb7771cadc46a31b32e4eb663c13b0543c4c 100644 (file)
@@ -18,8 +18,8 @@ struct test_spec
 {
   const char *shouldbe; /* the string the path should parse to */
   const char *shouldbe_delete_confed; /* ditto, but once confeds are deleted */
-  const int hops; /* aspath_count_hops result */
-  const int confeds; /* aspath_count_confeds */
+  const unsigned int hops; /* aspath_count_hops result */
+  const unsigned int confeds; /* aspath_count_confeds */
   const int private_as; /* whether the private_as check should pass or fail */
 #define NOT_ALL_PRIVATE 0
 #define ALL_PRIVATE 1
@@ -731,7 +731,7 @@ aggregate_test (struct tests *t)
 static void
 cmp_test ()
 {
-  int i;
+  unsigned int i;
 #define CMP_TESTS_MAX \
   (sizeof(left_compare) / sizeof (struct compare_tests))
 
diff --git a/tests/test-privs.c b/tests/test-privs.c
new file mode 100644 (file)
index 0000000..a888ea0
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * $Id: test-privs.c,v 1.1 2005/10/11 03:48:28 paul Exp $
+ *
+ * This file is part of Quagga.
+ *
+ * Quagga is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * Quagga is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Quagga; see the file COPYING.  If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <zebra.h>
+
+#include <lib/version.h>
+#include "getopt.h"
+#include "privs.h"
+#include "memory.h"
+
+zebra_capabilities_t _caps_p [] = 
+{
+  ZCAP_NET_RAW,
+  ZCAP_BIND,
+  ZCAP_NET_ADMIN,
+  ZCAP_DAC_OVERRIDE,
+};
+
+struct zebra_privs_t test_privs =
+{
+#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
+  .user = QUAGGA_USER,
+  .group = QUAGGA_GROUP,
+#endif
+#if defined(VTY_GROUP)
+  .vty_group = VTY_GROUP,
+#endif
+  .caps_p = _caps_p,
+  .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
+  .cap_num_i = 0
+};
+
+struct option longopts[] = 
+{
+  { "help",        no_argument,       NULL, 'h'},
+  { "user",        required_argument, NULL, 'u'},
+  { "group",       required_argument, NULL, 'g'},
+  { 0 }
+};
+
+/* Help information display. */
+static void
+usage (char *progname, int status)
+{
+  if (status != 0)
+    fprintf (stderr, "Try `%s --help' for more information.\n", progname);
+  else
+    {    
+      printf ("Usage : %s [OPTION...]\n\
+Daemon which does 'slow' things.\n\n\
+-u, --user         User to run as\n\
+-g, --group        Group to run as\n\
+-h, --help         Display this help and exit\n\
+\n\
+Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
+    }
+  exit (status);
+}
+\f
+struct thread_master *master;
+/* main routine. */
+int
+main (int argc, char **argv)
+{
+  char *p;
+  char *progname;
+  struct zprivs_ids_t ids;
+  
+  /* Set umask before anything for security */
+  umask (0027);
+
+  /* get program name */
+  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
+
+  while (1) 
+    {
+      int opt;
+
+      opt = getopt_long (argc, argv, "hu:g:", longopts, 0);
+    
+      if (opt == EOF)
+       break;
+
+      switch (opt) 
+       {
+       case 0:
+         break;
+        case 'u':
+          test_privs.user = optarg;
+          break;
+        case 'g':
+          test_privs.group = optarg;
+          break;
+       case 'h':
+         usage (progname, 0);
+         break;
+       default:
+         usage (progname, 1);
+         break;
+       }
+    }
+
+  /* Library inits. */
+  memory_init ();
+  zprivs_init (&test_privs);
+
+#define PRIV_STATE() \
+  ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
+  
+  printf ("%s\n", PRIV_STATE());
+  test_privs.change(ZPRIVS_RAISE);
+  
+  printf ("%s\n", PRIV_STATE());
+  test_privs.change(ZPRIVS_LOWER);
+  
+  printf ("%s\n", PRIV_STATE());
+  zprivs_get_ids (&ids);  
+  
+  /* terminate privileges */
+  zprivs_terminate(&test_privs);
+  
+  /* but these should continue to work... */
+  printf ("%s\n", PRIV_STATE());
+  test_privs.change(ZPRIVS_RAISE);
+  
+  printf ("%s\n", PRIV_STATE());
+  test_privs.change(ZPRIVS_LOWER);
+  
+  printf ("%s\n", PRIV_STATE());
+  zprivs_get_ids (&ids);  
+  
+  printf ("terminating\n");
+  return 0;
+}