error: Avoid "function declaration isn't a prototype" warning.
[gnulib.git] / tests / test-priv-set.c
blob76fcc60f55e7121d0e0bcb4aa5de286c200d69c8
1 /* Test the priv-set module.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2007. */
19 #include <config.h>
21 #include "priv-set.h"
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>
30 #include "macros.h"
32 int
33 main (void)
35 #if HAVE_GETPPRIV && HAVE_PRIV_H
36 priv_set_t *set;
38 ASSERT (set = priv_allocset ());
39 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
40 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
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);
71 /* Test the priv_set_linkdir wrappers. */
72 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
73 if (priv_ismember (set, PRIV_SYS_LINKDIR))
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);
82 #else
83 ASSERT (priv_set_restore_linkdir () == -1);
84 ASSERT (priv_set_remove_linkdir () == -1);
85 #endif
87 return 0;