root/maint/gnulib/tests/test-priv-set.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test the priv-set module.
   2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2007.  */
  18 
  19 #include <config.h>
  20 
  21 #include "priv-set.h"
  22 
  23 #if HAVE_GETPPRIV && HAVE_PRIV_H
  24 # include <priv.h>
  25 #endif
  26 #include <unistd.h>
  27 #include <errno.h>
  28 #include <sys/types.h>
  29 
  30 #include "macros.h"
  31 
  32 int
  33 main (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35 #if HAVE_GETPPRIV && HAVE_PRIV_H
  36     priv_set_t *set;
  37 
  38     ASSERT (set = priv_allocset ());
  39     ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  40     ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
  41 
  42     /* Do a series of removes and restores making sure that the results are
  43        consistent with our ismember function and solaris' priv_ismember.  */
  44     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
  45         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  46         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
  47     ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1);
  48         ASSERT (errno == EINVAL);
  49     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
  50         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  51         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
  52     ASSERT (priv_set_remove (PRIV_PROC_EXEC) == 0);
  53     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0);
  54         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  55         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0);
  56     ASSERT (priv_set_remove (PRIV_PROC_EXEC) == -1);
  57         ASSERT (errno == EINVAL);
  58     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0);
  59         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  60         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0);
  61     ASSERT (priv_set_restore (PRIV_PROC_EXEC) == 0);
  62     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
  63         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  64         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
  65     ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1);
  66         ASSERT (errno == EINVAL);
  67     ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
  68         ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  69         ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
  70 
  71     /* Test the priv_set_linkdir wrappers.  */
  72     ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
  73     if (priv_ismember (set, PRIV_SYS_LINKDIR))
  74       {
  75         ASSERT (priv_set_restore_linkdir () == -1);
  76             ASSERT (errno == EINVAL);
  77         ASSERT (priv_set_remove_linkdir () == 0);
  78         ASSERT (priv_set_remove_linkdir () == -1);
  79             ASSERT (errno == EINVAL);
  80         ASSERT (priv_set_restore_linkdir () == 0);
  81       }
  82 #else
  83     ASSERT (priv_set_restore_linkdir () == -1);
  84     ASSERT (priv_set_remove_linkdir () == -1);
  85 #endif
  86 
  87     return 0;
  88 }

/* [previous][next][first][last][top][bottom][index][help] */