1 /* Test the priv-set module.
2 Copyright (C) 2009 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. */
29 #include <sys/types.h>
31 #define ASSERT(expr) \
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
49 ASSERT (set = priv_allocset ());
50 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
51 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
53 /* Do a series of removes and restores making sure that the results are
54 consistent with our ismember function and solaris' priv_ismember. */
55 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
56 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
57 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
58 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1);
59 ASSERT (errno == EINVAL);
60 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
61 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
62 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
63 ASSERT (priv_set_remove (PRIV_PROC_EXEC) == 0);
64 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0);
65 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
66 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0);
67 ASSERT (priv_set_remove (PRIV_PROC_EXEC) == -1);
68 ASSERT (errno == EINVAL);
69 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0);
70 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
71 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0);
72 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == 0);
73 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
74 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
75 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
76 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1);
77 ASSERT (errno == EINVAL);
78 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1);
79 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
80 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1);
82 /* Test the priv_set_linkdir wrappers. */
83 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0);
84 if (priv_ismember (set, PRIV_SYS_LINKDIR))
86 ASSERT (priv_set_restore_linkdir () == -1);
87 ASSERT (errno == EINVAL);
88 ASSERT (priv_set_remove_linkdir () == 0);
89 ASSERT (priv_set_remove_linkdir () == -1);
90 ASSERT (errno == EINVAL);
91 ASSERT (priv_set_restore_linkdir () == 0);
94 ASSERT (priv_set_restore_linkdir () == -1);
95 ASSERT (priv_set_remove_linkdir () == -1);