pax_global_header00006660000000000000000000000064147621173720014524gustar00rootroot0000000000000052 comment=8e9157bbeea1899b7b8b257e7eaa71efef3fffed
libsepol-3.8.1/000077500000000000000000000000001476211737200133465ustar00rootroot00000000000000libsepol-3.8.1/.gitignore000066400000000000000000000002411476211737200153330ustar00rootroot00000000000000utils/chkcon
utils/sepol_check_access
utils/sepol_compute_av
utils/sepol_compute_member
utils/sepol_compute_relabel
utils/sepol_validate_transition
libsepol.map
libsepol-3.8.1/LICENSE000066400000000000000000000635001476211737200143570ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
libsepol-3.8.1/Makefile000066400000000000000000000006271476211737200150130ustar00rootroot00000000000000DISABLE_CIL ?= n
export DISABLE_CIL
all:
$(MAKE) -C src
$(MAKE) -C utils
install:
$(MAKE) -C include install
$(MAKE) -C src install
$(MAKE) -C utils install
$(MAKE) -C man install
relabel:
$(MAKE) -C src relabel
clean:
$(MAKE) -C src clean
$(MAKE) -C utils clean
$(MAKE) -C tests clean
indent:
$(MAKE) -C src $@
$(MAKE) -C include $@
$(MAKE) -C utils $@
test:
$(MAKE) -C tests test
libsepol-3.8.1/VERSION000066400000000000000000000000061476211737200144120ustar00rootroot000000000000003.8.1
libsepol-3.8.1/cil/000077500000000000000000000000001476211737200141155ustar00rootroot00000000000000libsepol-3.8.1/cil/.gitignore000066400000000000000000000001711476211737200161040ustar00rootroot00000000000000*.swp
*.gcda
*.gcno
*.o
*.a
src/cil_lexer.c
unit_tests
cov
secilc
docs/pdf/
docs/html/
docs/man8/
policy.*
file_contexts
libsepol-3.8.1/cil/include/000077500000000000000000000000001476211737200155405ustar00rootroot00000000000000libsepol-3.8.1/cil/include/cil/000077500000000000000000000000001476211737200163075ustar00rootroot00000000000000libsepol-3.8.1/cil/include/cil/cil.h000066400000000000000000000073511476211737200172350ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_H_
#define CIL_H_
#include
#ifdef __cplusplus
extern "C" {
#endif
struct cil_db;
typedef struct cil_db cil_db_t;
extern void cil_db_init(cil_db_t **db);
extern void cil_db_destroy(cil_db_t **db);
extern int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size);
extern int cil_compile(cil_db_t *db);
extern int cil_build_policydb(cil_db_t *db, sepol_policydb_t **sepol_db);
extern int cil_userprefixes_to_string(cil_db_t *db, char **out, size_t *size);
extern int cil_selinuxusers_to_string(cil_db_t *db, char **out, size_t *size);
extern int cil_filecons_to_string(cil_db_t *db, char **out, size_t *size);
extern void cil_set_disable_dontaudit(cil_db_t *db, int disable_dontaudit);
extern void cil_set_multiple_decls(cil_db_t *db, int multiple_decls);
extern void cil_set_qualified_names(struct cil_db *db, int qualified_names);
extern void cil_set_disable_neverallow(cil_db_t *db, int disable_neverallow);
extern void cil_set_preserve_tunables(cil_db_t *db, int preserve_tunables);
extern int cil_set_handle_unknown(cil_db_t *db, int handle_unknown);
extern void cil_set_mls(cil_db_t *db, int mls);
extern void cil_set_attrs_expand_generated(struct cil_db *db, int attrs_expand_generated);
extern void cil_set_attrs_expand_size(struct cil_db *db, unsigned attrs_expand_size);
extern void cil_set_target_platform(cil_db_t *db, int target_platform);
extern void cil_set_policy_version(cil_db_t *db, int policy_version);
extern void cil_write_policy_conf(FILE *out, struct cil_db *db);
extern int cil_write_parse_ast(FILE *out, cil_db_t *db);
extern int cil_write_build_ast(FILE *out, cil_db_t *db);
extern int cil_write_resolve_ast(FILE *out, cil_db_t *db);
extern int cil_write_post_ast(FILE *out, cil_db_t *db);
enum cil_log_level {
CIL_ERR = 1,
CIL_WARN,
CIL_INFO
};
extern void cil_set_log_level(enum cil_log_level lvl);
extern void cil_set_log_handler(void (*handler)(int lvl, const char *msg));
#ifdef __GNUC__
__attribute__ ((format(printf, 2, 3)))
#endif
extern void cil_log(enum cil_log_level lvl, const char *msg, ...);
extern void cil_set_malloc_error_handler(void (*handler)(void));
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/cil/src/000077500000000000000000000000001476211737200147045ustar00rootroot00000000000000libsepol-3.8.1/cil/src/cil.c000066400000000000000000002165171476211737200156330ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_symtab.h"
#include "cil_build_ast.h"
#include "cil_parser.h"
#include "cil_build_ast.h"
#include "cil_resolve_ast.h"
#include "cil_fqn.h"
#include "cil_post.h"
#include "cil_binary.h"
#include "cil_policy.h"
#include "cil_strpool.h"
#include "cil_write_ast.h"
const int cil_sym_sizes[CIL_SYM_ARRAY_NUM][CIL_SYM_NUM] = {
{64, 64, 64, 1 << 13, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
{8, 8, 8, 32, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
char *CIL_KEY_CONS_T1;
char *CIL_KEY_CONS_T2;
char *CIL_KEY_CONS_T3;
char *CIL_KEY_CONS_R1;
char *CIL_KEY_CONS_R2;
char *CIL_KEY_CONS_R3;
char *CIL_KEY_CONS_U1;
char *CIL_KEY_CONS_U2;
char *CIL_KEY_CONS_U3;
char *CIL_KEY_CONS_L1;
char *CIL_KEY_CONS_L2;
char *CIL_KEY_CONS_H1;
char *CIL_KEY_CONS_H2;
char *CIL_KEY_AND;
char *CIL_KEY_OR;
char *CIL_KEY_NOT;
char *CIL_KEY_EQ;
char *CIL_KEY_NEQ;
char *CIL_KEY_CONS_DOM;
char *CIL_KEY_CONS_DOMBY;
char *CIL_KEY_CONS_INCOMP;
char *CIL_KEY_CONDTRUE;
char *CIL_KEY_CONDFALSE;
char *CIL_KEY_SELF;
char *CIL_KEY_NOTSELF;
char *CIL_KEY_OTHER;
char *CIL_KEY_OBJECT_R;
char *CIL_KEY_STAR;
char *CIL_KEY_TCP;
char *CIL_KEY_UDP;
char *CIL_KEY_DCCP;
char *CIL_KEY_SCTP;
char *CIL_KEY_AUDITALLOW;
char *CIL_KEY_TUNABLEIF;
char *CIL_KEY_ALLOW;
char *CIL_KEY_DONTAUDIT;
char *CIL_KEY_TYPETRANSITION;
char *CIL_KEY_TYPECHANGE;
char *CIL_KEY_CALL;
char *CIL_KEY_TUNABLE;
char *CIL_KEY_XOR;
char *CIL_KEY_ALL;
char *CIL_KEY_RANGE;
char *CIL_KEY_GLOB;
char *CIL_KEY_FILE;
char *CIL_KEY_DIR;
char *CIL_KEY_CHAR;
char *CIL_KEY_BLOCK;
char *CIL_KEY_SOCKET;
char *CIL_KEY_PIPE;
char *CIL_KEY_SYMLINK;
char *CIL_KEY_ANY;
char *CIL_KEY_XATTR;
char *CIL_KEY_TASK;
char *CIL_KEY_TRANS;
char *CIL_KEY_TYPE;
char *CIL_KEY_ROLE;
char *CIL_KEY_USER;
char *CIL_KEY_USERATTRIBUTE;
char *CIL_KEY_USERATTRIBUTESET;
char *CIL_KEY_SENSITIVITY;
char *CIL_KEY_CATEGORY;
char *CIL_KEY_CATSET;
char *CIL_KEY_LEVEL;
char *CIL_KEY_LEVELRANGE;
char *CIL_KEY_CLASS;
char *CIL_KEY_IPADDR;
char *CIL_KEY_MAP_CLASS;
char *CIL_KEY_CLASSPERMISSION;
char *CIL_KEY_BOOL;
char *CIL_KEY_STRING;
char *CIL_KEY_NAME;
char *CIL_KEY_SOURCE;
char *CIL_KEY_TARGET;
char *CIL_KEY_LOW;
char *CIL_KEY_HIGH;
char *CIL_KEY_LOW_HIGH;
char *CIL_KEY_GLBLUB;
char *CIL_KEY_HANDLEUNKNOWN;
char *CIL_KEY_HANDLEUNKNOWN_ALLOW;
char *CIL_KEY_HANDLEUNKNOWN_DENY;
char *CIL_KEY_HANDLEUNKNOWN_REJECT;
char *CIL_KEY_MACRO;
char *CIL_KEY_IN;
char *CIL_KEY_IN_BEFORE;
char *CIL_KEY_IN_AFTER;
char *CIL_KEY_MLS;
char *CIL_KEY_DEFAULTRANGE;
char *CIL_KEY_BLOCKINHERIT;
char *CIL_KEY_BLOCKABSTRACT;
char *CIL_KEY_CLASSORDER;
char *CIL_KEY_CLASSMAPPING;
char *CIL_KEY_CLASSPERMISSIONSET;
char *CIL_KEY_COMMON;
char *CIL_KEY_CLASSCOMMON;
char *CIL_KEY_SID;
char *CIL_KEY_SIDCONTEXT;
char *CIL_KEY_SIDORDER;
char *CIL_KEY_USERLEVEL;
char *CIL_KEY_USERRANGE;
char *CIL_KEY_USERBOUNDS;
char *CIL_KEY_USERPREFIX;
char *CIL_KEY_SELINUXUSER;
char *CIL_KEY_SELINUXUSERDEFAULT;
char *CIL_KEY_TYPEATTRIBUTE;
char *CIL_KEY_TYPEATTRIBUTESET;
char *CIL_KEY_EXPANDTYPEATTRIBUTE;
char *CIL_KEY_TYPEALIAS;
char *CIL_KEY_TYPEALIASACTUAL;
char *CIL_KEY_TYPEBOUNDS;
char *CIL_KEY_TYPEPERMISSIVE;
char *CIL_KEY_RANGETRANSITION;
char *CIL_KEY_USERROLE;
char *CIL_KEY_ROLETYPE;
char *CIL_KEY_ROLETRANSITION;
char *CIL_KEY_ROLEALLOW;
char *CIL_KEY_ROLEATTRIBUTE;
char *CIL_KEY_ROLEATTRIBUTESET;
char *CIL_KEY_ROLEBOUNDS;
char *CIL_KEY_BOOLEANIF;
char *CIL_KEY_NEVERALLOW;
char *CIL_KEY_TYPEMEMBER;
char *CIL_KEY_SENSALIAS;
char *CIL_KEY_SENSALIASACTUAL;
char *CIL_KEY_CATALIAS;
char *CIL_KEY_CATALIASACTUAL;
char *CIL_KEY_CATORDER;
char *CIL_KEY_SENSITIVITYORDER;
char *CIL_KEY_SENSCAT;
char *CIL_KEY_CONSTRAIN;
char *CIL_KEY_MLSCONSTRAIN;
char *CIL_KEY_VALIDATETRANS;
char *CIL_KEY_MLSVALIDATETRANS;
char *CIL_KEY_CONTEXT;
char *CIL_KEY_FILECON;
char *CIL_KEY_IBPKEYCON;
char *CIL_KEY_IBENDPORTCON;
char *CIL_KEY_PORTCON;
char *CIL_KEY_NODECON;
char *CIL_KEY_GENFSCON;
char *CIL_KEY_NETIFCON;
char *CIL_KEY_PIRQCON;
char *CIL_KEY_IOMEMCON;
char *CIL_KEY_IOPORTCON;
char *CIL_KEY_PCIDEVICECON;
char *CIL_KEY_DEVICETREECON;
char *CIL_KEY_FSUSE;
char *CIL_KEY_POLICYCAP;
char *CIL_KEY_OPTIONAL;
char *CIL_KEY_DEFAULTUSER;
char *CIL_KEY_DEFAULTROLE;
char *CIL_KEY_DEFAULTTYPE;
char *CIL_KEY_ROOT;
char *CIL_KEY_NODE;
char *CIL_KEY_PERM;
char *CIL_KEY_ALLOWX;
char *CIL_KEY_AUDITALLOWX;
char *CIL_KEY_DONTAUDITX;
char *CIL_KEY_NEVERALLOWX;
char *CIL_KEY_PERMISSIONX;
char *CIL_KEY_IOCTL;
char *CIL_KEY_NLMSG;
char *CIL_KEY_UNORDERED;
char *CIL_KEY_SRC_INFO;
char *CIL_KEY_SRC_CIL;
char *CIL_KEY_SRC_HLL_LMS;
char *CIL_KEY_SRC_HLL_LMX;
char *CIL_KEY_SRC_HLL_LME;
char *CIL_KEY_DENY_RULE;
static void cil_init_keys(void)
{
/* Initialize CIL Keys into strpool */
CIL_KEY_CONS_T1 = cil_strpool_add("t1");
CIL_KEY_CONS_T2 = cil_strpool_add("t2");
CIL_KEY_CONS_T3 = cil_strpool_add("t3");
CIL_KEY_CONS_R1 = cil_strpool_add("r1");
CIL_KEY_CONS_R2 = cil_strpool_add("r2");
CIL_KEY_CONS_R3 = cil_strpool_add("r3");
CIL_KEY_CONS_U1 = cil_strpool_add("u1");
CIL_KEY_CONS_U2 = cil_strpool_add("u2");
CIL_KEY_CONS_U3 = cil_strpool_add("u3");
CIL_KEY_CONS_L1 = cil_strpool_add("l1");
CIL_KEY_CONS_L2 = cil_strpool_add("l2");
CIL_KEY_CONS_H1 = cil_strpool_add("h1");
CIL_KEY_CONS_H2 = cil_strpool_add("h2");
CIL_KEY_AND = cil_strpool_add("and");
CIL_KEY_OR = cil_strpool_add("or");
CIL_KEY_NOT = cil_strpool_add("not");
CIL_KEY_EQ = cil_strpool_add("eq");
CIL_KEY_NEQ = cil_strpool_add("neq");
CIL_KEY_CONS_DOM = cil_strpool_add("dom");
CIL_KEY_CONS_DOMBY = cil_strpool_add("domby");
CIL_KEY_CONS_INCOMP = cil_strpool_add("incomp");
CIL_KEY_CONDTRUE = cil_strpool_add("true");
CIL_KEY_CONDFALSE = cil_strpool_add("false");
CIL_KEY_SELF = cil_strpool_add("self");
CIL_KEY_NOTSELF = cil_strpool_add("notself");
CIL_KEY_OTHER = cil_strpool_add("other");
CIL_KEY_OBJECT_R = cil_strpool_add("object_r");
CIL_KEY_STAR = cil_strpool_add("*");
CIL_KEY_UDP = cil_strpool_add("udp");
CIL_KEY_TCP = cil_strpool_add("tcp");
CIL_KEY_DCCP = cil_strpool_add("dccp");
CIL_KEY_SCTP = cil_strpool_add("sctp");
CIL_KEY_AUDITALLOW = cil_strpool_add("auditallow");
CIL_KEY_TUNABLEIF = cil_strpool_add("tunableif");
CIL_KEY_ALLOW = cil_strpool_add("allow");
CIL_KEY_DONTAUDIT = cil_strpool_add("dontaudit");
CIL_KEY_TYPETRANSITION = cil_strpool_add("typetransition");
CIL_KEY_TYPECHANGE = cil_strpool_add("typechange");
CIL_KEY_CALL = cil_strpool_add("call");
CIL_KEY_TUNABLE = cil_strpool_add("tunable");
CIL_KEY_XOR = cil_strpool_add("xor");
CIL_KEY_ALL = cil_strpool_add("all");
CIL_KEY_RANGE = cil_strpool_add("range");
CIL_KEY_TYPE = cil_strpool_add("type");
CIL_KEY_ROLE = cil_strpool_add("role");
CIL_KEY_USER = cil_strpool_add("user");
CIL_KEY_USERATTRIBUTE = cil_strpool_add("userattribute");
CIL_KEY_USERATTRIBUTESET = cil_strpool_add("userattributeset");
CIL_KEY_SENSITIVITY = cil_strpool_add("sensitivity");
CIL_KEY_CATEGORY = cil_strpool_add("category");
CIL_KEY_CATSET = cil_strpool_add("categoryset");
CIL_KEY_LEVEL = cil_strpool_add("level");
CIL_KEY_LEVELRANGE = cil_strpool_add("levelrange");
CIL_KEY_CLASS = cil_strpool_add("class");
CIL_KEY_IPADDR = cil_strpool_add("ipaddr");
CIL_KEY_MAP_CLASS = cil_strpool_add("classmap");
CIL_KEY_CLASSPERMISSION = cil_strpool_add("classpermission");
CIL_KEY_BOOL = cil_strpool_add("boolean");
CIL_KEY_STRING = cil_strpool_add("string");
CIL_KEY_NAME = cil_strpool_add("name");
CIL_KEY_HANDLEUNKNOWN = cil_strpool_add("handleunknown");
CIL_KEY_HANDLEUNKNOWN_ALLOW = cil_strpool_add("allow");
CIL_KEY_HANDLEUNKNOWN_DENY = cil_strpool_add("deny");
CIL_KEY_HANDLEUNKNOWN_REJECT = cil_strpool_add("reject");
CIL_KEY_BLOCKINHERIT = cil_strpool_add("blockinherit");
CIL_KEY_BLOCKABSTRACT = cil_strpool_add("blockabstract");
CIL_KEY_CLASSORDER = cil_strpool_add("classorder");
CIL_KEY_CLASSMAPPING = cil_strpool_add("classmapping");
CIL_KEY_CLASSPERMISSIONSET = cil_strpool_add("classpermissionset");
CIL_KEY_COMMON = cil_strpool_add("common");
CIL_KEY_CLASSCOMMON = cil_strpool_add("classcommon");
CIL_KEY_SID = cil_strpool_add("sid");
CIL_KEY_SIDCONTEXT = cil_strpool_add("sidcontext");
CIL_KEY_SIDORDER = cil_strpool_add("sidorder");
CIL_KEY_USERLEVEL = cil_strpool_add("userlevel");
CIL_KEY_USERRANGE = cil_strpool_add("userrange");
CIL_KEY_USERBOUNDS = cil_strpool_add("userbounds");
CIL_KEY_USERPREFIX = cil_strpool_add("userprefix");
CIL_KEY_SELINUXUSER = cil_strpool_add("selinuxuser");
CIL_KEY_SELINUXUSERDEFAULT = cil_strpool_add("selinuxuserdefault");
CIL_KEY_TYPEATTRIBUTE = cil_strpool_add("typeattribute");
CIL_KEY_TYPEATTRIBUTESET = cil_strpool_add("typeattributeset");
CIL_KEY_EXPANDTYPEATTRIBUTE = cil_strpool_add("expandtypeattribute");
CIL_KEY_TYPEALIAS = cil_strpool_add("typealias");
CIL_KEY_TYPEALIASACTUAL = cil_strpool_add("typealiasactual");
CIL_KEY_TYPEBOUNDS = cil_strpool_add("typebounds");
CIL_KEY_TYPEPERMISSIVE = cil_strpool_add("typepermissive");
CIL_KEY_RANGETRANSITION = cil_strpool_add("rangetransition");
CIL_KEY_USERROLE = cil_strpool_add("userrole");
CIL_KEY_ROLETYPE = cil_strpool_add("roletype");
CIL_KEY_ROLETRANSITION = cil_strpool_add("roletransition");
CIL_KEY_ROLEALLOW = cil_strpool_add("roleallow");
CIL_KEY_ROLEATTRIBUTE = cil_strpool_add("roleattribute");
CIL_KEY_ROLEATTRIBUTESET = cil_strpool_add("roleattributeset");
CIL_KEY_ROLEBOUNDS = cil_strpool_add("rolebounds");
CIL_KEY_BOOLEANIF = cil_strpool_add("booleanif");
CIL_KEY_NEVERALLOW = cil_strpool_add("neverallow");
CIL_KEY_TYPEMEMBER = cil_strpool_add("typemember");
CIL_KEY_SENSALIAS = cil_strpool_add("sensitivityalias");
CIL_KEY_SENSALIASACTUAL = cil_strpool_add("sensitivityaliasactual");
CIL_KEY_CATALIAS = cil_strpool_add("categoryalias");
CIL_KEY_CATALIASACTUAL = cil_strpool_add("categoryaliasactual");
CIL_KEY_CATORDER = cil_strpool_add("categoryorder");
CIL_KEY_SENSITIVITYORDER = cil_strpool_add("sensitivityorder");
CIL_KEY_SENSCAT = cil_strpool_add("sensitivitycategory");
CIL_KEY_CONSTRAIN = cil_strpool_add("constrain");
CIL_KEY_MLSCONSTRAIN = cil_strpool_add("mlsconstrain");
CIL_KEY_VALIDATETRANS = cil_strpool_add("validatetrans");
CIL_KEY_MLSVALIDATETRANS = cil_strpool_add("mlsvalidatetrans");
CIL_KEY_CONTEXT = cil_strpool_add("context");
CIL_KEY_FILECON = cil_strpool_add("filecon");
CIL_KEY_IBPKEYCON = cil_strpool_add("ibpkeycon");
CIL_KEY_IBENDPORTCON = cil_strpool_add("ibendportcon");
CIL_KEY_PORTCON = cil_strpool_add("portcon");
CIL_KEY_NODECON = cil_strpool_add("nodecon");
CIL_KEY_GENFSCON = cil_strpool_add("genfscon");
CIL_KEY_NETIFCON = cil_strpool_add("netifcon");
CIL_KEY_PIRQCON = cil_strpool_add("pirqcon");
CIL_KEY_IOMEMCON = cil_strpool_add("iomemcon");
CIL_KEY_IOPORTCON = cil_strpool_add("ioportcon");
CIL_KEY_PCIDEVICECON = cil_strpool_add("pcidevicecon");
CIL_KEY_DEVICETREECON = cil_strpool_add("devicetreecon");
CIL_KEY_FSUSE = cil_strpool_add("fsuse");
CIL_KEY_POLICYCAP = cil_strpool_add("policycap");
CIL_KEY_OPTIONAL = cil_strpool_add("optional");
CIL_KEY_DEFAULTUSER = cil_strpool_add("defaultuser");
CIL_KEY_DEFAULTROLE = cil_strpool_add("defaultrole");
CIL_KEY_DEFAULTTYPE = cil_strpool_add("defaulttype");
CIL_KEY_MACRO = cil_strpool_add("macro");
CIL_KEY_IN = cil_strpool_add("in");
CIL_KEY_IN_BEFORE = cil_strpool_add("before");
CIL_KEY_IN_AFTER = cil_strpool_add("after");
CIL_KEY_MLS = cil_strpool_add("mls");
CIL_KEY_DEFAULTRANGE = cil_strpool_add("defaultrange");
CIL_KEY_GLOB = cil_strpool_add("*");
CIL_KEY_FILE = cil_strpool_add("file");
CIL_KEY_DIR = cil_strpool_add("dir");
CIL_KEY_CHAR = cil_strpool_add("char");
CIL_KEY_BLOCK = cil_strpool_add("block");
CIL_KEY_SOCKET = cil_strpool_add("socket");
CIL_KEY_PIPE = cil_strpool_add("pipe");
CIL_KEY_SYMLINK = cil_strpool_add("symlink");
CIL_KEY_ANY = cil_strpool_add("any");
CIL_KEY_XATTR = cil_strpool_add("xattr");
CIL_KEY_TASK = cil_strpool_add("task");
CIL_KEY_TRANS = cil_strpool_add("trans");
CIL_KEY_SOURCE = cil_strpool_add("source");
CIL_KEY_TARGET = cil_strpool_add("target");
CIL_KEY_LOW = cil_strpool_add("low");
CIL_KEY_HIGH = cil_strpool_add("high");
CIL_KEY_LOW_HIGH = cil_strpool_add("low-high");
CIL_KEY_GLBLUB = cil_strpool_add("glblub");
CIL_KEY_ROOT = cil_strpool_add("");
CIL_KEY_NODE = cil_strpool_add("");
CIL_KEY_PERM = cil_strpool_add("perm");
CIL_KEY_ALLOWX = cil_strpool_add("allowx");
CIL_KEY_AUDITALLOWX = cil_strpool_add("auditallowx");
CIL_KEY_DONTAUDITX = cil_strpool_add("dontauditx");
CIL_KEY_NEVERALLOWX = cil_strpool_add("neverallowx");
CIL_KEY_PERMISSIONX = cil_strpool_add("permissionx");
CIL_KEY_IOCTL = cil_strpool_add("ioctl");
CIL_KEY_NLMSG = cil_strpool_add("nlmsg");
CIL_KEY_UNORDERED = cil_strpool_add("unordered");
CIL_KEY_SRC_INFO = cil_strpool_add("");
CIL_KEY_SRC_CIL = cil_strpool_add("cil");
CIL_KEY_SRC_HLL_LMS = cil_strpool_add("lms");
CIL_KEY_SRC_HLL_LMX = cil_strpool_add("lmx");
CIL_KEY_SRC_HLL_LME = cil_strpool_add("lme");
CIL_KEY_DENY_RULE = cil_strpool_add("deny");
}
void cil_db_init(struct cil_db **db)
{
*db = cil_malloc(sizeof(**db));
cil_strpool_init();
cil_init_keys();
cil_tree_init(&(*db)->parse);
cil_tree_init(&(*db)->ast);
cil_root_init((struct cil_root **)&(*db)->ast->root->data);
(*db)->sidorder = NULL;
(*db)->classorder = NULL;
(*db)->catorder = NULL;
(*db)->sensitivityorder = NULL;
cil_sort_init(&(*db)->netifcon);
cil_sort_init(&(*db)->genfscon);
cil_sort_init(&(*db)->filecon);
cil_sort_init(&(*db)->nodecon);
cil_sort_init(&(*db)->ibpkeycon);
cil_sort_init(&(*db)->ibendportcon);
cil_sort_init(&(*db)->portcon);
cil_sort_init(&(*db)->pirqcon);
cil_sort_init(&(*db)->iomemcon);
cil_sort_init(&(*db)->ioportcon);
cil_sort_init(&(*db)->pcidevicecon);
cil_sort_init(&(*db)->devicetreecon);
cil_sort_init(&(*db)->fsuse);
cil_list_init(&(*db)->userprefixes, CIL_LIST_ITEM);
cil_list_init(&(*db)->selinuxusers, CIL_LIST_ITEM);
cil_list_init(&(*db)->declared_strings, CIL_LIST_ITEM);
cil_type_init(&(*db)->selftype);
(*db)->selftype->datum.name = CIL_KEY_SELF;
(*db)->selftype->datum.fqn = CIL_KEY_SELF;
cil_type_init(&(*db)->notselftype);
(*db)->notselftype->datum.name = CIL_KEY_NOTSELF;
(*db)->notselftype->datum.fqn = CIL_KEY_NOTSELF;
cil_type_init(&(*db)->othertype);
(*db)->othertype->datum.name = CIL_KEY_OTHER;
(*db)->othertype->datum.fqn = CIL_KEY_OTHER;
(*db)->num_types_and_attrs = 0;
(*db)->num_classes = 0;
(*db)->num_types = 0;
(*db)->num_roles = 0;
(*db)->num_users = 0;
(*db)->num_cats = 0;
(*db)->val_to_type = NULL;
(*db)->val_to_role = NULL;
(*db)->val_to_user = NULL;
(*db)->disable_dontaudit = CIL_FALSE;
(*db)->disable_neverallow = CIL_FALSE;
(*db)->attrs_expand_generated = CIL_FALSE;
(*db)->attrs_expand_size = 1;
(*db)->preserve_tunables = CIL_FALSE;
(*db)->handle_unknown = -1;
(*db)->mls = -1;
(*db)->multiple_decls = CIL_FALSE;
(*db)->qualified_names = CIL_FALSE;
(*db)->target_platform = SEPOL_TARGET_SELINUX;
(*db)->policy_version = POLICYDB_VERSION_MAX;
}
static void cil_declared_strings_list_destroy(struct cil_list **strings)
{
struct cil_list_item *i;
cil_list_for_each(i, *strings) {
struct cil_symtab_datum *d = i->data;
cil_symtab_datum_destroy(d);
free(d);
}
cil_list_destroy(strings, CIL_FALSE);
}
void cil_db_destroy(struct cil_db **db)
{
if (db == NULL || *db == NULL) {
return;
}
cil_tree_destroy(&(*db)->parse);
cil_tree_destroy(&(*db)->ast);
cil_list_destroy(&(*db)->sidorder, CIL_FALSE);
cil_list_destroy(&(*db)->classorder, CIL_FALSE);
cil_list_destroy(&(*db)->catorder, CIL_FALSE);
cil_list_destroy(&(*db)->sensitivityorder, CIL_FALSE);
cil_sort_destroy(&(*db)->netifcon);
cil_sort_destroy(&(*db)->genfscon);
cil_sort_destroy(&(*db)->filecon);
cil_sort_destroy(&(*db)->nodecon);
cil_sort_destroy(&(*db)->ibpkeycon);
cil_sort_destroy(&(*db)->ibendportcon);
cil_sort_destroy(&(*db)->portcon);
cil_sort_destroy(&(*db)->pirqcon);
cil_sort_destroy(&(*db)->iomemcon);
cil_sort_destroy(&(*db)->ioportcon);
cil_sort_destroy(&(*db)->pcidevicecon);
cil_sort_destroy(&(*db)->devicetreecon);
cil_sort_destroy(&(*db)->fsuse);
cil_list_destroy(&(*db)->userprefixes, CIL_FALSE);
cil_list_destroy(&(*db)->selinuxusers, CIL_FALSE);
cil_declared_strings_list_destroy(&(*db)->declared_strings);
cil_destroy_type((*db)->selftype);
cil_destroy_type((*db)->notselftype);
cil_destroy_type((*db)->othertype);
cil_strpool_destroy();
free((*db)->val_to_type);
free((*db)->val_to_role);
free((*db)->val_to_user);
free(*db);
*db = NULL;
}
void cil_root_init(struct cil_root **root)
{
struct cil_root *r = cil_malloc(sizeof(*r));
cil_symtab_array_init(r->symtab, cil_sym_sizes[CIL_SYM_ARRAY_ROOT]);
*root = r;
}
void cil_root_destroy(struct cil_root *root)
{
if (root == NULL) {
return;
}
cil_symtab_array_destroy(root->symtab);
free(root);
}
int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size)
{
char *buffer = NULL;
int rc;
cil_log(CIL_INFO, "Parsing %s\n", name);
buffer = cil_malloc(size + 2);
memcpy(buffer, data, size);
memset(buffer + size, 0, 2);
rc = cil_parser(name, buffer, size + 2, &db->parse);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to parse %s\n", name);
goto exit;
}
free(buffer);
buffer = NULL;
rc = SEPOL_OK;
exit:
free(buffer);
return rc;
}
int cil_compile(struct cil_db *db)
{
int rc = SEPOL_ERR;
if (db == NULL) {
goto exit;
}
cil_log(CIL_INFO, "Building AST from Parse Tree\n");
rc = cil_build_ast(db, db->parse->root, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to build AST\n");
goto exit;
}
cil_log(CIL_INFO, "Destroying Parse Tree\n");
cil_tree_destroy(&db->parse);
cil_log(CIL_INFO, "Resolving AST\n");
rc = cil_resolve_ast(db, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve AST\n");
goto exit;
}
cil_log(CIL_INFO, "Qualifying Names\n");
rc = cil_fqn_qualify(db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to qualify names\n");
goto exit;
}
cil_log(CIL_INFO, "Compile post process\n");
rc = cil_post_process(db);
if (rc != SEPOL_OK ) {
cil_log(CIL_ERR, "Post process failed\n");
goto exit;
}
exit:
return rc;
}
int cil_write_parse_ast(FILE *out, cil_db_t *db)
{
int rc = SEPOL_ERR;
if (db == NULL) {
goto exit;
}
cil_log(CIL_INFO, "Writing Parse AST\n");
rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_PARSE, db->parse->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to write parse ast\n");
goto exit;
}
exit:
return rc;
}
int cil_write_build_ast(FILE *out, cil_db_t *db)
{
int rc = SEPOL_ERR;
if (db == NULL) {
goto exit;
}
cil_log(CIL_INFO, "Building AST from Parse Tree\n");
rc = cil_build_ast(db, db->parse->root, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to build ast\n");
goto exit;
}
cil_log(CIL_INFO, "Destroying Parse Tree\n");
cil_tree_destroy(&db->parse);
cil_log(CIL_INFO, "Writing Build AST\n");
rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_BUILD, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to write build ast\n");
goto exit;
}
exit:
return rc;
}
int cil_write_resolve_ast(FILE *out, cil_db_t *db)
{
int rc = SEPOL_ERR;
if (db == NULL) {
goto exit;
}
cil_log(CIL_INFO, "Building AST from Parse Tree\n");
rc = cil_build_ast(db, db->parse->root, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to build ast\n");
goto exit;
}
cil_log(CIL_INFO, "Destroying Parse Tree\n");
cil_tree_destroy(&db->parse);
cil_log(CIL_INFO, "Resolving AST\n");
rc = cil_resolve_ast(db, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve ast\n");
goto exit;
}
cil_log(CIL_INFO, "Qualifying Names\n");
rc = cil_fqn_qualify(db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to qualify names\n");
goto exit;
}
cil_log(CIL_INFO, "Writing Resolve AST\n");
rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_RESOLVE, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to write resolve ast\n");
goto exit;
}
exit:
return rc;
}
int cil_write_post_ast(FILE *out, cil_db_t *db)
{
int rc = SEPOL_ERR;
if (db == NULL) {
goto exit;
}
cil_log(CIL_INFO, "Building AST from Parse Tree\n");
rc = cil_build_ast(db, db->parse->root, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to build ast\n");
goto exit;
}
cil_log(CIL_INFO, "Destroying Parse Tree\n");
cil_tree_destroy(&db->parse);
cil_log(CIL_INFO, "Resolving AST\n");
rc = cil_resolve_ast(db, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve ast\n");
goto exit;
}
cil_log(CIL_INFO, "Qualifying Names\n");
rc = cil_fqn_qualify(db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to qualify names\n");
goto exit;
}
cil_log(CIL_INFO, "Compile post process\n");
rc = cil_post_process(db);
if (rc != SEPOL_OK ) {
cil_log(CIL_ERR, "Post process failed\n");
goto exit;
}
cil_log(CIL_INFO, "Writing Post AST\n");
rc = cil_write_ast(out, CIL_WRITE_AST_PHASE_POST, db->ast->root);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to write post ast\n");
goto exit;
}
exit:
return rc;
}
int cil_build_policydb(cil_db_t *db, sepol_policydb_t **sepol_db)
{
int rc;
cil_log(CIL_INFO, "Building policy binary\n");
rc = cil_binary_create(db, sepol_db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to generate binary\n");
goto exit;
}
exit:
return rc;
}
void cil_write_policy_conf(FILE *out, struct cil_db *db)
{
cil_log(CIL_INFO, "Writing policy.conf file\n");
cil_gen_policy(out, db);
}
void cil_destroy_data(void **data, enum cil_flavor flavor)
{
if (*data == NULL) {
return;
}
switch(flavor) {
case CIL_NONE:
break;
case CIL_ROOT:
cil_root_destroy(*data);
break;
case CIL_NODE:
break;
case CIL_STRING:
break;
case CIL_DATUM:
break;
case CIL_LIST:
cil_list_destroy(*data, CIL_FALSE);
break;
case CIL_LIST_ITEM:
break;
case CIL_PARAM:
cil_destroy_param(*data);
break;
case CIL_ARGS:
cil_destroy_args(*data);
break;
case CIL_BLOCK:
cil_destroy_block(*data);
break;
case CIL_BLOCKINHERIT:
cil_destroy_blockinherit(*data);
break;
case CIL_BLOCKABSTRACT:
cil_destroy_blockabstract(*data);
break;
case CIL_IN:
cil_destroy_in(*data);
break;
case CIL_MACRO:
cil_destroy_macro(*data);
break;
case CIL_CALL:
cil_destroy_call(*data);
break;
case CIL_OPTIONAL:
cil_destroy_optional(*data);
break;
case CIL_BOOL:
cil_destroy_bool(*data);
break;
case CIL_BOOLEANIF:
cil_destroy_boolif(*data);
break;
case CIL_TUNABLE:
cil_destroy_tunable(*data);
break;
case CIL_TUNABLEIF:
cil_destroy_tunif(*data);
break;
case CIL_CONDBLOCK:
cil_destroy_condblock(*data);
break;
case CIL_CONDTRUE:
break;
case CIL_CONDFALSE:
break;
case CIL_PERM:
case CIL_MAP_PERM:
cil_destroy_perm(*data);
break;
case CIL_COMMON:
case CIL_CLASS:
case CIL_MAP_CLASS:
cil_destroy_class(*data);
break;
case CIL_CLASSORDER:
cil_destroy_ordered(*data);
break;
case CIL_CLASSPERMISSION:
cil_destroy_classpermission(*data);
break;
case CIL_CLASSCOMMON:
cil_destroy_classcommon(*data);
break;
case CIL_CLASSMAPPING:
cil_destroy_classmapping(*data);
break;
case CIL_CLASSPERMS:
cil_destroy_classperms(*data);
break;
case CIL_CLASSPERMS_SET:
cil_destroy_classperms_set(*data);
break;
case CIL_CLASSPERMISSIONSET:
cil_destroy_classpermissionset(*data);
break;
case CIL_USER:
cil_destroy_user(*data);
break;
case CIL_USERATTRIBUTE:
cil_destroy_userattribute(*data);
break;
case CIL_USERATTRIBUTESET:
cil_destroy_userattributeset(*data);
break;
case CIL_USERPREFIX:
cil_destroy_userprefix(*data);
break;
case CIL_USERROLE:
cil_destroy_userrole(*data);
break;
case CIL_USERLEVEL:
cil_destroy_userlevel(*data);
break;
case CIL_USERRANGE:
cil_destroy_userrange(*data);
break;
case CIL_USERBOUNDS:
cil_destroy_bounds(*data);
break;
case CIL_SELINUXUSER:
case CIL_SELINUXUSERDEFAULT:
cil_destroy_selinuxuser(*data);
break;
case CIL_ROLE:
cil_destroy_role(*data);
break;
case CIL_ROLEATTRIBUTE:
cil_destroy_roleattribute(*data);
break;
case CIL_ROLEATTRIBUTESET:
cil_destroy_roleattributeset(*data);
break;
case CIL_ROLETYPE:
cil_destroy_roletype(*data);
break;
case CIL_ROLEBOUNDS:
cil_destroy_bounds(*data);
break;
case CIL_TYPE:
cil_destroy_type(*data);
break;
case CIL_TYPEATTRIBUTE:
cil_destroy_typeattribute(*data);
break;
case CIL_TYPEALIAS:
cil_destroy_alias(*data);
break;
case CIL_TYPEATTRIBUTESET:
cil_destroy_typeattributeset(*data);
break;
case CIL_EXPANDTYPEATTRIBUTE:
cil_destroy_expandtypeattribute(*data);
break;
case CIL_TYPEALIASACTUAL:
cil_destroy_aliasactual(*data);
break;
case CIL_TYPEBOUNDS:
cil_destroy_bounds(*data);
break;
case CIL_TYPEPERMISSIVE:
cil_destroy_typepermissive(*data);
break;
case CIL_SENS:
cil_destroy_sensitivity(*data);
break;
case CIL_SENSALIAS:
cil_destroy_alias(*data);
break;
case CIL_SENSALIASACTUAL:
cil_destroy_aliasactual(*data);
break;
case CIL_SENSITIVITYORDER:
cil_destroy_ordered(*data);
break;
case CIL_SENSCAT:
cil_destroy_senscat(*data);
break;
case CIL_CAT:
cil_destroy_category(*data);
break;
case CIL_CATSET:
cil_destroy_catset(*data);
break;
case CIL_CATALIAS:
cil_destroy_alias(*data);
break;
case CIL_CATALIASACTUAL:
cil_destroy_aliasactual(*data);
break;
case CIL_CATORDER:
cil_destroy_ordered(*data);
break;
case CIL_LEVEL:
cil_destroy_level(*data);
break;
case CIL_LEVELRANGE:
cil_destroy_levelrange(*data);
break;
case CIL_SID:
cil_destroy_sid(*data);
break;
case CIL_SIDORDER:
cil_destroy_ordered(*data);
break;
case CIL_ROLEALLOW:
cil_destroy_roleallow(*data);
break;
case CIL_AVRULE:
case CIL_AVRULEX:
cil_destroy_avrule(*data);
break;
case CIL_PERMISSIONX:
cil_destroy_permissionx(*data);
break;
case CIL_DENY_RULE:
cil_destroy_deny_rule(*data);
break;
case CIL_ROLETRANSITION:
cil_destroy_roletransition(*data);
break;
case CIL_TYPE_RULE:
cil_destroy_type_rule(*data);
break;
case CIL_NAMETYPETRANSITION:
cil_destroy_typetransition(*data);
break;
case CIL_RANGETRANSITION:
cil_destroy_rangetransition(*data);
break;
case CIL_CONSTRAIN:
cil_destroy_constrain(*data);
break;
case CIL_MLSCONSTRAIN:
cil_destroy_constrain(*data);
break;
case CIL_VALIDATETRANS:
case CIL_MLSVALIDATETRANS:
cil_destroy_validatetrans(*data);
break;
case CIL_CONTEXT:
cil_destroy_context(*data);
break;
case CIL_IPADDR:
cil_destroy_ipaddr(*data);
break;
case CIL_DECLARED_STRING:
break;
case CIL_SIDCONTEXT:
cil_destroy_sidcontext(*data);
break;
case CIL_FSUSE:
cil_destroy_fsuse(*data);
break;
case CIL_FILECON:
cil_destroy_filecon(*data);
break;
case CIL_IBPKEYCON:
cil_destroy_ibpkeycon(*data);
break;
case CIL_PORTCON:
cil_destroy_portcon(*data);
break;
case CIL_IBENDPORTCON:
cil_destroy_ibendportcon(*data);
break;
case CIL_NODECON:
cil_destroy_nodecon(*data);
break;
case CIL_GENFSCON:
cil_destroy_genfscon(*data);
break;
case CIL_NETIFCON:
cil_destroy_netifcon(*data);
break;
case CIL_PIRQCON:
cil_destroy_pirqcon(*data);
break;
case CIL_IOMEMCON:
cil_destroy_iomemcon(*data);
break;
case CIL_IOPORTCON:
cil_destroy_ioportcon(*data);
break;
case CIL_PCIDEVICECON:
cil_destroy_pcidevicecon(*data);
break;
case CIL_DEVICETREECON:
cil_destroy_devicetreecon(*data);
break;
case CIL_POLICYCAP:
cil_destroy_policycap(*data);
break;
case CIL_DEFAULTUSER:
case CIL_DEFAULTROLE:
case CIL_DEFAULTTYPE:
cil_destroy_default(*data);
break;
case CIL_DEFAULTRANGE:
cil_destroy_defaultrange(*data);
break;
case CIL_HANDLEUNKNOWN:
cil_destroy_handleunknown(*data);
break;
case CIL_MLS:
cil_destroy_mls(*data);
break;
case CIL_SRC_INFO:
cil_destroy_src_info(*data);
break;
case CIL_OP:
case CIL_CONS_OPERAND:
break;
default:
cil_log(CIL_INFO, "Unknown data flavor: %d\n", flavor);
break;
}
*data = NULL;
}
int cil_flavor_to_symtab_index(enum cil_flavor flavor, enum cil_sym_index *sym_index)
{
if (flavor < CIL_MIN_DECLARATIVE) {
return SEPOL_ERR;
}
switch(flavor) {
case CIL_BLOCK:
*sym_index = CIL_SYM_BLOCKS;
break;
case CIL_MACRO:
*sym_index = CIL_SYM_BLOCKS;
break;
case CIL_OPTIONAL:
*sym_index = CIL_SYM_BLOCKS;
break;
case CIL_BOOL:
*sym_index = CIL_SYM_BOOLS;
break;
case CIL_TUNABLE:
*sym_index = CIL_SYM_TUNABLES;
break;
case CIL_PERM:
case CIL_MAP_PERM:
*sym_index = CIL_SYM_PERMS;
break;
case CIL_COMMON:
*sym_index = CIL_SYM_COMMONS;
break;
case CIL_CLASS:
case CIL_MAP_CLASS:
*sym_index = CIL_SYM_CLASSES;
break;
case CIL_CLASSPERMISSION:
case CIL_CLASSPERMISSIONSET:
*sym_index = CIL_SYM_CLASSPERMSETS;
break;
case CIL_USER:
case CIL_USERATTRIBUTE:
*sym_index = CIL_SYM_USERS;
break;
case CIL_ROLE:
case CIL_ROLEATTRIBUTE:
*sym_index = CIL_SYM_ROLES;
break;
case CIL_TYPE:
case CIL_TYPEALIAS:
case CIL_TYPEATTRIBUTE:
*sym_index = CIL_SYM_TYPES;
break;
case CIL_SENS:
case CIL_SENSALIAS:
*sym_index = CIL_SYM_SENS;
break;
case CIL_CAT:
case CIL_CATSET:
case CIL_CATALIAS:
*sym_index = CIL_SYM_CATS;
break;
case CIL_LEVEL:
*sym_index = CIL_SYM_LEVELS;
break;
case CIL_LEVELRANGE:
*sym_index = CIL_SYM_LEVELRANGES;
break;
case CIL_SID:
*sym_index = CIL_SYM_SIDS;
break;
case CIL_DECLARED_STRING:
*sym_index = CIL_SYM_STRINGS;
break;
case CIL_CONTEXT:
*sym_index = CIL_SYM_CONTEXTS;
break;
case CIL_IPADDR:
*sym_index = CIL_SYM_IPADDRS;
break;
case CIL_POLICYCAP:
*sym_index = CIL_SYM_POLICYCAPS;
break;
case CIL_PERMISSIONX:
*sym_index = CIL_SYM_PERMX;
break;
default:
*sym_index = CIL_SYM_UNKNOWN;
cil_log(CIL_INFO, "Failed to find flavor: %d\n", flavor);
return SEPOL_ERR;
}
return SEPOL_OK;
}
const char * cil_node_to_string(struct cil_tree_node *node)
{
switch (node->flavor) {
case CIL_NONE:
return "";
case CIL_ROOT:
return CIL_KEY_ROOT;
case CIL_NODE:
return CIL_KEY_NODE;
case CIL_STRING:
return CIL_KEY_STRING;
case CIL_DATUM:
return "";
case CIL_LIST:
return "";
case CIL_LIST_ITEM:
return "";
case CIL_PARAM:
return "";
case CIL_ARGS:
return "";
case CIL_BLOCK:
return CIL_KEY_BLOCK;
case CIL_BLOCKINHERIT:
return CIL_KEY_BLOCKINHERIT;
case CIL_BLOCKABSTRACT:
return CIL_KEY_BLOCKABSTRACT;
case CIL_IN:
return CIL_KEY_IN;
case CIL_MACRO:
return CIL_KEY_MACRO;
case CIL_CALL:
return CIL_KEY_CALL;
case CIL_OPTIONAL:
return CIL_KEY_OPTIONAL;
case CIL_BOOL:
return CIL_KEY_BOOL;
case CIL_BOOLEANIF:
return CIL_KEY_BOOLEANIF;
case CIL_TUNABLE:
return CIL_KEY_TUNABLE;
case CIL_TUNABLEIF:
return CIL_KEY_TUNABLEIF;
case CIL_CONDBLOCK:
switch (((struct cil_condblock*)node->data)->flavor) {
case CIL_CONDTRUE:
return CIL_KEY_CONDTRUE;
case CIL_CONDFALSE:
return CIL_KEY_CONDFALSE;
default:
break;
}
break;
case CIL_CONDTRUE:
return CIL_KEY_CONDTRUE;
case CIL_CONDFALSE:
return CIL_KEY_CONDFALSE;
case CIL_PERM:
return CIL_KEY_PERM;
case CIL_COMMON:
return CIL_KEY_COMMON;
case CIL_CLASS:
return CIL_KEY_CLASS;
case CIL_CLASSORDER:
return CIL_KEY_CLASSORDER;
case CIL_MAP_CLASS:
return CIL_KEY_MAP_CLASS;
case CIL_CLASSPERMISSION:
return CIL_KEY_CLASSPERMISSION;
case CIL_CLASSCOMMON:
return CIL_KEY_CLASSCOMMON;
case CIL_CLASSMAPPING:
return CIL_KEY_CLASSMAPPING;
case CIL_CLASSPERMISSIONSET:
return CIL_KEY_CLASSPERMISSIONSET;
case CIL_USER:
return CIL_KEY_USER;
case CIL_USERATTRIBUTE:
return CIL_KEY_USERATTRIBUTE;
case CIL_USERATTRIBUTESET:
return CIL_KEY_USERATTRIBUTESET;
case CIL_USERPREFIX:
return CIL_KEY_USERPREFIX;
case CIL_USERROLE:
return CIL_KEY_USERROLE;
case CIL_USERLEVEL:
return CIL_KEY_USERLEVEL;
case CIL_USERRANGE:
return CIL_KEY_USERRANGE;
case CIL_USERBOUNDS:
return CIL_KEY_USERBOUNDS;
case CIL_SELINUXUSER:
return CIL_KEY_SELINUXUSER;
case CIL_SELINUXUSERDEFAULT:
return CIL_KEY_SELINUXUSERDEFAULT;
case CIL_ROLE:
return CIL_KEY_ROLE;
case CIL_ROLEATTRIBUTE:
return CIL_KEY_ROLEATTRIBUTE;
case CIL_ROLEATTRIBUTESET:
return CIL_KEY_ROLEATTRIBUTESET;
case CIL_ROLETYPE:
return CIL_KEY_ROLETYPE;
case CIL_ROLEBOUNDS:
return CIL_KEY_ROLEBOUNDS;
case CIL_TYPE:
return CIL_KEY_TYPE;
case CIL_TYPEATTRIBUTE:
return CIL_KEY_TYPEATTRIBUTE;
case CIL_TYPEALIAS:
return CIL_KEY_TYPEALIAS;
case CIL_TYPEATTRIBUTESET:
return CIL_KEY_TYPEATTRIBUTESET;
case CIL_EXPANDTYPEATTRIBUTE:
return CIL_KEY_EXPANDTYPEATTRIBUTE;
case CIL_TYPEALIASACTUAL:
return CIL_KEY_TYPEALIASACTUAL;
case CIL_TYPEBOUNDS:
return CIL_KEY_TYPEBOUNDS;
case CIL_TYPEPERMISSIVE:
return CIL_KEY_TYPEPERMISSIVE;
case CIL_SENS:
return CIL_KEY_SENSITIVITY;
case CIL_SENSALIAS:
return CIL_KEY_SENSALIAS;
case CIL_SENSALIASACTUAL:
return CIL_KEY_SENSALIASACTUAL;
case CIL_SENSITIVITYORDER:
return CIL_KEY_SENSITIVITYORDER;
case CIL_SENSCAT:
return CIL_KEY_SENSCAT;
case CIL_CAT:
return CIL_KEY_CATEGORY;
case CIL_CATSET:
return CIL_KEY_CATSET;
case CIL_CATALIAS:
return CIL_KEY_CATALIAS;
case CIL_CATALIASACTUAL:
return CIL_KEY_CATALIASACTUAL;
case CIL_CATORDER:
return CIL_KEY_CATORDER;
case CIL_LEVEL:
return CIL_KEY_LEVEL;
case CIL_LEVELRANGE:
return CIL_KEY_LEVELRANGE;
case CIL_SID:
return CIL_KEY_SID;
case CIL_SIDORDER:
return CIL_KEY_SIDORDER;
case CIL_ROLEALLOW:
return CIL_KEY_ROLEALLOW;
case CIL_AVRULE:
switch (((struct cil_avrule *)node->data)->rule_kind) {
case CIL_AVRULE_ALLOWED:
return CIL_KEY_ALLOW;
case CIL_AVRULE_AUDITALLOW:
return CIL_KEY_AUDITALLOW;
case CIL_AVRULE_DONTAUDIT:
return CIL_KEY_DONTAUDIT;
case CIL_AVRULE_NEVERALLOW:
return CIL_KEY_NEVERALLOW;
default:
break;
}
break;
case CIL_AVRULEX:
switch (((struct cil_avrule *)node->data)->rule_kind) {
case CIL_AVRULE_ALLOWED:
return CIL_KEY_ALLOWX;
case CIL_AVRULE_AUDITALLOW:
return CIL_KEY_AUDITALLOWX;
case CIL_AVRULE_DONTAUDIT:
return CIL_KEY_DONTAUDITX;
case CIL_AVRULE_NEVERALLOW:
return CIL_KEY_NEVERALLOWX;
default:
break;
}
break;
case CIL_PERMISSIONX:
return CIL_KEY_PERMISSIONX;
case CIL_DENY_RULE:
return CIL_KEY_DENY_RULE;
case CIL_ROLETRANSITION:
return CIL_KEY_ROLETRANSITION;
case CIL_TYPE_RULE:
switch (((struct cil_type_rule *)node->data)->rule_kind) {
case CIL_TYPE_TRANSITION:
return CIL_KEY_TYPETRANSITION;
case CIL_TYPE_MEMBER:
return CIL_KEY_TYPEMEMBER;
case CIL_TYPE_CHANGE:
return CIL_KEY_TYPECHANGE;
default:
break;
}
break;
case CIL_NAMETYPETRANSITION:
return CIL_KEY_TYPETRANSITION;
case CIL_RANGETRANSITION:
return CIL_KEY_RANGETRANSITION;
case CIL_CONSTRAIN:
return CIL_KEY_CONSTRAIN;
case CIL_MLSCONSTRAIN:
return CIL_KEY_MLSCONSTRAIN;
case CIL_VALIDATETRANS:
return CIL_KEY_VALIDATETRANS;
case CIL_MLSVALIDATETRANS:
return CIL_KEY_MLSVALIDATETRANS;
case CIL_CONTEXT:
return CIL_KEY_CONTEXT;
case CIL_IPADDR:
return CIL_KEY_IPADDR;
case CIL_SIDCONTEXT:
return CIL_KEY_SIDCONTEXT;
case CIL_FSUSE:
return CIL_KEY_FSUSE;
case CIL_FILECON:
return CIL_KEY_FILECON;
case CIL_IBPKEYCON:
return CIL_KEY_IBPKEYCON;
case CIL_IBENDPORTCON:
return CIL_KEY_IBENDPORTCON;
case CIL_PORTCON:
return CIL_KEY_PORTCON;
case CIL_NODECON:
return CIL_KEY_NODECON;
case CIL_GENFSCON:
return CIL_KEY_GENFSCON;
case CIL_NETIFCON:
return CIL_KEY_NETIFCON;
case CIL_PIRQCON:
return CIL_KEY_PIRQCON;
case CIL_IOMEMCON:
return CIL_KEY_IOMEMCON;
case CIL_IOPORTCON:
return CIL_KEY_IOPORTCON;
case CIL_PCIDEVICECON:
return CIL_KEY_PCIDEVICECON;
case CIL_DEVICETREECON:
return CIL_KEY_DEVICETREECON;
case CIL_POLICYCAP:
return CIL_KEY_POLICYCAP;
case CIL_DEFAULTUSER:
return CIL_KEY_DEFAULTUSER;
case CIL_DEFAULTROLE:
return CIL_KEY_DEFAULTROLE;
case CIL_DEFAULTTYPE:
return CIL_KEY_DEFAULTTYPE;
case CIL_DEFAULTRANGE:
return CIL_KEY_DEFAULTRANGE;
case CIL_HANDLEUNKNOWN:
return CIL_KEY_HANDLEUNKNOWN;
case CIL_MLS:
return CIL_KEY_MLS;
case CIL_SRC_INFO:
return CIL_KEY_SRC_INFO;
case CIL_ALL:
return CIL_KEY_ALL;
case CIL_RANGE:
return CIL_KEY_RANGE;
case CIL_AND:
return CIL_KEY_AND;
case CIL_OR:
return CIL_KEY_OR;
case CIL_XOR:
return CIL_KEY_XOR;
case CIL_NOT:
return CIL_KEY_NOT;
case CIL_EQ:
return CIL_KEY_EQ;
case CIL_NEQ:
return CIL_KEY_NEQ;
case CIL_CONS_DOM:
return CIL_KEY_CONS_DOM;
case CIL_CONS_DOMBY:
return CIL_KEY_CONS_DOMBY;
case CIL_CONS_INCOMP:
return CIL_KEY_CONS_INCOMP;
case CIL_CONS_U1:
return CIL_KEY_CONS_U1;
case CIL_CONS_U2:
return CIL_KEY_CONS_U2;
case CIL_CONS_U3:
return CIL_KEY_CONS_U3;
case CIL_CONS_T1:
return CIL_KEY_CONS_T1;
case CIL_CONS_T2:
return CIL_KEY_CONS_T2;
case CIL_CONS_T3:
return CIL_KEY_CONS_T3;
case CIL_CONS_R1:
return CIL_KEY_CONS_R1;
case CIL_CONS_R2:
return CIL_KEY_CONS_R2;
case CIL_CONS_R3:
return CIL_KEY_CONS_R3;
case CIL_CONS_L1:
return CIL_KEY_CONS_L1;
case CIL_CONS_L2:
return CIL_KEY_CONS_L2;
case CIL_CONS_H1:
return CIL_KEY_CONS_H1;
case CIL_CONS_H2:
return CIL_KEY_CONS_H2;
default:
break;
}
return "";
}
int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size)
{
int rc = SEPOL_ERR;
size_t str_len = 0;
int buf_pos = 0;
char *str_tmp = NULL;
struct cil_list_item *curr;
struct cil_userprefix *userprefix = NULL;
struct cil_user *user = NULL;
*out = NULL;
if (db->userprefixes->head == NULL) {
rc = SEPOL_OK;
*size = 0;
goto exit;
}
cil_list_for_each(curr, db->userprefixes) {
userprefix = curr->data;
user = userprefix->user;
str_len += strlen("user ") + strlen(user->datum.fqn) + strlen(" prefix ") + strlen(userprefix->prefix_str) + 2;
}
*size = str_len * sizeof(char);
str_len++;
str_tmp = cil_malloc(str_len * sizeof(char));
*out = str_tmp;
cil_list_for_each(curr, db->userprefixes) {
userprefix = curr->data;
user = userprefix->user;
buf_pos = snprintf(str_tmp, str_len, "user %s prefix %s;\n", user->datum.fqn,
userprefix->prefix_str);
if (buf_pos < 0) {
free(str_tmp);
*size = 0;
*out = NULL;
goto exit;
}
str_len -= buf_pos;
str_tmp += buf_pos;
}
rc = SEPOL_OK;
exit:
return rc;
}
static int cil_cats_to_ebitmap(struct cil_cats *cats, struct ebitmap* cats_ebitmap)
{
int rc = SEPOL_ERR;
struct cil_list_item *i;
struct cil_list_item *j;
struct cil_cat* cat;
struct cil_catset *cs;
struct cil_tree_node *node;
if (cats == NULL) {
rc = SEPOL_OK;
goto exit;
}
cil_list_for_each(i, cats->datum_expr) {
node = NODE(i->data);
if (node->flavor == CIL_CATSET) {
cs = (struct cil_catset*)i->data;
cil_list_for_each(j, cs->cats->datum_expr) {
cat = (struct cil_cat*)j->data;
rc = ebitmap_set_bit(cats_ebitmap, cat->value, 1);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
cat = (struct cil_cat*)i->data;
rc = ebitmap_set_bit(cats_ebitmap, cat->value, 1);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_level_equals(struct cil_level *low, struct cil_level *high)
{
int rc;
struct ebitmap elow;
struct ebitmap ehigh;
if (strcmp(low->sens->datum.fqn, high->sens->datum.fqn)) {
rc = 0;
goto exit;
}
ebitmap_init(&elow);
ebitmap_init(&ehigh);
rc = cil_cats_to_ebitmap(low->cats, &elow);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_cats_to_ebitmap(high->cats, &ehigh);
if (rc != SEPOL_OK) {
goto exit;
}
rc = ebitmap_cmp(&elow, &ehigh);
ebitmap_destroy(&elow);
ebitmap_destroy(&ehigh);
exit:
return rc;
}
static int __cil_level_strlen(struct cil_level *lvl)
{
struct cil_list_item *item;
struct cil_cats *cats = lvl->cats;
int str_len = 0;
char *str1 = NULL;
char *str2 = NULL;
int first = -1;
int last = -1;
str_len += strlen(lvl->sens->datum.fqn);
if (cats && cats->datum_expr != NULL) {
str_len++; /* initial ":" */
cil_list_for_each(item, cats->datum_expr) {
struct cil_cat *cat = item->data;
if (first == -1) {
str1 = cat->datum.fqn;
first = cat->value;
last = first;
} else if (cat->value == last + 1) {
last++;
str2 = cat->datum.fqn;
} else {
if (first == last) {
str_len += strlen(str1) + strlen(cat->datum.fqn) + 1;
} else if (last == first + 1) {
str_len += strlen(str1) + strlen(str2) + strlen(cat->datum.fqn) + 2;
} else {
str_len += strlen(str1) + strlen(str2) + strlen(cat->datum.fqn) + 2;
}
first = -1;
last = -1;
if (item->next != NULL) {
str_len++; /* space for "," after */
}
}
}
if (first != -1) {
if (first == last) {
str_len += strlen(str1);
} else if (last == first + 1) {
str_len += strlen(str1) + strlen(str2) + 1;
} else {
str_len += strlen(str1) + strlen(str2) + 1;
}
}
}
return str_len;
}
static int __cil_level_to_string(struct cil_level *lvl, char *out)
{
struct cil_list_item *item;
struct cil_cats *cats = lvl->cats;
int buf_pos = 0;
char *str_tmp = out;
char *str1 = NULL;
char *str2 = NULL;
int first = -1;
int last = -1;
buf_pos = sprintf(str_tmp, "%s", lvl->sens->datum.fqn);
str_tmp += buf_pos;
if (cats && cats->datum_expr != NULL) {
buf_pos = sprintf(str_tmp, ":");
str_tmp += buf_pos;
cil_list_for_each(item, cats->datum_expr) {
struct cil_cat *cat = item->data;
if (first == -1) {
str1 = cat->datum.fqn;
first = cat->value;
last = first;
} else if (cat->value == last + 1) {
last++;
str2 = cat->datum.fqn;
} else {
if (first == last) {
buf_pos = sprintf(str_tmp, "%s,%s", str1, cat->datum.fqn);
str_tmp += buf_pos;
} else if (last == first + 1) {
buf_pos = sprintf(str_tmp, "%s,%s,%s", str1, str2, cat->datum.fqn);
str_tmp += buf_pos;
} else {
buf_pos = sprintf(str_tmp, "%s.%s,%s",str1, str2, cat->datum.fqn);
str_tmp += buf_pos;
}
first = -1;
last = -1;
if (item->next != NULL) {
buf_pos = sprintf(str_tmp, ",");
str_tmp += buf_pos;
}
}
}
if (first != -1) {
if (first == last) {
buf_pos = sprintf(str_tmp, "%s", str1);
str_tmp += buf_pos;
} else if (last == first + 1) {
buf_pos = sprintf(str_tmp, "%s,%s", str1, str2);
str_tmp += buf_pos;
} else {
buf_pos = sprintf(str_tmp, "%s.%s",str1, str2);
str_tmp += buf_pos;
}
}
}
return str_tmp - out;
}
int cil_selinuxusers_to_string(struct cil_db *db, char **out, size_t *size)
{
size_t str_len = 0;
int buf_pos = 0;
char *str_tmp = NULL;
struct cil_list_item *curr;
if (db->selinuxusers->head == NULL) {
*size = 0;
*out = NULL;
return SEPOL_OK;
}
cil_list_for_each(curr, db->selinuxusers) {
struct cil_selinuxuser *selinuxuser = curr->data;
struct cil_user *user = selinuxuser->user;
str_len += strlen(selinuxuser->name_str) + strlen(user->datum.fqn) + 1;
if (db->mls == CIL_TRUE) {
struct cil_levelrange *range = selinuxuser->range;
str_len += __cil_level_strlen(range->low) + __cil_level_strlen(range->high) + 2;
}
str_len++;
}
*size = str_len * sizeof(char);
str_tmp = cil_malloc(*size+1);
*out = str_tmp;
for(curr = db->selinuxusers->head; curr != NULL; curr = curr->next) {
struct cil_selinuxuser *selinuxuser = curr->data;
struct cil_user *user = selinuxuser->user;
buf_pos = sprintf(str_tmp, "%s:%s", selinuxuser->name_str, user->datum.fqn);
str_tmp += buf_pos;
if (db->mls == CIL_TRUE) {
struct cil_levelrange *range = selinuxuser->range;
buf_pos = sprintf(str_tmp, ":");
str_tmp += buf_pos;
buf_pos = __cil_level_to_string(range->low, str_tmp);
str_tmp += buf_pos;
buf_pos = sprintf(str_tmp, "-");
str_tmp += buf_pos;
buf_pos = __cil_level_to_string(range->high, str_tmp);
str_tmp += buf_pos;
}
buf_pos = sprintf(str_tmp, "\n");
str_tmp += buf_pos;
}
return SEPOL_OK;
}
int cil_filecons_to_string(struct cil_db *db, char **out, size_t *size)
{
uint32_t i = 0;
int buf_pos = 0;
size_t str_len = 0;
char *str_tmp = NULL;
struct cil_sort *filecons = db->filecon;
for (i = 0; i < filecons->count; i++) {
struct cil_filecon *filecon = filecons->array[i];
struct cil_context *ctx = filecon->context;
char *path_str = filecon->path ? DATUM(filecon->path)->fqn : filecon->path_str;
str_len += strlen(path_str);
if (filecon->type != CIL_FILECON_ANY) {
/* If a type is specified,
+2 for type string, +1 for tab */
str_len += 3;
}
if (ctx != NULL) {
struct cil_user *user = ctx->user;
struct cil_role *role = ctx->role;
struct cil_type *type = ctx->type;
str_len += (strlen(user->datum.fqn) + strlen(role->datum.fqn) + strlen(type->datum.fqn) + 3);
if (db->mls == CIL_TRUE) {
struct cil_levelrange *range = ctx->range;
if (cil_level_equals(range->low, range->high)) {
str_len += __cil_level_strlen(range->low) + 1;
} else {
str_len += __cil_level_strlen(range->low) + __cil_level_strlen(range->high) + 2;
}
}
} else {
str_len += strlen("\t<>");
}
str_len++;
}
*size = str_len * sizeof(char);
str_tmp = cil_malloc(*size+1);
*out = str_tmp;
for (i = 0; i < filecons->count; i++) {
struct cil_filecon *filecon = filecons->array[i];
struct cil_context *ctx = filecon->context;
const char *str_type = NULL;
char *path_str = filecon->path ? DATUM(filecon->path)->fqn : filecon->path_str;
buf_pos = sprintf(str_tmp, "%s", path_str);
str_tmp += buf_pos;
switch(filecon->type) {
case CIL_FILECON_ANY:
str_type = "";
break;
case CIL_FILECON_FILE:
str_type = "\t--";
break;
case CIL_FILECON_DIR:
str_type = "\t-d";
break;
case CIL_FILECON_CHAR:
str_type = "\t-c";
break;
case CIL_FILECON_BLOCK:
str_type = "\t-b";
break;
case CIL_FILECON_SOCKET:
str_type = "\t-s";
break;
case CIL_FILECON_PIPE:
str_type = "\t-p";
break;
case CIL_FILECON_SYMLINK:
str_type = "\t-l";
break;
default:
str_type = "";
break;
}
buf_pos = sprintf(str_tmp, "%s", str_type);
str_tmp += buf_pos;
if (ctx != NULL) {
struct cil_user *user = ctx->user;
struct cil_role *role = ctx->role;
struct cil_type *type = ctx->type;
buf_pos = sprintf(str_tmp, "\t%s:%s:%s", user->datum.fqn, role->datum.fqn,
type->datum.fqn);
str_tmp += buf_pos;
if (db->mls == CIL_TRUE) {
struct cil_levelrange *range = ctx->range;
buf_pos = sprintf(str_tmp, ":");
str_tmp += buf_pos;
buf_pos = __cil_level_to_string(range->low, str_tmp);
str_tmp += buf_pos;
if (!cil_level_equals(range->low, range->high)) {
buf_pos = sprintf(str_tmp, "-");
str_tmp += buf_pos;
buf_pos = __cil_level_to_string(range->high, str_tmp);
str_tmp += buf_pos;
}
}
} else {
buf_pos = sprintf(str_tmp, "\t<>");
str_tmp += buf_pos;
}
buf_pos = sprintf(str_tmp, "\n");
str_tmp += buf_pos;
}
return SEPOL_OK;
}
void cil_set_disable_dontaudit(struct cil_db *db, int disable_dontaudit)
{
db->disable_dontaudit = disable_dontaudit;
}
void cil_set_disable_neverallow(struct cil_db *db, int disable_neverallow)
{
db->disable_neverallow = disable_neverallow;
}
void cil_set_attrs_expand_generated(struct cil_db *db, int attrs_expand_generated)
{
db->attrs_expand_generated = attrs_expand_generated;
}
void cil_set_attrs_expand_size(struct cil_db *db, unsigned attrs_expand_size)
{
db->attrs_expand_size = attrs_expand_size;
}
void cil_set_preserve_tunables(struct cil_db *db, int preserve_tunables)
{
db->preserve_tunables = preserve_tunables;
}
int cil_set_handle_unknown(struct cil_db *db, int handle_unknown)
{
int rc = 0;
switch (handle_unknown) {
case SEPOL_DENY_UNKNOWN:
case SEPOL_REJECT_UNKNOWN:
case SEPOL_ALLOW_UNKNOWN:
db->handle_unknown = handle_unknown;
break;
default:
cil_log(CIL_ERR, "Unknown value for handle-unknown: %i\n", handle_unknown);
rc = -1;
}
return rc;
}
void cil_set_mls(struct cil_db *db, int mls)
{
db->mls = mls;
}
void cil_set_multiple_decls(struct cil_db *db, int multiple_decls)
{
db->multiple_decls = multiple_decls;
}
void cil_set_qualified_names(struct cil_db *db, int qualified_names)
{
db->qualified_names = qualified_names;
}
void cil_set_target_platform(struct cil_db *db, int target_platform)
{
db->target_platform = target_platform;
}
void cil_set_policy_version(struct cil_db *db, int policy_version)
{
db->policy_version = policy_version;
}
void cil_symtab_array_init(symtab_t symtab[], const int symtab_sizes[CIL_SYM_NUM])
{
uint32_t i = 0;
for (i = 0; i < CIL_SYM_NUM; i++) {
cil_symtab_init(&symtab[i], symtab_sizes[i]);
}
}
void cil_symtab_array_destroy(symtab_t symtab[])
{
int i = 0;
for (i = 0; i < CIL_SYM_NUM; i++) {
cil_symtab_destroy(&symtab[i]);
}
}
void cil_destroy_ast_symtabs(struct cil_tree_node *current)
{
while (current) {
switch (current->flavor) {
case CIL_BLOCK:
cil_symtab_array_destroy(((struct cil_block*)current->data)->symtab);
break;
case CIL_IN:
cil_symtab_array_destroy(((struct cil_in*)current->data)->symtab);
break;
case CIL_CLASS:
case CIL_COMMON:
case CIL_MAP_CLASS:
cil_symtab_destroy(&((struct cil_class*)current->data)->perms);
break;
case CIL_MACRO:
cil_symtab_array_destroy(((struct cil_macro*)current->data)->symtab);
break;
case CIL_CONDBLOCK:
cil_symtab_array_destroy(((struct cil_condblock*)current->data)->symtab);
break;
default:
break;
}
if (current->cl_head) {
cil_destroy_ast_symtabs(current->cl_head);
}
current = current->next;
}
}
int cil_get_symtab(struct cil_tree_node *ast_node, symtab_t **symtab, enum cil_sym_index sym_index)
{
struct cil_tree_node *node = ast_node;
*symtab = NULL;
if (sym_index == CIL_SYM_PERMS) {
/* Class statements are not blocks, so the passed node should be the class */
if (node->flavor == CIL_CLASS || node->flavor == CIL_MAP_CLASS ||
node->flavor == CIL_COMMON) {
*symtab = &((struct cil_class*)node->data)->perms;
return SEPOL_OK;
}
goto exit;
}
if (sym_index < CIL_SYM_BLOCKS || sym_index >= CIL_SYM_NUM) {
cil_log(CIL_ERR, "Invalid symtab type\n");
goto exit;
}
while (node != NULL && *symtab == NULL) {
switch (node->flavor) {
case CIL_ROOT:
*symtab = &((struct cil_root *)node->data)->symtab[sym_index];
break;
case CIL_BLOCK:
*symtab = &((struct cil_block*)node->data)->symtab[sym_index];
break;
case CIL_MACRO:
*symtab = &((struct cil_macro*)node->data)->symtab[sym_index];
break;
case CIL_IN:
/* In blocks only exist before resolving the AST */
*symtab = &((struct cil_in*)node->data)->symtab[sym_index];
break;
case CIL_CONDBLOCK: {
if (node->parent->flavor == CIL_TUNABLEIF) {
/* Cond blocks only exist before resolving the AST */
*symtab = &((struct cil_condblock*)node->data)->symtab[sym_index];
} else if (node->parent->flavor == CIL_BOOLEANIF) {
node = node->parent->parent;
}
break;
}
default:
node = node->parent;
}
}
if (*symtab == NULL) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(ast_node, CIL_ERR, "Failed to get symtab from node");
return SEPOL_ERR;
}
int cil_string_to_uint32(const char *string, uint32_t *value, int base)
{
unsigned long val;
char *end = NULL;
int rc = SEPOL_ERR;
if (string == NULL || value == NULL) {
goto exit;
}
errno = 0;
val = strtoul(string, &end, base);
if (errno != 0 || end == string || *end != '\0') {
rc = SEPOL_ERR;
goto exit;
}
/* Ensure that the value fits a 32-bit integer without triggering -Wtype-limits */
#if ULONG_MAX > UINT32_MAX
if (val > UINT32_MAX) {
rc = SEPOL_ERR;
goto exit;
}
#endif
*value = val;
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to create uint32_t from string\n");
return rc;
}
int cil_string_to_uint64(const char *string, uint64_t *value, int base)
{
char *end = NULL;
int rc = SEPOL_ERR;
if (string == NULL || value == NULL) {
goto exit;
}
errno = 0;
*value = strtoull(string, &end, base);
if (errno != 0 || end == string || *end != '\0') {
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to create uint64_t from string\n");
return rc;
}
void cil_sort_init(struct cil_sort **sort)
{
*sort = cil_malloc(sizeof(**sort));
(*sort)->flavor = CIL_NONE;
(*sort)->count = 0;
(*sort)->index = 0;
(*sort)->array = NULL;
}
void cil_sort_destroy(struct cil_sort **sort)
{
(*sort)->flavor = CIL_NONE;
(*sort)->count = 0;
(*sort)->index = 0;
if ((*sort)->array != NULL) {
free((*sort)->array);
}
(*sort)->array = NULL;
free(*sort);
*sort = NULL;
}
void cil_ordered_init(struct cil_ordered **ordered)
{
*ordered = cil_malloc(sizeof(**ordered));
(*ordered)->merged = CIL_FALSE;
(*ordered)->strs = NULL;
(*ordered)->datums = NULL;
}
void cil_netifcon_init(struct cil_netifcon **netifcon)
{
*netifcon = cil_malloc(sizeof(**netifcon));
(*netifcon)->interface_str = NULL;
(*netifcon)->if_context_str = NULL;
(*netifcon)->if_context = NULL;
(*netifcon)->packet_context_str = NULL;
(*netifcon)->packet_context = NULL;
(*netifcon)->context_str = NULL;
}
void cil_ibendportcon_init(struct cil_ibendportcon **ibendportcon)
{
*ibendportcon = cil_malloc(sizeof(**ibendportcon));
(*ibendportcon)->dev_name_str = NULL;
(*ibendportcon)->port = 0;
(*ibendportcon)->context_str = NULL;
(*ibendportcon)->context = NULL;
}
void cil_context_init(struct cil_context **context)
{
*context = cil_malloc(sizeof(**context));
cil_symtab_datum_init(&(*context)->datum);
(*context)->user_str = NULL;
(*context)->user = NULL;
(*context)->role_str = NULL;
(*context)->role = NULL;
(*context)->type_str = NULL;
(*context)->type = NULL;
(*context)->range_str = NULL;
(*context)->range = NULL;
}
void cil_level_init(struct cil_level **level)
{
*level = cil_malloc(sizeof(**level));
cil_symtab_datum_init(&(*level)->datum);
(*level)->sens_str = NULL;
(*level)->sens = NULL;
(*level)->cats = NULL;
}
void cil_levelrange_init(struct cil_levelrange **range)
{
*range = cil_malloc(sizeof(**range));
cil_symtab_datum_init(&(*range)->datum);
(*range)->low_str = NULL;
(*range)->low = NULL;
(*range)->high_str = NULL;
(*range)->high = NULL;
}
void cil_sens_init(struct cil_sens **sens)
{
*sens = cil_malloc(sizeof(**sens));
cil_symtab_datum_init(&(*sens)->datum);
(*sens)->cats_list = NULL;
(*sens)->ordered = CIL_FALSE;
}
void cil_block_init(struct cil_block **block)
{
*block = cil_malloc(sizeof(**block));
cil_symtab_datum_init(&(*block)->datum);
cil_symtab_array_init((*block)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_BLOCK]);
(*block)->is_abstract = CIL_FALSE;
(*block)->bi_nodes = NULL;
}
void cil_blockinherit_init(struct cil_blockinherit **inherit)
{
*inherit = cil_malloc(sizeof(**inherit));
(*inherit)->block_str = NULL;
(*inherit)->block = NULL;
}
void cil_blockabstract_init(struct cil_blockabstract **abstract)
{
*abstract = cil_malloc(sizeof(**abstract));
(*abstract)->block_str = NULL;
(*abstract)->block = NULL;
}
void cil_in_init(struct cil_in **in)
{
*in = cil_malloc(sizeof(**in));
cil_symtab_array_init((*in)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_IN]);
(*in)->is_after = CIL_FALSE;
(*in)->block_str = NULL;
(*in)->block = NULL;
}
void cil_class_init(struct cil_class **class)
{
*class = cil_malloc(sizeof(**class));
cil_symtab_datum_init(&(*class)->datum);
cil_symtab_init(&(*class)->perms, CIL_CLASS_SYM_SIZE);
(*class)->num_perms = 0;
(*class)->common = NULL;
(*class)->ordered = CIL_FALSE;
}
void cil_classcommon_init(struct cil_classcommon **classcommon)
{
*classcommon = cil_malloc(sizeof(**classcommon));
(*classcommon)->class_str = NULL;
(*classcommon)->class = NULL;
(*classcommon)->common_str = NULL;
(*classcommon)->common = NULL;
}
void cil_sid_init(struct cil_sid **sid)
{
*sid = cil_malloc(sizeof(**sid));
cil_symtab_datum_init(&(*sid)->datum);
(*sid)->ordered = CIL_FALSE;
(*sid)->context = NULL;
}
void cil_sidcontext_init(struct cil_sidcontext **sidcontext)
{
*sidcontext = cil_malloc(sizeof(**sidcontext));
(*sidcontext)->sid_str = NULL;
(*sidcontext)->sid = NULL;
(*sidcontext)->context_str = NULL;
(*sidcontext)->context = NULL;
}
void cil_userrole_init(struct cil_userrole **userrole)
{
*userrole = cil_malloc(sizeof(**userrole));
(*userrole)->user_str = NULL;
(*userrole)->user = NULL;
(*userrole)->role_str = NULL;
(*userrole)->role = NULL;
}
void cil_userprefix_init(struct cil_userprefix **userprefix)
{
*userprefix = cil_malloc(sizeof(**userprefix));
(*userprefix)->user_str = NULL;
(*userprefix)->user = NULL;
(*userprefix)->prefix_str = NULL;
}
void cil_selinuxuser_init(struct cil_selinuxuser **selinuxuser)
{
*selinuxuser = cil_malloc(sizeof(**selinuxuser));
(*selinuxuser)->name_str = NULL;
(*selinuxuser)->user_str = NULL;
(*selinuxuser)->user = NULL;
(*selinuxuser)->range_str = NULL;
(*selinuxuser)->range = NULL;
}
void cil_roletype_init(struct cil_roletype **roletype)
{
*roletype = cil_malloc(sizeof(**roletype));
(*roletype)->role_str = NULL;
(*roletype)->role = NULL;
(*roletype)->type_str = NULL;
(*roletype)->type = NULL;
}
void cil_roleattribute_init(struct cil_roleattribute **attr)
{
*attr = cil_malloc(sizeof(**attr));
cil_symtab_datum_init(&(*attr)->datum);
(*attr)->expr_list = NULL;
(*attr)->roles = NULL;
}
void cil_roleattributeset_init(struct cil_roleattributeset **attrset)
{
*attrset = cil_malloc(sizeof(**attrset));
(*attrset)->attr_str = NULL;
(*attrset)->attr = NULL;
(*attrset)->str_expr = NULL;
(*attrset)->datum_expr = NULL;
}
void cil_typeattribute_init(struct cil_typeattribute **attr)
{
*attr = cil_malloc(sizeof(**attr));
cil_symtab_datum_init(&(*attr)->datum);
(*attr)->expr_list = NULL;
(*attr)->types = NULL;
(*attr)->used = CIL_FALSE;
(*attr)->keep = CIL_FALSE;
}
void cil_typeattributeset_init(struct cil_typeattributeset **attrset)
{
*attrset = cil_malloc(sizeof(**attrset));
(*attrset)->attr_str = NULL;
(*attrset)->attr = NULL;
(*attrset)->str_expr = NULL;
(*attrset)->datum_expr = NULL;
}
void cil_expandtypeattribute_init(struct cil_expandtypeattribute **expandattr)
{
*expandattr = cil_malloc(sizeof(**expandattr));
(*expandattr)->attr_strs = NULL;
(*expandattr)->attr_datums = NULL;
(*expandattr)->expand = 0;
}
void cil_alias_init(struct cil_alias **alias)
{
*alias = cil_malloc(sizeof(**alias));
(*alias)->actual = NULL;
cil_symtab_datum_init(&(*alias)->datum);
}
void cil_aliasactual_init(struct cil_aliasactual **aliasactual)
{
*aliasactual = cil_malloc(sizeof(**aliasactual));
(*aliasactual)->alias_str = NULL;
(*aliasactual)->alias = NULL;
(*aliasactual)->actual_str = NULL;
(*aliasactual)->actual = NULL;
}
void cil_typepermissive_init(struct cil_typepermissive **typeperm)
{
*typeperm = cil_malloc(sizeof(**typeperm));
(*typeperm)->type_str = NULL;
(*typeperm)->type = NULL;
}
void cil_nametypetransition_init(struct cil_nametypetransition **nametypetrans)
{
*nametypetrans = cil_malloc(sizeof(**nametypetrans));
(*nametypetrans)->src_str = NULL;
(*nametypetrans)->src = NULL;
(*nametypetrans)->tgt_str = NULL;
(*nametypetrans)->tgt = NULL;
(*nametypetrans)->obj_str = NULL;
(*nametypetrans)->obj = NULL;
(*nametypetrans)->name_str = NULL;
(*nametypetrans)->name = NULL;
(*nametypetrans)->result_str = NULL;
(*nametypetrans)->result = NULL;
}
void cil_rangetransition_init(struct cil_rangetransition **rangetrans)
{
*rangetrans = cil_malloc(sizeof(**rangetrans));
(*rangetrans)->src_str = NULL;
(*rangetrans)->src = NULL;
(*rangetrans)->exec_str = NULL;
(*rangetrans)->exec = NULL;
(*rangetrans)->obj_str = NULL;
(*rangetrans)->obj = NULL;
(*rangetrans)->range_str = NULL;
(*rangetrans)->range = NULL;
}
void cil_bool_init(struct cil_bool **cilbool)
{
*cilbool = cil_malloc(sizeof(**cilbool));
cil_symtab_datum_init(&(*cilbool)->datum);
(*cilbool)->value = 0;
}
void cil_tunable_init(struct cil_tunable **ciltun)
{
*ciltun = cil_malloc(sizeof(**ciltun));
cil_symtab_datum_init(&(*ciltun)->datum);
(*ciltun)->value = 0;
}
void cil_condblock_init(struct cil_condblock **cb)
{
*cb = cil_malloc(sizeof(**cb));
(*cb)->flavor = CIL_NONE;
cil_symtab_array_init((*cb)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_CONDBLOCK]);
}
void cil_boolif_init(struct cil_booleanif **bif)
{
*bif = cil_malloc(sizeof(**bif));
(*bif)->str_expr = NULL;
(*bif)->datum_expr = NULL;
}
void cil_tunif_init(struct cil_tunableif **tif)
{
*tif = cil_malloc(sizeof(**tif));
(*tif)->str_expr = NULL;
(*tif)->datum_expr = NULL;
}
void cil_avrule_init(struct cil_avrule **avrule)
{
*avrule = cil_malloc(sizeof(**avrule));
(*avrule)->is_extended = 0;
(*avrule)->rule_kind = CIL_NONE;
(*avrule)->src_str = NULL;
(*avrule)->src = NULL;
(*avrule)->tgt_str = NULL;
(*avrule)->tgt = NULL;
memset(&((*avrule)->perms), 0, sizeof((*avrule)->perms));
}
void cil_permissionx_init(struct cil_permissionx **permx)
{
*permx = cil_malloc(sizeof(**permx));
cil_symtab_datum_init(&(*permx)->datum);
(*permx)->kind = CIL_NONE;
(*permx)->obj_str = NULL;
(*permx)->obj = NULL;
(*permx)->expr_str = NULL;
(*permx)->perms = NULL;
}
void cil_deny_rule_init(struct cil_deny_rule **rule)
{
*rule = cil_malloc(sizeof(**rule));
(*rule)->src_str = NULL;
(*rule)->src = NULL;
(*rule)->tgt_str = NULL;
(*rule)->tgt = NULL;
(*rule)->classperms = NULL;
}
void cil_type_rule_init(struct cil_type_rule **type_rule)
{
*type_rule = cil_malloc(sizeof(**type_rule));
(*type_rule)->rule_kind = CIL_NONE;
(*type_rule)->src_str = NULL;
(*type_rule)->src = NULL;
(*type_rule)->tgt_str = NULL;
(*type_rule)->tgt = NULL;
(*type_rule)->obj_str = NULL;
(*type_rule)->obj = NULL;
(*type_rule)->result_str = NULL;
(*type_rule)->result = NULL;
}
void cil_roletransition_init(struct cil_roletransition **role_trans)
{
*role_trans = cil_malloc(sizeof(**role_trans));
(*role_trans)->src_str = NULL;
(*role_trans)->src = NULL;
(*role_trans)->tgt_str = NULL;
(*role_trans)->tgt = NULL;
(*role_trans)->obj_str = NULL;
(*role_trans)->obj = NULL;
(*role_trans)->result_str = NULL;
(*role_trans)->result = NULL;
}
void cil_roleallow_init(struct cil_roleallow **roleallow)
{
*roleallow = cil_malloc(sizeof(**roleallow));
(*roleallow)->src_str = NULL;
(*roleallow)->src = NULL;
(*roleallow)->tgt_str = NULL;
(*roleallow)->tgt = NULL;
}
void cil_catset_init(struct cil_catset **catset)
{
*catset = cil_malloc(sizeof(**catset));
cil_symtab_datum_init(&(*catset)->datum);
(*catset)->cats = NULL;
}
void cil_senscat_init(struct cil_senscat **senscat)
{
*senscat = cil_malloc(sizeof(**senscat));
(*senscat)->sens_str = NULL;
(*senscat)->sens = NULL;
(*senscat)->cats = NULL;
}
void cil_cats_init(struct cil_cats **cats)
{
*cats = cil_malloc(sizeof(**cats));
(*cats)->evaluated = CIL_FALSE;
(*cats)->str_expr = NULL;
(*cats)->datum_expr = NULL;
}
void cil_filecon_init(struct cil_filecon **filecon)
{
*filecon = cil_malloc(sizeof(**filecon));
(*filecon)->path_str = NULL;
(*filecon)->type = CIL_FILECON_ANY;
(*filecon)->context_str = NULL;
(*filecon)->context = NULL;
}
void cil_ibpkeycon_init(struct cil_ibpkeycon **ibpkeycon)
{
*ibpkeycon = cil_malloc(sizeof(**ibpkeycon));
(*ibpkeycon)->subnet_prefix_str = NULL;
(*ibpkeycon)->pkey_low = 0;
(*ibpkeycon)->pkey_high = 0;
(*ibpkeycon)->context_str = NULL;
(*ibpkeycon)->context = NULL;
}
void cil_portcon_init(struct cil_portcon **portcon)
{
*portcon = cil_malloc(sizeof(**portcon));
(*portcon)->proto = 0;
(*portcon)->port_low = 0;
(*portcon)->port_high = 0;
(*portcon)->context_str = NULL;
(*portcon)->context = NULL;
}
void cil_nodecon_init(struct cil_nodecon **nodecon)
{
*nodecon = cil_malloc(sizeof(**nodecon));
(*nodecon)->addr_str = NULL;
(*nodecon)->addr = NULL;
(*nodecon)->mask_str = NULL;
(*nodecon)->mask = NULL;
(*nodecon)->context_str = NULL;
(*nodecon)->context = NULL;
}
void cil_genfscon_init(struct cil_genfscon **genfscon)
{
*genfscon = cil_malloc(sizeof(**genfscon));
(*genfscon)->fs_str = NULL;
(*genfscon)->path_str = NULL;
(*genfscon)->file_type = CIL_FILECON_ANY;
(*genfscon)->context_str = NULL;
(*genfscon)->context = NULL;
}
void cil_pirqcon_init(struct cil_pirqcon **pirqcon)
{
*pirqcon = cil_malloc(sizeof(**pirqcon));
(*pirqcon)->pirq = 0;
(*pirqcon)->context_str = NULL;
(*pirqcon)->context = NULL;
}
void cil_iomemcon_init(struct cil_iomemcon **iomemcon)
{
*iomemcon = cil_malloc(sizeof(**iomemcon));
(*iomemcon)->iomem_low = 0;
(*iomemcon)->iomem_high = 0;
(*iomemcon)->context_str = NULL;
(*iomemcon)->context = NULL;
}
void cil_ioportcon_init(struct cil_ioportcon **ioportcon)
{
*ioportcon = cil_malloc(sizeof(**ioportcon));
(*ioportcon)->context_str = NULL;
(*ioportcon)->context = NULL;
}
void cil_pcidevicecon_init(struct cil_pcidevicecon **pcidevicecon)
{
*pcidevicecon = cil_malloc(sizeof(**pcidevicecon));
(*pcidevicecon)->dev = 0;
(*pcidevicecon)->context_str = NULL;
(*pcidevicecon)->context = NULL;
}
void cil_devicetreecon_init(struct cil_devicetreecon **dtcon)
{
*dtcon = cil_malloc(sizeof(**dtcon));
(*dtcon)->path = NULL;
(*dtcon)->context_str = NULL;
(*dtcon)->context = NULL;
}
void cil_fsuse_init(struct cil_fsuse **fsuse)
{
*fsuse = cil_malloc(sizeof(**fsuse));
(*fsuse)->type = 0;
(*fsuse)->fs_str = NULL;
(*fsuse)->context_str = NULL;
(*fsuse)->context = NULL;
}
void cil_constrain_init(struct cil_constrain **constrain)
{
*constrain = cil_malloc(sizeof(**constrain));
(*constrain)->classperms = NULL;
(*constrain)->str_expr = NULL;
(*constrain)->datum_expr = NULL;
}
void cil_validatetrans_init(struct cil_validatetrans **validtrans)
{
*validtrans = cil_malloc(sizeof(**validtrans));
(*validtrans)->class_str = NULL;
(*validtrans)->class = NULL;
(*validtrans)->str_expr = NULL;
(*validtrans)->datum_expr = NULL;
}
void cil_ipaddr_init(struct cil_ipaddr **ipaddr)
{
*ipaddr = cil_malloc(sizeof(**ipaddr));
cil_symtab_datum_init(&(*ipaddr)->datum);
memset(&(*ipaddr)->ip, 0, sizeof((*ipaddr)->ip));
}
void cil_perm_init(struct cil_perm **perm)
{
*perm = cil_malloc(sizeof(**perm));
cil_symtab_datum_init(&(*perm)->datum);
(*perm)->value = 0;
(*perm)->classperms = NULL;
}
void cil_classpermission_init(struct cil_classpermission **cp)
{
*cp = cil_malloc(sizeof(**cp));
cil_symtab_datum_init(&(*cp)->datum);
(*cp)->classperms = NULL;
}
void cil_classpermissionset_init(struct cil_classpermissionset **cps)
{
*cps = cil_malloc(sizeof(**cps));
(*cps)->set_str = NULL;
(*cps)->set = NULL;
(*cps)->classperms = NULL;
}
void cil_classperms_set_init(struct cil_classperms_set **cp_set)
{
*cp_set = cil_malloc(sizeof(**cp_set));
(*cp_set)->set_str = NULL;
(*cp_set)->set = NULL;
}
void cil_classperms_init(struct cil_classperms **cp)
{
*cp = cil_malloc(sizeof(**cp));
(*cp)->class_str = NULL;
(*cp)->class = NULL;
(*cp)->perm_strs = NULL;
(*cp)->perms = NULL;
}
void cil_classmapping_init(struct cil_classmapping **mapping)
{
*mapping = cil_malloc(sizeof(**mapping));
(*mapping)->map_class_str = NULL;
(*mapping)->map_class = NULL;
(*mapping)->map_perm_str = NULL;
(*mapping)->map_perm = NULL;
(*mapping)->classperms = NULL;
}
void cil_user_init(struct cil_user **user)
{
*user = cil_malloc(sizeof(**user));
cil_symtab_datum_init(&(*user)->datum);
(*user)->bounds = NULL;
(*user)->roles = NULL;
(*user)->dftlevel = NULL;
(*user)->range = NULL;
(*user)->value = 0;
}
void cil_userattribute_init(struct cil_userattribute **attr)
{
*attr = cil_malloc(sizeof(**attr));
cil_symtab_datum_init(&(*attr)->datum);
(*attr)->expr_list = NULL;
(*attr)->users = NULL;
}
void cil_userattributeset_init(struct cil_userattributeset **attrset)
{
*attrset = cil_malloc(sizeof(**attrset));
(*attrset)->attr_str = NULL;
(*attrset)->attr = NULL;
(*attrset)->str_expr = NULL;
(*attrset)->datum_expr = NULL;
}
void cil_userlevel_init(struct cil_userlevel **usrlvl)
{
*usrlvl = cil_malloc(sizeof(**usrlvl));
(*usrlvl)->user_str = NULL;
(*usrlvl)->user = NULL;
(*usrlvl)->level_str = NULL;
(*usrlvl)->level = NULL;
}
void cil_userrange_init(struct cil_userrange **userrange)
{
*userrange = cil_malloc(sizeof(**userrange));
(*userrange)->user_str = NULL;
(*userrange)->user = NULL;
(*userrange)->range_str = NULL;
(*userrange)->range = NULL;
}
void cil_role_init(struct cil_role **role)
{
*role = cil_malloc(sizeof(**role));
cil_symtab_datum_init(&(*role)->datum);
(*role)->bounds = NULL;
(*role)->types = NULL;
(*role)->value = 0;
}
void cil_type_init(struct cil_type **type)
{
*type = cil_malloc(sizeof(**type));
cil_symtab_datum_init(&(*type)->datum);
(*type)->bounds = NULL;
(*type)->value = 0;
}
void cil_cat_init(struct cil_cat **cat)
{
*cat = cil_malloc(sizeof(**cat));
cil_symtab_datum_init(&(*cat)->datum);
(*cat)->ordered = CIL_FALSE;
(*cat)->value = 0;
}
void cil_args_init(struct cil_args **args)
{
*args = cil_malloc(sizeof(**args));
(*args)->arg_str = NULL;
(*args)->arg = NULL;
(*args)->param_str = NULL;
(*args)->flavor = CIL_NONE;
}
void cil_call_init(struct cil_call **call)
{
*call = cil_malloc(sizeof(**call));
(*call)->macro_str = NULL;
(*call)->macro = NULL;
(*call)->args_tree = NULL;
(*call)->args = NULL;
(*call)->copied = 0;
}
void cil_optional_init(struct cil_optional **optional)
{
*optional = cil_malloc(sizeof(**optional));
cil_symtab_datum_init(&(*optional)->datum);
}
void cil_param_init(struct cil_param **param)
{
*param = cil_malloc(sizeof(**param));
(*param)->str = NULL;
(*param)->flavor = CIL_NONE;
}
void cil_macro_init(struct cil_macro **macro)
{
*macro = cil_malloc(sizeof(**macro));
cil_symtab_datum_init(&(*macro)->datum);
cil_symtab_array_init((*macro)->symtab, cil_sym_sizes[CIL_SYM_ARRAY_MACRO]);
(*macro)->params = NULL;
}
void cil_policycap_init(struct cil_policycap **policycap)
{
*policycap = cil_malloc(sizeof(**policycap));
cil_symtab_datum_init(&(*policycap)->datum);
}
void cil_bounds_init(struct cil_bounds **bounds)
{
*bounds = cil_malloc(sizeof(**bounds));
(*bounds)->parent_str = NULL;
(*bounds)->parent = NULL;
(*bounds)->child_str = NULL;
(*bounds)->child = NULL;
}
void cil_default_init(struct cil_default **def)
{
*def = cil_malloc(sizeof(**def));
(*def)->flavor = CIL_NONE;
(*def)->class_strs = NULL;
(*def)->class_datums = NULL;
}
void cil_defaultrange_init(struct cil_defaultrange **def)
{
*def = cil_malloc(sizeof(**def));
(*def)->class_strs = NULL;
(*def)->class_datums = NULL;
}
void cil_handleunknown_init(struct cil_handleunknown **unk)
{
*unk = cil_malloc(sizeof(**unk));
}
void cil_mls_init(struct cil_mls **mls)
{
*mls = cil_malloc(sizeof(**mls));
(*mls)->value = 0;
}
void cil_src_info_init(struct cil_src_info **info)
{
*info = cil_malloc(sizeof(**info));
(*info)->kind = NULL;
(*info)->hll_line = 0;
(*info)->path = NULL;
}
libsepol-3.8.1/cil/src/cil_binary.c000066400000000000000000004312251476211737200171720ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#ifndef IPPROTO_DCCP
#define IPPROTO_DCCP 33
#endif
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif
#include
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_binary.h"
#include "cil_symtab.h"
#include "cil_find.h"
#include "cil_build_ast.h"
#define ROLE_TRANS_TABLE_SIZE (1 << 10)
#define AVRULEX_TABLE_SIZE (1 << 10)
#define PERMS_PER_CLASS 32
struct cil_args_xperm_tables {
hashtab_t ioctl;
hashtab_t nlmsg;
};
struct cil_args_binary {
const struct cil_db *db;
policydb_t *pdb;
struct cil_list *neverallows;
int pass;
hashtab_t role_trans_table;
struct cil_args_xperm_tables avrulex_xperm_tables;
void **type_value_to_cil;
};
struct cil_args_booleanif {
const struct cil_db *db;
policydb_t *pdb;
cond_node_t *cond_node;
enum cil_flavor cond_flavor;
struct cil_args_xperm_tables avrulex_xperm_tables;
};
static unsigned int avrulex_hash(__attribute__((unused)) hashtab_t h, const_hashtab_key_t key);
static int avrulex_compare(hashtab_t h
__attribute__ ((unused)), const_hashtab_key_t key1,
const_hashtab_key_t key2);
static int __cil_get_sepol_user_datum(policydb_t *pdb, struct cil_symtab_datum *datum, user_datum_t **sepol_user)
{
*sepol_user = hashtab_search(pdb->p_users.table, datum->fqn);
if (*sepol_user == NULL) {
cil_log(CIL_INFO, "Failed to find user %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_get_sepol_role_datum(policydb_t *pdb, struct cil_symtab_datum *datum, role_datum_t **sepol_role)
{
*sepol_role = hashtab_search(pdb->p_roles.table, datum->fqn);
if (*sepol_role == NULL) {
cil_log(CIL_INFO, "Failed to find role %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_get_sepol_type_datum(policydb_t *pdb, struct cil_symtab_datum *datum, type_datum_t **sepol_type)
{
*sepol_type = hashtab_search(pdb->p_types.table, datum->fqn);
if (*sepol_type == NULL) {
cil_log(CIL_INFO, "Failed to find type %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_get_sepol_class_datum(policydb_t *pdb, struct cil_symtab_datum *datum, class_datum_t **sepol_class)
{
*sepol_class = hashtab_search(pdb->p_classes.table, datum->fqn);
if (*sepol_class == NULL) {
cil_log(CIL_INFO, "Failed to find class %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_get_sepol_cat_datum(policydb_t *pdb, struct cil_symtab_datum *datum, cat_datum_t **sepol_cat)
{
*sepol_cat = hashtab_search(pdb->p_cats.table, datum->fqn);
if (*sepol_cat == NULL) {
cil_log(CIL_INFO, "Failed to find category %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_get_sepol_level_datum(policydb_t *pdb, struct cil_symtab_datum *datum, level_datum_t **sepol_level)
{
*sepol_level = hashtab_search(pdb->p_levels.table, datum->fqn);
if (*sepol_level == NULL) {
cil_log(CIL_INFO, "Failed to find level %s in sepol hashtab\n", datum->fqn);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_expand_user(struct cil_symtab_datum *datum, ebitmap_t *new)
{
struct cil_tree_node *node = NODE(datum);
struct cil_user *user = NULL;
struct cil_userattribute *attr = NULL;
if (node->flavor == CIL_USERATTRIBUTE) {
attr = (struct cil_userattribute *)datum;
if (ebitmap_cpy(new, attr->users)) {
cil_log(CIL_ERR, "Failed to copy user bits\n");
goto exit;
}
} else {
user = (struct cil_user *)datum;
ebitmap_init(new);
if (ebitmap_set_bit(new, user->value, 1)) {
cil_log(CIL_ERR, "Failed to set user bit\n");
ebitmap_destroy(new);
goto exit;
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_expand_role(struct cil_symtab_datum *datum, ebitmap_t *new)
{
struct cil_tree_node *node = NODE(datum);
if (node->flavor == CIL_ROLEATTRIBUTE) {
struct cil_roleattribute *attr = (struct cil_roleattribute *)datum;
if (ebitmap_cpy(new, attr->roles)) {
cil_log(CIL_ERR, "Failed to copy role bits\n");
goto exit;
}
} else {
struct cil_role *role = (struct cil_role *)datum;
ebitmap_init(new);
if (ebitmap_set_bit(new, role->value, 1)) {
cil_log(CIL_ERR, "Failed to set role bit\n");
ebitmap_destroy(new);
goto exit;
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_expand_type(struct cil_symtab_datum *datum, ebitmap_t *new)
{
struct cil_tree_node *node = NODE(datum);
if (node->flavor == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = (struct cil_typeattribute *)datum;
if (ebitmap_cpy(new, attr->types)) {
cil_log(CIL_ERR, "Failed to copy type bits\n");
goto exit;
}
} else {
struct cil_type *type = (struct cil_type *)datum;
ebitmap_init(new);
if (ebitmap_set_bit(new, type->value, 1)) {
cil_log(CIL_ERR, "Failed to set type bit\n");
ebitmap_destroy(new);
goto exit;
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static ocontext_t *cil_add_ocontext(ocontext_t **head, ocontext_t **tail)
{
ocontext_t *new = cil_malloc(sizeof(ocontext_t));
memset(new, 0, sizeof(ocontext_t));
if (*tail) {
(*tail)->next = new;
} else {
*head = new;
}
*tail = new;
return new;
}
int cil_common_to_policydb(policydb_t *pdb, struct cil_class *cil_common, common_datum_t **common_out)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
struct cil_tree_node *node = cil_common->datum.nodes->head->data;
struct cil_tree_node *cil_perm = node->cl_head;
common_datum_t *sepol_common = cil_malloc(sizeof(*sepol_common));
memset(sepol_common, 0, sizeof(common_datum_t));
key = cil_strdup(cil_common->datum.fqn);
rc = symtab_insert(pdb, SYM_COMMONS, key, sepol_common, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
free(sepol_common);
goto exit;
}
sepol_common->s.value = value;
rc = symtab_init(&sepol_common->permissions, PERM_SYMTAB_SIZE);
if (rc != SEPOL_OK) {
goto exit;
}
while (cil_perm != NULL) {
struct cil_perm *curr = cil_perm->data;
perm_datum_t *sepol_perm = cil_malloc(sizeof(*sepol_perm));
memset(sepol_perm, 0, sizeof(perm_datum_t));
key = cil_strdup(curr->datum.fqn);
rc = hashtab_insert(sepol_common->permissions.table, key, sepol_perm);
if (rc != SEPOL_OK) {
free(sepol_perm);
goto exit;
}
sepol_perm->s.value = sepol_common->permissions.nprim + 1;
sepol_common->permissions.nprim++;
cil_perm = cil_perm->next;
}
*common_out = sepol_common;
return SEPOL_OK;
exit:
free(key);
return rc;
}
static int cil_classorder_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_class *class_value_to_cil[], struct cil_perm **perm_value_to_cil[])
{
int rc = SEPOL_ERR;
struct cil_list_item *curr_class;
cil_list_for_each(curr_class, db->classorder) {
struct cil_class *cil_class = curr_class->data;
uint32_t value = 0;
char *key = NULL;
int class_index;
struct cil_tree_node *curr;
common_datum_t *sepol_common = NULL;
class_datum_t *sepol_class = cil_malloc(sizeof(*sepol_class));
memset(sepol_class, 0, sizeof(class_datum_t));
key = cil_strdup(cil_class->datum.fqn);
rc = symtab_insert(pdb, SYM_CLASSES, key, sepol_class, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
free(sepol_class);
free(key);
goto exit;
}
sepol_class->s.value = value;
class_index = value;
class_value_to_cil[class_index] = cil_class;
rc = symtab_init(&sepol_class->permissions, PERM_SYMTAB_SIZE);
if (rc != SEPOL_OK) {
goto exit;
}
if (cil_class->common != NULL) {
int i;
struct cil_class *cil_common = cil_class->common;
key = cil_class->common->datum.fqn;
sepol_common = hashtab_search(pdb->p_commons.table, key);
if (sepol_common == NULL) {
rc = cil_common_to_policydb(pdb, cil_common, &sepol_common);
if (rc != SEPOL_OK) {
goto exit;
}
}
sepol_class->comdatum = sepol_common;
sepol_class->comkey = cil_strdup(key);
sepol_class->permissions.nprim += sepol_common->permissions.nprim;
for (curr = NODE(cil_class->common)->cl_head, i = 1; curr; curr = curr->next, i++) {
struct cil_perm *cil_perm = curr->data;
perm_value_to_cil[class_index][i] = cil_perm;
}
}
for (curr = NODE(cil_class)->cl_head; curr; curr = curr->next) {
struct cil_perm *cil_perm = curr->data;
perm_datum_t *sepol_perm = cil_malloc(sizeof(*sepol_perm));
memset(sepol_perm, 0, sizeof(perm_datum_t));
key = cil_strdup(cil_perm->datum.fqn);
rc = hashtab_insert(sepol_class->permissions.table, key, sepol_perm);
if (rc != SEPOL_OK) {
free(sepol_perm);
free(key);
goto exit;
}
sepol_perm->s.value = sepol_class->permissions.nprim + 1;
sepol_class->permissions.nprim++;
perm_value_to_cil[class_index][sepol_perm->s.value] = cil_perm;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_role_to_policydb(policydb_t *pdb, struct cil_role *cil_role)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
role_datum_t *sepol_role = cil_malloc(sizeof(*sepol_role));
role_datum_init(sepol_role);
if (cil_role->datum.fqn == CIL_KEY_OBJECT_R) {
/* special case
* object_r defaults to 1 in libsepol symtab */
rc = SEPOL_OK;
goto exit;
}
key = cil_strdup(cil_role->datum.fqn);
rc = symtab_insert(pdb, SYM_ROLES, (hashtab_key_t)key, sepol_role, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
if (ebitmap_set_bit(&sepol_role->dominates, value - 1, 1)) {
cil_log(CIL_INFO, "Failed to set dominates bit for role\n");
rc = SEPOL_ERR;
goto exit;
}
sepol_role->s.value = value;
return SEPOL_OK;
exit:
free(key);
role_datum_destroy(sepol_role);
free(sepol_role);
return rc;
}
static int cil_role_bounds_to_policydb(policydb_t *pdb, struct cil_role *cil_role)
{
int rc = SEPOL_ERR;
role_datum_t *sepol_role = NULL;
role_datum_t *sepol_parent = NULL;
if (cil_role->bounds) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(cil_role), &sepol_role);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_role_datum(pdb, DATUM(cil_role->bounds), &sepol_parent);
if (rc != SEPOL_OK) goto exit;
sepol_role->bounds = sepol_parent->s.value;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to insert role bounds for role %s\n", cil_role->datum.fqn);
return SEPOL_ERR;
}
int cil_roletype_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_role *role)
{
int rc = SEPOL_ERR;
if (role->types) {
role_datum_t *sepol_role = NULL;
type_datum_t *sepol_type = NULL;
ebitmap_node_t *tnode;
unsigned int i;
rc = __cil_get_sepol_role_datum(pdb, DATUM(role), &sepol_role);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(role->types, tnode, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_type);
if (rc != SEPOL_OK) goto exit;
if (ebitmap_set_bit(&sepol_role->types.types, sepol_type->s.value - 1, 1)) {
cil_log(CIL_INFO, "Failed to set type bit for role\n");
rc = SEPOL_ERR;
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_type_to_policydb(policydb_t *pdb, struct cil_type *cil_type, void *type_value_to_cil[])
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
type_datum_t *sepol_type = cil_malloc(sizeof(*sepol_type));
type_datum_init(sepol_type);
sepol_type->flavor = TYPE_TYPE;
key = cil_strdup(cil_type->datum.fqn);
rc = symtab_insert(pdb, SYM_TYPES, key, sepol_type, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_type->s.value = value;
sepol_type->primary = 1;
type_value_to_cil[value] = cil_type;
return SEPOL_OK;
exit:
free(key);
type_datum_destroy(sepol_type);
free(sepol_type);
return rc;
}
static int cil_type_bounds_to_policydb(policydb_t *pdb, struct cil_type *cil_type)
{
int rc = SEPOL_ERR;
type_datum_t *sepol_type = NULL;
type_datum_t *sepol_parent = NULL;
if (cil_type->bounds) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_type), &sepol_type);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_type->bounds), &sepol_parent);
if (rc != SEPOL_OK) goto exit;
sepol_type->bounds = sepol_parent->s.value;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to insert type bounds for type %s\n", cil_type->datum.fqn);
return SEPOL_ERR;
}
int cil_typealias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alias)
{
int rc = SEPOL_ERR;
char *key = NULL;
type_datum_t *sepol_type = NULL;
type_datum_t *sepol_alias = cil_malloc(sizeof(*sepol_alias));
type_datum_init(sepol_alias);
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_alias->actual), &sepol_type);
if (rc != SEPOL_OK) goto exit;
sepol_alias->flavor = TYPE_TYPE;
key = cil_strdup(cil_alias->datum.fqn);
rc = symtab_insert(pdb, SYM_TYPES, key, sepol_alias, SCOPE_DECL, 0, NULL);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_alias->s.value = sepol_type->s.value;
sepol_alias->primary = 0;
return SEPOL_OK;
exit:
free(key);
type_datum_destroy(sepol_alias);
free(sepol_alias);
return rc;
}
int cil_typepermissive_to_policydb(policydb_t *pdb, struct cil_typepermissive *cil_typeperm)
{
int rc = SEPOL_ERR;
type_datum_t *sepol_type = NULL;
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_typeperm->type), &sepol_type);
if (rc != SEPOL_OK) goto exit;
if (ebitmap_set_bit(&pdb->permissive_map, sepol_type->s.value, 1)) {
goto exit;
}
return SEPOL_OK;
exit:
type_datum_destroy(sepol_type);
free(sepol_type);
return rc;
}
int cil_typeattribute_to_policydb(policydb_t *pdb, struct cil_typeattribute *cil_attr, void *type_value_to_cil[])
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
type_datum_t *sepol_attr = NULL;
if (!cil_attr->keep) {
return SEPOL_OK;
}
sepol_attr = cil_malloc(sizeof(*sepol_attr));
type_datum_init(sepol_attr);
sepol_attr->flavor = TYPE_ATTRIB;
key = cil_strdup(cil_attr->datum.fqn);
rc = symtab_insert(pdb, SYM_TYPES, key, sepol_attr, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_attr->s.value = value;
sepol_attr->primary = 1;
type_value_to_cil[value] = cil_attr;
return SEPOL_OK;
exit:
type_datum_destroy(sepol_attr);
free(sepol_attr);
return rc;
}
static int __cil_typeattr_bitmap_init(policydb_t *pdb)
{
int rc = SEPOL_ERR;
uint32_t i;
pdb->type_attr_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));
pdb->attr_type_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));
for (i = 0; i < pdb->p_types.nprim; i++) {
ebitmap_init(&pdb->type_attr_map[i]);
ebitmap_init(&pdb->attr_type_map[i]);
if (ebitmap_set_bit(&pdb->type_attr_map[i], i, 1)) {
rc = SEPOL_ERR;
goto exit;
}
if (pdb->type_val_to_struct[i] && pdb->type_val_to_struct[i]->flavor != TYPE_ATTRIB) {
if (ebitmap_set_bit(&pdb->attr_type_map[i], i, 1)) {
rc = SEPOL_ERR;
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_typeattribute_to_bitmap(policydb_t *pdb, const struct cil_db *db, struct cil_typeattribute *cil_attr)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
type_datum_t *sepol_type = NULL;
ebitmap_node_t *tnode;
unsigned int i;
if (!cil_attr->keep) {
return SEPOL_OK;
}
if (pdb->type_attr_map == NULL) {
rc = __cil_typeattr_bitmap_init(pdb);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_attr), &sepol_type);
if (rc != SEPOL_OK) goto exit;
value = sepol_type->s.value;
ebitmap_for_each_positive_bit(cil_attr->types, tnode, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_type);
if (rc != SEPOL_OK) goto exit;
ebitmap_set_bit(&pdb->type_attr_map[sepol_type->s.value - 1], value - 1, 1);
ebitmap_set_bit(&pdb->attr_type_map[value - 1], sepol_type->s.value - 1, 1);
}
rc = SEPOL_OK;
exit:
return rc;
}
int cil_policycap_to_policydb(policydb_t *pdb, struct cil_policycap *cil_polcap)
{
int rc = SEPOL_ERR;
int capnum;
capnum = sepol_polcap_getnum(cil_polcap->datum.fqn);
if (capnum == -1) {
goto exit;
}
if (ebitmap_set_bit(&pdb->policycaps, capnum, 1)) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_user_to_policydb(policydb_t *pdb, struct cil_user *cil_user)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
user_datum_t *sepol_user = cil_malloc(sizeof(*sepol_user));
user_datum_init(sepol_user);
key = cil_strdup(cil_user->datum.fqn);
rc = symtab_insert(pdb, SYM_USERS, key, sepol_user, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_user->s.value = value;
return SEPOL_OK;
exit:
free(key);
user_datum_destroy(sepol_user);
free(sepol_user);
return rc;
}
static int cil_user_bounds_to_policydb(policydb_t *pdb, struct cil_user *cil_user)
{
int rc = SEPOL_ERR;
user_datum_t *sepol_user = NULL;
user_datum_t *sepol_parent = NULL;
if (cil_user->bounds) {
rc = __cil_get_sepol_user_datum(pdb, DATUM(cil_user), &sepol_user);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_user_datum(pdb, DATUM(cil_user->bounds), &sepol_parent);
if (rc != SEPOL_OK) goto exit;
sepol_user->bounds = sepol_parent->s.value;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to insert user bounds for user %s\n", cil_user->datum.fqn);
return SEPOL_ERR;
}
int cil_userrole_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_user *user)
{
int rc = SEPOL_ERR;
user_datum_t *sepol_user = NULL;
role_datum_t *sepol_role = NULL;
ebitmap_node_t *rnode = NULL;
unsigned int i;
if (user->roles) {
rc = __cil_get_sepol_user_datum(pdb, DATUM(user), &sepol_user);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(user->roles, rnode, i) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(db->val_to_role[i]), &sepol_role);
if (rc != SEPOL_OK) {
goto exit;
}
if (sepol_role->s.value == 1) {
// role is object_r, ignore it since it is implicitly associated
// with all users
continue;
}
if (ebitmap_set_bit(&sepol_user->roles.roles, sepol_role->s.value - 1, 1)) {
cil_log(CIL_INFO, "Failed to set role bit for user\n");
rc = SEPOL_ERR;
goto exit;
}
}
}
rc = SEPOL_OK;
exit:
return rc;
}
int cil_bool_to_policydb(policydb_t *pdb, struct cil_bool *cil_bool)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
cond_bool_datum_t *sepol_bool = cil_malloc(sizeof(*sepol_bool));
memset(sepol_bool, 0, sizeof(cond_bool_datum_t));
key = cil_strdup(cil_bool->datum.fqn);
rc = symtab_insert(pdb, SYM_BOOLS, key, sepol_bool, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_bool->s.value = value;
sepol_bool->state = cil_bool->value;
return SEPOL_OK;
exit:
free(key);
free(sepol_bool);
return rc;
}
int cil_catorder_to_policydb(policydb_t *pdb, const struct cil_db *db)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
struct cil_list_item *curr_cat;
struct cil_cat *cil_cat = NULL;
cat_datum_t *sepol_cat = NULL;
cil_list_for_each(curr_cat, db->catorder) {
cil_cat = curr_cat->data;
sepol_cat = cil_malloc(sizeof(*sepol_cat));
cat_datum_init(sepol_cat);
key = cil_strdup(cil_cat->datum.fqn);
rc = symtab_insert(pdb, SYM_CATS, key, sepol_cat, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_cat->s.value = value;
}
return SEPOL_OK;
exit:
free(key);
cat_datum_destroy(sepol_cat);
free(sepol_cat);
return rc;
}
int cil_catalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alias)
{
int rc = SEPOL_ERR;
char *key = NULL;
cat_datum_t *sepol_cat;
cat_datum_t *sepol_alias = cil_malloc(sizeof(*sepol_cat));
cat_datum_init(sepol_alias);
rc = __cil_get_sepol_cat_datum(pdb, DATUM(cil_alias->actual), &sepol_cat);
if (rc != SEPOL_OK) goto exit;
key = cil_strdup(cil_alias->datum.fqn);
rc = symtab_insert(pdb, SYM_CATS, key, sepol_alias, SCOPE_DECL, 0, NULL);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_alias->s.value = sepol_cat->s.value;
sepol_alias->isalias = 1;
return SEPOL_OK;
exit:
free(key);
cat_datum_destroy(sepol_alias);
free(sepol_alias);
return rc;
}
int cil_sensitivityorder_to_policydb(policydb_t *pdb, const struct cil_db *db)
{
int rc = SEPOL_ERR;
uint32_t value = 0;
char *key = NULL;
struct cil_list_item *curr;
struct cil_sens *cil_sens = NULL;
level_datum_t *sepol_level = NULL;
mls_level_t *mls_level = NULL;
cil_list_for_each(curr, db->sensitivityorder) {
cil_sens = curr->data;
sepol_level = cil_malloc(sizeof(*sepol_level));
mls_level = cil_malloc(sizeof(*mls_level));
level_datum_init(sepol_level);
mls_level_init(mls_level);
key = cil_strdup(cil_sens->datum.fqn);
rc = symtab_insert(pdb, SYM_LEVELS, key, sepol_level, SCOPE_DECL, 0, &value);
if (rc != SEPOL_OK) {
goto exit;
}
mls_level->sens = value;
sepol_level->level = mls_level;
}
return SEPOL_OK;
exit:
level_datum_destroy(sepol_level);
mls_level_destroy(mls_level);
free(sepol_level);
free(mls_level);
free(key);
return rc;
}
static int cil_sensalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alias)
{
int rc = SEPOL_ERR;
char *key = NULL;
mls_level_t *mls_level = NULL;
level_datum_t *sepol_level = NULL;
level_datum_t *sepol_alias = cil_malloc(sizeof(*sepol_alias));
level_datum_init(sepol_alias);
rc = __cil_get_sepol_level_datum(pdb, DATUM(cil_alias->actual), &sepol_level);
if (rc != SEPOL_OK) goto exit;
key = cil_strdup(cil_alias->datum.fqn);
rc = symtab_insert(pdb, SYM_LEVELS, key, sepol_alias, SCOPE_DECL, 0, NULL);
if (rc != SEPOL_OK) {
goto exit;
}
mls_level = cil_malloc(sizeof(*mls_level));
mls_level_init(mls_level);
rc = mls_level_cpy(mls_level, sepol_level->level);
if (rc != SEPOL_OK) {
free(mls_level);
goto exit;
}
sepol_alias->level = mls_level;
sepol_alias->isalias = 1;
return SEPOL_OK;
exit:
level_datum_destroy(sepol_alias);
free(sepol_alias);
free(key);
return rc;
}
static int __cil_cond_insert_rule(avtab_t *avtab, avtab_key_t *avtab_key, avtab_datum_t *avtab_datum, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_OK;
avtab_ptr_t avtab_ptr = NULL;
cond_av_list_t *cond_list = NULL;
avtab_ptr = avtab_insert_nonunique(avtab, avtab_key, avtab_datum);
if (!avtab_ptr) {
rc = SEPOL_ERR;
goto exit;
}
// parse_context needs to be non-NULL for conditional rules to be
// written to the binary. it is normally used for finding duplicates,
// but cil checks that earlier, so we don't use it. it just needs to be
// set
avtab_ptr->parse_context = (void*)1;
cond_list = cil_malloc(sizeof(cond_av_list_t));
memset(cond_list, 0, sizeof(cond_av_list_t));
cond_list->node = avtab_ptr;
if (cond_flavor == CIL_CONDTRUE) {
cond_list->next = cond_node->true_list;
cond_node->true_list = cond_list;
} else {
cond_list->next = cond_node->false_list;
cond_node->false_list = cond_list;
}
exit:
return rc;
}
static avtab_datum_t *cil_cond_av_list_search(avtab_key_t *key, cond_av_list_t *cond_list)
{
cond_av_list_t *cur_av;
for (cur_av = cond_list; cur_av != NULL; cur_av = cur_av->next) {
if (cur_av->node->key.source_type == key->source_type &&
cur_av->node->key.target_type == key->target_type &&
cur_av->node->key.target_class == key->target_class &&
(cur_av->node->key.specified & key->specified))
return &cur_av->node->datum;
}
return NULL;
}
static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, struct cil_type_rule *cil_rule, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_OK;
avtab_key_t avtab_key;
avtab_datum_t avtab_datum = { .data = res, .xperms = NULL };
avtab_ptr_t existing;
avtab_key.source_type = src;
avtab_key.target_type = tgt;
avtab_key.target_class = obj;
switch (kind) {
case CIL_TYPE_TRANSITION:
avtab_key.specified = AVTAB_TRANSITION;
break;
case CIL_TYPE_CHANGE:
avtab_key.specified = AVTAB_CHANGE;
break;
case CIL_TYPE_MEMBER:
avtab_key.specified = AVTAB_MEMBER;
break;
default:
rc = SEPOL_ERR;
goto exit;
}
existing = avtab_search_node(&pdb->te_avtab, &avtab_key);
if (existing) {
/* Don't add duplicate type rule and warn if they conflict.
* A warning should have been previously given if there is a
* non-duplicate rule using the same key.
*/
if (existing->datum.data != res) {
cil_log(CIL_ERR, "Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s), existing=%s\n",
pdb->p_type_val_to_name[src - 1],
pdb->p_type_val_to_name[tgt - 1],
pdb->p_class_val_to_name[obj - 1],
pdb->p_type_val_to_name[res - 1],
pdb->p_type_val_to_name[existing->datum.data - 1]);
cil_log(CIL_ERR, "Expanded from type rule (scontext=%s tcontext=%s tclass=%s result=%s)\n",
cil_rule->src_str, cil_rule->tgt_str, cil_rule->obj_str, cil_rule->result_str);
rc = SEPOL_ERR;
}
goto exit;
}
if (!cond_node) {
rc = avtab_insert(&pdb->te_avtab, &avtab_key, &avtab_datum);
} else {
existing = avtab_search_node(&pdb->te_cond_avtab, &avtab_key);
if (existing) {
cond_av_list_t *this_list;
cond_av_list_t *other_list;
avtab_datum_t *search_datum;
if (cond_flavor == CIL_CONDTRUE) {
this_list = cond_node->true_list;
other_list = cond_node->false_list;
} else {
this_list = cond_node->false_list;
other_list = cond_node->true_list;
}
search_datum = cil_cond_av_list_search(&avtab_key, other_list);
if (search_datum == NULL) {
if (existing->datum.data != res) {
cil_log(CIL_ERR, "Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s), existing=%s\n",
pdb->p_type_val_to_name[src - 1],
pdb->p_type_val_to_name[tgt - 1],
pdb->p_class_val_to_name[obj - 1],
pdb->p_type_val_to_name[res - 1],
pdb->p_type_val_to_name[existing->datum.data - 1]);
cil_log(CIL_ERR, "Expanded from type rule (scontext=%s tcontext=%s tclass=%s result=%s)\n",
cil_rule->src_str, cil_rule->tgt_str, cil_rule->obj_str, cil_rule->result_str);
rc = SEPOL_ERR;
goto exit;
}
search_datum = cil_cond_av_list_search(&avtab_key, this_list);
if (search_datum) {
goto exit;
}
}
}
rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, &avtab_key, &avtab_datum, cond_node, cond_flavor);
}
exit:
return rc;
}
static int __cil_type_rule_to_avtab_helper(policydb_t *pdb,
type_datum_t *sepol_src,
type_datum_t *sepol_tgt,
struct cil_list *class_list,
type_datum_t *sepol_result,
struct cil_type_rule *cil_rule,
cond_node_t *cond_node,
enum cil_flavor cond_flavor)
{
int rc;
class_datum_t *sepol_obj = NULL;
struct cil_list_item *c;
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
if (rc != SEPOL_OK) return rc;
rc = __cil_insert_type_rule(
pdb, cil_rule->rule_kind, sepol_src->s.value,
sepol_tgt->s.value, sepol_obj->s.value,
sepol_result->s.value, cil_rule, cond_node, cond_flavor
);
if (rc != SEPOL_OK) return rc;
}
return SEPOL_OK;
}
static int __cil_type_rule_to_avtab(policydb_t *pdb, const struct cil_db *db, struct cil_type_rule *cil_rule, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_ERR;
struct cil_symtab_datum *src = NULL;
struct cil_symtab_datum *tgt = NULL;
type_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
struct cil_list *class_list = NULL;
type_datum_t *sepol_result = NULL;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *node1, *node2;
unsigned int i, j;
ebitmap_init(&src_bitmap);
ebitmap_init(&tgt_bitmap);
src = cil_rule->src;
tgt = cil_rule->tgt;
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) goto exit;
class_list = cil_expand_class(cil_rule->obj);
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_rule->result), &sepol_result);
if (rc != SEPOL_OK) goto exit;
if (tgt->fqn == CIL_KEY_SELF) {
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
rc = __cil_type_rule_to_avtab_helper(
pdb, sepol_src, sepol_src, class_list,
sepol_result, cil_rule, cond_node, cond_flavor
);
if (rc != SEPOL_OK) goto exit;
}
} else {
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&tgt_bitmap, node2, j) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[j]), &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
rc = __cil_type_rule_to_avtab_helper(
pdb, sepol_src, sepol_tgt, class_list,
sepol_result, cil_rule, cond_node,
cond_flavor
);
if (rc != SEPOL_OK) goto exit;
}
}
}
rc = SEPOL_OK;
exit:
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
int cil_type_rule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_type_rule *cil_rule)
{
return __cil_type_rule_to_avtab(pdb, db, cil_rule, NULL, CIL_FALSE);
}
static int __cil_typetransition_to_avtab_helper(policydb_t *pdb,
type_datum_t *sepol_src,
type_datum_t *sepol_tgt,
struct cil_list *class_list,
char *name,
type_datum_t *sepol_result)
{
int rc;
class_datum_t *sepol_obj = NULL;
uint32_t otype;
struct cil_list_item *c;
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
if (rc != SEPOL_OK) return rc;
rc = policydb_filetrans_insert(
pdb, sepol_src->s.value, sepol_tgt->s.value,
sepol_obj->s.value, name, NULL,
sepol_result->s.value, &otype
);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
if (sepol_result->s.value!= otype) {
cil_log(CIL_ERR, "Conflicting name type transition rules\n");
} else {
rc = SEPOL_OK;
}
} else {
cil_log(CIL_ERR, "Out of memory\n");
}
if (rc != SEPOL_OK) {
return rc;
}
}
}
return SEPOL_OK;
}
static int __cil_typetransition_to_avtab(policydb_t *pdb, const struct cil_db *db, struct cil_nametypetransition *typetrans, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_ERR;
struct cil_symtab_datum *src = NULL;
struct cil_symtab_datum *tgt = NULL;
type_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
struct cil_list *class_list = NULL;
type_datum_t *sepol_result = NULL;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *node1, *node2;
unsigned int i, j;
char *name = DATUM(typetrans->name)->name;
if (name == CIL_KEY_STAR) {
struct cil_type_rule trans;
trans.rule_kind = CIL_TYPE_TRANSITION;
trans.src = typetrans->src;
trans.tgt = typetrans->tgt;
trans.obj = typetrans->obj;
trans.result = typetrans->result;
trans.src_str = typetrans->src_str;
trans.tgt_str = typetrans->tgt_str;
trans.obj_str = typetrans->obj_str;
trans.result_str = typetrans->result_str;
return __cil_type_rule_to_avtab(pdb, db, &trans, cond_node, cond_flavor);
}
ebitmap_init(&src_bitmap);
ebitmap_init(&tgt_bitmap);
src = typetrans->src;
tgt = typetrans->tgt;
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) goto exit;
class_list = cil_expand_class(typetrans->obj);
rc = __cil_get_sepol_type_datum(pdb, DATUM(typetrans->result), &sepol_result);
if (rc != SEPOL_OK) goto exit;
if (tgt->fqn == CIL_KEY_SELF) {
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
rc = __cil_typetransition_to_avtab_helper(
pdb, sepol_src, sepol_src, class_list,
name, sepol_result
);
if (rc != SEPOL_OK) goto exit;
}
} else {
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&tgt_bitmap, node2, j) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[j]), &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
rc = __cil_typetransition_to_avtab_helper(
pdb, sepol_src, sepol_tgt, class_list,
name, sepol_result
);
if (rc != SEPOL_OK) goto exit;
}
}
}
rc = SEPOL_OK;
exit:
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
int cil_typetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_nametypetransition *typetrans)
{
return __cil_typetransition_to_avtab(pdb, db, typetrans, NULL, CIL_FALSE);
}
static int __perm_str_to_datum(char *perm_str, class_datum_t *sepol_class, uint32_t *datum)
{
int rc;
perm_datum_t *sepol_perm;
common_datum_t *sepol_common;
sepol_perm = hashtab_search(sepol_class->permissions.table, perm_str);
if (sepol_perm == NULL) {
sepol_common = sepol_class->comdatum;
sepol_perm = hashtab_search(sepol_common->permissions.table, perm_str);
if (sepol_perm == NULL) {
cil_log(CIL_ERR, "Failed to find datum for perm %s\n", perm_str);
rc = SEPOL_ERR;
goto exit;
}
}
*datum |= UINT32_C(1) << (sepol_perm->s.value - 1);
return SEPOL_OK;
exit:
return rc;
}
static int __cil_perms_to_datum(struct cil_list *perms, class_datum_t *sepol_class, uint32_t *datum)
{
int rc = SEPOL_ERR;
char *key = NULL;
struct cil_list_item *curr_perm;
struct cil_perm *cil_perm;
uint32_t data = 0;
cil_list_for_each(curr_perm, perms) {
cil_perm = curr_perm->data;
key = cil_perm->datum.fqn;
rc = __perm_str_to_datum(key, sepol_class, &data);
if (rc != SEPOL_OK) {
goto exit;
}
}
*datum = data;
return SEPOL_OK;
exit:
return rc;
}
static int __cil_insert_avrule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t data, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_OK;
avtab_key_t avtab_key;
avtab_datum_t avtab_datum = { .data = data, .xperms = NULL };
avtab_datum_t *avtab_dup = NULL;
avtab_key.source_type = src;
avtab_key.target_type = tgt;
avtab_key.target_class = obj;
switch (kind) {
case CIL_AVRULE_ALLOWED:
avtab_key.specified = AVTAB_ALLOWED;
break;
case CIL_AVRULE_AUDITALLOW:
avtab_key.specified = AVTAB_AUDITALLOW;
break;
case CIL_AVRULE_DONTAUDIT:
avtab_key.specified = AVTAB_AUDITDENY;
break;
default:
rc = SEPOL_ERR;
goto exit;
break;
}
if (!cond_node) {
avtab_dup = avtab_search(&pdb->te_avtab, &avtab_key);
if (!avtab_dup) {
rc = avtab_insert(&pdb->te_avtab, &avtab_key, &avtab_datum);
} else {
if (kind == CIL_AVRULE_DONTAUDIT)
avtab_dup->data &= data;
else
avtab_dup->data |= data;
}
} else {
rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, &avtab_key, &avtab_datum, cond_node, cond_flavor);
}
exit:
return rc;
}
static int __cil_avrule_expand_helper(policydb_t *pdb, uint16_t kind, struct cil_symtab_datum *src, struct cil_symtab_datum *tgt, struct cil_classperms *cp, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_ERR;
type_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
class_datum_t *sepol_class = NULL;
uint32_t data = 0;
rc = __cil_get_sepol_class_datum(pdb, DATUM(cp->class), &sepol_class);
if (rc != SEPOL_OK) goto exit;
rc = __cil_perms_to_datum(cp->perms, sepol_class, &data);
if (rc != SEPOL_OK) goto exit;
if (data == 0) {
/* No permissions, so don't insert rule. Maybe should return an error? */
return SEPOL_OK;
}
if (kind == CIL_AVRULE_DONTAUDIT) {
data = ~data;
}
rc = __cil_get_sepol_type_datum(pdb, src, &sepol_src);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_type_datum(pdb, tgt, &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
rc = __cil_insert_avrule(pdb, kind, sepol_src->s.value, sepol_tgt->s.value, sepol_class->s.value, data, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_avrule_expand(policydb_t *pdb, uint16_t kind, struct cil_symtab_datum *src, struct cil_symtab_datum *tgt, struct cil_list *classperms, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
cil_list_for_each(curr, classperms) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
rc = __cil_avrule_expand_helper(pdb, kind, src, tgt, cp, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
} else { /* MAP */
struct cil_list_item *i = NULL;
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
rc = __cil_avrule_expand(pdb, kind, src, tgt, cmp->classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
rc = __cil_avrule_expand(pdb, kind, src, tgt, cp->classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_should_expand_attribute( const struct cil_db *db, struct cil_symtab_datum *datum)
{
struct cil_tree_node *node;
struct cil_typeattribute *attr;
node = NODE(datum);
if (node->flavor != CIL_TYPEATTRIBUTE) {
return CIL_FALSE;
}
attr = (struct cil_typeattribute *)datum;
return !attr->keep || (ebitmap_cardinality(attr->types) < db->attrs_expand_size);
}
static int __cil_avrule_to_avtab(policydb_t *pdb, const struct cil_db *db, struct cil_avrule *cil_avrule, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{
int rc = SEPOL_ERR;
uint16_t kind = cil_avrule->rule_kind;
struct cil_symtab_datum *src = NULL;
struct cil_symtab_datum *tgt = NULL;
struct cil_list *classperms = cil_avrule->perms.classperms;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *snode, *tnode;
unsigned int s,t;
if (cil_avrule->rule_kind == CIL_AVRULE_DONTAUDIT && db->disable_dontaudit == CIL_TRUE) {
// Do not add dontaudit rules to binary
rc = SEPOL_OK;
goto exit;
}
src = cil_avrule->src;
tgt = cil_avrule->tgt;
if (tgt->fqn == CIL_KEY_SELF) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
rc = __cil_avrule_expand(pdb, kind, src, src, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
ebitmap_destroy(&src_bitmap);
} else if (tgt->fqn == CIL_KEY_NOTSELF) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
for (t = 0; t < (unsigned int)db->num_types; t++) {
if (s != t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
}
}
ebitmap_destroy(&src_bitmap);
} else if (tgt->fqn == CIL_KEY_OTHER) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
ebitmap_for_each_positive_bit(&src_bitmap, tnode, t) {
if (s != t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
}
}
ebitmap_destroy(&src_bitmap);
} else {
int expand_src = __cil_should_expand_attribute(db, src);
int expand_tgt = __cil_should_expand_attribute(db, tgt);
if (!expand_src && !expand_tgt) {
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
} else if (expand_src && expand_tgt) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
ebitmap_for_each_positive_bit(&tgt_bitmap, tnode, t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
goto exit;
}
}
}
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
} else if (expand_src) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
ebitmap_destroy(&src_bitmap);
} else { /* expand_tgt */
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&tgt_bitmap, tnode, t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrule_expand(pdb, kind, src, tgt, classperms, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
ebitmap_destroy(&tgt_bitmap);
goto exit;
}
}
ebitmap_destroy(&tgt_bitmap);
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_avrule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_avrule *cil_avrule)
{
return __cil_avrule_to_avtab(pdb, db, cil_avrule, NULL, CIL_FALSE);
}
// Copied from checkpolicy/policy_define.c
/* index of the u32 containing the permission */
#define XPERM_IDX(x) (x >> 5)
/* set bits 0 through x-1 within the u32 */
#define XPERM_SETBITS(x) ((UINT32_C(1) << (x & 0x1f)) - 1)
/* low value for this u32 */
#define XPERM_LOW(x) (x << 5)
/* high value for this u32 */
#define XPERM_HIGH(x) (((x + 1) << 5) - 1)
static void __avrule_xperm_setrangebits(uint16_t low, uint16_t high, struct avtab_extended_perms *xperms)
{
unsigned int i;
uint16_t h = high + 1;
/* for each u32 that this low-high range touches, set driver permissions */
for (i = XPERM_IDX(low); i <= XPERM_IDX(high); i++) {
/* set all bits in u32 */
if ((low <= XPERM_LOW(i)) && (high >= XPERM_HIGH(i)))
xperms->perms[i] |= ~0U;
/* set low bits */
else if ((low <= XPERM_LOW(i)) && (high < XPERM_HIGH(i)))
xperms->perms[i] |= XPERM_SETBITS(h);
/* set high bits */
else if ((low > XPERM_LOW(i)) && (high >= XPERM_HIGH(i)))
xperms->perms[i] |= ~0U - XPERM_SETBITS(low);
/* set middle bits */
else if ((low > XPERM_LOW(i)) && (high <= XPERM_HIGH(i)))
xperms->perms[i] |= XPERM_SETBITS(h) - XPERM_SETBITS(low);
}
}
static char* __cil_xperm_kind_to_str(uint32_t xperm_kind)
{
switch (xperm_kind) {
case CIL_PERMX_KIND_IOCTL:
return CIL_KEY_IOCTL;
case CIL_PERMX_KIND_NLMSG:
return CIL_KEY_NLMSG;
default:
return (char *) "unknown";
}
}
#define IOC_DRIV(x) (x >> 8)
#define IOC_FUNC(x) (x & 0xff)
static int __cil_permx_bitmap_to_sepol_xperms_list(uint32_t kind, ebitmap_t *xperms, struct cil_list **xperms_list)
{
ebitmap_node_t *node;
unsigned int i;
uint16_t low = 0, high = 0;
struct avtab_extended_perms *partial = NULL;
struct avtab_extended_perms *complete = NULL;
int start_new_range;
cil_list_init(xperms_list, CIL_NONE);
start_new_range = 1;
ebitmap_for_each_positive_bit(xperms, node, i) {
if (start_new_range) {
low = i;
start_new_range = 0;
}
// continue if the current bit isn't the end of the driver function or the next bit is set
if (IOC_FUNC(i) != 0xff && ebitmap_get_bit(xperms, i + 1)) {
continue;
}
// if we got here, i is the end of this range (either because the func
// is 0xff or the next bit isn't set). The next time around we are
// going to need a start a new range
high = i;
start_new_range = 1;
if (kind == CIL_PERMX_KIND_IOCTL && IOC_FUNC(low) == 0x00 && IOC_FUNC(high) == 0xff) {
if (!complete) {
complete = cil_calloc(1, sizeof(*complete));
complete->driver = 0x0;
complete->specified = AVTAB_XPERMS_IOCTLDRIVER;
}
__avrule_xperm_setrangebits(IOC_DRIV(low), IOC_DRIV(low), complete);
} else {
if (partial && partial->driver != IOC_DRIV(low)) {
cil_list_append(*xperms_list, CIL_NONE, partial);
partial = NULL;
}
if (!partial) {
partial = cil_calloc(1, sizeof(*partial));
partial->driver = IOC_DRIV(low);
switch (kind) {
case CIL_PERMX_KIND_IOCTL:
partial->specified = AVTAB_XPERMS_IOCTLFUNCTION;
break;
case CIL_PERMX_KIND_NLMSG:
partial->specified = AVTAB_XPERMS_NLMSG;
break;
}
}
__avrule_xperm_setrangebits(IOC_FUNC(low), IOC_FUNC(high), partial);
}
}
if (partial) {
cil_list_append(*xperms_list, CIL_NONE, partial);
}
if (complete) {
cil_list_append(*xperms_list, CIL_NONE, complete);
}
return SEPOL_OK;
}
static int __cil_avrulex_xperm_to_policydb(hashtab_key_t k, hashtab_datum_t datum, uint32_t xperm_kind, void *args)
{
int rc = SEPOL_OK;
struct cil_args_booleanif *booleanif_args = args;
struct policydb *pdb = booleanif_args->pdb;
cond_node_t *cond_node = booleanif_args->cond_node;
enum cil_flavor cond_flavor = booleanif_args->cond_flavor;
avtab_key_t *avtab_key;
avtab_datum_t avtab_datum;
struct cil_list *xperms_list = NULL;
struct cil_list_item *item;
class_datum_t *sepol_obj;
uint32_t data = 0;
char *kind = NULL;
avtab_key = (avtab_key_t *)k;
sepol_obj = pdb->class_val_to_struct[avtab_key->target_class - 1];
// setting the data for an extended avtab isn't really necessary because
// it is ignored by the kernel. However, neverallow checking requires that
// the data value be set, so set it for that to work.
kind = __cil_xperm_kind_to_str(xperm_kind);
rc = __perm_str_to_datum(kind, sepol_obj, &data);
if (rc != SEPOL_OK) {
goto exit;
}
avtab_datum.data = data;
rc = __cil_permx_bitmap_to_sepol_xperms_list(xperm_kind, datum, &xperms_list);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_for_each(item, xperms_list) {
avtab_datum.xperms = item->data;
if (cond_node) {
rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, avtab_key, &avtab_datum, cond_node, cond_flavor);
} else {
rc = avtab_insert(&pdb->te_avtab, avtab_key, &avtab_datum);
}
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = SEPOL_OK;
exit:
if (xperms_list != NULL) {
cil_list_for_each(item, xperms_list) {
free(item->data);
}
cil_list_destroy(&xperms_list, CIL_FALSE);
}
return rc;
}
static int __cil_avrulex_ioctl_to_policydb(hashtab_key_t k, hashtab_datum_t datum, void *args) {
return __cil_avrulex_xperm_to_policydb(k, datum, CIL_PERMX_KIND_IOCTL, args);
}
static int __cil_avrulex_nlmsg_to_policydb(hashtab_key_t k, hashtab_datum_t datum, void *args) {
return __cil_avrulex_xperm_to_policydb(k, datum, CIL_PERMX_KIND_NLMSG, args);
}
static int __cil_avrulex_xperm_to_hashtable(hashtab_t h, uint16_t kind, uint32_t src, uint32_t tgt, uint32_t obj, ebitmap_t *xperms)
{
uint16_t specified;
avtab_key_t *avtab_key;
ebitmap_t *hashtab_xperms;
int rc = SEPOL_ERR;
switch (kind) {
case CIL_AVRULE_ALLOWED:
specified = AVTAB_XPERMS_ALLOWED;
break;
case CIL_AVRULE_AUDITALLOW:
specified = AVTAB_XPERMS_AUDITALLOW;
break;
case CIL_AVRULE_DONTAUDIT:
specified = AVTAB_XPERMS_DONTAUDIT;
break;
default:
rc = SEPOL_ERR;
goto exit;
}
avtab_key = cil_malloc(sizeof(*avtab_key));
avtab_key->source_type = src;
avtab_key->target_type = tgt;
avtab_key->target_class = obj;
avtab_key->specified = specified;
hashtab_xperms = (ebitmap_t *)hashtab_search(h, (hashtab_key_t)avtab_key);
if (!hashtab_xperms) {
hashtab_xperms = cil_malloc(sizeof(*hashtab_xperms));
rc = ebitmap_cpy(hashtab_xperms, xperms);
if (rc != SEPOL_OK) {
free(hashtab_xperms);
free(avtab_key);
goto exit;
}
rc = hashtab_insert(h, (hashtab_key_t)avtab_key, hashtab_xperms);
if (rc != SEPOL_OK) {
free(hashtab_xperms);
free(avtab_key);
goto exit;
}
} else {
free(avtab_key);
rc = ebitmap_union(hashtab_xperms, xperms);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_avrulex_to_hashtable_helper(policydb_t *pdb, uint16_t kind, struct cil_symtab_datum *src, struct cil_symtab_datum *tgt, struct cil_permissionx *permx, struct cil_args_xperm_tables *xt)
{
int rc = SEPOL_ERR;
type_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
class_datum_t *sepol_obj = NULL;
struct cil_list *class_list = NULL;
struct cil_list_item *c;
rc = __cil_get_sepol_type_datum(pdb, src, &sepol_src);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_type_datum(pdb, tgt, &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
class_list = cil_expand_class(permx->obj);
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
if (rc != SEPOL_OK) goto exit;
switch (permx->kind) {
case CIL_PERMX_KIND_IOCTL:
rc = __cil_avrulex_xperm_to_hashtable(xt->ioctl, kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, permx->perms);
if (rc != SEPOL_OK) goto exit;
break;
case CIL_PERMX_KIND_NLMSG:
rc = __cil_avrulex_xperm_to_hashtable(xt->nlmsg, kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, permx->perms);
if (rc != SEPOL_OK) goto exit;
break;
default:
rc = SEPOL_ERR;
goto exit;
}
}
rc = SEPOL_OK;
exit:
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
static int cil_avrulex_to_hashtable(policydb_t *pdb, const struct cil_db *db, struct cil_avrule *cil_avrulex, struct cil_args_xperm_tables *xt)
{
int rc = SEPOL_ERR;
uint16_t kind;
struct cil_symtab_datum *src = NULL;
struct cil_symtab_datum *tgt = NULL;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *snode, *tnode;
unsigned int s,t;
if (cil_avrulex->rule_kind == CIL_AVRULE_DONTAUDIT && db->disable_dontaudit == CIL_TRUE) {
// Do not add dontaudit rules to binary
rc = SEPOL_OK;
goto exit;
}
kind = cil_avrulex->rule_kind;
src = cil_avrulex->src;
tgt = cil_avrulex->tgt;
if (tgt->fqn == CIL_KEY_SELF) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, src, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
ebitmap_destroy(&src_bitmap);
} else if (tgt->fqn == CIL_KEY_NOTSELF) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
for (t = 0; t < (unsigned int)db->num_types; t++) {
if (s != t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
}
}
ebitmap_destroy(&src_bitmap);
} else if (tgt->fqn == CIL_KEY_OTHER) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
ebitmap_for_each_positive_bit(&src_bitmap, tnode, t) {
if (s != t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
}
}
ebitmap_destroy(&src_bitmap);
} else {
int expand_src = __cil_should_expand_attribute(db, src);
int expand_tgt = __cil_should_expand_attribute(db, tgt);
if (!expand_src && !expand_tgt) {
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
goto exit;
}
} else if (expand_src && expand_tgt) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
ebitmap_for_each_positive_bit(&tgt_bitmap, tnode, t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
goto exit;
}
}
}
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
} else if (expand_src) {
rc = __cil_expand_type(src, &src_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&src_bitmap, snode, s) {
src = DATUM(db->val_to_type[s]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&src_bitmap);
goto exit;
}
}
ebitmap_destroy(&src_bitmap);
} else { /* expand_tgt */
rc = __cil_expand_type(tgt, &tgt_bitmap);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_for_each_positive_bit(&tgt_bitmap, tnode, t) {
tgt = DATUM(db->val_to_type[t]);
rc = __cil_avrulex_to_hashtable_helper(pdb, kind, src, tgt, cil_avrulex->perms.x.permx, xt);
if (rc != SEPOL_OK) {
ebitmap_destroy(&tgt_bitmap);
goto exit;
}
}
ebitmap_destroy(&tgt_bitmap);
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_avrulex_xperm_destroy(hashtab_key_t k, hashtab_datum_t datum, __attribute__((unused)) void *args)
{
free(k);
ebitmap_destroy(datum);
free(datum);
return SEPOL_OK;
}
static int __cil_cond_to_policydb_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *extra_args)
{
int rc;
enum cil_flavor flavor;
struct cil_args_booleanif *args = extra_args;
const struct cil_db *db = args->db;
policydb_t *pdb = args->pdb;
cond_node_t *cond_node = args->cond_node;
enum cil_flavor cond_flavor = args->cond_flavor;
struct cil_type_rule *cil_type_rule;
struct cil_avrule *cil_avrule;
struct cil_nametypetransition *cil_typetrans;
flavor = node->flavor;
switch (flavor) {
case CIL_NAMETYPETRANSITION:
cil_typetrans = (struct cil_nametypetransition*)node->data;
if (DATUM(cil_typetrans->name)->fqn != CIL_KEY_STAR) {
cil_log(CIL_ERR, "typetransition with file name not allowed within a booleanif block.\n");
cil_tree_log(node, CIL_ERR,"Invalid typetransition statement");
goto exit;
}
rc = __cil_typetransition_to_avtab(pdb, db, cil_typetrans, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Failed to insert type transition into avtab");
goto exit;
}
break;
case CIL_TYPE_RULE:
cil_type_rule = node->data;
rc = __cil_type_rule_to_avtab(pdb, db, cil_type_rule, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Failed to insert typerule into avtab");
goto exit;
}
break;
case CIL_AVRULE:
cil_avrule = node->data;
rc = __cil_avrule_to_avtab(pdb, db, cil_avrule, cond_node, cond_flavor);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Failed to insert avrule into avtab");
goto exit;
}
break;
case CIL_AVRULEX:
if (db->policy_version < POLICYDB_VERSION_COND_XPERMS) {
cil_tree_log(node, CIL_ERR, "Extended permission rules are not supported in policy version %d\n",
db->policy_version);
rc = SEPOL_ERR;
goto exit;
}
cil_avrule = node->data;
rc = cil_avrulex_to_hashtable(pdb, db, cil_avrule, &args->avrulex_xperm_tables);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Failed to insert avrulex into avtab");
goto exit;
}
break;
case CIL_CALL:
case CIL_TUNABLEIF:
break;
default:
cil_tree_log(node, CIL_ERR, "Invalid statement within booleanif");
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor, char **out);
static void __cil_expr_to_string_helper(struct cil_list_item *curr, enum cil_flavor flavor, char **out)
{
char *c;
if (curr->flavor == CIL_DATUM) {
*out = cil_strdup(DATUM(curr->data)->fqn);
} else if (curr->flavor == CIL_LIST) {
__cil_expr_to_string(curr->data, flavor, &c);
cil_asprintf(out, "(%s)", c);
free(c);
} else if (flavor == CIL_PERMISSIONX) {
// permissionx expressions aren't resolved into anything, so curr->flavor
// is just a CIL_STRING, not a CIL_DATUM, so just check on flavor for those
*out = cil_strdup(curr->data);
}
}
static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor, char **out)
{
struct cil_list_item *curr;
char *s1 = NULL;
char *s2 = NULL;
enum cil_flavor op;
if (expr == NULL || expr->head == NULL) {
*out = cil_strdup("");
return;
}
curr = expr->head;
if (curr->flavor == CIL_OP) {
op = (enum cil_flavor)(uintptr_t)curr->data;
if (op == CIL_ALL) {
*out = cil_strdup(CIL_KEY_ALL);
} else if (op == CIL_RANGE) {
__cil_expr_to_string_helper(curr->next, flavor, &s1);
__cil_expr_to_string_helper(curr->next->next, flavor, &s2);
cil_asprintf(out, "%s %s %s", CIL_KEY_RANGE, s1, s2);
free(s1);
free(s2);
} else {
__cil_expr_to_string_helper(curr->next, flavor, &s1);
if (op == CIL_NOT) {
cil_asprintf(out, "%s %s", CIL_KEY_NOT, s1);
free(s1);
} else {
const char *opstr = "";
__cil_expr_to_string_helper(curr->next->next, flavor, &s2);
if (op == CIL_OR) {
opstr = CIL_KEY_OR;
} else if (op == CIL_AND) {
opstr = CIL_KEY_AND;
} else if (op == CIL_XOR) {
opstr = CIL_KEY_XOR;
}
cil_asprintf(out, "%s %s %s", opstr, s1, s2);
free(s1);
free(s2);
}
}
} else {
char *c1 = NULL;
char *c2 = NULL;
__cil_expr_to_string_helper(curr, flavor, &c1);
for (curr = curr->next; curr; curr = curr->next) {
s1 = NULL;
__cil_expr_to_string_helper(curr, flavor, &s1);
cil_asprintf(&c2, "%s %s", c1, s1);
free(c1);
free(s1);
c1 = c2;
}
*out = c1;
}
}
static int __cil_cond_expr_to_sepol_expr_helper(policydb_t *pdb, struct cil_list *cil_expr, cond_expr_t **head, cond_expr_t **tail);
static int __cil_cond_item_to_sepol_expr(policydb_t *pdb, struct cil_list_item *item, cond_expr_t **head, cond_expr_t **tail)
{
if (item == NULL) {
goto exit;
} else if (item->flavor == CIL_DATUM) {
char *key = DATUM(item->data)->fqn;
cond_bool_datum_t *sepol_bool = hashtab_search(pdb->p_bools.table, key);
if (sepol_bool == NULL) {
cil_log(CIL_INFO, "Failed to find boolean\n");
goto exit;
}
*head = cil_malloc(sizeof(cond_expr_t));
(*head)->next = NULL;
(*head)->expr_type = COND_BOOL;
(*head)->boolean = sepol_bool->s.value;
*tail = *head;
} else if (item->flavor == CIL_LIST) {
struct cil_list *l = item->data;
int rc = __cil_cond_expr_to_sepol_expr_helper(pdb, l, head, tail);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_cond_expr_to_sepol_expr_helper(policydb_t *pdb, struct cil_list *cil_expr, cond_expr_t **head, cond_expr_t **tail)
{
int rc = SEPOL_ERR;
struct cil_list_item *item = cil_expr->head;
enum cil_flavor flavor = cil_expr->flavor;
cond_expr_t *op, *h1, *h2, *t1, *t2;
if (flavor != CIL_BOOL) {
cil_log(CIL_INFO, "Expected boolean expression\n");
goto exit;
}
if (item == NULL) {
goto exit;
} else if (item->flavor == CIL_OP) {
enum cil_flavor cil_op = (enum cil_flavor)(uintptr_t)item->data;
op = cil_malloc(sizeof(*op));
op->boolean = 0;
op->next = NULL;
switch (cil_op) {
case CIL_NOT:
op->expr_type = COND_NOT;
break;
case CIL_OR:
op->expr_type = COND_OR;
break;
case CIL_AND:
op->expr_type = COND_AND;
break;
case CIL_XOR:
op->expr_type = COND_XOR;
break;
case CIL_EQ:
op->expr_type = COND_EQ;
break;
case CIL_NEQ:
op->expr_type = COND_NEQ;
break;
default:
free(op);
goto exit;
}
rc = __cil_cond_item_to_sepol_expr(pdb, item->next, &h1, &t1);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get first operand of conditional expression\n");
free(op);
goto exit;
}
if (cil_op == CIL_NOT) {
*head = h1;
t1->next = op;
*tail = op;
} else {
rc = __cil_cond_item_to_sepol_expr(pdb, item->next->next, &h2, &t2);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get second operand of conditional expression\n");
free(op);
cond_expr_destroy(h1);
goto exit;
}
*head = h1;
t1->next = h2;
t2->next = op;
*tail = op;
}
} else {
rc = __cil_cond_item_to_sepol_expr(pdb, item, &h1, &t1);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get initial item in conditional list\n");
goto exit;
}
*head = h1;
for (item = item->next; item; item = item->next) {
rc = __cil_cond_item_to_sepol_expr(pdb, item, &h2, &t2);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get item in conditional list\n");
cond_expr_destroy(*head);
goto exit;
}
op = cil_malloc(sizeof(*op));
op->boolean = 0;
op->next = NULL;
op->expr_type = COND_OR;
t1->next = h2;
t2->next = op;
t1 = op;
}
*tail = t1;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_cond_expr_to_sepol_expr(policydb_t *pdb, struct cil_list *cil_expr, cond_expr_t **sepol_expr)
{
int rc;
cond_expr_t *head, *tail;
rc = __cil_cond_expr_to_sepol_expr_helper(pdb, cil_expr, &head, &tail);
if (rc != SEPOL_OK) {
return SEPOL_ERR;
}
*sepol_expr = head;
return SEPOL_OK;
}
static int __cil_validate_cond_expr(cond_expr_t *cond_expr)
{
cond_expr_t *e;
int depth = -1;
for (e = cond_expr; e != NULL; e = e->next) {
switch (e->expr_type) {
case COND_BOOL:
if (depth == (COND_EXPR_MAXDEPTH - 1)) {
cil_log(CIL_ERR,"Conditional expression exceeded max allowable depth\n");
return SEPOL_ERR;
}
depth++;
break;
case COND_NOT:
if (depth < 0) {
cil_log(CIL_ERR,"Invalid conditional expression\n");
return SEPOL_ERR;
}
break;
case COND_OR:
case COND_AND:
case COND_XOR:
case COND_EQ:
case COND_NEQ:
if (depth < 1) {
cil_log(CIL_ERR,"Invalid conditional expression\n");
return SEPOL_ERR;
}
depth--;
break;
default:
cil_log(CIL_ERR,"Invalid conditional expression\n");
return SEPOL_ERR;
}
}
if (depth != 0) {
cil_log(CIL_ERR,"Invalid conditional expression\n");
return SEPOL_ERR;
}
return SEPOL_OK;
}
int cil_booleanif_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_args_booleanif bool_args;
struct cil_booleanif *cil_boolif = (struct cil_booleanif*)node->data;
struct cil_tree_node *cb_node;
struct cil_tree_node *true_node = NULL;
struct cil_tree_node *false_node = NULL;
struct cil_tree_node *tmp_node = NULL;
cond_node_t *tmp_cond = NULL;
cond_node_t *cond_node = NULL;
int was_created;
int swapped = CIL_FALSE;
cond_av_list_t tmp_cl;
hashtab_t avrulex_ioctl_table = NULL;
hashtab_t avrulex_nlmsg_table = NULL;
tmp_cond = cond_node_create(pdb, NULL);
if (tmp_cond == NULL) {
rc = SEPOL_ERR;
cil_tree_log(node, CIL_INFO, "Failed to create sepol conditional node");
goto exit;
}
rc = __cil_cond_expr_to_sepol_expr(pdb, cil_boolif->datum_expr, &tmp_cond->expr);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Failed to convert CIL conditional expression to sepol expression");
goto exit;
}
rc = __cil_validate_cond_expr(tmp_cond->expr);
if (rc != SEPOL_OK) {
goto exit;
}
tmp_cond->true_list = &tmp_cl;
rc = cond_normalize_expr(pdb, tmp_cond);
if (rc != SEPOL_OK) {
goto exit;
}
if (tmp_cond->false_list != NULL) {
tmp_cond->true_list = NULL;
swapped = CIL_TRUE;
}
cond_node = cond_node_find(pdb, tmp_cond, pdb->cond_list, &was_created);
if (cond_node == NULL) {
rc = SEPOL_ERR;
goto exit;
}
if (was_created) {
cond_node->next = pdb->cond_list;
pdb->cond_list = cond_node;
}
cond_expr_destroy(tmp_cond->expr);
free(tmp_cond);
tmp_cond = NULL;
for (cb_node = node->cl_head; cb_node != NULL; cb_node = cb_node->next) {
if (cb_node->flavor == CIL_CONDBLOCK) {
struct cil_condblock *cb = cb_node->data;
if (cb->flavor == CIL_CONDTRUE) {
true_node = cb_node;
} else if (cb->flavor == CIL_CONDFALSE) {
false_node = cb_node;
}
}
}
if (swapped) {
tmp_node = true_node;
true_node = false_node;
false_node = tmp_node;
}
bool_args.db = db;
bool_args.pdb = pdb;
bool_args.cond_node = cond_node;
if (true_node != NULL) {
avrulex_ioctl_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_ioctl_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
avrulex_nlmsg_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_nlmsg_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
bool_args.cond_flavor = CIL_CONDTRUE;
bool_args.avrulex_xperm_tables.ioctl = avrulex_ioctl_table;
bool_args.avrulex_xperm_tables.nlmsg = avrulex_nlmsg_table;
rc = cil_tree_walk(true_node, __cil_cond_to_policydb_helper, NULL, NULL, &bool_args);
if (rc != SEPOL_OK) {
cil_tree_log(true_node, CIL_ERR, "Failure while walking true conditional block");
goto exit;
}
rc = hashtab_map(avrulex_ioctl_table, __cil_avrulex_ioctl_to_policydb, &bool_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
rc = hashtab_map(avrulex_nlmsg_table, __cil_avrulex_nlmsg_to_policydb, &bool_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
hashtab_map(avrulex_nlmsg_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_nlmsg_table);
avrulex_nlmsg_table = NULL;
hashtab_map(avrulex_ioctl_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_ioctl_table);
avrulex_ioctl_table = NULL;
}
if (false_node != NULL) {
avrulex_ioctl_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_ioctl_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
avrulex_nlmsg_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_nlmsg_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
bool_args.cond_flavor = CIL_CONDFALSE;
bool_args.avrulex_xperm_tables.ioctl = avrulex_ioctl_table;
bool_args.avrulex_xperm_tables.nlmsg = avrulex_nlmsg_table;
rc = cil_tree_walk(false_node, __cil_cond_to_policydb_helper, NULL, NULL, &bool_args);
if (rc != SEPOL_OK) {
cil_tree_log(false_node, CIL_ERR, "Failure while walking false conditional block");
goto exit;
}
rc = hashtab_map(avrulex_ioctl_table, __cil_avrulex_ioctl_to_policydb, &bool_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
rc = hashtab_map(avrulex_nlmsg_table, __cil_avrulex_nlmsg_to_policydb, &bool_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
hashtab_map(avrulex_nlmsg_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_nlmsg_table);
avrulex_nlmsg_table = NULL;
hashtab_map(avrulex_ioctl_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_ioctl_table);
avrulex_ioctl_table = NULL;
}
return SEPOL_OK;
exit:
hashtab_map(avrulex_nlmsg_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_nlmsg_table);
hashtab_map(avrulex_ioctl_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_ioctl_table);
if (tmp_cond) {
if (tmp_cond->expr)
cond_expr_destroy(tmp_cond->expr);
free(tmp_cond);
}
return rc;
}
int cil_roletrans_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_roletransition *roletrans, hashtab_t role_trans_table)
{
int rc = SEPOL_ERR;
role_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
class_datum_t *sepol_obj = NULL;
struct cil_list *class_list = NULL;
role_datum_t *sepol_result = NULL;
role_trans_t *new = NULL;
uint32_t *new_role = NULL;
ebitmap_t role_bitmap, type_bitmap;
ebitmap_node_t *rnode, *tnode;
unsigned int i, j;
struct cil_list_item *c;
rc = __cil_expand_role(DATUM(roletrans->src), &role_bitmap);
if (rc != SEPOL_OK) goto exit;
rc = __cil_expand_type(roletrans->tgt, &type_bitmap);
if (rc != SEPOL_OK) goto exit;
class_list = cil_expand_class(roletrans->obj);
rc = __cil_get_sepol_role_datum(pdb, DATUM(roletrans->result), &sepol_result);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&role_bitmap, rnode, i) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(db->val_to_role[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&type_bitmap, tnode, j) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[j]), &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
cil_list_for_each(c, class_list) {
int add = CIL_TRUE;
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
if (rc != SEPOL_OK) goto exit;
new = cil_malloc(sizeof(*new));
memset(new, 0, sizeof(*new));
new->role = sepol_src->s.value;
new->type = sepol_tgt->s.value;
new->tclass = sepol_obj->s.value;
new->new_role = sepol_result->s.value;
rc = hashtab_insert(role_trans_table, (hashtab_key_t)new, &(new->new_role));
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
add = CIL_FALSE;
new_role = hashtab_search(role_trans_table, (hashtab_key_t)new);
if (new->new_role != *new_role) {
cil_log(CIL_ERR, "Conflicting role transition rules\n");
} else {
rc = SEPOL_OK;
}
} else {
cil_log(CIL_ERR, "Out of memory\n");
}
}
if (add == CIL_TRUE) {
new->next = pdb->role_tr;
pdb->role_tr = new;
} else {
free(new);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
}
}
rc = SEPOL_OK;
exit:
ebitmap_destroy(&role_bitmap);
ebitmap_destroy(&type_bitmap);
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
int cil_roleallow_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_roleallow *roleallow)
{
int rc = SEPOL_ERR;
role_datum_t *sepol_src = NULL;
role_datum_t *sepol_tgt = NULL;
role_allow_t *sepol_roleallow = NULL;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *node1, *node2;
unsigned int i, j;
rc = __cil_expand_role(roleallow->src, &src_bitmap);
if (rc != SEPOL_OK) goto exit;
rc = __cil_expand_role(roleallow->tgt, &tgt_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(db->val_to_role[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&tgt_bitmap, node2, j) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(db->val_to_role[j]), &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
sepol_roleallow = cil_malloc(sizeof(*sepol_roleallow));
memset(sepol_roleallow, 0, sizeof(role_allow_t));
sepol_roleallow->role = sepol_src->s.value;
sepol_roleallow->new_role = sepol_tgt->s.value;
sepol_roleallow->next = pdb->role_allow;
pdb->role_allow = sepol_roleallow;
}
}
rc = SEPOL_OK;
exit:
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
return rc;
}
static int __cil_constrain_expr_datum_to_sepol_expr(policydb_t *pdb, const struct cil_db *db, struct cil_list_item *item, enum cil_flavor expr_flavor, constraint_expr_t *expr)
{
int rc = SEPOL_ERR;
if (expr_flavor == CIL_USER) {
user_datum_t *sepol_user = NULL;
ebitmap_t user_bitmap;
ebitmap_node_t *unode;
unsigned int i;
rc = __cil_expand_user(item->data, &user_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&user_bitmap, unode, i) {
rc = __cil_get_sepol_user_datum(pdb, DATUM(db->val_to_user[i]), &sepol_user);
if (rc != SEPOL_OK) {
ebitmap_destroy(&user_bitmap);
goto exit;
}
if (ebitmap_set_bit(&expr->names, sepol_user->s.value - 1, 1)) {
ebitmap_destroy(&user_bitmap);
goto exit;
}
}
ebitmap_destroy(&user_bitmap);
} else if (expr_flavor == CIL_ROLE) {
role_datum_t *sepol_role = NULL;
ebitmap_t role_bitmap;
ebitmap_node_t *rnode;
unsigned int i;
rc = __cil_expand_role(item->data, &role_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&role_bitmap, rnode, i) {
rc = __cil_get_sepol_role_datum(pdb, DATUM(db->val_to_role[i]), &sepol_role);
if (rc != SEPOL_OK) {
ebitmap_destroy(&role_bitmap);
goto exit;
}
if (ebitmap_set_bit(&expr->names, sepol_role->s.value - 1, 1)) {
ebitmap_destroy(&role_bitmap);
goto exit;
}
}
ebitmap_destroy(&role_bitmap);
} else if (expr_flavor == CIL_TYPE) {
type_datum_t *sepol_type = NULL;
ebitmap_t type_bitmap;
ebitmap_node_t *tnode;
unsigned int i;
if (pdb->policyvers >= POLICYDB_VERSION_CONSTRAINT_NAMES) {
rc = __cil_get_sepol_type_datum(pdb, item->data, &sepol_type);
if (rc != SEPOL_OK) {
if (FLAVOR(item->data) == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = item->data;
if (!attr->keep) {
rc = 0;
}
}
}
if (sepol_type) {
rc = ebitmap_set_bit(&expr->type_names->types, sepol_type->s.value - 1, 1);
}
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = __cil_expand_type(item->data, &type_bitmap);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&type_bitmap, tnode, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_type);
if (rc != SEPOL_OK) {
ebitmap_destroy(&type_bitmap);
goto exit;
}
if (ebitmap_set_bit(&expr->names, sepol_type->s.value - 1, 1)) {
ebitmap_destroy(&type_bitmap);
goto exit;
}
}
ebitmap_destroy(&type_bitmap);
} else {
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_constrain_expr_leaf_to_sepol_expr(policydb_t *pdb, const struct cil_db *db, struct cil_list_item *op_item, enum cil_flavor expr_flavor, constraint_expr_t *expr)
{
int rc = SEPOL_ERR;
struct cil_list_item *l_item = op_item->next;
struct cil_list_item *r_item = op_item->next->next;
enum cil_flavor l_operand = (enum cil_flavor)(uintptr_t)l_item->data;
switch (l_operand) {
case CIL_CONS_U1:
expr->attr = CEXPR_USER;
break;
case CIL_CONS_U2:
expr->attr = CEXPR_USER | CEXPR_TARGET;
break;
case CIL_CONS_U3:
expr->attr = CEXPR_USER | CEXPR_XTARGET;
break;
case CIL_CONS_R1:
expr->attr = CEXPR_ROLE;
break;
case CIL_CONS_R2:
expr->attr = CEXPR_ROLE | CEXPR_TARGET;
break;
case CIL_CONS_R3:
expr->attr = CEXPR_ROLE | CEXPR_XTARGET;
break;
case CIL_CONS_T1:
expr->attr = CEXPR_TYPE;
break;
case CIL_CONS_T2:
expr->attr = CEXPR_TYPE | CEXPR_TARGET;
break;
case CIL_CONS_T3:
expr->attr = CEXPR_TYPE | CEXPR_XTARGET;
break;
case CIL_CONS_L1: {
enum cil_flavor r_operand = (enum cil_flavor)(uintptr_t)r_item->data;
if (r_operand == CIL_CONS_L2) {
expr->attr = CEXPR_L1L2;
} else if (r_operand == CIL_CONS_H1) {
expr->attr = CEXPR_L1H1;
} else {
expr->attr = CEXPR_L1H2;
}
break;
}
case CIL_CONS_L2:
expr->attr = CEXPR_L2H2;
break;
case CIL_CONS_H1: {
enum cil_flavor r_operand = (enum cil_flavor)(uintptr_t)r_item->data;
if (r_operand == CIL_CONS_L2) {
expr->attr = CEXPR_H1L2;
} else {
expr->attr = CEXPR_H1H2;
}
break;
}
default:
goto exit;
break;
}
if (r_item->flavor == CIL_CONS_OPERAND) {
expr->expr_type = CEXPR_ATTR;
} else {
expr->expr_type = CEXPR_NAMES;
if (r_item->flavor == CIL_DATUM) {
rc = __cil_constrain_expr_datum_to_sepol_expr(pdb, db, r_item, expr_flavor, expr);
if (rc != SEPOL_OK) {
goto exit;
}
} else if (r_item->flavor == CIL_LIST) {
struct cil_list *r_expr = r_item->data;
struct cil_list_item *curr;
cil_list_for_each(curr, r_expr) {
rc = __cil_constrain_expr_datum_to_sepol_expr(pdb, db, curr, expr_flavor, expr);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
rc = SEPOL_ERR;
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_constrain_expr_to_sepol_expr_helper(policydb_t *pdb, const struct cil_db *db, const struct cil_list *cil_expr, constraint_expr_t **head, constraint_expr_t **tail)
{
int rc = SEPOL_ERR;
struct cil_list_item *item;
enum cil_flavor flavor;
enum cil_flavor cil_op;
constraint_expr_t *op, *h1, *h2, *t1, *t2;
int is_leaf = CIL_FALSE;
if (cil_expr == NULL) {
return SEPOL_ERR;
}
item = cil_expr->head;
flavor = cil_expr->flavor;
op = cil_malloc(sizeof(constraint_expr_t));
rc = constraint_expr_init(op);
if (rc != SEPOL_OK) {
goto exit;
}
cil_op = (enum cil_flavor)(uintptr_t)item->data;
switch (cil_op) {
case CIL_NOT:
op->expr_type = CEXPR_NOT;
break;
case CIL_AND:
op->expr_type = CEXPR_AND;
break;
case CIL_OR:
op->expr_type = CEXPR_OR;
break;
case CIL_EQ:
op->op = CEXPR_EQ;
is_leaf = CIL_TRUE;
break;
case CIL_NEQ:
op->op = CEXPR_NEQ;
is_leaf = CIL_TRUE;
break;
case CIL_CONS_DOM:
op->op = CEXPR_DOM;
is_leaf = CIL_TRUE;
break;
case CIL_CONS_DOMBY:
op->op = CEXPR_DOMBY;
is_leaf = CIL_TRUE;
break;
case CIL_CONS_INCOMP:
op->op = CEXPR_INCOMP;
is_leaf = CIL_TRUE;
break;
default:
goto exit;
}
if (is_leaf == CIL_TRUE) {
rc = __cil_constrain_expr_leaf_to_sepol_expr(pdb, db, item, flavor, op);
if (rc != SEPOL_OK) {
goto exit;
}
*head = op;
*tail = op;
} else if (cil_op == CIL_NOT) {
struct cil_list *l_expr = item->next->data;
rc = __cil_constrain_expr_to_sepol_expr_helper(pdb, db, l_expr, &h1, &t1);
if (rc != SEPOL_OK) {
goto exit;
}
t1->next = op;
*head = h1;
*tail = op;
} else {
struct cil_list *l_expr = item->next->data;
struct cil_list *r_expr = item->next->next->data;
rc = __cil_constrain_expr_to_sepol_expr_helper(pdb, db, l_expr, &h1, &t1);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_constrain_expr_to_sepol_expr_helper(pdb, db, r_expr, &h2, &t2);
if (rc != SEPOL_OK) {
constraint_expr_destroy(h1);
goto exit;
}
t1->next = h2;
t2->next = op;
*head = h1;
*tail = op;
}
return SEPOL_OK;
exit:
constraint_expr_destroy(op);
return SEPOL_ERR;
}
static int __cil_constrain_expr_to_sepol_expr(policydb_t *pdb, const struct cil_db *db, const struct cil_list *cil_expr, constraint_expr_t **sepol_expr)
{
int rc;
constraint_expr_t *head, *tail;
rc = __cil_constrain_expr_to_sepol_expr_helper(pdb, db, cil_expr, &head, &tail);
if (rc != SEPOL_OK) {
return SEPOL_ERR;
}
*sepol_expr = head;
return SEPOL_OK;
}
static int __cil_validate_constrain_expr(constraint_expr_t *sepol_expr)
{
constraint_expr_t *e;
int depth = -1;
for (e = sepol_expr; e != NULL; e = e->next) {
switch (e->expr_type) {
case CEXPR_NOT:
if (depth < 0) {
cil_log(CIL_ERR,"Invalid constraint expression\n");
return SEPOL_ERR;
}
break;
case CEXPR_AND:
case CEXPR_OR:
if (depth < 1) {
cil_log(CIL_ERR,"Invalid constraint expression\n");
return SEPOL_ERR;
}
depth--;
break;
case CEXPR_ATTR:
case CEXPR_NAMES:
if (depth == (CEXPR_MAXDEPTH - 1)) {
cil_log(CIL_ERR,"Constraint expression exceeded max allowable depth\n");
return SEPOL_ERR;
}
depth++;
break;
default:
cil_log(CIL_ERR,"Invalid constraint expression\n");
return SEPOL_ERR;
}
}
if (depth != 0) {
cil_log(CIL_ERR,"Invalid constraint expression\n");
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int cil_constrain_to_policydb_helper(policydb_t *pdb, const struct cil_db *db, struct cil_symtab_datum *class, struct cil_list *perms, struct cil_list *expr)
{
int rc = SEPOL_ERR;
constraint_node_t *sepol_constrain = NULL;
constraint_expr_t *sepol_expr = NULL;
class_datum_t *sepol_class = NULL;
sepol_constrain = cil_malloc(sizeof(*sepol_constrain));
memset(sepol_constrain, 0, sizeof(constraint_node_t));
rc = __cil_get_sepol_class_datum(pdb, class, &sepol_class);
if (rc != SEPOL_OK) goto exit;
rc = __cil_perms_to_datum(perms, sepol_class, &sepol_constrain->permissions);
if (rc != SEPOL_OK) {
goto exit;
}
if (sepol_constrain->permissions == 0) {
/* No permissions, so don't insert rule. */
free(sepol_constrain);
return SEPOL_OK;
}
rc = __cil_constrain_expr_to_sepol_expr(pdb, db, expr, &sepol_expr);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_validate_constrain_expr(sepol_expr);
if (rc != SEPOL_OK) {
goto exit;
}
sepol_constrain->expr = sepol_expr;
sepol_constrain->next = sepol_class->constraints;
sepol_class->constraints = sepol_constrain;
return SEPOL_OK;
exit:
constraint_expr_destroy(sepol_expr);
free(sepol_constrain);
return rc;
}
static int cil_constrain_expand(policydb_t *pdb, const struct cil_db *db, struct cil_list *classperms, struct cil_list *expr)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
cil_list_for_each(curr, classperms) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
rc = cil_constrain_to_policydb_helper(pdb, db, DATUM(cp->class), cp->perms, expr);
if (rc != SEPOL_OK) {
goto exit;
}
} else { /* MAP */
struct cil_list_item *i = NULL;
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
rc = cil_constrain_expand(pdb, db, cmp->classperms, expr);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
rc = cil_constrain_expand(pdb, db, cp->classperms, expr);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_constrain_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_constrain *cil_constrain)
{
int rc = SEPOL_ERR;
rc = cil_constrain_expand(pdb, db, cil_constrain->classperms, cil_constrain->datum_expr);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to insert constraint into policydb\n");
return rc;
}
static int cil_validatetrans_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_validatetrans *cil_validatetrans)
{
int rc = SEPOL_ERR;
struct cil_list *expr = cil_validatetrans->datum_expr;
class_datum_t *sepol_class = NULL;
struct cil_list *class_list;
constraint_node_t *sepol_validatetrans = NULL;
constraint_expr_t *sepol_expr = NULL;
struct cil_list_item *c;
class_list = cil_expand_class(cil_validatetrans->class);
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_class);
if (rc != SEPOL_OK) goto exit;
sepol_validatetrans = cil_malloc(sizeof(*sepol_validatetrans));
memset(sepol_validatetrans, 0, sizeof(constraint_node_t));
rc = __cil_constrain_expr_to_sepol_expr(pdb, db, expr, &sepol_expr);
if (rc != SEPOL_OK) {
free(sepol_validatetrans);
goto exit;
}
sepol_validatetrans->expr = sepol_expr;
sepol_validatetrans->next = sepol_class->validatetrans;
sepol_class->validatetrans = sepol_validatetrans;
}
rc = SEPOL_OK;
exit:
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
static int __cil_cats_to_mls_level(policydb_t *pdb, struct cil_cats *cats, mls_level_t *mls_level)
{
int rc = SEPOL_ERR;
struct cil_list_item *i;
cat_datum_t *sepol_cat = NULL;
cil_list_for_each(i, cats->datum_expr) {
struct cil_tree_node *node = NODE(i->data);
if (node->flavor == CIL_CATSET) {
struct cil_list_item *j;
struct cil_catset *cs = i->data;
cil_list_for_each(j, cs->cats->datum_expr) {
rc = __cil_get_sepol_cat_datum(pdb, j->data, &sepol_cat);
if (rc != SEPOL_OK) goto exit;
rc = ebitmap_set_bit(&mls_level->cat, sepol_cat->s.value - 1, 1);
if (rc != SEPOL_OK) goto exit;
}
} else {
rc = __cil_get_sepol_cat_datum(pdb, i->data, &sepol_cat);
if (rc != SEPOL_OK) goto exit;
rc = ebitmap_set_bit(&mls_level->cat, sepol_cat->s.value - 1, 1);
if (rc != SEPOL_OK) goto exit;
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
int cil_sepol_level_define(policydb_t *pdb, struct cil_sens *cil_sens)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
level_datum_t *sepol_level = NULL;
mls_level_t *mls_level = NULL;
rc = __cil_get_sepol_level_datum(pdb, DATUM(cil_sens), &sepol_level);
if (rc != SEPOL_OK) goto exit;
mls_level = sepol_level->level;
ebitmap_init(&mls_level->cat);
if (cil_sens->cats_list) {
cil_list_for_each(curr, cil_sens->cats_list) {
struct cil_cats *cats = curr->data;
rc = __cil_cats_to_mls_level(pdb, cats, mls_level);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to insert category set into sepol mls level\n");
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_level_to_mls_level(policydb_t *pdb, struct cil_level *cil_level, mls_level_t *mls_level)
{
int rc = SEPOL_ERR;
struct cil_sens *cil_sens = cil_level->sens;
struct cil_cats *cats = cil_level->cats;
level_datum_t *sepol_level = NULL;
rc = __cil_get_sepol_level_datum(pdb, DATUM(cil_sens), &sepol_level);
if (rc != SEPOL_OK) goto exit;
mls_level->sens = sepol_level->level->sens;
ebitmap_init(&mls_level->cat);
if (cats != NULL) {
rc = __cil_cats_to_mls_level(pdb, cats, mls_level);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to insert category set into sepol mls level\n");
goto exit;
}
}
rc = SEPOL_OK;
exit:
return rc;
}
static int __cil_levelrange_to_mls_range(policydb_t *pdb, struct cil_levelrange *cil_lvlrange, mls_range_t *mls_range)
{
int rc = SEPOL_ERR;
struct cil_level *low = cil_lvlrange->low;
struct cil_level *high = cil_lvlrange->high;
mls_level_t *mls_level = NULL;
mls_level = &mls_range->level[0];
rc = cil_level_to_mls_level(pdb, low, mls_level);
if (rc != SEPOL_OK) {
goto exit;
}
mls_level = &mls_range->level[1];
rc = cil_level_to_mls_level(pdb, high, mls_level);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_userlevel_userrange_to_policydb(policydb_t *pdb, struct cil_user *cil_user)
{
int rc = SEPOL_ERR;
struct cil_level *cil_level = cil_user->dftlevel;
struct cil_levelrange *cil_levelrange = cil_user->range;
user_datum_t *sepol_user = NULL;
rc = __cil_get_sepol_user_datum(pdb, DATUM(cil_user), &sepol_user);
if (rc != SEPOL_OK) goto exit;
rc = cil_level_to_mls_level(pdb, cil_level, &sepol_user->exp_dfltlevel);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_levelrange_to_mls_range(pdb, cil_levelrange, &sepol_user->exp_range);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_context_to_sepol_context(policydb_t *pdb, struct cil_context *cil_context, context_struct_t *sepol_context)
{
int rc = SEPOL_ERR;
struct cil_levelrange *cil_lvlrange = cil_context->range;
user_datum_t *sepol_user = NULL;
role_datum_t *sepol_role = NULL;
type_datum_t *sepol_type = NULL;
rc = __cil_get_sepol_user_datum(pdb, DATUM(cil_context->user), &sepol_user);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_role_datum(pdb, DATUM(cil_context->role), &sepol_role);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_type_datum(pdb, DATUM(cil_context->type), &sepol_type);
if (rc != SEPOL_OK) goto exit;
sepol_context->user = sepol_user->s.value;
sepol_context->role = sepol_role->s.value;
sepol_context->type = sepol_type->s.value;
if (pdb->mls == CIL_TRUE) {
mls_context_init(sepol_context);
rc = __cil_levelrange_to_mls_range(pdb, cil_lvlrange, &sepol_context->range);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR,"Problem with MLS\n");
mls_context_destroy(sepol_context);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_sidorder_to_policydb(policydb_t *pdb, const struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
unsigned count = 0;
ocontext_t *tail = NULL;
if (db->sidorder == NULL || db->sidorder->head == NULL) {
cil_log(CIL_WARN, "No sidorder statement in policy\n");
return SEPOL_OK;
}
cil_list_for_each(curr, db->sidorder) {
struct cil_sid *cil_sid = (struct cil_sid*)curr->data;
struct cil_context *cil_context = cil_sid->context;
/* even if no context, we must preserve initial SID values */
count++;
if (cil_context != NULL) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_ISID], &tail);
new_ocon->sid[0] = count;
new_ocon->u.name = cil_strdup(cil_sid->datum.fqn);
rc = __cil_context_to_sepol_context(pdb, cil_context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR,"Problem with context for SID %s\n",cil_sid->datum.fqn);
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_rangetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_rangetransition *rangetrans)
{
int rc = SEPOL_ERR;
type_datum_t *sepol_src = NULL;
type_datum_t *sepol_tgt = NULL;
class_datum_t *sepol_class = NULL;
struct cil_list *class_list = NULL;
range_trans_t *newkey = NULL;
struct mls_range *newdatum = NULL;
ebitmap_t src_bitmap, tgt_bitmap;
ebitmap_node_t *node1, *node2;
unsigned int i, j;
struct cil_list_item *c;
struct mls_range *o_range = NULL;
rc = __cil_expand_type(rangetrans->src, &src_bitmap);
if (rc != SEPOL_OK) goto exit;
rc = __cil_expand_type(rangetrans->exec, &tgt_bitmap);
if (rc != SEPOL_OK) goto exit;
class_list = cil_expand_class(rangetrans->obj);
ebitmap_for_each_positive_bit(&src_bitmap, node1, i) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[i]), &sepol_src);
if (rc != SEPOL_OK) goto exit;
ebitmap_for_each_positive_bit(&tgt_bitmap, node2, j) {
rc = __cil_get_sepol_type_datum(pdb, DATUM(db->val_to_type[j]), &sepol_tgt);
if (rc != SEPOL_OK) goto exit;
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_class);
if (rc != SEPOL_OK) goto exit;
newkey = cil_calloc(1, sizeof(*newkey));
newdatum = cil_calloc(1, sizeof(*newdatum));
newkey->source_type = sepol_src->s.value;
newkey->target_type = sepol_tgt->s.value;
newkey->target_class = sepol_class->s.value;
rc = __cil_levelrange_to_mls_range(pdb, rangetrans->range, newdatum);
if (rc != SEPOL_OK) {
free(newkey);
free(newdatum);
goto exit;
}
rc = hashtab_insert(pdb->range_tr, (hashtab_key_t)newkey, newdatum);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
o_range = hashtab_search(pdb->range_tr, (hashtab_key_t)newkey);
if (!mls_range_eq(newdatum, o_range)) {
cil_log(CIL_ERR, "Conflicting Range transition rules\n");
} else {
rc = SEPOL_OK;
}
} else {
cil_log(CIL_ERR, "Out of memory\n");
}
// TODO: add upper version bound once fixed in upstream GCC
#if defined(__GNUC__) && (__GNUC__ >= 12)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Warray-bounds"
# pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
mls_range_destroy(newdatum);
#if defined(__GNUC__) && (__GNUC__ >= 12)
# pragma GCC diagnostic pop
#endif
free(newdatum);
free(newkey);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
}
}
rc = SEPOL_OK;
exit:
ebitmap_destroy(&src_bitmap);
ebitmap_destroy(&tgt_bitmap);
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
int cil_ibpkeycon_to_policydb(policydb_t *pdb, struct cil_sort *ibpkeycons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
struct in6_addr subnet_prefix;
for (i = 0; i < ibpkeycons->count; i++) {
struct cil_ibpkeycon *cil_ibpkeycon = ibpkeycons->array[i];
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_IBPKEY], &tail);
rc = inet_pton(AF_INET6, cil_ibpkeycon->subnet_prefix_str, &subnet_prefix);
if (rc != 1) {
cil_log(CIL_ERR, "ibpkeycon subnet prefix not in valid IPV6 format\n");
rc = SEPOL_ERR;
goto exit;
}
memcpy(&new_ocon->u.ibpkey.subnet_prefix, &subnet_prefix.s6_addr[0],
sizeof(new_ocon->u.ibpkey.subnet_prefix));
new_ocon->u.ibpkey.low_pkey = cil_ibpkeycon->pkey_low;
new_ocon->u.ibpkey.high_pkey = cil_ibpkeycon->pkey_high;
rc = __cil_context_to_sepol_context(pdb, cil_ibpkeycon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_portcon_to_policydb(policydb_t *pdb, struct cil_sort *portcons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < portcons->count; i++) {
struct cil_portcon *cil_portcon = portcons->array[i];
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_PORT], &tail);
switch (cil_portcon->proto) {
case CIL_PROTOCOL_UDP:
new_ocon->u.port.protocol = IPPROTO_UDP;
break;
case CIL_PROTOCOL_TCP:
new_ocon->u.port.protocol = IPPROTO_TCP;
break;
case CIL_PROTOCOL_DCCP:
new_ocon->u.port.protocol = IPPROTO_DCCP;
break;
case CIL_PROTOCOL_SCTP:
new_ocon->u.port.protocol = IPPROTO_SCTP;
break;
default:
/* should not get here */
rc = SEPOL_ERR;
goto exit;
}
new_ocon->u.port.low_port = cil_portcon->port_low;
new_ocon->u.port.high_port = cil_portcon->port_high;
rc = __cil_context_to_sepol_context(pdb, cil_portcon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_netifcon_to_policydb(policydb_t *pdb, struct cil_sort *netifcons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < netifcons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_NETIF], &tail);
struct cil_netifcon *cil_netifcon = netifcons->array[i];
new_ocon->u.name = cil_strdup(cil_netifcon->interface_str);
rc = __cil_context_to_sepol_context(pdb, cil_netifcon->if_context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_context_to_sepol_context(pdb, cil_netifcon->packet_context, &new_ocon->context[1]);
if (rc != SEPOL_OK) {
context_destroy(&new_ocon->context[0]);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_ibendportcon_to_policydb(policydb_t *pdb, struct cil_sort *ibendportcons)
{
int rc = SEPOL_ERR;
uint32_t i;
ocontext_t *tail = NULL;
for (i = 0; i < ibendportcons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_IBENDPORT], &tail);
struct cil_ibendportcon *cil_ibendportcon = ibendportcons->array[i];
new_ocon->u.ibendport.dev_name = cil_strdup(cil_ibendportcon->dev_name_str);
new_ocon->u.ibendport.port = cil_ibendportcon->port;
rc = __cil_context_to_sepol_context(pdb, cil_ibendportcon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_nodecon_to_policydb(policydb_t *pdb, struct cil_sort *nodecons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
ocontext_t *tail6 = NULL;
for (i = 0; i < nodecons->count; i++) {
ocontext_t *new_ocon = NULL;
struct cil_nodecon *cil_nodecon = nodecons->array[i];
if (cil_nodecon->addr->family == AF_INET) {
new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_NODE], &tail);
new_ocon->u.node.addr = cil_nodecon->addr->ip.v4.s_addr;
new_ocon->u.node.mask = cil_nodecon->mask->ip.v4.s_addr;
} else if (cil_nodecon->addr->family == AF_INET6) {
new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_NODE6], &tail6);
memcpy(new_ocon->u.node6.addr, &cil_nodecon->addr->ip.v6.s6_addr[0], 16);
memcpy(new_ocon->u.node6.mask, &cil_nodecon->mask->ip.v6.s6_addr[0], 16);
} else {
/* should not get here */
rc = SEPOL_ERR;
goto exit;
}
rc = __cil_context_to_sepol_context(pdb, cil_nodecon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_fsuse_to_policydb(policydb_t *pdb, struct cil_sort *fsuses)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < fsuses->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_FSUSE], &tail);
struct cil_fsuse *cil_fsuse = fsuses->array[i];
new_ocon->u.name = cil_strdup(cil_fsuse->fs_str);
new_ocon->v.behavior = cil_fsuse->type;
rc = __cil_context_to_sepol_context(pdb, cil_fsuse->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_genfscon_to_policydb(policydb_t *pdb, struct cil_sort *genfscons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
genfs_t *genfs_tail = NULL;
ocontext_t *ocon_tail = NULL;
for (i = 0; i < genfscons->count; i++) {
struct cil_genfscon *cil_genfscon = genfscons->array[i];
ocontext_t *new_ocon = cil_malloc(sizeof(ocontext_t));
memset(new_ocon, 0, sizeof(ocontext_t));
if (genfs_tail && strcmp(genfs_tail->fstype, cil_genfscon->fs_str) == 0) {
ocon_tail->next = new_ocon;
} else {
genfs_t *new_genfs = cil_malloc(sizeof(genfs_t));
memset(new_genfs, 0, sizeof(genfs_t));
new_genfs->fstype = cil_strdup(cil_genfscon->fs_str);
new_genfs->head = new_ocon;
if (genfs_tail) {
genfs_tail->next = new_genfs;
} else {
pdb->genfs = new_genfs;
}
genfs_tail = new_genfs;
}
ocon_tail = new_ocon;
new_ocon->u.name = cil_strdup(cil_genfscon->path_str);
if (cil_genfscon->file_type != CIL_FILECON_ANY) {
class_datum_t *class_datum;
const char *class_name;
switch (cil_genfscon->file_type) {
case CIL_FILECON_FILE:
class_name = "file";
break;
case CIL_FILECON_DIR:
class_name = "dir";
break;
case CIL_FILECON_CHAR:
class_name = "chr_file";
break;
case CIL_FILECON_BLOCK:
class_name = "blk_file";
break;
case CIL_FILECON_SOCKET:
class_name = "sock_file";
break;
case CIL_FILECON_PIPE:
class_name = "fifo_file";
break;
case CIL_FILECON_SYMLINK:
class_name = "lnk_file";
break;
default:
rc = SEPOL_ERR;
goto exit;
}
class_datum = hashtab_search(pdb->p_classes.table, class_name);
if (!class_datum) {
rc = SEPOL_ERR;
goto exit;
}
new_ocon->v.sclass = class_datum->s.value;
}
rc = __cil_context_to_sepol_context(pdb, cil_genfscon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_pirqcon_to_policydb(policydb_t *pdb, struct cil_sort *pirqcons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < pirqcons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_XEN_PIRQ], &tail);
struct cil_pirqcon *cil_pirqcon = pirqcons->array[i];
new_ocon->u.pirq = cil_pirqcon->pirq;
rc = __cil_context_to_sepol_context(pdb, cil_pirqcon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_iomemcon_to_policydb(policydb_t *pdb, struct cil_sort *iomemcons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < iomemcons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_XEN_IOMEM], &tail);
struct cil_iomemcon *cil_iomemcon = iomemcons->array[i];
new_ocon->u.iomem.low_iomem = cil_iomemcon->iomem_low;
new_ocon->u.iomem.high_iomem = cil_iomemcon->iomem_high;
rc = __cil_context_to_sepol_context(pdb, cil_iomemcon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_ioportcon_to_policydb(policydb_t *pdb, struct cil_sort *ioportcons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < ioportcons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_XEN_IOPORT], &tail);
struct cil_ioportcon *cil_ioportcon = ioportcons->array[i];
new_ocon->u.ioport.low_ioport = cil_ioportcon->ioport_low;
new_ocon->u.ioport.high_ioport = cil_ioportcon->ioport_high;
rc = __cil_context_to_sepol_context(pdb, cil_ioportcon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_pcidevicecon_to_policydb(policydb_t *pdb, struct cil_sort *pcidevicecons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < pcidevicecons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_XEN_PCIDEVICE], &tail);
struct cil_pcidevicecon *cil_pcidevicecon = pcidevicecons->array[i];
new_ocon->u.device = cil_pcidevicecon->dev;
rc = __cil_context_to_sepol_context(pdb, cil_pcidevicecon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_devicetreecon_to_policydb(policydb_t *pdb, struct cil_sort *devicetreecons)
{
int rc = SEPOL_ERR;
uint32_t i = 0;
ocontext_t *tail = NULL;
for (i = 0; i < devicetreecons->count; i++) {
ocontext_t *new_ocon = cil_add_ocontext(&pdb->ocontexts[OCON_XEN_DEVICETREE], &tail);
struct cil_devicetreecon *cil_devicetreecon = devicetreecons->array[i];
new_ocon->u.name = cil_strdup(cil_devicetreecon->path);
rc = __cil_context_to_sepol_context(pdb, cil_devicetreecon->context, &new_ocon->context[0]);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_default_to_policydb(policydb_t *pdb, struct cil_default *def)
{
struct cil_list_item *curr;
class_datum_t *sepol_class;
struct cil_list *class_list = NULL;
cil_list_for_each(curr, def->class_datums) {
struct cil_list_item *c;
class_list = cil_expand_class(curr->data);
cil_list_for_each(c, class_list) {
int rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_class);
if (rc != SEPOL_OK) goto exit;
switch (def->flavor) {
case CIL_DEFAULTUSER:
if (!sepol_class->default_user) {
sepol_class->default_user = def->object;
} else if (sepol_class->default_user != (char)def->object) {
cil_log(CIL_ERR,"User default labeling for class %s already specified\n",DATUM(c->data)->fqn);
goto exit;
}
break;
case CIL_DEFAULTROLE:
if (!sepol_class->default_role) {
sepol_class->default_role = def->object;
} else if (sepol_class->default_role != (char)def->object) {
cil_log(CIL_ERR,"Role default labeling for class %s already specified\n",DATUM(c->data)->fqn);
goto exit;
}
break;
case CIL_DEFAULTTYPE:
if (!sepol_class->default_type) {
sepol_class->default_type = def->object;
} else if (sepol_class->default_type != (char)def->object) {
cil_log(CIL_ERR,"Type default labeling for class %s already specified\n",DATUM(c->data)->fqn);
goto exit;
}
break;
default:
goto exit;
}
}
cil_list_destroy(&class_list, CIL_FALSE);
}
return SEPOL_OK;
exit:
cil_list_destroy(&class_list, CIL_FALSE);
return SEPOL_ERR;
}
static int cil_defaultrange_to_policydb(policydb_t *pdb, struct cil_defaultrange *def)
{
struct cil_list_item *curr;
class_datum_t *sepol_class;
struct cil_list *class_list = NULL;
cil_list_for_each(curr, def->class_datums) {
struct cil_list_item *c;
class_list = cil_expand_class(curr->data);
cil_list_for_each(c, class_list) {
int rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_class);
if (rc != SEPOL_OK) goto exit;
if (!sepol_class->default_range) {
sepol_class->default_range = def->object_range;
} else if (sepol_class->default_range != (char)def->object_range) {
cil_log(CIL_ERR,"Range default labeling for class %s already specified\n", DATUM(curr->data)->fqn);
goto exit;
}
}
cil_list_destroy(&class_list, CIL_FALSE);
}
return SEPOL_OK;
exit:
cil_list_destroy(&class_list, CIL_FALSE);
return SEPOL_ERR;
}
static int __cil_node_to_policydb(struct cil_tree_node *node, void *extra_args)
{
int rc = SEPOL_OK;
int pass;
struct cil_args_binary *args = extra_args;
const struct cil_db *db;
policydb_t *pdb;
hashtab_t role_trans_table;
void **type_value_to_cil;
db = args->db;
pdb = args->pdb;
pass = args->pass;
role_trans_table = args->role_trans_table;
type_value_to_cil = args->type_value_to_cil;
if (node->flavor >= CIL_MIN_DECLARATIVE) {
if (node != NODE(node->data)) {
goto exit;
}
}
switch (pass) {
case 1:
switch (node->flavor) {
case CIL_ROLE:
rc = cil_role_to_policydb(pdb, node->data);
break;
case CIL_TYPE:
rc = cil_type_to_policydb(pdb, node->data, type_value_to_cil);
break;
case CIL_TYPEATTRIBUTE:
rc = cil_typeattribute_to_policydb(pdb, node->data, type_value_to_cil);
break;
case CIL_POLICYCAP:
rc = cil_policycap_to_policydb(pdb, node->data);
break;
case CIL_USER:
rc = cil_user_to_policydb(pdb, node->data);
break;
case CIL_BOOL:
rc = cil_bool_to_policydb(pdb, node->data);
break;
case CIL_CATALIAS:
if (pdb->mls == CIL_TRUE) {
rc = cil_catalias_to_policydb(pdb, node->data);
}
break;
case CIL_SENS:
if (pdb->mls == CIL_TRUE) {
rc = cil_sepol_level_define(pdb, node->data);
}
break;
default:
break;
}
break;
case 2:
switch (node->flavor) {
case CIL_TYPE:
rc = cil_type_bounds_to_policydb(pdb, node->data);
break;
case CIL_TYPEALIAS:
rc = cil_typealias_to_policydb(pdb, node->data);
break;
case CIL_TYPEPERMISSIVE:
rc = cil_typepermissive_to_policydb(pdb, node->data);
break;
case CIL_TYPEATTRIBUTE:
rc = cil_typeattribute_to_bitmap(pdb, db, node->data);
break;
case CIL_SENSALIAS:
if (pdb->mls == CIL_TRUE) {
rc = cil_sensalias_to_policydb(pdb, node->data);
}
break;
case CIL_ROLE:
rc = cil_role_bounds_to_policydb(pdb, node->data);
if (rc != SEPOL_OK) goto exit;
rc = cil_roletype_to_policydb(pdb, db, node->data);
break;
case CIL_USER:
rc = cil_user_bounds_to_policydb(pdb, node->data);
if (rc != SEPOL_OK) goto exit;
if (pdb->mls == CIL_TRUE) {
rc = cil_userlevel_userrange_to_policydb(pdb, node->data);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = cil_userrole_to_policydb(pdb, db, node->data);
break;
case CIL_TYPE_RULE:
rc = cil_type_rule_to_policydb(pdb, db, node->data);
break;
case CIL_AVRULE:
case CIL_AVRULEX: {
struct cil_avrule *rule = node->data;
if (db->disable_neverallow != CIL_TRUE && rule->rule_kind == CIL_AVRULE_NEVERALLOW) {
struct cil_list *neverallows = args->neverallows;
cil_list_prepend(neverallows, CIL_LIST_ITEM, node);
}
break;
}
case CIL_ROLETRANSITION:
rc = cil_roletrans_to_policydb(pdb, db, node->data, role_trans_table);
break;
case CIL_ROLEATTRIBUTESET:
/*rc = cil_roleattributeset_to_policydb(pdb, node->data);*/
break;
case CIL_NAMETYPETRANSITION:
rc = cil_typetransition_to_policydb(pdb, db, node->data);
break;
case CIL_CONSTRAIN:
rc = cil_constrain_to_policydb(pdb, db, node->data);
break;
case CIL_MLSCONSTRAIN:
if (pdb->mls == CIL_TRUE) {
rc = cil_constrain_to_policydb(pdb, db, node->data);
}
break;
case CIL_VALIDATETRANS:
rc = cil_validatetrans_to_policydb(pdb, db, node->data);
break;
case CIL_MLSVALIDATETRANS:
if (pdb->mls == CIL_TRUE) {
rc = cil_validatetrans_to_policydb(pdb, db, node->data);
}
break;
case CIL_RANGETRANSITION:
if (pdb->mls == CIL_TRUE) {
rc = cil_rangetransition_to_policydb(pdb, db, node->data);
}
break;
case CIL_DEFAULTUSER:
case CIL_DEFAULTROLE:
case CIL_DEFAULTTYPE:
rc = cil_default_to_policydb(pdb, node->data);
break;
case CIL_DEFAULTRANGE:
rc = cil_defaultrange_to_policydb(pdb, node->data);
break;
default:
break;
}
break;
case 3:
switch (node->flavor) {
case CIL_BOOLEANIF:
rc = cil_booleanif_to_policydb(pdb, db, node);
break;
case CIL_AVRULE: {
struct cil_avrule *rule = node->data;
if (rule->rule_kind != CIL_AVRULE_NEVERALLOW) {
rc = cil_avrule_to_policydb(pdb, db, node->data);
}
}
break;
case CIL_AVRULEX: {
struct cil_avrule *rule = node->data;
if (rule->rule_kind != CIL_AVRULE_NEVERALLOW) {
rc = cil_avrulex_to_hashtable(pdb, db, node->data, &args->avrulex_xperm_tables);
}
}
break;
case CIL_ROLEALLOW:
rc = cil_roleallow_to_policydb(pdb, db, node->data);
break;
default:
break;
}
default:
break;
}
exit:
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Binary policy creation failed");
}
return rc;
}
static int __cil_binary_create_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
if (node->flavor == CIL_BLOCK) {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
rc = SEPOL_OK;
goto exit;
}
} else if (node->flavor == CIL_MACRO) {
*finished = CIL_TREE_SKIP_HEAD;
rc = SEPOL_OK;
goto exit;
} else if (node->flavor == CIL_BOOLEANIF) {
*finished = CIL_TREE_SKIP_HEAD;
}
rc = __cil_node_to_policydb(node, extra_args);
if (rc != SEPOL_OK) {
goto exit;
}
exit:
return rc;
}
static int __cil_contexts_to_policydb(policydb_t *pdb, const struct cil_db *db)
{
int rc = SEPOL_ERR;
rc = cil_portcon_to_policydb(pdb, db->portcon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_netifcon_to_policydb(pdb, db->netifcon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_nodecon_to_policydb(pdb, db->nodecon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fsuse_to_policydb(pdb, db->fsuse);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_genfscon_to_policydb(pdb, db->genfscon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_ibpkeycon_to_policydb(pdb, db->ibpkeycon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_ibendportcon_to_policydb(pdb, db->ibendportcon);
if (rc != SEPOL_OK) {
goto exit;
}
if (db->target_platform == SEPOL_TARGET_XEN) {
rc = cil_pirqcon_to_policydb(pdb, db->pirqcon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_iomemcon_to_policydb(pdb, db->iomemcon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_ioportcon_to_policydb(pdb, db->ioportcon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_pcidevicecon_to_policydb(pdb, db->pcidevicecon);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_devicetreecon_to_policydb(pdb, db->devicetreecon);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_common_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
common_datum_t *common = (common_datum_t *)datum;
if (common->s.value < 1 || common->s.value > pdb->p_commons.nprim) {
return -EINVAL;
}
pdb->p_common_val_to_name[common->s.value - 1] = (char *)key;
return 0;
}
static int __cil_class_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
class_datum_t *class = (class_datum_t *)datum;
if (class->s.value < 1 || class->s.value > pdb->p_classes.nprim) {
return -EINVAL;
}
pdb->p_class_val_to_name[class->s.value - 1] = (char *)key;
pdb->class_val_to_struct[class->s.value - 1] = class;
return 0;
}
static int __cil_role_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
role_datum_t *role = (role_datum_t *)datum;
if (role->s.value < 1 || role->s.value > pdb->p_roles.nprim) {
return -EINVAL;
}
pdb->p_role_val_to_name[role->s.value - 1] = (char *)key;
pdb->role_val_to_struct[role->s.value - 1] = role;
return 0;
}
static int __cil_type_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
type_datum_t *type = (type_datum_t *)datum;
if (type->s.value < 1 || type->s.value > pdb->p_types.nprim) {
return -EINVAL;
}
pdb->p_type_val_to_name[type->s.value - 1] = (char *)key;
pdb->type_val_to_struct[type->s.value - 1] = type;
return 0;
}
static int __cil_user_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
user_datum_t *user = (user_datum_t *)datum;
if (user->s.value < 1 || user->s.value > pdb->p_users.nprim) {
return -EINVAL;
}
pdb->p_user_val_to_name[user->s.value - 1] = (char *)key;
pdb->user_val_to_struct[user->s.value - 1] = user;
return 0;
}
static int __cil_bool_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
cond_bool_datum_t *boolean = (cond_bool_datum_t *)datum;
if (boolean->s.value < 1 || boolean->s.value > pdb->p_bools.nprim) {
return -EINVAL;
}
pdb->p_bool_val_to_name[boolean->s.value - 1] = (char *)key;
pdb->bool_val_to_struct[boolean->s.value - 1] = boolean;
return 0;
}
static int __cil_level_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
level_datum_t *level = (level_datum_t *)datum;
if (level->level->sens < 1 || level->level->sens > pdb->p_levels.nprim) {
return -EINVAL;
}
pdb->p_sens_val_to_name[level->level->sens - 1] = (char *)key;
return 0;
}
static int __cil_cat_val_array_insert(hashtab_key_t key, hashtab_datum_t datum, void *data)
{
policydb_t *pdb = data;
cat_datum_t *cat = (cat_datum_t *)datum;
if (cat->s.value < 1 || cat->s.value > pdb->p_cats.nprim) {
return -EINVAL;
}
pdb->p_cat_val_to_name[cat->s.value - 1] = (char *)key;
return 0;
}
static int __cil_policydb_val_arrays_create(policydb_t *policydb)
{
int rc = SEPOL_ERR;
policydb->p_common_val_to_name = cil_malloc(sizeof(char *) * policydb->p_commons.nprim);
rc = hashtab_map(policydb->p_commons.table, &__cil_common_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_class_val_to_name = cil_malloc(sizeof(char *) * policydb->p_classes.nprim);
policydb->class_val_to_struct = cil_malloc(sizeof(class_datum_t *) * policydb->p_classes.nprim);
rc = hashtab_map(policydb->p_classes.table, &__cil_class_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_role_val_to_name = cil_malloc(sizeof(char *) * policydb->p_roles.nprim);
policydb->role_val_to_struct = cil_malloc(sizeof(role_datum_t *) * policydb->p_roles.nprim);
rc = hashtab_map(policydb->p_roles.table, &__cil_role_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_type_val_to_name = cil_malloc(sizeof(char *) * policydb->p_types.nprim);
policydb->type_val_to_struct = cil_malloc(sizeof(type_datum_t *) * policydb->p_types.nprim);
rc = hashtab_map(policydb->p_types.table, &__cil_type_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_user_val_to_name = cil_malloc(sizeof(char *) * policydb->p_users.nprim);
policydb->user_val_to_struct = cil_malloc(sizeof(user_datum_t *) * policydb->p_users.nprim);
rc = hashtab_map(policydb->p_users.table, &__cil_user_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_bool_val_to_name = cil_malloc(sizeof(char *) * policydb->p_bools.nprim);
policydb->bool_val_to_struct = cil_malloc(sizeof(cond_bool_datum_t *) * policydb->p_bools.nprim);
rc = hashtab_map(policydb->p_bools.table, &__cil_bool_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_sens_val_to_name = cil_malloc(sizeof(char *) * policydb->p_levels.nprim);
rc = hashtab_map(policydb->p_levels.table, &__cil_level_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
policydb->p_cat_val_to_name = cil_malloc(sizeof(char *) * policydb->p_cats.nprim);
rc = hashtab_map(policydb->p_cats.table, &__cil_cat_val_array_insert, policydb);
if (rc != SEPOL_OK) {
goto exit;
}
exit:
return rc;
}
static void __cil_set_conditional_state_and_flags(policydb_t *pdb)
{
cond_node_t *cur;
for (cur = pdb->cond_list; cur != NULL; cur = cur->next) {
int new_state;
cond_av_list_t *c;
new_state = cond_evaluate_expr(pdb, cur->expr);
cur->cur_state = new_state;
if (new_state == -1) {
cil_log(CIL_WARN, "Expression result was undefined - disabling all rules\n");
}
for (c = cur->true_list; c != NULL; c = c->next) {
if (new_state <= 0) {
c->node->key.specified &= ~AVTAB_ENABLED;
} else {
c->node->key.specified |= AVTAB_ENABLED;
}
}
for (c = cur->false_list; c != NULL; c = c->next) {
if (new_state) { /* -1 or 1 */
c->node->key.specified &= ~AVTAB_ENABLED;
} else {
c->node->key.specified |= AVTAB_ENABLED;
}
}
}
}
static int __cil_policydb_create(const struct cil_db *db, struct sepol_policydb **spdb)
{
int rc;
struct policydb *pdb = NULL;
rc = sepol_policydb_create(spdb);
if (rc < 0) {
cil_log(CIL_ERR, "Failed to create policy db\n");
// spdb could be a dangling pointer at this point, so reset it so
// callers of this function don't need to worry about freeing garbage
*spdb = NULL;
goto exit;
}
pdb = &(*spdb)->p;
pdb->policy_type = POLICY_KERN;
pdb->target_platform = db->target_platform;
pdb->policyvers = db->policy_version;
pdb->handle_unknown = db->handle_unknown;
pdb->mls = db->mls;
return SEPOL_OK;
exit:
return rc;
}
static int __cil_policydb_init(policydb_t *pdb, const struct cil_db *db, struct cil_class *class_value_to_cil[], struct cil_perm **perm_value_to_cil[])
{
int rc = SEPOL_ERR;
// these flags should get set in __cil_policydb_create. However, for
// backwards compatibility, it is possible that __cil_policydb_create is
// never called. So, they must also be set here.
pdb->handle_unknown = db->handle_unknown;
pdb->mls = db->mls;
rc = cil_classorder_to_policydb(pdb, db, class_value_to_cil, perm_value_to_cil);
if (rc != SEPOL_OK) {
goto exit;
}
if (pdb->mls == CIL_TRUE) {
rc = cil_catorder_to_policydb(pdb, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_sensitivityorder_to_policydb(pdb, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = avtab_alloc(&pdb->te_avtab, MAX_AVTAB_SIZE);
if (rc != SEPOL_OK) {
goto exit;
}
rc = avtab_alloc(&pdb->te_cond_avtab, MAX_AVTAB_SIZE);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static unsigned int role_trans_hash(hashtab_t h, const_hashtab_key_t key)
{
const role_trans_t *k = (const role_trans_t *)key;
return ((k->role + (k->type << 2) +
(k->tclass << 5)) & (h->size - 1));
}
static int role_trans_compare(hashtab_t h
__attribute__ ((unused)), const_hashtab_key_t key1,
const_hashtab_key_t key2)
{
const role_trans_t *a = (const role_trans_t *)key1;
const role_trans_t *b = (const role_trans_t *)key2;
return a->role != b->role || a->type != b->type || a->tclass != b->tclass;
}
/* Based on MurmurHash3, written by Austin Appleby and placed in the
* public domain.
*/
static unsigned int avrulex_hash(__attribute__((unused)) hashtab_t h, const_hashtab_key_t key)
{
const avtab_key_t *k = (const avtab_key_t *)key;
static const uint32_t c1 = 0xcc9e2d51;
static const uint32_t c2 = 0x1b873593;
static const uint32_t r1 = 15;
static const uint32_t r2 = 13;
static const uint32_t m = 5;
static const uint32_t n = 0xe6546b64;
uint32_t hash = 0;
#define mix(input) do { \
uint32_t v = input; \
v *= c1; \
v = (v << r1) | (v >> (32 - r1)); \
v *= c2; \
hash ^= v; \
hash = (hash << r2) | (hash >> (32 - r2)); \
hash = hash * m + n; \
} while (0)
mix(k->target_class);
mix(k->target_type);
mix(k->source_type);
mix(k->specified);
#undef mix
hash ^= hash >> 16;
hash *= 0x85ebca6b;
hash ^= hash >> 13;
hash *= 0xc2b2ae35;
hash ^= hash >> 16;
return hash & (AVRULEX_TABLE_SIZE - 1);
}
static int avrulex_compare(hashtab_t h
__attribute__ ((unused)), const_hashtab_key_t key1,
const_hashtab_key_t key2)
{
const avtab_key_t *a = (const avtab_key_t *)key1;
const avtab_key_t *b = (const avtab_key_t *)key2;
return a->source_type != b->source_type || a->target_type != b->target_type || a->target_class != b->target_class || a->specified != b->specified;
}
int cil_binary_create(const struct cil_db *db, sepol_policydb_t **policydb)
{
int rc = SEPOL_ERR;
struct sepol_policydb *pdb = NULL;
rc = __cil_policydb_create(db, &pdb);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_binary_create_allocated_pdb(db, pdb);
if (rc != SEPOL_OK) {
goto exit;
}
*policydb = pdb;
return SEPOL_OK;
exit:
sepol_policydb_free(pdb);
return rc;
}
static void __cil_destroy_sepol_class_perms(class_perm_node_t *curr)
{
class_perm_node_t *next;
while (curr) {
next = curr->next;
free(curr);
curr = next;
}
}
static int __cil_rule_to_sepol_class_perms(policydb_t *pdb, struct cil_list *classperms, class_perm_node_t **sepol_class_perms)
{
int rc = SEPOL_ERR;
struct cil_list_item *i;
cil_list_for_each(i, classperms) {
if (i->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = i->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
class_perm_node_t *cpn = NULL;
class_datum_t *sepol_class = NULL;
uint32_t data = 0;
rc = __cil_get_sepol_class_datum(pdb, DATUM(cp->class), &sepol_class);
if (rc != SEPOL_OK) goto exit;
rc = __cil_perms_to_datum(cp->perms, sepol_class, &data);
if (rc != SEPOL_OK) goto exit;
if (data != 0) { /* Only add if there are permissions */
cpn = cil_malloc(sizeof(class_perm_node_t));
cpn->tclass = sepol_class->s.value;
cpn->data = data;
cpn->next = *sepol_class_perms;
*sepol_class_perms = cpn;
}
} else { /* MAP */
struct cil_list_item *j = NULL;
cil_list_for_each(j, cp->perms) {
struct cil_perm *cmp = j->data;
rc = __cil_rule_to_sepol_class_perms(pdb, cmp->classperms, sepol_class_perms);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = i->data;
struct cil_classpermission *cp = cp_set->set;
rc = __cil_rule_to_sepol_class_perms(pdb, cp->classperms, sepol_class_perms);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_permx_to_sepol_class_perms(policydb_t *pdb, struct cil_permissionx *permx, class_perm_node_t **sepol_class_perms)
{
int rc = SEPOL_OK;
struct cil_list *class_list = NULL;
struct cil_list_item *c;
class_datum_t *sepol_obj = NULL;
class_perm_node_t *cpn;
uint32_t data = 0;
char *perm_str = NULL;
class_list = cil_expand_class(permx->obj);
cil_list_for_each(c, class_list) {
rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
if (rc != SEPOL_OK) {
goto exit;
}
switch (permx->kind) {
case CIL_PERMX_KIND_IOCTL:
perm_str = CIL_KEY_IOCTL;
break;
case CIL_PERMX_KIND_NLMSG:
perm_str = CIL_KEY_NLMSG;
break;
default:
rc = SEPOL_ERR;
goto exit;
}
rc = __perm_str_to_datum(perm_str, sepol_obj, &data);
if (rc != SEPOL_OK) {
goto exit;
}
cpn = cil_malloc(sizeof(*cpn));
cpn->tclass = sepol_obj->s.value;
cpn->data = data;
cpn->next = *sepol_class_perms;
*sepol_class_perms = cpn;
}
exit:
cil_list_destroy(&class_list, CIL_FALSE);
return rc;
}
static void __cil_init_sepol_type_set(type_set_t *t)
{
ebitmap_init(&t->types);
ebitmap_init(&t->negset);
t->flags = 0;
}
static int __cil_add_sepol_type(policydb_t *pdb, const struct cil_db *db, struct cil_symtab_datum *datum, ebitmap_t *map)
{
int rc = SEPOL_ERR;
struct cil_tree_node *n = NODE(datum);
type_datum_t *sepol_datum = NULL;
if (n->flavor == CIL_TYPEATTRIBUTE) {
ebitmap_node_t *tnode;
unsigned int i;
struct cil_typeattribute *attr = (struct cil_typeattribute *)datum;
ebitmap_for_each_positive_bit(attr->types, tnode, i) {
datum = DATUM(db->val_to_type[i]);
rc = __cil_get_sepol_type_datum(pdb, datum, &sepol_datum);
if (rc != SEPOL_OK) goto exit;
ebitmap_set_bit(map, sepol_datum->s.value - 1, 1);
}
} else {
rc = __cil_get_sepol_type_datum(pdb, datum, &sepol_datum);
if (rc != SEPOL_OK) goto exit;
ebitmap_set_bit(map, sepol_datum->s.value - 1, 1);
}
return SEPOL_OK;
exit:
return rc;
}
static avrule_t *__cil_init_sepol_avrule(uint32_t kind, struct cil_tree_node *node)
{
avrule_t *avrule;
struct cil_tree_node *source_node;
char *source_path;
char *lm_kind;
uint32_t hll_line;
avrule = cil_malloc(sizeof(avrule_t));
avrule->specified = kind;
avrule->flags = 0;
__cil_init_sepol_type_set(&avrule->stypes);
__cil_init_sepol_type_set(&avrule->ttypes);
avrule->perms = NULL;
avrule->line = node->line;
avrule->source_filename = NULL;
avrule->source_line = node->line;
source_node = cil_tree_get_next_path(node, &lm_kind, &hll_line, &source_path);
if (source_node) {
avrule->source_filename = source_path;
if (lm_kind != CIL_KEY_SRC_CIL) {
avrule->source_line = hll_line + node->hll_offset - source_node->hll_offset - 1;
}
}
avrule->next = NULL;
return avrule;
}
static void __cil_destroy_sepol_avrules(avrule_t *curr)
{
avrule_t *next;
while (curr) {
next = curr->next;
ebitmap_destroy(&curr->stypes.types);
ebitmap_destroy(&curr->stypes.negset);
ebitmap_destroy(&curr->ttypes.types);
ebitmap_destroy(&curr->ttypes.negset);
__cil_destroy_sepol_class_perms(curr->perms);
free(curr);
curr = next;
}
}
static void __cil_print_parents(const char *pad, struct cil_tree_node *n)
{
if (!n) return;
__cil_print_parents(pad, n->parent);
if (n->flavor != CIL_SRC_INFO) {
cil_tree_log(n, CIL_ERR,"%s%s", pad, cil_node_to_string(n));
}
}
static void __cil_print_classperm(struct cil_list *cp_list)
{
struct cil_list_item *i1, *i2;
i1 = cp_list->head;
if (i1->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = i1->data;
cil_log(CIL_ERR,"(%s (", DATUM(cp->class)->fqn);
cil_list_for_each(i2, cp->perms) {
cil_log(CIL_ERR,"%s",DATUM(i2->data)->fqn);
if (i2 != cp->perms->tail) {
cil_log(CIL_ERR," ");
} else {
cil_log(CIL_ERR,"))");
}
}
} else {
struct cil_classperms_set *cp_set = i1->data;
cil_log(CIL_ERR,"%s", DATUM(cp_set->set)->fqn);
}
}
static void __cil_print_permissionx(struct cil_permissionx *px)
{
const char *kind_str = NULL;
char *expr_str;
kind_str = __cil_xperm_kind_to_str(px->kind);
__cil_expr_to_string(px->expr_str, CIL_PERMISSIONX, &expr_str);
cil_log(CIL_ERR, "%s %s (%s)", kind_str, DATUM(px->obj)->fqn, expr_str);
free(expr_str);
}
static void __cil_print_rule(const char *pad, const char *kind, struct cil_avrule *avrule)
{
cil_log(CIL_ERR,"%s(%s ", pad, kind);
cil_log(CIL_ERR,"%s %s ", DATUM(avrule->src)->fqn, DATUM(avrule->tgt)->fqn);
if (!avrule->is_extended) {
__cil_print_classperm(avrule->perms.classperms);
} else {
cil_log(CIL_ERR, "(");
__cil_print_permissionx(avrule->perms.x.permx);
cil_log(CIL_ERR, ")");
}
cil_log(CIL_ERR,")\n");
}
static int __cil_print_neverallow_failure(const struct cil_db *db, struct cil_tree_node *node)
{
int rc;
struct cil_list_item *i2;
struct cil_list *matching;
struct cil_avrule *cil_rule = node->data;
struct cil_avrule target;
struct cil_tree_node *n2;
struct cil_avrule *r2;
char *neverallow_str;
char *allow_str;
enum cil_flavor avrule_flavor;
int num_matching = 0;
int count_matching = 0;
enum cil_log_level log_level = cil_get_log_level();
target.rule_kind = CIL_AVRULE_ALLOWED;
target.is_extended = cil_rule->is_extended;
target.src = cil_rule->src;
target.tgt = cil_rule->tgt;
target.perms = cil_rule->perms;
if (!cil_rule->is_extended) {
neverallow_str = CIL_KEY_NEVERALLOW;
allow_str = CIL_KEY_ALLOW;
avrule_flavor = CIL_AVRULE;
} else {
neverallow_str = CIL_KEY_NEVERALLOWX;
allow_str = CIL_KEY_ALLOWX;
avrule_flavor = CIL_AVRULEX;
}
cil_tree_log(node, CIL_ERR, "%s check failed", neverallow_str);
__cil_print_rule(" ", neverallow_str, cil_rule);
cil_list_init(&matching, CIL_NODE);
rc = cil_find_matching_avrule_in_ast(db->ast->root, avrule_flavor, &target, matching, CIL_FALSE);
if (rc) {
cil_log(CIL_ERR, "Error occurred while checking %s rules\n", neverallow_str);
cil_list_destroy(&matching, CIL_FALSE);
goto exit;
}
cil_list_for_each(i2, matching) {
num_matching++;
}
cil_list_for_each(i2, matching) {
n2 = i2->data;
r2 = n2->data;
__cil_print_parents(" ", n2);
__cil_print_rule(" ", allow_str, r2);
count_matching++;
if (count_matching >= 4 && num_matching > 4 && log_level == CIL_ERR) {
cil_log(CIL_ERR, " Only first 4 of %d matching rules shown (use \"-v\" to show all)\n", num_matching);
break;
}
}
cil_log(CIL_ERR,"\n");
cil_list_destroy(&matching, CIL_FALSE);
exit:
return rc;
}
static int cil_check_neverallow(const struct cil_db *db, policydb_t *pdb, struct cil_tree_node *node, int *violation)
{
int rc = SEPOL_OK;
struct cil_avrule *cil_rule = node->data;
struct cil_symtab_datum *tgt = cil_rule->tgt;
uint32_t kind;
avrule_t *rule;
struct cil_list *xperms = NULL;
struct cil_list_item *item;
if (!cil_rule->is_extended) {
kind = AVRULE_NEVERALLOW;
} else {
kind = AVRULE_XPERMS_NEVERALLOW;
}
rule = __cil_init_sepol_avrule(kind, node);
rule->next = NULL;
rc = __cil_add_sepol_type(pdb, db, cil_rule->src, &rule->stypes.types);
if (rc != SEPOL_OK) {
goto exit;
}
if (tgt->fqn == CIL_KEY_SELF) {
rule->flags = RULE_SELF;
} else if (tgt->fqn == CIL_KEY_NOTSELF) {
rule->flags = RULE_NOTSELF;
} else if (tgt->fqn == CIL_KEY_OTHER) {
rule->flags = RULE_NOTSELF;
rc = __cil_add_sepol_type(pdb, db, cil_rule->src, &rule->ttypes.types);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
rc = __cil_add_sepol_type(pdb, db, tgt, &rule->ttypes.types);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (!cil_rule->is_extended) {
rc = __cil_rule_to_sepol_class_perms(pdb, cil_rule->perms.classperms, &rule->perms);
if (rc != SEPOL_OK) {
goto exit;
}
rc = check_assertion(pdb, rule);
if (rc == CIL_TRUE) {
*violation = CIL_TRUE;
rc = __cil_print_neverallow_failure(db, node);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
rc = __cil_permx_to_sepol_class_perms(pdb, cil_rule->perms.x.permx, &rule->perms);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_permx_bitmap_to_sepol_xperms_list(cil_rule->perms.x.permx->kind, cil_rule->perms.x.permx->perms, &xperms);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_for_each(item, xperms) {
rule->xperms = item->data;
rc = check_assertion(pdb, rule);
if (rc == CIL_TRUE) {
*violation = CIL_TRUE;
rc = __cil_print_neverallow_failure(db, node);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
}
exit:
if (xperms != NULL) {
cil_list_for_each(item, xperms) {
free(item->data);
item->data = NULL;
}
cil_list_destroy(&xperms, CIL_FALSE);
}
rule->xperms = NULL;
__cil_destroy_sepol_avrules(rule);
return rc;
}
static int cil_check_neverallows(const struct cil_db *db, policydb_t *pdb, struct cil_list *neverallows, int *violation)
{
int rc = SEPOL_OK;
struct cil_list_item *item;
cil_list_for_each(item, neverallows) {
rc = cil_check_neverallow(db, pdb, item->data, violation);
if (rc != SEPOL_OK) {
goto exit;
}
}
exit:
return rc;
}
static struct cil_list *cil_classperms_from_sepol(policydb_t *pdb, uint16_t class, uint32_t data, struct cil_class *class_value_to_cil[], struct cil_perm **perm_value_to_cil[])
{
struct cil_classperms *cp;
struct cil_list *cp_list;
class_datum_t *sepol_class = pdb->class_val_to_struct[class - 1];
unsigned i;
cil_classperms_init(&cp);
cp->class = class_value_to_cil[class];
if (!cp->class) goto exit;
cil_list_init(&cp->perms, CIL_PERM);
for (i = 0; i < sepol_class->permissions.nprim; i++) {
struct cil_perm *perm;
if ((data & (UINT32_C(1) << i)) == 0) continue;
perm = perm_value_to_cil[class][i+1];
if (!perm) goto exit;
cil_list_append(cp->perms, CIL_PERM, perm);
}
cil_list_init(&cp_list, CIL_CLASSPERMS);
cil_list_append(cp_list, CIL_CLASSPERMS, cp);
return cp_list;
exit:
cil_destroy_classperms(cp);
cil_log(CIL_ERR,"Failed to create CIL class-permissions from sepol values\n");
return NULL;
}
static int cil_avrule_from_sepol(policydb_t *pdb, avtab_ptr_t sepol_rule, struct cil_avrule *cil_rule, void *type_value_to_cil[], struct cil_class *class_value_to_cil[], struct cil_perm **perm_value_to_cil[])
{
int rc = SEPOL_ERR;
avtab_key_t *k = &sepol_rule->key;
avtab_datum_t *d = &sepol_rule->datum;
cil_rule->src = type_value_to_cil[k->source_type];
if (!cil_rule->src) goto exit;
cil_rule->tgt = type_value_to_cil[k->target_type];
if (!cil_rule->tgt) goto exit;
cil_rule->perms.classperms = cil_classperms_from_sepol(pdb, k->target_class, d->data, class_value_to_cil, perm_value_to_cil);
if (!cil_rule->perms.classperms) goto exit;
return SEPOL_OK;
exit:
cil_log(CIL_ERR,"Failed to create CIL AV rule from sepol values\n");
return rc;
}
static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void *type_value_to_cil, struct cil_class *class_value_to_cil[], struct cil_perm **perm_value_to_cil[], int *violation)
{
int rc = SEPOL_OK;
int i;
for (i = 0; i < db->num_types; i++) {
type_datum_t *child;
type_datum_t *parent;
avtab_ptr_t bad = NULL;
int numbad = 0;
struct cil_type *t = db->val_to_type[i];
if (!t->bounds) continue;
rc = __cil_get_sepol_type_datum(pdb, DATUM(t), &child);
if (rc != SEPOL_OK) goto exit;
rc = __cil_get_sepol_type_datum(pdb, DATUM(t->bounds), &parent);
if (rc != SEPOL_OK) goto exit;
rc = bounds_check_type(NULL, pdb, child->s.value, parent->s.value, &bad, &numbad);
if (rc != SEPOL_OK) goto exit;
if (bad) {
avtab_ptr_t cur;
struct cil_avrule target;
struct cil_tree_node *n1 = NULL;
int count_bad = 0;
enum cil_log_level log_level = cil_get_log_level();
*violation = CIL_TRUE;
target.is_extended = 0;
target.rule_kind = CIL_AVRULE_ALLOWED;
target.src_str = NULL;
target.tgt_str = NULL;
cil_log(CIL_ERR, "Child type %s exceeds bounds of parent %s\n",
t->datum.fqn, t->bounds->datum.fqn);
for (cur = bad; cur; cur = cur->next) {
struct cil_list_item *i2;
struct cil_list *matching;
int num_matching = 0;
int count_matching = 0;
rc = cil_avrule_from_sepol(pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to convert sepol avrule to CIL\n");
bounds_destroy_bad(bad);
goto exit;
}
__cil_print_rule(" ", "allow", &target);
cil_list_init(&matching, CIL_NODE);
rc = cil_find_matching_avrule_in_ast(db->ast->root, CIL_AVRULE, &target, matching, CIL_TRUE);
if (rc) {
cil_log(CIL_ERR, "Error occurred while checking type bounds\n");
cil_list_destroy(&matching, CIL_FALSE);
cil_list_destroy(&target.perms.classperms, CIL_TRUE);
bounds_destroy_bad(bad);
goto exit;
}
cil_list_for_each(i2, matching) {
num_matching++;
}
cil_list_for_each(i2, matching) {
struct cil_tree_node *n2 = i2->data;
struct cil_avrule *r2 = n2->data;
if (n1 == n2) {
cil_log(CIL_ERR, " \n");
} else {
n1 = n2;
__cil_print_parents(" ", n2);
__cil_print_rule(" ", "allow", r2);
}
count_matching++;
if (count_matching >= 2 && num_matching > 2 && log_level == CIL_ERR) {
cil_log(CIL_ERR, " Only first 2 of %d matching rules shown (use \"-v\" to show all)\n", num_matching);
break;
}
}
cil_list_destroy(&matching, CIL_FALSE);
cil_list_destroy(&target.perms.classperms, CIL_TRUE);
count_bad++;
if (count_bad >= 4 && numbad > 4 && log_level == CIL_ERR) {
cil_log(CIL_ERR, " Only first 4 of %d bad rules shown (use \"-v\" to show all)\n", numbad);
break;
}
}
bounds_destroy_bad(bad);
}
}
exit:
return rc;
}
// assumes policydb is already allocated and initialized properly with things
// like policy type set to kernel and version set appropriately
int cil_binary_create_allocated_pdb(const struct cil_db *db, sepol_policydb_t *policydb)
{
int rc = SEPOL_ERR;
int i;
struct cil_args_binary extra_args;
struct cil_args_booleanif booleanif_args;
policydb_t *pdb = &policydb->p;
struct cil_list *neverallows = NULL;
hashtab_t role_trans_table = NULL;
hashtab_t avrulex_ioctl_table = NULL;
hashtab_t avrulex_nlmsg_table = NULL;
void **type_value_to_cil = NULL;
struct cil_class **class_value_to_cil = NULL;
struct cil_perm ***perm_value_to_cil = NULL;
if (db == NULL || policydb == NULL) {
if (db == NULL) {
cil_log(CIL_ERR,"db == NULL\n");
} else if (policydb == NULL) {
cil_log(CIL_ERR,"policydb == NULL\n");
}
return SEPOL_ERR;
}
/* libsepol values start at 1. Just allocate extra memory rather than
* subtract 1 from the sepol value.
*/
type_value_to_cil = calloc(db->num_types_and_attrs+1, sizeof(*type_value_to_cil));
if (!type_value_to_cil) goto exit;
class_value_to_cil = calloc(db->num_classes+1, sizeof(*class_value_to_cil));
if (!class_value_to_cil) goto exit;
perm_value_to_cil = calloc(db->num_classes+1, sizeof(*perm_value_to_cil));
if (!perm_value_to_cil) goto exit;
for (i=1; i < db->num_classes+1; i++) {
perm_value_to_cil[i] = calloc(PERMS_PER_CLASS+1, sizeof(*perm_value_to_cil[i]));
if (!perm_value_to_cil[i]) goto exit;
}
rc = __cil_policydb_init(pdb, db, class_value_to_cil, perm_value_to_cil);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR,"Problem in policydb_init\n");
goto exit;
}
role_trans_table = hashtab_create(role_trans_hash, role_trans_compare, ROLE_TRANS_TABLE_SIZE);
if (!role_trans_table) {
cil_log(CIL_INFO, "Failure to create hashtab for role_trans\n");
goto exit;
}
avrulex_ioctl_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_ioctl_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
avrulex_nlmsg_table = hashtab_create(avrulex_hash, avrulex_compare, AVRULEX_TABLE_SIZE);
if (!avrulex_nlmsg_table) {
cil_log(CIL_INFO, "Failure to create hashtab for avrulex\n");
goto exit;
}
cil_list_init(&neverallows, CIL_LIST_ITEM);
extra_args.db = db;
extra_args.pdb = pdb;
extra_args.neverallows = neverallows;
extra_args.role_trans_table = role_trans_table;
extra_args.avrulex_xperm_tables.ioctl = avrulex_ioctl_table;
extra_args.avrulex_xperm_tables.nlmsg = avrulex_nlmsg_table;
extra_args.type_value_to_cil = type_value_to_cil;
booleanif_args.db = db;
booleanif_args.pdb = pdb;
booleanif_args.cond_node = NULL;
booleanif_args.cond_flavor = CIL_NONE;
for (i = 1; i <= 3; i++) {
extra_args.pass = i;
rc = cil_tree_walk(db->ast->root, __cil_binary_create_helper, NULL, NULL, &extra_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure while walking cil database\n");
goto exit;
}
if (i == 1) {
rc = __cil_policydb_val_arrays_create(pdb);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating val_to_{struct,name} arrays\n");
goto exit;
}
}
if (i == 3) {
rc = hashtab_map(avrulex_ioctl_table, __cil_avrulex_ioctl_to_policydb, &booleanif_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
rc = hashtab_map(avrulex_nlmsg_table, __cil_avrulex_nlmsg_to_policydb, &booleanif_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure creating avrulex rules\n");
goto exit;
}
}
}
rc = cil_sidorder_to_policydb(pdb, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_contexts_to_policydb(pdb, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure while inserting cil contexts into sepol policydb\n");
goto exit;
}
if (pdb->type_attr_map == NULL) {
rc = __cil_typeattr_bitmap_init(pdb);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure while initializing typeattribute bitmap\n");
goto exit;
}
}
cond_optimize_lists(pdb->cond_list);
__cil_set_conditional_state_and_flags(pdb);
if (db->disable_neverallow != CIL_TRUE) {
int violation = CIL_FALSE;
cil_log(CIL_INFO, "Checking Neverallows\n");
rc = cil_check_neverallows(db, pdb, neverallows, &violation);
if (rc != SEPOL_OK) goto exit;
cil_log(CIL_INFO, "Checking User Bounds\n");
rc = bounds_check_users(NULL, pdb);
if (rc) {
violation = CIL_TRUE;
}
cil_log(CIL_INFO, "Checking Role Bounds\n");
rc = bounds_check_roles(NULL, pdb);
if (rc) {
violation = CIL_TRUE;
}
cil_log(CIL_INFO, "Checking Type Bounds\n");
rc = cil_check_type_bounds(db, pdb, type_value_to_cil, class_value_to_cil, perm_value_to_cil, &violation);
if (rc != SEPOL_OK) goto exit;
if (violation == CIL_TRUE) {
rc = SEPOL_ERR;
goto exit;
}
}
/* This pre-expands the roles and users for context validity checking */
if (hashtab_map(pdb->p_roles.table, policydb_role_cache, pdb)) {
cil_log(CIL_INFO, "Failure creating roles cache");
rc = SEPOL_ERR;
goto exit;
}
if (hashtab_map(pdb->p_users.table, policydb_user_cache, pdb)) {
cil_log(CIL_INFO, "Failure creating users cache");
rc = SEPOL_ERR;
goto exit;
}
rc = SEPOL_OK;
exit:
hashtab_destroy(role_trans_table);
hashtab_map(avrulex_ioctl_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_ioctl_table);
hashtab_map(avrulex_nlmsg_table, __cil_avrulex_xperm_destroy, NULL);
hashtab_destroy(avrulex_nlmsg_table);
free(type_value_to_cil);
free(class_value_to_cil);
if (perm_value_to_cil != NULL) {
/* Range is because libsepol values start at 1. */
for (i=1; i < db->num_classes+1; i++) {
free(perm_value_to_cil[i]);
}
free(perm_value_to_cil);
}
cil_list_destroy(&neverallows, CIL_FALSE);
return rc;
}
libsepol-3.8.1/cil/src/cil_binary.h000066400000000000000000000433451476211737200172010ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef _CIL_BINARY_H_
#define _CIL_BINARY_H_
#include
#include "cil_internal.h"
#include "cil_tree.h"
#include "cil_list.h"
/**
* Create a binary policydb from the cil db.
*
* @param[in] db The cil database.
* @param[in] pdb The policy database.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_binary_create(const struct cil_db *db, sepol_policydb_t **pdb);
/**
* Create a pre allocated binary policydb from the cil db.
*
* It is assumed that pdb has been allocated and initialized so that fields such
* as policy type and version are set appropriately. It is recommended that
* instead of calling this, one instead calls cil_binary_create, which will
* properly allocate and initialize the pdb and then calls this function. This
* function is used to maintain binary backwards compatibility.
*
* @param[in] db The cil database.
* @param[in] pdb The policy database.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_binary_create_allocated_pdb(const struct cil_db *db, sepol_policydb_t *pdb);
/**
* Insert cil common structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the common into.
* @param[in] datum The cil_common datum.
* @param[out] common_out The sepol common to send back.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_common_to_policydb(policydb_t *pdb, struct cil_class *cil_common, common_datum_t **common_out);
/**
* Insert cil class structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the class into.
* @param[in] datum The cil_class datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_class_to_policydb(policydb_t *pdb, struct cil_class *cil_class);
/**
* Insert cil role structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the role into.
* @param[in] datum The cil_role datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_role_to_policydb(policydb_t *pdb, struct cil_role *cil_role);
/**
* Insert cil roletype structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the roletype into.
* @param[in] db The cil database
* @param[in] datum The cil_roletype datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR otherwise.
*/
int cil_roletype_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_role *role);
/**
* Insert cil type structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the type into.
* @param[in] datum The cil_type datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_type_to_policydb(policydb_t *pdb, struct cil_type *cil_type, void *type_value_to_cil[]);
/**
* Insert cil typealias structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the typealias into.
* @param[in] datum The cil_typealias datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_typealias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alias);
/**
* Insert cil typepermissive structure into sepol policydb.
* The function looks up the previously inserted type and flips the bit
* in the permssive types bitmap that corresponds to that type's value.
*
* @param[in] pdb The policy database to insert the typepermissive into.
* @param[in] datum The cil_typepermissive datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_typepermissive_to_policydb(policydb_t *pdb, struct cil_typepermissive *cil_typeperm);
/**
* Insert cil attribute structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the attribute into.
* @param[in] datum The cil_attribute datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_typeattribute_to_policydb(policydb_t *pdb, struct cil_typeattribute *cil_attr, void *type_value_to_cil[]);
/**
* Insert cil attribute structure into sepol type->attribute bitmap.
* The function calls helper functions to loop over the attributes lists
* of types and negative types. If either of the lists contain an attribute,
* the helper functions will recurse into the attribute and record the
* attribute's types and negative types. There is no minimum depth.
*
* @param[in] pdb The policy database that contains the type->attribute bitmap.
* @param[in] db The cil database
* @param[in] node The tree node that contains the cil_attribute.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_typeattribute_to_bitmap(policydb_t *pdb, const struct cil_db *cdb, struct cil_typeattribute *cil_attr);
/**
* Insert cil policycap structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the policycap into.
* @param[in] node The tree node that contains the cil_policycap.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_policycap_to_policydb(policydb_t *pdb, struct cil_policycap *cil_polcap);
/**
* Insert cil user structure into sepol policydb.
*
* @param[in] pdb THe policy database to insert the user into.
* @param[in] node The tree node that contains the cil_user.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_user_to_policydb(policydb_t *pdb, struct cil_user *cil_user);
/**
* Insert cil userrole structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the userrole into.
* @param[in] db The cil database
* @param[in] datum The cil_user
*
* @return SEPOL_OK upon success or SEPOL_ERR otherwise.
*/
int cil_userrole_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_user *user);
/**
* Insert cil bool structure into sepol policydb.
*
* @param[in] pdb THe policy database to insert the bool into.
* @param[in] datum The cil_bool datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_bool_to_policydb(policydb_t *pdb, struct cil_bool *cil_bool);
/**
* Insert all ordered cil category structures into sepol policydb.
*
* @param[in] pdb The policy database to insert the categories into.
* @param[in] db The cil database that contains the category order list.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_catorder_to_policydb(policydb_t *pdb, const struct cil_db *db);
/**
* Insert cil category alias structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the category alias into.
* @param[in] datum The cil_catalias datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_catalias_to_policydb(policydb_t *pdb, struct cil_alias *cil_alias);
/**
* Insert the cil sensitivityorder into sepol policydb.
*
* @param[in] pdb The policy database to insert the sensitivityorder into.
* @param[in] db the cil database that contains the sensitivityorder list.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_sensitivityorder_to_policydb(policydb_t *pdb, const struct cil_db *db);
/**
* Insert cil type rule structure into sepol policydb. This includes
* typetransition, typechange, and typemember.
*
* @param[in] pdb The policy database to insert the type rule into.
* @param[in] datum The cil_type_rule datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_type_rule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_type_rule *cil_rule);
/**
* Insert cil avrule structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the avrule into.
* @param[in] datum The cil_avrule datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_avrule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_avrule *cil_avrule);
/**
* Insert cil booleanif structure into sepol policydb. This populates the
* policydb conditional list. Each conditional node contains an expression
* and true/false avtab_ptr lists that point into te_cond_avtab.
*
* @param[in] pdb The policy database to insert the booleanif into.
* @param[in] node The cil_booleanif node.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_booleanif_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_tree_node *node);
/**
* Insert cil role transition structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the role transition into.
* @param[in] datum The cil_role_trans datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_roletrans_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_roletransition *roletrans, hashtab_t role_trans_table);
/**
* Insert cil role allow structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the role allow into.
* @param[in] datum The cil_role_allow datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_roleallow_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_roleallow *roleallow);
/**
* Insert cil file transition structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the file transition into.
* @param[in] datum The cil_nametypetransition datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_typetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_nametypetransition *typetrans);
/**
* Insert cil constrain/mlsconstrain structure(s) into sepol policydb.
*
* @param[in] pdb The policy database to insert the (mls)constrain into.
* @param[in] datum The cil_(mls)constrain datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_constrain_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_constrain *cil_constrain);
/**
* Define sepol level.
* Associates the sepol level (sensitivity) with categories.
* Looks at the cil_sens structure for a list of cil_cats to
* associate the sensitivity with.
* Sets the sepol level as defined in the sepol policy database.
*
* @param[in] pdb The policy database that holds the sepol level.
* @param[in] datum The cil_sens datum.
*
* @return SEPOL_OK upon success or SEPOL_ERR upon error.
*/
int cil_sepol_level_define(policydb_t *pdb, struct cil_sens *cil_sens);
/**
* Insert cil rangetransition structure into sepol policydb.
*
* @param[in] pdb The policy database to insert the rangetransition into.
* @param[in] datum The cil_rangetransition datum.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_rangetransition_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_rangetransition *rangetrans);
/**
* Insert cil ibpkeycon structure into sepol policydb.
* The function is given a structure containing the sorted ibpkeycons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the ibpkeycon into.
* @param[in] node The cil_sort structure that contains the sorted ibpkeycons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_ibpkeycon_to_policydb(policydb_t *pdb, struct cil_sort *ibpkeycons);
/**
* Insert cil idbev structure into sepol policydb.
* The function is given a structure containing the sorted ibendportcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the pkeycon into.
* @param[in] node The cil_sort structure that contains the sorted ibendportcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_ibendportcon_to_policydb(policydb_t *pdb, struct cil_sort *pkeycons);
/**
* Insert cil portcon structure into sepol policydb.
* The function is given a structure containing the sorted portcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the portcon into.
* @param[in] node The cil_sort structure that contains the sorted portcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_portcon_to_policydb(policydb_t *pdb, struct cil_sort *portcons);
/**
* Insert cil netifcon structure into sepol policydb.
* The function is given a structure containing the sorted netifcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the netifcon into.
* @param[in] node The cil_sort structure that contains the sorted netifcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_netifcon_to_policydb(policydb_t *pdb, struct cil_sort *netifcons);
/**
* Insert cil nodecon structure into sepol policydb.
* The function is given a structure containing the sorted nodecons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the nodecon into.
* @param[in] node The cil_sort structure that contains the sorted nodecons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_nodecon_to_policydb(policydb_t *pdb, struct cil_sort *nodecons);
/**
* Insert cil fsuse structure into sepol policydb.
* The function is given a structure containing the sorted fsuses and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the fsuse into.
* @param[in] node The cil_sort structure that contains the sorted fsuses.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_fsuse_to_policydb(policydb_t *pdb, struct cil_sort *fsuses);
/**
* Insert cil genfscon structure into sepol policydb.
* The function is given a structure containing the sorted genfscons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the genfscon into.
* @param[in] node The cil_sort structure that contains the sorted genfscons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_genfscon_to_policydb(policydb_t *pdb, struct cil_sort *genfscons);
/**
* Insert cil pirqcon structure into sepol policydb.
* The function is given a structure containing the sorted pirqcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the pirqcon into.
* @param[in] node The cil_sort structure that contains the sorted pirqcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_pirqcon_to_policydb(policydb_t *pdb, struct cil_sort *pirqcons);
/**
* Insert cil iomemcon structure into sepol policydb.
* The function is given a structure containing the sorted iomemcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the iomemcon into.
* @param[in] node The cil_sort structure that contains the sorted iomemcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_iomemcon_to_policydb(policydb_t *pdb, struct cil_sort *iomemcons);
/**
* Insert cil ioportcon structure into sepol policydb.
* The function is given a structure containing the sorted ioportcons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the ioportcon into.
* @param[in] node The cil_sort structure that contains the sorted ioportcons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_ioportcon_to_policydb(policydb_t *pdb, struct cil_sort *ioportcons);
/**
* Insert cil pcidevicecon structure into sepol policydb.
* The function is given a structure containing the sorted pcidevicecons and
* loops over this structure inserting them into the policy database.
*
* @param[in] pdb The policy database to insert the pcidevicecon into.
* @param[in] node The cil_sort structure that contains the sorted pcidevicecons.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_pcidevicecon_to_policydb(policydb_t *pdb, struct cil_sort *pcidevicecons);
/**
* Create an mls level using a cil level.
* The function is given a structure containing the a cil_level and
* outputs a created mls_level_t.
*
* @param[in] pdb The policy database to use to get sepol level from cil_level's sensitivity.
* @param[in] cil_level The cil_level that will be used to create an mls_level_t.
* @param[out] mls_level The mls_level that is created.
*
* @return SEPOL_OK upon success or an error otherwise.
*/
int cil_level_to_mls_level(policydb_t *pdb, struct cil_level *cil_level, mls_level_t *mls_level);
#endif //_CIL_BINARY_H_
libsepol-3.8.1/cil/src/cil_build_ast.c000066400000000000000000004743501476211737200176620ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_parser.h"
#include "cil_build_ast.h"
#include "cil_copy_ast.h"
#include "cil_verify.h"
#include "cil_strpool.h"
struct cil_args_build {
struct cil_tree_node *ast;
struct cil_db *db;
struct cil_tree_node *tunif;
struct cil_tree_node *in;
struct cil_tree_node *macro;
struct cil_tree_node *optional;
struct cil_tree_node *boolif;
};
static int cil_fill_list(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **list)
{
int rc = SEPOL_ERR;
struct cil_tree_node *curr;
enum cil_syntax syntax[] = {
CIL_SYN_N_STRINGS,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
rc = __cil_verify_syntax(current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_init(list, flavor);
for (curr = current; curr != NULL; curr = curr->next) {
cil_list_append(*list, CIL_STRING, curr->data);
}
return SEPOL_OK;
exit:
return rc;
}
struct cil_symtab_datum *cil_gen_declared_string(struct cil_db *db, hashtab_key_t key, struct cil_tree_node *ast_node)
{
struct cil_tree_node *parent = ast_node->parent;
struct cil_macro *macro = NULL;
symtab_t *symtab;
struct cil_symtab_datum *datum;
while (parent) {
if (parent->flavor == CIL_MACRO) {
/* This condition is only reached in the build phase */
macro = parent->data;
break;
} else if (parent->flavor == CIL_CALL) {
/* This condition is only reached in the resolve phase */
struct cil_call *call = parent->data;
macro = call->macro;
break;
}
parent = parent->parent;
}
if (macro && macro->params) {
struct cil_list_item *item;
cil_list_for_each(item, macro->params) {
struct cil_param *param = item->data;
if (param->flavor == CIL_DECLARED_STRING && param->str == key) {
return NULL;
}
}
}
symtab = &((struct cil_root *)db->ast->root->data)->symtab[CIL_SYM_STRINGS];
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
return datum;
}
datum = cil_malloc(sizeof(*datum));
cil_symtab_datum_init(datum);
cil_symtab_insert(symtab, key, datum, ast_node);
cil_list_append(db->declared_strings, CIL_DATUM, datum);
return datum;
}
static int cil_allow_multiple_decls(struct cil_db *db, enum cil_flavor f_new, enum cil_flavor f_old)
{
if (f_new != f_old) {
return CIL_FALSE;
}
switch (f_new) {
case CIL_TYPE:
case CIL_TYPEATTRIBUTE:
case CIL_ROLE:
if (db->multiple_decls) {
return CIL_TRUE;
}
break;
case CIL_OPTIONAL:
return CIL_TRUE;
break;
default:
break;
}
return CIL_FALSE;
}
int cil_add_decl_to_symtab(struct cil_db *db, symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node)
{
int rc;
if (symtab == NULL || datum == NULL || node == NULL) {
return SEPOL_ERR;
}
rc = cil_symtab_insert(symtab, key, datum, node);
if (rc == SEPOL_EEXIST) {
struct cil_symtab_datum *prev;
rc = cil_symtab_get_datum(symtab, key, &prev);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(node), key);
return SEPOL_ERR;
}
if (!cil_allow_multiple_decls(db, node->flavor, FLAVOR(prev))) {
/* multiple_decls not ok, ret error */
struct cil_tree_node *n = NODE(prev);
cil_log(CIL_ERR, "Re-declaration of %s %s\n",
cil_node_to_string(node), key);
cil_tree_log(node, CIL_ERR, "Previous declaration of %s",
cil_node_to_string(n));
return SEPOL_ERR;
}
/* multiple_decls is enabled and works for this datum type, add node */
cil_list_append(prev->nodes, CIL_NODE, node);
node->data = prev;
return SEPOL_EEXIST;
}
return SEPOL_OK;
}
int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor)
{
int rc = SEPOL_ERR;
symtab_t *symtab = NULL;
rc = cil_verify_name(db, (const char*)key, nflavor);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_get_symtab(ast_node->parent, &symtab, sflavor);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = datum;
ast_node->flavor = nflavor;
rc = cil_add_decl_to_symtab(db, symtab, key, datum, ast_node);
if (rc != SEPOL_OK) {
goto exit;
}
if (ast_node->parent->flavor == CIL_MACRO) {
rc = cil_verify_decl_does_not_shadow_macro_parameter(ast_node->parent->data, ast_node, key);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static void cil_clear_node(struct cil_tree_node *ast_node)
{
if (ast_node == NULL) {
return;
}
ast_node->data = NULL;
ast_node->flavor = CIL_NONE;
}
int cil_gen_ordered(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_ordered *ordered = NULL;
struct cil_list_item *curr = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_ordered_init(&ordered);
rc = cil_fill_list(parse_current->next->cl_head, flavor, &ordered->strs);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_for_each(curr, ordered->strs) {
if (curr->data == CIL_KEY_UNORDERED) {
if (flavor == CIL_CLASSORDER) {
if (curr == ordered->strs->head && curr->next == NULL) {
cil_log(CIL_ERR, "classorder 'unordered' keyword must be followed by one or more class.\n");
rc = SEPOL_ERR;
goto exit;
} else if (curr != ordered->strs->head) {
cil_log(CIL_ERR, "classorder can only use 'unordered' keyword as the first item in the list.\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
cil_log(CIL_ERR, "The 'unordered' keyword can only be used with classorder rules.\n");
rc = SEPOL_ERR;
goto exit;
}
}
}
ast_node->data = ordered;
ast_node->flavor = flavor;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad ordered declaration");
cil_destroy_ordered(ordered);
return rc;
}
void cil_destroy_ordered(struct cil_ordered *ordered)
{
if (ordered == NULL) {
return;
}
if (ordered->strs != NULL) {
cil_list_destroy(&ordered->strs, CIL_FALSE);
}
if (ordered->datums != NULL) {
cil_list_destroy(&ordered->datums, CIL_FALSE);
}
free(ordered);
}
int cil_gen_block(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint16_t is_abstract)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_N_LISTS | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_block *block = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
if (db->qualified_names) {
cil_log(CIL_ERR, "Blocks are not allowed when the option for qualified names is used\n");
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_block_init(&block);
block->is_abstract = is_abstract;
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)block, (hashtab_key_t)key, CIL_SYM_BLOCKS, CIL_BLOCK);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad block declaration");
cil_destroy_block(block);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_block(struct cil_block *block)
{
struct cil_list_item *item;
struct cil_tree_node *bi_node;
struct cil_blockinherit *inherit;
if (block == NULL) {
return;
}
cil_symtab_datum_destroy(&block->datum);
cil_symtab_array_destroy(block->symtab);
if (block->bi_nodes != NULL) {
/* unlink blockinherit->block */
cil_list_for_each(item, block->bi_nodes) {
bi_node = item->data;
/* the conditions should always be true, but better be sure */
if (bi_node->flavor == CIL_BLOCKINHERIT) {
inherit = bi_node->data;
if (inherit->block == block) {
inherit->block = NULL;
}
}
}
cil_list_destroy(&block->bi_nodes, CIL_FALSE);
}
free(block);
}
int cil_gen_blockinherit(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_blockinherit *inherit = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
if (db->qualified_names) {
cil_log(CIL_ERR, "Block inherit rules are not allowed when the option for qualified names is used\n");
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_blockinherit_init(&inherit);
inherit->block_str = parse_current->next->data;
ast_node->data = inherit;
ast_node->flavor = CIL_BLOCKINHERIT;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad blockinherit declaration");
cil_destroy_blockinherit(inherit);
return rc;
}
void cil_destroy_blockinherit(struct cil_blockinherit *inherit)
{
if (inherit == NULL) {
return;
}
if (inherit->block != NULL && inherit->block->bi_nodes != NULL) {
struct cil_tree_node *node;
struct cil_list_item *item;
cil_list_for_each(item, inherit->block->bi_nodes) {
node = item->data;
if (node->data == inherit) {
cil_list_remove(inherit->block->bi_nodes, CIL_NODE, node, CIL_FALSE);
break;
}
}
}
free(inherit);
}
int cil_gen_blockabstract(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_blockabstract *abstract = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
if (db->qualified_names) {
cil_log(CIL_ERR, "Block abstract rules are not allowed when the option for qualified names is used\n");
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_blockabstract_init(&abstract);
abstract->block_str = parse_current->next->data;
ast_node->data = abstract;
ast_node->flavor = CIL_BLOCKABSTRACT;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad blockabstract declaration");
cil_destroy_blockabstract(abstract);
return rc;
}
void cil_destroy_blockabstract(struct cil_blockabstract *abstract)
{
if (abstract == NULL) {
return;
}
free(abstract);
}
int cil_gen_in(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_N_LISTS,
CIL_SYN_N_LISTS | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_in *in = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
if (db->qualified_names) {
cil_log(CIL_ERR, "In-statements are not allowed when the option for qualified names is used\n");
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_in_init(&in);
if (parse_current->next->next->data) {
char *is_after_str = parse_current->next->data;
if (is_after_str == CIL_KEY_IN_BEFORE) {
in->is_after = CIL_FALSE;
} else if (is_after_str == CIL_KEY_IN_AFTER) {
in->is_after = CIL_TRUE;
} else {
cil_log(CIL_ERR, "Value must be either \'before\' or \'after\'\n");
rc = SEPOL_ERR;
goto exit;
}
in->block_str = parse_current->next->next->data;
} else {
in->is_after = CIL_FALSE;
in->block_str = parse_current->next->data;
}
ast_node->data = in;
ast_node->flavor = CIL_IN;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad in-statement");
cil_destroy_in(in);
return rc;
}
void cil_destroy_in(struct cil_in *in)
{
if (in == NULL) {
return;
}
cil_symtab_array_destroy(in->symtab);
free(in);
}
int cil_gen_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST | CIL_SYN_EMPTY_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_class *class = NULL;
struct cil_tree_node *perms = NULL;
int rc = SEPOL_ERR;
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_class_init(&class);
key = parse_current->next->data;
if (key == CIL_KEY_UNORDERED) {
cil_log(CIL_ERR, "'unordered' keyword is reserved and not a valid class name.\n");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)class, (hashtab_key_t)key, CIL_SYM_CLASSES, CIL_CLASS);
if (rc != SEPOL_OK) {
goto exit;
}
if (parse_current->next->next != NULL) {
perms = parse_current->next->next->cl_head;
rc = cil_gen_perm_nodes(db, perms, ast_node, CIL_PERM, &class->num_perms);
if (rc != SEPOL_OK) {
goto exit;
}
if (class->num_perms > CIL_PERMS_PER_CLASS) {
cil_tree_log(parse_current, CIL_ERR, "Too many permissions in class '%s'", class->datum.name);
cil_tree_children_destroy(ast_node);
rc = SEPOL_ERR;
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad class declaration");
cil_destroy_class(class);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_class(struct cil_class *class)
{
if (class == NULL) {
return;
}
cil_symtab_datum_destroy(&class->datum);
cil_symtab_destroy(&class->perms);
free(class);
}
int cil_gen_perm(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms)
{
char *key = NULL;
struct cil_perm *perm = NULL;
int rc = SEPOL_ERR;
cil_perm_init(&perm);
key = parse_current->data;
if (key == NULL) {
cil_log(CIL_ERR, "Bad permission\n");
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)perm, (hashtab_key_t)key, CIL_SYM_PERMS, flavor);
if (rc != SEPOL_OK) {
goto exit;
}
perm->value = *num_perms;
(*num_perms)++;
return SEPOL_OK;
exit:
cil_destroy_perm(perm);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_perm(struct cil_perm *perm)
{
if (perm == NULL) {
return;
}
cil_symtab_datum_destroy(&perm->datum);
cil_list_destroy(&perm->classperms, CIL_FALSE);
free(perm);
}
int cil_gen_perm_nodes(struct cil_db *db, struct cil_tree_node *current_perm, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms)
{
int rc = SEPOL_ERR;
struct cil_tree_node *new_ast = NULL;
while(current_perm != NULL) {
if (current_perm->cl_head != NULL) {
rc = SEPOL_ERR;
goto exit;
}
cil_tree_node_init(&new_ast);
new_ast->parent = ast_node;
new_ast->line = current_perm->line;
new_ast->hll_offset = current_perm->hll_offset;
rc = cil_gen_perm(db, current_perm, new_ast, flavor, num_perms);
if (rc != SEPOL_OK) {
cil_tree_node_destroy(&new_ast);
goto exit;
}
if (ast_node->cl_head == NULL) {
ast_node->cl_head = new_ast;
} else {
ast_node->cl_tail->next = new_ast;
}
ast_node->cl_tail = new_ast;
current_perm = current_perm->next;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad permissions\n");
cil_tree_children_destroy(ast_node);
cil_clear_node(ast_node);
return rc;
}
int cil_fill_perms(struct cil_tree_node *start_perm, struct cil_list **perms)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_N_STRINGS | CIL_SYN_N_LISTS,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
rc = __cil_verify_syntax(start_perm->cl_head, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_expr(start_perm, CIL_PERM, perms);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad permission list or expression\n");
return rc;
}
int cil_fill_classperms(struct cil_tree_node *parse_current, struct cil_classperms **cp)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_classperms_init(cp);
(*cp)->class_str = parse_current->data;
rc = cil_fill_perms(parse_current->next, &(*cp)->perm_strs);
if (rc != SEPOL_OK) {
cil_destroy_classperms(*cp);
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad class-permissions\n");
*cp = NULL;
return rc;
}
void cil_destroy_classperms(struct cil_classperms *cp)
{
if (cp == NULL) {
return;
}
cil_list_destroy(&cp->perm_strs, CIL_TRUE);
cil_list_destroy(&cp->perms, CIL_FALSE);
free(cp);
}
void cil_fill_classperms_set(struct cil_tree_node *parse_current, struct cil_classperms_set **cp_set)
{
cil_classperms_set_init(cp_set);
(*cp_set)->set_str = parse_current->data;
}
void cil_destroy_classperms_set(struct cil_classperms_set *cp_set)
{
if (cp_set == NULL) {
return;
}
free(cp_set);
}
int cil_fill_classperms_list(struct cil_tree_node *parse_current, struct cil_list **cp_list)
{
int rc = SEPOL_ERR;
struct cil_tree_node *curr;
if (parse_current == NULL || cp_list == NULL) {
goto exit;
}
cil_list_init(cp_list, CIL_CLASSPERMS);
curr = parse_current->cl_head;
if (curr == NULL) {
/* Class-perms form: SET1 */
struct cil_classperms_set *new_cp_set;
cil_fill_classperms_set(parse_current, &new_cp_set);
cil_list_append(*cp_list, CIL_CLASSPERMS_SET, new_cp_set);
} else if (curr->cl_head == NULL) {
/* Class-perms form: (CLASS1 (PERM1 ...)) */
struct cil_classperms *new_cp;
rc = cil_fill_classperms(curr, &new_cp);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_append(*cp_list, CIL_CLASSPERMS, new_cp);
} else {
cil_log(CIL_ERR, "Bad class-permissions list syntax\n");
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Problem filling class-permissions list\n");
cil_list_destroy(cp_list, CIL_TRUE);
return rc;
}
void cil_destroy_classperms_list(struct cil_list **cp_list)
{
struct cil_list_item *curr;
if (cp_list == NULL || *cp_list == NULL) {
return;
}
cil_list_for_each(curr, *cp_list) {
if (curr->flavor == CIL_CLASSPERMS) {
cil_destroy_classperms(curr->data);
} else {
cil_destroy_classperms_set(curr->data);
}
}
cil_list_destroy(cp_list, CIL_FALSE);
}
int cil_gen_classpermission(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
char *key = NULL;
struct cil_classpermission *cp = NULL;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_classpermission_init(&cp);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)cp, (hashtab_key_t)key, CIL_SYM_CLASSPERMSETS, CIL_CLASSPERMISSION);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad classpermission declaration");
cil_destroy_classpermission(cp);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_classpermission(struct cil_classpermission *cp)
{
if (cp == NULL) {
return;
}
if (cp->datum.name != NULL) {
cil_list_destroy(&cp->classperms, CIL_FALSE);
} else {
/* anonymous classpermission from call */
cil_destroy_classperms_list(&cp->classperms);
}
cil_symtab_datum_destroy(&cp->datum);
free(cp);
}
int cil_gen_classpermissionset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
struct cil_classpermissionset *cps = NULL;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_classpermissionset_init(&cps);
cps->set_str = parse_current->next->data;
rc = cil_fill_classperms_list(parse_current->next->next, &cps->classperms);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = cps;
ast_node->flavor = CIL_CLASSPERMISSIONSET;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad classpermissionset");
cil_destroy_classpermissionset(cps);
return rc;
}
void cil_destroy_classpermissionset(struct cil_classpermissionset *cps)
{
if (cps == NULL) {
return;
}
cil_destroy_classperms_list(&cps->classperms);
free(cps);
}
int cil_gen_map_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_class *map = NULL;
int rc = SEPOL_ERR;
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_class_init(&map);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)map, (hashtab_key_t)key, CIL_SYM_CLASSES, CIL_MAP_CLASS);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_perm_nodes(db, parse_current->next->next->cl_head, ast_node, CIL_MAP_PERM, &map->num_perms);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad map class declaration");
cil_destroy_class(map);
cil_clear_node(ast_node);
return rc;
}
int cil_gen_classmapping(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
struct cil_classmapping *mapping = NULL;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_classmapping_init(&mapping);
mapping->map_class_str = parse_current->next->data;
mapping->map_perm_str = parse_current->next->next->data;
rc = cil_fill_classperms_list(parse_current->next->next->next, &mapping->classperms);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = mapping;
ast_node->flavor = CIL_CLASSMAPPING;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad classmapping declaration");
cil_destroy_classmapping(mapping);
return rc;
}
void cil_destroy_classmapping(struct cil_classmapping *mapping)
{
if (mapping == NULL) {
return;
}
cil_destroy_classperms_list(&mapping->classperms);
free(mapping);
}
// TODO try to merge some of this with cil_gen_class (helper function for both)
int cil_gen_common(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_class *common = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_class_init(&common);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)common, (hashtab_key_t)key, CIL_SYM_COMMONS, CIL_COMMON);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_perm_nodes(db, parse_current->next->next->cl_head, ast_node, CIL_PERM, &common->num_perms);
if (rc != SEPOL_OK) {
goto exit;
}
if (common->num_perms > CIL_PERMS_PER_CLASS) {
cil_tree_log(parse_current, CIL_ERR, "Too many permissions in common '%s'", common->datum.name);
cil_tree_children_destroy(ast_node);
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad common declaration");
cil_destroy_class(common);
cil_clear_node(ast_node);
return rc;
}
int cil_gen_classcommon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_classcommon *clscom = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_classcommon_init(&clscom);
clscom->class_str = parse_current->next->data;
clscom->common_str = parse_current->next->next->data;
ast_node->data = clscom;
ast_node->flavor = CIL_CLASSCOMMON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad classcommon declaration");
cil_destroy_classcommon(clscom);
return rc;
}
void cil_destroy_classcommon(struct cil_classcommon *clscom)
{
if (clscom == NULL) {
return;
}
free(clscom);
}
int cil_gen_sid(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_sid *sid = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_sid_init(&sid);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)sid, (hashtab_key_t)key, CIL_SYM_SIDS, CIL_SID);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad sid declaration");
cil_destroy_sid(sid);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_sid(struct cil_sid *sid)
{
if (sid == NULL) {
return;
}
cil_symtab_datum_destroy(&sid->datum);
free(sid);
}
int cil_gen_sidcontext(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_sidcontext *sidcon = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_sidcontext_init(&sidcon);
sidcon->sid_str = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
sidcon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&sidcon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, sidcon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = sidcon;
ast_node->flavor = CIL_SIDCONTEXT;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad sidcontext declaration");
cil_destroy_sidcontext(sidcon);
return rc;
}
void cil_destroy_sidcontext(struct cil_sidcontext *sidcon)
{
if (sidcon == NULL) {
return;
}
if (sidcon->context_str == NULL && sidcon->context != NULL) {
cil_destroy_context(sidcon->context);
}
free(sidcon);
}
int cil_gen_user(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_user *user = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_user_init(&user);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)user, (hashtab_key_t)key, CIL_SYM_USERS, CIL_USER);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad user declaration");
cil_destroy_user(user);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_user(struct cil_user *user)
{
if (user == NULL) {
return;
}
cil_symtab_datum_destroy(&user->datum);
ebitmap_destroy(user->roles);
free(user->roles);
free(user);
}
int cil_gen_userattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_userattribute *attr = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userattribute_init(&attr);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)attr, (hashtab_key_t)key, CIL_SYM_USERS, CIL_USERATTRIBUTE);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userattribute declaration");
cil_destroy_userattribute(attr);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_userattribute(struct cil_userattribute *attr)
{
struct cil_list_item *expr = NULL;
struct cil_list_item *next = NULL;
if (attr == NULL) {
return;
}
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
expr = attr->expr_list->head;
while (expr != NULL) {
next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
cil_symtab_datum_destroy(&attr->datum);
ebitmap_destroy(attr->users);
free(attr->users);
free(attr);
}
int cil_gen_userattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_userattributeset *attrset = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userattributeset_init(&attrset);
attrset->attr_str = parse_current->next->data;
rc = cil_gen_expr(parse_current->next->next, CIL_USER, &attrset->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = attrset;
ast_node->flavor = CIL_USERATTRIBUTESET;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userattributeset declaration");
cil_destroy_userattributeset(attrset);
return rc;
}
void cil_destroy_userattributeset(struct cil_userattributeset *attrset)
{
if (attrset == NULL) {
return;
}
cil_list_destroy(&attrset->str_expr, CIL_TRUE);
cil_list_destroy(&attrset->datum_expr, CIL_FALSE);
free(attrset);
}
int cil_gen_userlevel(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_userlevel *usrlvl = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userlevel_init(&usrlvl);
usrlvl->user_str = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
usrlvl->level_str = parse_current->next->next->data;
} else {
cil_level_init(&usrlvl->level);
rc = cil_fill_level(parse_current->next->next->cl_head, usrlvl->level);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = usrlvl;
ast_node->flavor = CIL_USERLEVEL;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userlevel declaration");
cil_destroy_userlevel(usrlvl);
return rc;
}
void cil_destroy_userlevel(struct cil_userlevel *usrlvl)
{
if (usrlvl == NULL) {
return;
}
if (usrlvl->level_str == NULL && usrlvl->level != NULL) {
cil_destroy_level(usrlvl->level);
}
free(usrlvl);
}
int cil_gen_userrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_userrange *userrange = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userrange_init(&userrange);
userrange->user_str = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
userrange->range_str = parse_current->next->next->data;
} else {
cil_levelrange_init(&userrange->range);
rc = cil_fill_levelrange(parse_current->next->next->cl_head, userrange->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = userrange;
ast_node->flavor = CIL_USERRANGE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userrange declaration");
cil_destroy_userrange(userrange);
return rc;
}
void cil_destroy_userrange(struct cil_userrange *userrange)
{
if (userrange == NULL) {
return;
}
if (userrange->range_str == NULL && userrange->range != NULL) {
cil_destroy_levelrange(userrange->range);
}
free(userrange);
}
int cil_gen_userprefix(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_userprefix *userprefix = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userprefix_init(&userprefix);
userprefix->user_str = parse_current->next->data;
userprefix->prefix_str = parse_current->next->next->data;
ast_node->data = userprefix;
ast_node->flavor = CIL_USERPREFIX;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userprefix declaration");
cil_destroy_userprefix(userprefix);
return rc;
}
void cil_destroy_userprefix(struct cil_userprefix *userprefix)
{
if (userprefix == NULL) {
return;
}
free(userprefix);
}
int cil_gen_selinuxuser(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_selinuxuser *selinuxuser = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_selinuxuser_init(&selinuxuser);
selinuxuser->name_str = parse_current->next->data;
selinuxuser->user_str = parse_current->next->next->data;
if (parse_current->next->next->next->cl_head == NULL) {
selinuxuser->range_str = parse_current->next->next->next->data;
} else {
cil_levelrange_init(&selinuxuser->range);
rc = cil_fill_levelrange(parse_current->next->next->next->cl_head, selinuxuser->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = selinuxuser;
ast_node->flavor = CIL_SELINUXUSER;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad selinuxuser declaration");
cil_destroy_selinuxuser(selinuxuser);
return rc;
}
int cil_gen_selinuxuserdefault(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_selinuxuser *selinuxuser = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_selinuxuser_init(&selinuxuser);
selinuxuser->name_str = cil_strpool_add("__default__");
selinuxuser->user_str = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
selinuxuser->range_str = parse_current->next->next->data;
} else {
cil_levelrange_init(&selinuxuser->range);
rc = cil_fill_levelrange(parse_current->next->next->cl_head, selinuxuser->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = selinuxuser;
ast_node->flavor = CIL_SELINUXUSERDEFAULT;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad selinuxuserdefault declaration");
cil_destroy_selinuxuser(selinuxuser);
return rc;
}
void cil_destroy_selinuxuser(struct cil_selinuxuser *selinuxuser)
{
if (selinuxuser == NULL) {
return;
}
if (selinuxuser->range_str == NULL && selinuxuser->range != NULL) {
cil_destroy_levelrange(selinuxuser->range);
}
free(selinuxuser);
}
int cil_gen_role(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_role *role = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_role_init(&role);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)role, (hashtab_key_t)key, CIL_SYM_ROLES, CIL_ROLE);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
cil_destroy_role(role);
role = NULL;
} else {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad role declaration");
cil_destroy_role(role);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_role(struct cil_role *role)
{
if (role == NULL) {
return;
}
cil_symtab_datum_destroy(&role->datum);
ebitmap_destroy(role->types);
free(role->types);
free(role);
}
int cil_gen_roletype(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_roletype *roletype = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_roletype_init(&roletype);
roletype->role_str = parse_current->next->data;
roletype->type_str = parse_current->next->next->data;
ast_node->data = roletype;
ast_node->flavor = CIL_ROLETYPE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad roletype declaration");
cil_destroy_roletype(roletype);
return rc;
}
void cil_destroy_roletype(struct cil_roletype *roletype)
{
if (roletype == NULL) {
return;
}
free(roletype);
}
int cil_gen_userrole(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_userrole *userrole = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_userrole_init(&userrole);
userrole->user_str = parse_current->next->data;
userrole->role_str = parse_current->next->next->data;
ast_node->data = userrole;
ast_node->flavor = CIL_USERROLE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad userrole declaration");
cil_destroy_userrole(userrole);
return rc;
}
void cil_destroy_userrole(struct cil_userrole *userrole)
{
if (userrole == NULL) {
return;
}
free(userrole);
}
int cil_gen_roletransition(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_roletransition *roletrans = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_roletransition_init(&roletrans);
roletrans->src_str = parse_current->next->data;
roletrans->tgt_str = parse_current->next->next->data;
roletrans->obj_str = parse_current->next->next->next->data;
roletrans->result_str = parse_current->next->next->next->next->data;
ast_node->data = roletrans;
ast_node->flavor = CIL_ROLETRANSITION;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad roletransition rule");
cil_destroy_roletransition(roletrans);
return rc;
}
void cil_destroy_roletransition(struct cil_roletransition *roletrans)
{
if (roletrans == NULL) {
return;
}
free(roletrans);
}
int cil_gen_roleallow(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_roleallow *roleallow = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_roleallow_init(&roleallow);
roleallow->src_str = parse_current->next->data;
roleallow->tgt_str = parse_current->next->next->data;
ast_node->data = roleallow;
ast_node->flavor = CIL_ROLEALLOW;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad roleallow rule");
cil_destroy_roleallow(roleallow);
return rc;
}
void cil_destroy_roleallow(struct cil_roleallow *roleallow)
{
if (roleallow == NULL) {
return;
}
free(roleallow);
}
int cil_gen_roleattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_roleattribute *attr = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_roleattribute_init(&attr);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)attr, (hashtab_key_t)key, CIL_SYM_ROLES, CIL_ROLEATTRIBUTE);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad roleattribute declaration");
cil_destroy_roleattribute(attr);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_roleattribute(struct cil_roleattribute *attr)
{
if (attr == NULL) {
return;
}
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
struct cil_list_item *expr = attr->expr_list->head;
while (expr != NULL) {
struct cil_list_item *next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
cil_symtab_datum_destroy(&attr->datum);
ebitmap_destroy(attr->roles);
free(attr->roles);
free(attr);
}
int cil_gen_roleattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_roleattributeset *attrset = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_roleattributeset_init(&attrset);
attrset->attr_str = parse_current->next->data;
rc = cil_gen_expr(parse_current->next->next, CIL_ROLE, &attrset->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = attrset;
ast_node->flavor = CIL_ROLEATTRIBUTESET;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad roleattributeset declaration");
cil_destroy_roleattributeset(attrset);
return rc;
}
void cil_destroy_roleattributeset(struct cil_roleattributeset *attrset)
{
if (attrset == NULL) {
return;
}
cil_list_destroy(&attrset->str_expr, CIL_TRUE);
cil_list_destroy(&attrset->datum_expr, CIL_FALSE);
free(attrset);
}
int cil_gen_avrule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_avrule *rule = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_avrule_init(&rule);
rule->is_extended = 0;
rule->rule_kind = rule_kind;
rule->src_str = parse_current->next->data;
rule->tgt_str = parse_current->next->next->data;
rc = cil_fill_classperms_list(parse_current->next->next->next, &rule->perms.classperms);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = rule;
ast_node->flavor = CIL_AVRULE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad allow rule");
cil_destroy_avrule(rule);
return rc;
}
void cil_destroy_avrule(struct cil_avrule *rule)
{
if (rule == NULL) {
return;
}
if (!rule->is_extended) {
cil_destroy_classperms_list(&rule->perms.classperms);
} else {
if (rule->perms.x.permx_str == NULL && rule->perms.x.permx != NULL) {
cil_destroy_permissionx(rule->perms.x.permx);
}
}
free(rule);
}
static int cil_fill_permissionx(struct cil_tree_node *parse_current, struct cil_permissionx *permx)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
if (parse_current->data == CIL_KEY_IOCTL) {
permx->kind = CIL_PERMX_KIND_IOCTL;
} else if (parse_current->data == CIL_KEY_NLMSG) {
permx->kind = CIL_PERMX_KIND_NLMSG;
} else {
cil_log(CIL_ERR, "Unknown permissionx kind, %s. Must be \"ioctl\" or \"nlmsg\"\n", (char *)parse_current->data);
rc = SEPOL_ERR;
goto exit;
}
permx->obj_str = parse_current->next->data;
rc = cil_gen_expr(parse_current->next->next, CIL_PERMISSIONX, &permx->expr_str);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad permissionx content");
return rc;
}
int cil_gen_permissionx(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_permissionx *permx = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_permissionx_init(&permx);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)permx, (hashtab_key_t)key, CIL_SYM_PERMX, CIL_PERMISSIONX);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fill_permissionx(parse_current->next->next->cl_head, permx);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad permissionx statement");
cil_destroy_permissionx(permx);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_permissionx(struct cil_permissionx *permx)
{
if (permx == NULL) {
return;
}
cil_symtab_datum_destroy(&permx->datum);
cil_list_destroy(&permx->expr_str, CIL_TRUE);
ebitmap_destroy(permx->perms);
free(permx->perms);
free(permx);
}
int cil_gen_avrulex(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_avrule *rule = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_avrule_init(&rule);
rule->is_extended = 1;
rule->rule_kind = rule_kind;
rule->src_str = parse_current->next->data;
rule->tgt_str = parse_current->next->next->data;
if (parse_current->next->next->next->cl_head == NULL) {
rule->perms.x.permx_str = parse_current->next->next->next->data;
} else {
cil_permissionx_init(&rule->perms.x.permx);
rc = cil_fill_permissionx(parse_current->next->next->next->cl_head, rule->perms.x.permx);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = rule;
ast_node->flavor = CIL_AVRULEX;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad allowx rule");
cil_destroy_avrule(rule);
return rc;
}
int cil_gen_deny_rule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_deny_rule *rule = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_deny_rule_init(&rule);
rule->src_str = parse_current->next->data;
rule->tgt_str = parse_current->next->next->data;
rc = cil_fill_classperms_list(parse_current->next->next->next, &rule->classperms);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = rule;
ast_node->flavor = CIL_DENY_RULE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad deny rule");
cil_destroy_deny_rule(rule);
return rc;
}
void cil_destroy_deny_rule(struct cil_deny_rule *rule)
{
if (rule == NULL) {
return;
}
cil_destroy_classperms_list(&rule->classperms);
free(rule);
}
int cil_gen_type_rule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_type_rule *rule = NULL;
int rc = SEPOL_ERR;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_type_rule_init(&rule);
rule->rule_kind = rule_kind;
rule->src_str = parse_current->next->data;
rule->tgt_str = parse_current->next->next->data;
rule->obj_str = parse_current->next->next->next->data;
rule->result_str = parse_current->next->next->next->next->data;
ast_node->data = rule;
ast_node->flavor = CIL_TYPE_RULE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad type rule");
cil_destroy_type_rule(rule);
return rc;
}
void cil_destroy_type_rule(struct cil_type_rule *rule)
{
if (rule == NULL) {
return;
}
free(rule);
}
int cil_gen_type(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_type *type = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_type_init(&type);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)type, (hashtab_key_t)key, CIL_SYM_TYPES, CIL_TYPE);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
cil_destroy_type(type);
type = NULL;
} else {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad type declaration");
cil_destroy_type(type);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_type(struct cil_type *type)
{
if (type == NULL) {
return;
}
cil_symtab_datum_destroy(&type->datum);
free(type);
}
int cil_gen_typeattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_typeattribute *attr = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_typeattribute_init(&attr);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)attr, (hashtab_key_t)key, CIL_SYM_TYPES, CIL_TYPEATTRIBUTE);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
cil_destroy_typeattribute(attr);
attr = NULL;
} else {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad typeattribute declaration");
cil_destroy_typeattribute(attr);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_typeattribute(struct cil_typeattribute *attr)
{
if (attr == NULL) {
return;
}
cil_symtab_datum_destroy(&attr->datum);
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
struct cil_list_item *expr = attr->expr_list->head;
while (expr != NULL) {
struct cil_list_item *next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
ebitmap_destroy(attr->types);
free(attr->types);
free(attr);
}
int cil_gen_bool(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunableif)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_bool *boolean = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_bool_init(&boolean);
key = parse_current->next->data;
if (parse_current->next->next->data == CIL_KEY_CONDTRUE) {
boolean->value = CIL_TRUE;
} else if (parse_current->next->next->data == CIL_KEY_CONDFALSE) {
boolean->value = CIL_FALSE;
} else {
cil_log(CIL_ERR, "Value must be either \'true\' or \'false\'");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)boolean, (hashtab_key_t)key, CIL_SYM_BOOLS, CIL_BOOL);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
if (tunableif) {
cil_tree_log(parse_current, CIL_ERR, "Bad tunable (treated as a boolean due to preserve-tunables) declaration");
} else {
cil_tree_log(parse_current, CIL_ERR, "Bad boolean declaration");
}
cil_destroy_bool(boolean);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_bool(struct cil_bool *boolean)
{
if (boolean == NULL) {
return;
}
cil_symtab_datum_destroy(&boolean->datum);
free(boolean);
}
int cil_gen_tunable(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_tunable *tunable = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_tunable_init(&tunable);
key = parse_current->next->data;
if (parse_current->next->next->data == CIL_KEY_CONDTRUE) {
tunable->value = CIL_TRUE;
} else if (parse_current->next->next->data == CIL_KEY_CONDFALSE) {
tunable->value = CIL_FALSE;
} else {
cil_log(CIL_ERR, "Value must be either \'true\' or \'false\'");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)tunable, (hashtab_key_t)key, CIL_SYM_TUNABLES, CIL_TUNABLE);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad tunable declaration");
cil_destroy_tunable(tunable);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_tunable(struct cil_tunable *tunable)
{
if (tunable == NULL) {
return;
}
cil_symtab_datum_destroy(&tunable->datum);
free(tunable);
}
static enum cil_flavor __cil_get_expr_operator_flavor(const char *op)
{
if (op == NULL) return CIL_NONE;
else if (op == CIL_KEY_AND) return CIL_AND;
else if (op == CIL_KEY_OR) return CIL_OR;
else if (op == CIL_KEY_NOT) return CIL_NOT;
else if (op == CIL_KEY_EQ) return CIL_EQ; /* Only conditional */
else if (op == CIL_KEY_NEQ) return CIL_NEQ; /* Only conditional */
else if (op == CIL_KEY_XOR) return CIL_XOR;
else if (op == CIL_KEY_ALL) return CIL_ALL; /* Only set and permissionx */
else if (op == CIL_KEY_RANGE) return CIL_RANGE; /* Only catset and permissionx */
else return CIL_NONE;
}
static int __cil_fill_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list *expr);
static int __cil_fill_expr_helper(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list *expr)
{
int rc = SEPOL_ERR;
enum cil_flavor op;
op = __cil_get_expr_operator_flavor(current->data);
rc = cil_verify_expr_syntax(current, op, flavor);
if (rc != SEPOL_OK) {
goto exit;
}
if (op != CIL_NONE) {
cil_list_append(expr, CIL_OP, (void *)op);
current = current->next;
}
for (;current != NULL; current = current->next) {
rc = __cil_fill_expr(current, flavor, expr);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_fill_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list *expr)
{
int rc = SEPOL_ERR;
if (current->cl_head == NULL) {
enum cil_flavor op = __cil_get_expr_operator_flavor(current->data);
if (op != CIL_NONE) {
cil_log(CIL_ERR, "Operator (%s) not in an expression\n", (char*)current->data);
goto exit;
}
cil_list_append(expr, CIL_STRING, current->data);
} else {
struct cil_list *sub_expr;
cil_list_init(&sub_expr, flavor);
rc = __cil_fill_expr_helper(current->cl_head, flavor, sub_expr);
if (rc != SEPOL_OK) {
cil_list_destroy(&sub_expr, CIL_TRUE);
goto exit;
}
cil_list_append(expr, CIL_LIST, sub_expr);
}
return SEPOL_OK;
exit:
return rc;
}
int cil_gen_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **expr)
{
int rc = SEPOL_ERR;
cil_list_init(expr, flavor);
if (current->cl_head == NULL) {
rc = __cil_fill_expr(current, flavor, *expr);
} else {
rc = __cil_fill_expr_helper(current->cl_head, flavor, *expr);
}
if (rc != SEPOL_OK) {
cil_list_destroy(expr, CIL_TRUE);
cil_log(CIL_ERR, "Bad expression\n");
}
return rc;
}
static enum cil_flavor __cil_get_constraint_operator_flavor(const char *op)
{
if (op == CIL_KEY_AND) return CIL_AND;
else if (op == CIL_KEY_OR) return CIL_OR;
else if (op == CIL_KEY_NOT) return CIL_NOT;
else if (op == CIL_KEY_EQ) return CIL_EQ;
else if (op == CIL_KEY_NEQ) return CIL_NEQ;
else if (op == CIL_KEY_CONS_DOM) return CIL_CONS_DOM;
else if (op == CIL_KEY_CONS_DOMBY) return CIL_CONS_DOMBY;
else if (op == CIL_KEY_CONS_INCOMP) return CIL_CONS_INCOMP;
else return CIL_NONE;
}
static enum cil_flavor __cil_get_constraint_operand_flavor(const char *operand)
{
if (operand == NULL) return CIL_LIST;
else if (operand == CIL_KEY_CONS_T1) return CIL_CONS_T1;
else if (operand == CIL_KEY_CONS_T2) return CIL_CONS_T2;
else if (operand == CIL_KEY_CONS_T3) return CIL_CONS_T3;
else if (operand == CIL_KEY_CONS_R1) return CIL_CONS_R1;
else if (operand == CIL_KEY_CONS_R2) return CIL_CONS_R2;
else if (operand == CIL_KEY_CONS_R3) return CIL_CONS_R3;
else if (operand == CIL_KEY_CONS_U1) return CIL_CONS_U1;
else if (operand == CIL_KEY_CONS_U2) return CIL_CONS_U2;
else if (operand == CIL_KEY_CONS_U3) return CIL_CONS_U3;
else if (operand == CIL_KEY_CONS_L1) return CIL_CONS_L1;
else if (operand == CIL_KEY_CONS_L2) return CIL_CONS_L2;
else if (operand == CIL_KEY_CONS_H1) return CIL_CONS_H1;
else if (operand == CIL_KEY_CONS_H2) return CIL_CONS_H2;
else return CIL_STRING;
}
static int __cil_fill_constraint_leaf_expr(struct cil_tree_node *current, enum cil_flavor expr_flavor, enum cil_flavor op, struct cil_list **leaf_expr)
{
int rc = SEPOL_ERR;
enum cil_flavor leaf_expr_flavor = CIL_NONE;
enum cil_flavor l_flavor = CIL_NONE;
enum cil_flavor r_flavor = CIL_NONE;
l_flavor = __cil_get_constraint_operand_flavor(current->next->data);
r_flavor = __cil_get_constraint_operand_flavor(current->next->next->data);
switch (l_flavor) {
case CIL_CONS_U1:
case CIL_CONS_U2:
case CIL_CONS_U3:
leaf_expr_flavor = CIL_USER;
break;
case CIL_CONS_R1:
case CIL_CONS_R2:
case CIL_CONS_R3:
leaf_expr_flavor = CIL_ROLE;
break;
case CIL_CONS_T1:
case CIL_CONS_T2:
case CIL_CONS_T3:
leaf_expr_flavor = CIL_TYPE;
break;
case CIL_CONS_L1:
case CIL_CONS_L2:
case CIL_CONS_H1:
case CIL_CONS_H2:
leaf_expr_flavor = CIL_LEVEL;
break;
default:
cil_log(CIL_ERR, "Invalid left operand (%s)\n", (char*)current->next->data);
goto exit;
}
rc = cil_verify_constraint_leaf_expr_syntax(l_flavor, r_flavor, op, expr_flavor);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_init(leaf_expr, leaf_expr_flavor);
cil_list_append(*leaf_expr, CIL_OP, (void *)op);
cil_list_append(*leaf_expr, CIL_CONS_OPERAND, (void *)l_flavor);
if (r_flavor == CIL_STRING) {
cil_list_append(*leaf_expr, CIL_STRING, current->next->next->data);
} else if (r_flavor == CIL_LIST) {
struct cil_list *sub_list;
rc = cil_fill_list(current->next->next->cl_head, leaf_expr_flavor, &sub_list);
if (rc != SEPOL_OK) {
cil_list_destroy(leaf_expr, CIL_TRUE);
goto exit;
}
cil_list_append(*leaf_expr, CIL_LIST, sub_list);
} else {
cil_list_append(*leaf_expr, CIL_CONS_OPERAND, (void *)r_flavor);
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_fill_constraint_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **expr)
{
int rc = SEPOL_ERR;
enum cil_flavor op;
struct cil_list *lexpr;
struct cil_list *rexpr;
if (current->data == NULL || current->cl_head != NULL) {
cil_log(CIL_ERR, "Expected a string at the start of the constraint expression\n");
goto exit;
}
op = __cil_get_constraint_operator_flavor(current->data);
rc = cil_verify_constraint_expr_syntax(current, op);
if (rc != SEPOL_OK) {
goto exit;
}
switch (op) {
case CIL_EQ:
case CIL_NEQ:
case CIL_CONS_DOM:
case CIL_CONS_DOMBY:
case CIL_CONS_INCOMP:
rc = __cil_fill_constraint_leaf_expr(current, flavor, op, expr);
if (rc != SEPOL_OK) {
goto exit;
}
break;
case CIL_NOT:
rc = __cil_fill_constraint_expr(current->next->cl_head, flavor, &lexpr);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_init(expr, flavor);
cil_list_append(*expr, CIL_OP, (void *)op);
cil_list_append(*expr, CIL_LIST, lexpr);
break;
default:
rc = __cil_fill_constraint_expr(current->next->cl_head, flavor, &lexpr);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_fill_constraint_expr(current->next->next->cl_head, flavor, &rexpr);
if (rc != SEPOL_OK) {
cil_list_destroy(&lexpr, CIL_TRUE);
goto exit;
}
cil_list_init(expr, flavor);
cil_list_append(*expr, CIL_OP, (void *)op);
cil_list_append(*expr, CIL_LIST, lexpr);
cil_list_append(*expr, CIL_LIST, rexpr);
break;
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_gen_constraint_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **expr)
{
int rc = SEPOL_ERR;
if (current->cl_head == NULL) {
goto exit;
}
rc = __cil_fill_constraint_expr(current->cl_head, flavor, expr);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad expression tree for constraint\n");
return rc;
}
int cil_gen_boolif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunableif)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_LIST,
CIL_SYN_LIST | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_booleanif *bif = NULL;
struct cil_tree_node *next = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_boolif_init(&bif);
bif->preserved_tunable = tunableif;
rc = cil_gen_expr(parse_current->next, CIL_BOOL, &bif->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_verify_conditional_blocks(parse_current->next->next);
if (rc != SEPOL_OK) {
goto exit;
}
/* Destroying expr tree */
next = parse_current->next->next;
cil_tree_subtree_destroy(parse_current->next);
parse_current->next = next;
ast_node->flavor = CIL_BOOLEANIF;
ast_node->data = bif;
return SEPOL_OK;
exit:
if (tunableif) {
cil_tree_log(parse_current, CIL_ERR, "Bad tunableif (treated as a booleanif due to preserve-tunables) declaration");
} else {
cil_tree_log(parse_current, CIL_ERR, "Bad booleanif declaration");
}
cil_destroy_boolif(bif);
return rc;
}
void cil_destroy_boolif(struct cil_booleanif *bif)
{
if (bif == NULL) {
return;
}
cil_list_destroy(&bif->str_expr, CIL_TRUE);
cil_list_destroy(&bif->datum_expr, CIL_FALSE);
free(bif);
}
int cil_gen_tunif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_LIST,
CIL_SYN_LIST | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_tunableif *tif = NULL;
struct cil_tree_node *next = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_tunif_init(&tif);
rc = cil_gen_expr(parse_current->next, CIL_TUNABLE, &tif->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_verify_conditional_blocks(parse_current->next->next);
if (rc != SEPOL_OK) {
goto exit;
}
/* Destroying expr tree */
next = parse_current->next->next;
cil_tree_subtree_destroy(parse_current->next);
parse_current->next = next;
ast_node->flavor = CIL_TUNABLEIF;
ast_node->data = tif;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad tunableif declaration");
cil_destroy_tunif(tif);
return rc;
}
void cil_destroy_tunif(struct cil_tunableif *tif)
{
if (tif == NULL) {
return;
}
cil_list_destroy(&tif->str_expr, CIL_TRUE);
cil_list_destroy(&tif->datum_expr, CIL_FALSE);
free(tif);
}
int cil_gen_condblock(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_N_LISTS,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_condblock *cb = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
if (ast_node->parent->flavor != CIL_BOOLEANIF && ast_node->parent->flavor != CIL_TUNABLEIF) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Conditional statements must be a direct child of a tunableif or booleanif statement.\n");
goto exit;
}
ast_node->flavor = CIL_CONDBLOCK;
cil_condblock_init(&cb);
cb->flavor = flavor;
ast_node->data = cb;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad %s condition declaration",
(char*)parse_current->data);
cil_destroy_condblock(cb);
return rc;
}
void cil_destroy_condblock(struct cil_condblock *cb)
{
if (cb == NULL) {
return;
}
cil_symtab_array_destroy(cb->symtab);
free(cb);
}
int cil_gen_alias(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_alias *alias = NULL;
enum cil_sym_index sym_index;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_alias_init(&alias);
key = parse_current->next->data;
rc = cil_flavor_to_symtab_index(flavor, &sym_index);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)alias, (hashtab_key_t)key, sym_index, flavor);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad %s declaration", (char*)parse_current->data);
cil_destroy_alias(alias);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_alias(struct cil_alias *alias)
{
if (alias == NULL) {
return;
}
cil_symtab_datum_destroy(&alias->datum);
alias->actual = NULL;
free(alias);
}
int cil_gen_aliasactual(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_aliasactual *aliasactual = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_aliasactual_init(&aliasactual);
aliasactual->alias_str = parse_current->next->data;
aliasactual->actual_str = parse_current->next->next->data;
ast_node->data = aliasactual;
ast_node->flavor = flavor;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad %s association", cil_node_to_string(parse_current));
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_aliasactual(struct cil_aliasactual *aliasactual)
{
if (aliasactual == NULL) {
return;
}
free(aliasactual);
}
int cil_gen_typeattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_typeattributeset *attrset = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_typeattributeset_init(&attrset);
attrset->attr_str = parse_current->next->data;
rc = cil_gen_expr(parse_current->next->next, CIL_TYPE, &attrset->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = attrset;
ast_node->flavor = CIL_TYPEATTRIBUTESET;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad typeattributeset statement");
cil_destroy_typeattributeset(attrset);
return rc;
}
void cil_destroy_typeattributeset(struct cil_typeattributeset *attrset)
{
if (attrset == NULL) {
return;
}
cil_list_destroy(&attrset->str_expr, CIL_TRUE);
cil_list_destroy(&attrset->datum_expr, CIL_FALSE);
free(attrset);
}
int cil_gen_expandtypeattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING,
CIL_SYN_END
};
char *expand_str;
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_expandtypeattribute *expandattr = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_expandtypeattribute_init(&expandattr);
if (parse_current->next->cl_head == NULL) {
cil_list_init(&expandattr->attr_strs, CIL_TYPE);
cil_list_append(expandattr->attr_strs, CIL_STRING, parse_current->next->data);
} else {
rc = cil_fill_list(parse_current->next->cl_head, CIL_TYPE, &expandattr->attr_strs);
if (rc != SEPOL_OK) {
goto exit;
}
}
expand_str = parse_current->next->next->data;
if (expand_str == CIL_KEY_CONDTRUE) {
expandattr->expand = CIL_TRUE;
} else if (expand_str == CIL_KEY_CONDFALSE) {
expandattr->expand = CIL_FALSE;
} else {
cil_log(CIL_ERR, "Value must be either \'true\' or \'false\'");
rc = SEPOL_ERR;
goto exit;
}
ast_node->data = expandattr;
ast_node->flavor = CIL_EXPANDTYPEATTRIBUTE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad expandtypeattribute statement");
cil_destroy_expandtypeattribute(expandattr);
return rc;
}
void cil_destroy_expandtypeattribute(struct cil_expandtypeattribute *expandattr)
{
if (expandattr == NULL) {
return;
}
cil_list_destroy(&expandattr->attr_strs, CIL_TRUE);
cil_list_destroy(&expandattr->attr_datums, CIL_FALSE);
free(expandattr);
}
int cil_gen_typepermissive(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_typepermissive *typeperm = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_typepermissive_init(&typeperm);
typeperm->type_str = parse_current->next->data;
ast_node->data = typeperm;
ast_node->flavor = CIL_TYPEPERMISSIVE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad typepermissive declaration");
cil_destroy_typepermissive(typeperm);
return rc;
}
void cil_destroy_typepermissive(struct cil_typepermissive *typeperm)
{
if (typeperm == NULL) {
return;
}
free(typeperm);
}
int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *s1, *s2, *s3, *s4, *s5;
if (db == NULL || parse_current == NULL || ast_node == NULL ) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
s1 = parse_current->next->data;
s2 = parse_current->next->next->data;
s3 = parse_current->next->next->next->data;
s4 = parse_current->next->next->next->next->data;
s5 = NULL;
if (parse_current->next->next->next->next->next) {
if (s4 == CIL_KEY_STAR) {
s4 = parse_current->next->next->next->next->next->data;
} else {
s5 = parse_current->next->next->next->next->next->data;
}
}
if (s5) {
struct cil_nametypetransition *nametypetrans = NULL;
cil_nametypetransition_init(&nametypetrans);
ast_node->data = nametypetrans;
ast_node->flavor = CIL_NAMETYPETRANSITION;
nametypetrans->src_str = s1;
nametypetrans->tgt_str = s2;
nametypetrans->obj_str = s3;
nametypetrans->name_str = s4;
nametypetrans->name = cil_gen_declared_string(db, s4, ast_node);
nametypetrans->result_str = s5;
} else {
struct cil_type_rule *rule = NULL;
cil_type_rule_init(&rule);
ast_node->data = rule;
ast_node->flavor = CIL_TYPE_RULE;
rule->rule_kind = CIL_TYPE_TRANSITION;
rule->src_str = s1;
rule->tgt_str = s2;
rule->obj_str = s3;
rule->result_str = s4;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad typetransition declaration");
return rc;
}
void cil_destroy_typetransition(struct cil_nametypetransition *nametypetrans)
{
if (nametypetrans == NULL) {
return;
}
free(nametypetrans);
}
int cil_gen_rangetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_rangetransition *rangetrans = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL ) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_rangetransition_init(&rangetrans);
rangetrans->src_str = parse_current->next->data;
rangetrans->exec_str = parse_current->next->next->data;
rangetrans->obj_str = parse_current->next->next->next->data;
rangetrans->range_str = NULL;
if (parse_current->next->next->next->next->cl_head == NULL) {
rangetrans->range_str = parse_current->next->next->next->next->data;
} else {
cil_levelrange_init(&rangetrans->range);
rc = cil_fill_levelrange(parse_current->next->next->next->next->cl_head, rangetrans->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = rangetrans;
ast_node->flavor = CIL_RANGETRANSITION;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad rangetransition declaration");
cil_destroy_rangetransition(rangetrans);
return rc;
}
void cil_destroy_rangetransition(struct cil_rangetransition *rangetrans)
{
if (rangetrans == NULL) {
return;
}
if (rangetrans->range_str == NULL && rangetrans->range != NULL) {
cil_destroy_levelrange(rangetrans->range);
}
free(rangetrans);
}
int cil_gen_sensitivity(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_sens *sens = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_sens_init(&sens);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)sens, (hashtab_key_t)key, CIL_SYM_SENS, CIL_SENS);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad sensitivity declaration");
cil_destroy_sensitivity(sens);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_sensitivity(struct cil_sens *sens)
{
if (sens == NULL) {
return;
}
cil_symtab_datum_destroy(&sens->datum);
cil_list_destroy(&sens->cats_list, CIL_FALSE);
free(sens);
}
int cil_gen_category(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_cat *cat = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_cat_init(&cat);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)cat, (hashtab_key_t)key, CIL_SYM_CATS, CIL_CAT);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad category declaration");
cil_destroy_category(cat);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_category(struct cil_cat *cat)
{
if (cat == NULL) {
return;
}
cil_symtab_datum_destroy(&cat->datum);
free(cat);
}
static int cil_gen_catset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_catset *catset = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_catset_init(&catset);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)catset, (hashtab_key_t)key, CIL_SYM_CATS, CIL_CATSET);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fill_cats(parse_current->next->next, &catset->cats);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad categoryset declaration");
cil_destroy_catset(catset);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_catset(struct cil_catset *catset)
{
if (catset == NULL) {
return;
}
cil_symtab_datum_destroy(&catset->datum);
cil_destroy_cats(catset->cats);
free(catset);
}
int cil_gen_senscat(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_senscat *senscat = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_senscat_init(&senscat);
senscat->sens_str = parse_current->next->data;
rc = cil_fill_cats(parse_current->next->next, &senscat->cats);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = senscat;
ast_node->flavor = CIL_SENSCAT;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad sensitivitycategory declaration");
cil_destroy_senscat(senscat);
return rc;
}
void cil_destroy_senscat(struct cil_senscat *senscat)
{
if (senscat == NULL) {
return;
}
cil_destroy_cats(senscat->cats);
free(senscat);
}
int cil_gen_level(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_level *level = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_level_init(&level);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)level, (hashtab_key_t)key, CIL_SYM_LEVELS, CIL_LEVEL);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fill_level(parse_current->next->next->cl_head, level);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad level declaration");
cil_destroy_level(level);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_level(struct cil_level *level)
{
if (level == NULL) {
return;
}
cil_symtab_datum_destroy(&level->datum);
cil_destroy_cats(level->cats);
free(level);
}
/* low should be pointing to either the name of the low level or to an open paren for an anonymous low level */
int cil_fill_levelrange(struct cil_tree_node *low, struct cil_levelrange *lvlrange)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
if (low == NULL || lvlrange == NULL) {
goto exit;
}
rc = __cil_verify_syntax(low, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
if (low->cl_head == NULL) {
lvlrange->low_str = low->data;
} else {
cil_level_init(&lvlrange->low);
rc = cil_fill_level(low->cl_head, lvlrange->low);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (low->next->cl_head == NULL) {
lvlrange->high_str = low->next->data;
} else {
cil_level_init(&lvlrange->high);
rc = cil_fill_level(low->next->cl_head, lvlrange->high);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad levelrange\n");
return rc;
}
int cil_gen_levelrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_levelrange *lvlrange = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_levelrange_init(&lvlrange);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)lvlrange, (hashtab_key_t)key, CIL_SYM_LEVELRANGES, CIL_LEVELRANGE);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fill_levelrange(parse_current->next->next->cl_head, lvlrange);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad levelrange declaration");
cil_destroy_levelrange(lvlrange);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_levelrange(struct cil_levelrange *lvlrange)
{
if (lvlrange == NULL) {
return;
}
cil_symtab_datum_destroy(&lvlrange->datum);
if (lvlrange->low_str == NULL) {
cil_destroy_level(lvlrange->low);
}
if (lvlrange->high_str == NULL) {
cil_destroy_level(lvlrange->high);
}
free(lvlrange);
}
int cil_gen_constrain(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_constrain *cons = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_constrain_init(&cons);
rc = cil_fill_classperms_list(parse_current->next, &cons->classperms);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_constraint_expr(parse_current->next->next, flavor, &cons->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = cons;
ast_node->flavor = flavor;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad constrain declaration");
cil_destroy_constrain(cons);
return rc;
}
void cil_destroy_constrain(struct cil_constrain *cons)
{
if (cons == NULL) {
return;
}
cil_destroy_classperms_list(&cons->classperms);
cil_list_destroy(&cons->str_expr, CIL_TRUE);
cil_list_destroy(&cons->datum_expr, CIL_FALSE);
free(cons);
}
int cil_gen_validatetrans(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_validatetrans *validtrans = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_validatetrans_init(&validtrans);
validtrans->class_str = parse_current->next->data;
rc = cil_gen_constraint_expr(parse_current->next->next, flavor, &validtrans->str_expr);
if (rc != SEPOL_OK) {
goto exit;
}
ast_node->data = validtrans;
ast_node->flavor = flavor;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad validatetrans declaration");
cil_destroy_validatetrans(validtrans);
return rc;
}
void cil_destroy_validatetrans(struct cil_validatetrans *validtrans)
{
if (validtrans == NULL) {
return;
}
cil_list_destroy(&validtrans->str_expr, CIL_TRUE);
cil_list_destroy(&validtrans->datum_expr, CIL_FALSE);
free(validtrans);
}
/* Fills in context starting from user */
int cil_fill_context(struct cil_tree_node *user_node, struct cil_context *context)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
if (user_node == NULL || context == NULL) {
goto exit;
}
rc = __cil_verify_syntax(user_node, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
context->user_str = user_node->data;
context->role_str = user_node->next->data;
context->type_str = user_node->next->next->data;
context->range_str = NULL;
if (user_node->next->next->next->cl_head == NULL) {
context->range_str = user_node->next->next->next->data;
} else {
cil_levelrange_init(&context->range);
rc = cil_fill_levelrange(user_node->next->next->next->cl_head, context->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad context\n");
return rc;
}
int cil_gen_context(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_context *context = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_context_init(&context);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)context, (hashtab_key_t)key, CIL_SYM_CONTEXTS, CIL_CONTEXT);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_fill_context(parse_current->next->next->cl_head, context);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad context declaration");
cil_destroy_context(context);
cil_clear_node(ast_node);
return SEPOL_ERR;
}
void cil_destroy_context(struct cil_context *context)
{
if (context == NULL) {
return;
}
cil_symtab_datum_destroy(&context->datum);
if (context->range_str == NULL && context->range != NULL) {
cil_destroy_levelrange(context->range);
}
free(context);
}
int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST | CIL_SYN_EMPTY_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_filecon *filecon = NULL;
char *type = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
type = parse_current->next->next->data;
cil_filecon_init(&filecon);
ast_node->data = filecon;
ast_node->flavor = CIL_FILECON;
filecon->path_str = parse_current->next->data;
/* filecon->path will be NULL if in a macro and the path is an argument */
filecon->path = cil_gen_declared_string(db, filecon->path_str, ast_node);
if (type == CIL_KEY_ANY) {
filecon->type = CIL_FILECON_ANY;
} else if (type == CIL_KEY_FILE) {
filecon->type = CIL_FILECON_FILE;
} else if (type == CIL_KEY_DIR) {
filecon->type = CIL_FILECON_DIR;
} else if (type == CIL_KEY_CHAR) {
filecon->type = CIL_FILECON_CHAR;
} else if (type == CIL_KEY_BLOCK) {
filecon->type = CIL_FILECON_BLOCK;
} else if (type == CIL_KEY_SOCKET) {
filecon->type = CIL_FILECON_SOCKET;
} else if (type == CIL_KEY_PIPE) {
filecon->type = CIL_FILECON_PIPE;
} else if (type == CIL_KEY_SYMLINK) {
filecon->type = CIL_FILECON_SYMLINK;
} else {
cil_log(CIL_ERR, "Invalid file type\n");
rc = SEPOL_ERR;
goto exit;
}
if (parse_current->next->next->next->cl_head == NULL) {
filecon->context_str = parse_current->next->next->next->data;
} else {
if (parse_current->next->next->next->cl_head->next == NULL) {
filecon->context = NULL;
} else {
cil_context_init(&filecon->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, filecon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad filecon declaration");
cil_destroy_filecon(filecon);
cil_clear_node(ast_node);
return rc;
}
//TODO: Should we be checking if the pointer is NULL when passed in?
void cil_destroy_filecon(struct cil_filecon *filecon)
{
if (filecon == NULL) {
return;
}
if (filecon->context_str == NULL && filecon->context != NULL) {
cil_destroy_context(filecon->context);
}
free(filecon);
}
int cil_gen_ibpkeycon(__attribute__((unused)) struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax) / sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_ibpkeycon *ibpkeycon = NULL;
if (!parse_current || !ast_node)
goto exit;
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK)
goto exit;
cil_ibpkeycon_init(&ibpkeycon);
ibpkeycon->subnet_prefix_str = parse_current->next->data;
if (parse_current->next->next->cl_head) {
if (parse_current->next->next->cl_head->next &&
!parse_current->next->next->cl_head->next->next) {
rc = cil_fill_integer(parse_current->next->next->cl_head, &ibpkeycon->pkey_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ibpkey specified\n");
goto exit;
}
rc = cil_fill_integer(parse_current->next->next->cl_head->next, &ibpkeycon->pkey_high, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ibpkey specified\n");
goto exit;
}
} else {
cil_log(CIL_ERR, "Improper ibpkey range specified\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
rc = cil_fill_integer(parse_current->next->next, &ibpkeycon->pkey_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ibpkey specified\n");
goto exit;
}
ibpkeycon->pkey_high = ibpkeycon->pkey_low;
}
if (!parse_current->next->next->next->cl_head) {
ibpkeycon->context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&ibpkeycon->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, ibpkeycon->context);
if (rc != SEPOL_OK)
goto exit;
}
ast_node->data = ibpkeycon;
ast_node->flavor = CIL_IBPKEYCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad ibpkeycon declaration");
cil_destroy_ibpkeycon(ibpkeycon);
return rc;
}
void cil_destroy_ibpkeycon(struct cil_ibpkeycon *ibpkeycon)
{
if (!ibpkeycon)
return;
if (!ibpkeycon->context_str && ibpkeycon->context)
cil_destroy_context(ibpkeycon->context);
free(ibpkeycon);
}
int cil_gen_portcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_portcon *portcon = NULL;
char *proto;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_portcon_init(&portcon);
proto = parse_current->next->data;
if (proto == CIL_KEY_UDP) {
portcon->proto = CIL_PROTOCOL_UDP;
} else if (proto == CIL_KEY_TCP) {
portcon->proto = CIL_PROTOCOL_TCP;
} else if (proto == CIL_KEY_DCCP) {
portcon->proto = CIL_PROTOCOL_DCCP;
} else if (proto == CIL_KEY_SCTP) {
portcon->proto = CIL_PROTOCOL_SCTP;
} else {
cil_log(CIL_ERR, "Invalid protocol\n");
rc = SEPOL_ERR;
goto exit;
}
if (parse_current->next->next->cl_head != NULL) {
if (parse_current->next->next->cl_head->next != NULL
&& parse_current->next->next->cl_head->next->next == NULL) {
rc = cil_fill_integer(parse_current->next->next->cl_head, &portcon->port_low, 10);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper port specified\n");
goto exit;
}
rc = cil_fill_integer(parse_current->next->next->cl_head->next, &portcon->port_high, 10);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper port specified\n");
goto exit;
}
} else {
cil_log(CIL_ERR, "Improper port range specified\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
rc = cil_fill_integer(parse_current->next->next, &portcon->port_low, 10);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper port specified\n");
goto exit;
}
portcon->port_high = portcon->port_low;
}
if (parse_current->next->next->next->cl_head == NULL ) {
portcon->context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&portcon->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, portcon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = portcon;
ast_node->flavor = CIL_PORTCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad portcon declaration");
cil_destroy_portcon(portcon);
return rc;
}
void cil_destroy_portcon(struct cil_portcon *portcon)
{
if (portcon == NULL) {
return;
}
if (portcon->context_str == NULL && portcon->context != NULL) {
cil_destroy_context(portcon->context);
}
free(portcon);
}
int cil_gen_nodecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_nodecon *nodecon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_nodecon_init(&nodecon);
if (parse_current->next->cl_head) {
cil_ipaddr_init(&nodecon->addr);
rc = cil_fill_ipaddr(parse_current->next->cl_head, nodecon->addr);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
char *addr = parse_current->next->data;
if (strchr(addr, ':') || (strchr(addr, '.') && isdigit(addr[0]))) {
cil_ipaddr_init(&nodecon->addr);
rc = cil_fill_ipaddr(parse_current->next, nodecon->addr);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
nodecon->addr_str = addr;
}
}
if (parse_current->next->next->cl_head) {
cil_ipaddr_init(&nodecon->mask);
rc = cil_fill_ipaddr(parse_current->next->next->cl_head, nodecon->mask);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
char *mask = parse_current->next->next->data;
if (strchr(mask, ':') || (strchr(mask, '.') && isdigit(mask[0]))) {
cil_ipaddr_init(&nodecon->mask);
rc = cil_fill_ipaddr(parse_current->next->next, nodecon->mask);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
nodecon->mask_str = mask;
}
}
if (parse_current->next->next->next->cl_head == NULL ) {
nodecon->context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&nodecon->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, nodecon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = nodecon;
ast_node->flavor = CIL_NODECON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad nodecon declaration");
cil_destroy_nodecon(nodecon);
return rc;
}
void cil_destroy_nodecon(struct cil_nodecon *nodecon)
{
if (nodecon == NULL) {
return;
}
if (nodecon->addr_str == NULL && nodecon->addr != NULL) {
cil_destroy_ipaddr(nodecon->addr);
}
if (nodecon->mask_str == NULL && nodecon->mask != NULL) {
cil_destroy_ipaddr(nodecon->mask);
}
if (nodecon->context_str == NULL && nodecon->context != NULL) {
cil_destroy_context(nodecon->context);
}
free(nodecon);
}
int cil_gen_genfscon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_tree_node *context_node;
int rc = SEPOL_ERR;
struct cil_genfscon *genfscon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_genfscon_init(&genfscon);
genfscon->fs_str = parse_current->next->data;
genfscon->path_str = parse_current->next->next->data;
if (parse_current->next->next->next->next) {
/* (genfscon ... */
char *file_type = parse_current->next->next->next->data;
if (file_type == CIL_KEY_ANY) {
genfscon->file_type = CIL_FILECON_ANY;
} else if (file_type == CIL_KEY_FILE) {
genfscon->file_type = CIL_FILECON_FILE;
} else if (file_type == CIL_KEY_DIR) {
genfscon->file_type = CIL_FILECON_DIR;
} else if (file_type == CIL_KEY_CHAR) {
genfscon->file_type = CIL_FILECON_CHAR;
} else if (file_type == CIL_KEY_BLOCK) {
genfscon->file_type = CIL_FILECON_BLOCK;
} else if (file_type == CIL_KEY_SOCKET) {
genfscon->file_type = CIL_FILECON_SOCKET;
} else if (file_type == CIL_KEY_PIPE) {
genfscon->file_type = CIL_FILECON_PIPE;
} else if (file_type == CIL_KEY_SYMLINK) {
genfscon->file_type = CIL_FILECON_SYMLINK;
} else {
if (parse_current->next->next->next->cl_head) {
cil_log(CIL_ERR, "Expecting file type, but found a list\n");
} else {
cil_log(CIL_ERR, "Invalid file type \"%s\"\n", file_type);
}
goto exit;
}
context_node = parse_current->next->next->next->next;
} else {
/* (genfscon ... */
context_node = parse_current->next->next->next;
}
if (context_node->cl_head) {
cil_context_init(&genfscon->context);
rc = cil_fill_context(context_node->cl_head, genfscon->context);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
genfscon->context_str = context_node->data;
}
ast_node->data = genfscon;
ast_node->flavor = CIL_GENFSCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad genfscon declaration");
cil_destroy_genfscon(genfscon);
return SEPOL_ERR;
}
void cil_destroy_genfscon(struct cil_genfscon *genfscon)
{
if (genfscon == NULL) {
return;
}
if (genfscon->context_str == NULL && genfscon->context != NULL) {
cil_destroy_context(genfscon->context);
}
free(genfscon);
}
int cil_gen_netifcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_netifcon *netifcon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_netifcon_init(&netifcon);
netifcon->interface_str = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
netifcon->if_context_str = parse_current->next->next->data;
} else {
cil_context_init(&netifcon->if_context);
rc = cil_fill_context(parse_current->next->next->cl_head, netifcon->if_context);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (parse_current->next->next->next->cl_head == NULL) {
netifcon->packet_context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&netifcon->packet_context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, netifcon->packet_context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = netifcon;
ast_node->flavor = CIL_NETIFCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad netifcon declaration");
cil_destroy_netifcon(netifcon);
return SEPOL_ERR;
}
void cil_destroy_netifcon(struct cil_netifcon *netifcon)
{
if (netifcon == NULL) {
return;
}
if (netifcon->if_context_str == NULL && netifcon->if_context != NULL) {
cil_destroy_context(netifcon->if_context);
}
if (netifcon->packet_context_str == NULL && netifcon->packet_context != NULL) {
cil_destroy_context(netifcon->packet_context);
}
free(netifcon);
}
int cil_gen_ibendportcon(__attribute__((unused)) struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax) / sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_ibendportcon *ibendportcon = NULL;
if (!parse_current || !ast_node)
goto exit;
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK)
goto exit;
cil_ibendportcon_init(&ibendportcon);
ibendportcon->dev_name_str = parse_current->next->data;
rc = cil_fill_integer(parse_current->next->next, &ibendportcon->port, 10);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ibendport port specified\n");
goto exit;
}
if (!parse_current->next->next->next->cl_head) {
ibendportcon->context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&ibendportcon->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, ibendportcon->context);
if (rc != SEPOL_OK)
goto exit;
}
ast_node->data = ibendportcon;
ast_node->flavor = CIL_IBENDPORTCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad ibendportcon declaration");
cil_destroy_ibendportcon(ibendportcon);
return SEPOL_ERR;
}
void cil_destroy_ibendportcon(struct cil_ibendportcon *ibendportcon)
{
if (!ibendportcon)
return;
if (!ibendportcon->context_str && ibendportcon->context)
cil_destroy_context(ibendportcon->context);
free(ibendportcon);
}
int cil_gen_pirqcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_pirqcon *pirqcon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_pirqcon_init(&pirqcon);
rc = cil_fill_integer(parse_current->next, &pirqcon->pirq, 10);
if (rc != SEPOL_OK) {
goto exit;
}
if (parse_current->next->next->cl_head == NULL) {
pirqcon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&pirqcon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, pirqcon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = pirqcon;
ast_node->flavor = CIL_PIRQCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad pirqcon declaration");
cil_destroy_pirqcon(pirqcon);
return rc;
}
void cil_destroy_pirqcon(struct cil_pirqcon *pirqcon)
{
if (pirqcon == NULL) {
return;
}
if (pirqcon->context_str == NULL && pirqcon->context != NULL) {
cil_destroy_context(pirqcon->context);
}
free(pirqcon);
}
int cil_gen_iomemcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_iomemcon *iomemcon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_iomemcon_init(&iomemcon);
if (parse_current->next->cl_head != NULL) {
if (parse_current->next->cl_head->next != NULL &&
parse_current->next->cl_head->next->next == NULL) {
rc = cil_fill_integer64(parse_current->next->cl_head, &iomemcon->iomem_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper iomem specified\n");
goto exit;
}
rc = cil_fill_integer64(parse_current->next->cl_head->next, &iomemcon->iomem_high, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper iomem specified\n");
goto exit;
}
} else {
cil_log(CIL_ERR, "Improper iomem range specified\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
rc = cil_fill_integer64(parse_current->next, &iomemcon->iomem_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper iomem specified\n");
goto exit;
}
iomemcon->iomem_high = iomemcon->iomem_low;
}
if (parse_current->next->next->cl_head == NULL ) {
iomemcon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&iomemcon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, iomemcon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = iomemcon;
ast_node->flavor = CIL_IOMEMCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad iomemcon declaration");
cil_destroy_iomemcon(iomemcon);
return rc;
}
void cil_destroy_iomemcon(struct cil_iomemcon *iomemcon)
{
if (iomemcon == NULL) {
return;
}
if (iomemcon->context_str == NULL && iomemcon->context != NULL) {
cil_destroy_context(iomemcon->context);
}
free(iomemcon);
}
int cil_gen_ioportcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_ioportcon *ioportcon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_ioportcon_init(&ioportcon);
if (parse_current->next->cl_head != NULL) {
if (parse_current->next->cl_head->next != NULL &&
parse_current->next->cl_head->next->next == NULL) {
rc = cil_fill_integer(parse_current->next->cl_head, &ioportcon->ioport_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ioport specified\n");
goto exit;
}
rc = cil_fill_integer(parse_current->next->cl_head->next, &ioportcon->ioport_high, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ioport specified\n");
goto exit;
}
} else {
cil_log(CIL_ERR, "Improper ioport range specified\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
rc = cil_fill_integer(parse_current->next, &ioportcon->ioport_low, 0);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Improper ioport specified\n");
goto exit;
}
ioportcon->ioport_high = ioportcon->ioport_low;
}
if (parse_current->next->next->cl_head == NULL ) {
ioportcon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&ioportcon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, ioportcon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = ioportcon;
ast_node->flavor = CIL_IOPORTCON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad ioportcon declaration");
cil_destroy_ioportcon(ioportcon);
return rc;
}
void cil_destroy_ioportcon(struct cil_ioportcon *ioportcon)
{
if (ioportcon == NULL) {
return;
}
if (ioportcon->context_str == NULL && ioportcon->context != NULL) {
cil_destroy_context(ioportcon->context);
}
free(ioportcon);
}
int cil_gen_pcidevicecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_pcidevicecon *pcidevicecon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_pcidevicecon_init(&pcidevicecon);
rc = cil_fill_integer(parse_current->next, &pcidevicecon->dev, 0);
if (rc != SEPOL_OK) {
goto exit;
}
if (parse_current->next->next->cl_head == NULL) {
pcidevicecon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&pcidevicecon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, pcidevicecon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = pcidevicecon;
ast_node->flavor = CIL_PCIDEVICECON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad pcidevicecon declaration");
cil_destroy_pcidevicecon(pcidevicecon);
return rc;
}
void cil_destroy_pcidevicecon(struct cil_pcidevicecon *pcidevicecon)
{
if (pcidevicecon == NULL) {
return;
}
if (pcidevicecon->context_str == NULL && pcidevicecon->context != NULL) {
cil_destroy_context(pcidevicecon->context);
}
free(pcidevicecon);
}
int cil_gen_devicetreecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
int rc = SEPOL_ERR;
struct cil_devicetreecon *devicetreecon = NULL;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_devicetreecon_init(&devicetreecon);
devicetreecon->path = parse_current->next->data;
if (parse_current->next->next->cl_head == NULL) {
devicetreecon->context_str = parse_current->next->next->data;
} else {
cil_context_init(&devicetreecon->context);
rc = cil_fill_context(parse_current->next->next->cl_head, devicetreecon->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = devicetreecon;
ast_node->flavor = CIL_DEVICETREECON;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad devicetreecon declaration");
cil_destroy_devicetreecon(devicetreecon);
return rc;
}
void cil_destroy_devicetreecon(struct cil_devicetreecon *devicetreecon)
{
if (devicetreecon == NULL) {
return;
}
if (devicetreecon->context_str == NULL && devicetreecon->context != NULL) {
cil_destroy_context(devicetreecon->context);
}
free(devicetreecon);
}
int cil_gen_fsuse(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *type = NULL;
struct cil_fsuse *fsuse = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
type = parse_current->next->data;
cil_fsuse_init(&fsuse);
if (type == CIL_KEY_XATTR) {
fsuse->type = CIL_FSUSE_XATTR;
} else if (type == CIL_KEY_TASK) {
fsuse->type = CIL_FSUSE_TASK;
} else if (type == CIL_KEY_TRANS) {
fsuse->type = CIL_FSUSE_TRANS;
} else {
cil_log(CIL_ERR, "Invalid fsuse type\n");
goto exit;
}
fsuse->fs_str = parse_current->next->next->data;
if (parse_current->next->next->next->cl_head == NULL) {
fsuse->context_str = parse_current->next->next->next->data;
} else {
cil_context_init(&fsuse->context);
rc = cil_fill_context(parse_current->next->next->next->cl_head, fsuse->context);
if (rc != SEPOL_OK) {
goto exit;
}
}
ast_node->data = fsuse;
ast_node->flavor = CIL_FSUSE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad fsuse declaration");
cil_destroy_fsuse(fsuse);
return SEPOL_ERR;
}
void cil_destroy_fsuse(struct cil_fsuse *fsuse)
{
if (fsuse == NULL) {
return;
}
if (fsuse->context_str == NULL && fsuse->context != NULL) {
cil_destroy_context(fsuse->context);
}
free(fsuse);
}
void cil_destroy_param(struct cil_param *param)
{
if (param == NULL) {
return;
}
free(param);
}
int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
char *key = NULL;
struct cil_macro *macro = NULL;
struct cil_tree_node *macro_content = NULL;
struct cil_tree_node *current_item;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST | CIL_SYN_EMPTY_LIST,
CIL_SYN_N_LISTS | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/ sizeof(*syntax);
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc =__cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_macro_init(¯o);
key = parse_current->next->data;
current_item = parse_current->next->next->cl_head;
while (current_item != NULL) {
enum cil_syntax param_syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
int param_syntax_len = sizeof(param_syntax)/sizeof(*param_syntax);
char *kind = NULL;
struct cil_param *param = NULL;
struct cil_list_item *curr_param;
rc =__cil_verify_syntax(current_item->cl_head, param_syntax, param_syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
if (macro->params == NULL) {
cil_list_init(¯o->params, CIL_LIST_ITEM);
}
kind = current_item->cl_head->data;
cil_param_init(¶m);
if (kind == CIL_KEY_TYPE) {
param->flavor = CIL_TYPE;
} else if (kind == CIL_KEY_ROLE) {
param->flavor = CIL_ROLE;
} else if (kind == CIL_KEY_USER) {
param->flavor = CIL_USER;
} else if (kind == CIL_KEY_SENSITIVITY) {
param->flavor = CIL_SENS;
} else if (kind == CIL_KEY_CATEGORY) {
param->flavor = CIL_CAT;
} else if (kind == CIL_KEY_CATSET) {
param->flavor = CIL_CATSET;
} else if (kind == CIL_KEY_LEVEL) {
param->flavor = CIL_LEVEL;
} else if (kind == CIL_KEY_LEVELRANGE) {
param->flavor = CIL_LEVELRANGE;
} else if (kind == CIL_KEY_CLASS) {
param->flavor = CIL_CLASS;
} else if (kind == CIL_KEY_IPADDR) {
param->flavor = CIL_IPADDR;
} else if (kind == CIL_KEY_MAP_CLASS) {
param->flavor = CIL_MAP_CLASS;
} else if (kind == CIL_KEY_CLASSPERMISSION) {
param->flavor = CIL_CLASSPERMISSION;
} else if (kind == CIL_KEY_BOOL) {
param->flavor = CIL_BOOL;
} else if (kind == CIL_KEY_STRING) {
param->flavor = CIL_DECLARED_STRING;
} else if (kind == CIL_KEY_NAME) {
param->flavor = CIL_DECLARED_STRING;
} else {
cil_log(CIL_ERR, "The kind %s is not allowed as a parameter\n",kind);
cil_destroy_param(param);
goto exit;
}
param->str = current_item->cl_head->next->data;
rc = cil_verify_name(db, param->str, param->flavor);
if (rc != SEPOL_OK) {
cil_destroy_param(param);
goto exit;
}
//walk current list and check for duplicate parameters
cil_list_for_each(curr_param, macro->params) {
if (param->str == ((struct cil_param*)curr_param->data)->str) {
cil_log(CIL_ERR, "Duplicate parameter\n");
cil_destroy_param(param);
goto exit;
}
}
cil_list_append(macro->params, CIL_PARAM, param);
current_item = current_item->next;
}
/* we don't want the tree walker to walk the macro parameters (they were just handled above), so the subtree is deleted, and the next pointer of the
node containing the macro name is updated to point to the start of the macro content */
macro_content = parse_current->next->next->next;
cil_tree_subtree_destroy(parse_current->next->next);
parse_current->next->next = macro_content;
if (macro_content == NULL) {
/* No statements in macro and macro parameter list was last node */
parse_current->parent->cl_tail = parse_current->next;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)macro, (hashtab_key_t)key, CIL_SYM_BLOCKS, CIL_MACRO);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad macro declaration");
cil_destroy_macro(macro);
cil_clear_node(ast_node);
return SEPOL_ERR;
}
void cil_destroy_macro(struct cil_macro *macro)
{
if (macro == NULL) {
return;
}
cil_symtab_datum_destroy(¯o->datum);
cil_symtab_array_destroy(macro->symtab);
if (macro->params != NULL) {
cil_list_destroy(¯o->params, 1);
}
free(macro);
}
int cil_gen_call(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_LIST | CIL_SYN_EMPTY_LIST | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_call *call = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_call_init(&call);
call->macro_str = parse_current->next->data;
if (parse_current->next->next != NULL) {
cil_tree_init(&call->args_tree);
cil_copy_ast(db, parse_current->next->next, call->args_tree->root);
}
ast_node->data = call;
ast_node->flavor = CIL_CALL;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad macro call");
cil_destroy_call(call);
return rc;
}
void cil_destroy_call(struct cil_call *call)
{
if (call == NULL) {
return;
}
call->macro = NULL;
if (call->args_tree != NULL) {
cil_tree_destroy(&call->args_tree);
}
if (call->args != NULL) {
cil_list_destroy(&call->args, 1);
}
free(call);
}
void cil_destroy_args(struct cil_args *args)
{
if (args == NULL) {
return;
}
if (args->arg_str != NULL) {
args->arg_str = NULL;
} else if (args->arg != NULL) {
struct cil_tree_node *node = args->arg->nodes->head->data;
switch (args->flavor) {
case CIL_DECLARED_STRING:
break;
case CIL_CATSET:
cil_destroy_catset((struct cil_catset *)args->arg);
free(node);
break;
case CIL_LEVEL:
cil_destroy_level((struct cil_level *)args->arg);
free(node);
break;
case CIL_LEVELRANGE:
cil_destroy_levelrange((struct cil_levelrange *)args->arg);
free(node);
break;
case CIL_IPADDR:
cil_destroy_ipaddr((struct cil_ipaddr *)args->arg);
free(node);
break;
case CIL_CLASSPERMISSION:
cil_destroy_classpermission((struct cil_classpermission *)args->arg);
free(node);
break;
default:
cil_log(CIL_ERR, "Destroying arg with the unexpected flavor=%d\n",args->flavor);
break;
}
}
args->param_str = NULL;
args->arg = NULL;
free(args);
}
int cil_gen_optional(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_N_LISTS | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_optional *optional = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_optional_init(&optional);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)optional, (hashtab_key_t)key, CIL_SYM_BLOCKS, CIL_OPTIONAL);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
cil_destroy_optional(optional);
optional = NULL;
} else {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad optional");
cil_destroy_optional(optional);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_optional(struct cil_optional *optional)
{
if (optional == NULL) {
return;
}
cil_symtab_datum_destroy(&optional->datum);
free(optional);
}
int cil_gen_policycap(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_policycap *polcap = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_policycap_init(&polcap);
key = parse_current->next->data;
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)polcap, (hashtab_key_t)key, CIL_SYM_POLICYCAPS, CIL_POLICYCAP);
if (rc != SEPOL_OK)
goto exit;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad policycap statement");
cil_destroy_policycap(polcap);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_policycap(struct cil_policycap *polcap)
{
if (polcap == NULL) {
return;
}
cil_symtab_datum_destroy(&polcap->datum);
free(polcap);
}
int cil_gen_ipaddr(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
char *key = NULL;
struct cil_ipaddr *ipaddr = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_ipaddr_init(&ipaddr);
key = parse_current->next->data;
rc = cil_fill_ipaddr(parse_current->next->next, ipaddr);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_gen_node(db, ast_node, (struct cil_symtab_datum*)ipaddr, (hashtab_key_t)key, CIL_SYM_IPADDRS, CIL_IPADDR);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad ipaddr statement");
cil_destroy_ipaddr(ipaddr);
cil_clear_node(ast_node);
return rc;
}
void cil_destroy_ipaddr(struct cil_ipaddr *ipaddr)
{
if (ipaddr == NULL) {
return;
}
cil_symtab_datum_destroy(&ipaddr->datum);
free(ipaddr);
}
int cil_fill_integer(struct cil_tree_node *int_node, uint32_t *integer, int base)
{
int rc = SEPOL_ERR;
if (int_node == NULL || int_node->data == NULL || integer == NULL) {
goto exit;
}
rc = cil_string_to_uint32(int_node->data, integer, base);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to fill 32-bit integer\n");
return rc;
}
int cil_fill_integer64(struct cil_tree_node *int_node, uint64_t *integer, int base)
{
int rc = SEPOL_ERR;
if (int_node == NULL || int_node->data == NULL || integer == NULL) {
goto exit;
}
rc = cil_string_to_uint64(int_node->data, integer, base);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Failed to fill 64-bit integer\n");
return rc;
}
int cil_fill_ipaddr(struct cil_tree_node *addr_node, struct cil_ipaddr *addr)
{
int rc = SEPOL_ERR;
char *addr_str;
if (addr_node == NULL || addr_node->data == NULL || addr == NULL) {
goto exit;
}
addr_str = addr_node->data;
if (strchr(addr_str, ':')) {
addr->family = AF_INET6;
} else if (strchr(addr_str, '.') && isdigit(addr_str[0])) {
addr->family = AF_INET;
} else {
goto exit;
}
rc = inet_pton(addr->family, addr_node->data, &addr->ip);
if (rc != 1) {
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad ip address or netmask: %s\n", (addr_node && addr_node->data) ? (const char *)addr_node->data : "NULL");
return rc;
}
int cil_fill_level(struct cil_tree_node *curr, struct cil_level *level)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
if (curr == NULL) {
goto exit;
}
rc = __cil_verify_syntax(curr, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
level->sens_str = curr->data;
if (curr->next != NULL) {
rc = cil_fill_cats(curr->next, &level->cats);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Bad level\n");
return rc;
}
int cil_fill_cats(struct cil_tree_node *curr, struct cil_cats **cats)
{
int rc = SEPOL_ERR;
cil_cats_init(cats);
rc = cil_gen_expr(curr, CIL_CAT, &(*cats)->str_expr);
if (rc != SEPOL_OK) {
cil_destroy_cats(*cats);
*cats = NULL;
}
return rc;
}
void cil_destroy_cats(struct cil_cats *cats)
{
if (cats == NULL) {
return;
}
cil_list_destroy(&cats->str_expr, CIL_TRUE);
cil_list_destroy(&cats->datum_expr, CIL_FALSE);
free(cats);
}
int cil_gen_bounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_bounds *bounds = NULL;
int rc = SEPOL_ERR;
if (db == NULL || parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_bounds_init(&bounds);
bounds->parent_str = parse_current->next->data;
bounds->child_str = parse_current->next->next->data;
ast_node->data = bounds;
switch (flavor) {
case CIL_USER:
ast_node->flavor = CIL_USERBOUNDS;
break;
case CIL_ROLE:
ast_node->flavor = CIL_ROLEBOUNDS;
break;
case CIL_TYPE:
ast_node->flavor = CIL_TYPEBOUNDS;
break;
default:
break;
}
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad bounds declaration");
cil_destroy_bounds(bounds);
return rc;
}
void cil_destroy_bounds(struct cil_bounds *bounds)
{
if (bounds == NULL) {
return;
}
free(bounds);
}
int cil_gen_default(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor)
{
int rc = SEPOL_ERR;
struct cil_default *def = NULL;
char *object;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_default_init(&def);
def->flavor = flavor;
if (parse_current->next->cl_head == NULL) {
cil_list_init(&def->class_strs, CIL_CLASS);
cil_list_append(def->class_strs, CIL_STRING, parse_current->next->data);
} else {
rc = cil_fill_list(parse_current->next->cl_head, CIL_CLASS, &def->class_strs);
if (rc != SEPOL_OK) {
goto exit;
}
}
object = parse_current->next->next->data;
if (object == CIL_KEY_SOURCE) {
def->object = CIL_DEFAULT_SOURCE;
} else if (object == CIL_KEY_TARGET) {
def->object = CIL_DEFAULT_TARGET;
} else {
cil_log(CIL_ERR,"Expected either 'source' or 'target'\n");
rc = SEPOL_ERR;
goto exit;
}
ast_node->data = def;
ast_node->flavor = flavor;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad %s declaration", cil_node_to_string(parse_current));
cil_destroy_default(def);
return rc;
}
void cil_destroy_default(struct cil_default *def)
{
if (def == NULL) {
return;
}
cil_list_destroy(&def->class_strs, CIL_TRUE);
cil_list_destroy(&def->class_datums, CIL_FALSE);
free(def);
}
int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
struct cil_defaultrange *def = NULL;
char *object;
char *range;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_defaultrange_init(&def);
if (parse_current->next->cl_head == NULL) {
cil_list_init(&def->class_strs, CIL_CLASS);
cil_list_append(def->class_strs, CIL_STRING, parse_current->next->data);
} else {
rc = cil_fill_list(parse_current->next->cl_head, CIL_CLASS, &def->class_strs);
if (rc != SEPOL_OK) {
goto exit;
}
}
object = parse_current->next->next->data;
if (object == CIL_KEY_SOURCE) {
if (!parse_current->next->next->next) {
cil_log(CIL_ERR, "Missing 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
range = parse_current->next->next->next->data;
if (range == CIL_KEY_LOW) {
def->object_range = CIL_DEFAULT_SOURCE_LOW;
} else if (range == CIL_KEY_HIGH) {
def->object_range = CIL_DEFAULT_SOURCE_HIGH;
} else if (range == CIL_KEY_LOW_HIGH) {
def->object_range = CIL_DEFAULT_SOURCE_LOW_HIGH;
} else {
cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
} else if (object == CIL_KEY_TARGET) {
if (!parse_current->next->next->next) {
cil_log(CIL_ERR, "Missing 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
range = parse_current->next->next->next->data;
if (range == CIL_KEY_LOW) {
def->object_range = CIL_DEFAULT_TARGET_LOW;
} else if (range == CIL_KEY_HIGH) {
def->object_range = CIL_DEFAULT_TARGET_HIGH;
} else if (range == CIL_KEY_LOW_HIGH) {
def->object_range = CIL_DEFAULT_TARGET_LOW_HIGH;
} else {
cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
rc = SEPOL_ERR;
goto exit;
}
} else if (object == CIL_KEY_GLBLUB) {
def->object_range = CIL_DEFAULT_GLBLUB;
} else {
cil_log(CIL_ERR,"Expected \'source\', \'target\', or \'glblub\'\n");
rc = SEPOL_ERR;
goto exit;
}
ast_node->data = def;
ast_node->flavor = CIL_DEFAULTRANGE;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad defaultrange declaration");
cil_destroy_defaultrange(def);
return rc;
}
void cil_destroy_defaultrange(struct cil_defaultrange *def)
{
if (def == NULL) {
return;
}
cil_list_destroy(&def->class_strs, CIL_TRUE);
cil_list_destroy(&def->class_datums, CIL_FALSE);
free(def);
}
int cil_gen_handleunknown(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_handleunknown *unknown = NULL;
char *unknown_key;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_handleunknown_init(&unknown);
unknown_key = parse_current->next->data;
if (unknown_key == CIL_KEY_HANDLEUNKNOWN_ALLOW) {
unknown->handle_unknown = SEPOL_ALLOW_UNKNOWN;
} else if (unknown_key == CIL_KEY_HANDLEUNKNOWN_DENY) {
unknown->handle_unknown = SEPOL_DENY_UNKNOWN;
} else if (unknown_key == CIL_KEY_HANDLEUNKNOWN_REJECT) {
unknown->handle_unknown = SEPOL_REJECT_UNKNOWN;
} else {
cil_log(CIL_ERR, "Expected either \'%s\', \'%s\', or \'%s\'\n", CIL_KEY_HANDLEUNKNOWN_ALLOW, CIL_KEY_HANDLEUNKNOWN_DENY, CIL_KEY_HANDLEUNKNOWN_REJECT);
rc = SEPOL_ERR;
goto exit;
}
ast_node->data = unknown;
ast_node->flavor = CIL_HANDLEUNKNOWN;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad handleunknown");
cil_destroy_handleunknown(unknown);
return rc;
}
void cil_destroy_handleunknown(struct cil_handleunknown *unk)
{
free(unk);
}
int cil_gen_mls(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_mls *mls = NULL;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_mls_init(&mls);
if (parse_current->next->data == CIL_KEY_CONDTRUE) {
mls->value = CIL_TRUE;
} else if (parse_current->next->data == CIL_KEY_CONDFALSE) {
mls->value = CIL_FALSE;
} else {
cil_log(CIL_ERR, "Value must be either \'true\' or \'false\'");
rc = SEPOL_ERR;
goto exit;
}
ast_node->data = mls;
ast_node->flavor = CIL_MLS;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad mls");
cil_destroy_mls(mls);
return rc;
}
void cil_destroy_mls(struct cil_mls *mls)
{
free(mls);
}
int cil_gen_src_info(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
int rc = SEPOL_ERR;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_STRING,
CIL_SYN_N_LISTS | CIL_SYN_END,
CIL_SYN_END
};
size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
struct cil_src_info *info = NULL;
if (parse_current == NULL || ast_node == NULL) {
goto exit;
}
rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
cil_src_info_init(&info);
info->kind = parse_current->next->data;
if (info->kind != CIL_KEY_SRC_CIL && info->kind != CIL_KEY_SRC_HLL_LMS && info->kind != CIL_KEY_SRC_HLL_LMX) {
cil_log(CIL_ERR, "Invalid src info kind\n");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_string_to_uint32(parse_current->next->next->data, &info->hll_line, 10);
if (rc != SEPOL_OK) {
goto exit;
}
info->path = parse_current->next->next->next->data;
ast_node->data = info;
ast_node->flavor = CIL_SRC_INFO;
return SEPOL_OK;
exit:
cil_tree_log(parse_current, CIL_ERR, "Bad src info");
cil_destroy_src_info(info);
return rc;
}
void cil_destroy_src_info(struct cil_src_info *info)
{
free(info);
}
static int check_for_illegal_statement(struct cil_tree_node *parse_current, struct cil_args_build *args)
{
if (args->tunif != NULL) {
if (parse_current->data == CIL_KEY_TUNABLE) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in tunableif", (char *)parse_current->data);
return SEPOL_ERR;
}
}
if (args->in != NULL) {
struct cil_in *in_block = args->in->data;
if (parse_current->data == CIL_KEY_TUNABLE ||
parse_current->data == CIL_KEY_IN) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in in-statement", (char *)parse_current->data);
return SEPOL_ERR;
}
if (in_block->is_after == CIL_TRUE) {
if (parse_current->data == CIL_KEY_BLOCKINHERIT ||
parse_current->data == CIL_KEY_BLOCKABSTRACT) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in an after in-statement", (char *)parse_current->data);
return SEPOL_ERR;
}
}
}
if (args->macro != NULL) {
if (parse_current->data == CIL_KEY_TUNABLE ||
parse_current->data == CIL_KEY_IN ||
parse_current->data == CIL_KEY_BLOCK ||
parse_current->data == CIL_KEY_BLOCKINHERIT ||
parse_current->data == CIL_KEY_BLOCKABSTRACT ||
parse_current->data == CIL_KEY_MACRO) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in macro", (char *)parse_current->data);
return SEPOL_ERR;
}
}
if (args->optional != NULL) {
if (parse_current->data == CIL_KEY_TUNABLE ||
parse_current->data == CIL_KEY_IN ||
parse_current->data == CIL_KEY_BLOCK ||
parse_current->data == CIL_KEY_BLOCKABSTRACT ||
parse_current->data == CIL_KEY_MACRO) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in optional", (char *)parse_current->data);
return SEPOL_ERR;
}
}
if (args->boolif != NULL) {
if (parse_current->data != CIL_KEY_TUNABLEIF &&
parse_current->data != CIL_KEY_CALL &&
parse_current->data != CIL_KEY_CONDTRUE &&
parse_current->data != CIL_KEY_CONDFALSE &&
parse_current->data != CIL_KEY_ALLOW &&
parse_current->data != CIL_KEY_DONTAUDIT &&
parse_current->data != CIL_KEY_AUDITALLOW &&
parse_current->data != CIL_KEY_TYPETRANSITION &&
parse_current->data != CIL_KEY_TYPECHANGE &&
parse_current->data != CIL_KEY_TYPEMEMBER &&
((args->db->policy_version < POLICYDB_VERSION_COND_XPERMS) ||
(parse_current->data != CIL_KEY_ALLOWX &&
parse_current->data != CIL_KEY_DONTAUDITX &&
parse_current->data != CIL_KEY_AUDITALLOWX))) {
if (((struct cil_booleanif*)args->boolif->data)->preserved_tunable) {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in tunableif being treated as a booleanif", (char *)parse_current->data);
} else {
cil_tree_log(parse_current, CIL_ERR, "%s is not allowed in booleanif", (char *)parse_current->data);
}
return SEPOL_ERR;
}
}
return SEPOL_OK;
}
static struct cil_tree_node * parse_statement(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_parent)
{
struct cil_tree_node *new_ast_node = NULL;
int rc = SEPOL_ERR;
cil_tree_node_init(&new_ast_node);
new_ast_node->parent = ast_parent;
new_ast_node->line = parse_current->line;
new_ast_node->hll_offset = parse_current->hll_offset;
if (parse_current->data == CIL_KEY_BLOCK) {
rc = cil_gen_block(db, parse_current, new_ast_node, 0);
} else if (parse_current->data == CIL_KEY_BLOCKINHERIT) {
rc = cil_gen_blockinherit(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_BLOCKABSTRACT) {
rc = cil_gen_blockabstract(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IN) {
rc = cil_gen_in(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASS) {
rc = cil_gen_class(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASSORDER) {
rc = cil_gen_ordered(db, parse_current, new_ast_node, CIL_CLASSORDER);
} else if (parse_current->data == CIL_KEY_MAP_CLASS) {
rc = cil_gen_map_class(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASSMAPPING) {
rc = cil_gen_classmapping(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASSPERMISSION) {
rc = cil_gen_classpermission(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASSPERMISSIONSET) {
rc = cil_gen_classpermissionset(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_COMMON) {
rc = cil_gen_common(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CLASSCOMMON) {
rc = cil_gen_classcommon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SID) {
rc = cil_gen_sid(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SIDCONTEXT) {
rc = cil_gen_sidcontext(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SIDORDER) {
rc = cil_gen_ordered(db, parse_current, new_ast_node, CIL_SIDORDER);
} else if (parse_current->data == CIL_KEY_USER) {
rc = cil_gen_user(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERATTRIBUTE) {
rc = cil_gen_userattribute(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERATTRIBUTESET) {
rc = cil_gen_userattributeset(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERLEVEL) {
rc = cil_gen_userlevel(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERRANGE) {
rc = cil_gen_userrange(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERBOUNDS) {
rc = cil_gen_bounds(db, parse_current, new_ast_node, CIL_USER);
} else if (parse_current->data == CIL_KEY_USERPREFIX) {
rc = cil_gen_userprefix(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SELINUXUSER) {
rc = cil_gen_selinuxuser(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SELINUXUSERDEFAULT) {
rc = cil_gen_selinuxuserdefault(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPE) {
rc = cil_gen_type(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPEATTRIBUTE) {
rc = cil_gen_typeattribute(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPEATTRIBUTESET) {
rc = cil_gen_typeattributeset(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_EXPANDTYPEATTRIBUTE) {
rc = cil_gen_expandtypeattribute(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPEALIAS) {
rc = cil_gen_alias(db, parse_current, new_ast_node, CIL_TYPEALIAS);
} else if (parse_current->data == CIL_KEY_TYPEALIASACTUAL) {
rc = cil_gen_aliasactual(db, parse_current, new_ast_node, CIL_TYPEALIASACTUAL);
} else if (parse_current->data == CIL_KEY_TYPEBOUNDS) {
rc = cil_gen_bounds(db, parse_current, new_ast_node, CIL_TYPE);
} else if (parse_current->data == CIL_KEY_TYPEPERMISSIVE) {
rc = cil_gen_typepermissive(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_RANGETRANSITION) {
rc = cil_gen_rangetransition(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLE) {
rc = cil_gen_role(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_USERROLE) {
rc = cil_gen_userrole(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLETYPE) {
rc = cil_gen_roletype(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLETRANSITION) {
rc = cil_gen_roletransition(parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLEALLOW) {
rc = cil_gen_roleallow(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLEATTRIBUTE) {
rc = cil_gen_roleattribute(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLEATTRIBUTESET) {
rc = cil_gen_roleattributeset(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_ROLEBOUNDS) {
rc = cil_gen_bounds(db, parse_current, new_ast_node, CIL_ROLE);
} else if (parse_current->data == CIL_KEY_BOOL) {
rc = cil_gen_bool(db, parse_current, new_ast_node, CIL_FALSE);
} else if (parse_current->data == CIL_KEY_BOOLEANIF) {
rc = cil_gen_boolif(db, parse_current, new_ast_node, CIL_FALSE);
} else if(parse_current->data == CIL_KEY_TUNABLE) {
if (db->preserve_tunables) {
rc = cil_gen_bool(db, parse_current, new_ast_node, CIL_TRUE);
} else {
rc = cil_gen_tunable(db, parse_current, new_ast_node);
}
} else if (parse_current->data == CIL_KEY_TUNABLEIF) {
if (db->preserve_tunables) {
rc = cil_gen_boolif(db, parse_current, new_ast_node, CIL_TRUE);
} else {
rc = cil_gen_tunif(db, parse_current, new_ast_node);
}
} else if (parse_current->data == CIL_KEY_CONDTRUE) {
rc = cil_gen_condblock(db, parse_current, new_ast_node, CIL_CONDTRUE);
} else if (parse_current->data == CIL_KEY_CONDFALSE) {
rc = cil_gen_condblock(db, parse_current, new_ast_node, CIL_CONDFALSE);
} else if (parse_current->data == CIL_KEY_ALLOW) {
rc = cil_gen_avrule(parse_current, new_ast_node, CIL_AVRULE_ALLOWED);
} else if (parse_current->data == CIL_KEY_AUDITALLOW) {
rc = cil_gen_avrule(parse_current, new_ast_node, CIL_AVRULE_AUDITALLOW);
} else if (parse_current->data == CIL_KEY_DONTAUDIT) {
rc = cil_gen_avrule(parse_current, new_ast_node, CIL_AVRULE_DONTAUDIT);
} else if (parse_current->data == CIL_KEY_NEVERALLOW) {
rc = cil_gen_avrule(parse_current, new_ast_node, CIL_AVRULE_NEVERALLOW);
} else if (parse_current->data == CIL_KEY_ALLOWX) {
rc = cil_gen_avrulex(parse_current, new_ast_node, CIL_AVRULE_ALLOWED);
} else if (parse_current->data == CIL_KEY_AUDITALLOWX) {
rc = cil_gen_avrulex(parse_current, new_ast_node, CIL_AVRULE_AUDITALLOW);
} else if (parse_current->data == CIL_KEY_DONTAUDITX) {
rc = cil_gen_avrulex(parse_current, new_ast_node, CIL_AVRULE_DONTAUDIT);
} else if (parse_current->data == CIL_KEY_NEVERALLOWX) {
rc = cil_gen_avrulex(parse_current, new_ast_node, CIL_AVRULE_NEVERALLOW);
} else if (parse_current->data == CIL_KEY_PERMISSIONX) {
rc = cil_gen_permissionx(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_DENY_RULE) {
rc = cil_gen_deny_rule(parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPETRANSITION) {
rc = cil_gen_typetransition(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_TYPECHANGE) {
rc = cil_gen_type_rule(parse_current, new_ast_node, CIL_TYPE_CHANGE);
} else if (parse_current->data == CIL_KEY_TYPEMEMBER) {
rc = cil_gen_type_rule(parse_current, new_ast_node, CIL_TYPE_MEMBER);
} else if (parse_current->data == CIL_KEY_SENSITIVITY) {
rc = cil_gen_sensitivity(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SENSALIAS) {
rc = cil_gen_alias(db, parse_current, new_ast_node, CIL_SENSALIAS);
} else if (parse_current->data == CIL_KEY_SENSALIASACTUAL) {
rc = cil_gen_aliasactual(db, parse_current, new_ast_node, CIL_SENSALIASACTUAL);
} else if (parse_current->data == CIL_KEY_CATEGORY) {
rc = cil_gen_category(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CATALIAS) {
rc = cil_gen_alias(db, parse_current, new_ast_node, CIL_CATALIAS);
} else if (parse_current->data == CIL_KEY_CATALIASACTUAL) {
rc = cil_gen_aliasactual(db, parse_current, new_ast_node, CIL_CATALIASACTUAL);
} else if (parse_current->data == CIL_KEY_CATSET) {
rc = cil_gen_catset(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CATORDER) {
rc = cil_gen_ordered(db, parse_current, new_ast_node, CIL_CATORDER);
} else if (parse_current->data == CIL_KEY_SENSITIVITYORDER) {
rc = cil_gen_ordered(db, parse_current, new_ast_node, CIL_SENSITIVITYORDER);
} else if (parse_current->data == CIL_KEY_SENSCAT) {
rc = cil_gen_senscat(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_LEVEL) {
rc = cil_gen_level(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_LEVELRANGE) {
rc = cil_gen_levelrange(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CONSTRAIN) {
rc = cil_gen_constrain(db, parse_current, new_ast_node, CIL_CONSTRAIN);
} else if (parse_current->data == CIL_KEY_MLSCONSTRAIN) {
rc = cil_gen_constrain(db, parse_current, new_ast_node, CIL_MLSCONSTRAIN);
} else if (parse_current->data == CIL_KEY_VALIDATETRANS) {
rc = cil_gen_validatetrans(db, parse_current, new_ast_node, CIL_VALIDATETRANS);
} else if (parse_current->data == CIL_KEY_MLSVALIDATETRANS) {
rc = cil_gen_validatetrans(db, parse_current, new_ast_node, CIL_MLSVALIDATETRANS);
} else if (parse_current->data == CIL_KEY_CONTEXT) {
rc = cil_gen_context(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_FILECON) {
rc = cil_gen_filecon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IBPKEYCON) {
rc = cil_gen_ibpkeycon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IBENDPORTCON) {
rc = cil_gen_ibendportcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_PORTCON) {
rc = cil_gen_portcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_NODECON) {
rc = cil_gen_nodecon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_GENFSCON) {
rc = cil_gen_genfscon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_NETIFCON) {
rc = cil_gen_netifcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_PIRQCON) {
rc = cil_gen_pirqcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IOMEMCON) {
rc = cil_gen_iomemcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IOPORTCON) {
rc = cil_gen_ioportcon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_PCIDEVICECON) {
rc = cil_gen_pcidevicecon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_DEVICETREECON) {
rc = cil_gen_devicetreecon(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_FSUSE) {
rc = cil_gen_fsuse(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_MACRO) {
rc = cil_gen_macro(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_CALL) {
rc = cil_gen_call(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_POLICYCAP) {
rc = cil_gen_policycap(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_OPTIONAL) {
rc = cil_gen_optional(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_IPADDR) {
rc = cil_gen_ipaddr(db, parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_DEFAULTUSER) {
rc = cil_gen_default(parse_current, new_ast_node, CIL_DEFAULTUSER);
} else if (parse_current->data == CIL_KEY_DEFAULTROLE) {
rc = cil_gen_default(parse_current, new_ast_node, CIL_DEFAULTROLE);
} else if (parse_current->data == CIL_KEY_DEFAULTTYPE) {
rc = cil_gen_default(parse_current, new_ast_node, CIL_DEFAULTTYPE);
} else if (parse_current->data == CIL_KEY_DEFAULTRANGE) {
rc = cil_gen_defaultrange(parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_HANDLEUNKNOWN) {
rc = cil_gen_handleunknown(parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_MLS) {
rc = cil_gen_mls(parse_current, new_ast_node);
} else if (parse_current->data == CIL_KEY_SRC_INFO) {
rc = cil_gen_src_info(parse_current, new_ast_node);
} else {
cil_log(CIL_ERR, "Error: Unknown keyword %s\n", (char *)parse_current->data);
rc = SEPOL_ERR;
}
if (rc == SEPOL_OK) {
if (ast_parent->cl_head == NULL) {
ast_parent->cl_head = new_ast_node;
} else {
ast_parent->cl_tail->next = new_ast_node;
}
ast_parent->cl_tail = new_ast_node;
} else {
cil_tree_node_destroy(&new_ast_node);
new_ast_node = NULL;
}
return new_ast_node;
}
static int __cil_build_ast_node_helper(struct cil_tree_node *parse_current, uint32_t *finished, void *extra_args)
{
struct cil_args_build *args = extra_args;
struct cil_tree_node *new_ast_node = NULL;
int rc = SEPOL_ERR;
if (parse_current->parent->cl_head != parse_current) {
/* ignore anything that isn't following a parenthesis */
return SEPOL_OK;
} else if (parse_current->data == NULL) {
/* the only time parenthesis can immediately following parenthesis is if
* the parent is the root node */
if (parse_current->parent->parent == NULL) {
return SEPOL_OK;
} else {
cil_tree_log(parse_current, CIL_ERR, "Keyword expected after open parenthesis");
return SEPOL_ERR;
}
}
rc = check_for_illegal_statement(parse_current, args);
if (rc != SEPOL_OK) {
return SEPOL_ERR;
}
new_ast_node = parse_statement(args->db, parse_current, args->ast);
if (!new_ast_node) {
return SEPOL_ERR;
}
args->ast = new_ast_node;
if (parse_current->data != CIL_KEY_BLOCK &&
parse_current->data != CIL_KEY_IN &&
parse_current->data != CIL_KEY_TUNABLEIF &&
parse_current->data != CIL_KEY_BOOLEANIF &&
parse_current->data != CIL_KEY_CONDTRUE &&
parse_current->data != CIL_KEY_CONDFALSE &&
parse_current->data != CIL_KEY_MACRO &&
parse_current->data != CIL_KEY_OPTIONAL &&
parse_current->data != CIL_KEY_SRC_INFO) {
/* Skip anything that does not contain a list of policy statements */
*finished = CIL_TREE_SKIP_NEXT;
}
return SEPOL_OK;
}
static int __cil_build_ast_first_child_helper(__attribute__((unused)) struct cil_tree_node *parse_current, void *extra_args)
{
struct cil_args_build *args = extra_args;
struct cil_tree_node *ast = args->ast;
if (ast->flavor == CIL_TUNABLEIF) {
args->tunif = ast;
} else if (ast->flavor == CIL_IN) {
args->in = ast;
} else if (ast->flavor == CIL_MACRO) {
args->macro = ast;
} else if (ast->flavor == CIL_OPTIONAL) {
args->optional = ast;
} else if (ast->flavor == CIL_BOOLEANIF) {
args->boolif = ast;
}
return SEPOL_OK;
}
static int __cil_build_ast_last_child_helper(struct cil_tree_node *parse_current, void *extra_args)
{
struct cil_args_build *args = extra_args;
struct cil_tree_node *ast = args->ast;
if (ast->flavor == CIL_ROOT) {
return SEPOL_OK;
}
args->ast = ast->parent;
if (ast->flavor == CIL_TUNABLEIF) {
args->tunif = NULL;
}
if (ast->flavor == CIL_IN) {
args->in = NULL;
}
if (ast->flavor == CIL_MACRO) {
args->macro = NULL;
}
if (ast->flavor == CIL_OPTIONAL) {
struct cil_tree_node *n = ast->parent;
args->optional = NULL;
/* Optionals can be nested */
while (n && n->flavor != CIL_ROOT) {
if (n->flavor == CIL_OPTIONAL) {
args->optional = n;
break;
}
n = n->parent;
}
}
if (ast->flavor == CIL_BOOLEANIF) {
args->boolif = NULL;
}
// At this point we no longer have any need for parse_current or any of its
// siblings; they have all been converted to the appropriate AST node. The
// full parse tree will get deleted elsewhere, but in an attempt to
// minimize memory usage (of which the parse tree uses a lot), start
// deleting the parts we don't need now.
cil_tree_children_destroy(parse_current->parent);
return SEPOL_OK;
}
int cil_build_ast(struct cil_db *db, struct cil_tree_node *parse_tree, struct cil_tree_node *ast)
{
int rc = SEPOL_ERR;
struct cil_args_build extra_args;
if (db == NULL || parse_tree == NULL || ast == NULL) {
goto exit;
}
extra_args.ast = ast;
extra_args.db = db;
extra_args.tunif = NULL;
extra_args.in = NULL;
extra_args.macro = NULL;
extra_args.optional = NULL;
extra_args.boolif = NULL;
rc = cil_tree_walk(parse_tree, __cil_build_ast_node_helper, __cil_build_ast_first_child_helper, __cil_build_ast_last_child_helper, &extra_args);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
libsepol-3.8.1/cil/src/cil_build_ast.h000066400000000000000000000437441476211737200176660ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_BUILD_AST_H_
#define CIL_BUILD_AST_H_
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_symtab.h"
#include "cil_tree.h"
#include "cil_list.h"
int cil_add_decl_to_symtab(struct cil_db *db, symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node);
struct cil_symtab_datum *cil_gen_declared_string(struct cil_db *db, hashtab_key_t key, struct cil_tree_node *ast_node);
int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor);
int cil_parse_to_list(struct cil_tree_node *parse_cl_head, struct cil_list *ast_cl, enum cil_flavor flavor);
int cil_gen_ordered(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_ordered(struct cil_ordered *ordered);
int cil_gen_block(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint16_t is_abstract);
void cil_destroy_block(struct cil_block *block);
int cil_gen_blockinherit(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_blockinherit(struct cil_blockinherit *inherit);
int cil_gen_blockabstract(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_blockabstract(struct cil_blockabstract *abstract);
int cil_gen_in(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_in(struct cil_in *in);
int cil_gen_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_class(struct cil_class *class);
int cil_gen_perm(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms);
void cil_destroy_perm(struct cil_perm *perm);
int cil_gen_perm_nodes(struct cil_db *db, struct cil_tree_node *current_perm, struct cil_tree_node *ast_node, enum cil_flavor flavor, unsigned int *num_perms);
int cil_fill_perms(struct cil_tree_node *start_perm, struct cil_list **perm_strs);
int cil_fill_classperms(struct cil_tree_node *parse_current, struct cil_classperms **cp);
void cil_destroy_classperms(struct cil_classperms *cp);
void cil_fill_classperms_set(struct cil_tree_node *parse_current, struct cil_classperms_set **cp_set);
void cil_destroy_classperms_set(struct cil_classperms_set *cp_set);
int cil_fill_classperms_list(struct cil_tree_node *parse_current, struct cil_list **expr_list);
void cil_destroy_classperms_list(struct cil_list **cp_list);
int cil_gen_classpermission(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_classpermission(struct cil_classpermission *cp);
int cil_gen_classpermissionset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_classpermissionset(struct cil_classpermissionset *cps);
int cil_gen_map_class(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_classmapping(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_classmapping(struct cil_classmapping *mapping);
int cil_gen_common(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_classcommon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_classcommon(struct cil_classcommon *clscom);
int cil_gen_sid(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_sid(struct cil_sid *sid);
int cil_gen_sidcontext(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_sidcontext(struct cil_sidcontext *sidcon);
int cil_gen_user(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_user(struct cil_user *user);
int cil_gen_userattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userattribute(struct cil_userattribute *attr);
int cil_gen_userattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userattributeset(struct cil_userattributeset *attrset);
int cil_gen_userlevel(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userlevel(struct cil_userlevel *usrlvl);
int cil_gen_userrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userrange(struct cil_userrange *userrange);
int cil_gen_userbounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_userprefix(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userprefix(struct cil_userprefix *userprefix);
int cil_gen_selinuxuser(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_selinuxuserdefault(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_selinuxuser(struct cil_selinuxuser *selinuxuser);
int cil_gen_role(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_role(struct cil_role *role);
int cil_gen_roletype(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_roletype(struct cil_roletype *roletype);
int cil_gen_userrole(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_userrole(struct cil_userrole *userrole);
int cil_gen_roletransition(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_roletransition(struct cil_roletransition *roletrans);
int cil_gen_roleallow(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_roleallow(struct cil_roleallow *roleallow);
int cil_gen_roleattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_roleattribute(struct cil_roleattribute *role);
int cil_gen_roleattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_roleattributeset(struct cil_roleattributeset *attrset);
int cil_gen_rolebounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_avrule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind);
void cil_destroy_avrule(struct cil_avrule *rule);
int cil_gen_avrulex(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind);
int cil_gen_permissionx(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_permissionx(struct cil_permissionx *permx);
int cil_gen_deny_rule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_deny_rule(struct cil_deny_rule *rule);
int cil_gen_type_rule(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, uint32_t rule_kind);
void cil_destroy_type_rule(struct cil_type_rule *rule);
int cil_gen_type(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_type(struct cil_type *type);
int cil_gen_typeattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_typeattribute(struct cil_typeattribute *type);
int cil_gen_bool(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunableif);
void cil_destroy_bool(struct cil_bool *boolean);
int cil_gen_tunable(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_tunable(struct cil_tunable *tunable);
int cil_gen_constrain_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **stack);
int cil_gen_expr(struct cil_tree_node *current, enum cil_flavor flavor, struct cil_list **stack);
int cil_gen_boolif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, int tunable_if);
void cil_destroy_boolif(struct cil_booleanif *bif);
int cil_gen_tunif(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_tunif(struct cil_tunableif *tif);
int cil_gen_condblock(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_condblock(struct cil_condblock *cb);
int cil_gen_alias(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_alias(struct cil_alias *alias);
int cil_gen_aliasactual(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_aliasactual(struct cil_aliasactual *aliasactual);
int cil_gen_typeattributeset(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_typeattributeset(struct cil_typeattributeset *attrtypes);
int cil_gen_expandtypeattribute(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_expandtypeattribute(struct cil_expandtypeattribute *expandattr);
int cil_gen_typebounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
int cil_gen_typepermissive(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_typepermissive(struct cil_typepermissive *typeperm);
int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_typetransition(struct cil_nametypetransition *nametypetrans);
int cil_gen_rangetransition(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_rangetransition(struct cil_rangetransition *rangetrans);
int cil_gen_sensitivity(struct cil_db *idb, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_sensitivity(struct cil_sens *sens);
int cil_gen_category(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_category(struct cil_cat *cat);
int cil_set_to_list(struct cil_tree_node *parse_current, struct cil_list *ast_cl);
void cil_destroy_catset(struct cil_catset *catset);
int cil_gen_senscat(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_senscat(struct cil_senscat *senscat);
int cil_gen_level(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_level(struct cil_level *level);
int cil_fill_levelrange(struct cil_tree_node *low, struct cil_levelrange *lvlrange);
int cil_gen_levelrange(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_levelrange(struct cil_levelrange *lvlrange);
void cil_destroy_constrain_node(struct cil_tree_node *cons_node);
int cil_gen_constrain(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_constrain(struct cil_constrain *cons);
int cil_gen_validatetrans(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_validatetrans(struct cil_validatetrans *validtrans);
int cil_fill_context(struct cil_tree_node *user_node, struct cil_context *context);
int cil_gen_context(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_context(struct cil_context *context);
int cil_gen_filecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_filecon(struct cil_filecon *filecon);
int cil_gen_ibpkeycon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_ibpkeycon(struct cil_ibpkeycon *ibpkeycon);
int cil_gen_ibendportcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_ibendportcon(struct cil_ibendportcon *ibendportcon);
int cil_gen_portcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_portcon(struct cil_portcon *portcon);
int cil_gen_nodecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_nodecon(struct cil_nodecon *nodecon);
int cil_gen_genfscon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_genfscon(struct cil_genfscon *genfscon);
int cil_gen_netifcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_netifcon(struct cil_netifcon *netifcon);
int cil_gen_pirqcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_pirqcon(struct cil_pirqcon *pirqcon);
int cil_gen_iomemcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_iomemcon(struct cil_iomemcon *iomemcon);
int cil_gen_ioportcon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_ioportcon(struct cil_ioportcon *ioportcon);
int cil_gen_pcidevicecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_pcidevicecon(struct cil_pcidevicecon *pcidevicecon);
int cil_gen_devicetreecon(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_devicetreecon(struct cil_devicetreecon *devicetreecon);
int cil_gen_fsuse(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_fsuse(struct cil_fsuse *fsuse);
void cil_destroy_param(struct cil_param *param);
int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_macro(struct cil_macro *macro);
int cil_gen_call(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_call(struct cil_call *call);
void cil_destroy_args(struct cil_args *args);
int cil_gen_optional(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_optional(struct cil_optional *optional);
int cil_gen_policycap(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_policycap(struct cil_policycap *polcap);
int cil_gen_ipaddr(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_ipaddr(struct cil_ipaddr *ipaddr);
int cil_gen_bounds(struct cil_db *db, struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_bounds(struct cil_bounds *bounds);
int cil_gen_default(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node, enum cil_flavor flavor);
void cil_destroy_default(struct cil_default *def);
int cil_gen_handleunknown(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_handleunknown(struct cil_handleunknown *unk);
int cil_gen_mls(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_mls(struct cil_mls *mls);
int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_defaultrange(struct cil_defaultrange *def);
int cil_gen_src_info(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node);
void cil_destroy_src_info(struct cil_src_info *info);
int cil_fill_cats(struct cil_tree_node *curr, struct cil_cats **cats);
void cil_destroy_cats(struct cil_cats *cats);
int cil_fill_context(struct cil_tree_node *user_node, struct cil_context *context);
int cil_fill_integer(struct cil_tree_node *int_node, uint32_t *integer, int base);
int cil_fill_integer64(struct cil_tree_node *int_node, uint64_t *integer, int base);
int cil_fill_ipaddr(struct cil_tree_node *addr_node, struct cil_ipaddr *addr);
int cil_fill_level(struct cil_tree_node *sens, struct cil_level *level);
int cil_build_ast(struct cil_db *db, struct cil_tree_node *parse_tree, struct cil_tree_node *ast);
#endif /* CIL_BUILD_AST_H_ */
libsepol-3.8.1/cil/src/cil_copy_ast.c000066400000000000000000001441521476211737200175270ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include "cil_internal.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_symtab.h"
#include "cil_copy_ast.h"
#include "cil_build_ast.h"
#include "cil_strpool.h"
#include "cil_verify.h"
struct cil_args_copy {
struct cil_tree_node *orig_dest;
struct cil_tree_node *dest;
struct cil_db *db;
};
void cil_copy_list(struct cil_list *data, struct cil_list **copy)
{
struct cil_list *new;
struct cil_list_item *orig_item;
cil_list_init(&new, data->flavor);
cil_list_for_each(orig_item, data) {
switch (orig_item->flavor) {
case CIL_STRING:
cil_list_append(new, CIL_STRING, orig_item->data);
break;
case CIL_LIST: {
struct cil_list *new_sub = NULL;
cil_copy_list((struct cil_list*)orig_item->data, &new_sub);
cil_list_append(new, CIL_LIST, new_sub);
break;
}
case CIL_PARAM: {
struct cil_param *po = orig_item->data;
struct cil_param *pn;
cil_param_init(&pn);
pn->str = po->str;
pn->flavor = po->flavor;
cil_list_append(new, CIL_PARAM, pn);
}
break;
default:
cil_list_append(new, orig_item->flavor, orig_item->data);
break;
}
}
*copy = new;
}
static int cil_copy_node(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
char *new = NULL;
if (data != NULL) {
new = data;
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_ordered(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_ordered *orig = data;
struct cil_ordered *new = NULL;
cil_ordered_init(&new);
if (orig->strs != NULL) {
cil_copy_list(orig->strs, &new->strs);
}
if (orig->datums != NULL) {
cil_copy_list(orig->datums, &new->datums);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_block(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_block *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
if (FLAVOR(datum) != CIL_BLOCK) {
cil_tree_log(NODE(orig), CIL_ERR, "Block %s being copied", key);
cil_tree_log(NODE(datum), CIL_ERR, " Conflicts with %s already declared", cil_node_to_string(NODE(datum)));
return SEPOL_ERR;
}
cil_tree_log(NODE(orig), CIL_WARN, "Block %s being copied", key);
cil_tree_log(NODE(datum), CIL_WARN, " Previously declared");
*copy = datum;
} else {
struct cil_block *new;
cil_block_init(&new);
*copy = new;
}
return SEPOL_OK;
}
int cil_copy_blockabstract(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_blockabstract *orig = data;
struct cil_blockabstract *new = NULL;
cil_blockabstract_init(&new);
new->block_str = orig->block_str;
new->block = orig->block;
*copy = new;
return SEPOL_OK;
}
int cil_copy_blockinherit(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_blockinherit *orig = data;
struct cil_blockinherit *new = NULL;
cil_blockinherit_init(&new);
new->block_str = orig->block_str;
new->block = orig->block;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_policycap(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_policycap *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_policycap *new;
cil_policycap_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_perm(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_perm *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_perm *new;
cil_perm_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
void cil_copy_classperms(struct cil_classperms *orig, struct cil_classperms **new)
{
cil_classperms_init(new);
(*new)->class_str = orig->class_str;
cil_copy_list(orig->perm_strs, &((*new)->perm_strs));
}
void cil_copy_classperms_set(struct cil_classperms_set *orig, struct cil_classperms_set **new)
{
cil_classperms_set_init(new);
(*new)->set_str = orig->set_str;
}
void cil_copy_classperms_list(struct cil_list *orig, struct cil_list **new)
{
struct cil_list_item *orig_item;
if (orig == NULL) {
return;
}
cil_list_init(new, CIL_LIST_ITEM);
cil_list_for_each(orig_item, orig) {
if (orig_item->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp;
cil_copy_classperms(orig_item->data, &cp);
cil_list_append(*new, CIL_CLASSPERMS, cp);
} else {
struct cil_classperms_set *cp_set;
cil_copy_classperms_set(orig_item->data, &cp_set);
cil_list_append(*new, CIL_CLASSPERMS_SET, cp_set);
}
}
}
int cil_copy_classmapping(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_classmapping *orig = data;
struct cil_classmapping *new = NULL;
cil_classmapping_init(&new);
new->map_class_str = orig->map_class_str;
new->map_class = orig->map_class;
new->map_perm_str = orig->map_perm_str;
new->map_perm = orig->map_perm;
cil_copy_classperms_list(orig->classperms, &new->classperms);
*copy = new;
return SEPOL_OK;
}
int cil_copy_class(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_class *orig = data;
struct cil_class *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_class: class cannot be redefined\n");
return SEPOL_ERR;
}
cil_class_init(&new);
new->common = NULL;
*copy = new;
return SEPOL_OK;
}
int cil_copy_classpermission(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_classpermission *orig = data;
struct cil_classpermission *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
if (key != NULL) {
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "classpermission cannot be redefined\n");
return SEPOL_ERR;
}
}
cil_classpermission_init(&new);
cil_copy_classperms_list(orig->classperms, &new->classperms);
*copy = new;
return SEPOL_OK;
}
int cil_copy_classpermissionset(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_classpermissionset *orig = data;
struct cil_classpermissionset *new = NULL;
cil_classpermissionset_init(&new);
new->set_str = orig->set_str;
new->set = orig->set;
cil_copy_classperms_list(orig->classperms, &new->classperms);
*copy = new;
return SEPOL_OK;
}
int cil_copy_classcommon(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_classcommon *orig = data;
struct cil_classcommon *new = NULL;
cil_classcommon_init(&new);
new->class_str = orig->class_str;
new->class = orig->class;
new->common_str = orig->common_str;
new->common = orig->common;
*copy = new;
return SEPOL_OK;
}
int cil_copy_sid(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_sid *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_sid *new;
cil_sid_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_sidcontext(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_sidcontext *orig = data;
struct cil_sidcontext *new = NULL;
cil_sidcontext_init(&new);
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_user(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_user *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_user *new;
cil_user_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_userattribute(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_userattribute *orig = data;
struct cil_userattribute *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
cil_userattribute_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_userattributeset(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_userattributeset *orig = data;
struct cil_userattributeset *new = NULL;
cil_userattributeset_init(&new);
new->attr_str = orig->attr_str;
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
int cil_copy_userrole(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_userrole *orig = data;
struct cil_userrole *new = NULL;
cil_userrole_init(&new);
new->user_str = orig->user_str;
new->role_str = orig->role_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_userlevel(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_userlevel *orig = data;
struct cil_userlevel *new = NULL;
cil_userlevel_init(&new);
new->user_str = orig->user_str;
if (orig->level_str != NULL) {
new->level_str = orig->level_str;
} else {
cil_copy_fill_level(db, orig->level, &new->level);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_userrange(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_userrange *orig = data;
struct cil_userrange *new = NULL;
cil_userrange_init(&new);
new->user_str = orig->user_str;
if (orig->range_str != NULL) {
new->range_str = orig->range_str;
} else {
cil_levelrange_init(&new->range);
cil_copy_fill_levelrange(db, orig->range, new->range);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_userprefix(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_userprefix *orig = data;
struct cil_userprefix *new = NULL;
cil_userprefix_init(&new);
new->user_str = orig->user_str;
new->prefix_str = orig->prefix_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_role(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_role *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_role *new;
cil_role_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_roletype(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_roletype *orig = data;
struct cil_roletype *new = NULL;
cil_roletype_init(&new);
new->role_str = orig->role_str;
new->type_str = orig->type_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_roleattribute(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_roleattribute *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_roleattribute *new;
cil_roleattribute_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_roleattributeset(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_roleattributeset *orig = data;
struct cil_roleattributeset *new = NULL;
cil_roleattributeset_init(&new);
new->attr_str = orig->attr_str;
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
int cil_copy_roleallow(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_roleallow *orig = data;
struct cil_roleallow *new = NULL;
cil_roleallow_init(&new);
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_type(__attribute__((unused)) struct cil_db *db, __attribute__((unused)) void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_type *new;
cil_type_init(&new);
*copy = new;
return SEPOL_OK;
}
int cil_copy_typepermissive(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_typepermissive *orig = data;
struct cil_typepermissive *new = NULL;
cil_typepermissive_init(&new);
new->type_str = orig->type_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_typeattribute(__attribute__((unused)) struct cil_db *db, __attribute__((unused)) void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_typeattribute *new;
cil_typeattribute_init(&new);
*copy = new;
return SEPOL_OK;
}
int cil_copy_typeattributeset(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_typeattributeset *orig = data;
struct cil_typeattributeset *new = NULL;
cil_typeattributeset_init(&new);
new->attr_str = orig->attr_str;
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
static int cil_copy_expandtypeattribute(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_expandtypeattribute *orig = data;
struct cil_expandtypeattribute *new = NULL;
cil_expandtypeattribute_init(&new);
if (orig->attr_strs != NULL) {
cil_copy_list(orig->attr_strs, &new->attr_strs);
}
if (orig->attr_datums != NULL) {
cil_copy_list(orig->attr_datums, &new->attr_datums);
}
new->expand = orig->expand;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_alias(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_alias *orig = data;
struct cil_alias *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_alias: alias cannot be redefined\n");
return SEPOL_ERR;
}
cil_alias_init(&new);
*copy = new;
return SEPOL_OK;
}
static int cil_copy_aliasactual(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused))symtab_t *symtab)
{
struct cil_aliasactual *orig = data;
struct cil_aliasactual *new = NULL;
cil_aliasactual_init(&new);
new->alias_str = orig->alias_str;
new->alias = orig->alias;
new->actual_str = orig->actual_str;
new->actual = orig->actual;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_roletransition(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_roletransition *orig = data;
struct cil_roletransition *new = NULL;
cil_roletransition_init(&new);
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
new->obj_str = orig->obj_str;
new->result_str = orig->result_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_nametypetransition(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_nametypetransition *orig = data;
struct cil_nametypetransition *new = NULL;
cil_nametypetransition_init(&new);
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
new->obj_str = orig->obj_str;
new->name_str = orig->name_str;
new->name = orig->name;
new->result_str = orig->result_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_rangetransition(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_rangetransition *orig = data;
struct cil_rangetransition *new = NULL;
cil_rangetransition_init(&new);
new->src_str = orig->src_str;
new->exec_str = orig->exec_str;
new->obj_str = orig->obj_str;
if (orig->range_str != NULL) {
new->range_str = orig->range_str;
} else {
cil_levelrange_init(&new->range);
cil_copy_fill_levelrange(db, orig->range, new->range);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_bool(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_bool *orig = data;
struct cil_bool *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_bool: boolean cannot be redefined\n");
return SEPOL_ERR;
}
cil_bool_init(&new);
new->value = orig->value;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_tunable(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_tunable *orig = data;
struct cil_tunable *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_tunable: tunable cannot be redefined\n");
return SEPOL_ERR;
}
cil_tunable_init(&new);
new->value = orig->value;
*copy = new;
return SEPOL_OK;
}
static void cil_copy_fill_permissionx(struct cil_db *db, struct cil_permissionx *orig, struct cil_permissionx *new)
{
new->kind = orig->kind;
new->obj_str = orig->obj_str;
cil_copy_expr(db, orig->expr_str, &new->expr_str);
}
int cil_copy_avrule(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_avrule *orig = data;
struct cil_avrule *new = NULL;
cil_avrule_init(&new);
new->is_extended = orig->is_extended;
new->rule_kind = orig->rule_kind;
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
if (!new->is_extended) {
cil_copy_classperms_list(orig->perms.classperms, &new->perms.classperms);
} else {
if (orig->perms.x.permx_str != NULL) {
new->perms.x.permx_str = orig->perms.x.permx_str;
} else {
cil_permissionx_init(&new->perms.x.permx);
cil_copy_fill_permissionx(db, orig->perms.x.permx, new->perms.x.permx);
}
}
*copy = new;
return SEPOL_OK;
}
static int cil_copy_permissionx(struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_permissionx *orig = data;
struct cil_permissionx *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_permissionx: permissionx cannot be redefined\n");
return SEPOL_ERR;
}
cil_permissionx_init(&new);
cil_copy_fill_permissionx(db, orig, new);
*copy = new;
return SEPOL_OK;
}
int cil_copy_deny_rule(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_deny_rule *orig = data;
struct cil_deny_rule *new = NULL;
cil_deny_rule_init(&new);
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
cil_copy_classperms_list(orig->classperms, &new->classperms);
*copy = new;
return SEPOL_OK;
}
int cil_copy_type_rule(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_type_rule *orig = data;
struct cil_type_rule *new = NULL;
cil_type_rule_init(&new);
new->rule_kind = orig->rule_kind;
new->src_str = orig->src_str;
new->tgt_str = orig->tgt_str;
new->obj_str = orig->obj_str;
new->result_str = orig->result_str;
*copy = new;
return SEPOL_OK;
}
int cil_copy_sens(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_sens *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_sens *new;
cil_sens_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
int cil_copy_cat(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_cat *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum == NULL) {
struct cil_cat *new;
cil_cat_init(&new);
*copy = new;
} else {
*copy = datum;
}
return SEPOL_OK;
}
static void cil_copy_cats(struct cil_db *db, struct cil_cats *orig, struct cil_cats **new)
{
cil_cats_init(new);
cil_copy_expr(db, orig->str_expr, &(*new)->str_expr);
cil_copy_expr(db, orig->datum_expr, &(*new)->datum_expr);
}
int cil_copy_catset(struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_catset *orig = data;
struct cil_catset *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_catset: categoryset cannot be redefined\n");
return SEPOL_ERR;
}
cil_catset_init(&new);
cil_copy_cats(db, orig->cats, &new->cats);
*copy = new;
return SEPOL_OK;
}
int cil_copy_senscat(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_senscat *orig = data;
struct cil_senscat *new = NULL;
cil_senscat_init(&new);
new->sens_str = orig->sens_str;
cil_copy_cats(db, orig->cats, &new->cats);
*copy = new;
return SEPOL_OK;
}
void cil_copy_fill_level(struct cil_db *db, struct cil_level *orig, struct cil_level **new)
{
cil_level_init(new);
(*new)->sens_str = orig->sens_str;
if (orig->cats != NULL) {
cil_copy_cats(db, orig->cats, &(*new)->cats);
}
}
int cil_copy_level(struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_level *orig = data;
struct cil_level *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
if (key != NULL) {
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_level: level cannot be redefined\n");
return SEPOL_ERR;
}
}
cil_copy_fill_level(db, orig, &new);
*copy = new;
return SEPOL_OK;
}
void cil_copy_fill_levelrange(struct cil_db *db, struct cil_levelrange *data, struct cil_levelrange *new)
{
if (data->low_str != NULL) {
new->low_str = data->low_str;
} else {
cil_copy_fill_level(db, data->low, &new->low);
}
if (data->high_str != NULL) {
new->high_str = data->high_str;
} else {
cil_copy_fill_level(db, data->high, &new->high);
}
}
int cil_copy_levelrange(struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_levelrange *orig = data;
struct cil_levelrange *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
if (key != NULL) {
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_levelrange: levelrange cannot be redefined\n");
return SEPOL_ERR;
}
}
cil_levelrange_init(&new);
cil_copy_fill_levelrange(db, orig, new);
*copy = new;
return SEPOL_OK;
}
void cil_copy_fill_context(struct cil_db *db, struct cil_context *data, struct cil_context *new)
{
new->user_str = data->user_str;
new->role_str = data->role_str;
new->type_str = data->type_str;
if (data->range_str != NULL) {
new->range_str = data->range_str;
} else {
cil_levelrange_init(&new->range);
cil_copy_fill_levelrange(db, data->range, new->range);
}
}
int cil_copy_context(struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_context *orig = data;
struct cil_context *new = NULL;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
if (key != NULL) {
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_context: context cannot be redefined\n");
return SEPOL_ERR;
}
}
cil_context_init(&new);
cil_copy_fill_context(db, orig, new);
*copy = new;
return SEPOL_OK;
}
int cil_copy_netifcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_netifcon *orig = data;
struct cil_netifcon *new = NULL;
cil_netifcon_init(&new);
new->interface_str = orig->interface_str;
if (orig->if_context_str != NULL) {
new->if_context_str = orig->if_context_str;
} else {
cil_context_init(&new->if_context);
cil_copy_fill_context(db, orig->if_context, new->if_context);
}
if (orig->packet_context_str != NULL) {
new->packet_context_str = orig->packet_context_str;
} else {
cil_context_init(&new->packet_context);
cil_copy_fill_context(db, orig->packet_context, new->packet_context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_genfscon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_genfscon *orig = data;
struct cil_genfscon *new = NULL;
cil_genfscon_init(&new);
new->fs_str = orig->fs_str;
new->path_str = orig->path_str;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_filecon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_filecon *orig = data;
struct cil_filecon *new = NULL;
cil_filecon_init(&new);
new->path_str = orig->path_str;
new->path = orig->path;
new->type = orig->type;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else if (orig->context != NULL) {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_nodecon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_nodecon *orig = data;
struct cil_nodecon *new = NULL;
cil_nodecon_init(&new);
if (orig->addr_str != NULL) {
new->addr_str = orig->addr_str;
} else {
cil_ipaddr_init(&new->addr);
cil_copy_fill_ipaddr(orig->addr, new->addr);
}
if (orig->mask_str != NULL) {
new->mask_str = orig->mask_str;
} else {
cil_ipaddr_init(&new->mask);
cil_copy_fill_ipaddr(orig->mask, new->mask);
}
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_ibpkeycon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_ibpkeycon *orig = data;
struct cil_ibpkeycon *new = NULL;
cil_ibpkeycon_init(&new);
new->subnet_prefix_str = orig->subnet_prefix_str;
new->pkey_low = orig->pkey_low;
new->pkey_high = orig->pkey_high;
if (orig->context_str) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
static int cil_copy_ibendportcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_ibendportcon *orig = data;
struct cil_ibendportcon *new = NULL;
cil_ibendportcon_init(&new);
new->dev_name_str = orig->dev_name_str;
new->port = orig->port;
if (orig->context_str) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_portcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_portcon *orig = data;
struct cil_portcon *new = NULL;
cil_portcon_init(&new);
new->proto = orig->proto;
new->port_low = orig->port_low;
new->port_high = orig->port_high;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_pirqcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_pirqcon *orig = data;
struct cil_pirqcon *new = NULL;
cil_pirqcon_init(&new);
new->pirq = orig->pirq;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_iomemcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_iomemcon *orig = data;
struct cil_iomemcon *new = NULL;
cil_iomemcon_init(&new);
new->iomem_low = orig->iomem_low;
new->iomem_high = orig->iomem_high;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_ioportcon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_ioportcon *orig = data;
struct cil_ioportcon *new = NULL;
cil_ioportcon_init(&new);
new->ioport_low = orig->ioport_low;
new->ioport_high = orig->ioport_high;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_pcidevicecon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_pcidevicecon *orig = data;
struct cil_pcidevicecon *new = NULL;
cil_pcidevicecon_init(&new);
new->dev = orig->dev;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
static int cil_copy_devicetreecon(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_devicetreecon *orig = data;
struct cil_devicetreecon *new = NULL;
cil_devicetreecon_init(&new);
new->path = orig->path;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_fsuse(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_fsuse *orig = data;
struct cil_fsuse *new = NULL;
cil_fsuse_init(&new);
new->type = orig->type;
new->fs_str = orig->fs_str;
if (orig->context_str != NULL) {
new->context_str = orig->context_str;
} else {
cil_context_init(&new->context);
cil_copy_fill_context(db, orig->context, new->context);
}
*copy = new;
return SEPOL_OK;
}
int cil_copy_expr(struct cil_db *db, struct cil_list *orig, struct cil_list **new)
{
struct cil_list_item *curr;
if (orig == NULL) {
*new = NULL;
return SEPOL_OK;
}
cil_list_init(new, orig->flavor);
cil_list_for_each(curr, orig) {
switch (curr->flavor) {
case CIL_LIST: {
struct cil_list *sub_list;
cil_copy_expr(db, curr->data, &sub_list);
cil_list_append(*new, CIL_LIST, sub_list);
break;
}
case CIL_STRING:
cil_list_append(*new, CIL_STRING, curr->data);
break;
case CIL_DATUM:
cil_list_append(*new, curr->flavor, curr->data);
break;
case CIL_OP:
cil_list_append(*new, curr->flavor, curr->data);
break;
case CIL_CONS_OPERAND:
cil_list_append(*new, curr->flavor, curr->data);
break;
default:
cil_log(CIL_INFO, "Unknown flavor %d in expression being copied\n",curr->flavor);
cil_list_append(*new, curr->flavor, curr->data);
break;
}
}
return SEPOL_OK;
}
int cil_copy_constrain(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_constrain *orig = data;
struct cil_constrain *new = NULL;
cil_constrain_init(&new);
cil_copy_classperms_list(orig->classperms, &new->classperms);
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
int cil_copy_validatetrans(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_validatetrans *orig = data;
struct cil_validatetrans *new = NULL;
cil_validatetrans_init(&new);
new->class_str = orig->class_str;
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
int cil_copy_call(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_call *orig = data;
struct cil_call *new = NULL;
int rc = SEPOL_ERR;
cil_call_init(&new);
new->macro_str = orig->macro_str;
new->macro = orig->macro;
if (orig->args_tree != NULL) {
cil_tree_init(&new->args_tree);
rc = cil_copy_ast(db, orig->args_tree->root, new->args_tree->root);
if (rc != SEPOL_OK) {
goto exit;
}
}
new->copied = orig->copied;
*copy = new;
return SEPOL_OK;
exit:
cil_destroy_call(new);
return rc;
}
static int cil_copy_macro(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_macro *orig = data;
char *key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
if (FLAVOR(datum) != CIL_MACRO) {
cil_tree_log(NODE(orig), CIL_ERR, "Macro %s being copied", key);
cil_tree_log(NODE(datum), CIL_ERR, " Conflicts with %s already declared", cil_node_to_string(NODE(datum)));
return SEPOL_ERR;
}
cil_tree_log(NODE(orig), CIL_WARN, "Skipping macro %s", key);
cil_tree_log(NODE(datum), CIL_WARN, " Previously declared");
*copy = NULL;
} else {
struct cil_macro *new;
cil_macro_init(&new);
if (orig->params != NULL) {
cil_copy_list(orig->params, &new->params);
}
*copy = new;
}
return SEPOL_OK;
}
int cil_copy_optional(__attribute__((unused)) struct cil_db *db, __attribute__((unused)) void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_optional *new;
cil_optional_init(&new);
*copy = new;
return SEPOL_OK;
}
void cil_copy_fill_ipaddr(struct cil_ipaddr *data, struct cil_ipaddr *new)
{
new->family = data->family;
memcpy(&new->ip, &data->ip, sizeof(data->ip));
}
int cil_copy_ipaddr(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab)
{
struct cil_ipaddr *orig = data;
struct cil_ipaddr *new = NULL;
char * key = orig->datum.name;
struct cil_symtab_datum *datum = NULL;
cil_symtab_get_datum(symtab, key, &datum);
if (datum != NULL) {
cil_log(CIL_INFO, "cil_copy_ipaddr: ipaddress cannot be redefined\n");
return SEPOL_ERR;
}
cil_ipaddr_init(&new);
cil_copy_fill_ipaddr(orig, new);
*copy = new;
return SEPOL_OK;
}
static int cil_copy_condblock(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_condblock *orig = data;
struct cil_condblock *new = *copy;
cil_condblock_init(&new);
new->flavor = orig->flavor;
*copy = new;
return SEPOL_OK;
}
int cil_copy_boolif(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_booleanif *orig = data;
struct cil_booleanif *new = NULL;
cil_boolif_init(&new);
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
new->preserved_tunable = orig->preserved_tunable;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_tunif(struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_tunableif *orig = data;
struct cil_tunableif *new = NULL;
cil_tunif_init(&new);
cil_copy_expr(db, orig->str_expr, &new->str_expr);
cil_copy_expr(db, orig->datum_expr, &new->datum_expr);
*copy = new;
return SEPOL_OK;
}
static int cil_copy_default(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_default *orig = data;
struct cil_default *new = NULL;
cil_default_init(&new);
new->flavor = orig->flavor;
if (orig->class_strs != NULL) {
cil_copy_list(orig->class_strs, &new->class_strs);
}
new->object = orig->object;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_defaultrange(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_defaultrange *orig = data;
struct cil_defaultrange *new = NULL;
cil_defaultrange_init(&new);
if (orig->class_strs != NULL) {
cil_copy_list(orig->class_strs, &new->class_strs);
}
new->object_range = orig->object_range;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_handleunknown(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_handleunknown *orig = data;
struct cil_handleunknown *new = NULL;
cil_handleunknown_init(&new);
new->handle_unknown = orig->handle_unknown;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_mls(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_mls *orig = data;
struct cil_mls *new = NULL;
cil_mls_init(&new);
new->value = orig->value;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_bounds(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_bounds *orig = data;
struct cil_bounds *new = NULL;
cil_bounds_init(&new);
new->parent_str = orig->parent_str;
new->child_str = orig->child_str;
*copy = new;
return SEPOL_OK;
}
static int cil_copy_src_info(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab)
{
struct cil_src_info *orig = data;
struct cil_src_info *new = NULL;
cil_src_info_init(&new);
new->kind = orig->kind;
new->hll_line = orig->hll_line;
new->path = orig->path;
*copy = new;
return SEPOL_OK;
}
static int __cil_copy_node_helper(struct cil_tree_node *orig, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_tree_node *parent = NULL;
struct cil_tree_node *new = NULL;
struct cil_db *db = NULL;
struct cil_args_copy *args = NULL;
struct cil_tree_node *namespace = NULL;
enum cil_sym_index sym_index = CIL_SYM_UNKNOWN;
symtab_t *symtab = NULL;
void *data = NULL;
int (*copy_func)(struct cil_db *db, void *data, void **copy, symtab_t *symtab) = NULL;
struct cil_blockinherit *blockinherit = NULL;
if (orig == NULL || extra_args == NULL) {
goto exit;
}
args = extra_args;
parent = args->dest;
db = args->db;
switch (orig->flavor) {
case CIL_BLOCK:
copy_func = &cil_copy_block;
break;
case CIL_BLOCKABSTRACT:
if (args->orig_dest->flavor == CIL_BLOCKINHERIT) {
/* When inheriting a block, don't copy any blockabstract
* statements. Inheriting a block from a block that was
* just inherited never worked. */
return SEPOL_OK;
}
copy_func = &cil_copy_blockabstract;
break;
case CIL_BLOCKINHERIT:
copy_func = &cil_copy_blockinherit;
break;
case CIL_POLICYCAP:
copy_func = &cil_copy_policycap;
break;
case CIL_PERM:
case CIL_MAP_PERM:
copy_func = &cil_copy_perm;
break;
case CIL_CLASSMAPPING:
copy_func = &cil_copy_classmapping;
break;
case CIL_CLASS:
case CIL_COMMON:
case CIL_MAP_CLASS:
copy_func = &cil_copy_class;
break;
case CIL_CLASSORDER:
copy_func = &cil_copy_ordered;
break;
case CIL_CLASSPERMISSION:
copy_func = &cil_copy_classpermission;
break;
case CIL_CLASSPERMISSIONSET:
copy_func = &cil_copy_classpermissionset;
break;
case CIL_CLASSCOMMON:
copy_func = &cil_copy_classcommon;
break;
case CIL_SID:
copy_func = &cil_copy_sid;
break;
case CIL_SIDCONTEXT:
copy_func = &cil_copy_sidcontext;
break;
case CIL_SIDORDER:
copy_func = &cil_copy_ordered;
break;
case CIL_USER:
copy_func = &cil_copy_user;
break;
case CIL_USERATTRIBUTE:
copy_func = &cil_copy_userattribute;
break;
case CIL_USERATTRIBUTESET:
copy_func = &cil_copy_userattributeset;
break;
case CIL_USERROLE:
copy_func = &cil_copy_userrole;
break;
case CIL_USERLEVEL:
copy_func = &cil_copy_userlevel;
break;
case CIL_USERRANGE:
copy_func = &cil_copy_userrange;
break;
case CIL_USERBOUNDS:
copy_func = &cil_copy_bounds;
break;
case CIL_USERPREFIX:
copy_func = &cil_copy_userprefix;
break;
case CIL_ROLE:
copy_func = &cil_copy_role;
break;
case CIL_ROLETYPE:
copy_func = &cil_copy_roletype;
break;
case CIL_ROLEBOUNDS:
copy_func = &cil_copy_bounds;
break;
case CIL_ROLEATTRIBUTE:
copy_func = &cil_copy_roleattribute;
break;
case CIL_ROLEATTRIBUTESET:
copy_func = &cil_copy_roleattributeset;
break;
case CIL_ROLEALLOW:
copy_func = &cil_copy_roleallow;
break;
case CIL_TYPE:
copy_func = &cil_copy_type;
break;
case CIL_TYPEBOUNDS:
copy_func = &cil_copy_bounds;
break;
case CIL_TYPEPERMISSIVE:
copy_func = cil_copy_typepermissive;
break;
case CIL_TYPEATTRIBUTE:
copy_func = &cil_copy_typeattribute;
break;
case CIL_TYPEATTRIBUTESET:
copy_func = &cil_copy_typeattributeset;
break;
case CIL_EXPANDTYPEATTRIBUTE:
copy_func = &cil_copy_expandtypeattribute;
break;
case CIL_TYPEALIAS:
copy_func = &cil_copy_alias;
break;
case CIL_TYPEALIASACTUAL:
copy_func = &cil_copy_aliasactual;
break;
case CIL_ROLETRANSITION:
copy_func = &cil_copy_roletransition;
break;
case CIL_NAMETYPETRANSITION:
copy_func = &cil_copy_nametypetransition;
break;
case CIL_RANGETRANSITION:
copy_func = &cil_copy_rangetransition;
break;
case CIL_TUNABLE:
copy_func = &cil_copy_tunable;
break;
case CIL_BOOL:
copy_func = &cil_copy_bool;
break;
case CIL_AVRULE:
case CIL_AVRULEX:
copy_func = &cil_copy_avrule;
break;
case CIL_PERMISSIONX:
copy_func = &cil_copy_permissionx;
break;
case CIL_DENY_RULE:
copy_func = &cil_copy_deny_rule;
break;
case CIL_TYPE_RULE:
copy_func = &cil_copy_type_rule;
break;
case CIL_SENS:
copy_func = &cil_copy_sens;
break;
case CIL_SENSALIAS:
copy_func = &cil_copy_alias;
break;
case CIL_SENSALIASACTUAL:
copy_func = &cil_copy_aliasactual;
break;
case CIL_CAT:
copy_func = &cil_copy_cat;
break;
case CIL_CATALIAS:
copy_func = &cil_copy_alias;
break;
case CIL_CATALIASACTUAL:
copy_func = &cil_copy_aliasactual;
break;
case CIL_CATSET:
copy_func = &cil_copy_catset;
break;
case CIL_SENSCAT:
copy_func = &cil_copy_senscat;
break;
case CIL_CATORDER:
copy_func = &cil_copy_ordered;
break;
case CIL_SENSITIVITYORDER:
copy_func = &cil_copy_ordered;
break;
case CIL_LEVEL:
copy_func = &cil_copy_level;
break;
case CIL_LEVELRANGE:
copy_func = &cil_copy_levelrange;
break;
case CIL_CONTEXT:
copy_func = &cil_copy_context;
break;
case CIL_NETIFCON:
copy_func = &cil_copy_netifcon;
break;
case CIL_GENFSCON:
copy_func = &cil_copy_genfscon;
break;
case CIL_FILECON:
copy_func = &cil_copy_filecon;
break;
case CIL_NODECON:
copy_func = &cil_copy_nodecon;
break;
case CIL_IBPKEYCON:
copy_func = &cil_copy_ibpkeycon;
break;
case CIL_IBENDPORTCON:
copy_func = &cil_copy_ibendportcon;
break;
case CIL_PORTCON:
copy_func = &cil_copy_portcon;
break;
case CIL_PIRQCON:
copy_func = &cil_copy_pirqcon;
break;
case CIL_IOMEMCON:
copy_func = &cil_copy_iomemcon;
break;
case CIL_IOPORTCON:
copy_func = &cil_copy_ioportcon;
break;
case CIL_PCIDEVICECON:
copy_func = &cil_copy_pcidevicecon;
break;
case CIL_DEVICETREECON:
copy_func = &cil_copy_devicetreecon;
break;
case CIL_FSUSE:
copy_func = &cil_copy_fsuse;
break;
case CIL_CONSTRAIN:
case CIL_MLSCONSTRAIN:
copy_func = &cil_copy_constrain;
break;
case CIL_VALIDATETRANS:
case CIL_MLSVALIDATETRANS:
copy_func = &cil_copy_validatetrans;
break;
case CIL_CALL:
copy_func = &cil_copy_call;
break;
case CIL_MACRO:
copy_func = &cil_copy_macro;
break;
case CIL_NODE:
copy_func = &cil_copy_node;
break;
case CIL_OPTIONAL:
copy_func = &cil_copy_optional;
break;
case CIL_IPADDR:
copy_func = &cil_copy_ipaddr;
break;
case CIL_CONDBLOCK:
copy_func = &cil_copy_condblock;
break;
case CIL_BOOLEANIF:
copy_func = &cil_copy_boolif;
break;
case CIL_TUNABLEIF:
copy_func = &cil_copy_tunif;
break;
case CIL_DEFAULTUSER:
case CIL_DEFAULTROLE:
case CIL_DEFAULTTYPE:
copy_func = &cil_copy_default;
break;
case CIL_DEFAULTRANGE:
copy_func = &cil_copy_defaultrange;
break;
case CIL_HANDLEUNKNOWN:
copy_func = &cil_copy_handleunknown;
break;
case CIL_MLS:
copy_func = &cil_copy_mls;
break;
case CIL_SRC_INFO:
copy_func = &cil_copy_src_info;
break;
default:
goto exit;
}
if (orig->flavor >= CIL_MIN_DECLARATIVE) {
rc = cil_flavor_to_symtab_index(orig->flavor, &sym_index);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_get_symtab(parent, &symtab, sym_index);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = (*copy_func)(db, orig->data, &data, symtab);
if (rc == SEPOL_OK) {
if (orig->flavor == CIL_MACRO && data == NULL) {
/* Skipping macro re-declaration */
if (args->orig_dest->flavor != CIL_BLOCKINHERIT) {
cil_log(CIL_ERR, " Re-declaration of macro is only allowed when inheriting a block\n");
return SEPOL_ERR;
}
*finished = CIL_TREE_SKIP_HEAD;
return SEPOL_OK;
}
cil_tree_node_init(&new);
new->parent = parent;
new->line = orig->line;
new->hll_offset = orig->hll_offset;
new->flavor = orig->flavor;
new->data = data;
if (orig->flavor == CIL_BLOCK && DATUM(data)->nodes->head != NULL) {
/* Duplicate block */
if (args->orig_dest->flavor != CIL_BLOCKINHERIT) {
cil_log(CIL_ERR, " Re-declaration of block is only allowed when inheriting a block\n");
rc = SEPOL_ERR;
goto exit;
}
cil_list_append(DATUM(new->data)->nodes, CIL_NODE, new);
} else if (orig->flavor >= CIL_MIN_DECLARATIVE) {
/* Check the flavor of data if was found in the destination symtab */
if (DATUM(data)->nodes->head && FLAVOR(data) != orig->flavor) {
cil_tree_log(orig, CIL_ERR, "Incompatible flavor when trying to copy %s", DATUM(data)->name);
cil_tree_log(NODE(data), CIL_ERR, "Note: conflicting declaration");
new->flavor = FLAVOR(data);
rc = SEPOL_ERR;
goto exit;
}
rc = cil_add_decl_to_symtab(db, symtab, DATUM(orig->data)->name, DATUM(data), new);
if (rc != SEPOL_OK) {
if (rc == SEPOL_EEXIST) {
cil_symtab_datum_destroy(data);
free(data);
data = NULL;
rc = SEPOL_OK;
} else {
goto exit;
}
}
namespace = new;
while (namespace->flavor != CIL_MACRO && namespace->flavor != CIL_BLOCK && namespace->flavor != CIL_ROOT) {
namespace = namespace->parent;
}
if (namespace->flavor == CIL_MACRO) {
rc = cil_verify_decl_does_not_shadow_macro_parameter(namespace->data, orig, DATUM(orig->data)->name);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
if (new->flavor == CIL_BLOCKINHERIT) {
blockinherit = new->data;
// if a blockinherit statement is copied before blockinherit are
// resolved (like in an in-statement), the block will not have been
// resolved yet, so there's nothing to append yet. This is fine,
// the copied blockinherit statement will be handled later, as if
// it wasn't in an in-statement
if (blockinherit->block != NULL) {
cil_list_append(blockinherit->block->bi_nodes, CIL_NODE, new);
}
}
if (parent->cl_head == NULL) {
parent->cl_head = new;
parent->cl_tail = new;
} else {
parent->cl_tail->next = new;
parent->cl_tail = new;
}
if (orig->cl_head != NULL) {
args->dest = new;
}
} else {
cil_tree_log(orig, CIL_ERR, "Problem copying %s node", cil_node_to_string(orig));
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_node_destroy(&new);
return rc;
}
static int __cil_copy_last_child_helper(__attribute__((unused)) struct cil_tree_node *orig, void *extra_args)
{
struct cil_tree_node *node = NULL;
struct cil_args_copy *args = NULL;
args = extra_args;
node = args->dest;
if (node->flavor != CIL_ROOT) {
args->dest = node->parent;
}
return SEPOL_OK;
}
// dest is the parent node to copy into
// if the copy is for a call to a macro, dest should be a pointer to the call
int cil_copy_ast(struct cil_db *db, struct cil_tree_node *orig, struct cil_tree_node *dest)
{
int rc = SEPOL_ERR;
struct cil_args_copy extra_args;
extra_args.orig_dest = dest;
extra_args.dest = dest;
extra_args.db = db;
rc = cil_tree_walk(orig, __cil_copy_node_helper, NULL, __cil_copy_last_child_helper, &extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(dest, CIL_ERR, "Failed to copy %s to %s", cil_node_to_string(orig), cil_node_to_string(dest));
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
libsepol-3.8.1/cil/src/cil_copy_ast.h000066400000000000000000000205261476211737200175320ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_COPY_H_
#define CIL_COPY_H_
#include "cil_internal.h"
#include "cil_tree.h"
#include "cil_symtab.h"
void cil_copy_list(struct cil_list *orig, struct cil_list **copy);
int cil_copy_expr(struct cil_db *db, struct cil_list *orig, struct cil_list **new);
int cil_copy_ordered(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab);
int cil_copy_block(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_blockabstract(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_blockinherit(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_perm(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_class(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_classmapping(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_permset(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
void cil_copy_classperms(struct cil_classperms *orig, struct cil_classperms **new);
void cil_copy_classperms_set(struct cil_classperms_set *orig, struct cil_classperms_set **new);
void cil_copy_classperms_list(struct cil_list *orig, struct cil_list **new);
int cil_copy_classpermission(__attribute__((unused)) struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_classpermissionset(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab);
int cil_copy_common(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_classcommon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_sid(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_sidcontext(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_user(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userattribute(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userattributeset(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userrole(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userlevel(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userrange(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userbounds(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_userprefix(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_role(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_roletype(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_rolebounds(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_roleattribute(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_roleattributeset(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_roleallow(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_type(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_typebounds(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_typepermissive(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_typeattribute(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_typeattributeset(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_typealias(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_nametypetransition(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_rangetransition(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_bool(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_avrule(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_deny_rule(__attribute__((unused)) struct cil_db *db, void *data, void **copy, __attribute__((unused)) symtab_t *symtab);
int cil_copy_type_rule(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_sens(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_sensalias(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_cat(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_catalias(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_catset(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_senscat(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
void cil_copy_fill_level(struct cil_db *db, struct cil_level *orig, struct cil_level **new);
int cil_copy_level(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
void cil_copy_fill_levelrange(struct cil_db *db, struct cil_levelrange *orig, struct cil_levelrange *new);
int cil_copy_levelrange(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
void cil_copy_fill_context(struct cil_db *db, struct cil_context *orig, struct cil_context *new);
int cil_copy_context(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_netifcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_genfscon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_filecon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_nodecon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_ibpkeycon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_portcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_pirqcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_iomemcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_ioportcon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_pcidevicecon(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_fsuse(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_exrp(struct cil_db *db, struct cil_list *orig, struct cil_list **new);
int cil_copy_constrain(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_validatetrans(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_call(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_optional(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
void cil_copy_fill_ipaddr(struct cil_ipaddr *orig, struct cil_ipaddr *new);
int cil_copy_ipaddr(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_boolif(struct cil_db *db, void *data, void **copy, symtab_t *symtab);
int cil_copy_ast(struct cil_db *db, struct cil_tree_node *orig, struct cil_tree_node *dest);
#endif
libsepol-3.8.1/cil/src/cil_deny.c000066400000000000000000001125201476211737200166370ustar00rootroot00000000000000/*
* This file is public domain software, i.e. not copyrighted.
*
* Warranty Exclusion
* ------------------
* You agree that this software is a non-commercially developed program
* that may contain "bugs" (as that term is used in the industry) and
* that it may not function as intended. The software is licensed
* "as is". NSA makes no, and hereby expressly disclaims all, warranties,
* express, implied, statutory, or otherwise with respect to the software,
* including noninfringement and the implied warranties of merchantability
* and fitness for a particular purpose.
*
* Limitation of Liability
*-----------------------
* In no event will NSA be liable for any damages, including loss of data,
* lost profits, cost of cover, or other special, incidental, consequential,
* direct or indirect damages arising from the software or the use thereof,
* however caused and on any theory of liability. This limitation will apply
* even if NSA has been advised of the possibility of such damage. You
* acknowledge that this is a reasonable allocation of risk.
*
* Original author: James Carter
*/
#include
#include "cil_internal.h"
#include "cil_find.h"
#include "cil_flavor.h"
#include "cil_list.h"
#include "cil_strpool.h"
#include "cil_log.h"
#include "cil_symtab.h"
#include "cil_build_ast.h"
#include "cil_copy_ast.h"
#include "cil_deny.h"
#define CIL_DENY_ATTR_PREFIX "deny_rule_attr"
/*
* A deny rule is like a neverallow rule, except that permissions are
* removed rather than an error reported.
*
* (allow S1 T1 P1)
* (deny S2 T2 P2)
*
* First, write the allow rule with all of the permissions not in the deny rule
* P3 = P1 and not P2
* (allow S1 T1 P3)
*
* Obviously, the rule is only written if P3 is not an empty list. This goes
* for the rest of the rules as well--they are only written if the source and
* target exist.
*
* The remaining rules will only involve the common permissions
* P4 = P1 and P2
*
* Next, write the allow rule for any types in S1 that are not in S2
* S3 = S1 and not S2
* (allow S3 T1 P4)
*
* Finally, write any allow rules needed to cover the types in T1 that are
* not in T2. Since, T1 and T2 might be "self", "notself", or "other", this
* requires more complicated handling. Any rule with "self" will not match
* a rule with either "notself" or "other".
*
* if (T1 is self and T2 is self) or (T1 is notself and T2 is notself) then
* Nothing more needs to be done.
*
* The rest of the rules will depend on the intersection of S1 and S2
* which cannot be the empty set since the allow and deny rules match.
* S4 = S1 and S2
*
* if T1 is notself or T1 is other or T2 is notself or T2 is other then
* if T1 is notself then
* if T2 is other then
* T = ALL and not S2
* (allow S4 T P4)
* else [T2 is not self, notself, or other]
* S5 = S4 and not T2
* S6 = S4 and T2
* TA = ALL and not T2
* TB = TA and not S4
* (allow S6 TA P4)
* (allow S5 TB P4)
* if cardinality(S5) > 1 then
* (allow S5 other P4)
* else if T1 is other then
* (allow S3 S4 P4)
* if T2 is notself then
* [Nothing else is needed]
* else if T2 is other then
* (allow S4 S3 P4)
* else [T2 is not self, notself, or other]
* S5 = S4 and not T2
* S6 = S4 and T2
* TC = S1 and not T2
* TD = S3 and not T2
* (allow S6 TC P4)
* (allow S5 TD P4)
* if cardinality(S5) > 1 then
* (allow S5 other P4)
* else [T1 is not self, notself, or other]
* S8 = S4 and T1
* (allow S8 self P4)
* if T2 is notself then
* [Nothing else is needed]
* else [T2 is other]
* T = T1 and not S2
* (allow S4 T P4)
* else [Neither T1 nor T2 are notself or other]
* if T1 is self and T2 is not self then
* S5 = S4 and not T2
* (allow S5 self P4)
* else if T1 is not self and T2 is self then
* S7 = S4 and not T1
* S8 = S4 and T1
* T8 = T1 and not S4
* (allow S7 T1 P4)
* (allow S8 T8 P4)
* if cardinality(S8) > 1 then
* (allow S8 other P4)
* else [Neither T1 nor T2 is self]
* T3 = T1 and not T2
* (allow S4 T3 P4)
*/
static int cil_perm_match(const struct cil_perm *p1, const struct cil_list *pl2)
{
struct cil_list_item *curr;
cil_list_for_each(curr, pl2) {
struct cil_perm *p = curr->data;
if (p == p1) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int cil_class_perm_match(const struct cil_class *c1, const struct cil_perm *p1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
cil_list_for_each(curr, cpl2) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
if (cp->class == c1) {
if (cil_perm_match(p1, cp->perms)) {
return CIL_TRUE;
}
}
} else { /* MAP */
struct cil_list_item *p;
cil_list_for_each(p, cp->perms) {
struct cil_perm *cmp = p->data;
if (cil_class_perm_match(c1, p1, cmp->classperms)) {
return CIL_TRUE;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
if (cil_class_perm_match(c1, p1, cp->classperms)) {
return CIL_TRUE;
}
}
}
return CIL_FALSE;
}
static int cil_classperms_match_any(const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
cil_list_for_each(curr, cp1->perms) {
struct cil_perm *perm = curr->data;
if (cil_class_perm_match(cp1->class, perm, cpl2)) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
int cil_classperms_list_match_any(const struct cil_list *cpl1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
if (!cpl1 || !cpl2) {
return (!cpl1 && !cpl2) ? CIL_TRUE : CIL_FALSE;
}
cil_list_for_each(curr, cpl1) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
if (cil_classperms_match_any(cp, cpl2)) {
return CIL_TRUE;
}
} else { /* MAP */
struct cil_list_item *p;
cil_list_for_each(p, cp->perms) {
struct cil_perm *cmp = p->data;
if (cil_classperms_list_match_any(cmp->classperms, cpl2)) {
return CIL_TRUE;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
if (cil_classperms_list_match_any(cp->classperms, cpl2)) {
return CIL_TRUE;
}
}
}
return CIL_FALSE;
}
static int cil_classperms_match_all(const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
cil_list_for_each(curr, cp1->perms) {
struct cil_perm *perm = curr->data;
if (!cil_class_perm_match(cp1->class, perm, cpl2)) {
return CIL_FALSE;
}
}
return CIL_TRUE;
}
int cil_classperms_list_match_all(const struct cil_list *cpl1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
if (!cpl1 || !cpl2) {
return (!cpl1 && !cpl2) ? CIL_TRUE : CIL_FALSE;
}
cil_list_for_each(curr, cpl1) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
if (!cil_classperms_match_all(cp, cpl2)) {
return CIL_FALSE;
}
} else { /* MAP */
struct cil_list_item *p;
cil_list_for_each(p, cp->perms) {
struct cil_perm *cmp = p->data;
if (!cil_classperms_list_match_all(cmp->classperms, cpl2)) {
return CIL_FALSE;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
if (!cil_classperms_list_match_all(cp->classperms, cpl2)) {
return CIL_FALSE;
}
}
}
return CIL_TRUE;
}
static void cil_classperms_copy(struct cil_classperms **new, const struct cil_classperms *old)
{
cil_classperms_init(new);
(*new)->class_str = old->class_str;
(*new)->class = old->class;
cil_copy_list(old->perm_strs, &(*new)->perm_strs);
cil_copy_list(old->perms, &(*new)->perms);
}
static void cil_classperms_set_copy(struct cil_classperms_set **new, const struct cil_classperms_set *old)
{
cil_classperms_set_init(new);
(*new)->set_str = old->set_str;
(*new)->set = old->set;
}
void cil_classperms_list_copy(struct cil_list **new, const struct cil_list *old)
{
struct cil_list_item *curr;
if (!new) {
return;
}
if (!old) {
*new = NULL;
return;
}
cil_list_init(new, CIL_LIST);
cil_list_for_each(curr, old) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *new_cp;
cil_classperms_copy(&new_cp, curr->data);
cil_list_append(*new, CIL_CLASSPERMS, new_cp);
} else { /* SET */
struct cil_classperms_set *new_cps;
cil_classperms_set_copy(&new_cps, curr->data);
cil_list_append(*new, CIL_CLASSPERMS_SET, new_cps);
}
}
if (cil_list_is_empty(*new)) {
cil_list_destroy(new, CIL_FALSE);
}
}
/* Append cp1 and cpl2 to result */
static void cil_classperms_and(struct cil_list **result, const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_classperms *new_cp = NULL;
struct cil_list_item *curr;
if (cil_classperms_match_all(cp1, cpl2)) {
cil_classperms_copy(&new_cp, cp1);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
return;
}
cil_list_for_each(curr, cp1->perms) {
struct cil_perm *perm = curr->data;
if (cil_class_perm_match(cp1->class, perm, cpl2)) {
if (new_cp == NULL) {
cil_classperms_init(&new_cp);
new_cp->class_str = cp1->class_str;
new_cp->class = cp1->class;
cil_list_init(&new_cp->perm_strs, CIL_PERM);
cil_list_init(&new_cp->perms, CIL_PERM);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
}
cil_list_append(new_cp->perm_strs, CIL_STRING, perm->datum.fqn);
cil_list_append(new_cp->perms, CIL_DATUM, perm);
}
}
}
/* Append cp1 and cpl2 to result */
static void cil_classperms_map_and(struct cil_list **result, const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_classperms *new_cp = NULL;
struct cil_list_item *p;
cil_list_for_each(p, cp1->perms) {
struct cil_perm *map_perm = p->data;
if (cil_classperms_list_match_all(map_perm->classperms, cpl2)) {
if (new_cp == NULL) {
cil_classperms_init(&new_cp);
new_cp->class_str = cp1->class_str;
new_cp->class = cp1->class;
cil_list_init(&new_cp->perm_strs, CIL_PERM);
cil_list_init(&new_cp->perms, CIL_PERM);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
}
cil_list_append(new_cp->perm_strs, CIL_STRING, map_perm->datum.fqn);
cil_list_append(new_cp->perms, CIL_DATUM, map_perm);
} else {
struct cil_list *new_cpl = NULL;
cil_classperms_list_and(&new_cpl, map_perm->classperms, cpl2);
if (new_cpl) {
struct cil_list_item *i;
cil_list_for_each(i, new_cpl) {
cil_list_append(*result, i->flavor, i->data);
}
cil_list_destroy(&new_cpl, CIL_FALSE);
}
}
}
}
/* Append cps1 and cpl2 to result */
static void cil_classperms_set_and(struct cil_list **result, const struct cil_classperms_set *cps1, const struct cil_list *cpl2)
{
struct cil_classpermission *cp = cps1->set;
if (cil_classperms_list_match_all(cp->classperms, cpl2)) {
struct cil_classperms_set *new_cps;
cil_classperms_set_copy(&new_cps, cps1);
cil_list_append(*result, CIL_CLASSPERMS_SET, new_cps);
} else {
struct cil_list *new_cpl;
cil_classperms_list_and(&new_cpl, cp->classperms, cpl2);
if (new_cpl) {
struct cil_list_item *i;
cil_list_for_each(i, new_cpl) {
cil_list_append(*result, i->flavor, i->data);
}
cil_list_destroy(&new_cpl, CIL_FALSE);
}
}
}
/* result = cpl1 and cpl2 */
void cil_classperms_list_and(struct cil_list **result, const struct cil_list *cpl1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
if (!result) {
return;
}
if (!cpl1 || !cpl2) {
*result = NULL;
return;
}
if (cil_classperms_list_match_all(cpl1, cpl2)) {
cil_classperms_list_copy(result, cpl1);
return;
}
cil_list_init(result, CIL_LIST);
cil_list_for_each(curr, cpl1) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
cil_classperms_and(result, cp, cpl2);
} else { /* MAP */
cil_classperms_map_and(result, cp, cpl2);
}
} else { /* SET */
struct cil_classperms_set *cps = curr->data;
cil_classperms_set_and(result, cps, cpl2);
}
}
if (cil_list_is_empty(*result)) {
cil_list_destroy(result, CIL_FALSE);
}
}
/* Append cp1 and not cpl2 to result */
static void cil_classperms_andnot(struct cil_list **result, const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_classperms *new_cp = NULL;
struct cil_list_item *curr;
if (!cil_classperms_match_any(cp1, cpl2)) {
cil_classperms_copy(&new_cp, cp1);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
return;
}
cil_list_for_each(curr, cp1->perms) {
struct cil_perm *perm = curr->data;
if (!cil_class_perm_match(cp1->class, perm, cpl2)) {
if (new_cp == NULL) {
cil_classperms_init(&new_cp);
new_cp->class_str = cp1->class_str;
new_cp->class = cp1->class;
cil_list_init(&new_cp->perm_strs, CIL_PERM);
cil_list_init(&new_cp->perms, CIL_PERM);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
}
cil_list_append(new_cp->perm_strs, CIL_STRING, perm->datum.fqn);
cil_list_append(new_cp->perms, CIL_DATUM, perm);
}
}
}
/* Append cp1 and not cpl2 to result */
static void cil_classperms_map_andnot(struct cil_list **result, const struct cil_classperms *cp1, const struct cil_list *cpl2)
{
struct cil_classperms *new_cp = NULL;
struct cil_list_item *p;
cil_list_for_each(p, cp1->perms) {
struct cil_perm *map_perm = p->data;
if (!cil_classperms_list_match_any(map_perm->classperms, cpl2)) {
if (new_cp == NULL) {
cil_classperms_init(&new_cp);
new_cp->class_str = cp1->class_str;
new_cp->class = cp1->class;
cil_list_init(&new_cp->perm_strs, CIL_PERM);
cil_list_init(&new_cp->perms, CIL_PERM);
cil_list_append(*result, CIL_CLASSPERMS, new_cp);
}
cil_list_append(new_cp->perm_strs, CIL_STRING, map_perm->datum.fqn);
cil_list_append(new_cp->perms, CIL_DATUM, map_perm);
} else {
struct cil_list *new_cpl = NULL;
cil_classperms_list_andnot(&new_cpl, map_perm->classperms, cpl2);
if (new_cpl) {
struct cil_list_item *i;
cil_list_for_each(i, new_cpl) {
cil_list_append(*result, i->flavor, i->data);
}
cil_list_destroy(&new_cpl, CIL_FALSE);
}
}
}
}
/* Append cps1 and not cpl2 to result */
static void cil_classperms_set_andnot(struct cil_list **result, const struct cil_classperms_set *cps1, const struct cil_list *cpl2)
{
struct cil_classpermission *cp = cps1->set;
if (!cil_classperms_list_match_any(cp->classperms, cpl2)) {
struct cil_classperms_set *new_cps;
cil_classperms_set_copy(&new_cps, cps1);
cil_list_append(*result, CIL_CLASSPERMS_SET, new_cps);
} else {
struct cil_list *new_cpl;
cil_classperms_list_andnot(&new_cpl, cp->classperms, cpl2);
if (new_cpl) {
struct cil_list_item *i;
cil_list_for_each(i, new_cpl) {
cil_list_append(*result, i->flavor, i->data);
}
cil_list_destroy(&new_cpl, CIL_FALSE);
}
}
}
/* result = cpl1 and not cpl2 */
void cil_classperms_list_andnot(struct cil_list **result, const struct cil_list *cpl1, const struct cil_list *cpl2)
{
struct cil_list_item *curr;
if (!result) {
return;
}
if (!cpl1) {
*result = NULL;
return;
}
if (!cpl2 || !cil_classperms_list_match_any(cpl1, cpl2)) {
cil_classperms_list_copy(result, cpl1);
return;
}
cil_list_init(result, CIL_LIST);
cil_list_for_each(curr, cpl1) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
cil_classperms_andnot(result, cp, cpl2);
} else { /* MAP */
cil_classperms_map_andnot(result, cp, cpl2);
}
} else { /* SET */
struct cil_classperms_set *cps = curr->data;
cil_classperms_set_andnot(result, cps, cpl2);
}
}
if (cil_list_is_empty(*result)) {
cil_list_destroy(result, CIL_FALSE);
}
}
static int cil_datum_cardinality(const struct cil_symtab_datum *d)
{
if (!d) {
return 0;
}
if (FLAVOR(d) != CIL_TYPEATTRIBUTE) {
return 1;
} else {
struct cil_typeattribute *a = (struct cil_typeattribute *)d;
return ebitmap_cardinality(a->types);
}
}
/* result = ALL and not d2 */
static int cil_datum_not(ebitmap_t *result, const struct cil_symtab_datum *d, int max)
{
int rc = SEPOL_OK;
if (FLAVOR(d) != CIL_TYPEATTRIBUTE) {
struct cil_type *t = (struct cil_type *)d;
ebitmap_t e;
ebitmap_init(&e);
rc = ebitmap_set_bit(&e, t->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(&e);
goto exit;
}
ebitmap_init(result);
rc = ebitmap_not(result, &e, max);
if (rc != SEPOL_OK) {
ebitmap_destroy(&e);
ebitmap_destroy(result);
goto exit;
}
ebitmap_destroy(&e);
} else {
struct cil_typeattribute *a = (struct cil_typeattribute *)d;
ebitmap_init(result);
rc = ebitmap_not(result, a->types, max);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
exit:
return rc;
}
/* result = d1 and d2 */
static int cil_datums_and(ebitmap_t *result, const struct cil_symtab_datum *d1, const struct cil_symtab_datum *d2)
{
int rc = SEPOL_OK;
enum cil_flavor f1 = FLAVOR(d1);
enum cil_flavor f2 = FLAVOR(d2);
if (f1 != CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
ebitmap_init(result);
if (t1->value == t2->value) {
rc = ebitmap_set_bit(result, t1->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
} else if (f1 == CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
ebitmap_init(result);
if (ebitmap_get_bit(a1->types, t2->value)) {
rc = ebitmap_set_bit(result, t2->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
} else if (f1 != CIL_TYPEATTRIBUTE && f2 == CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
ebitmap_init(result);
if (ebitmap_get_bit(a2->types, t1->value)) {
rc = ebitmap_set_bit(result, t1->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
} else {
/* Both are attributes */
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
rc = ebitmap_and(result, a1->types, a2->types);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
exit:
return rc;
}
/* result = d1 and not d2 */
static int cil_datums_andnot(ebitmap_t *result, const struct cil_symtab_datum *d1, const struct cil_symtab_datum *d2)
{
int rc = SEPOL_OK;
enum cil_flavor f1 = FLAVOR(d1);
enum cil_flavor f2 = FLAVOR(d2);
if (f1 != CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
ebitmap_init(result);
if (t1->value != t2->value) {
rc = ebitmap_set_bit(result, t1->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
} else if (f1 == CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
rc = ebitmap_cpy(result, a1->types);
if (rc != SEPOL_OK) {
goto exit;
}
rc = ebitmap_set_bit(result, t2->value, 0);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
} else if (f1 != CIL_TYPEATTRIBUTE && f2 == CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
ebitmap_init(result);
if (!ebitmap_get_bit(a2->types, t1->value)) {
rc = ebitmap_set_bit(result, t1->value, 1);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
} else {
/* Both are attributes */
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
rc = ebitmap_andnot(result, a1->types, a2->types, a1->types->highbit);
if (rc != SEPOL_OK) {
ebitmap_destroy(result);
goto exit;
}
}
exit:
return rc;
}
static size_t num_digits(unsigned n)
{
size_t num = 1;
while (n >= 10) {
n /= 10;
num++;
}
return num;
}
static char *cil_create_new_attribute_name(unsigned num)
{
char *s1 = NULL;
char *s2 = NULL;
size_t len_num = num_digits(num);
size_t len = strlen(CIL_DENY_ATTR_PREFIX) + 1 + len_num + 1;
int rc;
if (len >= CIL_MAX_NAME_LENGTH) {
cil_log(CIL_ERR, "Name length greater than max name length of %d",
CIL_MAX_NAME_LENGTH);
goto exit;
}
s1 = cil_malloc(len);
rc = snprintf(s1, len, "%s_%u", CIL_DENY_ATTR_PREFIX, num);
if (rc < 0 || (size_t)rc >= len) {
cil_log(CIL_ERR, "Error creating new attribute name");
free(s1);
goto exit;
}
s2 = cil_strpool_add(s1);
free(s1);
exit:
return s2;
}
static struct cil_list *cil_create_and_expr_list(enum cil_flavor f1, void *v1, enum cil_flavor f2, void *v2)
{
struct cil_list *expr;
cil_list_init(&expr, CIL_TYPE);
cil_list_append(expr, CIL_OP, (void *)CIL_AND);
cil_list_append(expr, f1, v1);
cil_list_append(expr, f2, v2);
return expr;
}
static struct cil_list *cil_create_andnot_expr_list(enum cil_flavor f1, void *v1, enum cil_flavor f2, void *v2)
{
struct cil_list *expr, *sub_expr;
cil_list_init(&expr, CIL_TYPE);
cil_list_append(expr, CIL_OP, (void *)CIL_AND);
cil_list_append(expr, f1, v1);
cil_list_init(&sub_expr, CIL_TYPE);
cil_list_append(sub_expr, CIL_OP, (void *)CIL_NOT);
cil_list_append(sub_expr, f2, v2);
cil_list_append(expr, CIL_LIST, sub_expr);
return expr;
}
static struct cil_tree_node *cil_create_and_insert_node(struct cil_tree_node *prev, enum cil_flavor flavor, void *data)
{
struct cil_tree_node *new;
cil_tree_node_init(&new);
new->parent = prev->parent;
new->line = prev->line;
new->hll_offset = prev->hll_offset;
new->flavor = flavor;
new->data = data;
new->next = prev->next;
prev->next = new;
return new;
}
static int cil_create_and_insert_attribute_and_set(struct cil_db *db, struct cil_tree_node *prev, struct cil_list *str_expr, struct cil_list *datum_expr, ebitmap_t *types, struct cil_symtab_datum **d)
{
struct cil_tree_node *attr_node = NULL;
char *name;
struct cil_typeattribute *attr = NULL;
struct cil_tree_node *attrset_node = NULL;
struct cil_typeattributeset *attrset = NULL;
symtab_t *symtab = NULL;
int rc = SEPOL_ERR;
name = cil_create_new_attribute_name(db->num_types_and_attrs);
if (!name) {
goto exit;
}
cil_typeattributeset_init(&attrset);
attrset->attr_str = name;
attrset->str_expr = str_expr;
attrset->datum_expr = datum_expr;
cil_typeattribute_init(&attr);
cil_list_init(&attr->expr_list, CIL_TYPE);
cil_list_append(attr->expr_list, CIL_LIST, datum_expr);
attr->types = types;
attr->used = CIL_ATTR_AVRULE;
attr->keep = (ebitmap_cardinality(types) < db->attrs_expand_size) ? CIL_FALSE : CIL_TRUE;
attr_node = cil_create_and_insert_node(prev, CIL_TYPEATTRIBUTE, attr);
attrset_node = cil_create_and_insert_node(attr_node, CIL_TYPEATTRIBUTESET, attrset);
rc = cil_get_symtab(prev->parent, &symtab, CIL_SYM_TYPES);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_symtab_insert(symtab, name, &attr->datum, attr_node);
if (rc != SEPOL_OK) {
goto exit;
}
db->num_types_and_attrs++;
*d = &attr->datum;
return SEPOL_OK;
exit:
if (attr_node) {
cil_destroy_typeattribute(attr_node->data); // This will not destroy datum_expr
free(attr_node);
}
if (attrset_node) {
prev->next = attrset_node->next;
free(attrset_node);
}
return rc;
}
struct attr_symtab_map_data {
struct cil_symtab_datum *d;
ebitmap_t *types;
};
static int cil_check_attribute_in_symtab(__attribute__((unused))hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct attr_symtab_map_data *data = args;
if (FLAVOR(d) == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = (struct cil_typeattribute *)d;
if (ebitmap_cmp(data->types, attr->types)) {
data->d = d;
}
}
return SEPOL_OK;
}
static struct cil_symtab_datum *cil_check_for_previously_defined_attribute(struct cil_db *db, ebitmap_t *types, struct cil_symtab_datum *d)
{
symtab_t *local_symtab, *root_symtab;
struct attr_symtab_map_data data;
int rc;
data.d = NULL;
data.types = types;
local_symtab = d->symtab;
root_symtab = &((struct cil_root *)db->ast->root->data)->symtab[CIL_SYM_TYPES];
if (local_symtab != root_symtab) {
rc = cil_symtab_map(local_symtab, cil_check_attribute_in_symtab, &data);
if (rc != SEPOL_OK) {
return NULL;
}
}
if (!data.d) {
rc = cil_symtab_map(root_symtab, cil_check_attribute_in_symtab, &data);
if (rc != SEPOL_OK) {
return NULL;
}
}
return data.d;
}
static int cil_create_attribute_all_and_not_d(struct cil_db *db, struct cil_symtab_datum *d, struct cil_symtab_datum **d3)
{
struct cil_list *str_expr;
struct cil_list *datum_expr;
ebitmap_t *types;
int rc;
*d3 = NULL;
if (!d) {
return SEPOL_ERR;
}
str_expr = cil_create_andnot_expr_list(CIL_OP, (void *)CIL_ALL, CIL_STRING, d->fqn);
datum_expr = cil_create_andnot_expr_list(CIL_OP, (void *)CIL_ALL, CIL_DATUM, d);
types = cil_malloc(sizeof(*types));
rc = cil_datum_not(types, d, db->num_types);
if (rc != SEPOL_OK) {
goto exit;
}
if (ebitmap_is_empty(types)) {
rc = SEPOL_OK;
goto exit;
}
if (ebitmap_cardinality(types) == 1) {
unsigned i = ebitmap_highest_set_bit(types);
*d3 = DATUM(db->val_to_type[i]);
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
*d3 = cil_check_for_previously_defined_attribute(db, types, d);
if (*d3) {
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
rc = cil_create_and_insert_attribute_and_set(db, NODE(d), str_expr, datum_expr, types, d3);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_list_destroy(&str_expr, CIL_FALSE);
cil_list_destroy(&datum_expr, CIL_FALSE);
free(types);
return rc;
}
static int cil_create_attribute_d1_and_not_d2(struct cil_db *db, struct cil_symtab_datum *d1, struct cil_symtab_datum *d2, struct cil_symtab_datum **d3)
{
struct cil_list *str_expr;
struct cil_list *datum_expr;
ebitmap_t *types;
int rc;
if (!d2) {
*d3 = d1;
return SEPOL_OK;
}
*d3 = NULL;
if (!d1 || d1 == d2) {
return SEPOL_OK;
}
str_expr = cil_create_andnot_expr_list(CIL_STRING, d1->fqn, CIL_STRING, d2->fqn);
datum_expr = cil_create_andnot_expr_list(CIL_DATUM, d1, CIL_DATUM, d2);
types = cil_malloc(sizeof(*types));
rc = cil_datums_andnot(types, d1, d2);
if (rc != SEPOL_OK) {
goto exit;
}
if (ebitmap_is_empty(types)) {
rc = SEPOL_OK;
goto exit;
}
if (ebitmap_cardinality(types) == 1) {
unsigned i = ebitmap_highest_set_bit(types);
*d3 = DATUM(db->val_to_type[i]);
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
*d3 = cil_check_for_previously_defined_attribute(db, types, d1);
if (*d3) {
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
rc = cil_create_and_insert_attribute_and_set(db, NODE(d1), str_expr, datum_expr, types, d3);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_list_destroy(&str_expr, CIL_FALSE);
cil_list_destroy(&datum_expr, CIL_FALSE);
free(types);
return rc;
}
static int cil_create_attribute_d1_and_d2(struct cil_db *db, struct cil_symtab_datum *d1, struct cil_symtab_datum *d2, struct cil_symtab_datum **d3)
{
struct cil_list *str_expr;
struct cil_list *datum_expr;
ebitmap_t *types;
int rc;
if (d1 == d2) {
*d3 = d1;
return SEPOL_OK;
}
*d3 = NULL;
if (!d1 || !d2) {
return SEPOL_OK;
}
str_expr = cil_create_and_expr_list(CIL_STRING, d1->fqn, CIL_STRING, d2->fqn);
datum_expr = cil_create_and_expr_list(CIL_DATUM, d1, CIL_DATUM, d2);
types = cil_malloc(sizeof(*types));
rc = cil_datums_and(types, d1, d2);
if (rc != SEPOL_OK) {
goto exit;
}
if (ebitmap_is_empty(types)) {
rc = SEPOL_OK;
goto exit;
}
if (ebitmap_cardinality(types) == 1) {
unsigned i = ebitmap_highest_set_bit(types);
*d3 = DATUM(db->val_to_type[i]);
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
*d3 = cil_check_for_previously_defined_attribute(db, types, d1);
if (*d3) {
ebitmap_destroy(types);
rc = SEPOL_OK;
goto exit;
}
rc = cil_create_and_insert_attribute_and_set(db, NODE(d1), str_expr, datum_expr, types, d3);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_list_destroy(&str_expr, CIL_FALSE);
cil_list_destroy(&datum_expr, CIL_FALSE);
free(types);
return rc;
}
static struct cil_avrule *cil_create_avrule(struct cil_symtab_datum *src, struct cil_symtab_datum *tgt, struct cil_list *classperms)
{
struct cil_avrule *new;
cil_avrule_init(&new);
new->is_extended = CIL_FALSE;
new->rule_kind = CIL_AVRULE_ALLOWED;
new->src_str = src->name;
new->src = src;
new->tgt_str = tgt->name;
new->tgt = tgt;
new->perms.classperms = classperms;
return new;
}
static struct cil_tree_node *cil_create_and_add_avrule(struct cil_tree_node *curr, struct cil_symtab_datum *src, struct cil_symtab_datum *tgt, struct cil_list *classperms)
{
struct cil_avrule *new_avrule;
struct cil_list *new_cp_list;
if (!src || !tgt) {
return curr;
}
cil_classperms_list_copy(&new_cp_list, classperms);
new_avrule = cil_create_avrule(src, tgt, new_cp_list);
return cil_create_and_insert_node(curr, CIL_AVRULE, new_avrule);
}
static int cil_remove_permissions_from_special_rule(struct cil_db *db, struct cil_tree_node *curr, struct cil_symtab_datum *s1, struct cil_symtab_datum *t1, struct cil_symtab_datum *s2, struct cil_symtab_datum *t2, struct cil_list *p4, struct cil_symtab_datum *s3, struct cil_symtab_datum *s4)
{
int rc;
if (t1 == DATUM(db->notselftype)) {
if (t2 == DATUM(db->othertype)) {
struct cil_symtab_datum *t;
rc = cil_create_attribute_all_and_not_d(db, s2, &t);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s4, t, p4);
} else {
struct cil_symtab_datum *s5, *s6, *ta, *tb;
rc = cil_create_attribute_d1_and_not_d2(db, s4, t2, &s5);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_d2(db, s4, t2, &s6);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_all_and_not_d(db, t2, &ta);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_not_d2(db, ta, s4, &tb);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s6, ta, p4);
curr = cil_create_and_add_avrule(curr, s5, tb, p4);
if (cil_datum_cardinality(s5) > 1) {
curr = cil_create_and_add_avrule(curr, s5, DATUM(db->othertype), p4);
}
}
} else if (t1 == DATUM(db->othertype)) {
curr = cil_create_and_add_avrule(curr, s3, s4, p4);
if (t2 == DATUM(db->notselftype)) {
/* Nothing else is needed */
} else if (t2 == DATUM(db->othertype)) {
curr = cil_create_and_add_avrule(curr, s4, s3, p4);
} else {
struct cil_symtab_datum *s5, *s6, *tc, *td;
rc = cil_create_attribute_d1_and_not_d2(db, s4, t2, &s5);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_d2(db, s4, t2, &s6);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_not_d2(db, s1, t2, &tc);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_not_d2(db, s3, t2, &td);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s6, tc, p4);
curr = cil_create_and_add_avrule(curr, s5, td, p4);
if (cil_datum_cardinality(s5) > 1) {
curr = cil_create_and_add_avrule(curr, s5, DATUM(db->othertype), p4);
}
}
} else {
struct cil_symtab_datum *s8;
rc = cil_create_attribute_d1_and_d2(db, s4, t1, &s8);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s8, DATUM(db->selftype), p4);
if (t2 == DATUM(db->notselftype)) {
/* Nothing else is needed */
} else { /* t2 == DATUM(db->othertype) */
struct cil_symtab_datum *t;
rc = cil_create_attribute_d1_and_not_d2(db, t1, s2, &t);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s4, t, p4);
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_remove_permissions_from_rule(struct cil_db *db, struct cil_tree_node *allow_node, const struct cil_tree_node *deny_node)
{
struct cil_avrule *allow_rule = allow_node->data;
struct cil_deny_rule *deny_rule = deny_node->data;
struct cil_symtab_datum *s1 = allow_rule->src;
struct cil_symtab_datum *t1 = allow_rule->tgt;
struct cil_list *p1 = allow_rule->perms.classperms;
struct cil_symtab_datum *s2 = deny_rule->src;
struct cil_symtab_datum *t2 = deny_rule->tgt;
struct cil_list *p2 = deny_rule->classperms;
struct cil_list *p3 = NULL;
struct cil_list *p4 = NULL;
struct cil_symtab_datum *s3, *s4;
struct cil_tree_node *curr = allow_node;
int rc;
cil_classperms_list_andnot(&p3, p1, p2);
if (!cil_list_is_empty(p3)) {;
curr = cil_create_and_add_avrule(curr, s1, t1, p3);
}
cil_destroy_classperms_list(&p3);
p3 = NULL;
cil_classperms_list_and(&p4, p1, p2);
if (cil_list_is_empty(p4)) {
cil_tree_log(allow_node, CIL_ERR, "Allow rule did not match deny rule: No matching class and permissions");
cil_tree_log((struct cil_tree_node *)deny_node, CIL_ERR, "Deny rule");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_create_attribute_d1_and_not_d2(db, s1, s2, &s3);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s3, t1, p4);
if ((t1 == DATUM(db->selftype) && t2 == DATUM(db->selftype)) ||
(t1 == DATUM(db->notselftype) && t2 == DATUM(db->notselftype))) {
/* Nothing more needs to be done */
rc = SEPOL_OK;
goto exit;
}
rc = cil_create_attribute_d1_and_d2(db, s1, s2, &s4);
if (rc != SEPOL_OK) {
goto exit;
}
if (t1 == DATUM(db->notselftype) || t1 == DATUM(db->othertype) ||
t2 == DATUM(db->notselftype) || t2 == DATUM(db->othertype)) {
rc = cil_remove_permissions_from_special_rule(db, curr, s1, t1, s2, t2, p4, s3, s4);
goto exit;
}
if (t1 == DATUM(db->selftype) && t2 != DATUM(db->selftype)) {
struct cil_symtab_datum *s5;
rc = cil_create_attribute_d1_and_not_d2(db, s4, t2, &s5);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s5, DATUM(db->selftype), p4);
} else if (t1 != DATUM(db->selftype) && t2 == DATUM(db->selftype)) {
struct cil_symtab_datum *s7, *s8, *t8;
rc = cil_create_attribute_d1_and_not_d2(db, s4, t1, &s7);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_d2(db, s4, t1, &s8);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_create_attribute_d1_and_not_d2(db, t1, s4, &t8);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s7, t1, p4);
curr = cil_create_and_add_avrule(curr, s8, t8, p4);
if (cil_datum_cardinality(s8) > 1) {
curr = cil_create_and_add_avrule(curr, s8, DATUM(db->othertype), p4);
}
} else {
struct cil_symtab_datum *t3;
rc = cil_create_attribute_d1_and_not_d2(db, t1, t2, &t3);
if (rc != SEPOL_OK) {
goto exit;
}
curr = cil_create_and_add_avrule(curr, s4, t3, p4);
}
exit:
if (p4) {
cil_destroy_classperms_list(&p4);
}
return rc;
}
static int cil_find_matching_allow_rules(struct cil_list *matching, struct cil_tree_node *start, struct cil_tree_node *deny_node)
{
struct cil_deny_rule *deny_rule = deny_node->data;
struct cil_avrule target;
target.rule_kind = CIL_AVRULE_ALLOWED;
target.is_extended = CIL_FALSE;
target.src = deny_rule->src;
target.tgt = deny_rule->tgt;
target.perms.classperms = deny_rule->classperms;
return cil_find_matching_avrule_in_ast(start, CIL_AVRULE, &target, matching, CIL_FALSE);
}
static int cil_process_deny_rule(struct cil_db *db, struct cil_tree_node *start, struct cil_tree_node *deny_node)
{
struct cil_list *matching;
struct cil_list_item *item;
int rc;
cil_list_init(&matching, CIL_NODE);
rc = cil_find_matching_allow_rules(matching, start, deny_node);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_for_each(item, matching) {
struct cil_tree_node *allow_node = item->data;
rc = cil_remove_permissions_from_rule(db, allow_node, deny_node);
cil_tree_node_remove(allow_node);
if (rc != SEPOL_OK) {
goto exit;
}
}
exit:
cil_list_destroy(&matching, CIL_FALSE);
return rc;
}
static int cil_process_deny_rules(struct cil_db *db, struct cil_tree_node *start, struct cil_list *deny_rules)
{
struct cil_list_item *item;
int rc = SEPOL_OK;
cil_list_for_each(item, deny_rules) {
struct cil_tree_node *deny_node = item->data;
rc = cil_process_deny_rule(db, start, deny_node);
if (rc != SEPOL_OK) {
goto exit;
}
cil_tree_node_remove(deny_node);
}
exit:
return rc;
}
static int __cil_find_deny_rules(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_list *deny_rules = extra_args;
if (node->flavor == CIL_BLOCK) {
struct cil_block *block = node->data;
if (block->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
} else if (node->flavor == CIL_MACRO) {
*finished = CIL_TREE_SKIP_HEAD;
} else if (node->flavor == CIL_DENY_RULE) {
cil_list_append(deny_rules, CIL_DENY_RULE, node);
}
return SEPOL_OK;
}
int cil_process_deny_rules_in_ast(struct cil_db *db)
{
struct cil_tree_node *start;
struct cil_list *deny_rules;
int rc = SEPOL_ERR;
cil_list_init(&deny_rules, CIL_DENY_RULE);
if (!db) {
cil_log(CIL_ERR, "No CIL db provided to process deny rules\n");
goto exit;
}
start = db->ast->root;
rc = cil_tree_walk(start, __cil_find_deny_rules, NULL, NULL, deny_rules);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "An error occurred while getting deny rules\n");
goto exit;
}
rc = cil_process_deny_rules(db, start, deny_rules);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "An error occurred while processing deny rules\n");
goto exit;
}
exit:
cil_list_destroy(&deny_rules, CIL_FALSE);
return rc;
}
libsepol-3.8.1/cil/src/cil_deny.h000066400000000000000000000033131476211737200166430ustar00rootroot00000000000000/*
* This file is public domain software, i.e. not copyrighted.
*
* Warranty Exclusion
* ------------------
* You agree that this software is a non-commercially developed program
* that may contain "bugs" (as that term is used in the industry) and
* that it may not function as intended. The software is licensed
* "as is". NSA makes no, and hereby expressly disclaims all, warranties,
* express, implied, statutory, or otherwise with respect to the software,
* including noninfringement and the implied warranties of merchantability
* and fitness for a particular purpose.
*
* Limitation of Liability
*-----------------------
* In no event will NSA be liable for any damages, including loss of data,
* lost profits, cost of cover, or other special, incidental, consequential,
* direct or indirect damages arising from the software or the use thereof,
* however caused and on any theory of liability. This limitation will apply
* even if NSA has been advised of the possibility of such damage. You
* acknowledge that this is a reasonable allocation of risk.
*
* Original author: James Carter
*/
#ifndef CIL_DENY_H_
#define CIL_DENY_H_
int cil_classperms_list_match_any(const struct cil_list *cpl1, const struct cil_list *cpl2);
int cil_classperms_list_match_all(const struct cil_list *cpl1, const struct cil_list *cpl2);
void cil_classperms_list_copy(struct cil_list **new, const struct cil_list *old);
void cil_classperms_list_and(struct cil_list **result, const struct cil_list *cpl1, const struct cil_list *cpl2);
void cil_classperms_list_andnot(struct cil_list **result, const struct cil_list *cpl1, const struct cil_list *cpl2);
int cil_process_deny_rules_in_ast(struct cil_db *db);
#endif /* CIL_DENY_H_ */
libsepol-3.8.1/cil/src/cil_find.c000066400000000000000000000365141476211737200166300ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "cil_internal.h"
#include "cil_find.h"
#include "cil_flavor.h"
#include "cil_list.h"
#include "cil_log.h"
#include "cil_symtab.h"
struct cil_args_find {
enum cil_flavor flavor;
void *target;
struct cil_list *matching;
int match_self;
};
static int cil_type_match_any(struct cil_symtab_datum *d1, struct cil_symtab_datum *d2)
{
enum cil_flavor f1 = FLAVOR(d1);
enum cil_flavor f2 = FLAVOR(d2);
if (f1 != CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
if (t1->value == t2->value) {
return CIL_TRUE;
}
} else if (f1 == CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *a = (struct cil_typeattribute *)d1;
struct cil_type *t = (struct cil_type *)d2;
if (ebitmap_get_bit(a->types, t->value)) {
return CIL_TRUE;
}
} else if (f1 != CIL_TYPEATTRIBUTE && f2 == CIL_TYPEATTRIBUTE) {
struct cil_type *t = (struct cil_type *)d1;
struct cil_typeattribute *a = (struct cil_typeattribute *)d2;
if (ebitmap_get_bit(a->types, t->value)) {
return CIL_TRUE;
}
} else {
/* Both are attributes */
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
if (d1 == d2) {
return CIL_TRUE;
} else if (ebitmap_match_any(a1->types, a2->types)) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int cil_type_matches(ebitmap_t *matches, struct cil_symtab_datum *d1, struct cil_symtab_datum *d2)
{
int rc = SEPOL_OK;
enum cil_flavor f1 = FLAVOR(d1);
enum cil_flavor f2 = FLAVOR(d2);
if (f1 == CIL_TYPEATTRIBUTE && f2 == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *a1 = (struct cil_typeattribute *)d1;
struct cil_typeattribute *a2 = (struct cil_typeattribute *)d2;
rc = ebitmap_and(matches, a1->types, a2->types);
} else {
ebitmap_init(matches);
if (f1 != CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_type *t1 = (struct cil_type *)d1;
struct cil_type *t2 = (struct cil_type *)d2;
if (t1->value == t2->value) {
rc = ebitmap_set_bit(matches, t1->value, 1);
}
} else if (f1 == CIL_TYPEATTRIBUTE && f2 != CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *a = (struct cil_typeattribute *)d1;
struct cil_type *t = (struct cil_type *)d2;
if (ebitmap_get_bit(a->types, t->value)) {
rc = ebitmap_set_bit(matches, t->value, 1);
}
} else { // f1 != CIL_TYPEATTRIBUTE && f2 == CIL_TYPEATTRIBUTE
struct cil_type *t = (struct cil_type *)d1;
struct cil_typeattribute *a = (struct cil_typeattribute *)d2;
if (ebitmap_get_bit(a->types, t->value)) {
rc = ebitmap_set_bit(matches, t->value, 1);
}
}
if (rc != SEPOL_OK) {
ebitmap_destroy(matches);
}
}
return rc;
}
/* s1 is the src type that is matched with a self
* s2, and t2 are the source and type of the other rule
* Assumes there is a match between s1 and s2
*/
static int cil_self_match_any(struct cil_symtab_datum *s1, struct cil_symtab_datum *s2, struct cil_symtab_datum *t2)
{
int rc;
if (FLAVOR(s1) != CIL_TYPEATTRIBUTE) {
rc = cil_type_match_any(s1, t2);
} else {
struct cil_typeattribute *a = (struct cil_typeattribute *)s1;
ebitmap_t map;
rc = cil_type_matches(&map, s2, t2);
if (rc < 0) {
return rc;
}
if (ebitmap_is_empty(&map)) {
return CIL_FALSE;
}
rc = ebitmap_match_any(&map, a->types);
ebitmap_destroy(&map);
}
return rc;
}
/* s1 is the src type that is matched with a notself
* s2 and t2 are the source and type of the other rule
* Assumes there is a match between s1 and s2
*/
static int cil_notself_match_any(struct cil_symtab_datum *s1, struct cil_symtab_datum *s2, struct cil_symtab_datum *t2)
{
int rc;
ebitmap_node_t *snode, *tnode;
unsigned int s,t;
if (FLAVOR(s1) != CIL_TYPEATTRIBUTE) {
struct cil_type *ts1 = (struct cil_type *)s1;
if (FLAVOR(t2) != CIL_TYPEATTRIBUTE) {
struct cil_type *tt2 = (struct cil_type *)t2;
if (ts1->value != tt2->value) {
return CIL_TRUE;
}
} else {
struct cil_typeattribute *at2 = (struct cil_typeattribute *)t2;
ebitmap_for_each_positive_bit(at2->types, tnode, t) {
if (t != (unsigned int)ts1->value) {
return CIL_TRUE;
}
}
}
} else {
ebitmap_t smap;
rc = cil_type_matches(&smap, s1, s2);
if (rc < 0) {
return rc;
}
if (ebitmap_is_empty(&smap)) {
return CIL_FALSE;
}
if (FLAVOR(t2) != CIL_TYPEATTRIBUTE) {
struct cil_type *tt2 = (struct cil_type *)t2;
ebitmap_for_each_positive_bit(&smap, snode, s) {
if (s != (unsigned int)tt2->value) {
ebitmap_destroy(&smap);
return CIL_TRUE;
}
}
} else {
struct cil_typeattribute *at2 = (struct cil_typeattribute *)t2;
ebitmap_for_each_positive_bit(&smap, snode, s) {
ebitmap_for_each_positive_bit(at2->types, tnode, t) {
if (s != t) {
ebitmap_destroy(&smap);
return CIL_TRUE;
}
}
}
}
ebitmap_destroy(&smap);
}
return CIL_FALSE;
}
/* s1 is the src type that is matched with an other
* s2, and t2 are the source and type of the other rule
* Assumes there is a match between s1 and s2
*/
static int cil_other_match_any(struct cil_symtab_datum *s1, struct cil_symtab_datum *s2, struct cil_symtab_datum *t2)
{
int rc;
ebitmap_t smap, tmap;
ebitmap_node_t *snode, *tnode;
unsigned int s,t;
if (FLAVOR(s1) != CIL_TYPEATTRIBUTE) {
return CIL_FALSE;
}
rc = cil_type_matches(&smap, s1, s2);
if (rc < 0) {
return rc;
}
if (ebitmap_is_empty(&smap)) {
return CIL_FALSE;
}
rc = cil_type_matches(&tmap, s1, t2);
if (rc < 0) {
ebitmap_destroy(&smap);
return rc;
}
if (ebitmap_is_empty(&tmap)) {
ebitmap_destroy(&smap);
return CIL_FALSE;
}
ebitmap_for_each_positive_bit(&smap, snode, s) {
ebitmap_for_each_positive_bit(&tmap, tnode, t) {
if (s != t) {
rc = CIL_TRUE;
goto exit;
}
}
}
rc = CIL_FALSE;
exit:
ebitmap_destroy(&smap);
ebitmap_destroy(&tmap);
return rc;
}
/* s2 is the src type that is matched with an other
* Assumes there is a match between s1 and s2
* s1 is not needed, since it is known that there is a match
*/
static int cil_notself_other_match_any(struct cil_symtab_datum *s2)
{
if (FLAVOR(s2) == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *as2 = (struct cil_typeattribute *)s2;
if (ebitmap_cardinality(as2->types) > 1) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int cil_classperms_match_any(struct cil_classperms *cp1, struct cil_classperms *cp2)
{
struct cil_class *c1 = cp1->class;
struct cil_class *c2 = cp2->class;
struct cil_list_item *i1, *i2;
if (&c1->datum != &c2->datum) return CIL_FALSE;
cil_list_for_each(i1, cp1->perms) {
struct cil_perm *p1 = i1->data;
cil_list_for_each(i2, cp2->perms) {
struct cil_perm *p2 = i2->data;
if (&p1->datum == &p2->datum) return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int __cil_classperms_list_match_any(struct cil_classperms *cp1, struct cil_list *cpl2)
{
int rc;
struct cil_list_item *curr;
cil_list_for_each(curr, cpl2) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
rc = cil_classperms_match_any(cp1, cp);
if (rc == CIL_TRUE) return CIL_TRUE;
} else { /* MAP */
struct cil_list_item *i = NULL;
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
rc = __cil_classperms_list_match_any(cp1, cmp->classperms);
if (rc == CIL_TRUE) return CIL_TRUE;
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
rc = __cil_classperms_list_match_any(cp1, cp->classperms);
if (rc == CIL_TRUE) return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int cil_classperms_list_match_any(struct cil_list *cpl1, struct cil_list *cpl2)
{
int rc;
struct cil_list_item *curr;
cil_list_for_each(curr, cpl1) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
rc = __cil_classperms_list_match_any(cp, cpl2);
if (rc == CIL_TRUE) return CIL_TRUE;
} else { /* MAP */
struct cil_list_item *i = NULL;
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
rc = cil_classperms_list_match_any(cmp->classperms, cpl2);
if (rc == CIL_TRUE) return CIL_TRUE;
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
rc = cil_classperms_list_match_any(cp->classperms, cpl2);
if (rc == CIL_TRUE) return CIL_TRUE;
}
}
return CIL_FALSE;
}
static void __add_classes_from_classperms_list(struct cil_list *classperms, struct cil_list *class_list)
{
struct cil_list_item *curr;
cil_list_for_each(curr, classperms) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
cil_list_append(class_list, CIL_CLASS, cp->class);
} else { /* MAP */
struct cil_list_item *i = NULL;
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
__add_classes_from_classperms_list(cmp->classperms, class_list);
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
__add_classes_from_classperms_list(cp->classperms, class_list);
}
}
}
static int __add_classes_from_map_perms(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_list *class_list = args;
struct cil_perm *cmp = (struct cil_perm *)d;
__add_classes_from_classperms_list(cmp->classperms, class_list);
return SEPOL_OK;
}
struct cil_list *cil_expand_class(struct cil_class *class)
{
struct cil_list *class_list;
cil_list_init(&class_list, CIL_CLASS);
if (FLAVOR(class) == CIL_CLASS) {
cil_list_append(class_list, CIL_CLASS, class);
} else { /* MAP */
cil_symtab_map(&class->perms, __add_classes_from_map_perms, class_list);
}
return class_list;
}
static int cil_permissionx_match_any(struct cil_permissionx *px1, struct cil_permissionx *px2)
{
int rc = CIL_FALSE;
struct cil_list *cl1 = NULL;
struct cil_list *cl2 = NULL;
if (px1->kind != px2->kind) goto exit;
if (!ebitmap_match_any(px1->perms, px2->perms)) goto exit;
cl1 = cil_expand_class(px1->obj);
cl2 = cil_expand_class(px2->obj);
if (!cil_list_match_any(cl1, cl2)) goto exit;
rc = CIL_TRUE;
exit:
cil_list_destroy(&cl1, CIL_FALSE);
cil_list_destroy(&cl2, CIL_FALSE);
return rc;
}
static int cil_find_matching_avrule(struct cil_tree_node *node, struct cil_avrule *avrule, struct cil_avrule *target, struct cil_list *matching, int match_self)
{
int rc = SEPOL_OK;
struct cil_symtab_datum *s1 = avrule->src;
struct cil_symtab_datum *t1 = avrule->tgt;
struct cil_symtab_datum *s2 = target->src;
struct cil_symtab_datum *t2 = target->tgt;
if (match_self != CIL_TRUE && avrule == target) goto exit;
if (avrule->rule_kind != target->rule_kind) goto exit;
if (avrule->is_extended != target->is_extended) goto exit;
if (!cil_type_match_any(s1, s2)) goto exit;
if (t1->fqn == CIL_KEY_SELF) {
if (t2->fqn == CIL_KEY_SELF) {
/* The earlier check whether s1 and s2 matches is all that is needed */
rc = CIL_TRUE;
} else if (t2->fqn == CIL_KEY_NOTSELF || t2->fqn == CIL_KEY_OTHER) {
rc = CIL_FALSE;
} else {
rc = cil_self_match_any(s1, s2, t2);
}
} else if (t1->fqn == CIL_KEY_NOTSELF) {
if (t2->fqn == CIL_KEY_SELF) {
rc = CIL_FALSE;
} else if (t2->fqn == CIL_KEY_NOTSELF) {
/* The earlier check whether s1 and s2 matches is all that is needed */
rc = CIL_TRUE;
} else if (t2->fqn == CIL_KEY_OTHER) {
rc = cil_notself_other_match_any(s2);
} else {
rc = cil_notself_match_any(s1, s2, t2);
}
} else if (t1->fqn == CIL_KEY_OTHER) {
if (t2->fqn == CIL_KEY_SELF) {
rc = CIL_FALSE;
} else if (t2->fqn == CIL_KEY_NOTSELF) {
rc = cil_notself_other_match_any(s1);
} else if (t2->fqn == CIL_KEY_OTHER) {
/* The earlier check whether s1 and s2 matches is all that is needed */
rc = CIL_TRUE;
} else {
rc = cil_other_match_any(s1, s2, t2);
}
} else {
if (t2->fqn == CIL_KEY_SELF) {
rc = cil_self_match_any(s2, s1, t1);
} else if (t2->fqn == CIL_KEY_NOTSELF) {
rc = cil_notself_match_any(s2, s1, t1);
} else if (t2->fqn == CIL_KEY_OTHER) {
rc = cil_other_match_any(s2, s1, t1);
} else {
rc = cil_type_match_any(t1, t2);
}
}
if (rc < 0) {
goto exit;
} else if (rc == CIL_FALSE) {
rc = SEPOL_OK;
goto exit;
}
if (!target->is_extended) {
if (cil_classperms_list_match_any(avrule->perms.classperms, target->perms.classperms)) {
cil_list_append(matching, CIL_NODE, node);
}
} else {
if (cil_permissionx_match_any(avrule->perms.x.permx, target->perms.x.permx)) {
cil_list_append(matching, CIL_NODE, node);
}
}
rc = SEPOL_OK;
exit:
return rc;
}
static int __cil_find_matching_avrule_in_ast(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_OK;
struct cil_args_find *args = extra_args;
if (node->flavor == CIL_BLOCK) {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
goto exit;
}
} else if (node->flavor == CIL_MACRO) {
*finished = CIL_TREE_SKIP_HEAD;
goto exit;
} else if (node->flavor == CIL_AVRULE || node->flavor == CIL_AVRULEX) {
if (node->flavor == args->flavor) {
rc = cil_find_matching_avrule(node, node->data, args->target, args->matching, args->match_self);
}
}
exit:
return rc;
}
int cil_find_matching_avrule_in_ast(struct cil_tree_node *current, enum cil_flavor flavor, void *target, struct cil_list *matching, int match_self)
{
int rc;
struct cil_args_find args;
args.flavor = flavor;
args.target = target;
args.matching = matching;
args.match_self = match_self;
rc = cil_tree_walk(current, __cil_find_matching_avrule_in_ast, NULL, NULL, &args);
if (rc) {
cil_log(CIL_ERR, "An error occurred while searching for avrule in AST\n");
}
return rc;
}
libsepol-3.8.1/cil/src/cil_find.h000066400000000000000000000036161476211737200166320ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include "cil_flavor.h"
#include "cil_tree.h"
#include "cil_list.h"
#ifndef CIL_FIND_H_
#define CIL_FIND_H_
int cil_find_matching_avrule_in_ast(struct cil_tree_node *current, enum cil_flavor flavor, void *target, struct cil_list *matching, int match_self);
struct cil_list *cil_expand_class(struct cil_class *class);
#endif
libsepol-3.8.1/cil/src/cil_flavor.h000066400000000000000000000104771476211737200172060ustar00rootroot00000000000000/*
* Copyright 2013 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_FLAVOR_H_
#define CIL_FLAVOR_H_
/*
Tree/list node types
*/
#define CIL_MIN_OP_OPERANDS 1000
#define CIL_MIN_DECLARATIVE 2000
enum cil_flavor {
CIL_NONE = 0,
CIL_ROOT,
CIL_NODE,
CIL_STRING,
CIL_DATUM,
CIL_LIST,
CIL_LIST_ITEM,
CIL_PARAM,
CIL_ARGS,
CIL_BLOCKINHERIT,
CIL_BLOCKABSTRACT,
CIL_IN,
CIL_CALL,
CIL_BOOLEANIF,
CIL_TUNABLEIF,
CIL_CONDBLOCK,
CIL_CONDTRUE,
CIL_CONDFALSE,
CIL_CLASSORDER,
CIL_CLASSCOMMON,
CIL_CLASSMAPPING,
CIL_CLASSPERMS,
CIL_CLASSPERMS_SET,
CIL_CLASSPERMISSIONSET,
CIL_USERPREFIX,
CIL_USERROLE,
CIL_USERATTRIBUTESET,
CIL_USERLEVEL,
CIL_USERRANGE,
CIL_USERBOUNDS,
CIL_SELINUXUSER,
CIL_SELINUXUSERDEFAULT,
CIL_ROLEATTRIBUTESET,
CIL_ROLETYPE,
CIL_ROLEBOUNDS,
CIL_TYPEATTRIBUTESET,
CIL_EXPANDTYPEATTRIBUTE,
CIL_TYPEALIASACTUAL,
CIL_TYPEBOUNDS,
CIL_TYPEPERMISSIVE,
CIL_SENSALIASACTUAL,
CIL_SENSITIVITYORDER,
CIL_SENSCAT,
CIL_CATALIASACTUAL,
CIL_CATORDER,
CIL_SIDORDER,
CIL_ROLEALLOW,
CIL_AVRULE,
CIL_AVRULEX,
CIL_DENY_RULE,
CIL_ROLETRANSITION,
CIL_TYPE_RULE,
CIL_NAMETYPETRANSITION,
CIL_RANGETRANSITION,
CIL_CONSTRAIN,
CIL_MLSCONSTRAIN,
CIL_VALIDATETRANS,
CIL_MLSVALIDATETRANS,
CIL_SIDCONTEXT,
CIL_FSUSE,
CIL_FILECON,
CIL_PORTCON,
CIL_NODECON,
CIL_GENFSCON,
CIL_NETIFCON,
CIL_PIRQCON,
CIL_IOMEMCON,
CIL_IOPORTCON,
CIL_PCIDEVICECON,
CIL_DEVICETREECON,
CIL_DEFAULTUSER,
CIL_DEFAULTROLE,
CIL_DEFAULTTYPE,
CIL_DEFAULTRANGE,
CIL_HANDLEUNKNOWN,
CIL_MLS,
CIL_SRC_INFO,
CIL_IBPKEYCON,
CIL_IBENDPORTCON,
/*
* boolean constraint set catset
* dom X
* domby X
* incomp X
* eq X X
* ne X X
* and X X X X
* not X X X X
* or X X X X
* xor X X X
* all X X
* range X
*/
CIL_OP = CIL_MIN_OP_OPERANDS,
CIL_ALL,
CIL_AND,
CIL_OR,
CIL_XOR,
CIL_NOT,
CIL_EQ,
CIL_NEQ,
CIL_RANGE,
CIL_CONS_DOM,
CIL_CONS_DOMBY,
CIL_CONS_INCOMP,
CIL_CONS_OPERAND,
CIL_CONS_U1,
CIL_CONS_U2,
CIL_CONS_U3,
CIL_CONS_T1,
CIL_CONS_T2,
CIL_CONS_T3,
CIL_CONS_R1,
CIL_CONS_R2,
CIL_CONS_R3,
CIL_CONS_L1,
CIL_CONS_L2,
CIL_CONS_H1,
CIL_CONS_H2,
CIL_BLOCK = CIL_MIN_DECLARATIVE,
CIL_MACRO,
CIL_OPTIONAL,
CIL_BOOL,
CIL_TUNABLE,
CIL_PERM,
CIL_MAP_PERM,
CIL_COMMON,
CIL_CLASS,
CIL_MAP_CLASS,
CIL_CLASSPERMISSION,
CIL_USER,
CIL_USERATTRIBUTE,
CIL_ROLE,
CIL_ROLEATTRIBUTE,
CIL_TYPE,
CIL_TYPEATTRIBUTE,
CIL_TYPEALIAS,
CIL_SENS,
CIL_SENSALIAS,
CIL_CAT,
CIL_CATSET,
CIL_CATALIAS,
CIL_LEVEL,
CIL_LEVELRANGE,
CIL_SID,
CIL_DECLARED_STRING,
CIL_CONTEXT,
CIL_IPADDR,
CIL_POLICYCAP,
CIL_PERMISSIONX
};
#endif /* CIL_FLAVOR_H_ */
libsepol-3.8.1/cil/src/cil_fqn.c000066400000000000000000000104441476211737200164660ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include "cil_fqn.h"
#include "cil_internal.h"
#include "cil_log.h"
#include "cil_strpool.h"
#include "cil_symtab.h"
struct cil_fqn_args {
char prefix[CIL_MAX_NAME_LENGTH];
int len;
struct cil_tree_node *node;
};
static int __cil_fqn_qualify_decls(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_fqn_args *fqn_args = args;
struct cil_symtab_datum *datum = (struct cil_symtab_datum *)d;
int newlen;
char prefix[CIL_MAX_NAME_LENGTH];
int rc = SEPOL_OK;
if (fqn_args->len == 0) {
goto exit;
}
newlen = fqn_args->len + strlen(datum->name);
if (newlen >= CIL_MAX_NAME_LENGTH) {
cil_log(CIL_INFO, "Fully qualified name for %s is too long\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
strcpy(prefix, fqn_args->prefix);
strcat(prefix, datum->name);
datum->fqn = cil_strpool_add(prefix);
exit:
return rc;
}
static int __cil_fqn_qualify_blocks(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_fqn_args *fqn_args = args;
struct cil_fqn_args child_args;
struct cil_block *block = (struct cil_block *)d;
struct cil_symtab_datum *datum = (struct cil_symtab_datum *)block;
struct cil_tree_node *node = NODE(datum);
int i;
int rc = SEPOL_OK;
int newlen;
if (node->flavor != CIL_BLOCK) {
goto exit;
}
newlen = fqn_args->len + strlen(datum->name) + 1;
if (newlen >= CIL_MAX_NAME_LENGTH) {
cil_log(CIL_INFO, "Fully qualified name for block %s is too long\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
child_args.node = node;
child_args.len = newlen;
strcpy(child_args.prefix, fqn_args->prefix);
strcat(child_args.prefix, datum->name);
strcat(child_args.prefix, ".");
for (i=1; isymtab[i]), __cil_fqn_qualify_decls, &child_args);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
}
rc = cil_symtab_map(&(block->symtab[CIL_SYM_BLOCKS]), __cil_fqn_qualify_blocks, &child_args);
exit:
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR,"Problem qualifying names in block");
}
return rc;
}
int cil_fqn_qualify(struct cil_tree_node *root_node)
{
struct cil_root *root = root_node->data;
struct cil_fqn_args fqn_args;
fqn_args.prefix[0] = '\0';
fqn_args.len = 0;
fqn_args.node = root_node;
return cil_symtab_map(&(root->symtab[CIL_SYM_BLOCKS]), __cil_fqn_qualify_blocks, &fqn_args);
}
libsepol-3.8.1/cil/src/cil_fqn.h000066400000000000000000000033631476211737200164750ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_FQN_H_
#define CIL_FQN_H_
#include "cil_internal.h"
#include "cil_tree.h"
int cil_fqn_qualify(struct cil_tree_node *root_node);
#endif /* CIL_FQN_H_ */
libsepol-3.8.1/cil/src/cil_internal.h000066400000000000000000000671721476211737200175350ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_INTERNAL_H_
#define CIL_INTERNAL_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include "cil_flavor.h"
#include "cil_tree.h"
#include "cil_symtab.h"
#include "cil_mem.h"
#define CIL_MAX_NAME_LENGTH 2048
#define CIL_DEGENERATE_INHERITANCE_DEPTH 10UL
#define CIL_DEGENERATE_INHERITANCE_MINIMUM (0x01 << CIL_DEGENERATE_INHERITANCE_DEPTH)
#define CIL_DEGENERATE_INHERITANCE_GROWTH 10UL
enum cil_pass {
CIL_PASS_INIT = 0,
CIL_PASS_TIF,
CIL_PASS_IN_BEFORE,
CIL_PASS_BLKIN_LINK,
CIL_PASS_BLKIN_COPY,
CIL_PASS_BLKABS,
CIL_PASS_IN_AFTER,
CIL_PASS_CALL1,
CIL_PASS_CALL2,
CIL_PASS_ALIAS1,
CIL_PASS_ALIAS2,
CIL_PASS_MISC1,
CIL_PASS_MLS,
CIL_PASS_MISC2,
CIL_PASS_MISC3,
CIL_PASS_NUM
};
/*
Keywords
*/
extern char *CIL_KEY_CONS_T1;
extern char *CIL_KEY_CONS_T2;
extern char *CIL_KEY_CONS_T3;
extern char *CIL_KEY_CONS_R1;
extern char *CIL_KEY_CONS_R2;
extern char *CIL_KEY_CONS_R3;
extern char *CIL_KEY_CONS_U1;
extern char *CIL_KEY_CONS_U2;
extern char *CIL_KEY_CONS_U3;
extern char *CIL_KEY_CONS_L1;
extern char *CIL_KEY_CONS_L2;
extern char *CIL_KEY_CONS_H1;
extern char *CIL_KEY_CONS_H2;
extern char *CIL_KEY_AND;
extern char *CIL_KEY_OR;
extern char *CIL_KEY_NOT;
extern char *CIL_KEY_EQ;
extern char *CIL_KEY_NEQ;
extern char *CIL_KEY_CONS_DOM;
extern char *CIL_KEY_CONS_DOMBY;
extern char *CIL_KEY_CONS_INCOMP;
extern char *CIL_KEY_CONDTRUE;
extern char *CIL_KEY_CONDFALSE;
extern char *CIL_KEY_SELF;
extern char *CIL_KEY_NOTSELF;
extern char *CIL_KEY_OTHER;
extern char *CIL_KEY_OBJECT_R;
extern char *CIL_KEY_STAR;
extern char *CIL_KEY_TCP;
extern char *CIL_KEY_UDP;
extern char *CIL_KEY_DCCP;
extern char *CIL_KEY_SCTP;
extern char *CIL_KEY_AUDITALLOW;
extern char *CIL_KEY_TUNABLEIF;
extern char *CIL_KEY_ALLOW;
extern char *CIL_KEY_DONTAUDIT;
extern char *CIL_KEY_TYPETRANSITION;
extern char *CIL_KEY_TYPECHANGE;
extern char *CIL_KEY_CALL;
extern char *CIL_KEY_TUNABLE;
extern char *CIL_KEY_XOR;
extern char *CIL_KEY_ALL;
extern char *CIL_KEY_RANGE;
extern char *CIL_KEY_GLOB;
extern char *CIL_KEY_FILE;
extern char *CIL_KEY_DIR;
extern char *CIL_KEY_CHAR;
extern char *CIL_KEY_BLOCK;
extern char *CIL_KEY_SOCKET;
extern char *CIL_KEY_PIPE;
extern char *CIL_KEY_SYMLINK;
extern char *CIL_KEY_ANY;
extern char *CIL_KEY_XATTR;
extern char *CIL_KEY_TASK;
extern char *CIL_KEY_TRANS;
extern char *CIL_KEY_TYPE;
extern char *CIL_KEY_ROLE;
extern char *CIL_KEY_USER;
extern char *CIL_KEY_USERATTRIBUTE;
extern char *CIL_KEY_USERATTRIBUTESET;
extern char *CIL_KEY_SENSITIVITY;
extern char *CIL_KEY_CATEGORY;
extern char *CIL_KEY_CATSET;
extern char *CIL_KEY_LEVEL;
extern char *CIL_KEY_LEVELRANGE;
extern char *CIL_KEY_CLASS;
extern char *CIL_KEY_IPADDR;
extern char *CIL_KEY_MAP_CLASS;
extern char *CIL_KEY_CLASSPERMISSION;
extern char *CIL_KEY_BOOL;
extern char *CIL_KEY_STRING;
extern char *CIL_KEY_NAME;
extern char *CIL_KEY_SOURCE;
extern char *CIL_KEY_TARGET;
extern char *CIL_KEY_LOW;
extern char *CIL_KEY_HIGH;
extern char *CIL_KEY_LOW_HIGH;
extern char *CIL_KEY_GLBLUB;
extern char *CIL_KEY_HANDLEUNKNOWN;
extern char *CIL_KEY_HANDLEUNKNOWN_ALLOW;
extern char *CIL_KEY_HANDLEUNKNOWN_DENY;
extern char *CIL_KEY_HANDLEUNKNOWN_REJECT;
extern char *CIL_KEY_MACRO;
extern char *CIL_KEY_IN;
extern char *CIL_KEY_IN_BEFORE;
extern char *CIL_KEY_IN_AFTER;
extern char *CIL_KEY_MLS;
extern char *CIL_KEY_DEFAULTRANGE;
extern char *CIL_KEY_BLOCKINHERIT;
extern char *CIL_KEY_BLOCKABSTRACT;
extern char *CIL_KEY_CLASSORDER;
extern char *CIL_KEY_CLASSMAPPING;
extern char *CIL_KEY_CLASSPERMISSIONSET;
extern char *CIL_KEY_COMMON;
extern char *CIL_KEY_CLASSCOMMON;
extern char *CIL_KEY_SID;
extern char *CIL_KEY_SIDCONTEXT;
extern char *CIL_KEY_SIDORDER;
extern char *CIL_KEY_USERLEVEL;
extern char *CIL_KEY_USERRANGE;
extern char *CIL_KEY_USERBOUNDS;
extern char *CIL_KEY_USERPREFIX;
extern char *CIL_KEY_SELINUXUSER;
extern char *CIL_KEY_SELINUXUSERDEFAULT;
extern char *CIL_KEY_TYPEATTRIBUTE;
extern char *CIL_KEY_TYPEATTRIBUTESET;
extern char *CIL_KEY_EXPANDTYPEATTRIBUTE;
extern char *CIL_KEY_TYPEALIAS;
extern char *CIL_KEY_TYPEALIASACTUAL;
extern char *CIL_KEY_TYPEBOUNDS;
extern char *CIL_KEY_TYPEPERMISSIVE;
extern char *CIL_KEY_RANGETRANSITION;
extern char *CIL_KEY_USERROLE;
extern char *CIL_KEY_ROLETYPE;
extern char *CIL_KEY_ROLETRANSITION;
extern char *CIL_KEY_ROLEALLOW;
extern char *CIL_KEY_ROLEATTRIBUTE;
extern char *CIL_KEY_ROLEATTRIBUTESET;
extern char *CIL_KEY_ROLEBOUNDS;
extern char *CIL_KEY_BOOLEANIF;
extern char *CIL_KEY_NEVERALLOW;
extern char *CIL_KEY_TYPEMEMBER;
extern char *CIL_KEY_SENSALIAS;
extern char *CIL_KEY_SENSALIASACTUAL;
extern char *CIL_KEY_CATALIAS;
extern char *CIL_KEY_CATALIASACTUAL;
extern char *CIL_KEY_CATORDER;
extern char *CIL_KEY_SENSITIVITYORDER;
extern char *CIL_KEY_SENSCAT;
extern char *CIL_KEY_CONSTRAIN;
extern char *CIL_KEY_MLSCONSTRAIN;
extern char *CIL_KEY_VALIDATETRANS;
extern char *CIL_KEY_MLSVALIDATETRANS;
extern char *CIL_KEY_CONTEXT;
extern char *CIL_KEY_FILECON;
extern char *CIL_KEY_IBPKEYCON;
extern char *CIL_KEY_IBENDPORTCON;
extern char *CIL_KEY_PORTCON;
extern char *CIL_KEY_NODECON;
extern char *CIL_KEY_GENFSCON;
extern char *CIL_KEY_NETIFCON;
extern char *CIL_KEY_PIRQCON;
extern char *CIL_KEY_IOMEMCON;
extern char *CIL_KEY_IOPORTCON;
extern char *CIL_KEY_PCIDEVICECON;
extern char *CIL_KEY_DEVICETREECON;
extern char *CIL_KEY_FSUSE;
extern char *CIL_KEY_POLICYCAP;
extern char *CIL_KEY_OPTIONAL;
extern char *CIL_KEY_DEFAULTUSER;
extern char *CIL_KEY_DEFAULTROLE;
extern char *CIL_KEY_DEFAULTTYPE;
extern char *CIL_KEY_ROOT;
extern char *CIL_KEY_NODE;
extern char *CIL_KEY_PERM;
extern char *CIL_KEY_ALLOWX;
extern char *CIL_KEY_AUDITALLOWX;
extern char *CIL_KEY_DONTAUDITX;
extern char *CIL_KEY_NEVERALLOWX;
extern char *CIL_KEY_PERMISSIONX;
extern char *CIL_KEY_IOCTL;
extern char *CIL_KEY_NLMSG;
extern char *CIL_KEY_UNORDERED;
extern char *CIL_KEY_SRC_INFO;
extern char *CIL_KEY_SRC_CIL;
extern char *CIL_KEY_SRC_HLL_LMS;
extern char *CIL_KEY_SRC_HLL_LMX;
extern char *CIL_KEY_SRC_HLL_LME;
extern char *CIL_KEY_DENY_RULE;
/*
Symbol Table Array Indices
*/
enum cil_sym_index {
CIL_SYM_BLOCKS = 0,
CIL_SYM_USERS,
CIL_SYM_ROLES,
CIL_SYM_TYPES,
CIL_SYM_COMMONS,
CIL_SYM_CLASSES,
CIL_SYM_CLASSPERMSETS,
CIL_SYM_BOOLS,
CIL_SYM_TUNABLES,
CIL_SYM_SENS,
CIL_SYM_CATS,
CIL_SYM_SIDS,
CIL_SYM_CONTEXTS,
CIL_SYM_LEVELS,
CIL_SYM_LEVELRANGES,
CIL_SYM_POLICYCAPS,
CIL_SYM_IPADDRS,
CIL_SYM_STRINGS,
CIL_SYM_PERMX,
CIL_SYM_NUM,
CIL_SYM_UNKNOWN,
CIL_SYM_PERMS // Special case for permissions. This symtab is not included in arrays
};
enum cil_sym_array {
CIL_SYM_ARRAY_ROOT = 0,
CIL_SYM_ARRAY_BLOCK,
CIL_SYM_ARRAY_IN,
CIL_SYM_ARRAY_MACRO,
CIL_SYM_ARRAY_CONDBLOCK,
CIL_SYM_ARRAY_NUM
};
extern const int cil_sym_sizes[CIL_SYM_ARRAY_NUM][CIL_SYM_NUM];
#define CIL_CLASS_SYM_SIZE 256
#define CIL_PERMS_PER_CLASS (sizeof(sepol_access_vector_t) * 8)
struct cil_db {
struct cil_tree *parse;
struct cil_tree *ast;
struct cil_type *selftype;
struct cil_type *notselftype;
struct cil_type *othertype;
struct cil_list *sidorder;
struct cil_list *classorder;
struct cil_list *catorder;
struct cil_list *sensitivityorder;
struct cil_sort *netifcon;
struct cil_sort *genfscon;
struct cil_sort *filecon;
struct cil_sort *nodecon;
struct cil_sort *ibpkeycon;
struct cil_sort *ibendportcon;
struct cil_sort *portcon;
struct cil_sort *pirqcon;
struct cil_sort *iomemcon;
struct cil_sort *ioportcon;
struct cil_sort *pcidevicecon;
struct cil_sort *devicetreecon;
struct cil_sort *fsuse;
struct cil_list *userprefixes;
struct cil_list *selinuxusers;
struct cil_list *declared_strings;
int num_types_and_attrs;
int num_classes;
int num_cats;
int num_types;
int num_roles;
int num_users;
struct cil_type **val_to_type;
struct cil_role **val_to_role;
struct cil_user **val_to_user;
int disable_dontaudit;
int disable_neverallow;
int attrs_expand_generated;
unsigned attrs_expand_size;
int preserve_tunables;
int handle_unknown;
int mls;
int multiple_decls;
int qualified_names;
int target_platform;
int policy_version;
};
struct cil_root {
symtab_t symtab[CIL_SYM_NUM];
};
struct cil_sort {
enum cil_flavor flavor;
uint32_t count;
uint32_t index;
void **array;
};
struct cil_ordered {
int merged;
struct cil_list *strs;
struct cil_list *datums;
};
struct cil_block {
struct cil_symtab_datum datum;
symtab_t symtab[CIL_SYM_NUM];
uint16_t is_abstract;
struct cil_list *bi_nodes;
};
struct cil_blockinherit {
char *block_str;
struct cil_block *block;
};
struct cil_blockabstract {
char *block_str;
struct cil_block *block;
};
struct cil_in {
symtab_t symtab[CIL_SYM_NUM];
int is_after;
char *block_str;
struct cil_block *block;
};
struct cil_optional {
struct cil_symtab_datum datum;
};
struct cil_perm {
struct cil_symtab_datum datum;
unsigned int value;
struct cil_list *classperms; /* Only used for map perms */
};
struct cil_class {
struct cil_symtab_datum datum;
symtab_t perms;
unsigned int num_perms;
struct cil_class *common; /* Only used for kernel class */
uint32_t ordered; /* Only used for kernel class */
};
struct cil_classperms_set {
char *set_str;
struct cil_classpermission *set;
};
struct cil_classperms {
char *class_str;
struct cil_class *class;
struct cil_list *perm_strs;
struct cil_list *perms;
};
struct cil_classpermission {
struct cil_symtab_datum datum;
struct cil_list *classperms;
};
struct cil_classpermissionset {
char *set_str;
struct cil_classpermission *set;
struct cil_list *classperms;
};
struct cil_classmapping {
char *map_class_str;
struct cil_class *map_class;
char *map_perm_str;
struct cil_perm *map_perm;
struct cil_list *classperms;
};
struct cil_classcommon {
char *class_str;
struct cil_class *class;
char *common_str;
struct cil_class *common;
};
struct cil_alias {
struct cil_symtab_datum datum;
void *actual;
};
struct cil_aliasactual {
char *alias_str;
void *alias;
char *actual_str;
void *actual;
};
struct cil_sid {
struct cil_symtab_datum datum;
struct cil_context *context;
uint32_t ordered;
};
struct cil_sidcontext {
char *sid_str;
struct cil_sid *sid;
char *context_str;
struct cil_context *context;
};
struct cil_user {
struct cil_symtab_datum datum;
struct cil_user *bounds;
ebitmap_t *roles;
struct cil_level *dftlevel;
struct cil_levelrange *range;
int value;
};
struct cil_userattribute {
struct cil_symtab_datum datum;
struct cil_list *expr_list;
ebitmap_t *users;
};
struct cil_userattributeset {
char *attr_str;
struct cil_userattribute *attr;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_userrole {
char *user_str;
void *user;
char *role_str;
void *role;
};
struct cil_userlevel {
char *user_str;
void *user;
char *level_str;
struct cil_level *level;
};
struct cil_userrange {
char *user_str;
void *user;
char *range_str;
struct cil_levelrange *range;
};
struct cil_userprefix {
char *user_str;
struct cil_user *user;
char *prefix_str;
};
struct cil_selinuxuser {
char *name_str;
char *user_str;
struct cil_user *user;
char *range_str;
struct cil_levelrange *range;
};
struct cil_role {
struct cil_symtab_datum datum;
struct cil_role *bounds;
ebitmap_t *types;
int value;
};
struct cil_roleattribute {
struct cil_symtab_datum datum;
struct cil_list *expr_list;
ebitmap_t *roles;
};
struct cil_roleattributeset {
char *attr_str;
struct cil_roleattribute *attr;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_roletype {
char *role_str;
void *role; /* role or attribute */
char *type_str;
void *type; /* type, alias, or attribute */
};
struct cil_type {
struct cil_symtab_datum datum;
struct cil_type *bounds;
int value;
};
#define CIL_ATTR_AVRULE (1 << 0)
#define CIL_ATTR_NEVERALLOW (1 << 1)
#define CIL_ATTR_CONSTRAINT (1 << 2)
#define CIL_ATTR_EXPAND_TRUE (1 << 3)
#define CIL_ATTR_EXPAND_FALSE (1 << 4)
struct cil_typeattribute {
struct cil_symtab_datum datum;
struct cil_list *expr_list;
ebitmap_t *types;
int used; // whether or not this attribute was used in a binary policy rule
int keep;
};
struct cil_typeattributeset {
char *attr_str;
struct cil_typeattribute *attr;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_expandtypeattribute {
struct cil_list *attr_strs;
struct cil_list *attr_datums;
int expand;
};
struct cil_typepermissive {
char *type_str;
void *type; /* type or alias */
};
struct cil_nametypetransition {
char *src_str;
void *src; /* type, alias, or attribute */
char *tgt_str;
void *tgt; /* type, alias, or attribute */
char *obj_str;
struct cil_class *obj;
char *name_str;
struct cil_symtab_datum *name;
char *result_str;
void *result; /* type or alias */
};
struct cil_rangetransition {
char *src_str;
void *src; /* type, alias, or attribute */
char *exec_str;
void *exec; /* type, alias, or attribute */
char *obj_str;
struct cil_class *obj;
char *range_str;
struct cil_levelrange *range;
};
struct cil_bool {
struct cil_symtab_datum datum;
uint16_t value;
};
struct cil_tunable {
struct cil_symtab_datum datum;
uint16_t value;
};
#define CIL_AVRULE_ALLOWED 1
#define CIL_AVRULE_AUDITALLOW 2
#define CIL_AVRULE_DONTAUDIT 8
#define CIL_AVRULE_NEVERALLOW 128
#define CIL_AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_DONTAUDIT | AVRULE_NEVERALLOW)
struct cil_avrule {
int is_extended;
uint32_t rule_kind;
char *src_str;
void *src; /* type, alias, or attribute */
char *tgt_str;
void *tgt; /* type, alias, or attribute */
union {
struct cil_list *classperms;
struct {
char *permx_str;
struct cil_permissionx *permx;
} x;
} perms;
};
#define CIL_PERMX_KIND_IOCTL 1
#define CIL_PERMX_KIND_NLMSG 2
struct cil_permissionx {
struct cil_symtab_datum datum;
uint32_t kind;
char *obj_str;
struct cil_class *obj;
struct cil_list *expr_str;
ebitmap_t *perms;
};
struct cil_deny_rule {
char *src_str;
void *src; /* type, alias, or attribute */
char *tgt_str;
void *tgt; /* type, alias, or attribute */
struct cil_list *classperms;
};
#define CIL_TYPE_TRANSITION 16
#define CIL_TYPE_MEMBER 32
#define CIL_TYPE_CHANGE 64
#define CIL_AVRULE_TYPE (AVRULE_TRANSITION | AVRULE_MEMBER | AVRULE_CHANGE)
struct cil_type_rule {
uint32_t rule_kind;
char *src_str;
void *src; /* type, alias, or attribute */
char *tgt_str;
void *tgt; /* type, alias, or attribute */
char *obj_str;
struct cil_class *obj;
char *result_str;
void *result; /* type or alias */
};
struct cil_roletransition {
char *src_str;
struct cil_role *src;
char *tgt_str;
void *tgt; /* type, alias, or attribute */
char *obj_str;
struct cil_class *obj;
char *result_str;
struct cil_role *result;
};
struct cil_roleallow {
char *src_str;
void *src; /* role or attribute */
char *tgt_str;
void *tgt; /* role or attribute */
};
struct cil_sens {
struct cil_symtab_datum datum;
struct cil_list *cats_list;
uint32_t ordered;
};
struct cil_cat {
struct cil_symtab_datum datum;
uint32_t ordered;
int value;
};
struct cil_cats {
uint32_t evaluated;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_catset {
struct cil_symtab_datum datum;
struct cil_cats *cats;
};
struct cil_senscat {
char *sens_str;
struct cil_sens *sens;
struct cil_cats *cats;
};
struct cil_level {
struct cil_symtab_datum datum;
char *sens_str;
struct cil_sens *sens;
struct cil_cats *cats;
};
struct cil_levelrange {
struct cil_symtab_datum datum;
char *low_str;
struct cil_level *low;
char *high_str;
struct cil_level *high;
};
struct cil_context {
struct cil_symtab_datum datum;
char *user_str;
struct cil_user *user;
char *role_str;
struct cil_role *role;
char *type_str;
void *type; /* type or alias */
char *range_str;
struct cil_levelrange *range;
};
enum cil_filecon_types {
CIL_FILECON_ANY = 0,
CIL_FILECON_FILE,
CIL_FILECON_DIR,
CIL_FILECON_CHAR,
CIL_FILECON_BLOCK,
CIL_FILECON_SOCKET,
CIL_FILECON_PIPE,
CIL_FILECON_SYMLINK,
};
struct cil_filecon {
char *path_str;
struct cil_symtab_datum *path;
enum cil_filecon_types type;
char *context_str;
struct cil_context *context;
};
enum cil_protocol {
CIL_PROTOCOL_UDP = 1,
CIL_PROTOCOL_TCP,
CIL_PROTOCOL_DCCP,
CIL_PROTOCOL_SCTP
};
struct cil_ibpkeycon {
char *subnet_prefix_str;
uint32_t pkey_low;
uint32_t pkey_high;
char *context_str;
struct cil_context *context;
};
struct cil_portcon {
enum cil_protocol proto;
uint32_t port_low;
uint32_t port_high;
char *context_str;
struct cil_context *context;
};
struct cil_nodecon {
char *addr_str;
struct cil_ipaddr *addr;
char *mask_str;
struct cil_ipaddr *mask;
char *context_str;
struct cil_context *context;
};
struct cil_ipaddr {
struct cil_symtab_datum datum;
int family;
union {
struct in_addr v4;
struct in6_addr v6;
} ip;
};
struct cil_genfscon {
char *fs_str;
char *path_str;
enum cil_filecon_types file_type;
char *context_str;
struct cil_context *context;
};
struct cil_netifcon {
char *interface_str;
char *if_context_str;
struct cil_context *if_context;
char *packet_context_str;
struct cil_context *packet_context;
char *context_str;
};
struct cil_ibendportcon {
char *dev_name_str;
uint32_t port;
char *context_str;
struct cil_context *context;
};
struct cil_pirqcon {
uint32_t pirq;
char *context_str;
struct cil_context *context;
};
struct cil_iomemcon {
uint64_t iomem_low;
uint64_t iomem_high;
char *context_str;
struct cil_context *context;
};
struct cil_ioportcon {
uint32_t ioport_low;
uint32_t ioport_high;
char *context_str;
struct cil_context *context;
};
struct cil_pcidevicecon {
uint32_t dev;
char *context_str;
struct cil_context *context;
};
struct cil_devicetreecon {
char *path;
char *context_str;
struct cil_context *context;
};
/* Ensure that CIL uses the same values as sepol services.h */
enum cil_fsuse_types {
CIL_FSUSE_XATTR = SECURITY_FS_USE_XATTR,
CIL_FSUSE_TASK = SECURITY_FS_USE_TASK,
CIL_FSUSE_TRANS = SECURITY_FS_USE_TRANS
};
struct cil_fsuse {
enum cil_fsuse_types type;
char *fs_str;
char *context_str;
struct cil_context *context;
};
#define CIL_MLS_LEVELS "l1 l2 h1 h2"
#define CIL_CONSTRAIN_KEYS "t1 t2 r1 r2 u1 u2"
#define CIL_MLSCONSTRAIN_KEYS CIL_MLS_LEVELS CIL_CONSTRAIN_KEYS
#define CIL_CONSTRAIN_OPER "== != eq dom domby incomp not and or"
struct cil_constrain {
struct cil_list *classperms;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_validatetrans {
char *class_str;
struct cil_class *class;
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_param {
char *str;
enum cil_flavor flavor;
};
struct cil_macro {
struct cil_symtab_datum datum;
symtab_t symtab[CIL_SYM_NUM];
struct cil_list *params;
};
struct cil_args {
char *arg_str;
struct cil_symtab_datum *arg;
char *param_str;
enum cil_flavor flavor;
};
struct cil_call {
char *macro_str;
struct cil_macro *macro;
struct cil_tree *args_tree;
struct cil_list *args;
int copied;
};
#define CIL_TRUE 1
#define CIL_FALSE 0
struct cil_condblock {
enum cil_flavor flavor;
symtab_t symtab[CIL_SYM_NUM];
};
struct cil_booleanif {
struct cil_list *str_expr;
struct cil_list *datum_expr;
int preserved_tunable;
};
struct cil_tunableif {
struct cil_list *str_expr;
struct cil_list *datum_expr;
};
struct cil_policycap {
struct cil_symtab_datum datum;
};
struct cil_bounds {
char *parent_str;
void *parent;
char *child_str;
void *child;
};
/* Ensure that CIL uses the same values as sepol policydb.h */
enum cil_default_object {
CIL_DEFAULT_SOURCE = DEFAULT_SOURCE,
CIL_DEFAULT_TARGET = DEFAULT_TARGET,
};
/* Default labeling behavior for users, roles, and types */
struct cil_default {
enum cil_flavor flavor;
struct cil_list *class_strs;
struct cil_list *class_datums;
enum cil_default_object object;
};
/* Ensure that CIL uses the same values as sepol policydb.h */
enum cil_default_object_range {
CIL_DEFAULT_SOURCE_LOW = DEFAULT_SOURCE_LOW,
CIL_DEFAULT_SOURCE_HIGH = DEFAULT_SOURCE_HIGH,
CIL_DEFAULT_SOURCE_LOW_HIGH = DEFAULT_SOURCE_LOW_HIGH,
CIL_DEFAULT_TARGET_LOW = DEFAULT_TARGET_LOW,
CIL_DEFAULT_TARGET_HIGH = DEFAULT_TARGET_HIGH,
CIL_DEFAULT_TARGET_LOW_HIGH = DEFAULT_TARGET_LOW_HIGH,
CIL_DEFAULT_GLBLUB = DEFAULT_GLBLUB,
};
/* Default labeling behavior for range */
struct cil_defaultrange {
struct cil_list *class_strs;
struct cil_list *class_datums;
enum cil_default_object_range object_range;
};
struct cil_handleunknown {
int handle_unknown;
};
struct cil_mls {
int value;
};
struct cil_src_info {
char *kind;
uint32_t hll_line;
char *path;
};
void cil_db_init(struct cil_db **db);
void cil_db_destroy(struct cil_db **db);
void cil_root_init(struct cil_root **root);
void cil_root_destroy(struct cil_root *root);
void cil_destroy_data(void **data, enum cil_flavor flavor);
int cil_flavor_to_symtab_index(enum cil_flavor flavor, enum cil_sym_index *index);
const char * cil_node_to_string(struct cil_tree_node *node);
int cil_userprefixes_to_string(struct cil_db *db, char **out, size_t *size);
int cil_selinuxusers_to_string(struct cil_db *db, char **out, size_t *size);
int cil_filecons_to_string(struct cil_db *db, char **out, size_t *size);
void cil_symtab_array_init(symtab_t symtab[], const int symtab_sizes[CIL_SYM_NUM]);
void cil_symtab_array_destroy(symtab_t symtab[]);
void cil_destroy_ast_symtabs(struct cil_tree_node *root);
int cil_get_symtab(struct cil_tree_node *ast_node, symtab_t **symtab, enum cil_sym_index sym_index);
int cil_string_to_uint32(const char *string, uint32_t *value, int base);
int cil_string_to_uint64(const char *string, uint64_t *value, int base);
void cil_sort_init(struct cil_sort **sort);
void cil_sort_destroy(struct cil_sort **sort);
void cil_ordered_init(struct cil_ordered **ordered);
void cil_netifcon_init(struct cil_netifcon **netifcon);
void cil_ibendportcon_init(struct cil_ibendportcon **ibendportcon);
void cil_context_init(struct cil_context **context);
void cil_level_init(struct cil_level **level);
void cil_levelrange_init(struct cil_levelrange **lvlrange);
void cil_sens_init(struct cil_sens **sens);
void cil_block_init(struct cil_block **block);
void cil_blockinherit_init(struct cil_blockinherit **inherit);
void cil_blockabstract_init(struct cil_blockabstract **abstract);
void cil_in_init(struct cil_in **in);
void cil_class_init(struct cil_class **class);
void cil_classcommon_init(struct cil_classcommon **classcommon);
void cil_sid_init(struct cil_sid **sid);
void cil_sidcontext_init(struct cil_sidcontext **sidcontext);
void cil_userrole_init(struct cil_userrole **userrole);
void cil_userprefix_init(struct cil_userprefix **userprefix);
void cil_selinuxuser_init(struct cil_selinuxuser **selinuxuser);
void cil_roleattribute_init(struct cil_roleattribute **attribute);
void cil_roleattributeset_init(struct cil_roleattributeset **attrset);
void cil_roletype_init(struct cil_roletype **roletype);
void cil_typeattribute_init(struct cil_typeattribute **attribute);
void cil_typeattributeset_init(struct cil_typeattributeset **attrset);
void cil_expandtypeattribute_init(struct cil_expandtypeattribute **expandattr);
void cil_alias_init(struct cil_alias **alias);
void cil_aliasactual_init(struct cil_aliasactual **aliasactual);
void cil_typepermissive_init(struct cil_typepermissive **typeperm);
void cil_nametypetransition_init(struct cil_nametypetransition **nametypetrans);
void cil_rangetransition_init(struct cil_rangetransition **rangetrans);
void cil_bool_init(struct cil_bool **cilbool);
void cil_boolif_init(struct cil_booleanif **bif);
void cil_condblock_init(struct cil_condblock **cb);
void cil_tunable_init(struct cil_tunable **ciltun);
void cil_tunif_init(struct cil_tunableif **tif);
void cil_avrule_init(struct cil_avrule **avrule);
void cil_permissionx_init(struct cil_permissionx **permx);
void cil_deny_rule_init(struct cil_deny_rule **rule);
void cil_type_rule_init(struct cil_type_rule **type_rule);
void cil_roletransition_init(struct cil_roletransition **roletrans);
void cil_roleallow_init(struct cil_roleallow **role_allow);
void cil_catset_init(struct cil_catset **catset);
void cil_cats_init(struct cil_cats **cats);
void cil_senscat_init(struct cil_senscat **senscat);
void cil_filecon_init(struct cil_filecon **filecon);
void cil_ibpkeycon_init(struct cil_ibpkeycon **ibpkeycon);
void cil_portcon_init(struct cil_portcon **portcon);
void cil_nodecon_init(struct cil_nodecon **nodecon);
void cil_genfscon_init(struct cil_genfscon **genfscon);
void cil_pirqcon_init(struct cil_pirqcon **pirqcon);
void cil_iomemcon_init(struct cil_iomemcon **iomemcon);
void cil_ioportcon_init(struct cil_ioportcon **ioportcon);
void cil_pcidevicecon_init(struct cil_pcidevicecon **pcidevicecon);
void cil_devicetreecon_init(struct cil_devicetreecon **devicetreecon);
void cil_fsuse_init(struct cil_fsuse **fsuse);
void cil_constrain_init(struct cil_constrain **constrain);
void cil_validatetrans_init(struct cil_validatetrans **validtrans);
void cil_ipaddr_init(struct cil_ipaddr **ipaddr);
void cil_perm_init(struct cil_perm **perm);
void cil_classpermission_init(struct cil_classpermission **cp);
void cil_classpermissionset_init(struct cil_classpermissionset **cps);
void cil_classperms_set_init(struct cil_classperms_set **cp_set);
void cil_classperms_init(struct cil_classperms **cp);
void cil_classmapping_init(struct cil_classmapping **mapping);
void cil_user_init(struct cil_user **user);
void cil_userlevel_init(struct cil_userlevel **usrlvl);
void cil_userrange_init(struct cil_userrange **userrange);
void cil_role_init(struct cil_role **role);
void cil_type_init(struct cil_type **type);
void cil_cat_init(struct cil_cat **cat);
void cil_args_init(struct cil_args **args);
void cil_call_init(struct cil_call **call);
void cil_optional_init(struct cil_optional **optional);
void cil_param_init(struct cil_param **param);
void cil_macro_init(struct cil_macro **macro);
void cil_policycap_init(struct cil_policycap **policycap);
void cil_bounds_init(struct cil_bounds **bounds);
void cil_default_init(struct cil_default **def);
void cil_defaultrange_init(struct cil_defaultrange **def);
void cil_handleunknown_init(struct cil_handleunknown **unk);
void cil_mls_init(struct cil_mls **mls);
void cil_src_info_init(struct cil_src_info **info);
void cil_userattribute_init(struct cil_userattribute **attribute);
void cil_userattributeset_init(struct cil_userattributeset **attrset);
#endif
libsepol-3.8.1/cil/src/cil_lexer.h000066400000000000000000000040111476211737200170170ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_LEXER_H_
#define CIL_LEXER_H_
#include
#define OPAREN 1
#define CPAREN 2
#define SYMBOL 3
#define QSTRING 4
#define COMMENT 5
#define HLL_LINEMARK 6
#define NEWLINE 7
#define END_OF_FILE 8
#define UNKNOWN 9
struct token {
uint32_t type;
char * value;
uint32_t line;
};
int cil_lexer_setup(char *buffer, uint32_t size);
void cil_lexer_destroy(void);
int cil_lexer_next(struct token *tok);
#endif /* CIL_LEXER_H_ */
libsepol-3.8.1/cil/src/cil_lexer.l000066400000000000000000000054421476211737200170340ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
%{
#include
#include
#include "cil_internal.h"
#include "cil_lexer.h"
#include "cil_log.h"
#include "cil_mem.h"
char *value = NULL;
int line = 1;
%}
%option nounput
%option noinput
%option noyywrap
%option prefix="cil_yy"
digit [0-9]
alpha [a-zA-Z]
spec_char [\[\]\.\@\=\/\*\-\_\$\%\+\-\!\|\&\^\:\~\`\#\{\}\'\<\>\?\,]
symbol ({digit}|{alpha}|{spec_char})+
white [ \t]
newline [\n\r]
qstring \"[^"\n\0]*\"
hll_lm ^;;\*
comment ;
%%
{newline} line++; return NEWLINE;
{hll_lm} value=yytext; return HLL_LINEMARK;
{comment} value=yytext; return COMMENT;
"(" value=yytext; return OPAREN;
")" value=yytext; return CPAREN;
{symbol} value=yytext; return SYMBOL;
{white} ;
{qstring} value=yytext; return QSTRING;
<> return END_OF_FILE;
. value=yytext; return UNKNOWN;
%%
int cil_lexer_setup(char *buffer, uint32_t size)
{
size = (yy_size_t)size;
if (yy_scan_buffer(buffer, size) == NULL) {
cil_log(CIL_INFO, "Lexer failed to setup buffer\n");
return SEPOL_ERR;
}
line = 1;
return SEPOL_OK;
}
void cil_lexer_destroy(void)
{
yylex_destroy();
}
int cil_lexer_next(struct token *tok)
{
tok->type = yylex();
tok->value = value;
tok->line = line;
return SEPOL_OK;
}
libsepol-3.8.1/cil/src/cil_list.c000066400000000000000000000145501476211737200166570ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
__attribute__((noreturn)) __attribute__((format (printf, 1, 2))) static void cil_list_error(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
cil_vlog(CIL_ERR, msg, ap);
va_end(ap);
exit(1);
}
void cil_list_init(struct cil_list **list, enum cil_flavor flavor)
{
struct cil_list *new_list = cil_malloc(sizeof(*new_list));
new_list->head = NULL;
new_list->tail = NULL;
new_list->flavor = flavor;
*list = new_list;
}
void cil_list_destroy(struct cil_list **list, unsigned destroy_data)
{
struct cil_list_item *item;
if (*list == NULL) {
return;
}
item = (*list)->head;
while (item != NULL)
{
struct cil_list_item *next = item->next;
if (item->flavor == CIL_LIST) {
cil_list_destroy((struct cil_list**)&(item->data), destroy_data);
free(item);
} else {
cil_list_item_destroy(&item, destroy_data);
}
item = next;
}
free(*list);
*list = NULL;
}
void cil_list_item_init(struct cil_list_item **item)
{
struct cil_list_item *new_item = cil_malloc(sizeof(*new_item));
new_item->next = NULL;
new_item->flavor = CIL_NONE;
new_item->data = NULL;
*item = new_item;
}
void cil_list_item_destroy(struct cil_list_item **item, unsigned destroy_data)
{
if (destroy_data) {
cil_destroy_data(&(*item)->data, (*item)->flavor);
}
free(*item);
*item = NULL;
}
void cil_list_append(struct cil_list *list, enum cil_flavor flavor, void *data)
{
struct cil_list_item *item;
if (list == NULL) {
cil_list_error("Attempt to append data to a NULL list");
}
cil_list_item_init(&item);
item->flavor = flavor;
item->data = data;
if (list->tail == NULL) {
list->head = item;
list->tail = item;
return;
}
list->tail->next = item;
list->tail = item;
}
void cil_list_prepend(struct cil_list *list, enum cil_flavor flavor, void *data)
{
struct cil_list_item *item;
if (list == NULL) {
cil_list_error("Attempt to prepend data to a NULL list");
}
cil_list_item_init(&item);
item->flavor = flavor;
item->data = data;
if (list->tail == NULL) {
list->head = item;
list->tail = item;
return;
}
item->next = list->head;
list->head = item;
}
struct cil_list_item *cil_list_insert(struct cil_list *list, struct cil_list_item *curr, enum cil_flavor flavor, void *data)
{
struct cil_list_item *item;
if (list == NULL) {
cil_list_error("Attempt to append data to a NULL list");
}
if (curr == NULL) {
/* Insert at the front of the list */
cil_list_prepend(list, flavor, data);
return list->head;
}
if (curr == list->tail) {
cil_list_append(list, flavor, data);
return list->tail;
}
cil_list_item_init(&item);
item->flavor = flavor;
item->data = data;
item->next = curr->next;
curr->next = item;
return item;
}
void cil_list_append_item(struct cil_list *list, struct cil_list_item *item)
{
struct cil_list_item *last = item;
if (list == NULL) {
cil_list_error("Attempt to append an item to a NULL list");
}
if (item == NULL) {
cil_list_error("Attempt to append a NULL item to a list");
}
while (last->next != NULL) {
last = last->next;
}
if (list->tail == NULL) {
list->head = item;
list->tail = last;
return;
}
list->tail->next = item;
list->tail = last;
}
void cil_list_prepend_item(struct cil_list *list, struct cil_list_item *item)
{
struct cil_list_item *last = item;
if (list == NULL) {
cil_list_error("Attempt to prepend an item to a NULL list");
}
if (item == NULL) {
cil_list_error("Attempt to prepend a NULL item to a list");
}
while (last->next != NULL) {
last = last->next;
}
if (list->tail == NULL) {
list->head = item;
list->tail = last;
return;
}
last->next = list->head;
list->head = item;
}
void cil_list_remove(struct cil_list *list, enum cil_flavor flavor, void *data, unsigned destroy_data)
{
struct cil_list_item *item;
struct cil_list_item *previous = NULL;
if (list == NULL) {
cil_list_error("Attempt to remove data from a NULL list");
}
cil_list_for_each(item, list) {
if (item->data == data && item->flavor == flavor) {
if (previous == NULL) {
list->head = item->next;
} else {
previous->next = item->next;
}
if (item->next == NULL) {
list->tail = previous;
}
cil_list_item_destroy(&item, destroy_data);
break;
}
previous = item;
}
}
int cil_list_contains(struct cil_list *list, void *data)
{
struct cil_list_item *curr = NULL;
cil_list_for_each(curr, list) {
if (curr->data == data) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
int cil_list_match_any(struct cil_list *l1, struct cil_list *l2)
{
struct cil_list_item *i1;
struct cil_list_item *i2;
cil_list_for_each(i1, l1) {
cil_list_for_each(i2, l2) {
if (i1->data == i2->data && i1->flavor == i2->flavor) {
return CIL_TRUE;
}
}
}
return CIL_FALSE;
}
libsepol-3.8.1/cil/src/cil_list.h000066400000000000000000000057031476211737200166640ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_LIST_H_
#define CIL_LIST_H_
#include "cil_flavor.h"
struct cil_list {
struct cil_list_item *head;
struct cil_list_item *tail;
enum cil_flavor flavor;
};
struct cil_list_item {
struct cil_list_item *next;
enum cil_flavor flavor;
void *data;
};
#define cil_list_is_empty(list) \
((list) == NULL || (list)->head == NULL)
#define cil_list_for_each(item, list) \
for (item = (list)->head; item != NULL; item = item->next)
void cil_list_init(struct cil_list **list, enum cil_flavor flavor);
void cil_list_destroy (struct cil_list **list, unsigned destroy_data);
void cil_list_item_init(struct cil_list_item **item);
void cil_list_item_destroy(struct cil_list_item **item, unsigned destroy_data);
void cil_list_append(struct cil_list *list, enum cil_flavor flavor, void *data);
void cil_list_prepend(struct cil_list *list, enum cil_flavor flavor, void *data);
void cil_list_remove(struct cil_list *list, enum cil_flavor flavor, void *data, unsigned destroy_data);
struct cil_list_item *cil_list_insert(struct cil_list *list, struct cil_list_item *curr, enum cil_flavor flavor, void *data);
void cil_list_append_item(struct cil_list *list, struct cil_list_item *item);
void cil_list_prepend_item(struct cil_list *list, struct cil_list_item *item);
int cil_list_contains(struct cil_list *list, void *data);
int cil_list_match_any(struct cil_list *l1, struct cil_list *l2);
#endif
libsepol-3.8.1/cil/src/cil_log.c000066400000000000000000000054051476211737200164640ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include "cil_log.h"
static enum cil_log_level cil_log_level = CIL_ERR;
static void cil_default_log_handler(__attribute__((unused)) int lvl, const char *msg)
{
fprintf(stderr, "%s", msg);
}
static void (*cil_log_handler)(int lvl, const char *msg) = &cil_default_log_handler;
void cil_set_log_handler(void (*handler)(int lvl, const char *msg))
{
cil_log_handler = handler;
}
__attribute__ ((format (printf, 2, 0))) void cil_vlog(enum cil_log_level lvl, const char *msg, va_list args)
{
if (cil_log_level >= lvl) {
char buff[MAX_LOG_SIZE];
int n = vsnprintf(buff, MAX_LOG_SIZE, msg, args);
if (n > 0) {
(*cil_log_handler)(cil_log_level, buff);
if (n >= MAX_LOG_SIZE) {
(*cil_log_handler)(cil_log_level, " ");
}
}
}
}
__attribute__ ((format (printf, 2, 3))) void cil_log(enum cil_log_level lvl, const char *msg, ...)
{
va_list args;
va_start(args, msg);
cil_vlog(lvl, msg, args);
va_end(args);
}
void cil_set_log_level(enum cil_log_level lvl)
{
cil_log_level = lvl;
}
enum cil_log_level cil_get_log_level(void)
{
return cil_log_level;
}
libsepol-3.8.1/cil/src/cil_log.h000066400000000000000000000037351476211737200164750ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_LOG_H_
#define CIL_LOG_H_
#include
#include
#include
#define MAX_LOG_SIZE 512
__attribute__ ((format(printf, 2, 0))) void cil_vlog(enum cil_log_level lvl, const char *msg, va_list args);
__attribute__ ((format(printf, 2, 3))) void cil_log(enum cil_log_level lvl, const char *msg, ...);
enum cil_log_level cil_get_log_level(void);
#endif // CIL_LOG_H_
libsepol-3.8.1/cil/src/cil_mem.c000066400000000000000000000054541476211737200164650ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_log.h"
#include "cil_mem.h"
void *cil_malloc(size_t size)
{
void *mem = malloc(size);
if (mem == NULL){
if (size == 0) {
return NULL;
}
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
return mem;
}
void *cil_calloc(size_t num_elements, size_t element_size)
{
void *mem = calloc(num_elements, element_size);
if (mem == NULL){
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
return mem;
}
void *cil_realloc(void *ptr, size_t size)
{
void *mem = realloc(ptr, size);
if (mem == NULL){
if (size == 0) {
return NULL;
}
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
return mem;
}
char *cil_strdup(const char *str)
{
char *mem = NULL;
if (str == NULL) {
return NULL;
}
mem = strdup(str);
if (mem == NULL) {
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
return mem;
}
__attribute__ ((format (printf, 2, 3))) int cil_asprintf(char **strp, const char *fmt, ...)
{
int rc;
va_list ap;
va_start(ap, fmt);
rc = vasprintf(strp, fmt, ap);
va_end(ap);
if (rc == -1) {
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
return rc;
}
libsepol-3.8.1/cil/src/cil_mem.h000066400000000000000000000036611476211737200164700ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_MEM_H_
#define CIL_MEM_H_
/* Wrapped malloc that catches errors and calls the error callback */
void *cil_malloc(size_t size);
void *cil_calloc(size_t num_elements, size_t element_size);
void *cil_realloc(void *ptr, size_t size);
char *cil_strdup(const char *str);
int cil_asprintf(char **strp, const char *fmt, ...);
#endif /* CIL_MEM_H_ */
libsepol-3.8.1/cil/src/cil_parser.c000066400000000000000000000221071476211737200171750ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_lexer.h"
#include "cil_parser.h"
#include "cil_strpool.h"
#include "cil_stack.h"
#define CIL_PARSER_MAX_EXPR_DEPTH (0x1 << 12)
struct hll_info {
uint32_t hll_offset;
uint32_t hll_expand;
};
static void push_hll_info(struct cil_stack *stack, uint32_t hll_offset, uint32_t hll_expand)
{
struct hll_info *new = cil_malloc(sizeof(*new));
new->hll_offset = hll_offset;
new->hll_expand = hll_expand;
cil_stack_push(stack, CIL_NONE, new);
}
static void pop_hll_info(struct cil_stack *stack, uint32_t *hll_offset, uint32_t *hll_expand)
{
struct cil_stack_item *curr = cil_stack_pop(stack);
struct hll_info *info;
if (!curr) {
return;
}
info = curr->data;
*hll_expand = info->hll_expand;
*hll_offset = info->hll_offset;
free(curr->data);
}
static void create_node(struct cil_tree_node **node, struct cil_tree_node *current, uint32_t line, uint32_t hll_offset, void *value)
{
cil_tree_node_init(node);
(*node)->parent = current;
(*node)->flavor = CIL_NODE;
(*node)->line = line;
(*node)->hll_offset = hll_offset;
(*node)->data = value;
}
static void insert_node(struct cil_tree_node *node, struct cil_tree_node *current)
{
if (current->cl_head == NULL) {
current->cl_head = node;
} else {
current->cl_tail->next = node;
}
current->cl_tail = node;
}
static int add_hll_linemark(struct cil_tree_node **current, uint32_t *hll_offset, uint32_t *hll_expand, struct cil_stack *stack, char *path)
{
char *hll_type;
struct cil_tree_node *node;
struct token tok;
uint32_t prev_hll_expand, prev_hll_offset;
cil_lexer_next(&tok);
if (tok.type != SYMBOL) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
goto exit;
}
hll_type = cil_strpool_add(tok.value);
if (hll_type != CIL_KEY_SRC_HLL_LME && hll_type != CIL_KEY_SRC_HLL_LMS && hll_type != CIL_KEY_SRC_HLL_LMX) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
goto exit;
}
if (hll_type == CIL_KEY_SRC_HLL_LME) {
if (cil_stack_is_empty(stack)) {
cil_log(CIL_ERR, "Line mark end without start\n");
goto exit;
}
prev_hll_expand = *hll_expand;
prev_hll_offset = *hll_offset;
pop_hll_info(stack, hll_offset, hll_expand);
if (!*hll_expand) {
/* This is needed if not going back to an lmx section. */
*hll_offset = prev_hll_offset;
}
if (prev_hll_expand && !*hll_expand) {
/* This is needed to count the lme at the end of an lmx section
* within an lms section (or within no hll section).
*/
(*hll_offset)++;
}
*current = (*current)->parent;
} else {
push_hll_info(stack, *hll_offset, *hll_expand);
if (cil_stack_number_of_items(stack) > CIL_PARSER_MAX_EXPR_DEPTH) {
cil_log(CIL_ERR, "Number of active line marks exceeds limit of %d\n", CIL_PARSER_MAX_EXPR_DEPTH);
goto exit;
}
create_node(&node, *current, tok.line, *hll_offset, NULL);
insert_node(node, *current);
*current = node;
create_node(&node, *current, tok.line, *hll_offset, CIL_KEY_SRC_INFO);
insert_node(node, *current);
create_node(&node, *current, tok.line, *hll_offset, hll_type);
insert_node(node, *current);
cil_lexer_next(&tok);
if (tok.type != SYMBOL) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
goto exit;
}
create_node(&node, *current, tok.line, *hll_offset, cil_strpool_add(tok.value));
insert_node(node, *current);
cil_lexer_next(&tok);
if (tok.type != SYMBOL && tok.type != QSTRING) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
goto exit;
}
if (tok.type == QSTRING) {
tok.value[strlen(tok.value) - 1] = '\0';
tok.value = tok.value+1;
}
create_node(&node, *current, tok.line, *hll_offset, cil_strpool_add(tok.value));
insert_node(node, *current);
*hll_expand = (hll_type == CIL_KEY_SRC_HLL_LMX) ? 1 : 0;
}
cil_lexer_next(&tok);
if (tok.type != NEWLINE) {
cil_log(CIL_ERR, "Invalid line mark syntax\n");
goto exit;
}
if (!*hll_expand) {
/* Need to increment because of the NEWLINE */
(*hll_offset)++;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Problem with high-level line mark at line %u of %s\n", tok.line, path);
return SEPOL_ERR;
}
static void add_cil_path(struct cil_tree_node **current, char *path)
{
struct cil_tree_node *node;
create_node(&node, *current, 0, 0, NULL);
insert_node(node, *current);
*current = node;
create_node(&node, *current, 0, 0, CIL_KEY_SRC_INFO);
insert_node(node, *current);
create_node(&node, *current, 0, 0, CIL_KEY_SRC_CIL);
insert_node(node, *current);
create_node(&node, *current, 0, 0, cil_strpool_add("1"));
insert_node(node, *current);
create_node(&node, *current, 0, 0, path);
insert_node(node, *current);
}
int cil_parser(const char *_path, char *buffer, uint32_t size, struct cil_tree **parse_tree)
{
int paren_count = 0;
struct cil_tree *tree = NULL;
struct cil_tree_node *node = NULL;
struct cil_tree_node *current = NULL;
char *path = cil_strpool_add(_path);
struct cil_stack *stack;
uint32_t hll_offset = 1;
uint32_t hll_expand = 0;
struct token tok;
int rc = SEPOL_OK;
cil_stack_init(&stack);
cil_lexer_setup(buffer, size);
tree = *parse_tree;
current = tree->root;
add_cil_path(¤t, path);
do {
cil_lexer_next(&tok);
switch (tok.type) {
case HLL_LINEMARK:
rc = add_hll_linemark(¤t, &hll_offset, &hll_expand, stack, path);
if (rc != SEPOL_OK) {
goto exit;
}
break;
case OPAREN:
paren_count++;
if (paren_count > CIL_PARSER_MAX_EXPR_DEPTH) {
cil_log(CIL_ERR, "Number of open parenthesis exceeds limit of %d at line %d of %s\n", CIL_PARSER_MAX_EXPR_DEPTH, tok.line, path);
goto exit;
}
create_node(&node, current, tok.line, hll_offset, NULL);
insert_node(node, current);
current = node;
break;
case CPAREN:
paren_count--;
if (paren_count < 0) {
cil_log(CIL_ERR, "Close parenthesis without matching open at line %d of %s\n", tok.line, path);
goto exit;
}
current = current->parent;
break;
case QSTRING:
tok.value[strlen(tok.value) - 1] = '\0';
tok.value = tok.value+1;
/* FALLTHRU */
case SYMBOL:
if (paren_count == 0) {
cil_log(CIL_ERR, "Symbol not inside parenthesis at line %d of %s\n", tok.line, path);
goto exit;
}
create_node(&node, current, tok.line, hll_offset, cil_strpool_add(tok.value));
insert_node(node, current);
break;
case NEWLINE :
if (!hll_expand) {
hll_offset++;
}
break;
case COMMENT:
while (tok.type != NEWLINE && tok.type != END_OF_FILE) {
cil_lexer_next(&tok);
}
if (!hll_expand) {
hll_offset++;
}
if (tok.type != END_OF_FILE) {
break;
}
/* FALLTHRU */
// Fall through if EOF
case END_OF_FILE:
if (paren_count > 0) {
cil_log(CIL_ERR, "Open parenthesis without matching close at line %d of %s\n", tok.line, path);
goto exit;
}
if (!cil_stack_is_empty(stack)) {
cil_log(CIL_ERR, "High-level language line marker start without close at line %d of %s\n", tok.line, path);
goto exit;
}
break;
case UNKNOWN:
cil_log(CIL_ERR, "Invalid token '%s' at line %d of %s\n", tok.value, tok.line, path);
goto exit;
default:
cil_log(CIL_ERR, "Unknown token type '%d' at line %d of %s\n", tok.type, tok.line, path);
goto exit;
}
}
while (tok.type != END_OF_FILE);
cil_lexer_destroy();
cil_stack_destroy(&stack);
*parse_tree = tree;
return SEPOL_OK;
exit:
while (!cil_stack_is_empty(stack)) {
pop_hll_info(stack, &hll_offset, &hll_expand);
}
cil_lexer_destroy();
cil_stack_destroy(&stack);
return SEPOL_ERR;
}
libsepol-3.8.1/cil/src/cil_parser.h000066400000000000000000000034111476211737200171770ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_PARSER_H_
#define CIL_PARSER_H_
#include "cil_tree.h"
int cil_parser(const char *path, char *buffer, uint32_t size, struct cil_tree **parse_tree);
#endif /* CIL_PARSER_H_ */
libsepol-3.8.1/cil/src/cil_policy.c000066400000000000000000001441371476211737200172100ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_find.h"
#include "cil_mem.h"
#include "cil_policy.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_symtab.h"
enum cil_statement_list {
CIL_LIST_COMMON = 1,
CIL_LIST_DEFAULT_USER,
CIL_LIST_DEFAULT_ROLE,
CIL_LIST_DEFAULT_TYPE,
CIL_LIST_DEFAULT_RANGE,
CIL_LIST_SENSALIAS,
CIL_LIST_CATALIAS,
CIL_LIST_MLSCONSTRAIN,
CIL_LIST_MLSVALIDATETRANS,
CIL_LIST_POLICYCAP,
CIL_LIST_TYPEATTRIBUTE,
CIL_LIST_ROLEATTRIBUTE,
CIL_LIST_BOOL,
CIL_LIST_TYPE,
CIL_LIST_TYPEALIAS,
CIL_LIST_ROLE,
CIL_LIST_ROLEALLOW,
CIL_LIST_ROLETRANSITION,
CIL_LIST_USER,
CIL_LIST_CONSTRAINT,
CIL_LIST_VALIDATETRANS,
CIL_LIST_NUM_LISTS
};
static int __cil_gather_statements_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_list **lists;
int kind = 0;
lists = (struct cil_list **)extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_BOOLEANIF:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_COMMON:
kind = CIL_LIST_COMMON;
break;
case CIL_DEFAULTUSER:
kind = CIL_LIST_DEFAULT_USER;
break;
case CIL_DEFAULTROLE:
kind = CIL_LIST_DEFAULT_ROLE;
break;
case CIL_DEFAULTTYPE:
kind = CIL_LIST_DEFAULT_TYPE;
break;
case CIL_DEFAULTRANGE:
kind = CIL_LIST_DEFAULT_RANGE;
break;
case CIL_SENSALIAS:
kind = CIL_LIST_SENSALIAS;
break;
case CIL_CATALIAS:
kind = CIL_LIST_CATALIAS;
break;
case CIL_MLSCONSTRAIN:
kind = CIL_LIST_MLSCONSTRAIN;
break;
case CIL_MLSVALIDATETRANS:
kind = CIL_LIST_MLSVALIDATETRANS;
break;
case CIL_POLICYCAP:
kind = CIL_LIST_POLICYCAP;
break;
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = node->data;
if (strcmp(attr->datum.fqn, "cil_gen_require") != 0) {
kind = CIL_LIST_TYPEATTRIBUTE;
}
break;
}
case CIL_ROLEATTRIBUTE: {
struct cil_roleattribute *attr = node->data;
if (strcmp(attr->datum.fqn, "cil_gen_require") != 0) {
kind = CIL_LIST_ROLEATTRIBUTE;
}
break;
}
case CIL_BOOL:
kind = CIL_LIST_BOOL;
break;
case CIL_TYPE:
kind = CIL_LIST_TYPE;
break;
case CIL_TYPEALIAS:
kind = CIL_LIST_TYPEALIAS;
break;
case CIL_ROLE: {
struct cil_role *role = node->data;
if (strcmp(role->datum.fqn, "object_r") != 0) {
kind = CIL_LIST_ROLE;
}
break;
}
case CIL_ROLEALLOW:
kind = CIL_LIST_ROLEALLOW;
break;
case CIL_ROLETRANSITION:
kind = CIL_LIST_ROLETRANSITION;
break;
case CIL_USER:
kind = CIL_LIST_USER;
break;
case CIL_CONSTRAIN:
kind = CIL_LIST_CONSTRAINT;
break;
case CIL_VALIDATETRANS:
kind = CIL_LIST_VALIDATETRANS;
break;
default:
break;
}
if (kind > 0) {
cil_list_append(lists[kind], node->flavor, node->data);
}
return SEPOL_OK;
}
static void cil_gather_statements(struct cil_tree_node *start, struct cil_list *lists[])
{
cil_tree_walk(start, __cil_gather_statements_helper, NULL, NULL, lists);
}
static void cil_simple_rules_to_policy(FILE *out, struct cil_list *rules, const char *kind)
{
struct cil_list_item *i1;
cil_list_for_each(i1, rules) {
fprintf(out, "%s %s;\n", kind, DATUM(i1->data)->fqn);
}
}
static void cil_cats_to_policy(FILE *out, struct cil_cats *cats)
{
const char *lead = "";
struct cil_cat *first = NULL, *last = NULL, *cat;
struct cil_list_item *i1;
cil_list_for_each(i1, cats->datum_expr) {
cat = i1->data;
if (first == NULL) {
first = cat;
} else if (last == NULL) {
if (cat->value == first->value + 1) {
last = cat;
} else {
fprintf(out, "%s%s", lead, DATUM(first)->fqn);
lead = ",";
first = cat;
}
} else if (cat->value == last->value + 1) {
last = cat;
} else {
fprintf(out, "%s%s", lead, DATUM(first)->fqn);
lead = ",";
if (last->value >= first->value + 1) {
fprintf(out, ".");
} else {
fprintf(out, ",");
}
fprintf(out, "%s", DATUM(last)->fqn);
first = cat;
last = NULL;
}
}
if (first) {
fprintf(out, "%s%s", lead, DATUM(first)->fqn);
if (last != NULL) {
if (last->value >= first->value + 1) {
fprintf(out, ".");
} else {
fprintf(out, ",");
}
fprintf(out, "%s", DATUM(last)->fqn);
}
}
}
static void cil_level_to_policy(FILE *out, struct cil_level *level)
{
fprintf(out, "%s", DATUM(level->sens)->fqn);
if (level->cats != NULL) {
fprintf(out, ":");
cil_cats_to_policy(out, level->cats);
}
}
static int cil_levels_simple_and_equal(struct cil_level *l1, struct cil_level *l2)
{
/* Mostly just want to detect s0 - s0 ranges */
if (l1 == l2)
return CIL_TRUE;
if (l1->sens == l2->sens && (l1->cats == NULL && l2->cats == NULL))
return CIL_TRUE;
return CIL_FALSE;
}
static void cil_levelrange_to_policy(FILE *out, struct cil_levelrange *lvlrange)
{
cil_level_to_policy(out, lvlrange->low);
if (cil_levels_simple_and_equal(lvlrange->low, lvlrange->high) == CIL_FALSE) {
fprintf(out, " - ");
cil_level_to_policy(out, lvlrange->high);
}
}
static void cil_context_to_policy(FILE *out, struct cil_context *context, int mls)
{
fprintf(out, "%s:", DATUM(context->user)->fqn);
fprintf(out, "%s:", DATUM(context->role)->fqn);
fprintf(out, "%s", DATUM(context->type)->fqn);
if (mls) {
fprintf(out, ":");
cil_levelrange_to_policy(out, context->range);
}
}
static void cil_cond_expr_to_policy(FILE *out, struct cil_list *expr, int first)
{
struct cil_list_item *i1 = expr->head;
if (i1->flavor == CIL_OP) {
enum cil_flavor op = (enum cil_flavor)(uintptr_t)i1->data;
fprintf(out, "(");
switch (op) {
case CIL_NOT:
fprintf(out, "! ");
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
break;
case CIL_OR:
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
fprintf(out, " || ");
cil_cond_expr_to_policy(out, i1->next->next->data, CIL_FALSE);
break;
case CIL_AND:
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
fprintf(out, " && ");
cil_cond_expr_to_policy(out, i1->next->next->data, CIL_FALSE);
break;
case CIL_XOR:
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
fprintf(out, " ^ ");
cil_cond_expr_to_policy(out, i1->next->next->data, CIL_FALSE);
break;
case CIL_EQ:
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
fprintf(out, " == ");
cil_cond_expr_to_policy(out, i1->next->next->data, CIL_FALSE);
break;
case CIL_NEQ:
cil_cond_expr_to_policy(out, i1->next->data, CIL_FALSE);
fprintf(out, " != ");
cil_cond_expr_to_policy(out, i1->next->next->data, CIL_FALSE);
break;
default:
fprintf(out, "???");
break;
}
fprintf(out, ")");
} else if (i1->flavor == CIL_DATUM) {
if (first == CIL_TRUE) {
fprintf(out, "(");
}
fprintf(out, "%s", DATUM(i1->data)->fqn);
if (first == CIL_TRUE) {
fprintf(out, ")");
}
} else if (i1->flavor == CIL_LIST) {
cil_cond_expr_to_policy(out, i1->data, CIL_FALSE);
} else {
fprintf(out, "???");
}
}
static size_t __cil_userattribute_len(struct cil_db *db, struct cil_userattribute *attr)
{
ebitmap_node_t *unode;
unsigned int i;
size_t len = 0;
ebitmap_for_each_positive_bit(attr->users, unode, i) {
len += strlen(DATUM(db->val_to_user[i])->fqn);
len++;
}
return len;
}
static size_t __cil_cons_leaf_operand_len(struct cil_db *db, struct cil_list_item *operand)
{
struct cil_list_item *i1;
enum cil_flavor flavor = operand->flavor;
size_t len = 0;
if (flavor == CIL_CONS_OPERAND) {
len = 2;
} else if (flavor == CIL_DATUM) {
struct cil_tree_node *node = NODE(operand->data);
if (node->flavor == CIL_USERATTRIBUTE) {
len = __cil_userattribute_len(db, operand->data);
len++; /* "{" */
} else {
len = strlen(DATUM(operand->data)->fqn);
}
} else if (flavor == CIL_LIST) {
len = 1; /* "{" */
cil_list_for_each(i1, (struct cil_list *)operand->data) {
struct cil_tree_node *node = NODE(operand->data);
if (node->flavor == CIL_USERATTRIBUTE) {
len = __cil_userattribute_len(db, operand->data);
} else {
len += strlen(DATUM(operand->data)->fqn);
len++; /* " " or "}" */
}
}
}
return len;
}
static size_t __cil_cons_leaf_op_len(struct cil_list_item *op)
{
enum cil_flavor flavor = (enum cil_flavor)(uintptr_t)op->data;
size_t len;
switch (flavor) {
case CIL_EQ:
len = 4; /* " == " */
break;
case CIL_NEQ:
len = 4; /* " != " */
break;
case CIL_CONS_DOM:
len = 5; /* " dom " */
break;
case CIL_CONS_DOMBY:
len = 7; /* " domby " */
break;
case CIL_CONS_INCOMP:
len = 8; /* " incomp " */
break;
default:
/* Should be impossible to be here */
len = 5; /* " ??? " */
}
return len;
}
static size_t cil_cons_expr_len(struct cil_db *db, struct cil_list *cons_expr)
{
struct cil_list_item *i1;
enum cil_flavor op;
size_t len;
i1 = cons_expr->head;
op = (enum cil_flavor)(uintptr_t)i1->data;
switch (op) {
case CIL_NOT:
len = 6; /* "(not )" */
len += cil_cons_expr_len(db, i1->next->data);
break;
case CIL_AND:
len = 7; /* "( and )" */
len += cil_cons_expr_len(db, i1->next->data);
len += cil_cons_expr_len(db, i1->next->next->data);
break;
case CIL_OR:
len = 6; /* "( or )" */
len += cil_cons_expr_len(db, i1->next->data);
len += cil_cons_expr_len(db, i1->next->next->data);
break;
default:
len = 2; /* "()" */
len += __cil_cons_leaf_operand_len(db, i1->next);
len += __cil_cons_leaf_op_len(i1);
len += __cil_cons_leaf_operand_len(db, i1->next->next);
}
return len;
}
static char *__cil_userattribute_to_string(struct cil_db *db, struct cil_userattribute *attr, char *new)
{
ebitmap_node_t *unode;
unsigned int i;
char *str;
size_t len;
ebitmap_for_each_positive_bit(attr->users, unode, i) {
str = DATUM(db->val_to_user[i])->fqn;
len = strlen(str);
memcpy(new, str, len);
new += len;
*new++ = ' ';
}
return new;
}
static char *__cil_cons_leaf_operand_to_string(struct cil_db *db, struct cil_list_item *operand, char *new)
{
struct cil_list_item *i1;
enum cil_flavor flavor = operand->flavor;
const char *o_str;
size_t o_len;
if (flavor == CIL_CONS_OPERAND) {
enum cil_flavor o_flavor = (enum cil_flavor)(uintptr_t)operand->data;
switch (o_flavor) {
case CIL_CONS_U1:
o_str = "u1";
break;
case CIL_CONS_U2:
o_str = "u2";
break;
case CIL_CONS_U3:
o_str = "u3";
break;
case CIL_CONS_R1:
o_str = "r1";
break;
case CIL_CONS_R2:
o_str = "r2";
break;
case CIL_CONS_R3:
o_str = "r3";
break;
case CIL_CONS_T1:
o_str = "t1";
break;
case CIL_CONS_T2:
o_str = "t2";
break;
case CIL_CONS_T3:
o_str = "t3";
break;
case CIL_CONS_L1:
o_str = "l1";
break;
case CIL_CONS_L2:
o_str = "l2";
break;
case CIL_CONS_H1:
o_str = "h1";
break;
case CIL_CONS_H2:
o_str = "h2";
break;
default:
/* Impossible */
o_str = "??";
}
strcpy(new, o_str);
new += 2;
} else if (flavor == CIL_DATUM) {
struct cil_tree_node *node = NODE(operand->data);
if (node->flavor == CIL_USERATTRIBUTE) {
*new++ = '{';
new = __cil_userattribute_to_string(db, operand->data, new);
new--;
*new++ = '}';
} else {
o_str = DATUM(operand->data)->fqn;
o_len = strlen(o_str);
memcpy(new, o_str, o_len);
new += o_len;
}
} else if (flavor == CIL_LIST) {
*new++ = '{';
cil_list_for_each(i1, (struct cil_list *)operand->data) {
struct cil_tree_node *node = NODE(operand->data);
if (node->flavor == CIL_USERATTRIBUTE) {
new = __cil_userattribute_to_string(db, operand->data, new);
} else {
o_str = DATUM(operand->data)->fqn;
o_len = strlen(o_str);
memcpy(new, o_str, o_len);
new += o_len;
*new++ = ' ';
}
}
new--;
*new++ = '}';
}
return new;
}
static char *__cil_cons_leaf_op_to_string(struct cil_list_item *op, char *new)
{
enum cil_flavor flavor = (enum cil_flavor)(uintptr_t)op->data;
const char *op_str;
size_t len;
switch (flavor) {
case CIL_EQ:
op_str = " == ";
len = 4;
break;
case CIL_NEQ:
op_str = " != ";
len = 4;
break;
case CIL_CONS_DOM:
op_str = " dom ";
len = 5;
break;
case CIL_CONS_DOMBY:
op_str = " domby ";
len = 7;
break;
case CIL_CONS_INCOMP:
op_str = " incomp ";
len = 8;
break;
default:
/* Should be impossible to be here */
op_str = " ??? ";
len = 5;
}
strcpy(new, op_str);
new += len;
return new;
}
static char *__cil_cons_expr_to_string(struct cil_db *db, struct cil_list *cons_expr, char *new)
{
struct cil_list_item *i1;
enum cil_flavor op;
i1 = cons_expr->head;
op = (enum cil_flavor)(uintptr_t)i1->data;
switch (op) {
case CIL_NOT:
*new++ = '(';
strcpy(new, "not ");
new += 4;
new = __cil_cons_expr_to_string(db, i1->next->data, new);
*new++ = ')';
break;
case CIL_AND:
*new++ = '(';
new = __cil_cons_expr_to_string(db, i1->next->data, new);
strcpy(new, " and ");
new += 5;
new = __cil_cons_expr_to_string(db, i1->next->next->data, new);
*new++ = ')';
break;
case CIL_OR:
*new++ = '(';
new = __cil_cons_expr_to_string(db, i1->next->data, new);
strcpy(new, " or ");
new += 4;
new = __cil_cons_expr_to_string(db, i1->next->next->data, new);
*new++ = ')';
break;
default:
*new++ = '(';
new = __cil_cons_leaf_operand_to_string(db, i1->next, new);
new = __cil_cons_leaf_op_to_string(i1, new);
new = __cil_cons_leaf_operand_to_string(db, i1->next->next, new);
*new++ = ')';
}
return new;
}
static char *cil_cons_expr_to_string(struct cil_db *db, struct cil_list *cons_expr)
{
char *new, *tail;
size_t len = cil_cons_expr_len(db, cons_expr);
new = cil_malloc(len+1);
tail = __cil_cons_expr_to_string(db, cons_expr, new);
*tail = '\0';
return new;
}
static void cil_classperms_to_string(struct cil_classperms *classperms, struct cil_list *classperms_strs)
{
struct cil_list_item *i1;
size_t len = 0;
char *new, *curr;
len += strlen(DATUM(classperms->class)->fqn) + 1;
cil_list_for_each(i1, classperms->perms) {
len += strlen(DATUM(i1->data)->fqn) + 1;
}
len += 4; /* for "{ " and " }" */
new = cil_malloc(len);
curr = new;
curr[len-1] = '\0';
len = strlen(DATUM(classperms->class)->fqn);
memcpy(curr, DATUM(classperms->class)->fqn, len);
curr += len;
*curr++ = ' ';
*curr++ = '{';
*curr++ = ' ';
cil_list_for_each(i1, classperms->perms) {
len = strlen(DATUM(i1->data)->fqn);
memcpy(curr, DATUM(i1->data)->fqn, len);
curr += len;
*curr++ = ' ';
}
*curr++ = '}';
cil_list_append(classperms_strs, CIL_STRING, new);
}
static void cil_classperms_to_strings(struct cil_list *classperms, struct cil_list *classperms_strs)
{
struct cil_list_item *i1;
cil_list_for_each(i1, classperms) {
if (i1->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = i1->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
cil_classperms_to_string(cp, classperms_strs);
} else { /* MAP */
struct cil_list_item *i2 = NULL;
cil_list_for_each(i2, cp->perms) {
struct cil_perm *cmp = i2->data;
cil_classperms_to_strings(cmp->classperms, classperms_strs);
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = i1->data;
struct cil_classpermission *cp = cp_set->set;
cil_classperms_to_strings(cp->classperms, classperms_strs);
}
}
}
static void cil_class_decls_to_policy(FILE *out, struct cil_list *classorder)
{
struct cil_list_item *i1;
cil_list_for_each(i1, classorder) {
fprintf(out, "class %s\n", DATUM(i1->data)->fqn);
}
}
static void cil_sid_decls_to_policy(FILE *out, struct cil_list *sidorder)
{
struct cil_list_item *i1;
cil_list_for_each(i1, sidorder) {
fprintf(out, "sid %s\n", DATUM(i1->data)->fqn);
}
}
static void cil_commons_to_policy(FILE *out, struct cil_list *commons)
{
struct cil_list_item *i1;
struct cil_class* common;
struct cil_tree_node *node;
struct cil_tree_node *perm;
cil_list_for_each(i1, commons) {
common = i1->data;
node = NODE(&common->datum);
perm = node->cl_head;
fprintf(out, "common %s {", common->datum.fqn);
while (perm != NULL) {
fprintf(out, "%s ", DATUM(perm->data)->fqn);
perm = perm->next;
}
fprintf(out, "}\n");
}
}
static void cil_classes_to_policy(FILE *out, struct cil_list *classorder)
{
struct cil_list_item *i1;
struct cil_class *class;
struct cil_tree_node *node;
cil_list_for_each(i1, classorder) {
class = i1->data;
node = NODE(&class->datum);
fprintf(out, "class %s", class->datum.fqn);
if (class->common != NULL) {
fprintf(out, " inherits %s", class->common->datum.fqn);
}
if (node->cl_head != NULL) {
struct cil_tree_node *perm = node->cl_head;
fprintf(out, " {");
while (perm != NULL) {
fprintf(out, " %s", DATUM(perm->data)->fqn);
perm = perm->next;
}
fprintf(out, " }");
}
fprintf(out, "\n");
}
}
static void cil_defaults_to_policy(FILE *out, struct cil_list *defaults, const char *kind)
{
struct cil_list_item *i1, *i2, *i3;
struct cil_default *def;
struct cil_list *class_list;
cil_list_for_each(i1, defaults) {
def = i1->data;
fprintf(out, "%s {",kind);
cil_list_for_each(i2, def->class_datums) {
class_list = cil_expand_class(i2->data);
cil_list_for_each(i3, class_list) {
fprintf(out, " %s", DATUM(i3->data)->fqn);
}
cil_list_destroy(&class_list, CIL_FALSE);
}
fprintf(out, " }");
if (def->object == CIL_DEFAULT_SOURCE) {
fprintf(out," %s",CIL_KEY_SOURCE);
} else if (def->object == CIL_DEFAULT_TARGET) {
fprintf(out," %s",CIL_KEY_TARGET);
}
fprintf(out,";\n");
}
}
static void cil_default_ranges_to_policy(FILE *out, struct cil_list *defaults)
{
struct cil_list_item *i1, *i2, *i3;
struct cil_defaultrange *def;
struct cil_list *class_list;
cil_list_for_each(i1, defaults) {
def = i1->data;
fprintf(out, "default_range {");
cil_list_for_each(i2, def->class_datums) {
class_list = cil_expand_class(i2->data);
cil_list_for_each(i3, class_list) {
fprintf(out, " %s", DATUM(i3->data)->fqn);
}
cil_list_destroy(&class_list, CIL_FALSE);
}
fprintf(out, " }");
switch (def->object_range) {
case CIL_DEFAULT_SOURCE_LOW:
fprintf(out," %s %s", CIL_KEY_SOURCE, CIL_KEY_LOW);
break;
case CIL_DEFAULT_SOURCE_HIGH:
fprintf(out," %s %s", CIL_KEY_SOURCE, CIL_KEY_HIGH);
break;
case CIL_DEFAULT_SOURCE_LOW_HIGH:
fprintf(out," %s %s", CIL_KEY_SOURCE, CIL_KEY_LOW_HIGH);
break;
case CIL_DEFAULT_TARGET_LOW:
fprintf(out," %s %s", CIL_KEY_TARGET, CIL_KEY_LOW);
break;
case CIL_DEFAULT_TARGET_HIGH:
fprintf(out," %s %s", CIL_KEY_TARGET, CIL_KEY_HIGH);
break;
case CIL_DEFAULT_TARGET_LOW_HIGH:
fprintf(out," %s %s", CIL_KEY_TARGET, CIL_KEY_LOW_HIGH);
break;
case CIL_DEFAULT_GLBLUB:
fprintf(out," %s", CIL_KEY_GLBLUB);
break;
default:
break;
}
fprintf(out,";\n");
}
}
static void cil_sensitivities_to_policy(FILE *out, struct cil_list *sensorder, struct cil_list *all_aliases)
{
struct cil_list_item *i1, *i2;
struct cil_sens *sens;
struct cil_list *aliases = NULL;
struct cil_alias *alias;
struct cil_sens *actual;
int num_aliases;
cil_list_for_each(i1, sensorder) {
sens = i1->data;
num_aliases = 0;
cil_list_for_each(i2, all_aliases) {
alias = i2->data;
actual = alias->actual;
if (sens == actual) {
if (num_aliases == 0) {
cil_list_init(&aliases, CIL_LIST);
}
cil_list_append(aliases, CIL_SENSALIAS, alias);
num_aliases++;
}
}
fprintf(out, "sensitivity %s", sens->datum.fqn);
if (num_aliases > 0) {
fprintf(out, " alias");
if (num_aliases > 1) {
fprintf(out, " {");
}
cil_list_for_each(i2, aliases) {
alias = i2->data;
fprintf(out, " %s", alias->datum.fqn);
}
if (num_aliases > 1) {
fprintf(out, " }");
}
cil_list_destroy(&aliases, CIL_FALSE);
}
fprintf(out, ";\n");
}
}
static void cil_dominance_to_policy(FILE *out, struct cil_list *sensorder)
{
struct cil_list_item *item;
struct cil_sens *sens;
fprintf(out, "dominance {");
cil_list_for_each(item, sensorder) {
sens = item->data;
fprintf(out, " %s", sens->datum.fqn);
}
fprintf(out, " }\n");
}
static void cil_categories_to_policy(FILE *out, struct cil_list *catorder, struct cil_list *all_aliases)
{
struct cil_list_item *i1, *i2;
struct cil_sens *cat;
struct cil_list *aliases = NULL;
struct cil_alias *alias;
struct cil_sens *actual;
int num_aliases;
cil_list_for_each(i1, catorder) {
cat = i1->data;
num_aliases = 0;
cil_list_for_each(i2, all_aliases) {
alias = i2->data;
actual = alias->actual;
if (cat == actual) {
if (num_aliases == 0) {
cil_list_init(&aliases, CIL_LIST);
}
cil_list_append(aliases, CIL_CATALIAS, alias);
num_aliases++;
}
}
fprintf(out, "category %s",cat->datum.fqn);
if (num_aliases > 0) {
fprintf(out, " alias");
if (num_aliases > 1) {
fprintf(out, " { ");
}
cil_list_for_each(i2, aliases) {
alias = i2->data;
fprintf(out, " %s", alias->datum.fqn);
}
if (num_aliases > 1) {
fprintf(out, " }");
}
cil_list_destroy(&aliases, CIL_FALSE);
}
fprintf(out, ";\n");
}
}
static void cil_levels_to_policy(FILE *out, struct cil_list *sensorder)
{
struct cil_list_item *i1, *i2;
struct cil_sens *sens;
cil_list_for_each(i1, sensorder) {
sens = i1->data;
if (sens->cats_list) {
cil_list_for_each(i2, sens->cats_list) {
fprintf(out, "level %s:",sens->datum.fqn);
cil_cats_to_policy(out, i2->data);
fprintf(out,";\n");
}
} else {
fprintf(out, "level %s;\n",sens->datum.fqn);
}
}
}
static void cil_mlsconstrains_to_policy(FILE *out, struct cil_db *db, struct cil_list *mlsconstrains)
{
struct cil_list_item *i1, *i2;
struct cil_constrain *cons;
struct cil_list *classperms_strs;
char *cp_str;
char *expr_str;
cil_list_for_each(i1, mlsconstrains) {
cons = i1->data;
cil_list_init(&classperms_strs, CIL_LIST);
cil_classperms_to_strings(cons->classperms, classperms_strs);
expr_str = cil_cons_expr_to_string(db, cons->datum_expr);
cil_list_for_each(i2, classperms_strs) {
cp_str = i2->data;
fprintf(out, "mlsconstrain %s %s;\n", cp_str, expr_str);
free(cp_str);
}
free(expr_str);
cil_list_destroy(&classperms_strs, CIL_FALSE);
}
}
static void cil_validatetrans_to_policy(FILE *out, struct cil_db *db, struct cil_list *validatetrans, char *kind)
{
struct cil_list_item *i1, *i2;
struct cil_validatetrans *trans;
struct cil_list *class_list;
struct cil_class *class;
char *expr_str;
cil_list_for_each(i1, validatetrans) {
trans = i1->data;
class_list = cil_expand_class(trans->class);
expr_str = cil_cons_expr_to_string(db, trans->datum_expr);
cil_list_for_each(i2, class_list) {
class = i2->data;
fprintf(out, "%s %s %s;\n", kind, class->datum.fqn, expr_str);
}
free(expr_str);
cil_list_destroy(&class_list, CIL_FALSE);
}
}
static void cil_bools_to_policy(FILE *out, struct cil_list *bools)
{
struct cil_list_item *i1;
struct cil_bool *boolean;
const char *value;
cil_list_for_each(i1, bools) {
boolean = i1->data;
value = boolean->value ? "true" : "false";
fprintf(out, "bool %s %s;\n", boolean->datum.fqn, value);
}
}
static void cil_typealiases_to_policy(FILE *out, struct cil_list *types, struct cil_list *all_aliases)
{
struct cil_list_item *i1, *i2;
struct cil_type *type;
struct cil_list *aliases = NULL;
struct cil_alias *alias;
struct cil_type *actual;
int num_aliases;
cil_list_for_each(i1, types) {
type = i1->data;
num_aliases = 0;
cil_list_for_each(i2, all_aliases) {
alias = i2->data;
actual = alias->actual;
if (type == actual) {
if (num_aliases == 0) {
cil_list_init(&aliases, CIL_LIST);
}
cil_list_append(aliases, CIL_TYPEALIAS, alias);
num_aliases++;
}
}
if (num_aliases > 0) {
fprintf(out, "typealias %s alias", type->datum.fqn);
if (num_aliases > 1) {
fprintf(out, " {");
}
cil_list_for_each(i2, aliases) {
alias = i2->data;
fprintf(out, " %s", alias->datum.fqn);
}
if (num_aliases > 1) {
fprintf(out, " }");
}
fprintf(out, ";\n");
cil_list_destroy(&aliases, CIL_FALSE);
}
}
}
static void cil_typebounds_to_policy(FILE *out, struct cil_list *types)
{
struct cil_list_item *i1;
struct cil_type *child;
struct cil_type *parent;
cil_list_for_each(i1, types) {
child = i1->data;
if (child->bounds != NULL) {
parent = child->bounds;
fprintf(out, "typebounds %s %s;\n", parent->datum.fqn, child->datum.fqn);
}
}
}
static void cil_typeattributes_to_policy(FILE *out, struct cil_list *types, struct cil_list *attributes)
{
struct cil_list_item *i1, *i2;
struct cil_type *type;
struct cil_typeattribute *attribute;
int first = CIL_TRUE;
cil_list_for_each(i1, types) {
type = i1->data;
cil_list_for_each(i2, attributes) {
attribute = i2->data;
if (!attribute->keep)
continue;
if (ebitmap_get_bit(attribute->types, type->value)) {
if (first) {
fprintf(out, "typeattribute %s %s", type->datum.fqn, attribute->datum.fqn);
first = CIL_FALSE;
} else {
fprintf(out, ", %s", attribute->datum.fqn);
}
}
}
if (!first) {
fprintf(out, ";\n");
first = CIL_TRUE;
}
}
}
static void cil_xperms_to_policy(FILE *out, struct cil_permissionx *permx)
{
ebitmap_node_t *node;
unsigned int i, first = 0, last = 0;
int need_first = CIL_TRUE, need_last = CIL_TRUE;
const char *kind;
if (permx->kind == CIL_PERMX_KIND_IOCTL) {
kind = "ioctl";
} else if (permx->kind == CIL_PERMX_KIND_NLMSG) {
kind = "nlmsg";
} else {
kind = "???";
}
fprintf(out, "%s %s {", DATUM(permx->obj)->fqn, kind);
ebitmap_for_each_positive_bit(permx->perms, node, i) {
if (need_first == CIL_TRUE) {
first = i;
need_first = CIL_FALSE;
} else if (need_last == CIL_TRUE) {
if (i == first+1) {
last = i;
need_last = CIL_FALSE;
} else {
fprintf(out, " 0x%x", first);
first = i;
}
} else if (i == last+1) {
last = i;
} else {
if (last > first+1) {
fprintf(out, " 0x%x-0x%x", first, last);
} else {
fprintf(out, " 0x%x 0x%x", first, last);
}
first = i;
need_last = CIL_TRUE;
}
}
if (need_first == CIL_FALSE) {
if (need_last == CIL_FALSE) {
fprintf(out, " 0x%x-0x%x", first, last);
} else {
fprintf(out, " 0x%x", first);
}
}
fprintf(out," }");
}
static void cil_av_rulex_to_policy(FILE *out, struct cil_avrule *rule)
{
const char *kind;
struct cil_symtab_datum *src, *tgt;
src = rule->src;
tgt = rule->tgt;
switch (rule->rule_kind) {
case CIL_AVRULE_ALLOWED:
kind = "allowxperm";
break;
case CIL_AVRULE_AUDITALLOW:
kind = "auditallowxperm";
break;
case CIL_AVRULE_DONTAUDIT:
kind = "dontauditxperm";
break;
case CIL_AVRULE_NEVERALLOW:
kind = "neverallowxperm";
break;
default:
kind = "???";
break;
}
fprintf(out, "%s %s %s : ", kind, src->fqn, tgt->fqn);
cil_xperms_to_policy(out, rule->perms.x.permx);
fprintf(out, ";\n");
}
static void cil_av_rule_to_policy(FILE *out, struct cil_avrule *rule)
{
const char *kind;
struct cil_symtab_datum *src, *tgt;
struct cil_list *classperms_strs;
struct cil_list_item *i1;
src = rule->src;
tgt = rule->tgt;
switch (rule->rule_kind) {
case CIL_AVRULE_ALLOWED:
kind = "allow";
break;
case CIL_AVRULE_AUDITALLOW:
kind = "auditallow";
break;
case CIL_AVRULE_DONTAUDIT:
kind = "dontaudit";
break;
case CIL_AVRULE_NEVERALLOW:
kind = "neverallow";
break;
default:
kind = "???";
break;
}
cil_list_init(&classperms_strs, CIL_LIST);
cil_classperms_to_strings(rule->perms.classperms, classperms_strs);
cil_list_for_each(i1, classperms_strs) {
char *cp_str = i1->data;
fprintf(out, "%s %s %s : %s;\n", kind, src->fqn, tgt->fqn, cp_str);
free(cp_str);
}
cil_list_destroy(&classperms_strs, CIL_FALSE);
}
static void cil_type_rule_to_policy(FILE *out, struct cil_type_rule *rule)
{
const char *kind;
struct cil_symtab_datum *src, *tgt, *res;
struct cil_list *class_list;
struct cil_list_item *i1;
src = rule->src;
tgt = rule->tgt;
res = rule->result;
switch (rule->rule_kind) {
case CIL_TYPE_TRANSITION:
kind = "type_transition";
break;
case CIL_TYPE_MEMBER:
kind = "type_member";
break;
case CIL_TYPE_CHANGE:
kind = "type_change";
break;
default:
kind = "???";
break;
}
class_list = cil_expand_class(rule->obj);
cil_list_for_each(i1, class_list) {
fprintf(out, "%s %s %s : %s %s;\n", kind, src->fqn, tgt->fqn, DATUM(i1->data)->fqn, res->fqn);
}
cil_list_destroy(&class_list, CIL_FALSE);
}
static void cil_nametypetransition_to_policy(FILE *out, struct cil_nametypetransition *trans)
{
struct cil_symtab_datum *src, *tgt, *name, *res;
struct cil_list *class_list;
struct cil_list_item *i1;
src = trans->src;
tgt = trans->tgt;
name = trans->name;
res = trans->result;
class_list = cil_expand_class(trans->obj);
cil_list_for_each(i1, class_list) {
fprintf(out, "type_transition %s %s : %s %s \"%s\";\n", src->fqn, tgt->fqn, DATUM(i1->data)->fqn, res->fqn, name->fqn);
}
cil_list_destroy(&class_list, CIL_FALSE);
}
static void cil_rangetransition_to_policy(FILE *out, struct cil_rangetransition *trans)
{
struct cil_symtab_datum *src, *exec;
struct cil_list *class_list;
struct cil_list_item *i1;
src = trans->src;
exec = trans->exec;
class_list = cil_expand_class(trans->obj);
cil_list_for_each(i1, class_list) {
fprintf(out, "range_transition %s %s : %s ", src->fqn, exec->fqn, DATUM(i1->data)->fqn);
cil_levelrange_to_policy(out, trans->range);
fprintf(out, ";\n");
}
cil_list_destroy(&class_list, CIL_FALSE);
}
static void cil_typepermissive_to_policy(FILE *out, struct cil_typepermissive *rule)
{
fprintf(out, "permissive %s;\n", DATUM(rule->type)->fqn);
}
struct block_te_rules_extra {
FILE *out;
enum cil_flavor flavor;
uint32_t rule_kind;
};
static int __cil_block_te_rules_to_policy_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct block_te_rules_extra *args = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_BOOLEANIF:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_AVRULE:
case CIL_AVRULEX:
if (args->flavor == node->flavor) {
struct cil_avrule *rule = node->data;
if (args->rule_kind == rule->rule_kind) {
if (rule->is_extended) {
cil_av_rulex_to_policy(args->out, rule);
} else {
cil_av_rule_to_policy(args->out, rule);
}
}
}
break;
case CIL_TYPE_RULE:
if (args->flavor == node->flavor) {
struct cil_type_rule *rule = node->data;
if (args->rule_kind == rule->rule_kind) {
cil_type_rule_to_policy(args->out, rule);
}
}
break;
case CIL_NAMETYPETRANSITION:
if (args->flavor == node->flavor) {
cil_nametypetransition_to_policy(args->out, node->data);
}
break;
case CIL_RANGETRANSITION:
if (args->flavor == node->flavor) {
cil_rangetransition_to_policy(args->out, node->data);
}
break;
case CIL_TYPEPERMISSIVE:
if (args->flavor == node->flavor) {
cil_typepermissive_to_policy(args->out, node->data);
}
break;
default:
break;
}
return SEPOL_OK;
}
static void cil_block_te_rules_to_policy(FILE *out, struct cil_tree_node *start, int mls)
{
struct block_te_rules_extra args;
args.out = out;
args.flavor = CIL_TYPEPERMISSIVE;
args.rule_kind = 0;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.flavor = CIL_AVRULE;
args.rule_kind = CIL_AVRULE_ALLOWED;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_AUDITALLOW;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_DONTAUDIT;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_NEVERALLOW;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.flavor = CIL_AVRULEX;
args.rule_kind = CIL_AVRULE_ALLOWED;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_AUDITALLOW;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_DONTAUDIT;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_NEVERALLOW;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.flavor = CIL_TYPE_RULE;
args.rule_kind = CIL_TYPE_TRANSITION;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_TYPE_MEMBER;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_TYPE_CHANGE;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.rule_kind = CIL_AVRULE_TYPE;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
args.flavor = CIL_NAMETYPETRANSITION;
args.rule_kind = 0;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
if (mls == CIL_TRUE) {
args.flavor = CIL_RANGETRANSITION;
args.rule_kind = 0;
cil_tree_walk(start, __cil_block_te_rules_to_policy_helper, NULL, NULL, &args);
}
}
struct te_rules_extra {
FILE *out;
int mls;
};
static int __cil_te_rules_to_policy_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct te_rules_extra *args = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_BOOLEANIF: {
struct cil_booleanif *boolean = node->data;
struct cil_tree_node *n;
struct cil_condblock *cb;
fprintf(args->out, "if ");
cil_cond_expr_to_policy(args->out, boolean->datum_expr, CIL_TRUE);
fprintf(args->out," {\n");
n = node->cl_head;
cb = n != NULL ? n->data : NULL;
if (cb && cb->flavor == CIL_CONDTRUE) {
cil_block_te_rules_to_policy(args->out, n, args->mls);
n = n->next;
cb = n != NULL ? n->data : NULL;
}
if (cb && cb->flavor == CIL_CONDFALSE) {
fprintf(args->out,"} else {\n");
cil_block_te_rules_to_policy(args->out, n, args->mls);
}
fprintf(args->out,"}\n");
*finished = CIL_TREE_SKIP_HEAD;
break;
}
default:
break;
}
return SEPOL_OK;
}
static void cil_te_rules_to_policy(FILE *out, struct cil_tree_node *head, int mls)
{
struct te_rules_extra args;
args.out = out;
args.mls = mls;
cil_block_te_rules_to_policy(out, head, mls);
cil_tree_walk(head, __cil_te_rules_to_policy_helper, NULL, NULL, &args);
}
static void cil_roles_to_policy(FILE *out, struct cil_list *rules)
{
struct cil_list_item *i1;
struct cil_role *role;
cil_list_for_each(i1, rules) {
role = i1->data;
if (strcmp(role->datum.fqn,"object_r") == 0)
continue;
fprintf(out, "role %s;\n", role->datum.fqn);
}
}
static void cil_role_types_to_policy(FILE *out, struct cil_list *roles, struct cil_list *types)
{
struct cil_list_item *i1, *i2;
struct cil_role *role;
struct cil_type *type;
int first = CIL_TRUE;
cil_list_for_each(i1, roles) {
role = i1->data;
if (strcmp(role->datum.fqn,"object_r") == 0)
continue;
if (role->types) {
cil_list_for_each(i2, types) {
type = i2->data;
if (ebitmap_get_bit(role->types, type->value)) {
if (first) {
fprintf(out, "role %s types { %s", role->datum.fqn, type->datum.fqn);
first = CIL_FALSE;
} else {
fprintf(out, " %s", type->datum.fqn);
}
}
}
if (!first) {
fprintf(out, " }");
first = CIL_TRUE;
}
fprintf(out, ";\n");
}
}
}
static void cil_roleattributes_to_policy(FILE *out, struct cil_list *roles, struct cil_list *attributes)
{
struct cil_list_item *i1, *i2;
struct cil_role *role;
struct cil_roleattribute *attribute;
int first = CIL_TRUE;
cil_list_for_each(i1, roles) {
role = i1->data;
if (strcmp(role->datum.fqn,"object_r") == 0)
continue;
cil_list_for_each(i2, attributes) {
attribute = i2->data;
if (ebitmap_get_bit(attribute->roles, role->value)) {
if (first) {
fprintf(out, "roleattribute %s %s", role->datum.fqn, attribute->datum.fqn);
first = CIL_FALSE;
} else {
fprintf(out, ", %s", attribute->datum.fqn);
}
}
}
if (!first) {
fprintf(out, ";\n");
first = CIL_TRUE;
}
}
}
static void cil_roleallows_to_policy(FILE *out, struct cil_list *roleallows)
{
struct cil_list_item *i1;
struct cil_roleallow *allow;
cil_list_for_each(i1, roleallows) {
allow = i1->data;
fprintf(out, "allow %s %s;\n", DATUM(allow->src)->fqn, DATUM(allow->tgt)->fqn);
}
}
static void cil_roletransitions_to_policy(FILE *out, struct cil_list *roletransitions)
{
struct cil_list_item *i1, *i2;
struct cil_list *class_list;
struct cil_roletransition *trans;
cil_list_for_each(i1, roletransitions) {
trans = i1->data;
class_list = cil_expand_class(trans->obj);
cil_list_for_each(i2, class_list) {
fprintf(out, "role_transition %s %s : %s %s;\n", DATUM(trans->src)->fqn, DATUM(trans->tgt)->fqn, DATUM(i2->data)->fqn, DATUM(trans->result)->fqn);
}
cil_list_destroy(&class_list, CIL_FALSE);
}
}
static void cil_users_to_policy(FILE *out, int mls, struct cil_list *users, struct cil_list *all_roles)
{
struct cil_list_item *i1, *i2;
struct cil_user *user;
struct cil_list *roles = NULL;
struct cil_role *role;
int num_roles;
cil_list_for_each(i1, users) {
user = i1->data;
num_roles = 0;
fprintf(out, "user %s",user->datum.fqn);
cil_list_for_each(i2, all_roles) {
role = i2->data;
if (ebitmap_get_bit(user->roles, role->value)) {
if (num_roles == 0) {
cil_list_init(&roles, CIL_LIST);
}
cil_list_append(roles, CIL_ROLE, role);
num_roles++;
}
}
if (num_roles > 0) {
fprintf(out, " roles");
if (num_roles > 1) {
fprintf(out, " {");
}
cil_list_for_each(i2, roles) {
role = i2->data;
fprintf(out, " %s", role->datum.fqn);
}
if (num_roles > 1) {
fprintf(out, " }");
}
cil_list_destroy(&roles, CIL_FALSE);
}
if (mls == CIL_TRUE && user->dftlevel != NULL) {
fprintf(out, " level ");
cil_level_to_policy(out, user->dftlevel);
}
if (mls == CIL_TRUE && user->range != NULL) {
fprintf(out, " range ");
cil_levelrange_to_policy(out, user->range);
}
fprintf(out,";\n");
}
}
static void cil_constrains_to_policy(FILE *out, struct cil_db *db, struct cil_list *constrains)
{
struct cil_list_item *i1, *i2;
struct cil_constrain *cons;
struct cil_list *classperms_strs;
char *cp_str;
char *expr_str;
cil_list_for_each(i1, constrains) {
cons = i1->data;
cil_list_init(&classperms_strs, CIL_LIST);
cil_classperms_to_strings(cons->classperms, classperms_strs);
expr_str = cil_cons_expr_to_string(db, cons->datum_expr);
cil_list_for_each(i2, classperms_strs) {
cp_str = i2->data;
fprintf(out, "constrain %s %s;\n",cp_str, expr_str);
free(cp_str);
}
free(expr_str);
cil_list_destroy(&classperms_strs, CIL_FALSE);
}
}
static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mls)
{
struct cil_list_item *i1;
struct cil_sid *sid;
cil_list_for_each(i1, sids) {
sid = i1->data;
if (sid->context) {
fprintf(out, "sid %s ", sid->datum.fqn);
cil_context_to_policy(out, sid->context, mls);
fprintf(out,"\n");
}
}
}
static void cil_fsuses_to_policy(FILE *out, struct cil_sort *fsuses, int mls)
{
unsigned i;
struct cil_fsuse *fsuse;
for (i=0; icount; i++) {
fsuse = fsuses->array[i];
if (fsuse->type == CIL_FSUSE_XATTR) {
fprintf(out, "fs_use_xattr %s ", fsuse->fs_str);
cil_context_to_policy(out, fsuse->context, mls);
fprintf(out,";\n");
}
}
for (i=0; icount; i++) {
fsuse = fsuses->array[i];
if (fsuse->type == CIL_FSUSE_TASK) {
fprintf(out, "fs_use_task %s ", fsuse->fs_str);
cil_context_to_policy(out, fsuse->context, mls);
fprintf(out,";\n");
}
}
for (i=0; icount; i++) {
fsuse = fsuses->array[i];
if (fsuse->type == CIL_FSUSE_TRANS) {
fprintf(out, "fs_use_trans %s ", fsuse->fs_str);
cil_context_to_policy(out, fsuse->context, mls);
fprintf(out,";\n");
}
}
}
static void cil_genfscons_to_policy(FILE *out, struct cil_sort *genfscons, int mls)
{
unsigned i;
struct cil_genfscon *genfscon;
for (i=0; icount; i++) {
genfscon = genfscons->array[i];
fprintf(out, "genfscon %s %s ", genfscon->fs_str, genfscon->path_str);
cil_context_to_policy(out, genfscon->context, mls);
fprintf(out, "\n");
}
}
static void cil_ibpkeycons_to_policy(FILE *out, struct cil_sort *ibpkeycons, int mls)
{
uint32_t i = 0;
for (i = 0; i < ibpkeycons->count; i++) {
struct cil_ibpkeycon *ibpkeycon = (struct cil_ibpkeycon *)ibpkeycons->array[i];
fprintf(out, "ibpkeycon %s ", ibpkeycon->subnet_prefix_str);
fprintf(out, "%d ", ibpkeycon->pkey_low);
fprintf(out, "%d ", ibpkeycon->pkey_high);
cil_context_to_policy(out, ibpkeycon->context, mls);
fprintf(out, "\n");
}
}
static void cil_ibendportcons_to_policy(FILE *out, struct cil_sort *ibendportcons, int mls)
{
uint32_t i;
for (i = 0; i < ibendportcons->count; i++) {
struct cil_ibendportcon *ibendportcon = (struct cil_ibendportcon *)ibendportcons->array[i];
fprintf(out, "ibendportcon %s ", ibendportcon->dev_name_str);
fprintf(out, "%u ", ibendportcon->port);
cil_context_to_policy(out, ibendportcon->context, mls);
fprintf(out, "\n");
}
}
static void cil_portcons_to_policy(FILE *out, struct cil_sort *portcons, int mls)
{
unsigned i;
struct cil_portcon *portcon;
for (i=0; icount; i++) {
portcon = portcons->array[i];
fprintf(out, "portcon ");
if (portcon->proto == CIL_PROTOCOL_UDP) {
fprintf(out, "udp ");
} else if (portcon->proto == CIL_PROTOCOL_TCP) {
fprintf(out, "tcp ");
} else if (portcon->proto == CIL_PROTOCOL_DCCP) {
fprintf(out, "dccp ");
} else if (portcon->proto == CIL_PROTOCOL_SCTP) {
fprintf(out, "sctp ");
}
if (portcon->port_low == portcon->port_high) {
fprintf(out, "%d ", portcon->port_low);
} else {
fprintf(out, "%d-%d ", portcon->port_low, portcon->port_high);
}
cil_context_to_policy(out, portcon->context, mls);
fprintf(out, "\n");
}
}
static void cil_netifcons_to_policy(FILE *out, struct cil_sort *netifcons, int mls)
{
unsigned i;
struct cil_netifcon *netifcon;
for (i=0; icount; i++) {
netifcon = netifcons->array[i];
fprintf(out, "netifcon %s ", netifcon->interface_str);
cil_context_to_policy(out, netifcon->if_context, mls);
fprintf(out, " ");
cil_context_to_policy(out, netifcon->packet_context, mls);
fprintf(out, "\n");
}
}
static void cil_nodecons_to_policy(FILE *out, struct cil_sort *nodecons, int mls)
{
unsigned i;
struct cil_nodecon *nodecon;
char *addr, *mask;
for (i=0; icount; i++) {
nodecon = nodecons->array[i];
fprintf(out, "nodecon ");
if (nodecon->addr->family == AF_INET) {
errno = 0;
addr = cil_malloc(INET_ADDRSTRLEN);
inet_ntop(nodecon->addr->family, &nodecon->addr->ip.v4, addr, INET_ADDRSTRLEN);
if (errno == 0) {
fprintf(out, "%s ",addr);
} else {
fprintf(out, "[INVALID] ");
}
free(addr);
errno = 0;
mask = cil_malloc(INET_ADDRSTRLEN);
inet_ntop(nodecon->mask->family, &nodecon->mask->ip.v4, mask, INET_ADDRSTRLEN);
if (errno == 0) {
fprintf(out, "%s ",mask);
} else {
fprintf(out, "[INVALID] ");
}
free(mask);
} else {
errno = 0;
addr = cil_malloc(INET6_ADDRSTRLEN);
inet_ntop(nodecon->addr->family, &nodecon->addr->ip.v6, addr, INET6_ADDRSTRLEN);
if (errno == 0) {
fprintf(out, "%s ",addr);
} else {
fprintf(out, "[INVALID] ");
}
free(addr);
errno = 0;
mask = cil_malloc(INET6_ADDRSTRLEN);
inet_ntop(nodecon->mask->family, &nodecon->mask->ip.v6, mask, INET6_ADDRSTRLEN);
if (errno == 0) {
fprintf(out, "%s ",mask);
} else {
fprintf(out, "[INVALID] ");
}
free(mask);
}
cil_context_to_policy(out, nodecon->context, mls);
fprintf(out, "\n");
}
}
static void cil_pirqcons_to_policy(FILE *out, struct cil_sort *pirqcons, int mls)
{
unsigned i;
struct cil_pirqcon *pirqcon;
for (i = 0; icount; i++) {
pirqcon = pirqcons->array[i];
fprintf(out, "pirqcon %d ", pirqcon->pirq);
cil_context_to_policy(out, pirqcon->context, mls);
fprintf(out, ";\n");
}
}
static void cil_iomemcons_to_policy(FILE *out, struct cil_sort *iomemcons, int mls)
{
unsigned i;
struct cil_iomemcon *iomemcon;
for (i = 0; icount; i++) {
iomemcon = iomemcons->array[i];
if (iomemcon->iomem_low == iomemcon->iomem_high) {
fprintf(out, "iomemcon %"PRIx64" ", iomemcon->iomem_low);
} else {
fprintf(out, "iomemcon %"PRIx64"-%"PRIx64" ", iomemcon->iomem_low, iomemcon->iomem_high);
}
cil_context_to_policy(out, iomemcon->context, mls);
fprintf(out, ";\n");
}
}
static void cil_ioportcons_to_policy(FILE *out, struct cil_sort *ioportcons, int mls)
{
unsigned i;
struct cil_ioportcon *ioportcon;
for (i = 0; i < ioportcons->count; i++) {
ioportcon = ioportcons->array[i];
fprintf(out, "ioportcon 0x%x-0x%x ", ioportcon->ioport_low, ioportcon->ioport_high);
cil_context_to_policy(out, ioportcon->context, mls);
fprintf(out, ";\n");
}
}
static void cil_pcidevicecons_to_policy(FILE *out, struct cil_sort *pcidevicecons, int mls)
{
unsigned i;
struct cil_pcidevicecon *pcidevicecon;
for (i = 0; i < pcidevicecons->count; i++) {
pcidevicecon = pcidevicecons->array[i];
fprintf(out, "pcidevicecon 0x%x ", pcidevicecon->dev);
cil_context_to_policy(out, pcidevicecon->context, mls);
fprintf(out, ";\n");
}
}
static void cil_devicetreecons_to_policy(FILE *out, struct cil_sort *devicetreecons, int mls)
{
unsigned i;
struct cil_devicetreecon *devicetreecon;
for (i = 0; i < devicetreecons->count; i++) {
devicetreecon = devicetreecons->array[i];
fprintf(out, "devicetreecon %s ", devicetreecon->path);
cil_context_to_policy(out, devicetreecon->context, mls);
fprintf(out, ";\n");
}
}
void cil_gen_policy(FILE *out, struct cil_db *db)
{
unsigned i;
struct cil_tree_node *head = db->ast->root;
struct cil_list *lists[CIL_LIST_NUM_LISTS];
for (i=0; iclassorder);
cil_sid_decls_to_policy(out, db->sidorder);
cil_commons_to_policy(out, lists[CIL_LIST_COMMON]);
cil_classes_to_policy(out, db->classorder);
cil_defaults_to_policy(out, lists[CIL_LIST_DEFAULT_USER], "default_user");
cil_defaults_to_policy(out, lists[CIL_LIST_DEFAULT_ROLE], "default_role");
cil_defaults_to_policy(out, lists[CIL_LIST_DEFAULT_TYPE], "default_type");
if (db->mls == CIL_TRUE) {
cil_default_ranges_to_policy(out, lists[CIL_LIST_DEFAULT_RANGE]);
cil_sensitivities_to_policy(out, db->sensitivityorder, lists[CIL_LIST_SENSALIAS]);
cil_dominance_to_policy(out, db->sensitivityorder);
cil_categories_to_policy(out, db->catorder, lists[CIL_LIST_CATALIAS]);
cil_levels_to_policy(out, db->sensitivityorder);
cil_mlsconstrains_to_policy(out, db, lists[CIL_LIST_MLSCONSTRAIN]);
cil_validatetrans_to_policy(out, db, lists[CIL_LIST_MLSVALIDATETRANS], CIL_KEY_MLSVALIDATETRANS);
}
cil_simple_rules_to_policy(out, lists[CIL_LIST_POLICYCAP], CIL_KEY_POLICYCAP);
cil_simple_rules_to_policy(out, lists[CIL_LIST_TYPEATTRIBUTE], "attribute");
cil_simple_rules_to_policy(out, lists[CIL_LIST_ROLEATTRIBUTE], "attribute_role");
cil_bools_to_policy(out, lists[CIL_LIST_BOOL]);
cil_simple_rules_to_policy(out, lists[CIL_LIST_TYPE], "type");
cil_typealiases_to_policy(out, lists[CIL_LIST_TYPE], lists[CIL_LIST_TYPEALIAS]);
cil_typebounds_to_policy(out, lists[CIL_LIST_TYPE]);
cil_typeattributes_to_policy(out, lists[CIL_LIST_TYPE], lists[CIL_LIST_TYPEATTRIBUTE]);
cil_te_rules_to_policy(out, head, db->mls);
cil_roles_to_policy(out, lists[CIL_LIST_ROLE]);
cil_role_types_to_policy(out, lists[CIL_LIST_ROLE], lists[CIL_LIST_TYPE]);
cil_roleattributes_to_policy(out, lists[CIL_LIST_ROLE], lists[CIL_LIST_ROLEATTRIBUTE]);
cil_roleallows_to_policy(out, lists[CIL_LIST_ROLEALLOW]);
cil_roletransitions_to_policy(out, lists[CIL_LIST_ROLETRANSITION]);
cil_users_to_policy(out, db->mls, lists[CIL_LIST_USER], lists[CIL_LIST_ROLE]);
cil_constrains_to_policy(out, db, lists[CIL_LIST_CONSTRAINT]);
cil_validatetrans_to_policy(out, db, lists[CIL_LIST_VALIDATETRANS], CIL_KEY_VALIDATETRANS);
cil_sid_contexts_to_policy(out, db->sidorder, db->mls);
cil_fsuses_to_policy(out, db->fsuse, db->mls);
cil_genfscons_to_policy(out, db->genfscon, db->mls);
cil_portcons_to_policy(out, db->portcon, db->mls);
cil_netifcons_to_policy(out, db->netifcon, db->mls);
cil_ibpkeycons_to_policy(out, db->ibpkeycon, db->mls);
cil_ibendportcons_to_policy(out, db->ibendportcon, db->mls);
cil_nodecons_to_policy(out, db->nodecon, db->mls);
cil_pirqcons_to_policy(out, db->pirqcon, db->mls);
cil_iomemcons_to_policy(out, db->iomemcon, db->mls);
cil_ioportcons_to_policy(out, db->ioportcon, db->mls);
cil_pcidevicecons_to_policy(out, db->pcidevicecon, db->mls);
cil_devicetreecons_to_policy(out, db->devicetreecon, db->mls);
for (i=0; i
#include
#include
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_post.h"
#include "cil_policy.h"
#include "cil_verify.h"
#include "cil_symtab.h"
#include "cil_deny.h"
#define GEN_REQUIRE_ATTR "cil_gen_require" /* Also in libsepol/src/module_to_cil.c */
#define TYPEATTR_INFIX "_typeattr_" /* Also in libsepol/src/module_to_cil.c */
#define spaceship_cmp(a, b) (((a) > (b)) - ((a) < (b)))
struct fc_data {
unsigned int meta;
size_t stem_len;
size_t str_len;
};
static int __cil_expr_to_bitmap(struct cil_list *expr, ebitmap_t *out, int max, struct cil_db *db);
static int __cil_expr_list_to_bitmap(struct cil_list *expr_list, ebitmap_t *out, int max, struct cil_db *db);
static int cats_compare(struct cil_cats *a, struct cil_cats *b)
{
struct cil_list_item *i, *j;
int rc;
if (a == b) return 0;
if (!a) return -1;
if (!b) return 1;
/* Expects cat expression to have been evaluated */
cil_list_for_each(i, a->datum_expr) {
cil_list_for_each(j, b->datum_expr) {
rc = strcmp(DATUM(i->data)->fqn, DATUM(j->data)->fqn);
if (!rc) return rc;
}
}
return 0;
}
static int level_compare(struct cil_level *a, struct cil_level *b)
{
int rc;
if (a == b) return 0;
if (!a) return -1;
if (!b) return 1;
if (a->sens != b->sens) {
rc = strcmp(DATUM(a->sens)->fqn, DATUM(b->sens)->fqn);
if (rc != 0) return rc;
}
if (a->cats != b->cats) {
return cats_compare(a->cats, b->cats);
}
return 0;
}
static int range_compare(struct cil_levelrange *a, struct cil_levelrange *b)
{
int rc;
if (a == b) return 0;
if (!a) return -1;
if (!b) return 1;
if (a->low != b->low) {
rc = level_compare(a->low, b->low);
if (rc != 0) return rc;
}
if (a->high != b->high) {
return level_compare(a->high, b->high);
}
return 0;
}
static int context_compare(struct cil_context *a, struct cil_context *b)
{
int rc;
if (a->user != b->user) {
rc = strcmp(DATUM(a->user)->fqn, DATUM(b->user)->fqn);
if (rc != 0) return rc;
}
if (a->role != b->role) {
rc = strcmp(DATUM(a->role)->fqn, DATUM(b->role)->fqn);
if (rc != 0) return rc;
}
if (a->type != b->type) {
rc = strcmp(DATUM(a->type)->fqn, DATUM(b->type)->fqn);
if (rc != 0) return rc;
}
if (a->range != b->range) {
return range_compare(a->range, b->range);
}
return 0;
}
static int cil_verify_is_list(struct cil_list *list, enum cil_flavor flavor)
{
struct cil_list_item *curr;
cil_list_for_each(curr, list) {
switch (curr->flavor) {
case CIL_LIST:
return CIL_FALSE;
break;
case CIL_OP:
return CIL_FALSE;
break;
default:
if (flavor == CIL_CAT) {
struct cil_symtab_datum *d = curr->data;
struct cil_tree_node *n = d->nodes->head->data;
if (n->flavor == CIL_CATSET) {
return CIL_FALSE;
}
}
break;
}
}
return CIL_TRUE;
}
static void cil_post_fc_fill_data(struct fc_data *fc, const char *path)
{
size_t c = 0;
fc->meta = 0;
fc->stem_len = 0;
fc->str_len = 0;
while (path[c] != '\0') {
switch (path[c]) {
case '.':
case '^':
case '$':
case '?':
case '*':
case '+':
case '|':
case '[':
case '(':
case '{':
fc->meta = 1;
break;
case '\\':
c++;
if (path[c] == '\0') {
if (!fc->meta) {
fc->stem_len++;
}
fc->str_len++;
return;
}
/* FALLTHRU */
default:
if (!fc->meta) {
fc->stem_len++;
}
break;
}
fc->str_len++;
c++;
}
}
int cil_post_filecon_compare(const void *a, const void *b)
{
int rc = 0;
struct cil_filecon *a_filecon = *(struct cil_filecon**)a;
struct cil_filecon *b_filecon = *(struct cil_filecon**)b;
struct fc_data *a_data = cil_malloc(sizeof(*a_data));
struct fc_data *b_data = cil_malloc(sizeof(*b_data));
char *a_path_str, *a_path, *b_path_str, *b_path;
a_path_str = a_filecon->path ? DATUM(a_filecon->path)->fqn : a_filecon->path_str;
b_path_str = b_filecon->path ? DATUM(b_filecon->path)->fqn : b_filecon->path_str;
a_path = cil_malloc(strlen(a_path_str) + 1);
b_path = cil_malloc(strlen(b_path_str) + 1);
a_path[0] = '\0';
b_path[0] = '\0';
strcat(a_path, a_path_str);
strcat(b_path, b_path_str);
cil_post_fc_fill_data(a_data, a_path);
cil_post_fc_fill_data(b_data, b_path);
if (a_data->meta && !b_data->meta) {
rc = -1;
} else if (b_data->meta && !a_data->meta) {
rc = 1;
} else if (a_data->stem_len < b_data->stem_len) {
rc = -1;
} else if (b_data->stem_len < a_data->stem_len) {
rc = 1;
} else if (a_data->str_len < b_data->str_len) {
rc = -1;
} else if (b_data->str_len < a_data->str_len) {
rc = 1;
} else if (a_filecon->type < b_filecon->type) {
rc = -1;
} else if (b_filecon->type < a_filecon->type) {
rc = 1;
} else {
rc = strcmp(a_path_str, b_path_str);
}
free(a_path);
free(b_path);
free(a_data);
free(b_data);
return rc;
}
int cil_post_ibpkeycon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_ibpkeycon *aibpkeycon = *(struct cil_ibpkeycon **)a;
struct cil_ibpkeycon *bibpkeycon = *(struct cil_ibpkeycon **)b;
rc = strcmp(aibpkeycon->subnet_prefix_str, bibpkeycon->subnet_prefix_str);
if (rc)
return rc;
rc = spaceship_cmp(aibpkeycon->pkey_high - aibpkeycon->pkey_low,
bibpkeycon->pkey_high - bibpkeycon->pkey_low);
if (rc == 0) {
if (aibpkeycon->pkey_low < bibpkeycon->pkey_low)
rc = -1;
else if (bibpkeycon->pkey_low < aibpkeycon->pkey_low)
rc = 1;
}
return rc;
}
int cil_post_portcon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_portcon *aportcon = *(struct cil_portcon**)a;
struct cil_portcon *bportcon = *(struct cil_portcon**)b;
rc = spaceship_cmp(aportcon->port_high - aportcon->port_low,
bportcon->port_high - bportcon->port_low);
if (rc == 0) {
if (aportcon->port_low < bportcon->port_low) {
rc = -1;
} else if (bportcon->port_low < aportcon->port_low) {
rc = 1;
} else if (aportcon->proto < bportcon->proto) {
rc = -1;
} else if (aportcon->proto > bportcon->proto) {
rc = 1;
}
}
return rc;
}
int cil_post_genfscon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_genfscon *agenfscon = *(struct cil_genfscon**)a;
struct cil_genfscon *bgenfscon = *(struct cil_genfscon**)b;
rc = strcmp(agenfscon->fs_str, bgenfscon->fs_str);
if (rc == 0) {
rc = strcmp(agenfscon->path_str, bgenfscon->path_str);
}
return rc;
}
int cil_post_netifcon_compare(const void *a, const void *b)
{
struct cil_netifcon *anetifcon = *(struct cil_netifcon**)a;
struct cil_netifcon *bnetifcon = *(struct cil_netifcon**)b;
return strcmp(anetifcon->interface_str, bnetifcon->interface_str);
}
int cil_post_ibendportcon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_ibendportcon *aibendportcon = *(struct cil_ibendportcon **)a;
struct cil_ibendportcon *bibendportcon = *(struct cil_ibendportcon **)b;
rc = strcmp(aibendportcon->dev_name_str, bibendportcon->dev_name_str);
if (rc)
return rc;
if (aibendportcon->port < bibendportcon->port)
return -1;
else if (bibendportcon->port < aibendportcon->port)
return 1;
return rc;
}
int cil_post_nodecon_compare(const void *a, const void *b)
{
struct cil_nodecon *anodecon;
struct cil_nodecon *bnodecon;
anodecon = *(struct cil_nodecon**)a;
bnodecon = *(struct cil_nodecon**)b;
/* sort ipv4 before ipv6 */
if (anodecon->addr->family != bnodecon->addr->family) {
if (anodecon->addr->family == AF_INET) {
return -1;
} else {
return 1;
}
}
/* most specific netmask goes first, then order by ip addr */
if (anodecon->addr->family == AF_INET) {
int rc = memcmp(&anodecon->mask->ip.v4, &bnodecon->mask->ip.v4, sizeof(anodecon->mask->ip.v4));
if (rc != 0) {
return -1 * rc;
}
return memcmp(&anodecon->addr->ip.v4, &bnodecon->addr->ip.v4, sizeof(anodecon->addr->ip.v4));
} else {
int rc = memcmp(&anodecon->mask->ip.v6, &bnodecon->mask->ip.v6, sizeof(anodecon->mask->ip.v6));
if (rc != 0) {
return -1 * rc;
}
return memcmp(&anodecon->addr->ip.v6, &bnodecon->addr->ip.v6, sizeof(anodecon->addr->ip.v6));
}
}
static int cil_post_pirqcon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_pirqcon *apirqcon = *(struct cil_pirqcon**)a;
struct cil_pirqcon *bpirqcon = *(struct cil_pirqcon**)b;
if (apirqcon->pirq < bpirqcon->pirq) {
rc = -1;
} else if (bpirqcon->pirq < apirqcon->pirq) {
rc = 1;
} else {
rc = 0;
}
return rc;
}
static int cil_post_iomemcon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_iomemcon *aiomemcon = *(struct cil_iomemcon**)a;
struct cil_iomemcon *biomemcon = *(struct cil_iomemcon**)b;
rc = spaceship_cmp(aiomemcon->iomem_high - aiomemcon->iomem_low,
biomemcon->iomem_high - biomemcon->iomem_low);
if (rc == 0) {
if (aiomemcon->iomem_low < biomemcon->iomem_low) {
rc = -1;
} else if (biomemcon->iomem_low < aiomemcon->iomem_low) {
rc = 1;
}
}
return rc;
}
static int cil_post_ioportcon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_ioportcon *aioportcon = *(struct cil_ioportcon**)a;
struct cil_ioportcon *bioportcon = *(struct cil_ioportcon**)b;
rc = spaceship_cmp(aioportcon->ioport_high - aioportcon->ioport_low,
bioportcon->ioport_high - bioportcon->ioport_low);
if (rc == 0) {
if (aioportcon->ioport_low < bioportcon->ioport_low) {
rc = -1;
} else if (bioportcon->ioport_low < aioportcon->ioport_low) {
rc = 1;
}
}
return rc;
}
static int cil_post_pcidevicecon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_pcidevicecon *apcidevicecon = *(struct cil_pcidevicecon**)a;
struct cil_pcidevicecon *bpcidevicecon = *(struct cil_pcidevicecon**)b;
if (apcidevicecon->dev < bpcidevicecon->dev) {
rc = -1;
} else if (bpcidevicecon->dev < apcidevicecon->dev) {
rc = 1;
} else {
rc = 0;
}
return rc;
}
static int cil_post_devicetreecon_compare(const void *a, const void *b)
{
int rc = SEPOL_ERR;
struct cil_devicetreecon *adevicetreecon = *(struct cil_devicetreecon**)a;
struct cil_devicetreecon *bdevicetreecon = *(struct cil_devicetreecon**)b;
rc = strcmp(adevicetreecon->path, bdevicetreecon->path);
return rc;
}
int cil_post_fsuse_compare(const void *a, const void *b)
{
int rc;
struct cil_fsuse *afsuse;
struct cil_fsuse *bfsuse;
afsuse = *(struct cil_fsuse**)a;
bfsuse = *(struct cil_fsuse**)b;
if (afsuse->type < bfsuse->type) {
rc = -1;
} else if (bfsuse->type < afsuse->type) {
rc = 1;
} else {
rc = strcmp(afsuse->fs_str, bfsuse->fs_str);
}
return rc;
}
static int cil_post_filecon_context_compare(const void *a, const void *b)
{
struct cil_filecon *a_filecon = *(struct cil_filecon**)a;
struct cil_filecon *b_filecon = *(struct cil_filecon**)b;
return context_compare(a_filecon->context, b_filecon->context);
}
static int cil_post_ibpkeycon_context_compare(const void *a, const void *b)
{
struct cil_ibpkeycon *a_ibpkeycon = *(struct cil_ibpkeycon **)a;
struct cil_ibpkeycon *b_ibpkeycon = *(struct cil_ibpkeycon **)b;
return context_compare(a_ibpkeycon->context, b_ibpkeycon->context);
}
static int cil_post_portcon_context_compare(const void *a, const void *b)
{
struct cil_portcon *a_portcon = *(struct cil_portcon**)a;
struct cil_portcon *b_portcon = *(struct cil_portcon**)b;
return context_compare(a_portcon->context, b_portcon->context);
}
static int cil_post_genfscon_context_compare(const void *a, const void *b)
{
struct cil_genfscon *a_genfscon = *(struct cil_genfscon**)a;
struct cil_genfscon *b_genfscon = *(struct cil_genfscon**)b;
return context_compare(a_genfscon->context, b_genfscon->context);
}
static int cil_post_netifcon_context_compare(const void *a, const void *b)
{
int rc;
struct cil_netifcon *a_netifcon = *(struct cil_netifcon**)a;
struct cil_netifcon *b_netifcon = *(struct cil_netifcon**)b;
rc = context_compare(a_netifcon->if_context, b_netifcon->if_context);
if (rc != 0) {
return rc;
}
return context_compare(a_netifcon->packet_context, b_netifcon->packet_context);
}
static int cil_post_ibendportcon_context_compare(const void *a, const void *b)
{
struct cil_ibendportcon *a_ibendportcon = *(struct cil_ibendportcon **)a;
struct cil_ibendportcon *b_ibendportcon = *(struct cil_ibendportcon **)b;
return context_compare(a_ibendportcon->context, b_ibendportcon->context);
}
static int cil_post_nodecon_context_compare(const void *a, const void *b)
{
struct cil_nodecon *a_nodecon = *(struct cil_nodecon **)a;
struct cil_nodecon *b_nodecon = *(struct cil_nodecon **)b;
return context_compare(a_nodecon->context, b_nodecon->context);
}
static int cil_post_pirqcon_context_compare(const void *a, const void *b)
{
struct cil_pirqcon *a_pirqcon = *(struct cil_pirqcon**)a;
struct cil_pirqcon *b_pirqcon = *(struct cil_pirqcon**)b;
return context_compare(a_pirqcon->context, b_pirqcon->context);
}
static int cil_post_iomemcon_context_compare(const void *a, const void *b)
{
struct cil_iomemcon *a_iomemcon = *(struct cil_iomemcon**)a;
struct cil_iomemcon *b_iomemcon = *(struct cil_iomemcon**)b;
return context_compare(a_iomemcon->context, b_iomemcon->context);
}
static int cil_post_ioportcon_context_compare(const void *a, const void *b)
{
struct cil_ioportcon *a_ioportcon = *(struct cil_ioportcon**)a;
struct cil_ioportcon *b_ioportcon = *(struct cil_ioportcon**)b;
return context_compare(a_ioportcon->context, b_ioportcon->context);
}
static int cil_post_pcidevicecon_context_compare(const void *a, const void *b)
{
struct cil_pcidevicecon *a_pcidevicecon = *(struct cil_pcidevicecon**)a;
struct cil_pcidevicecon *b_pcidevicecon = *(struct cil_pcidevicecon**)b;
return context_compare(a_pcidevicecon->context, b_pcidevicecon->context);
}
static int cil_post_devicetreecon_context_compare(const void *a, const void *b)
{
struct cil_devicetreecon *a_devicetreecon = *(struct cil_devicetreecon**)a;
struct cil_devicetreecon *b_devicetreecon = *(struct cil_devicetreecon**)b;
return context_compare(a_devicetreecon->context, b_devicetreecon->context);
}
static int cil_post_fsuse_context_compare(const void *a, const void *b)
{
struct cil_fsuse *a_fsuse = *(struct cil_fsuse**)a;
struct cil_fsuse *b_fsuse = *(struct cil_fsuse**)b;
return context_compare(a_fsuse->context, b_fsuse->context);
}
static int __cil_post_db_count_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_db *db = extra_args;
switch(node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_CLASS: {
struct cil_class *class = node->data;
if (class->datum.nodes->head->data == node) {
// Multiple nodes can point to the same datum. Only count once.
db->num_classes++;
}
break;
}
case CIL_TYPE: {
struct cil_type *type = node->data;
if (type->datum.nodes->head->data == node) {
// Multiple nodes can point to the same datum. Only count once.
type->value = db->num_types;
db->num_types++;
db->num_types_and_attrs++;
}
break;
}
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = node->data;
if (attr->datum.nodes->head->data == node) {
// Multiple nodes can point to the same datum. Only count once.
db->num_types_and_attrs++;
}
break;
}
case CIL_ROLE: {
struct cil_role *role = node->data;
if (role->datum.nodes->head->data == node) {
// Multiple nodes can point to the same datum. Only count once.
role->value = db->num_roles;
db->num_roles++;
}
break;
}
case CIL_USER: {
struct cil_user *user = node->data;
if (user->datum.nodes->head->data == node) {
// multiple AST nodes can point to the same cil_user data (like if
// copied from a macro). This check ensures we only count the
// duplicates once
user->value = db->num_users;
db->num_users++;
}
break;
}
case CIL_NETIFCON:
db->netifcon->count++;
break;
case CIL_GENFSCON:
db->genfscon->count++;
break;
case CIL_FILECON:
db->filecon->count++;
break;
case CIL_NODECON:
db->nodecon->count++;
break;
case CIL_IBPKEYCON:
db->ibpkeycon->count++;
break;
case CIL_IBENDPORTCON:
db->ibendportcon->count++;
break;
case CIL_PORTCON:
db->portcon->count++;
break;
case CIL_PIRQCON:
db->pirqcon->count++;
break;
case CIL_IOMEMCON:
db->iomemcon->count++;
break;
case CIL_IOPORTCON:
db->ioportcon->count++;
break;
case CIL_PCIDEVICECON:
db->pcidevicecon->count++;
break;
case CIL_DEVICETREECON:
db->devicetreecon->count++;
break;
case CIL_FSUSE:
db->fsuse->count++;
break;
default:
break;
}
return SEPOL_OK;
}
static int __cil_post_db_array_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_db *db = extra_args;
switch(node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_TYPE: {
struct cil_type *type = node->data;
if (db->val_to_type == NULL) {
db->val_to_type = cil_malloc(sizeof(*db->val_to_type) * db->num_types);
}
db->val_to_type[type->value] = type;
break;
}
case CIL_ROLE: {
struct cil_role *role = node->data;
if (db->val_to_role == NULL) {
db->val_to_role = cil_malloc(sizeof(*db->val_to_role) * db->num_roles);
}
db->val_to_role[role->value] = role;
break;
}
case CIL_USER: {
struct cil_user *user= node->data;
if (db->val_to_user == NULL) {
db->val_to_user = cil_malloc(sizeof(*db->val_to_user) * db->num_users);
}
db->val_to_user[user->value] = user;
break;
}
case CIL_USERPREFIX: {
cil_list_append(db->userprefixes, CIL_USERPREFIX, node->data);
break;
}
case CIL_SELINUXUSER: {
cil_list_prepend(db->selinuxusers, CIL_SELINUXUSER, node->data);
break;
}
case CIL_SELINUXUSERDEFAULT: {
cil_list_append(db->selinuxusers, CIL_SELINUXUSERDEFAULT, node->data);
break;
}
case CIL_NETIFCON: {
struct cil_sort *sort = db->netifcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_IBENDPORTCON: {
struct cil_sort *sort = db->ibendportcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (!sort->array)
sort->array = cil_malloc(sizeof(*sort->array) * count);
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_FSUSE: {
struct cil_sort *sort = db->fsuse;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_GENFSCON: {
struct cil_sort *sort = db->genfscon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_FILECON: {
struct cil_sort *sort = db->filecon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_NODECON: {
struct cil_sort *sort = db->nodecon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_IBPKEYCON: {
struct cil_sort *sort = db->ibpkeycon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (!sort->array)
sort->array = cil_malloc(sizeof(*sort->array) * count);
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_PORTCON: {
struct cil_sort *sort = db->portcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_PIRQCON: {
struct cil_sort *sort = db->pirqcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_IOMEMCON: {
struct cil_sort *sort = db->iomemcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_IOPORTCON: {
struct cil_sort *sort = db->ioportcon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_PCIDEVICECON: {
struct cil_sort *sort = db->pcidevicecon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
case CIL_DEVICETREECON: {
struct cil_sort *sort = db->devicetreecon;
uint32_t count = sort->count;
uint32_t i = sort->index;
if (sort->array == NULL) {
sort->array = cil_malloc(sizeof(*sort->array)*count);
}
sort->array[i] = node->data;
sort->index++;
break;
}
default:
break;
}
return SEPOL_OK;
}
static int __evaluate_type_expression(struct cil_typeattribute *attr, struct cil_db *db)
{
int rc;
attr->types = cil_malloc(sizeof(*attr->types));
rc = __cil_expr_list_to_bitmap(attr->expr_list, attr->types, db->num_types, db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to expand type attribute to bitmap\n");
ebitmap_destroy(attr->types);
free(attr->types);
attr->types = NULL;
}
return rc;
}
static int __cil_type_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = datum->nodes->head->data;
ebitmap_init(bitmap);
if (node->flavor == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = (struct cil_typeattribute *)datum;
if (attr->types == NULL) {
rc = __evaluate_type_expression(attr, db);
if (rc != SEPOL_OK) goto exit;
}
ebitmap_union(bitmap, attr->types);
} else if (node->flavor == CIL_TYPEALIAS) {
struct cil_alias *alias = (struct cil_alias *)datum;
struct cil_type *type = alias->actual;
if (ebitmap_set_bit(bitmap, type->value, 1)) {
cil_log(CIL_ERR, "Failed to set type bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
} else {
struct cil_type *type = (struct cil_type *)datum;
if (ebitmap_set_bit(bitmap, type->value, 1)) {
cil_log(CIL_ERR, "Failed to set type bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __evaluate_user_expression(struct cil_userattribute *attr, struct cil_db *db)
{
int rc;
attr->users = cil_malloc(sizeof(*attr->users));
rc = __cil_expr_list_to_bitmap(attr->expr_list, attr->users, db->num_users, db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to expand user attribute to bitmap\n");
ebitmap_destroy(attr->users);
free(attr->users);
attr->users = NULL;
}
return rc;
}
static int __cil_user_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = datum->nodes->head->data;
struct cil_userattribute *attr = NULL;
struct cil_user *user = NULL;
ebitmap_init(bitmap);
if (node->flavor == CIL_USERATTRIBUTE) {
attr = (struct cil_userattribute *)datum;
if (attr->users == NULL) {
rc = __evaluate_user_expression(attr, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
ebitmap_union(bitmap, attr->users);
} else {
user = (struct cil_user *)datum;
if (ebitmap_set_bit(bitmap, user->value, 1)) {
cil_log(CIL_ERR, "Failed to set user bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __evaluate_role_expression(struct cil_roleattribute *attr, struct cil_db *db)
{
int rc;
attr->roles = cil_malloc(sizeof(*attr->roles));
rc = __cil_expr_list_to_bitmap(attr->expr_list, attr->roles, db->num_roles, db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to expand role attribute to bitmap\n");
ebitmap_destroy(attr->roles);
free(attr->roles);
attr->roles = NULL;
}
return rc;
}
static int __cil_role_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = datum->nodes->head->data;
ebitmap_init(bitmap);
if (node->flavor == CIL_ROLEATTRIBUTE) {
struct cil_roleattribute *attr = (struct cil_roleattribute *)datum;
if (attr->roles == NULL) {
rc = __evaluate_role_expression(attr, db);
if (rc != SEPOL_OK) goto exit;
}
ebitmap_union(bitmap, attr->roles);
} else {
struct cil_role *role = (struct cil_role *)datum;
if (ebitmap_set_bit(bitmap, role->value, 1)) {
cil_log(CIL_ERR, "Failed to set role bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __evaluate_permissionx_expression(struct cil_permissionx *permx, struct cil_db *db)
{
int rc;
permx->perms = cil_malloc(sizeof(*permx->perms));
ebitmap_init(permx->perms);
rc = __cil_expr_to_bitmap(permx->expr_str, permx->perms, 0x10000, db); // max is one more than 0xFFFF
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to expand permissionx expression\n");
ebitmap_destroy(permx->perms);
free(permx->perms);
permx->perms = NULL;
}
return rc;
}
static int __cil_permx_str_to_int(char *permx_str, uint16_t *val)
{
char *endptr = NULL;
long lval = strtol(permx_str, &endptr, 0);
if (*endptr != '\0') {
cil_log(CIL_ERR, "permissionx value %s not valid number\n", permx_str);
goto exit;
}
if (lval < 0x0000 || lval > 0xFFFF) {
cil_log(CIL_ERR, "permissionx value %s must be between 0x0000 and 0xFFFF\n", permx_str);
goto exit;
}
*val = (uint16_t)lval;
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_permx_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, __attribute__((unused)) struct cil_db *db)
{
int rc = SEPOL_ERR;
uint16_t val;
rc = __cil_permx_str_to_int((char*)datum, &val);
if (rc != SEPOL_OK) {
goto exit;
}
ebitmap_init(bitmap);
if (ebitmap_set_bit(bitmap, (unsigned int)val, 1)) {
cil_log(CIL_ERR, "Failed to set permissionx bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_perm_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, __attribute__((unused)) struct cil_db *db)
{
struct cil_perm *perm = (struct cil_perm *)datum;
unsigned int value = perm->value;
ebitmap_init(bitmap);
if (ebitmap_set_bit(bitmap, value, 1)) {
cil_log(CIL_INFO, "Failed to set perm bit\n");
ebitmap_destroy(bitmap);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __evaluate_cat_expression(struct cil_cats *cats, struct cil_db *db)
{
int rc = SEPOL_ERR;
ebitmap_t bitmap;
struct cil_list *new;
struct cil_list_item *curr;
if (cats->evaluated == CIL_TRUE) {
return SEPOL_OK;
}
if (cil_verify_is_list(cats->datum_expr, CIL_CAT)) {
return SEPOL_OK;
}
ebitmap_init(&bitmap);
rc = __cil_expr_to_bitmap(cats->datum_expr, &bitmap, db->num_cats, db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to expand category expression to bitmap\n");
ebitmap_destroy(&bitmap);
goto exit;
}
cil_list_init(&new, CIL_CAT);
cil_list_for_each(curr, db->catorder) {
struct cil_cat *cat = curr->data;
if (ebitmap_get_bit(&bitmap, cat->value)) {
cil_list_append(new, CIL_DATUM, cat);
}
}
ebitmap_destroy(&bitmap);
cil_list_destroy(&cats->datum_expr, CIL_FALSE);
cats->datum_expr = new;
cats->evaluated = CIL_TRUE;
return SEPOL_OK;
exit:
return rc;
}
static int __cil_cat_to_bitmap(struct cil_symtab_datum *datum, ebitmap_t *bitmap, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = datum->nodes->head->data;
ebitmap_init(bitmap);
if (node->flavor == CIL_CATSET) {
struct cil_catset *catset = (struct cil_catset *)datum;
struct cil_list_item *curr;
if (catset->cats->evaluated == CIL_FALSE) {
rc = __evaluate_cat_expression(catset->cats, db);
if (rc != SEPOL_OK) goto exit;
}
for (curr = catset->cats->datum_expr->head; curr; curr = curr->next) {
struct cil_cat *cat = (struct cil_cat *)curr->data;
if (ebitmap_set_bit(bitmap, cat->value, 1)) {
cil_log(CIL_ERR, "Failed to set cat bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
}
} else if (node->flavor == CIL_CATALIAS) {
struct cil_alias *alias = (struct cil_alias *)datum;
struct cil_cat *cat = alias->actual;
if (ebitmap_set_bit(bitmap, cat->value, 1)) {
cil_log(CIL_ERR, "Failed to set cat bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
} else {
struct cil_cat *cat = (struct cil_cat *)datum;
if (ebitmap_set_bit(bitmap, cat->value, 1)) {
cil_log(CIL_ERR, "Failed to set cat bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_cat_expr_range_to_bitmap_helper(struct cil_list_item *i1, struct cil_list_item *i2, ebitmap_t *bitmap)
{
int rc = SEPOL_ERR;
struct cil_symtab_datum *d1 = i1->data;
struct cil_symtab_datum *d2 = i2->data;
struct cil_tree_node *n1 = d1->nodes->head->data;
struct cil_tree_node *n2 = d2->nodes->head->data;
struct cil_cat *c1 = (struct cil_cat *)d1;
struct cil_cat *c2 = (struct cil_cat *)d2;
if (n1->flavor == CIL_CATSET || n2->flavor == CIL_CATSET) {
cil_log(CIL_ERR, "Category sets cannot be used in a category range\n");
goto exit;
}
if (n1->flavor == CIL_CATALIAS) {
struct cil_alias *alias = (struct cil_alias *)d1;
c1 = alias->actual;
}
if (n2->flavor == CIL_CATALIAS) {
struct cil_alias *alias = (struct cil_alias *)d2;
c2 = alias->actual;
}
if (c1->value > c2->value) {
cil_log(CIL_ERR, "Invalid category range\n");
goto exit;
}
if (ebitmap_init_range(bitmap, c1->value, c2->value)) {
cil_log(CIL_ERR, "Failed to set cat bit\n");
ebitmap_destroy(bitmap);
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_permissionx_expr_range_to_bitmap_helper(struct cil_list_item *i1, struct cil_list_item *i2, ebitmap_t *bitmap)
{
int rc = SEPOL_ERR;
char *p1 = i1->data;
char *p2 = i2->data;
uint16_t v1;
uint16_t v2;
rc = __cil_permx_str_to_int(p1, &v1);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_permx_str_to_int(p2, &v2);
if (rc != SEPOL_OK) {
goto exit;
}
if (ebitmap_init_range(bitmap, v1, v2)) {
cil_log(CIL_ERR, "Failed to set permissionx bits\n");
ebitmap_destroy(bitmap);
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_expr_to_bitmap_helper(struct cil_list_item *curr, enum cil_flavor flavor, ebitmap_t *bitmap, int max, struct cil_db *db)
{
int rc = SEPOL_ERR;
if (curr->flavor == CIL_DATUM) {
switch (flavor) {
case CIL_TYPE:
rc = __cil_type_to_bitmap(curr->data, bitmap, db);
break;
case CIL_ROLE:
rc = __cil_role_to_bitmap(curr->data, bitmap, db);
break;
case CIL_USER:
rc = __cil_user_to_bitmap(curr->data, bitmap, db);
break;
case CIL_PERM:
rc = __cil_perm_to_bitmap(curr->data, bitmap, db);
break;
case CIL_CAT:
rc = __cil_cat_to_bitmap(curr->data, bitmap, db);
break;
default:
rc = SEPOL_ERR;
}
} else if (curr->flavor == CIL_LIST) {
struct cil_list *l = curr->data;
ebitmap_init(bitmap);
rc = __cil_expr_to_bitmap(l, bitmap, max, db);
if (rc != SEPOL_OK) {
ebitmap_destroy(bitmap);
}
} else if (flavor == CIL_PERMISSIONX) {
// permissionx expressions aren't resolved into anything, so curr->flavor
// is just a CIL_STRING, not a CIL_DATUM, so just check on flavor for those
rc = __cil_permx_to_bitmap(curr->data, bitmap, db);
}
return rc;
}
static int __cil_expr_to_bitmap(struct cil_list *expr, ebitmap_t *out, int max, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
enum cil_flavor flavor;
ebitmap_t tmp, b1, b2;
if (expr == NULL || expr->head == NULL) {
return SEPOL_OK;
}
curr = expr->head;
flavor = expr->flavor;
ebitmap_init(&tmp);
if (curr->flavor == CIL_OP) {
enum cil_flavor op = (enum cil_flavor)(uintptr_t)curr->data;
if (op == CIL_ALL) {
rc = ebitmap_init_range(&tmp, 0, max - 1);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to expand 'all' operator\n");
ebitmap_destroy(&tmp);
goto exit;
}
} else if (op == CIL_RANGE) {
if (flavor == CIL_CAT) {
rc = __cil_cat_expr_range_to_bitmap_helper(curr->next, curr->next->next, &tmp);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to expand category range\n");
goto exit;
}
} else if (flavor == CIL_PERMISSIONX) {
rc = __cil_permissionx_expr_range_to_bitmap_helper(curr->next, curr->next->next, &tmp);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to expand category range\n");
goto exit;
}
} else {
cil_log(CIL_INFO, "Range operation only supported for categories permissionx\n");
rc = SEPOL_ERR;
goto exit;
}
} else {
rc = __cil_expr_to_bitmap_helper(curr->next, flavor, &b1, max, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get first operand bitmap\n");
goto exit;
}
if (op == CIL_NOT) {
rc = ebitmap_not(&tmp, &b1, max);
ebitmap_destroy(&b1);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to NOT bitmap\n");
ebitmap_destroy(&tmp);
goto exit;
}
} else {
rc = __cil_expr_to_bitmap_helper(curr->next->next, flavor, &b2, max, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get second operand bitmap\n");
ebitmap_destroy(&b1);
goto exit;
}
if (op == CIL_OR) {
rc = ebitmap_or(&tmp, &b1, &b2);
} else if (op == CIL_AND) {
rc = ebitmap_and(&tmp, &b1, &b2);
} else if (op == CIL_XOR) {
rc = ebitmap_xor(&tmp, &b1, &b2);
} else {
rc = SEPOL_ERR;
}
ebitmap_destroy(&b1);
ebitmap_destroy(&b2);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to apply operator to bitmaps\n");
ebitmap_destroy(&tmp);
goto exit;
}
}
}
} else {
ebitmap_init(&tmp);
for (;curr; curr = curr->next) {
rc = __cil_expr_to_bitmap_helper(curr, flavor, &b2, max, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to get operand in list\n");
ebitmap_destroy(&tmp);
goto exit;
}
b1 = tmp;
rc = ebitmap_or(&tmp, &b1, &b2);
ebitmap_destroy(&b1);
ebitmap_destroy(&b2);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to OR operands in list\n");
ebitmap_destroy(&tmp);
goto exit;
}
}
}
ebitmap_union(out, &tmp);
ebitmap_destroy(&tmp);
return SEPOL_OK;
exit:
return rc;
}
static int __cil_expr_list_to_bitmap(struct cil_list *expr_list, ebitmap_t *out, int max, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *expr;
ebitmap_init(out);
if (expr_list == NULL) {
return SEPOL_OK;
}
cil_list_for_each(expr, expr_list) {
ebitmap_t bitmap;
struct cil_list *l = (struct cil_list *)expr->data;
ebitmap_init(&bitmap);
rc = __cil_expr_to_bitmap(l, &bitmap, max, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to expand expression list to bitmap\n");
ebitmap_destroy(&bitmap);
goto exit;
}
ebitmap_union(out, &bitmap);
ebitmap_destroy(&bitmap);
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int cil_typeattribute_used(struct cil_typeattribute *attr, struct cil_db *db)
{
if (!attr->used) {
return CIL_FALSE;
}
if (attr->used & CIL_ATTR_EXPAND_FALSE) {
return CIL_TRUE;
}
if (attr->used & CIL_ATTR_EXPAND_TRUE) {
return CIL_FALSE;
}
if (attr->used & CIL_ATTR_CONSTRAINT) {
return CIL_TRUE;
}
if (db->attrs_expand_generated || attr->used == CIL_ATTR_NEVERALLOW) {
if (strcmp(DATUM(attr)->name, GEN_REQUIRE_ATTR) == 0) {
return CIL_FALSE;
} else if (strstr(DATUM(attr)->name, TYPEATTR_INFIX) != NULL) {
return CIL_FALSE;
}
if (attr->used == CIL_ATTR_NEVERALLOW) {
return CIL_TRUE;
}
}
if (attr->used == CIL_ATTR_AVRULE) {
if (ebitmap_cardinality(attr->types) < db->attrs_expand_size) {
return CIL_FALSE;
}
}
return CIL_TRUE;
}
static void __mark_neverallow_attrs(struct cil_list *expr_list)
{
struct cil_list_item *curr;
if (!expr_list) {
return;
}
cil_list_for_each(curr, expr_list) {
if (curr->flavor == CIL_DATUM) {
if (FLAVOR(curr->data) == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = curr->data;
if (strstr(DATUM(attr)->name, TYPEATTR_INFIX)) {
__mark_neverallow_attrs(attr->expr_list);
} else {
attr->used |= CIL_ATTR_NEVERALLOW;
}
}
} else if (curr->flavor == CIL_LIST) {
__mark_neverallow_attrs(curr->data);
}
}
}
static int __cil_post_db_neverallow_attr_helper(struct cil_tree_node *node, uint32_t *finished, __attribute__((unused)) void *extra_args)
{
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = node->data;
if ((attr->used & CIL_ATTR_NEVERALLOW) &&
strstr(DATUM(attr)->name, TYPEATTR_INFIX)) {
__mark_neverallow_attrs(attr->expr_list);
}
break;
}
default:
break;
}
return SEPOL_OK;
}
static int __cil_post_db_attr_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_db *db = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = node->data;
if (attr->types == NULL) {
rc = __evaluate_type_expression(attr, db);
if (rc != SEPOL_OK) goto exit;
}
attr->keep = cil_typeattribute_used(attr, db);
break;
}
case CIL_ROLEATTRIBUTE: {
struct cil_roleattribute *attr = node->data;
if (attr->roles == NULL) {
rc = __evaluate_role_expression(attr, db);
if (rc != SEPOL_OK) goto exit;
}
break;
}
case CIL_AVRULEX: {
struct cil_avrule *rule = node->data;
if (rule->perms.x.permx_str == NULL) {
rc = __evaluate_permissionx_expression(rule->perms.x.permx, db);
if (rc != SEPOL_OK) goto exit;
}
break;
}
case CIL_PERMISSIONX: {
struct cil_permissionx *permx = node->data;
rc = __evaluate_permissionx_expression(permx, db);
if (rc != SEPOL_OK) goto exit;
break;
}
case CIL_USERATTRIBUTE: {
struct cil_userattribute *attr = node->data;
if (attr->users == NULL) {
rc = __evaluate_user_expression(attr, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
break;
}
default:
break;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_role_assign_types(struct cil_role *role, struct cil_symtab_datum *datum)
{
struct cil_tree_node *node = datum->nodes->head->data;
if (role->types == NULL) {
role->types = cil_malloc(sizeof(*role->types));
ebitmap_init(role->types);
}
if (node->flavor == CIL_TYPE) {
struct cil_type *type = (struct cil_type *)datum;
if (ebitmap_set_bit(role->types, type->value, 1)) {
cil_log(CIL_INFO, "Failed to set bit in role types bitmap\n");
goto exit;
}
} else if (node->flavor == CIL_TYPEALIAS) {
struct cil_alias *alias = (struct cil_alias *)datum;
struct cil_type *type = alias->actual;
if (ebitmap_set_bit(role->types, type->value, 1)) {
cil_log(CIL_INFO, "Failed to set bit in role types bitmap\n");
goto exit;
}
} else if (node->flavor == CIL_TYPEATTRIBUTE) {
struct cil_typeattribute *attr = (struct cil_typeattribute *)datum;
ebitmap_union(role->types, attr->types);
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_post_db_roletype_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_db *db = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_ROLETYPE: {
struct cil_roletype *roletype = node->data;
struct cil_symtab_datum *role_datum = roletype->role;
struct cil_symtab_datum *type_datum = roletype->type;
struct cil_tree_node *role_node = role_datum->nodes->head->data;
if (role_node->flavor == CIL_ROLEATTRIBUTE) {
struct cil_roleattribute *attr = roletype->role;
ebitmap_node_t *rnode;
unsigned int i;
ebitmap_for_each_positive_bit(attr->roles, rnode, i) {
struct cil_role *role = NULL;
role = db->val_to_role[i];
rc = __cil_role_assign_types(role, type_datum);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
struct cil_role *role = roletype->role;
rc = __cil_role_assign_types(role, type_datum);
if (rc != SEPOL_OK) {
goto exit;
}
}
break;
}
default:
break;
}
return SEPOL_OK;
exit:
cil_log(CIL_INFO, "cil_post_db_roletype_helper failed\n");
return rc;
}
static int __cil_user_assign_roles(struct cil_user *user, struct cil_symtab_datum *datum)
{
struct cil_tree_node *node = datum->nodes->head->data;
struct cil_role *role = NULL;
struct cil_roleattribute *attr = NULL;
if (user->roles == NULL) {
user->roles = cil_malloc(sizeof(*user->roles));
ebitmap_init(user->roles);
}
if (node->flavor == CIL_ROLE) {
role = (struct cil_role *)datum;
if (ebitmap_set_bit(user->roles, role->value, 1)) {
cil_log(CIL_INFO, "Failed to set bit in user roles bitmap\n");
goto exit;
}
} else if (node->flavor == CIL_ROLEATTRIBUTE) {
attr = (struct cil_roleattribute *)datum;
ebitmap_union(user->roles, attr->roles);
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_post_db_userrole_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_db *db = extra_args;
struct cil_block *blk = NULL;
struct cil_userrole *userrole = NULL;
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *role_datum = NULL;
struct cil_tree_node *user_node = NULL;
struct cil_userattribute *u_attr = NULL;
unsigned int i;
struct cil_user *user = NULL;
ebitmap_node_t *unode = NULL;
switch (node->flavor) {
case CIL_BLOCK: {
blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_USERROLE: {
userrole = node->data;
user_datum = userrole->user;
role_datum = userrole->role;
user_node = user_datum->nodes->head->data;
if (user_node->flavor == CIL_USERATTRIBUTE) {
u_attr = userrole->user;
ebitmap_for_each_positive_bit(u_attr->users, unode, i) {
user = db->val_to_user[i];
rc = __cil_user_assign_roles(user, role_datum);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
user = userrole->user;
rc = __cil_user_assign_roles(user, role_datum);
if (rc != SEPOL_OK) {
goto exit;
}
}
break;
}
default:
break;
}
return SEPOL_OK;
exit:
cil_log(CIL_INFO, "cil_post_db_userrole_helper failed\n");
return rc;
}
static int __evaluate_level_expression(struct cil_level *level, struct cil_db *db)
{
if (level->cats != NULL) {
return __evaluate_cat_expression(level->cats, db);
}
return SEPOL_OK;
}
static int __evaluate_levelrange_expression(struct cil_levelrange *levelrange, struct cil_db *db)
{
int rc = SEPOL_OK;
if (levelrange->low != NULL && levelrange->low->cats != NULL) {
rc = __evaluate_cat_expression(levelrange->low->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (levelrange->high != NULL && levelrange->high->cats != NULL) {
rc = __evaluate_cat_expression(levelrange->high->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
exit:
return rc;
}
static int __cil_post_db_cat_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_db *db = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_CATSET: {
struct cil_catset *catset = node->data;
rc = __evaluate_cat_expression(catset->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_SENSCAT: {
struct cil_senscat *senscat = node->data;
rc = __evaluate_cat_expression(senscat->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_LEVEL: {
rc = __evaluate_level_expression(node->data, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_LEVELRANGE: {
rc = __evaluate_levelrange_expression(node->data, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_USER: {
struct cil_user *user = node->data;
rc = __evaluate_level_expression(user->dftlevel, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __evaluate_levelrange_expression(user->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_SELINUXUSERDEFAULT:
case CIL_SELINUXUSER: {
struct cil_selinuxuser *selinuxuser = node->data;
rc = __evaluate_levelrange_expression(selinuxuser->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_RANGETRANSITION: {
struct cil_rangetransition *rangetrans = node->data;
rc = __evaluate_levelrange_expression(rangetrans->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_CONTEXT: {
struct cil_context *context = node->data;
rc = __evaluate_levelrange_expression(context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_SIDCONTEXT: {
struct cil_sidcontext *sidcontext = node->data;
rc = __evaluate_levelrange_expression(sidcontext->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_FILECON: {
struct cil_filecon *filecon = node->data;
if (filecon->context) {
rc = __evaluate_levelrange_expression(filecon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
break;
}
case CIL_IBPKEYCON: {
struct cil_ibpkeycon *ibpkeycon = node->data;
rc = __evaluate_levelrange_expression(ibpkeycon->context->range, db);
if (rc != SEPOL_OK)
goto exit;
break;
}
case CIL_IBENDPORTCON: {
struct cil_ibendportcon *ibendportcon = node->data;
rc = __evaluate_levelrange_expression(ibendportcon->context->range, db);
if (rc != SEPOL_OK)
goto exit;
break;
}
case CIL_PORTCON: {
struct cil_portcon *portcon = node->data;
rc = __evaluate_levelrange_expression(portcon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_NODECON: {
struct cil_nodecon *nodecon = node->data;
rc = __evaluate_levelrange_expression(nodecon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_GENFSCON: {
struct cil_genfscon *genfscon = node->data;
rc = __evaluate_levelrange_expression(genfscon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_NETIFCON: {
struct cil_netifcon *netifcon = node->data;
rc = __evaluate_levelrange_expression(netifcon->if_context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __evaluate_levelrange_expression(netifcon->packet_context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_PIRQCON: {
struct cil_pirqcon *pirqcon = node->data;
rc = __evaluate_levelrange_expression(pirqcon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_IOMEMCON: {
struct cil_iomemcon *iomemcon = node->data;
rc = __evaluate_levelrange_expression(iomemcon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_IOPORTCON: {
struct cil_ioportcon *ioportcon = node->data;
rc = __evaluate_levelrange_expression(ioportcon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_PCIDEVICECON: {
struct cil_pcidevicecon *pcidevicecon = node->data;
rc = __evaluate_levelrange_expression(pcidevicecon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_DEVICETREECON: {
struct cil_devicetreecon *devicetreecon = node->data;
rc = __evaluate_levelrange_expression(devicetreecon->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_FSUSE: {
struct cil_fsuse *fsuse = node->data;
rc = __evaluate_levelrange_expression(fsuse->context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
default:
break;
}
return SEPOL_OK;
exit:
return rc;
}
struct perm_to_list {
enum cil_flavor flavor;
ebitmap_t *perms;
struct cil_list *new_list;
};
static int __perm_bits_to_list(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct perm_to_list *perm_args = (struct perm_to_list *)args;
ebitmap_t *perms = perm_args->perms;
struct cil_list *new_list = perm_args->new_list;
struct cil_perm *perm = (struct cil_perm *)d;
unsigned int value = perm->value;
if (!ebitmap_get_bit(perms, value)) {
return SEPOL_OK;
}
cil_list_append(new_list, CIL_DATUM, d);
return SEPOL_OK;
}
static int __evaluate_perm_expression(struct cil_list *perms, enum cil_flavor flavor, symtab_t *class_symtab, symtab_t *common_symtab, unsigned int num_perms, struct cil_list **new_list, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct perm_to_list args;
ebitmap_t bitmap;
if (cil_verify_is_list(perms, CIL_PERM)) {
return SEPOL_OK;
}
ebitmap_init(&bitmap);
rc = __cil_expr_to_bitmap(perms, &bitmap, num_perms, db);
if (rc != SEPOL_OK) {
ebitmap_destroy(&bitmap);
goto exit;
}
cil_list_init(new_list, flavor);
args.flavor = flavor;
args.perms = &bitmap;
args.new_list = *new_list;
cil_symtab_map(class_symtab, __perm_bits_to_list, &args);
if (common_symtab != NULL) {
cil_symtab_map(common_symtab, __perm_bits_to_list, &args);
}
ebitmap_destroy(&bitmap);
return SEPOL_OK;
exit:
return rc;
}
static int __evaluate_classperms(struct cil_classperms *cp, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_class *class = cp->class;
struct cil_class *common = class->common;
symtab_t *common_symtab = NULL;
struct cil_list *new_list = NULL;
if (common) {
common_symtab = &common->perms;
}
rc = __evaluate_perm_expression(cp->perms, CIL_PERM, &class->perms, common_symtab, class->num_perms, &new_list, db);
if (rc != SEPOL_OK) {
goto exit;
}
if (new_list == NULL) {
return SEPOL_OK;
}
cil_list_destroy(&cp->perms, CIL_FALSE);
cp->perms = new_list;
return SEPOL_OK;
exit:
return rc;
}
static int __evaluate_classperms_list(struct cil_list *classperms, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
cil_list_for_each(curr, classperms) {
if (curr->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = curr->data;
if (FLAVOR(cp->class) == CIL_CLASS) {
rc = __evaluate_classperms(cp, db);
if (rc != SEPOL_OK) {
goto exit;
}
} else { /* MAP */
struct cil_list_item *i = NULL;
rc = __evaluate_classperms(cp, db);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_for_each(i, cp->perms) {
struct cil_perm *cmp = i->data;
rc = __evaluate_classperms_list(cmp->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
} else { /* SET */
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
rc = __evaluate_classperms_list(cp->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
struct class_map_args {
struct cil_db *db;
int rc;
};
static int __evaluate_map_perm_classperms(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct class_map_args *map_args = args;
struct cil_perm *cmp = (struct cil_perm *)d;
int rc = __evaluate_classperms_list(cmp->classperms, map_args->db);
if (rc != SEPOL_OK) {
map_args->rc = rc;
}
return SEPOL_OK;
}
static int __evaluate_map_class(struct cil_class *mc, struct cil_db *db)
{
struct class_map_args map_args;
map_args.db = db;
map_args.rc = SEPOL_OK;
cil_symtab_map(&mc->perms, __evaluate_map_perm_classperms, &map_args);
return map_args.rc;
}
static int __cil_post_db_classperms_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_db *db = extra_args;
switch (node->flavor) {
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_MACRO:
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_MAP_CLASS: {
rc = __evaluate_map_class(node->data, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_CLASSPERMISSION: {
struct cil_classpermission *cp = node->data;
rc = __evaluate_classperms_list(cp->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_AVRULE: {
struct cil_avrule *avrule = node->data;
rc = __evaluate_classperms_list(avrule->perms.classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
case CIL_CONSTRAIN:
case CIL_MLSCONSTRAIN: {
struct cil_constrain *constrain = node->data;
rc = __evaluate_classperms_list(constrain->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
break;
}
default:
break;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_post_report_conflict(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_list_item *li = extra_args;
if (node->flavor == CIL_BLOCK) {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
} else if (node->flavor == CIL_MACRO) {
*finished = CIL_TREE_SKIP_HEAD;
} else if (node->flavor == li->flavor) {
if (node->data == li->data) {
char *path = cil_tree_get_cil_path(node);
cil_log(CIL_WARN, " at %s:%d\n", path, node->line);
}
}
return SEPOL_OK;
}
static int __cil_post_process_context_rules(struct cil_sort *sort, int (*compar)(const void *, const void *), int (*concompar)(const void *, const void *), struct cil_db *db, enum cil_flavor flavor, const char *flavor_str)
{
uint32_t count = sort->count;
uint32_t i = 0, j, removed = 0;
int conflicting = 0;
int rc = SEPOL_OK;
enum cil_log_level log_level = cil_get_log_level();
if (count < 2) {
return SEPOL_OK;
}
qsort(sort->array, sort->count, sizeof(sort->array), compar);
for (j=1; jarray[i], &sort->array[j]) != 0) {
i++;
if (conflicting >= 4) {
/* 2 rules were written when conflicting == 1 */
cil_log(CIL_WARN, " Only first 4 of %d conflicting rules shown\n", conflicting);
}
conflicting = 0;
} else {
removed++;
if (!db->multiple_decls || concompar(&sort->array[i], &sort->array[j]) != 0) {
rc = SEPOL_ERR;
conflicting++;
if (log_level >= CIL_WARN) {
struct cil_list_item li;
int rc2;
li.flavor = flavor;
if (conflicting == 1) {
cil_log(CIL_WARN, "Found conflicting %s rules\n", flavor_str);
li.data = sort->array[i];
rc2 = cil_tree_walk(db->ast->root, __cil_post_report_conflict,
NULL, NULL, &li);
if (rc2 != SEPOL_OK) goto exit;
}
if (conflicting < 4 || log_level > CIL_WARN) {
li.data = sort->array[j];
rc2 = cil_tree_walk(db->ast->root, __cil_post_report_conflict,
NULL, NULL, &li);
if (rc2 != SEPOL_OK) goto exit;
}
}
}
}
if (i != j && !conflicting) {
sort->array[i] = sort->array[j];
}
}
sort->count = count - removed;
exit:
return rc;
}
static int cil_post_db(struct cil_db *db)
{
int rc = SEPOL_ERR;
rc = cil_tree_walk(db->ast->root, __cil_post_db_count_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure during cil database count helper\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_array_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failure during cil database array helper\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_neverallow_attr_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to mark attributes used by generated attributes used in neverallow rules\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_attr_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to create attribute bitmaps\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_roletype_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed during roletype association\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_userrole_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed during userrole association\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_classperms_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to evaluate class mapping permissions expressions\n");
goto exit;
}
rc = cil_tree_walk(db->ast->root, __cil_post_db_cat_helper, NULL, NULL, db);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Failed to evaluate category expressions\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->netifcon, cil_post_netifcon_compare, cil_post_netifcon_context_compare, db, CIL_NETIFCON, CIL_KEY_NETIFCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing netifcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->genfscon, cil_post_genfscon_compare, cil_post_genfscon_context_compare, db, CIL_GENFSCON, CIL_KEY_GENFSCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing genfscon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->ibpkeycon, cil_post_ibpkeycon_compare, cil_post_ibpkeycon_context_compare, db, CIL_IBPKEYCON, CIL_KEY_IBPKEYCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing ibpkeycon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->ibendportcon, cil_post_ibendportcon_compare, cil_post_ibendportcon_context_compare, db, CIL_IBENDPORTCON, CIL_KEY_IBENDPORTCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing ibendportcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->portcon, cil_post_portcon_compare, cil_post_portcon_context_compare, db, CIL_PORTCON, CIL_KEY_PORTCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing portcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->nodecon, cil_post_nodecon_compare, cil_post_nodecon_context_compare, db, CIL_NODECON, CIL_KEY_NODECON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing nodecon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->fsuse, cil_post_fsuse_compare, cil_post_fsuse_context_compare, db, CIL_FSUSE, CIL_KEY_FSUSE);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing fsuse rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->filecon, cil_post_filecon_compare, cil_post_filecon_context_compare, db, CIL_FILECON, CIL_KEY_FILECON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing filecon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->pirqcon, cil_post_pirqcon_compare, cil_post_pirqcon_context_compare, db, CIL_PIRQCON, CIL_KEY_IOMEMCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing pirqcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->iomemcon, cil_post_iomemcon_compare, cil_post_iomemcon_context_compare, db, CIL_IOMEMCON, CIL_KEY_IOMEMCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing iomemcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->ioportcon, cil_post_ioportcon_compare, cil_post_ioportcon_context_compare, db, CIL_IOPORTCON, CIL_KEY_IOPORTCON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing ioportcon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->pcidevicecon, cil_post_pcidevicecon_compare, cil_post_pcidevicecon_context_compare, db, CIL_PCIDEVICECON, CIL_KEY_PCIDEVICECON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing pcidevicecon rules\n");
goto exit;
}
rc = __cil_post_process_context_rules(db->devicetreecon, cil_post_devicetreecon_compare, cil_post_devicetreecon_context_compare, db, CIL_DEVICETREECON, CIL_KEY_DEVICETREECON);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Problems processing devicetreecon rules\n");
goto exit;
}
exit:
return rc;
}
static int cil_post_verify(struct cil_db *db)
{
int rc = SEPOL_ERR;
int avrule_cnt = 0;
int handleunknown = -1;
int mls = -1;
int nseuserdflt = 0;
int pass = 0;
struct cil_args_verify extra_args;
struct cil_complex_symtab csymtab;
cil_complex_symtab_init(&csymtab, CIL_CLASS_SYM_SIZE);
extra_args.db = db;
extra_args.csymtab = &csymtab;
extra_args.avrule_cnt = &avrule_cnt;
extra_args.handleunknown = &handleunknown;
extra_args.mls = &mls;
extra_args.nseuserdflt = &nseuserdflt;
extra_args.pass = &pass;
for (pass = 0; pass < 2; pass++) {
rc = cil_tree_walk(db->ast->root, __cil_verify_helper, NULL, NULL, &extra_args);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to verify cil database\n");
goto exit;
}
}
if (db->handle_unknown == -1) {
if (handleunknown == -1) {
db->handle_unknown = SEPOL_DENY_UNKNOWN;
} else {
db->handle_unknown = handleunknown;
}
}
if (db->mls == -1) {
if (mls == -1) {
db->mls = CIL_FALSE;
} else {
db->mls = mls;
}
}
if (avrule_cnt == 0) {
cil_log(CIL_ERR, "Policy must include at least one avrule\n");
rc = SEPOL_ERR;
goto exit;
}
if (nseuserdflt > 1) {
cil_log(CIL_ERR, "Policy cannot contain more than one selinuxuserdefault, found: %d\n", nseuserdflt);
rc = SEPOL_ERR;
goto exit;
}
exit:
cil_complex_symtab_destroy(&csymtab);
return rc;
}
static int cil_pre_verify(struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_args_verify extra_args;
extra_args.db = db;
rc = cil_tree_walk(db->ast->root, __cil_pre_verify_helper, NULL, NULL, &extra_args);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to verify cil database\n");
goto exit;
}
exit:
return rc;
}
int cil_post_process(struct cil_db *db)
{
int rc = SEPOL_ERR;
rc = cil_pre_verify(db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to verify cil database\n");
goto exit;
}
rc = cil_post_db(db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed post db handling\n");
goto exit;
}
rc = cil_process_deny_rules_in_ast(db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to process deny rules\n");
goto exit;
}
rc = cil_post_verify(db);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to verify cil database\n");
goto exit;
}
exit:
return rc;
}
libsepol-3.8.1/cil/src/cil_post.h000066400000000000000000000042751476211737200167010ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_POST_H_
#define CIL_POST_H_
int cil_post_filecon_compare(const void *a, const void *b);
int cil_post_ibpkeycon_compare(const void *a, const void *b);
int cil_post_portcon_compare(const void *a, const void *b);
int cil_post_ibendportcon_compare(const void *a, const void *b);
int cil_post_genfscon_compare(const void *a, const void *b);
int cil_post_netifcon_compare(const void *a, const void *b);
int cil_post_nodecon_compare(const void *a, const void *b);
int cil_post_fsuse_compare(const void *a, const void *b);
int cil_post_context_sort(struct cil_db *db);
int cil_post_process(struct cil_db *db);
#endif
libsepol-3.8.1/cil/src/cil_reset_ast.c000066400000000000000000000366761476211737200177120ustar00rootroot00000000000000
#include "cil_internal.h"
#include "cil_log.h"
#include "cil_list.h"
#include "cil_reset_ast.h"
#include "cil_symtab.h"
static inline void cil_reset_classperms_list(struct cil_list *cp_list);
static inline void cil_reset_level(struct cil_level *level);
static inline void cil_reset_levelrange(struct cil_levelrange *levelrange);
static inline void cil_reset_context(struct cil_context *context);
static void cil_reset_ordered(struct cil_ordered *ordered)
{
ordered->merged = CIL_FALSE;
cil_list_destroy(&ordered->datums, CIL_FALSE);
}
static int __class_reset_perm_values(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_perm *perm = (struct cil_perm *)d;
perm->value -= *((int *)args);
return SEPOL_OK;
}
static void cil_reset_class(struct cil_class *class)
{
if (class->common != NULL) {
/* Must assume that the common has been destroyed */
int num_common_perms = class->num_perms - class->perms.nprim;
cil_symtab_map(&class->perms, __class_reset_perm_values, &num_common_perms);
/* during a re-resolve, we need to reset the common, so a classcommon
* statement isn't seen as a duplicate */
class->num_perms = class->perms.nprim;
class->common = NULL; /* Must make this NULL or there will be an error when re-resolving */
}
class->ordered = CIL_FALSE;
}
static void cil_reset_perm(struct cil_perm *perm)
{
cil_list_destroy(&perm->classperms, CIL_FALSE);
}
static inline void cil_reset_classperms(struct cil_classperms *cp)
{
if (cp == NULL) {
return;
}
cp->class = NULL;
cil_list_destroy(&cp->perms, CIL_FALSE);
}
static void cil_reset_classpermission(struct cil_classpermission *cp)
{
if (cp == NULL) {
return;
}
cil_list_destroy(&cp->classperms, CIL_FALSE);
}
static void cil_reset_classperms_set(struct cil_classperms_set *cp_set)
{
if (cp_set == NULL || cp_set->set == NULL) {
return;
}
if (cp_set->set->datum.name == NULL) {
cil_reset_classperms_list(cp_set->set->classperms);
}
cp_set->set = NULL;
}
static inline void cil_reset_classperms_list(struct cil_list *cp_list)
{
struct cil_list_item *curr;
if (cp_list == NULL) {
return;
}
cil_list_for_each(curr, cp_list) {
if (curr->flavor == CIL_CLASSPERMS) { /* KERNEL or MAP */
cil_reset_classperms(curr->data);
} else if (curr->flavor == CIL_CLASSPERMS_SET) { /* SET */
cil_reset_classperms_set(curr->data);
}
}
}
static void cil_reset_classpermissionset(struct cil_classpermissionset *cps)
{
cil_reset_classperms_list(cps->classperms);
}
static void cil_reset_classmapping(struct cil_classmapping *cm)
{
cil_reset_classperms_list(cm->classperms);
}
static void cil_reset_alias(struct cil_alias *alias)
{
/* reset actual to NULL during a re-resolve */
alias->actual = NULL;
}
static void cil_reset_user(struct cil_user *user)
{
/* reset the bounds to NULL during a re-resolve */
user->bounds = NULL;
user->dftlevel = NULL;
user->range = NULL;
}
static void cil_reset_userattr(struct cil_userattribute *attr)
{
struct cil_list_item *expr = NULL;
struct cil_list_item *next = NULL;
/* during a re-resolve, we need to reset the lists of expression stacks associated with this attribute from a userattribute statement */
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
expr = attr->expr_list->head;
while (expr != NULL) {
next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
}
static void cil_reset_userattributeset(struct cil_userattributeset *uas)
{
cil_list_destroy(&uas->datum_expr, CIL_FALSE);
}
static void cil_reset_selinuxuser(struct cil_selinuxuser *selinuxuser)
{
selinuxuser->user = NULL;
if (selinuxuser->range_str == NULL) {
cil_reset_levelrange(selinuxuser->range);
} else {
selinuxuser->range = NULL;
}
}
static void cil_reset_role(struct cil_role *role)
{
/* reset the bounds to NULL during a re-resolve */
role->bounds = NULL;
}
static void cil_reset_roleattr(struct cil_roleattribute *attr)
{
/* during a re-resolve, we need to reset the lists of expression stacks associated with this attribute from a attributeroles statement */
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
struct cil_list_item *expr = attr->expr_list->head;
while (expr != NULL) {
struct cil_list_item *next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
}
static void cil_reset_roleattributeset(struct cil_roleattributeset *ras)
{
cil_list_destroy(&ras->datum_expr, CIL_FALSE);
}
static void cil_reset_type(struct cil_type *type)
{
/* reset the bounds to NULL during a re-resolve */
type->bounds = NULL;
}
static void cil_reset_typeattr(struct cil_typeattribute *attr)
{
/* during a re-resolve, we need to reset the lists of expression stacks associated with this attribute from a attributetypes statement */
if (attr->expr_list != NULL) {
/* we don't want to destroy the expression stacks (cil_list) inside
* this list cil_list_destroy destroys sublists, so we need to do it
* manually */
struct cil_list_item *expr = attr->expr_list->head;
while (expr != NULL) {
struct cil_list_item *next = expr->next;
cil_list_item_destroy(&expr, CIL_FALSE);
expr = next;
}
free(attr->expr_list);
attr->expr_list = NULL;
}
attr->used = CIL_FALSE;
attr->keep = CIL_FALSE;
}
static void cil_reset_typeattributeset(struct cil_typeattributeset *tas)
{
cil_list_destroy(&tas->datum_expr, CIL_FALSE);
}
static void cil_reset_expandtypeattribute(struct cil_expandtypeattribute *expandattr)
{
cil_list_destroy(&expandattr->attr_datums, CIL_FALSE);
}
static void cil_reset_avrule(struct cil_avrule *rule)
{
cil_reset_classperms_list(rule->perms.classperms);
}
static void cil_reset_deny_rule(struct cil_deny_rule *rule)
{
cil_reset_classperms_list(rule->classperms);
}
static void cil_reset_rangetransition(struct cil_rangetransition *rangetrans)
{
if (rangetrans->range_str == NULL) {
cil_reset_levelrange(rangetrans->range);
} else {
rangetrans->range = NULL;
}
}
static void cil_reset_sens(struct cil_sens *sens)
{
/* during a re-resolve, we need to reset the categories associated with
* this sensitivity from a (sensitivitycategory) statement */
cil_list_destroy(&sens->cats_list, CIL_FALSE);
sens->ordered = CIL_FALSE;
}
static void cil_reset_cat(struct cil_cat *cat)
{
cat->ordered = CIL_FALSE;
}
static inline void cil_reset_cats(struct cil_cats *cats)
{
if (cats != NULL) {
cats->evaluated = CIL_FALSE;
cil_list_destroy(&cats->datum_expr, CIL_FALSE);
}
}
static void cil_reset_senscat(struct cil_senscat *senscat)
{
cil_reset_cats(senscat->cats);
}
static void cil_reset_catset(struct cil_catset *catset)
{
cil_reset_cats(catset->cats);
}
static inline void cil_reset_level(struct cil_level *level)
{
level->sens = NULL;
cil_reset_cats(level->cats);
}
static inline void cil_reset_levelrange(struct cil_levelrange *levelrange)
{
if (levelrange->low_str == NULL) {
cil_reset_level(levelrange->low);
} else {
levelrange->low = NULL;
}
if (levelrange->high_str == NULL) {
cil_reset_level(levelrange->high);
} else {
levelrange->high = NULL;
}
}
static inline void cil_reset_userlevel(struct cil_userlevel *userlevel)
{
if (userlevel->level_str == NULL) {
cil_reset_level(userlevel->level);
} else {
userlevel->level = NULL;
}
}
static inline void cil_reset_userrange(struct cil_userrange *userrange)
{
if (userrange->range_str == NULL) {
cil_reset_levelrange(userrange->range);
} else {
userrange->range = NULL;
}
}
static inline void cil_reset_context(struct cil_context *context)
{
if (!context) {
return;
}
if (context->range_str == NULL) {
cil_reset_levelrange(context->range);
} else {
context->range = NULL;
}
}
static void cil_reset_sidcontext(struct cil_sidcontext *sidcontext)
{
if (sidcontext->context_str == NULL) {
cil_reset_context(sidcontext->context);
} else {
sidcontext->context = NULL;
}
}
static void cil_reset_filecon(struct cil_filecon *filecon)
{
if (filecon->context_str == NULL) {
cil_reset_context(filecon->context);
} else {
filecon->context = NULL;
}
}
static void cil_reset_ibpkeycon(struct cil_ibpkeycon *ibpkeycon)
{
if (ibpkeycon->context_str == NULL) {
cil_reset_context(ibpkeycon->context);
} else {
ibpkeycon->context = NULL;
}
}
static void cil_reset_portcon(struct cil_portcon *portcon)
{
if (portcon->context_str == NULL) {
cil_reset_context(portcon->context);
} else {
portcon->context = NULL;
}
}
static void cil_reset_nodecon(struct cil_nodecon *nodecon)
{
if (nodecon->context_str == NULL) {
cil_reset_context(nodecon->context);
} else {
nodecon->context = NULL;
}
}
static void cil_reset_genfscon(struct cil_genfscon *genfscon)
{
if (genfscon->context_str == NULL) {
cil_reset_context(genfscon->context);
} else {
genfscon->context = NULL;
}
}
static void cil_reset_netifcon(struct cil_netifcon *netifcon)
{
if (netifcon->if_context_str == NULL) {
cil_reset_context(netifcon->if_context);
} else {
netifcon->if_context = NULL;
}
if (netifcon->packet_context_str == NULL) {
cil_reset_context(netifcon->packet_context);
} else {
netifcon->packet_context = NULL;
}
}
static void cil_reset_ibendportcon(struct cil_ibendportcon *ibendportcon)
{
if (ibendportcon->context_str == NULL) {
cil_reset_context(ibendportcon->context);
} else {
ibendportcon->context = NULL;
}
}
static void cil_reset_pirqcon(struct cil_pirqcon *pirqcon)
{
if (pirqcon->context_str == NULL) {
cil_reset_context(pirqcon->context);
} else {
pirqcon->context = NULL;
}
}
static void cil_reset_iomemcon(struct cil_iomemcon *iomemcon)
{
if (iomemcon->context_str == NULL) {
cil_reset_context(iomemcon->context);
} else {
iomemcon->context = NULL;
}
}
static void cil_reset_ioportcon(struct cil_ioportcon *ioportcon)
{
if (ioportcon->context_str == NULL) {
cil_reset_context(ioportcon->context);
} else {
ioportcon->context = NULL;
}
}
static void cil_reset_pcidevicecon(struct cil_pcidevicecon *pcidevicecon)
{
if (pcidevicecon->context_str == NULL) {
cil_reset_context(pcidevicecon->context);
} else {
pcidevicecon->context = NULL;
}
}
static void cil_reset_devicetreecon(struct cil_devicetreecon *devicetreecon)
{
if (devicetreecon->context_str == NULL) {
cil_reset_context(devicetreecon->context);
} else {
devicetreecon->context = NULL;
}
}
static void cil_reset_fsuse(struct cil_fsuse *fsuse)
{
if (fsuse->context_str == NULL) {
cil_reset_context(fsuse->context);
} else {
fsuse->context = NULL;
}
}
static void cil_reset_sid(struct cil_sid *sid)
{
/* reset the context to NULL during a re-resolve */
sid->context = NULL;
sid->ordered = CIL_FALSE;
}
static void cil_reset_constrain(struct cil_constrain *con)
{
cil_reset_classperms_list(con->classperms);
cil_list_destroy(&con->datum_expr, CIL_FALSE);
}
static void cil_reset_validatetrans(struct cil_validatetrans *vt)
{
cil_list_destroy(&vt->datum_expr, CIL_FALSE);
}
static void cil_reset_default(struct cil_default *def)
{
cil_list_destroy(&def->class_datums, CIL_FALSE);
}
static void cil_reset_defaultrange(struct cil_defaultrange *def)
{
cil_list_destroy(&def->class_datums, CIL_FALSE);
}
static void cil_reset_booleanif(struct cil_booleanif *bif)
{
cil_list_destroy(&bif->datum_expr, CIL_FALSE);
}
static int __cil_reset_node(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, __attribute__((unused)) void *extra_args)
{
switch (node->flavor) {
case CIL_CLASS:
cil_reset_class(node->data);
break;
case CIL_PERM:
case CIL_MAP_PERM:
cil_reset_perm(node->data);
break;
case CIL_CLASSPERMISSION:
cil_reset_classpermission(node->data);
break;
case CIL_CLASSPERMISSIONSET:
cil_reset_classpermissionset(node->data);
break;
case CIL_CLASSMAPPING:
cil_reset_classmapping(node->data);
break;
case CIL_TYPEALIAS:
case CIL_SENSALIAS:
case CIL_CATALIAS:
cil_reset_alias(node->data);
break;
case CIL_USERRANGE:
cil_reset_userrange(node->data);
break;
case CIL_USERLEVEL:
cil_reset_userlevel(node->data);
break;
case CIL_USER:
cil_reset_user(node->data);
break;
case CIL_USERATTRIBUTE:
cil_reset_userattr(node->data);
break;
case CIL_USERATTRIBUTESET:
cil_reset_userattributeset(node->data);
break;
case CIL_SELINUXUSERDEFAULT:
case CIL_SELINUXUSER:
cil_reset_selinuxuser(node->data);
break;
case CIL_ROLE:
cil_reset_role(node->data);
break;
case CIL_ROLEATTRIBUTE:
cil_reset_roleattr(node->data);
break;
case CIL_ROLEATTRIBUTESET:
cil_reset_roleattributeset(node->data);
break;
case CIL_TYPE:
cil_reset_type(node->data);
break;
case CIL_TYPEATTRIBUTE:
cil_reset_typeattr(node->data);
break;
case CIL_TYPEATTRIBUTESET:
cil_reset_typeattributeset(node->data);
break;
case CIL_EXPANDTYPEATTRIBUTE:
cil_reset_expandtypeattribute(node->data);
break;
case CIL_RANGETRANSITION:
cil_reset_rangetransition(node->data);
break;
case CIL_AVRULE:
cil_reset_avrule(node->data);
break;
case CIL_DENY_RULE:
cil_reset_deny_rule(node->data);
break;
case CIL_SENS:
cil_reset_sens(node->data);
break;
case CIL_CAT:
cil_reset_cat(node->data);
break;
case CIL_SENSCAT:
cil_reset_senscat(node->data);
break;
case CIL_CATSET:
cil_reset_catset(node->data);
break;
case CIL_LEVEL:
cil_reset_level(node->data);
break;
case CIL_LEVELRANGE:
cil_reset_levelrange(node->data);
break;
case CIL_CONTEXT:
cil_reset_context(node->data);
break;
case CIL_SIDCONTEXT:
cil_reset_sidcontext(node->data);
break;
case CIL_FILECON:
cil_reset_filecon(node->data);
break;
case CIL_IBPKEYCON:
cil_reset_ibpkeycon(node->data);
break;
case CIL_IBENDPORTCON:
cil_reset_ibendportcon(node->data);
break;
case CIL_PORTCON:
cil_reset_portcon(node->data);
break;
case CIL_NODECON:
cil_reset_nodecon(node->data);
break;
case CIL_GENFSCON:
cil_reset_genfscon(node->data);
break;
case CIL_NETIFCON:
cil_reset_netifcon(node->data);
break;
case CIL_PIRQCON:
cil_reset_pirqcon(node->data);
break;
case CIL_IOMEMCON:
cil_reset_iomemcon(node->data);
break;
case CIL_IOPORTCON:
cil_reset_ioportcon(node->data);
break;
case CIL_PCIDEVICECON:
cil_reset_pcidevicecon(node->data);
break;
case CIL_DEVICETREECON:
cil_reset_devicetreecon(node->data);
break;
case CIL_FSUSE:
cil_reset_fsuse(node->data);
break;
case CIL_SID:
cil_reset_sid(node->data);
break;
case CIL_CONSTRAIN:
case CIL_MLSCONSTRAIN:
cil_reset_constrain(node->data);
break;
case CIL_VALIDATETRANS:
case CIL_MLSVALIDATETRANS:
cil_reset_validatetrans(node->data);
break;
case CIL_DEFAULTUSER:
case CIL_DEFAULTROLE:
case CIL_DEFAULTTYPE:
cil_reset_default(node->data);
break;
case CIL_DEFAULTRANGE:
cil_reset_defaultrange(node->data);
break;
case CIL_BOOLEANIF:
cil_reset_booleanif(node->data);
break;
case CIL_SIDORDER:
case CIL_CLASSORDER:
case CIL_CATORDER:
case CIL_SENSITIVITYORDER:
cil_reset_ordered(node->data);
break;
case CIL_TUNABLEIF:
case CIL_CALL:
break; /* Not effected by optional block disabling */
case CIL_MACRO:
break; /* Nothing to reset */
default:
break;
}
return SEPOL_OK;
}
int cil_reset_ast(struct cil_tree_node *current)
{
int rc = SEPOL_ERR;
rc = cil_tree_walk(current, __cil_reset_node, NULL, NULL, NULL);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to reset AST\n");
return SEPOL_ERR;
}
return SEPOL_OK;
}
libsepol-3.8.1/cil/src/cil_reset_ast.h000066400000000000000000000002331476211737200176730ustar00rootroot00000000000000#ifndef CIL_RESET_AST_H_
#define CIL_RESET_AST_H_
#include "cil_tree.h"
int cil_reset_ast(struct cil_tree_node *current);
#endif /* CIL_RESET_AST_H_ */
libsepol-3.8.1/cil/src/cil_resolve_ast.c000066400000000000000000003346431476211737200202420ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_build_ast.h"
#include "cil_resolve_ast.h"
#include "cil_reset_ast.h"
#include "cil_copy_ast.h"
#include "cil_verify.h"
#include "cil_strpool.h"
#include "cil_symtab.h"
#include "cil_stack.h"
struct cil_args_resolve {
struct cil_db *db;
enum cil_pass pass;
uint32_t *changed;
struct cil_list *to_destroy;
struct cil_tree_node *block;
struct cil_tree_node *macro;
struct cil_tree_node *optional;
struct cil_tree_node *disabled_optional;
struct cil_tree_node *boolif;
struct cil_list *sidorder_lists;
struct cil_list *classorder_lists;
struct cil_list *unordered_classorder_lists;
struct cil_list *catorder_lists;
struct cil_list *sensitivityorder_lists;
struct cil_list *in_list_before;
struct cil_list *in_list_after;
struct cil_list *abstract_blocks;
};
static int __cil_resolve_perms(symtab_t *class_symtab, symtab_t *common_symtab, struct cil_list *perm_strs, struct cil_list **perm_datums, enum cil_flavor class_flavor)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
cil_list_init(perm_datums, perm_strs->flavor);
cil_list_for_each(curr, perm_strs) {
if (curr->flavor == CIL_LIST) {
struct cil_list *sub_list;
rc = __cil_resolve_perms(class_symtab, common_symtab, curr->data, &sub_list, class_flavor);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve permission list\n");
goto exit;
}
cil_list_append(*perm_datums, CIL_LIST, sub_list);
} else if (curr->flavor == CIL_STRING) {
struct cil_symtab_datum *perm_datum = NULL;
rc = cil_symtab_get_datum(class_symtab, curr->data, &perm_datum);
if (rc == SEPOL_ENOENT) {
if (common_symtab) {
rc = cil_symtab_get_datum(common_symtab, curr->data, &perm_datum);
}
}
if (rc != SEPOL_OK) {
if (class_flavor == CIL_MAP_CLASS) {
cil_log(CIL_ERR, "Failed to resolve permission %s for map class\n", (char*)curr->data);
} else {
cil_log(CIL_ERR, "Failed to resolve permission %s\n", (char*)curr->data);
}
goto exit;
}
cil_list_append(*perm_datums, CIL_DATUM, perm_datum);
} else {
cil_list_append(*perm_datums, curr->flavor, curr->data);
}
}
return SEPOL_OK;
exit:
cil_list_destroy(perm_datums, CIL_FALSE);
return rc;
}
int cil_resolve_classperms(struct cil_tree_node *current, struct cil_classperms *cp, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_symtab_datum *datum = NULL;
symtab_t *common_symtab = NULL;
struct cil_class *class;
if (cp->class) {
return SEPOL_OK;
}
rc = cil_resolve_name(current, cp->class_str, CIL_SYM_CLASSES, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
class = (struct cil_class *)datum;
if (class->common != NULL) {
common_symtab = &class->common->perms;
}
cp->class = class;
rc = __cil_resolve_perms(&class->perms, common_symtab, cp->perm_strs, &cp->perms, FLAVOR(datum));
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_classperms_set(struct cil_tree_node *current, struct cil_classperms_set *cp_set, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_symtab_datum *datum = NULL;
rc = cil_resolve_name(current, cp_set->set_str, CIL_SYM_CLASSPERMSETS, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
cp_set->set = (struct cil_classpermission*)datum;
/* This could be an anonymous classpermission */
if (datum->name == NULL) {
rc = cil_resolve_classperms_list(current, cp_set->set->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_classperms_list(struct cil_tree_node *current, struct cil_list *cp_list, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
cil_list_for_each(curr, cp_list) {
if (curr->flavor == CIL_CLASSPERMS) {
rc = cil_resolve_classperms(current, curr->data, db);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
rc = cil_resolve_classperms_set(current, curr->data, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_classpermissionset(struct cil_tree_node *current, struct cil_classpermissionset *cps, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
struct cil_symtab_datum *datum;
struct cil_classpermission *cp;
rc = cil_resolve_name(current, cps->set_str, CIL_SYM_CLASSPERMSETS, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (!datum->fqn) {
cil_tree_log(current, CIL_ERR, "Anonymous classpermission used in a classpermissionset");
rc = SEPOL_ERR;
goto exit;
}
rc = cil_resolve_classperms_list(current, cps->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
cp = (struct cil_classpermission *)datum;
cps->set = cp;
if (cp->classperms == NULL) {
cil_list_init(&cp->classperms, CIL_CLASSPERMS);
}
cil_list_for_each(curr, cps->classperms) {
cil_list_append(cp->classperms, curr->flavor, curr->data);
}
return SEPOL_OK;
exit:
return rc;
}
static void cil_type_used(struct cil_symtab_datum *datum, int used)
{
struct cil_typeattribute *attr = NULL;
if (FLAVOR(datum) == CIL_TYPEATTRIBUTE) {
attr = (struct cil_typeattribute*)datum;
attr->used |= used;
if ((attr->used & CIL_ATTR_EXPAND_TRUE) &&
(attr->used & CIL_ATTR_EXPAND_FALSE)) {
cil_log(CIL_WARN, "Conflicting use of expandtypeattribute. "
"Expandtypeattribute was set to both true or false for %s. "
"Resolving to false. \n", attr->datum.name);
attr->used &= ~CIL_ATTR_EXPAND_TRUE;
}
}
}
static int cil_resolve_permissionx(struct cil_tree_node *current, struct cil_permissionx *permx, struct cil_db *db)
{
struct cil_symtab_datum *obj_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, permx->obj_str, CIL_SYM_CLASSES, db, &obj_datum);
if (rc != SEPOL_OK) {
goto exit;
}
permx->obj = (struct cil_class*)obj_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_avrule(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_avrule *rule = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
struct cil_symtab_datum *permx_datum = NULL;
int used;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, rule->src_str, CIL_SYM_TYPES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->src = src_datum;
if (rule->tgt_str == CIL_KEY_SELF) {
rule->tgt = db->selftype;
} else if (rule->tgt_str == CIL_KEY_NOTSELF) {
rule->tgt = db->notselftype;
} else if (rule->tgt_str == CIL_KEY_OTHER) {
rule->tgt = db->othertype;
} else {
rc = cil_resolve_name(current, rule->tgt_str, CIL_SYM_TYPES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->tgt = tgt_datum;
used = (rule->rule_kind == CIL_AVRULE_NEVERALLOW) ?
CIL_ATTR_NEVERALLOW : CIL_ATTR_AVRULE;
cil_type_used(src_datum, used); /* src not used if tgt is self */
cil_type_used(tgt_datum, used);
}
if (!rule->is_extended) {
rc = cil_resolve_classperms_list(current, rule->perms.classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
if (rule->perms.x.permx_str != NULL) {
rc = cil_resolve_name(current, rule->perms.x.permx_str, CIL_SYM_PERMX, db, &permx_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->perms.x.permx = (struct cil_permissionx*)permx_datum;
} else {
rc = cil_resolve_permissionx(current, rule->perms.x.permx, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_deny_rule(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_deny_rule *rule = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, rule->src_str, CIL_SYM_TYPES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->src = src_datum;
if (rule->tgt_str == CIL_KEY_SELF) {
rule->tgt = db->selftype;
} else if (rule->tgt_str == CIL_KEY_NOTSELF) {
rule->tgt = db->notselftype;
} else if (rule->tgt_str == CIL_KEY_OTHER) {
rule->tgt = db->othertype;
} else {
rc = cil_resolve_name(current, rule->tgt_str, CIL_SYM_TYPES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->tgt = tgt_datum;
}
rc = cil_resolve_classperms_list(current, rule->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_type_rule(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_type_rule *rule = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
struct cil_symtab_datum *obj_datum = NULL;
struct cil_symtab_datum *result_datum = NULL;
struct cil_tree_node *result_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, rule->src_str, CIL_SYM_TYPES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->src = src_datum;
if (rule->tgt_str == CIL_KEY_SELF) {
rule->tgt = db->selftype;
} else {
rc = cil_resolve_name(current, rule->tgt_str, CIL_SYM_TYPES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->tgt = tgt_datum;
}
rc = cil_resolve_name(current, rule->obj_str, CIL_SYM_CLASSES, db, &obj_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rule->obj = (struct cil_class*)obj_datum;
rc = cil_resolve_name(current, rule->result_str, CIL_SYM_TYPES, db, &result_datum);
if (rc != SEPOL_OK) {
goto exit;
}
result_node = NODE(result_datum);
if (result_node->flavor != CIL_TYPE) {
cil_log(CIL_ERR, "Type rule result must be a type [%d]\n",result_node->flavor);
rc = SEPOL_ERR;
goto exit;
}
rule->result = result_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_typeattributeset(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_typeattributeset *attrtypes = current->data;
struct cil_symtab_datum *attr_datum = NULL;
struct cil_tree_node *attr_node = NULL;
struct cil_typeattribute *attr = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, attrtypes->attr_str, CIL_SYM_TYPES, db, &attr_datum);
if (rc != SEPOL_OK) {
goto exit;
}
attr_node = NODE(attr_datum);
if (attr_node->flavor != CIL_TYPEATTRIBUTE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Attribute type not an attribute\n");
goto exit;
}
attr = (struct cil_typeattribute*)attr_datum;
rc = cil_resolve_expr(CIL_TYPEATTRIBUTESET, attrtypes->str_expr, &attrtypes->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
if (attr->expr_list == NULL) {
cil_list_init(&attr->expr_list, CIL_TYPEATTRIBUTE);
}
cil_list_append(attr->expr_list, CIL_LIST, attrtypes->datum_expr);
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_expandtypeattribute(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_expandtypeattribute *expandattr = current->data;
struct cil_symtab_datum *attr_datum = NULL;
struct cil_tree_node *attr_node = NULL;
struct cil_list_item *curr;
int used;
int rc = SEPOL_ERR;
cil_list_init(&expandattr->attr_datums, CIL_TYPE);
cil_list_for_each(curr, expandattr->attr_strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_TYPES, db, &attr_datum);
if (rc != SEPOL_OK) {
goto exit;
}
attr_node = NODE(attr_datum);
if (attr_node->flavor != CIL_TYPEATTRIBUTE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Attribute type not an attribute\n");
goto exit;
}
used = expandattr->expand ? CIL_ATTR_EXPAND_TRUE : CIL_ATTR_EXPAND_FALSE;
cil_type_used(attr_datum, used);
cil_list_append(expandattr->attr_datums, CIL_TYPE, attr_datum);
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_aliasactual(struct cil_tree_node *current, struct cil_db *db, enum cil_flavor flavor, enum cil_flavor alias_flavor)
{
int rc = SEPOL_ERR;
enum cil_sym_index sym_index;
struct cil_aliasactual *aliasactual = current->data;
struct cil_symtab_datum *alias_datum = NULL;
struct cil_symtab_datum *actual_datum = NULL;
struct cil_alias *alias;
rc = cil_flavor_to_symtab_index(flavor, &sym_index);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_resolve_name_keep_aliases(current, aliasactual->alias_str, sym_index, db, &alias_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (FLAVOR(alias_datum) != alias_flavor) {
cil_log(CIL_ERR, "%s is not an alias\n",alias_datum->name);
rc = SEPOL_ERR;
goto exit;
}
rc = cil_resolve_name(current, aliasactual->actual_str, sym_index, db, &actual_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (FLAVOR(actual_datum) != flavor && FLAVOR(actual_datum) != alias_flavor) {
cil_log(CIL_ERR, "%s is a %s, but aliases a %s\n", alias_datum->name, cil_node_to_string(NODE(alias_datum)), cil_node_to_string(NODE(actual_datum)));
rc = SEPOL_ERR;
goto exit;
}
alias = (struct cil_alias *)alias_datum;
aliasactual->alias = alias_datum;
if (alias->actual != NULL) {
cil_log(CIL_ERR, "%s %s cannot bind more than one value\n", cil_node_to_string(NODE(alias_datum)), alias_datum->name);
rc = SEPOL_ERR;
goto exit;
}
alias->actual = actual_datum;
aliasactual->actual = actual_datum;
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_alias_to_actual(struct cil_tree_node *current, enum cil_flavor flavor)
{
struct cil_alias *alias = current->data;
struct cil_alias *a1 = current->data;
struct cil_alias *a2 = current->data;
struct cil_tree_node *a1_node = NULL;
int steps = 0;
int limit = 2;
if (alias->actual == NULL) {
cil_tree_log(current, CIL_ERR, "Alias declared but not used");
return SEPOL_ERR;
}
a1_node = a1->datum.nodes->head->data;
while (flavor != a1_node->flavor) {
if (a1->actual == NULL) {
cil_tree_log(current, CIL_ERR, "Alias %s references an unused alias %s", alias->datum.name, a1->datum.name);
return SEPOL_ERR;
}
a1 = a1->actual;
a1_node = a1->datum.nodes->head->data;
steps += 1;
if (a1 == a2) {
cil_log(CIL_ERR, "Circular alias found: %s ", a1->datum.name);
a1 = a1->actual;
while (a1 != a2) {
cil_log(CIL_ERR, "%s ", a1->datum.name);
a1 = a1->actual;
}
cil_log(CIL_ERR,"\n");
return SEPOL_ERR;
}
if (steps == limit) {
steps = 0;
limit *= 2;
a2 = a1;
}
}
alias->actual = a1;
return SEPOL_OK;
}
int cil_resolve_typepermissive(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_typepermissive *typeperm = current->data;
struct cil_symtab_datum *type_datum = NULL;
struct cil_tree_node *type_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, typeperm->type_str, CIL_SYM_TYPES, db, &type_datum);
if (rc != SEPOL_OK) {
goto exit;
}
type_node = NODE(type_datum);
if (type_node->flavor != CIL_TYPE && type_node->flavor != CIL_TYPEALIAS) {
cil_log(CIL_ERR, "Typepermissive must be a type or type alias\n");
rc = SEPOL_ERR;
goto exit;
}
typeperm->type = type_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_nametypetransition(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_nametypetransition *nametypetrans = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
struct cil_symtab_datum *obj_datum = NULL;
struct cil_symtab_datum *name_datum = NULL;
struct cil_symtab_datum *result_datum = NULL;
struct cil_tree_node *result_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, nametypetrans->src_str, CIL_SYM_TYPES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nametypetrans->src = src_datum;
if (nametypetrans->tgt_str == CIL_KEY_SELF) {
nametypetrans->tgt = db->selftype;
} else {
rc = cil_resolve_name(current, nametypetrans->tgt_str, CIL_SYM_TYPES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nametypetrans->tgt = tgt_datum;
}
rc = cil_resolve_name(current, nametypetrans->obj_str, CIL_SYM_CLASSES, db, &obj_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nametypetrans->obj = (struct cil_class*)obj_datum;
if (!nametypetrans->name) {
rc = cil_resolve_name(current, nametypetrans->name_str, CIL_SYM_STRINGS, db, &name_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nametypetrans->name = name_datum;
}
rc = cil_resolve_name(current, nametypetrans->result_str, CIL_SYM_TYPES, db, &result_datum);
if (rc != SEPOL_OK) {
goto exit;
}
result_node = NODE(result_datum);
if (result_node->flavor != CIL_TYPE && result_node->flavor != CIL_TYPEALIAS) {
cil_log(CIL_ERR, "typetransition result is not a type or type alias\n");
rc = SEPOL_ERR;
goto exit;
}
nametypetrans->result = result_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_rangetransition(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_rangetransition *rangetrans = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *exec_datum = NULL;
struct cil_symtab_datum *obj_datum = NULL;
struct cil_symtab_datum *range_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, rangetrans->src_str, CIL_SYM_TYPES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rangetrans->src = src_datum;
rc = cil_resolve_name(current, rangetrans->exec_str, CIL_SYM_TYPES, db, &exec_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rangetrans->exec = exec_datum;
rc = cil_resolve_name(current, rangetrans->obj_str, CIL_SYM_CLASSES, db, &obj_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rangetrans->obj = (struct cil_class*)obj_datum;
if (rangetrans->range_str != NULL) {
rc = cil_resolve_name(current, rangetrans->range_str, CIL_SYM_LEVELRANGES, db, &range_datum);
if (rc != SEPOL_OK) {
goto exit;
}
rangetrans->range = (struct cil_levelrange*)range_datum;
/* This could still be an anonymous levelrange even if range_str is set, if range_str is a param_str*/
if (rangetrans->range->datum.name == NULL) {
rc = cil_resolve_levelrange(current, rangetrans->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
rc = cil_resolve_levelrange(current, rangetrans->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __class_update_perm_values(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_perm *perm = (struct cil_perm *)d;
perm->value += *((int *)args);
return SEPOL_OK;
}
int cil_resolve_classcommon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_class *class = NULL;
struct cil_class *common = NULL;
struct cil_classcommon *clscom = current->data;
struct cil_symtab_datum *class_datum = NULL;
struct cil_symtab_datum *common_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, clscom->class_str, CIL_SYM_CLASSES, db, &class_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (NODE(class_datum)->flavor != CIL_CLASS) {
cil_log(CIL_ERR, "Class %s is not a kernel class and cannot be associated with common %s\n", clscom->class_str, clscom->common_str);
rc = SEPOL_ERR;
goto exit;
}
rc = cil_resolve_name(current, clscom->common_str, CIL_SYM_COMMONS, db, &common_datum);
if (rc != SEPOL_OK) {
goto exit;
}
class = (struct cil_class *)class_datum;
common = (struct cil_class *)common_datum;
if (class->common != NULL) {
cil_log(CIL_ERR, "class cannot be associated with more than one common\n");
rc = SEPOL_ERR;
goto exit;
}
class->common = common;
clscom->class = class;
clscom->common = common;
cil_symtab_map(&class->perms, __class_update_perm_values, &common->num_perms);
class->num_perms += common->num_perms;
if (class->num_perms > CIL_PERMS_PER_CLASS) {
cil_tree_log(current, CIL_ERR, "Too many permissions in class '%s' when including common permissions", class->datum.name);
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_classmapping(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_classmapping *mapping = current->data;
struct cil_class *map = NULL;
struct cil_perm *mp = NULL;
struct cil_symtab_datum *datum = NULL;
struct cil_list_item *curr;
rc = cil_resolve_name(current, mapping->map_class_str, CIL_SYM_CLASSES, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
map = (struct cil_class*)datum;
mapping->map_class = map;
rc = cil_symtab_get_datum(&map->perms, mapping->map_perm_str, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
mp = (struct cil_perm*)datum;
mapping->map_perm = mp;
rc = cil_resolve_classperms_list(current, mapping->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
if (mp->classperms == NULL) {
cil_list_init(&mp->classperms, CIL_CLASSPERMS);
}
cil_list_for_each(curr, mapping->classperms) {
cil_list_append(mp->classperms, curr->flavor, curr->data);
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_userrole(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_userrole *userrole = current->data;
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *role_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, userrole->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
userrole->user = (struct cil_user*)user_datum;
rc = cil_resolve_name(current, userrole->role_str, CIL_SYM_ROLES, db, &role_datum);
if (rc != SEPOL_OK) {
goto exit;
}
userrole->role = role_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_userlevel(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_userlevel *usrlvl = current->data;
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *lvl_datum = NULL;
struct cil_user *user = NULL;
struct cil_tree_node *user_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, usrlvl->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
user_node = NODE(user_datum);
if (user_node->flavor != CIL_USER) {
cil_log(CIL_ERR, "Userlevel must be a user\n");
rc = SEPOL_ERR;
goto exit;
}
user = (struct cil_user*)user_datum;
usrlvl->user = user;
if (usrlvl->level_str != NULL) {
rc = cil_resolve_name(current, usrlvl->level_str, CIL_SYM_LEVELS, db, &lvl_datum);
if (rc != SEPOL_OK) {
goto exit;
}
usrlvl->level = (struct cil_level*)lvl_datum;
user->dftlevel = usrlvl->level;
/* This could still be an anonymous level even if level_str is set, if level_str is a param_str*/
if (user->dftlevel->datum.name == NULL) {
rc = cil_resolve_level(current, user->dftlevel, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (usrlvl->level != NULL) {
rc = cil_resolve_level(current, usrlvl->level, db);
if (rc != SEPOL_OK) {
goto exit;
}
user->dftlevel = usrlvl->level;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_userrange(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_userrange *userrange = current->data;
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *range_datum = NULL;
struct cil_user *user = NULL;
struct cil_tree_node *user_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, userrange->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
user_node = NODE(user_datum);
if (user_node->flavor != CIL_USER) {
cil_log(CIL_ERR, "Userrange must be a user: %s\n", user_datum->fqn);
rc = SEPOL_ERR;
goto exit;
}
user = (struct cil_user*)user_datum;
userrange->user = user;
if (userrange->range_str != NULL) {
rc = cil_resolve_name(current, userrange->range_str, CIL_SYM_LEVELRANGES, db, &range_datum);
if (rc != SEPOL_OK) {
goto exit;
}
userrange->range = (struct cil_levelrange*)range_datum;
user->range = userrange->range;
/* This could still be an anonymous levelrange even if levelrange_str is set, if levelrange_str is a param_str*/
if (user->range->datum.name == NULL) {
rc = cil_resolve_levelrange(current, user->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (userrange->range != NULL) {
rc = cil_resolve_levelrange(current, userrange->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
user->range = userrange->range;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_userprefix(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_userprefix *userprefix = current->data;
struct cil_symtab_datum *user_datum = NULL;
struct cil_tree_node *user_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, userprefix->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
user_node = NODE(user_datum);
if (user_node->flavor != CIL_USER) {
cil_log(CIL_ERR, "Userprefix must be a user: %s\n", user_datum->fqn);
rc = SEPOL_ERR;
goto exit;
}
userprefix->user = (struct cil_user*)user_datum;
exit:
return rc;
}
int cil_resolve_selinuxuser(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_selinuxuser *selinuxuser = current->data;
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *lvlrange_datum = NULL;
struct cil_tree_node *user_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, selinuxuser->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
user_node = NODE(user_datum);
if (user_node->flavor != CIL_USER) {
cil_log(CIL_ERR, "Selinuxuser must be a user: %s\n", user_datum->fqn);
rc = SEPOL_ERR;
goto exit;
}
selinuxuser->user = (struct cil_user*)user_datum;
if (selinuxuser->range_str != NULL) {
rc = cil_resolve_name(current, selinuxuser->range_str, CIL_SYM_LEVELRANGES, db, &lvlrange_datum);
if (rc != SEPOL_OK) {
goto exit;
}
selinuxuser->range = (struct cil_levelrange*)lvlrange_datum;
/* This could still be an anonymous levelrange even if range_str is set, if range_str is a param_str*/
if (selinuxuser->range->datum.name == NULL) {
rc = cil_resolve_levelrange(current, selinuxuser->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (selinuxuser->range != NULL) {
rc = cil_resolve_levelrange(current, selinuxuser->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = SEPOL_OK;
exit:
return rc;
}
int cil_resolve_roletype(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_roletype *roletype = current->data;
struct cil_symtab_datum *role_datum = NULL;
struct cil_symtab_datum *type_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, roletype->role_str, CIL_SYM_ROLES, db, &role_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roletype->role = (struct cil_role*)role_datum;
rc = cil_resolve_name(current, roletype->type_str, CIL_SYM_TYPES, db, &type_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roletype->type = (struct cil_type*)type_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_roletransition(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_roletransition *roletrans = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
struct cil_symtab_datum *obj_datum = NULL;
struct cil_symtab_datum *result_datum = NULL;
struct cil_tree_node *node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, roletrans->src_str, CIL_SYM_ROLES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roletrans->src = (struct cil_role*)src_datum;
rc = cil_resolve_name(current, roletrans->tgt_str, CIL_SYM_TYPES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roletrans->tgt = tgt_datum;
rc = cil_resolve_name(current, roletrans->obj_str, CIL_SYM_CLASSES, db, &obj_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roletrans->obj = (struct cil_class*)obj_datum;
rc = cil_resolve_name(current, roletrans->result_str, CIL_SYM_ROLES, db, &result_datum);
if (rc != SEPOL_OK) {
goto exit;
}
node = NODE(result_datum);
if (node->flavor != CIL_ROLE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "roletransition must result in a role, but %s is a %s\n", roletrans->result_str, cil_node_to_string(node));
goto exit;
}
roletrans->result = (struct cil_role*)result_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_roleallow(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_roleallow *roleallow = current->data;
struct cil_symtab_datum *src_datum = NULL;
struct cil_symtab_datum *tgt_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, roleallow->src_str, CIL_SYM_ROLES, db, &src_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roleallow->src = (struct cil_role*)src_datum;
rc = cil_resolve_name(current, roleallow->tgt_str, CIL_SYM_ROLES, db, &tgt_datum);
if (rc != SEPOL_OK) {
goto exit;
}
roleallow->tgt = (struct cil_role*)tgt_datum;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_roleattributeset(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_roleattributeset *attrroles = current->data;
struct cil_symtab_datum *attr_datum = NULL;
struct cil_tree_node *attr_node = NULL;
struct cil_roleattribute *attr = NULL;
rc = cil_resolve_name(current, attrroles->attr_str, CIL_SYM_ROLES, db, &attr_datum);
if (rc != SEPOL_OK) {
goto exit;
}
attr_node = NODE(attr_datum);
if (attr_node->flavor != CIL_ROLEATTRIBUTE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Attribute role not an attribute\n");
goto exit;
}
attr = (struct cil_roleattribute*)attr_datum;
rc = cil_resolve_expr(CIL_ROLEATTRIBUTESET, attrroles->str_expr, &attrroles->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
if (attr->expr_list == NULL) {
cil_list_init(&attr->expr_list, CIL_ROLEATTRIBUTE);
}
cil_list_append(attr->expr_list, CIL_LIST, attrroles->datum_expr);
return SEPOL_OK;
exit:
return rc;
}
static struct cil_list_item *__cil_ordered_item_insert(struct cil_list *old, struct cil_list_item *curr, struct cil_list_item *item)
{
if (item->flavor == CIL_SID) {
struct cil_sid *sid = item->data;
if (sid->ordered == CIL_TRUE) {
cil_log(CIL_ERR, "SID %s has already been merged into the ordered list\n", sid->datum.name);
return NULL;
}
sid->ordered = CIL_TRUE;
} else if (item->flavor == CIL_CLASS) {
struct cil_class *class = item->data;
if (class->ordered == CIL_TRUE) {
cil_log(CIL_ERR, "Class %s has already been merged into the ordered list\n", class->datum.name);
return NULL;
}
class->ordered = CIL_TRUE;
} else if (item->flavor == CIL_CAT) {
struct cil_cat *cat = item->data;
if (cat->ordered == CIL_TRUE) {
cil_log(CIL_ERR, "Category %s has already been merged into the ordered list\n", cat->datum.name);
return NULL;
}
cat->ordered = CIL_TRUE;
} else if (item->flavor == CIL_SENS) {
struct cil_sens *sens = item->data;
if (sens->ordered == CIL_TRUE) {
cil_log(CIL_ERR, "Sensitivity %s has already been merged into the ordered list\n", sens->datum.name);
return NULL;
}
sens->ordered = CIL_TRUE;
}
return cil_list_insert(old, curr, item->flavor, item->data);
}
static int __cil_ordered_list_insert(struct cil_list *old, struct cil_list_item *ocurr, struct cil_list_item *nstart, struct cil_list_item *nstop)
{
struct cil_list_item *ncurr = NULL;
for (ncurr = nstart; ncurr != nstop; ncurr = ncurr->next) {
ocurr = __cil_ordered_item_insert(old, ocurr, ncurr);
if (ocurr == NULL) {
return SEPOL_ERR;
}
}
return SEPOL_OK;
}
static void __cil_ordered_find_next_match(struct cil_list_item **i, struct cil_list_item **j, struct cil_list_item **p)
{
struct cil_list_item *pstart = *p;
struct cil_list_item *jstart = *j;
while (*i) {
*p = pstart;
*j = jstart;
while (*j) {
if ((*i)->data == (*j)->data) {
return;
}
*p = *j;
*j = (*j)->next;
}
*i = (*i)->next;
}
}
static int __cil_ordered_lists_merge(struct cil_list *old, struct cil_list *new)
{
struct cil_list_item *ofirst = old->head;
struct cil_list_item *ocurr = NULL;
struct cil_list_item *oprev = NULL;
struct cil_list_item *nfirst = new->head;
struct cil_list_item *ncurr = NULL;
int rc = SEPOL_ERR;
if (nfirst == NULL) {
return SEPOL_OK;
}
if (ofirst == NULL) {
/* First list added */
return __cil_ordered_list_insert(old, NULL, nfirst, NULL);
}
ncurr = nfirst;
ocurr = ofirst;
oprev = NULL;
while (ncurr && ocurr) {
__cil_ordered_find_next_match(&ncurr, &ocurr, &oprev);
if (!ncurr || !ocurr) {
break;
}
if (ncurr != nfirst) {
rc = __cil_ordered_list_insert(old, oprev, nfirst, ncurr);
if (rc != SEPOL_OK) {
return rc;
}
}
ncurr = ncurr->next;
nfirst = ncurr;
oprev = ocurr;
ocurr = ocurr->next;
}
if (!ncurr) {
if (!nfirst) {
/* Done */
return SEPOL_OK;
} else {
/* Can't merge yet */
return SEPOL_ERR;
}
}
if (ncurr && !ocurr) { /* some remaining */
rc = __cil_ordered_list_insert(old, oprev, ncurr, NULL);
if (rc != SEPOL_OK) {
return rc;
}
}
return SEPOL_OK;
}
static int insert_unordered(struct cil_list *merged, struct cil_list *unordered_list)
{
struct cil_tree_node *node;
struct cil_ordered *unordered;
struct cil_list_item *curr = NULL;
struct cil_list_item *item = NULL;
struct cil_list_item *ret = NULL;
int rc = SEPOL_ERR;
cil_list_for_each(curr, unordered_list) {
node = curr->data;
unordered = node->data;
cil_list_for_each(item, unordered->datums) {
if (cil_list_contains(merged, item->data)) {
/* item was declared in an ordered statement, which supersedes
* all unordered statements */
if (item->flavor == CIL_CLASS) {
cil_log(CIL_WARN, "Ignoring '%s' as it has already been declared in classorder.\n", ((struct cil_class*)(item->data))->datum.name);
}
continue;
}
ret = __cil_ordered_item_insert(merged, merged->tail, item);
if (ret == NULL) {
rc = SEPOL_ERR;
goto exit;
}
}
}
rc = SEPOL_OK;
exit:
return rc;
}
static struct cil_list *__cil_ordered_lists_merge_all(struct cil_list **ordered_lists, struct cil_list **unordered_lists)
{
struct cil_list *composite = NULL;
struct cil_tree_node *node;
struct cil_ordered *ordered;
struct cil_list_item *curr = NULL;
int changed = CIL_TRUE;
int waiting = 1;
int rc = SEPOL_ERR;
cil_list_init(&composite, (*ordered_lists)->flavor);
while (waiting && changed == CIL_TRUE) {
changed = CIL_FALSE;
waiting = 0;
cil_list_for_each(curr, *ordered_lists) {
node = curr->data;
ordered = node->data;
if (ordered->merged == CIL_FALSE) {
rc = __cil_ordered_lists_merge(composite, ordered->datums);
if (rc != SEPOL_OK) {
/* Can't merge yet */
waiting++;
} else {
ordered->merged = CIL_TRUE;
changed = CIL_TRUE;
}
}
}
if (waiting > 0 && changed == CIL_FALSE) {
cil_list_for_each(curr, *ordered_lists) {
node = curr->data;
ordered = node->data;
if (ordered->merged == CIL_FALSE) {
cil_tree_log(node, CIL_ERR, "Unable to merge ordered list");
}
}
goto exit;
}
}
rc = cil_verify_completed_ordered_list(composite, *ordered_lists);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Unable to validate ordering\n");
goto exit;
}
if (unordered_lists != NULL) {
rc = insert_unordered(composite, *unordered_lists);
if (rc != SEPOL_OK) {
goto exit;
}
}
return composite;
exit:
cil_list_destroy(&composite, CIL_FALSE);
return NULL;
}
int cil_resolve_classorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *classorder_list, struct cil_list *unordered_classorder_list)
{
struct cil_ordered *ordered = current->data;
struct cil_list_item *curr = NULL;
struct cil_symtab_datum *datum = NULL;
int rc = SEPOL_ERR;
int unordered = CIL_FALSE;
cil_list_init(&ordered->datums, CIL_DATUM);
cil_list_for_each(curr, ordered->strs) {
if (curr->data == CIL_KEY_UNORDERED) {
unordered = CIL_TRUE;
continue;
}
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_CLASSES, db, &datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve class %s in classorder\n", (char *)curr->data);
rc = SEPOL_ERR;
goto exit;
}
if (FLAVOR(datum) != CIL_CLASS) {
cil_log(CIL_ERR, "%s is not a class. Only classes are allowed in classorder statements\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
cil_list_append(ordered->datums, CIL_CLASS, datum);
}
if (unordered) {
cil_list_append(unordered_classorder_list, CIL_CLASSORDER, current);
} else {
cil_list_append(classorder_list, CIL_CLASSORDER, current);
}
return SEPOL_OK;
exit:
cil_list_destroy(&ordered->datums, CIL_FALSE);
return rc;
}
int cil_resolve_sidorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *sidorder_list)
{
struct cil_ordered *ordered = current->data;
struct cil_list_item *curr = NULL;
struct cil_symtab_datum *datum = NULL;
int rc = SEPOL_ERR;
cil_list_init(&ordered->datums, CIL_DATUM);
cil_list_for_each(curr, ordered->strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_SIDS, db, &datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve sid %s in sidorder\n", (char *)curr->data);
goto exit;
}
if (FLAVOR(datum) != CIL_SID) {
cil_log(CIL_ERR, "%s is not a sid. Only sids are allowed in sidorder statements\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
cil_list_append(ordered->datums, CIL_SID, datum);
}
cil_list_append(sidorder_list, CIL_SIDORDER, current);
return SEPOL_OK;
exit:
cil_list_destroy(&ordered->datums, CIL_FALSE);
return rc;
}
static void cil_set_cat_values(struct cil_list *ordered_cats, struct cil_db *db)
{
struct cil_list_item *curr;
int v = 0;
cil_list_for_each(curr, ordered_cats) {
struct cil_cat *cat = curr->data;
cat->value = v;
v++;
}
db->num_cats = v;
}
int cil_resolve_catorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *catorder_list)
{
struct cil_ordered *ordered = current->data;
struct cil_list_item *curr = NULL;
struct cil_symtab_datum *datum;
int rc = SEPOL_ERR;
cil_list_init(&ordered->datums, CIL_DATUM);
cil_list_for_each(curr, ordered->strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_CATS, db, &datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve category %s in categoryorder\n", (char *)curr->data);
goto exit;
}
if (FLAVOR(datum) != CIL_CAT) {
cil_log(CIL_ERR, "%s is not a category. Only categories are allowed in categoryorder statements\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
cil_list_append(ordered->datums, CIL_CAT, datum);
}
cil_list_append(catorder_list, CIL_CATORDER, current);
return SEPOL_OK;
exit:
cil_list_destroy(&ordered->datums, CIL_FALSE);
return rc;
}
int cil_resolve_sensitivityorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *sensitivityorder_list)
{
struct cil_ordered *ordered = current->data;
struct cil_list_item *curr = NULL;
struct cil_symtab_datum *datum = NULL;
int rc = SEPOL_ERR;
cil_list_init(&ordered->datums, CIL_DATUM);
cil_list_for_each(curr, ordered->strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_SENS, db, &datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to resolve sensitivity %s in sensitivityorder\n", (char *)curr->data);
goto exit;
}
if (FLAVOR(datum) != CIL_SENS) {
cil_log(CIL_ERR, "%s is not a sensitivity. Only sensitivities are allowed in sensitivityorder statements\n", datum->name);
rc = SEPOL_ERR;
goto exit;
}
cil_list_append(ordered->datums, CIL_SENS, datum);
}
cil_list_append(sensitivityorder_list, CIL_SENSITIVITYORDER, current);
return SEPOL_OK;
exit:
cil_list_destroy(&ordered->datums, CIL_FALSE);
return rc;
}
static int cil_resolve_cats(struct cil_tree_node *current, struct cil_cats *cats, struct cil_db *db)
{
int rc = SEPOL_ERR;
rc = cil_resolve_expr(CIL_CATSET, cats->str_expr, &cats->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_catset(struct cil_tree_node *current, struct cil_catset *catset, struct cil_db *db)
{
return cil_resolve_cats(current, catset->cats, db);
}
int cil_resolve_senscat(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_senscat *senscat = current->data;
struct cil_symtab_datum *sens_datum;
struct cil_sens *sens = NULL;
rc = cil_resolve_name(current, (char*)senscat->sens_str, CIL_SYM_SENS, db, &sens_datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to find sensitivity\n");
goto exit;
}
rc = cil_resolve_cats(current, senscat->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
sens = (struct cil_sens *)sens_datum;
if (sens->cats_list == NULL ) {
cil_list_init(&sens->cats_list, CIL_CAT);
}
cil_list_append(sens->cats_list, CIL_CAT, senscat->cats);
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_level(struct cil_tree_node *current, struct cil_level *level, struct cil_db *db)
{
struct cil_symtab_datum *sens_datum = NULL;
int rc = SEPOL_ERR;
if (level->sens) {
return SEPOL_OK;
}
rc = cil_resolve_name(current, (char*)level->sens_str, CIL_SYM_SENS, db, &sens_datum);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to find sensitivity\n");
goto exit;
}
level->sens = (struct cil_sens *)sens_datum;
if (level->cats != NULL) {
rc = cil_resolve_cats(current, level->cats, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_levelrange(struct cil_tree_node *current, struct cil_levelrange *lvlrange, struct cil_db *db)
{
struct cil_symtab_datum *low_datum = NULL;
struct cil_symtab_datum *high_datum = NULL;
int rc = SEPOL_ERR;
if (lvlrange->low_str != NULL) {
rc = cil_resolve_name(current, lvlrange->low_str, CIL_SYM_LEVELS, db, &low_datum);
if (rc != SEPOL_OK) {
goto exit;
}
lvlrange->low = (struct cil_level*)low_datum;
/* This could still be an anonymous level even if low_str is set, if low_str is a param_str */
if (lvlrange->low->datum.name == NULL) {
rc = cil_resolve_level(current, lvlrange->low, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (lvlrange->low != NULL) {
rc = cil_resolve_level(current, lvlrange->low, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (lvlrange->high_str != NULL) {
rc = cil_resolve_name(current, lvlrange->high_str, CIL_SYM_LEVELS, db, &high_datum);
if (rc != SEPOL_OK) {
goto exit;
}
lvlrange->high = (struct cil_level*)high_datum;
/* This could still be an anonymous level even if high_str is set, if high_str is a param_str */
if (lvlrange->high->datum.name == NULL) {
rc = cil_resolve_level(current, lvlrange->high, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (lvlrange->high != NULL) {
rc = cil_resolve_level(current, lvlrange->high, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_constrain(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_constrain *cons = current->data;
int rc = SEPOL_ERR;
rc = cil_resolve_classperms_list(current, cons->classperms, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_resolve_expr(CIL_CONSTRAIN, cons->str_expr, &cons->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_validatetrans(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_validatetrans *validtrans = current->data;
struct cil_symtab_datum *class_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, validtrans->class_str, CIL_SYM_CLASSES, db, &class_datum);
if (rc != SEPOL_OK) {
goto exit;
}
validtrans->class = (struct cil_class*)class_datum;
rc = cil_resolve_expr(CIL_VALIDATETRANS, validtrans->str_expr, &validtrans->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_context(struct cil_tree_node *current, struct cil_context *context, struct cil_db *db)
{
struct cil_symtab_datum *user_datum = NULL;
struct cil_symtab_datum *role_datum = NULL;
struct cil_symtab_datum *type_datum = NULL;
struct cil_tree_node *node = NULL;
struct cil_symtab_datum *lvlrange_datum = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, context->user_str, CIL_SYM_USERS, db, &user_datum);
if (rc != SEPOL_OK) {
goto exit;
}
node = NODE(user_datum);
if (node->flavor != CIL_USER) {
cil_log(CIL_ERR, "Context user must be a user: %s\n", user_datum->fqn);
rc = SEPOL_ERR;
goto exit;
}
context->user = (struct cil_user*)user_datum;
rc = cil_resolve_name(current, context->role_str, CIL_SYM_ROLES, db, &role_datum);
if (rc != SEPOL_OK) {
goto exit;
}
node = NODE(role_datum);
if (node->flavor != CIL_ROLE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Context role not a role: %s\n", role_datum->fqn);
goto exit;
}
context->role = (struct cil_role*)role_datum;
rc = cil_resolve_name(current, context->type_str, CIL_SYM_TYPES, db, &type_datum);
if (rc != SEPOL_OK) {
goto exit;
}
node = NODE(type_datum);
if (node->flavor != CIL_TYPE && node->flavor != CIL_TYPEALIAS) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Type not a type or type alias\n");
goto exit;
}
context->type = type_datum;
if (context->range_str != NULL) {
rc = cil_resolve_name(current, context->range_str, CIL_SYM_LEVELRANGES, db, &lvlrange_datum);
if (rc != SEPOL_OK) {
goto exit;
}
context->range = (struct cil_levelrange*)lvlrange_datum;
/* This could still be an anonymous levelrange even if levelrange_str is set, if levelrange_str is a param_str*/
if (context->range->datum.name == NULL) {
rc = cil_resolve_levelrange(current, context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (context->range != NULL) {
rc = cil_resolve_levelrange(current, context->range, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_filecon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_filecon *filecon = current->data;
struct cil_symtab_datum *context_datum = NULL;
struct cil_symtab_datum *path_datum = NULL;
int rc = SEPOL_ERR;
if (!filecon->path) {
rc = cil_resolve_name(current, filecon->path_str, CIL_SYM_STRINGS, db, &path_datum);
if (rc != SEPOL_OK) {
return rc;
}
filecon->path = path_datum;
}
if (filecon->context_str != NULL) {
rc = cil_resolve_name(current, filecon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
return rc;
}
filecon->context = (struct cil_context*)context_datum;
} else if (filecon->context != NULL) {
rc = cil_resolve_context(current, filecon->context, db);
if (rc != SEPOL_OK) {
return rc;
}
}
return SEPOL_OK;
}
int cil_resolve_ibpkeycon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_ibpkeycon *ibpkeycon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (ibpkeycon->context_str) {
rc = cil_resolve_name(current, ibpkeycon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK)
goto exit;
ibpkeycon->context = (struct cil_context *)context_datum;
} else {
rc = cil_resolve_context(current, ibpkeycon->context, db);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_portcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_portcon *portcon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (portcon->context_str != NULL) {
rc = cil_resolve_name(current, portcon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
portcon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, portcon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_genfscon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_genfscon *genfscon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (genfscon->context_str != NULL) {
rc = cil_resolve_name(current, genfscon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
genfscon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, genfscon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_nodecon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_nodecon *nodecon = current->data;
struct cil_symtab_datum *addr_datum = NULL;
struct cil_symtab_datum *mask_datum = NULL;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (nodecon->addr_str != NULL) {
rc = cil_resolve_name(current, nodecon->addr_str, CIL_SYM_IPADDRS, db, &addr_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nodecon->addr = (struct cil_ipaddr*)addr_datum;
}
if (nodecon->mask_str != NULL) {
rc = cil_resolve_name(current, nodecon->mask_str, CIL_SYM_IPADDRS, db, &mask_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nodecon->mask = (struct cil_ipaddr*)mask_datum;
}
if (nodecon->context_str != NULL) {
rc = cil_resolve_name(current, nodecon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
nodecon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, nodecon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (nodecon->addr->family != nodecon->mask->family) {
cil_log(CIL_ERR, "Nodecon ip address not in the same family\n");
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_netifcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_netifcon *netifcon = current->data;
struct cil_symtab_datum *ifcon_datum = NULL;
struct cil_symtab_datum *packcon_datum = NULL;
int rc = SEPOL_ERR;
if (netifcon->if_context_str != NULL) {
rc = cil_resolve_name(current, netifcon->if_context_str, CIL_SYM_CONTEXTS, db, &ifcon_datum);
if (rc != SEPOL_OK) {
goto exit;
}
netifcon->if_context = (struct cil_context*)ifcon_datum;
} else {
rc = cil_resolve_context(current, netifcon->if_context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (netifcon->packet_context_str != NULL) {
rc = cil_resolve_name(current, netifcon->packet_context_str, CIL_SYM_CONTEXTS, db, &packcon_datum);
if (rc != SEPOL_OK) {
goto exit;
}
netifcon->packet_context = (struct cil_context*)packcon_datum;
} else {
rc = cil_resolve_context(current, netifcon->packet_context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_ibendportcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_ibendportcon *ibendportcon = current->data;
struct cil_symtab_datum *con_datum = NULL;
int rc = SEPOL_ERR;
if (ibendportcon->context_str) {
rc = cil_resolve_name(current, ibendportcon->context_str, CIL_SYM_CONTEXTS, db, &con_datum);
if (rc != SEPOL_OK)
goto exit;
ibendportcon->context = (struct cil_context *)con_datum;
} else {
rc = cil_resolve_context(current, ibendportcon->context, db);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_pirqcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_pirqcon *pirqcon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (pirqcon->context_str != NULL) {
rc = cil_resolve_name(current, pirqcon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
pirqcon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, pirqcon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_iomemcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_iomemcon *iomemcon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (iomemcon->context_str != NULL) {
rc = cil_resolve_name(current, iomemcon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
iomemcon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, iomemcon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_ioportcon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_ioportcon *ioportcon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (ioportcon->context_str != NULL) {
rc = cil_resolve_name(current, ioportcon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
ioportcon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, ioportcon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_pcidevicecon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_pcidevicecon *pcidevicecon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (pcidevicecon->context_str != NULL) {
rc = cil_resolve_name(current, pcidevicecon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
pcidevicecon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, pcidevicecon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_devicetreecon(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_devicetreecon *devicetreecon = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (devicetreecon->context_str != NULL) {
rc = cil_resolve_name(current, devicetreecon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
devicetreecon->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, devicetreecon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_fsuse(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_fsuse *fsuse = current->data;
struct cil_symtab_datum *context_datum = NULL;
int rc = SEPOL_ERR;
if (fsuse->context_str != NULL) {
rc = cil_resolve_name(current, fsuse->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
fsuse->context = (struct cil_context*)context_datum;
} else {
rc = cil_resolve_context(current, fsuse->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_sidcontext(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_sidcontext *sidcon = current->data;
struct cil_symtab_datum *sid_datum = NULL;
struct cil_symtab_datum *context_datum = NULL;
struct cil_sid *sid = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, sidcon->sid_str, CIL_SYM_SIDS, db, &sid_datum);
if (rc != SEPOL_OK) {
goto exit;
}
sid = (struct cil_sid*)sid_datum;
sidcon->sid = sid;
if (sidcon->context_str != NULL) {
rc = cil_resolve_name(current, sidcon->context_str, CIL_SYM_CONTEXTS, db, &context_datum);
if (rc != SEPOL_OK) {
goto exit;
}
sidcon->context = (struct cil_context*)context_datum;
} else if (sidcon->context != NULL) {
rc = cil_resolve_context(current, sidcon->context, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (sid->context != NULL) {
cil_log(CIL_ERR, "sid's cannot be associated with more than one context\n");
rc = SEPOL_ERR;
goto exit;
}
sid->context = sidcon->context;
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_blockinherit_link(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_blockinherit *inherit = current->data;
struct cil_symtab_datum *block_datum = NULL;
struct cil_tree_node *node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, inherit->block_str, CIL_SYM_BLOCKS, db, &block_datum);
if (rc != SEPOL_OK) {
goto exit;
}
node = NODE(block_datum);
if (node->flavor != CIL_BLOCK) {
cil_log(CIL_ERR, "%s is not a block\n", cil_node_to_string(node));
rc = SEPOL_ERR;
goto exit;
}
inherit->block = (struct cil_block *)block_datum;
if (inherit->block->bi_nodes == NULL) {
cil_list_init(&inherit->block->bi_nodes, CIL_NODE);
}
cil_list_append(inherit->block->bi_nodes, CIL_NODE, current);
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_blockinherit_copy(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_block *block = current->data;
struct cil_list_item *item = NULL;
int rc = SEPOL_ERR;
// This block is not inherited
if (block->bi_nodes == NULL) {
rc = SEPOL_OK;
goto exit;
}
// Make sure this is the original block and not a merged block from a blockinherit
if (current != block->datum.nodes->head->data) {
rc = SEPOL_OK;
goto exit;
}
cil_list_for_each(item, block->bi_nodes) {
rc = cil_copy_ast(db, current, item->data);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to copy block contents into blockinherit\n");
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static void cil_mark_subtree_abstract(struct cil_tree_node *node)
{
struct cil_block *block = node->data;
block->is_abstract = CIL_TRUE;
for (node = node->cl_head; node; node = node->next) {
if (node->flavor == CIL_BLOCK) {
cil_mark_subtree_abstract(node);
}
}
}
static int cil_resolve_blockabstract(struct cil_tree_node *current, struct cil_db *db, struct cil_list *abstract_blocks)
{
struct cil_blockabstract *abstract = current->data;
struct cil_symtab_datum *block_datum = NULL;
struct cil_tree_node *block_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, abstract->block_str, CIL_SYM_BLOCKS, db, &block_datum);
if (rc != SEPOL_OK) {
goto exit;
}
block_node = NODE(block_datum);
if (block_node->flavor != CIL_BLOCK) {
cil_log(CIL_ERR, "Failed to resolve blockabstract to a block, rc: %d\n", rc);
rc = SEPOL_ERR;
goto exit;
}
abstract->block = (struct cil_block *)block_datum;
cil_list_append(abstract_blocks, CIL_NODE, block_node);
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_in *in = current->data;
struct cil_symtab_datum *block_datum = NULL;
struct cil_tree_node *block_node = NULL;
int rc = SEPOL_ERR;
rc = cil_resolve_name(current, in->block_str, CIL_SYM_BLOCKS, db, &block_datum);
if (rc != SEPOL_OK) {
goto exit;
}
in->block = (struct cil_block *)block_datum;
block_node = NODE(block_datum);
if (block_node->flavor == CIL_OPTIONAL) {
if (block_datum->nodes && block_datum->nodes->head != block_datum->nodes->tail) {
cil_tree_log(current, CIL_ERR, "Multiple optional blocks referred to by in-statement");
cil_tree_log(block_node, CIL_ERR, "First optional block");
rc = SEPOL_ERR;
goto exit;
}
}
rc = cil_copy_ast(db, current, block_node);
if (rc != SEPOL_OK) {
cil_tree_log(current, CIL_ERR, "Failed to copy in-statement");
goto exit;
}
cil_tree_children_destroy(current);
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_in_list(struct cil_list *in_list, struct cil_db *db)
{
struct cil_list_item *curr = NULL;
struct cil_tree_node *node = NULL;
struct cil_tree_node *last_failed_node = NULL;
struct cil_in *in = NULL;
struct cil_symtab_datum *block_datum = NULL;
int resolved = 0;
int unresolved = 0;
int rc = SEPOL_ERR;
do {
resolved = 0;
unresolved = 0;
cil_list_for_each(curr, in_list) {
if (curr->flavor != CIL_NODE) {
continue;
}
node = curr->data;
in = node->data;
rc = cil_resolve_name(node, in->block_str, CIL_SYM_BLOCKS, db, &block_datum);
if (rc != SEPOL_OK) {
unresolved++;
last_failed_node = node;
} else {
rc = cil_resolve_in(node, db);
if (rc != SEPOL_OK) {
goto exit;
}
resolved++;
curr->data = NULL;
curr->flavor = CIL_NONE;
}
}
if (unresolved > 0 && resolved == 0) {
cil_tree_log(last_failed_node, CIL_ERR, "Failed to resolve in-statement");
rc = SEPOL_ERR;
goto exit;
}
} while (unresolved > 0);
rc = SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_bounds(struct cil_tree_node *current, struct cil_db *db, enum cil_flavor flavor, enum cil_flavor attr_flavor)
{
int rc = SEPOL_ERR;
struct cil_bounds *bounds = current->data;
enum cil_sym_index index;
struct cil_symtab_datum *parent_datum = NULL;
struct cil_symtab_datum *child_datum = NULL;
rc = cil_flavor_to_symtab_index(flavor, &index);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_resolve_name(current, bounds->parent_str, index, db, &parent_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (FLAVOR(parent_datum) == attr_flavor) {
cil_log(CIL_ERR, "Bounds parent %s is an attribute\n", bounds->parent_str);
rc = SEPOL_ERR;
goto exit;
}
rc = cil_resolve_name(current, bounds->child_str, index, db, &child_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (FLAVOR(child_datum) == attr_flavor) {
cil_log(CIL_ERR, "Bounds child %s is an attribute\n", bounds->child_str);
rc = SEPOL_ERR;
goto exit;
}
switch (flavor) {
case CIL_USER: {
struct cil_user *user = (struct cil_user *)child_datum;
if (user->bounds != NULL) {
cil_tree_log(NODE(user->bounds), CIL_ERR, "User %s already bound by parent", bounds->child_str);
rc = SEPOL_ERR;
goto exit;
}
user->bounds = (struct cil_user *)parent_datum;
break;
}
case CIL_ROLE: {
struct cil_role *role = (struct cil_role *)child_datum;
if (role->bounds != NULL) {
cil_tree_log(NODE(role->bounds), CIL_ERR, "Role %s already bound by parent", bounds->child_str);
rc = SEPOL_ERR;
goto exit;
}
role->bounds = (struct cil_role *)parent_datum;
break;
}
case CIL_TYPE: {
struct cil_type *type = (struct cil_type *)child_datum;
if (type->bounds != NULL) {
cil_tree_log(NODE(type->bounds), CIL_ERR, "Type %s already bound by parent", bounds->child_str);
rc = SEPOL_ERR;
goto exit;
}
type->bounds = (struct cil_type *)parent_datum;
break;
}
default:
break;
}
return SEPOL_OK;
exit:
cil_tree_log(current, CIL_ERR, "Bad bounds statement");
return rc;
}
static int cil_resolve_default(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_default *def = current->data;
struct cil_list_item *curr;
struct cil_symtab_datum *datum;
cil_list_init(&def->class_datums, def->flavor);
cil_list_for_each(curr, def->class_strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_CLASSES, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_append(def->class_datums, CIL_CLASS, datum);
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_defaultrange(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_defaultrange *def = current->data;
struct cil_list_item *curr;
struct cil_symtab_datum *datum;
cil_list_init(&def->class_datums, CIL_DEFAULTRANGE);
cil_list_for_each(curr, def->class_strs) {
rc = cil_resolve_name(current, (char *)curr->data, CIL_SYM_CLASSES, db, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_append(def->class_datums, CIL_CLASS, datum);
}
return SEPOL_OK;
exit:
return rc;
}
static void cil_print_recursive_call(struct cil_tree_node *call_node, struct cil_tree_node *terminating_node)
{
struct cil_list *trace = NULL;
struct cil_list_item * item = NULL;
struct cil_tree_node *curr = NULL;
cil_list_init(&trace, CIL_NODE);
for (curr = call_node; curr != terminating_node; curr = curr->parent) {
if (curr->flavor == CIL_CALL) {
if (curr != call_node) {
cil_list_prepend(trace, CIL_NODE, NODE(((struct cil_call *)curr->data)->macro));
}
cil_list_prepend(trace, CIL_NODE, curr);
}
}
if (terminating_node->flavor == CIL_MACRO) {
cil_list_prepend(trace, CIL_NODE, terminating_node);
} else {
cil_list_prepend(trace, CIL_NODE, NODE(((struct cil_call *)terminating_node->data)->macro));
}
cil_list_for_each(item, trace) {
curr = item->data;
if (curr->flavor == CIL_MACRO) {
cil_tree_log(curr, CIL_ERR, "macro %s", DATUM(curr->data)->name);
} else {
cil_tree_log(curr, CIL_ERR, "call %s", ((struct cil_call *)curr->data)->macro_str);
}
}
cil_list_destroy(&trace, CIL_FALSE);
}
static int cil_check_recursive_call(struct cil_tree_node *call_node, struct cil_tree_node *macro_node)
{
struct cil_tree_node *curr = NULL;
struct cil_call * call = NULL;
int rc = SEPOL_ERR;
for (curr = call_node; curr != NULL; curr = curr->parent) {
if (curr->flavor == CIL_CALL) {
if (curr == call_node) {
continue;
}
call = curr->data;
if (call->macro != macro_node->data) {
continue;
}
} else if (curr->flavor == CIL_MACRO) {
if (curr != macro_node) {
rc = SEPOL_OK;
goto exit;
}
} else {
continue;
}
cil_log(CIL_ERR, "Recursive macro call found:\n");
cil_print_recursive_call(call_node, curr);
rc = SEPOL_ERR;
goto exit;
}
rc = SEPOL_OK;
exit:
return rc;
}
static int cil_build_call_args(struct cil_tree_node *call_node, struct cil_call *call, struct cil_macro *macro, struct cil_db *db)
{
struct cil_list_item *item;
struct cil_args *arg = NULL;
struct cil_tree_node *arg_node = NULL;
int rc = SEPOL_ERR;
if (macro->params == NULL) {
if (call->args_tree == NULL) {
return SEPOL_OK;
} else {
cil_tree_log(call_node, CIL_ERR, "Unexpected arguments");
return SEPOL_ERR;
}
}
if (call->args_tree == NULL) {
cil_tree_log(call_node, CIL_ERR, "Missing arguments");
return SEPOL_ERR;
}
arg_node = call->args_tree->root->cl_head;
cil_list_init(&call->args, CIL_LIST_ITEM);
cil_list_for_each(item, macro->params) {
enum cil_flavor flavor = ((struct cil_param*)item->data)->flavor;
if (arg_node == NULL) {
cil_tree_log(call_node, CIL_ERR, "Missing arguments");
rc = SEPOL_ERR;
goto exit;
}
if (item->flavor != CIL_PARAM) {
rc = SEPOL_ERR;
goto exit;
}
cil_args_init(&arg);
switch (flavor) {
case CIL_DECLARED_STRING: {
struct cil_symtab_datum *string;
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
string = cil_gen_declared_string(db, arg_node->data, call_node);
if (string) {
arg->arg = string;
} else {
arg->arg_str = arg_node->data;
}
}
break;
case CIL_TYPE:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_ROLE:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_USER:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_SENS:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_CAT:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_BOOL:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_CATSET: {
if (arg_node->cl_head != NULL) {
struct cil_catset *catset = NULL;
struct cil_tree_node *cat_node = NULL;
cil_catset_init(&catset);
rc = cil_fill_cats(arg_node, &catset->cats);
if (rc != SEPOL_OK) {
cil_destroy_catset(catset);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&cat_node);
cat_node->flavor = CIL_CATSET;
cat_node->data = catset;
cil_list_append(((struct cil_symtab_datum*)catset)->nodes,
CIL_LIST_ITEM, cat_node);
arg->arg = (struct cil_symtab_datum*)catset;
} else if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else {
arg->arg_str = arg_node->data;
}
break;
}
case CIL_LEVEL: {
if (arg_node->cl_head != NULL) {
struct cil_level *level = NULL;
struct cil_tree_node *lvl_node = NULL;
cil_level_init(&level);
rc = cil_fill_level(arg_node->cl_head, level);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to create anonymous level, rc: %d\n", rc);
cil_destroy_level(level);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&lvl_node);
lvl_node->flavor = CIL_LEVEL;
lvl_node->data = level;
cil_list_append(((struct cil_symtab_datum*)level)->nodes,
CIL_LIST_ITEM, lvl_node);
arg->arg = (struct cil_symtab_datum*)level;
} else if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else {
arg->arg_str = arg_node->data;
}
break;
}
case CIL_LEVELRANGE: {
if (arg_node->cl_head != NULL) {
struct cil_levelrange *range = NULL;
struct cil_tree_node *range_node = NULL;
cil_levelrange_init(&range);
rc = cil_fill_levelrange(arg_node->cl_head, range);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to create anonymous levelrange, rc: %d\n", rc);
cil_destroy_levelrange(range);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&range_node);
range_node->flavor = CIL_LEVELRANGE;
range_node->data = range;
cil_list_append(((struct cil_symtab_datum*)range)->nodes,
CIL_LIST_ITEM, range_node);
arg->arg = (struct cil_symtab_datum*)range;
} else if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else {
arg->arg_str = arg_node->data;
}
break;
}
case CIL_IPADDR: {
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else if (strchr(arg_node->data, '.') || strchr(arg_node->data, ':')) {
struct cil_ipaddr *ipaddr = NULL;
struct cil_tree_node *addr_node = NULL;
cil_ipaddr_init(&ipaddr);
rc = cil_fill_ipaddr(arg_node, ipaddr);
if (rc != SEPOL_OK) {
cil_tree_log(call_node, CIL_ERR, "Failed to create anonymous ip address");
cil_destroy_ipaddr(ipaddr);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&addr_node);
addr_node->flavor = CIL_IPADDR;
addr_node->data = ipaddr;
cil_list_append(DATUM(ipaddr)->nodes, CIL_LIST_ITEM, addr_node);
arg->arg = DATUM(ipaddr);
} else {
arg->arg_str = arg_node->data;
}
break;
}
case CIL_CLASS:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_MAP_CLASS:
if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->arg_str = arg_node->data;
break;
case CIL_CLASSPERMISSION: {
if (arg_node->cl_head != NULL) {
struct cil_classpermission *cp = NULL;
struct cil_tree_node *cp_node = NULL;
cil_classpermission_init(&cp);
rc = cil_fill_classperms_list(arg_node, &cp->classperms);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to create anonymous classpermission\n");
cil_destroy_classpermission(cp);
cil_destroy_args(arg);
goto exit;
}
cil_tree_node_init(&cp_node);
cp_node->flavor = CIL_CLASSPERMISSION;
cp_node->data = cp;
cil_list_append(cp->datum.nodes, CIL_LIST_ITEM, cp_node);
arg->arg = (struct cil_symtab_datum*)cp;
} else if (arg_node->data == NULL) {
cil_tree_log(call_node, CIL_ERR, "Invalid macro parameter");
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
} else {
arg->arg_str = arg_node->data;
}
break;
}
default:
cil_log(CIL_ERR, "Unexpected flavor: %d\n",
(((struct cil_param*)item->data)->flavor));
cil_destroy_args(arg);
rc = SEPOL_ERR;
goto exit;
}
arg->param_str = ((struct cil_param*)item->data)->str;
arg->flavor = flavor;
cil_list_append(call->args, CIL_ARGS, arg);
arg_node = arg_node->next;
}
if (arg_node != NULL) {
cil_tree_log(call_node, CIL_ERR, "Unexpected arguments");
rc = SEPOL_ERR;
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_call(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_call *call = current->data;
struct cil_tree_node *macro_node = NULL;
struct cil_symtab_datum *macro_datum = NULL;
int rc = SEPOL_ERR;
if (call->copied) {
return SEPOL_OK;
}
rc = cil_resolve_name(current, call->macro_str, CIL_SYM_BLOCKS, db, ¯o_datum);
if (rc != SEPOL_OK) {
goto exit;
}
macro_node = NODE(macro_datum);
if (macro_node->flavor != CIL_MACRO) {
cil_tree_log(current, CIL_ERR, "Failed to resolve %s to a macro", call->macro_str);
rc = SEPOL_ERR;
goto exit;
}
call->macro = (struct cil_macro*)macro_datum;
rc = cil_build_call_args(current, call, call->macro, db);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_check_recursive_call(current, macro_node);
if (rc != SEPOL_OK) {
goto exit;
}
rc = cil_copy_ast(db, macro_node, current);
if (rc != SEPOL_OK) {
cil_tree_log(current, CIL_ERR, "Failed to copy macro %s to call", macro_datum->name);
goto exit;
}
call->copied = 1;
return SEPOL_OK;
exit:
return rc;
}
static int cil_resolve_call_args(struct cil_tree_node *current, struct cil_db *db)
{
struct cil_call *call = current->data;
int rc = SEPOL_ERR;
enum cil_sym_index sym_index = CIL_SYM_UNKNOWN;
struct cil_list_item *item;
if (call->args == NULL) {
rc = SEPOL_OK;
goto exit;
}
cil_list_for_each(item, call->args) {
struct cil_args *arg = item->data;
if (arg->arg == NULL && arg->arg_str == NULL) {
cil_log(CIL_ERR, "Arguments not created correctly\n");
rc = SEPOL_ERR;
goto exit;
}
switch (arg->flavor) {
case CIL_DECLARED_STRING:
if (arg->arg != NULL) {
continue; /* No need to resolve */
} else {
sym_index = CIL_SYM_STRINGS;
}
break;
case CIL_LEVEL:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue; // anonymous, no need to resolve
} else {
sym_index = CIL_SYM_LEVELS;
}
break;
case CIL_LEVELRANGE:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue; // anonymous, no need to resolve
} else {
sym_index = CIL_SYM_LEVELRANGES;
}
break;
case CIL_CATSET:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue; // anonymous, no need to resolve
} else {
sym_index = CIL_SYM_CATS;
}
break;
case CIL_IPADDR:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue; // anonymous, no need to resolve
} else {
sym_index = CIL_SYM_IPADDRS;
}
break;
case CIL_CLASSPERMISSION:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue;
} else {
sym_index = CIL_SYM_CLASSPERMSETS;
}
break;
case CIL_TYPE:
if (arg->arg_str == NULL && arg->arg != NULL) {
continue; // anonymous, no need to resolve
} else {
sym_index = CIL_SYM_TYPES;
}
break;
case CIL_ROLE:
sym_index = CIL_SYM_ROLES;
break;
case CIL_USER:
sym_index = CIL_SYM_USERS;
break;
case CIL_SENS:
sym_index = CIL_SYM_SENS;
break;
case CIL_CAT:
sym_index = CIL_SYM_CATS;
break;
case CIL_CLASS:
case CIL_MAP_CLASS:
sym_index = CIL_SYM_CLASSES;
break;
case CIL_BOOL:
sym_index = CIL_SYM_BOOLS;
break;
default:
rc = SEPOL_ERR;
goto exit;
}
if (sym_index != CIL_SYM_UNKNOWN) {
struct cil_symtab_datum *datum;
struct cil_tree_node *n;
rc = cil_resolve_name(current, arg->arg_str, sym_index, db, &datum);
if (rc != SEPOL_OK) {
cil_tree_log(current, CIL_ERR, "Failed to resolve %s in call argument list", arg->arg_str);
goto exit;
}
arg->arg = datum;
n = NODE(datum);
while (n && n->flavor != CIL_ROOT) {
if (n == current) {
symtab_t *s = datum->symtab;
/* Call arg should not resolve to declaration in the call
* Need to remove datum temporarily to resolve to a datum outside
* the call.
*/
cil_symtab_remove_datum(datum);
rc = cil_resolve_name(current, arg->arg_str, sym_index, db, &(arg->arg));
if (rc != SEPOL_OK) {
cil_tree_log(current, CIL_ERR, "Failed to resolve %s in call argument list", arg->arg_str);
goto exit;
}
rc = cil_symtab_insert(s, datum->name, datum, NULL);
if (rc != SEPOL_OK) {
cil_tree_log(current, CIL_ERR, "Failed to re-insert datum while resolving %s in call argument list", arg->arg_str);
goto exit;
}
break;
}
n = n->parent;
}
}
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_name_call_args(struct cil_call *call, char *name, enum cil_sym_index sym_index, struct cil_symtab_datum **datum)
{
struct cil_list_item *item;
enum cil_sym_index param_index = CIL_SYM_UNKNOWN;
int rc = SEPOL_ERR;
if (call == NULL || name == NULL) {
goto exit;
}
if (call->args == NULL) {
goto exit;
}
cil_list_for_each(item, call->args) {
struct cil_args * arg = item->data;
rc = cil_flavor_to_symtab_index(arg->flavor, ¶m_index);
if (param_index == sym_index) {
if (name == arg->param_str) {
*datum = arg->arg;
rc = *datum ? SEPOL_OK : SEPOL_ERR;
goto exit;
}
}
}
return SEPOL_ERR;
exit:
return rc;
}
int cil_resolve_expr(enum cil_flavor expr_type, struct cil_list *str_expr, struct cil_list **datum_expr, struct cil_tree_node *parent, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
struct cil_symtab_datum *res_datum = NULL;
enum cil_sym_index sym_index = CIL_SYM_UNKNOWN;
struct cil_list *datum_sub_expr;
enum cil_flavor op = CIL_NONE;
switch (str_expr->flavor) {
case CIL_BOOL:
sym_index = CIL_SYM_BOOLS;
break;
case CIL_TUNABLE:
sym_index = CIL_SYM_TUNABLES;
break;
case CIL_TYPE:
sym_index = CIL_SYM_TYPES;
break;
case CIL_ROLE:
sym_index = CIL_SYM_ROLES;
break;
case CIL_USER:
sym_index = CIL_SYM_USERS;
break;
case CIL_CAT:
sym_index = CIL_SYM_CATS;
break;
default:
break;
}
cil_list_init(datum_expr, str_expr->flavor);
cil_list_for_each(curr, str_expr) {
switch (curr->flavor) {
case CIL_STRING:
rc = cil_resolve_name(parent, curr->data, sym_index, db, &res_datum);
if (rc != SEPOL_OK) {
goto exit;
}
if (sym_index == CIL_SYM_CATS && NODE(res_datum)->flavor == CIL_CATSET) {
struct cil_catset *catset = (struct cil_catset *)res_datum;
if (op == CIL_RANGE) {
cil_tree_log(parent, CIL_ERR, "Category set not allowed in category range");
rc = SEPOL_ERR;
goto exit;
}
if (!res_datum->name) {
/* Anonymous category sets need to be resolved when encountered */
if (!catset->cats->datum_expr) {
rc = cil_resolve_expr(expr_type, catset->cats->str_expr, &catset->cats->datum_expr, parent, db);
if (rc != SEPOL_OK) {
goto exit;
}
}
cil_copy_list(catset->cats->datum_expr, &datum_sub_expr);
cil_list_append(*datum_expr, CIL_LIST, datum_sub_expr);
} else {
cil_list_append(*datum_expr, CIL_DATUM, res_datum);
}
} else {
if (sym_index == CIL_SYM_TYPES && (expr_type == CIL_CONSTRAIN || expr_type == CIL_VALIDATETRANS)) {
cil_type_used(res_datum, CIL_ATTR_CONSTRAINT);
}
cil_list_append(*datum_expr, CIL_DATUM, res_datum);
}
break;
case CIL_LIST: {
rc = cil_resolve_expr(expr_type, curr->data, &datum_sub_expr, parent, db);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_append(*datum_expr, CIL_LIST, datum_sub_expr);
break;
}
default:
if (curr->flavor == CIL_OP) {
op = (enum cil_flavor)(uintptr_t)curr->data;
}
cil_list_append(*datum_expr, curr->flavor, curr->data);
break;
}
}
return SEPOL_OK;
exit:
cil_list_destroy(datum_expr, CIL_FALSE);
return rc;
}
int cil_resolve_boolif(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_booleanif *bif = (struct cil_booleanif*)current->data;
rc = cil_resolve_expr(CIL_BOOLEANIF, bif->str_expr, &bif->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_evaluate_tunable_expr(struct cil_list_item *curr);
static int __cil_evaluate_tunable_expr_helper(struct cil_list_item *curr)
{
if (curr == NULL) {
return CIL_FALSE;
} else if (curr->flavor == CIL_DATUM) {
struct cil_tunable *tun = curr->data;
return tun->value;
} else if (curr->flavor == CIL_LIST) {
struct cil_list *l = curr->data;
return __cil_evaluate_tunable_expr(l->head);
} else {
return CIL_FALSE;
}
}
static int __cil_evaluate_tunable_expr(struct cil_list_item *curr)
{
/* Assumes expression is well-formed */
if (curr == NULL) {
return CIL_FALSE;
} else if (curr->flavor == CIL_OP) {
uint16_t v1, v2;
enum cil_flavor op_flavor = (enum cil_flavor)(uintptr_t)curr->data;
v1 = __cil_evaluate_tunable_expr_helper(curr->next);
if (op_flavor == CIL_NOT) return !v1;
v2 = __cil_evaluate_tunable_expr_helper(curr->next->next);
if (op_flavor == CIL_AND) return (v1 && v2);
else if (op_flavor == CIL_OR) return (v1 || v2);
else if (op_flavor == CIL_XOR) return (v1 ^ v2);
else if (op_flavor == CIL_EQ) return (v1 == v2);
else if (op_flavor == CIL_NEQ) return (v1 != v2);
else return CIL_FALSE;
} else {
uint16_t v;
for (;curr; curr = curr->next) {
v = __cil_evaluate_tunable_expr_helper(curr);
if (v) return v;
}
return CIL_FALSE;
}
}
int cil_resolve_tunif(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_tunableif *tif = (struct cil_tunableif*)current->data;
uint16_t result = CIL_FALSE;
struct cil_tree_node *true_node = NULL;
struct cil_tree_node *false_node = NULL;
struct cil_condblock *cb = NULL;
rc = cil_resolve_expr(CIL_TUNABLEIF, tif->str_expr, &tif->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
result = __cil_evaluate_tunable_expr(tif->datum_expr->head);
if (current->cl_head != NULL && current->cl_head->flavor == CIL_CONDBLOCK) {
cb = current->cl_head->data;
if (cb->flavor == CIL_CONDTRUE) {
true_node = current->cl_head;
} else if (cb->flavor == CIL_CONDFALSE) {
false_node = current->cl_head;
}
}
if (current->cl_head != NULL && current->cl_head->next != NULL && current->cl_head->next->flavor == CIL_CONDBLOCK) {
cb = current->cl_head->next->data;
if (cb->flavor == CIL_CONDTRUE) {
true_node = current->cl_head->next;
} else if (cb->flavor == CIL_CONDFALSE) {
false_node = current->cl_head->next;
}
}
if (result == CIL_TRUE) {
if (true_node != NULL) {
rc = cil_copy_ast(db, true_node, current->parent);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else {
if (false_node != NULL) {
rc = cil_copy_ast(db, false_node, current->parent);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
cil_tree_children_destroy(current);
current->cl_head = NULL;
current->cl_tail = NULL;
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_userattributeset(struct cil_tree_node *current, struct cil_db *db)
{
int rc = SEPOL_ERR;
struct cil_userattributeset *attrusers = current->data;
struct cil_symtab_datum *attr_datum = NULL;
struct cil_tree_node *attr_node = NULL;
struct cil_userattribute *attr = NULL;
rc = cil_resolve_name(current, attrusers->attr_str, CIL_SYM_USERS, db, &attr_datum);
if (rc != SEPOL_OK) {
goto exit;
}
attr_node = NODE(attr_datum);
if (attr_node->flavor != CIL_USERATTRIBUTE) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Attribute user not an attribute\n");
goto exit;
}
attr = (struct cil_userattribute*)attr_datum;
attrusers->attr = attr;
rc = cil_resolve_expr(CIL_USERATTRIBUTESET, attrusers->str_expr, &attrusers->datum_expr, current, db);
if (rc != SEPOL_OK) {
goto exit;
}
if (attr->expr_list == NULL) {
cil_list_init(&attr->expr_list, CIL_USERATTRIBUTE);
}
cil_list_append(attr->expr_list, CIL_LIST, attrusers->datum_expr);
return SEPOL_OK;
exit:
return rc;
}
/*
* Degenerate inheritance leads to exponential growth of the policy
* It can take many forms, but here is one example.
* ...
* (blockinherit ba)
* (block b0
* (block b1
* (block b2
* (block b3
* ...
* )
* (blockinherit b3)
* )
* (blockinherit b2)
* )
* (blockinherit b1)
* )
* (blockinherit b0)
* ...
* This leads to 2^4 copies of the content of block b3, 2^3 copies of the
* contents of block b2, etc.
*/
static unsigned cil_count_actual(struct cil_tree_node *node)
{
unsigned count = 0;
if (node->flavor == CIL_BLOCKINHERIT) {
count += 1;
}
for (node = node->cl_head; node; node = node->next) {
count += cil_count_actual(node);
}
return count;
}
static int cil_check_inheritances(struct cil_tree_node *node, unsigned max, unsigned *count, struct cil_stack *stack, unsigned *loop)
{
int rc;
if (node->flavor == CIL_BLOCKINHERIT) {
struct cil_blockinherit *bi = node->data;
*count += 1;
if (*count > max) {
cil_tree_log(node, CIL_ERR, "Degenerate inheritance detected");
return SEPOL_ERR;
}
if (bi->block) {
struct cil_tree_node *block_node = NODE(bi->block);
struct cil_stack_item *item;
int i = 0;
cil_stack_for_each(stack, i, item) {
if (block_node == (struct cil_tree_node *)item->data) {
*loop = CIL_TRUE;
cil_tree_log(block_node, CIL_ERR, "Block inheritance loop found");
cil_tree_log(node, CIL_ERR, " blockinherit");
return SEPOL_ERR;
}
}
cil_stack_push(stack, CIL_BLOCK, block_node);
rc = cil_check_inheritances(block_node, max, count, stack, loop);
cil_stack_pop(stack);
if (rc != SEPOL_OK) {
if (*loop == CIL_TRUE) {
cil_tree_log(node, CIL_ERR, " blockinherit");
}
return SEPOL_ERR;
}
}
}
for (node = node->cl_head; node; node = node->next) {
rc = cil_check_inheritances(node, max, count, stack, loop);
if (rc != SEPOL_OK) {
return SEPOL_ERR;
}
}
return SEPOL_OK;
}
static int cil_check_for_bad_inheritance(struct cil_tree_node *node)
{
unsigned num_actual, max;
unsigned num_potential = 0;
unsigned loop = CIL_FALSE;
struct cil_stack *stack;
int rc;
num_actual = cil_count_actual(node);
max = num_actual * CIL_DEGENERATE_INHERITANCE_GROWTH;
if (max < CIL_DEGENERATE_INHERITANCE_MINIMUM) {
max = CIL_DEGENERATE_INHERITANCE_MINIMUM;
}
cil_stack_init(&stack);
rc = cil_check_inheritances(node, max, &num_potential, stack, &loop);
cil_stack_destroy(&stack);
return rc;
}
static int __cil_resolve_ast_node(struct cil_tree_node *node, struct cil_args_resolve *args)
{
int rc = SEPOL_OK;
struct cil_db *db = args->db;
enum cil_pass pass = 0;
pass = args->pass;
switch (pass) {
case CIL_PASS_TIF:
if (node->flavor == CIL_TUNABLEIF) {
rc = cil_resolve_tunif(node, db);
}
break;
case CIL_PASS_IN_BEFORE:
if (node->flavor == CIL_IN) {
// due to ordering issues, in statements are just gathered here and
// resolved together in cil_resolve_in_list once all are found
struct cil_in *in = node->data;
if (in->is_after == CIL_FALSE) {
cil_list_prepend(args->in_list_before, CIL_NODE, node);
}
}
break;
case CIL_PASS_BLKIN_LINK:
if (node->flavor == CIL_BLOCKINHERIT) {
rc = cil_resolve_blockinherit_link(node, db);
}
break;
case CIL_PASS_BLKIN_COPY:
if (node->flavor == CIL_BLOCK) {
rc = cil_resolve_blockinherit_copy(node, db);
}
break;
case CIL_PASS_BLKABS:
if (node->flavor == CIL_BLOCKABSTRACT) {
rc = cil_resolve_blockabstract(node, db, args->abstract_blocks);
}
break;
case CIL_PASS_IN_AFTER:
if (node->flavor == CIL_IN) {
// due to ordering issues, in statements are just gathered here and
// resolved together in cil_resolve_in_list once all are found
struct cil_in *in = node->data;
if (in->is_after == CIL_TRUE) {
cil_list_prepend(args->in_list_after, CIL_NODE, node);
}
}
break;
case CIL_PASS_CALL1:
if (node->flavor == CIL_CALL && args->macro == NULL) {
rc = cil_resolve_call(node, db);
}
break;
case CIL_PASS_CALL2:
if (node->flavor == CIL_CALL && args->macro == NULL) {
rc = cil_resolve_call_args(node, db);
}
break;
case CIL_PASS_ALIAS1:
switch (node->flavor) {
case CIL_TYPEALIASACTUAL:
rc = cil_resolve_aliasactual(node, db, CIL_TYPE, CIL_TYPEALIAS);
break;
case CIL_SENSALIASACTUAL:
rc = cil_resolve_aliasactual(node, db, CIL_SENS, CIL_SENSALIAS);
break;
case CIL_CATALIASACTUAL:
rc = cil_resolve_aliasactual(node, db, CIL_CAT, CIL_CATALIAS);
break;
default:
break;
}
break;
case CIL_PASS_ALIAS2:
switch (node->flavor) {
case CIL_TYPEALIAS:
rc = cil_resolve_alias_to_actual(node, CIL_TYPE);
break;
case CIL_SENSALIAS:
rc = cil_resolve_alias_to_actual(node, CIL_SENS);
break;
case CIL_CATALIAS:
rc = cil_resolve_alias_to_actual(node, CIL_CAT);
break;
default:
break;
}
break;
case CIL_PASS_MISC1:
switch (node->flavor) {
case CIL_SIDORDER:
rc = cil_resolve_sidorder(node, db, args->sidorder_lists);
break;
case CIL_CLASSORDER:
rc = cil_resolve_classorder(node, db, args->classorder_lists, args->unordered_classorder_lists);
break;
case CIL_CATORDER:
rc = cil_resolve_catorder(node, db, args->catorder_lists);
break;
case CIL_SENSITIVITYORDER:
rc = cil_resolve_sensitivityorder(node, db, args->sensitivityorder_lists);
break;
case CIL_BOOLEANIF:
rc = cil_resolve_boolif(node, db);
break;
default:
break;
}
break;
case CIL_PASS_MLS:
switch (node->flavor) {
case CIL_CATSET:
rc = cil_resolve_catset(node, (struct cil_catset*)node->data, db);
break;
default:
break;
}
break;
case CIL_PASS_MISC2:
switch (node->flavor) {
case CIL_SENSCAT:
rc = cil_resolve_senscat(node, db);
break;
case CIL_CLASSCOMMON:
rc = cil_resolve_classcommon(node, db);
break;
default:
break;
}
break;
case CIL_PASS_MISC3:
switch (node->flavor) {
case CIL_TYPEATTRIBUTESET:
rc = cil_resolve_typeattributeset(node, db);
break;
case CIL_EXPANDTYPEATTRIBUTE:
rc = cil_resolve_expandtypeattribute(node, db);
break;
case CIL_TYPEBOUNDS:
rc = cil_resolve_bounds(node, db, CIL_TYPE, CIL_TYPEATTRIBUTE);
break;
case CIL_TYPEPERMISSIVE:
rc = cil_resolve_typepermissive(node, db);
break;
case CIL_NAMETYPETRANSITION:
rc = cil_resolve_nametypetransition(node, db);
break;
case CIL_RANGETRANSITION:
rc = cil_resolve_rangetransition(node, db);
break;
case CIL_CLASSPERMISSIONSET:
rc = cil_resolve_classpermissionset(node, (struct cil_classpermissionset*)node->data, db);
break;
case CIL_CLASSMAPPING:
rc = cil_resolve_classmapping(node, db);
break;
case CIL_AVRULE:
case CIL_AVRULEX:
rc = cil_resolve_avrule(node, db);
break;
case CIL_PERMISSIONX:
rc = cil_resolve_permissionx(node, (struct cil_permissionx*)node->data, db);
break;
case CIL_DENY_RULE:
rc = cil_resolve_deny_rule(node, db);
break;
case CIL_TYPE_RULE:
rc = cil_resolve_type_rule(node, db);
break;
case CIL_USERROLE:
rc = cil_resolve_userrole(node, db);
break;
case CIL_USERLEVEL:
rc = cil_resolve_userlevel(node, db);
break;
case CIL_USERRANGE:
rc = cil_resolve_userrange(node, db);
break;
case CIL_USERBOUNDS:
rc = cil_resolve_bounds(node, db, CIL_USER, CIL_USERATTRIBUTE);
break;
case CIL_USERPREFIX:
rc = cil_resolve_userprefix(node, db);
break;
case CIL_SELINUXUSER:
case CIL_SELINUXUSERDEFAULT:
rc = cil_resolve_selinuxuser(node, db);
break;
case CIL_ROLEATTRIBUTESET:
rc = cil_resolve_roleattributeset(node, db);
break;
case CIL_ROLETYPE:
rc = cil_resolve_roletype(node, db);
break;
case CIL_ROLETRANSITION:
rc = cil_resolve_roletransition(node, db);
break;
case CIL_ROLEALLOW:
rc = cil_resolve_roleallow(node, db);
break;
case CIL_ROLEBOUNDS:
rc = cil_resolve_bounds(node, db, CIL_ROLE, CIL_ROLEATTRIBUTE);
break;
case CIL_LEVEL:
rc = cil_resolve_level(node, (struct cil_level*)node->data, db);
break;
case CIL_LEVELRANGE:
rc = cil_resolve_levelrange(node, (struct cil_levelrange*)node->data, db);
break;
case CIL_CONSTRAIN:
rc = cil_resolve_constrain(node, db);
break;
case CIL_MLSCONSTRAIN:
rc = cil_resolve_constrain(node, db);
break;
case CIL_VALIDATETRANS:
case CIL_MLSVALIDATETRANS:
rc = cil_resolve_validatetrans(node, db);
break;
case CIL_CONTEXT:
rc = cil_resolve_context(node, (struct cil_context*)node->data, db);
break;
case CIL_FILECON:
rc = cil_resolve_filecon(node, db);
break;
case CIL_IBPKEYCON:
rc = cil_resolve_ibpkeycon(node, db);
break;
case CIL_PORTCON:
rc = cil_resolve_portcon(node, db);
break;
case CIL_NODECON:
rc = cil_resolve_nodecon(node, db);
break;
case CIL_GENFSCON:
rc = cil_resolve_genfscon(node, db);
break;
case CIL_NETIFCON:
rc = cil_resolve_netifcon(node, db);
break;
case CIL_IBENDPORTCON:
rc = cil_resolve_ibendportcon(node, db);
break;
case CIL_PIRQCON:
rc = cil_resolve_pirqcon(node, db);
break;
case CIL_IOMEMCON:
rc = cil_resolve_iomemcon(node, db);
break;
case CIL_IOPORTCON:
rc = cil_resolve_ioportcon(node, db);
break;
case CIL_PCIDEVICECON:
rc = cil_resolve_pcidevicecon(node, db);
break;
case CIL_DEVICETREECON:
rc = cil_resolve_devicetreecon(node, db);
break;
case CIL_FSUSE:
rc = cil_resolve_fsuse(node, db);
break;
case CIL_SIDCONTEXT:
rc = cil_resolve_sidcontext(node, db);
break;
case CIL_DEFAULTUSER:
case CIL_DEFAULTROLE:
case CIL_DEFAULTTYPE:
rc = cil_resolve_default(node, db);
break;
case CIL_DEFAULTRANGE:
rc = cil_resolve_defaultrange(node, db);
break;
case CIL_USERATTRIBUTESET:
rc = cil_resolve_userattributeset(node, db);
break;
default:
break;
}
break;
default:
break;
}
return rc;
}
static int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_OK;
struct cil_args_resolve *args = extra_args;
enum cil_pass pass = args->pass;
struct cil_tree_node *block = args->block;
struct cil_tree_node *macro = args->macro;
struct cil_tree_node *optional = args->optional;
struct cil_tree_node *boolif = args->boolif;
if (node == NULL) {
goto exit;
}
if (block != NULL) {
if (node->flavor == CIL_CAT ||
node->flavor == CIL_SENS) {
cil_tree_log(node, CIL_ERR, "%s is not allowed in block", cil_node_to_string(node));
rc = SEPOL_ERR;
goto exit;
}
}
if (macro != NULL) {
if (node->flavor == CIL_TUNABLE ||
node->flavor == CIL_IN ||
node->flavor == CIL_BLOCK ||
node->flavor == CIL_BLOCKINHERIT ||
node->flavor == CIL_BLOCKABSTRACT ||
node->flavor == CIL_MACRO) {
cil_tree_log(node, CIL_ERR, "%s is not allowed in macro", cil_node_to_string(node));
rc = SEPOL_ERR;
goto exit;
}
}
if (optional != NULL) {
if (node->flavor == CIL_TUNABLE ||
node->flavor == CIL_IN ||
node->flavor == CIL_BLOCK ||
node->flavor == CIL_BLOCKABSTRACT ||
node->flavor == CIL_MACRO) {
cil_tree_log(node, CIL_ERR, "%s is not allowed in optional", cil_node_to_string(node));
rc = SEPOL_ERR;
goto exit;
}
}
if (boolif != NULL) {
if (node->flavor != CIL_TUNABLEIF &&
node->flavor != CIL_CALL &&
node->flavor != CIL_CONDBLOCK &&
node->flavor != CIL_AVRULE &&
node->flavor != CIL_TYPE_RULE &&
node->flavor != CIL_NAMETYPETRANSITION &&
((args->db->policy_version < POLICYDB_VERSION_COND_XPERMS) ||
(node->flavor != CIL_AVRULEX))) {
rc = SEPOL_ERR;
} else if (node->flavor == CIL_AVRULE || node->flavor == CIL_AVRULEX) {
struct cil_avrule *rule = node->data;
if (rule->rule_kind == CIL_AVRULE_NEVERALLOW) {
rc = SEPOL_ERR;
}
}
if (rc == SEPOL_ERR) {
if (((struct cil_booleanif*)boolif->data)->preserved_tunable) {
cil_tree_log(node, CIL_ERR, "%s is not allowed in tunableif being treated as a booleanif", cil_node_to_string(node));
} else {
cil_tree_log(node, CIL_ERR, "%s is not allowed in booleanif", cil_node_to_string(node));
}
goto exit;
}
}
if (node->flavor == CIL_MACRO) {
if (pass > CIL_PASS_IN_AFTER) {
*finished = CIL_TREE_SKIP_HEAD;
rc = SEPOL_OK;
goto exit;
}
}
if (node->flavor == CIL_BLOCK && ((((struct cil_block*)node->data)->is_abstract == CIL_TRUE) && (pass > CIL_PASS_BLKABS))) {
*finished = CIL_TREE_SKIP_HEAD;
rc = SEPOL_OK;
goto exit;
}
rc = __cil_resolve_ast_node(node, args);
if (rc == SEPOL_ENOENT) {
if (optional == NULL) {
cil_tree_log(node, CIL_ERR, "Failed to resolve %s statement", cil_node_to_string(node));
} else {
if (!args->disabled_optional) {
args->disabled_optional = optional;
}
cil_tree_log(node, CIL_INFO, "Failed to resolve %s statement", cil_node_to_string(node));
cil_tree_log(optional, CIL_INFO, "Disabling optional '%s'", DATUM(optional->data)->name);
rc = SEPOL_OK;
}
goto exit;
}
return rc;
exit:
return rc;
}
static int __cil_resolve_ast_first_child_helper(struct cil_tree_node *current, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_args_resolve *args = extra_args;
struct cil_tree_node *parent = NULL;
if (current == NULL || extra_args == NULL) {
goto exit;
}
parent = current->parent;
if (parent->flavor == CIL_BLOCK) {
args->block = parent;
} else if (parent->flavor == CIL_MACRO) {
args->macro = parent;
} else if (parent->flavor == CIL_OPTIONAL) {
args->optional = parent;
} else if (parent->flavor == CIL_BOOLEANIF) {
args->boolif = parent;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_resolve_ast_last_child_helper(struct cil_tree_node *current, void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_args_resolve *args = extra_args;
struct cil_tree_node *parent = NULL;
if (current == NULL || extra_args == NULL) {
goto exit;
}
parent = current->parent;
if (parent->flavor == CIL_BLOCK) {
struct cil_tree_node *n = parent->parent;
args->block = NULL;
while (n && n->flavor != CIL_ROOT) {
if (n->flavor == CIL_BLOCK) {
args->block = n;
break;
}
n = n->parent;
}
} else if (parent->flavor == CIL_MACRO) {
args->macro = NULL;
} else if (parent->flavor == CIL_OPTIONAL) {
struct cil_tree_node *n = parent->parent;
if (args->disabled_optional == parent) {
*(args->changed) = CIL_TRUE;
cil_list_append(args->to_destroy, CIL_NODE, parent);
args->disabled_optional = NULL;
}
args->optional = NULL;
while (n && n->flavor != CIL_ROOT) {
if (n->flavor == CIL_OPTIONAL) {
args->optional = n;
break;
}
n = n->parent;
}
} else if (parent->flavor == CIL_BOOLEANIF) {
args->boolif = NULL;
}
return SEPOL_OK;
exit:
return rc;
}
int cil_resolve_ast(struct cil_db *db, struct cil_tree_node *current)
{
int rc = SEPOL_ERR;
struct cil_args_resolve extra_args;
enum cil_pass pass = CIL_PASS_TIF;
uint32_t changed = 0;
if (db == NULL || current == NULL) {
return rc;
}
extra_args.db = db;
extra_args.pass = pass;
extra_args.changed = &changed;
extra_args.block = NULL;
extra_args.macro = NULL;
extra_args.optional = NULL;
extra_args.disabled_optional = NULL;
extra_args.boolif= NULL;
extra_args.sidorder_lists = NULL;
extra_args.classorder_lists = NULL;
extra_args.unordered_classorder_lists = NULL;
extra_args.catorder_lists = NULL;
extra_args.sensitivityorder_lists = NULL;
extra_args.in_list_before = NULL;
extra_args.in_list_after = NULL;
extra_args.abstract_blocks = NULL;
cil_list_init(&extra_args.to_destroy, CIL_NODE);
cil_list_init(&extra_args.sidorder_lists, CIL_SIDORDER);
cil_list_init(&extra_args.classorder_lists, CIL_CLASSORDER);
cil_list_init(&extra_args.unordered_classorder_lists, CIL_CLASSORDER);
cil_list_init(&extra_args.catorder_lists, CIL_CATORDER);
cil_list_init(&extra_args.sensitivityorder_lists, CIL_SENSITIVITYORDER);
cil_list_init(&extra_args.in_list_before, CIL_IN);
cil_list_init(&extra_args.in_list_after, CIL_IN);
cil_list_init(&extra_args.abstract_blocks, CIL_NODE);
for (pass = CIL_PASS_TIF; pass < CIL_PASS_NUM; pass++) {
extra_args.pass = pass;
rc = cil_tree_walk(current, __cil_resolve_ast_node_helper, __cil_resolve_ast_first_child_helper, __cil_resolve_ast_last_child_helper, &extra_args);
if (rc != SEPOL_OK) {
cil_log(CIL_INFO, "Pass %i of resolution failed\n", pass);
goto exit;
}
if (pass == CIL_PASS_IN_BEFORE) {
rc = cil_resolve_in_list(extra_args.in_list_before, db);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_destroy(&extra_args.in_list_before, CIL_FALSE);
} else if (pass == CIL_PASS_IN_AFTER) {
rc = cil_resolve_in_list(extra_args.in_list_after, db);
if (rc != SEPOL_OK) {
goto exit;
}
cil_list_destroy(&extra_args.in_list_after, CIL_FALSE);
}
if (pass == CIL_PASS_BLKABS) {
struct cil_list_item *item;
cil_list_for_each(item, extra_args.abstract_blocks) {
cil_mark_subtree_abstract(item->data);
}
}
if (pass == CIL_PASS_BLKIN_LINK) {
rc = cil_check_for_bad_inheritance(current);
if (rc != SEPOL_OK) {
rc = SEPOL_ERR;
goto exit;
}
}
if (pass == CIL_PASS_MISC1) {
db->sidorder = __cil_ordered_lists_merge_all(&extra_args.sidorder_lists, NULL);
if (db->sidorder == NULL) {
rc = SEPOL_ERR;
goto exit;
}
db->classorder = __cil_ordered_lists_merge_all(&extra_args.classorder_lists, &extra_args.unordered_classorder_lists);
if (db->classorder == NULL) {
rc = SEPOL_ERR;
goto exit;
}
db->catorder = __cil_ordered_lists_merge_all(&extra_args.catorder_lists, NULL);
if (db->catorder == NULL) {
rc = SEPOL_ERR;
goto exit;
}
cil_set_cat_values(db->catorder, db);
db->sensitivityorder = __cil_ordered_lists_merge_all(&extra_args.sensitivityorder_lists, NULL);
if (db->sensitivityorder == NULL) {
rc = SEPOL_ERR;
goto exit;
}
rc = __cil_verify_ordered(current, CIL_SID);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_verify_ordered(current, CIL_CLASS);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_verify_ordered(current, CIL_CAT);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_verify_ordered(current, CIL_SENS);
if (rc != SEPOL_OK) {
goto exit;
}
}
if (changed) {
struct cil_list_item *item;
if (pass > CIL_PASS_CALL1) {
int has_decls = CIL_FALSE;
cil_list_for_each(item, extra_args.to_destroy) {
has_decls = cil_tree_subtree_has_decl(item->data);
if (has_decls) {
break;
}
}
if (has_decls) {
/* Need to re-resolve because an optional was disabled that
* contained one or more declarations.
* Everything that needs to be reset comes after the
* CIL_PASS_CALL2 pass. We set pass to CIL_PASS_CALL1 because
* the pass++ will increment it to CIL_PASS_CALL2
*/
cil_log(CIL_INFO, "Resetting declarations\n");
if (pass >= CIL_PASS_MISC1) {
cil_list_destroy(&extra_args.sidorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.classorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.catorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.sensitivityorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.unordered_classorder_lists, CIL_FALSE);
cil_list_init(&extra_args.sidorder_lists, CIL_SIDORDER);
cil_list_init(&extra_args.classorder_lists, CIL_CLASSORDER);
cil_list_init(&extra_args.unordered_classorder_lists, CIL_CLASSORDER);
cil_list_init(&extra_args.catorder_lists, CIL_CATORDER);
cil_list_init(&extra_args.sensitivityorder_lists, CIL_SENSITIVITYORDER);
cil_list_destroy(&db->sidorder, CIL_FALSE);
cil_list_destroy(&db->classorder, CIL_FALSE);
cil_list_destroy(&db->catorder, CIL_FALSE);
cil_list_destroy(&db->sensitivityorder, CIL_FALSE);
}
pass = CIL_PASS_CALL1;
rc = cil_reset_ast(current);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to reset declarations\n");
goto exit;
}
}
}
cil_list_for_each(item, extra_args.to_destroy) {
cil_tree_children_destroy(item->data);
}
cil_list_destroy(&extra_args.to_destroy, CIL_FALSE);
cil_list_init(&extra_args.to_destroy, CIL_NODE);
changed = 0;
}
}
rc = __cil_verify_initsids(db->sidorder);
if (rc != SEPOL_OK) {
goto exit;
}
rc = SEPOL_OK;
exit:
cil_list_destroy(&extra_args.sidorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.classorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.catorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.sensitivityorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.unordered_classorder_lists, CIL_FALSE);
cil_list_destroy(&extra_args.to_destroy, CIL_FALSE);
cil_list_destroy(&extra_args.in_list_before, CIL_FALSE);
cil_list_destroy(&extra_args.in_list_after, CIL_FALSE);
cil_list_destroy(&extra_args.abstract_blocks, CIL_FALSE);
return rc;
}
static int __cil_resolve_name_with_root(struct cil_db *db, char *name, enum cil_sym_index sym_index, struct cil_symtab_datum **datum)
{
symtab_t *symtab = &((struct cil_root *)db->ast->root->data)->symtab[sym_index];
return cil_symtab_get_datum(symtab, name, datum);
}
static int __cil_resolve_name_with_parents(struct cil_tree_node *node, char *name, enum cil_sym_index sym_index, struct cil_symtab_datum **datum)
{
int rc = SEPOL_ERR;
symtab_t *symtab = NULL;
while (node != NULL && rc != SEPOL_OK) {
switch (node->flavor) {
case CIL_ROOT:
goto exit;
break;
case CIL_BLOCK: {
struct cil_block *block = node->data;
if (!block->is_abstract) {
symtab = &block->symtab[sym_index];
rc = cil_symtab_get_datum(symtab, name, datum);
}
}
break;
case CIL_BLOCKINHERIT: {
struct cil_blockinherit *inherit = node->data;
rc = __cil_resolve_name_with_parents(node->parent, name, sym_index, datum);
if (rc != SEPOL_OK) {
/* Continue search in original block's parent */
rc = __cil_resolve_name_with_parents(NODE(inherit->block)->parent, name, sym_index, datum);
goto exit;
}
}
break;
case CIL_MACRO: {
struct cil_macro *macro = node->data;
symtab = ¯o->symtab[sym_index];
rc = cil_symtab_get_datum(symtab, name, datum);
}
break;
case CIL_CALL: {
struct cil_call *call = node->data;
struct cil_macro *macro = call->macro;
symtab = ¯o->symtab[sym_index];
rc = cil_symtab_get_datum(symtab, name, datum);
if (rc == SEPOL_OK) {
/* If the name was declared in the macro, just look on the call side */
rc = SEPOL_ERR;
} else {
rc = cil_resolve_name_call_args(call, name, sym_index, datum);
if (rc != SEPOL_OK) {
/* Continue search in macro's parent */
rc = __cil_resolve_name_with_parents(NODE(call->macro)->parent, name, sym_index, datum);
}
}
}
break;
case CIL_IN:
/* In block symtabs only exist before resolving the AST */
case CIL_CONDBLOCK:
/* Cond block symtabs only exist before resolving the AST */
default:
break;
}
node = node->parent;
}
exit:
return rc;
}
static int __cil_resolve_name_helper(struct cil_db *db, struct cil_tree_node *node, char *name, enum cil_sym_index sym_index, struct cil_symtab_datum **datum)
{
int rc = SEPOL_ERR;
rc = __cil_resolve_name_with_parents(node, name, sym_index, datum);
if (rc != SEPOL_OK) {
rc = __cil_resolve_name_with_root(db, name, sym_index, datum);
}
return rc;
}
int cil_resolve_name(struct cil_tree_node *ast_node, char *name, enum cil_sym_index sym_index, struct cil_db *db, struct cil_symtab_datum **datum)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = NULL;
rc = cil_resolve_name_keep_aliases(ast_node, name, sym_index, db, datum);
if (rc != SEPOL_OK) {
goto exit;
}
/* If this datum is an alias, then return the actual node
* This depends on aliases already being processed
*/
node = NODE(*datum);
if (node->flavor == CIL_TYPEALIAS || node->flavor == CIL_SENSALIAS
|| node->flavor == CIL_CATALIAS) {
struct cil_alias *alias = (struct cil_alias *)(*datum);
if (alias->actual) {
*datum = alias->actual;
}
}
rc = SEPOL_OK;
exit:
return rc;
}
int cil_resolve_name_keep_aliases(struct cil_tree_node *ast_node, char *name, enum cil_sym_index sym_index, struct cil_db *db, struct cil_symtab_datum **datum)
{
int rc = SEPOL_ERR;
struct cil_tree_node *node = NULL;
if (name == NULL || sym_index >= CIL_SYM_NUM) {
cil_log(CIL_ERR, "Invalid call to cil_resolve_name\n");
goto exit;
}
*datum = NULL;
if (db->qualified_names || strchr(name,'.') == NULL) {
/* Using qualified names or No '.' in name */
rc = __cil_resolve_name_helper(db, ast_node->parent, name, sym_index, datum);
if (rc != SEPOL_OK) {
goto exit;
}
} else {
char *sp = NULL;
char *name_dup = cil_strdup(name);
char *current = strtok_r(name_dup, ".", &sp);
char *next = strtok_r(NULL, ".", &sp);
symtab_t *symtab = NULL;
if (current == NULL) {
/* Only dots */
cil_tree_log(ast_node, CIL_ERR, "Invalid name %s", name);
free(name_dup);
goto exit;
}
node = ast_node;
if (*name == '.') {
/* Leading '.' */
symtab = &((struct cil_root *)db->ast->root->data)->symtab[CIL_SYM_BLOCKS];
} else {
rc = __cil_resolve_name_helper(db, node->parent, current, CIL_SYM_BLOCKS, datum);
if (rc != SEPOL_OK) {
free(name_dup);
goto exit;
}
symtab = (*datum)->symtab;
}
/* Keep looking up blocks by name until only last part of name remains */
while (next != NULL) {
rc = cil_symtab_get_datum(symtab, current, datum);
if (rc != SEPOL_OK) {
free(name_dup);
goto exit;
}
node = NODE(*datum);
if (node->flavor == CIL_BLOCK) {
symtab = &((struct cil_block*)node->data)->symtab[CIL_SYM_BLOCKS];
} else {
if (ast_node->flavor != CIL_IN) {
cil_log(CIL_WARN, "Can only use %s name for name resolution in \"in\" blocks\n", cil_node_to_string(node));
free(name_dup);
rc = SEPOL_ERR;
goto exit;
}
if (node->flavor == CIL_MACRO) {
struct cil_macro *macro = node->data;
symtab = ¯o->symtab[sym_index];
}
}
current = next;
next = strtok_r(NULL, ".", &sp);
}
symtab = &(symtab[sym_index]);
rc = cil_symtab_get_datum(symtab, current, datum);
free(name_dup);
if (rc != SEPOL_OK) {
goto exit;
}
}
rc = SEPOL_OK;
exit:
if (rc != SEPOL_OK) {
*datum = NULL;
}
return rc;
}
libsepol-3.8.1/cil/src/cil_resolve_ast.h000066400000000000000000000165461476211737200202460ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_RESOLVE_AST_H_
#define CIL_RESOLVE_AST_H_
#include
#include "cil_internal.h"
#include "cil_tree.h"
int cil_resolve_classorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *classorder_list, struct cil_list *unordered_classorder_list);
int cil_resolve_classperms(struct cil_tree_node *current, struct cil_classperms *cp, struct cil_db *db);
int cil_resolve_classpermissionset(struct cil_tree_node *current, struct cil_classpermissionset *cps, struct cil_db *db);
int cil_resolve_classperms_list(struct cil_tree_node *current, struct cil_list *cp_list, struct cil_db *db);
int cil_resolve_avrule(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_deny_rule(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_type_rule(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_typeattributeset(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_typealias(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_typebounds(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_typepermissive(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_nametypetransition(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_rangetransition(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_classcommon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_classmapping(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userrole(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userlevel(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userrange(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userbounds(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userprefix(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_userattributeset(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_selinuxuser(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_roletype(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_roletransition(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_roleallow(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_roleattributeset(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_rolebounds(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_sensalias(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_catalias(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_catorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *catorder_list);
int cil_resolve_sensitivityorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *sensitivityorder_list);
int cil_resolve_cat_list(struct cil_tree_node *current, struct cil_list *cat_list, struct cil_list *res_cat_list, struct cil_db *db);
int cil_resolve_catset(struct cil_tree_node *current, struct cil_catset *catset, struct cil_db *db);
int cil_resolve_senscat(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_level(struct cil_tree_node *current, struct cil_level *level, struct cil_db *db);
int cil_resolve_levelrange(struct cil_tree_node *current, struct cil_levelrange *levelrange, struct cil_db *db);
int cil_resolve_constrain(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_validatetrans(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_context(struct cil_tree_node *current, struct cil_context *context, struct cil_db *db);
int cil_resolve_filecon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_ibpkeycon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_ibendportcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_portcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_genfscon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_nodecon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_netifcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_pirqcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_iomemcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_ioportcon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_pcidevicecon(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_fsuse(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_sidcontext(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_sidorder(struct cil_tree_node *current, struct cil_db *db, struct cil_list *sidorder_list);
int cil_resolve_blockinherit(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_call1(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_call2(struct cil_tree_node *, struct cil_db *db);
int cil_resolve_name_call_args(struct cil_call *call, char *name, enum cil_sym_index sym_index, struct cil_symtab_datum **datum);
int cil_resolve_expr(enum cil_flavor expr_type, struct cil_list *str_expr, struct cil_list **datum_expr, struct cil_tree_node *parent, struct cil_db *db);
int cil_resolve_boolif(struct cil_tree_node *current, struct cil_db *db);
int cil_evaluate_expr(struct cil_list *datum_expr, uint16_t *result);
int cil_resolve_tunif(struct cil_tree_node *current, struct cil_db *db);
int cil_resolve_ast(struct cil_db *db, struct cil_tree_node *current);
int cil_resolve_name(struct cil_tree_node *ast_node, char *name, enum cil_sym_index sym_index, struct cil_db *db, struct cil_symtab_datum **datum);
int cil_resolve_name_keep_aliases(struct cil_tree_node *ast_node, char *name, enum cil_sym_index sym_index, struct cil_db *db, struct cil_symtab_datum **datum);
#endif /* CIL_RESOLVE_AST_H_ */
libsepol-3.8.1/cil/src/cil_stack.c000066400000000000000000000063141476211737200170100ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "cil_internal.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_stack.h"
#define CIL_STACK_INIT_SIZE 16
void cil_stack_init(struct cil_stack **stack)
{
struct cil_stack *new_stack = cil_malloc(sizeof(*new_stack));
new_stack->stack = cil_malloc(sizeof(*(new_stack->stack)) * CIL_STACK_INIT_SIZE);
new_stack->size = CIL_STACK_INIT_SIZE;
new_stack->pos = -1;
*stack = new_stack;
}
void cil_stack_destroy(struct cil_stack **stack)
{
if (stack == NULL || *stack == NULL) {
return;
}
free((*stack)->stack);
free(*stack);
*stack = NULL;
}
void cil_stack_empty(struct cil_stack *stack)
{
stack->pos = -1;
}
int cil_stack_is_empty(struct cil_stack *stack)
{
return (stack->pos == -1);
}
int cil_stack_number_of_items(struct cil_stack *stack)
{
return stack->pos + 1;
}
void cil_stack_push(struct cil_stack *stack, enum cil_flavor flavor, void *data)
{
stack->pos++;
if (stack->pos == stack->size) {
stack->size *= 2;
stack->stack = cil_realloc(stack->stack, sizeof(*stack->stack) * stack->size);
}
stack->stack[stack->pos].flavor = flavor;
stack->stack[stack->pos].data = data;
}
struct cil_stack_item *cil_stack_pop(struct cil_stack *stack)
{
if (stack->pos == -1) {
return NULL;
}
stack->pos--;
return &stack->stack[stack->pos + 1];
}
struct cil_stack_item *cil_stack_peek(struct cil_stack *stack)
{
if (stack->pos < 0) {
return NULL;
}
return &stack->stack[stack->pos];
}
struct cil_stack_item *cil_stack_peek_at(struct cil_stack *stack, int pos)
{
int peekpos = stack->pos - pos;
if (peekpos < 0 || peekpos > stack->pos) {
return NULL;
}
return &stack->stack[peekpos];
}
libsepol-3.8.1/cil/src/cil_stack.h000066400000000000000000000050771476211737200170220ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_STACK_H_
#define CIL_STACK_H_
struct cil_stack {
struct cil_stack_item *stack;
int size;
int pos;
};
struct cil_stack_item {
enum cil_flavor flavor;
void *data;
};
#define cil_stack_for_each_starting_at(stack, start, pos, item) \
for (pos = start, item = cil_stack_peek_at(stack, pos); item != NULL; pos++, item = cil_stack_peek_at(stack, pos))
#define cil_stack_for_each(stack, pos, item) cil_stack_for_each_starting_at(stack, 0, pos, item)
void cil_stack_init(struct cil_stack **stack);
void cil_stack_destroy(struct cil_stack **stack);
void cil_stack_empty(struct cil_stack *stack);
int cil_stack_is_empty(struct cil_stack *stack);
int cil_stack_number_of_items(struct cil_stack *stack);
void cil_stack_push(struct cil_stack *stack, enum cil_flavor flavor, void *data);
struct cil_stack_item *cil_stack_pop(struct cil_stack *stack);
struct cil_stack_item *cil_stack_peek(struct cil_stack *stack);
struct cil_stack_item *cil_stack_peek_at(struct cil_stack *stack, int pos);
#endif
libsepol-3.8.1/cil/src/cil_strpool.c000066400000000000000000000076221476211737200174100ustar00rootroot00000000000000/*
* Copyright 2014 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_mem.h"
#include "cil_strpool.h"
#include "cil_log.h"
#define CIL_STRPOOL_TABLE_SIZE 1 << 15
struct cil_strpool_entry {
char *str;
};
static pthread_mutex_t cil_strpool_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned int cil_strpool_readers = 0;
static hashtab_t cil_strpool_tab = NULL;
static unsigned int cil_strpool_hash(hashtab_t h, const_hashtab_key_t key)
{
unsigned int hash = 5381;
unsigned char c;
while ((c = *(unsigned const char *)key++))
hash = ((hash << 5) + hash) ^ c;
return hash & (h->size - 1);
}
static int cil_strpool_compare(hashtab_t h __attribute__ ((unused)), const_hashtab_key_t key1, const_hashtab_key_t key2)
{
return strcmp(key1, key2);
}
char *cil_strpool_add(const char *str)
{
struct cil_strpool_entry *strpool_ref = NULL;
pthread_mutex_lock(&cil_strpool_mutex);
strpool_ref = hashtab_search(cil_strpool_tab, str);
if (strpool_ref == NULL) {
int rc;
strpool_ref = cil_malloc(sizeof(*strpool_ref));
strpool_ref->str = cil_strdup(str);
rc = hashtab_insert(cil_strpool_tab, strpool_ref->str, strpool_ref);
if (rc != SEPOL_OK) {
pthread_mutex_unlock(&cil_strpool_mutex);
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
}
pthread_mutex_unlock(&cil_strpool_mutex);
return strpool_ref->str;
}
static int cil_strpool_entry_destroy(hashtab_key_t k __attribute__ ((unused)), hashtab_datum_t d, void *args __attribute__ ((unused)))
{
struct cil_strpool_entry *strpool_ref = (struct cil_strpool_entry*)d;
free(strpool_ref->str);
free(strpool_ref);
return SEPOL_OK;
}
void cil_strpool_init(void)
{
pthread_mutex_lock(&cil_strpool_mutex);
if (cil_strpool_tab == NULL) {
cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
if (cil_strpool_tab == NULL) {
pthread_mutex_unlock(&cil_strpool_mutex);
cil_log(CIL_ERR, "Failed to allocate memory\n");
exit(1);
}
}
cil_strpool_readers++;
pthread_mutex_unlock(&cil_strpool_mutex);
}
void cil_strpool_destroy(void)
{
pthread_mutex_lock(&cil_strpool_mutex);
cil_strpool_readers--;
if (cil_strpool_readers == 0) {
hashtab_map(cil_strpool_tab, cil_strpool_entry_destroy, NULL);
hashtab_destroy(cil_strpool_tab);
cil_strpool_tab = NULL;
}
pthread_mutex_unlock(&cil_strpool_mutex);
}
libsepol-3.8.1/cil/src/cil_strpool.h000066400000000000000000000034411476211737200174100ustar00rootroot00000000000000/*
* Copyright 2014 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_STRPOOL_H_
#define CIL_STRPOOL_H_
#include
char *cil_strpool_add(const char *str);
void cil_strpool_init(void);
void cil_strpool_destroy(void);
#endif /* CIL_STRPOOL_H_ */
libsepol-3.8.1/cil/src/cil_symtab.c000066400000000000000000000172201476211737200172000ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_tree.h"
#include "cil_symtab.h"
#include "cil_mem.h"
#include "cil_strpool.h"
#include "cil_log.h"
__attribute__((noreturn)) __attribute__((format (printf, 1, 2))) static void cil_symtab_error(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
cil_vlog(CIL_ERR, msg, ap);
va_end(ap);
exit(1);
}
void cil_symtab_init(symtab_t *symtab, unsigned int size)
{
int rc = symtab_init(symtab, size);
if (rc != SEPOL_OK) {
cil_symtab_error("Failed to create symtab\n");
}
}
void cil_symtab_datum_init(struct cil_symtab_datum *datum)
{
datum->name = NULL;
datum->fqn = NULL;
datum->symtab = NULL;
cil_list_init(&datum->nodes, CIL_LIST_ITEM);
}
void cil_symtab_datum_destroy(struct cil_symtab_datum *datum)
{
cil_list_destroy(&datum->nodes, 0);
cil_symtab_remove_datum(datum);
}
void cil_symtab_datum_remove_node(struct cil_symtab_datum *datum, struct cil_tree_node *node)
{
if (datum && datum->nodes != NULL) {
cil_list_remove(datum->nodes, CIL_NODE, node, 0);
if (datum->nodes->head == NULL) {
cil_symtab_datum_destroy(datum);
}
}
}
/* This both initializes the datum and inserts it into the symtab.
Note that cil_symtab_datum_destroy() is the analog to the initializer portion */
int cil_symtab_insert(symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node)
{
int rc = hashtab_insert(symtab->table, key, (hashtab_datum_t)datum);
if (rc == SEPOL_OK) {
datum->name = key;
datum->fqn = key;
datum->symtab = symtab;
symtab->nprim++;
if (node) {
cil_list_append(datum->nodes, CIL_NODE, node);
}
} else if (rc != SEPOL_EEXIST) {
cil_symtab_error("Failed to insert datum into hashtab\n");
}
return rc;
}
void cil_symtab_remove_datum(struct cil_symtab_datum *datum)
{
symtab_t *symtab = datum->symtab;
if (symtab == NULL) {
return;
}
hashtab_remove(symtab->table, datum->name, NULL, NULL);
symtab->nprim--;
datum->symtab = NULL;
}
int cil_symtab_get_datum(symtab_t *symtab, char *key, struct cil_symtab_datum **datum)
{
*datum = (struct cil_symtab_datum*)hashtab_search(symtab->table, (hashtab_key_t)key);
if (*datum == NULL) {
return SEPOL_ENOENT;
}
return SEPOL_OK;
}
int cil_symtab_map(symtab_t *symtab,
int (*apply) (hashtab_key_t k, hashtab_datum_t d, void *args),
void *args)
{
return hashtab_map(symtab->table, apply, args);
}
static int __cil_symtab_destroy_helper(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, __attribute__((unused)) void *args)
{
struct cil_symtab_datum *datum = d;
datum->symtab = NULL;
return SEPOL_OK;
}
void cil_symtab_destroy(symtab_t *symtab)
{
if (symtab->table != NULL){
cil_symtab_map(symtab, __cil_symtab_destroy_helper, NULL);
hashtab_destroy(symtab->table);
symtab->table = NULL;
}
}
static void cil_complex_symtab_hash(struct cil_complex_symtab_key *ckey, int mask, intptr_t *hash)
{
intptr_t sum = ckey->key1 + ckey->key2 + ckey->key3 + ckey->key4;
*hash = (intptr_t)((sum >> 2) & mask);
}
void cil_complex_symtab_init(struct cil_complex_symtab *symtab, unsigned int size)
{
symtab->htable = cil_calloc(size, sizeof(struct cil_complex_symtab *));
symtab->nelems = 0;
symtab->nslots = size;
symtab->mask = size - 1;
}
int cil_complex_symtab_insert(struct cil_complex_symtab *symtab,
struct cil_complex_symtab_key *ckey,
struct cil_complex_symtab_datum *datum)
{
intptr_t hash;
struct cil_complex_symtab_node *node = NULL;
struct cil_complex_symtab_node *prev = NULL;
struct cil_complex_symtab_node *curr = NULL;
node = cil_malloc(sizeof(*node));
memset(node, 0, sizeof(*node));
node->ckey = ckey;
node->datum = datum;
cil_complex_symtab_hash(ckey, symtab->mask, &hash);
for (prev = NULL, curr = symtab->htable[hash]; curr != NULL;
prev = curr, curr = curr->next) {
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 == curr->ckey->key3 &&
ckey->key4 == curr->ckey->key4) {
free(node);
return SEPOL_EEXIST;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 < curr->ckey->key2) {
break;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 < curr->ckey->key3) {
break;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 == curr->ckey->key3 &&
ckey->key4 < curr->ckey->key4) {
break;
}
}
if (prev != NULL) {
node->next = prev->next;
prev->next = node;
} else {
node->next = symtab->htable[hash];
symtab->htable[hash] = node;
}
symtab->nelems++;
return SEPOL_OK;
}
void cil_complex_symtab_search(struct cil_complex_symtab *symtab,
struct cil_complex_symtab_key *ckey,
struct cil_complex_symtab_datum **out)
{
intptr_t hash;
struct cil_complex_symtab_node *curr = NULL;
cil_complex_symtab_hash(ckey, symtab->mask, &hash);
for (curr = symtab->htable[hash]; curr != NULL; curr = curr->next) {
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 == curr->ckey->key3 &&
ckey->key4 == curr->ckey->key4) {
*out = curr->datum;
return;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 < curr->ckey->key2) {
break;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 < curr->ckey->key3) {
break;
}
if (ckey->key1 == curr->ckey->key1 &&
ckey->key2 == curr->ckey->key2 &&
ckey->key3 == curr->ckey->key3 &&
ckey->key4 < curr->ckey->key4) {
break;
}
}
*out = NULL;
}
void cil_complex_symtab_destroy(struct cil_complex_symtab *symtab)
{
struct cil_complex_symtab_node *curr = NULL;
struct cil_complex_symtab_node *temp = NULL;
unsigned int i;
if (symtab == NULL) {
return;
}
for (i = 0; i < symtab->nslots; i++) {
curr = symtab->htable[i];
while (curr != NULL) {
temp = curr;
curr = curr->next;
free(temp);
}
symtab->htable[i] = NULL;
}
free(symtab->htable);
symtab->htable = NULL;
symtab->nelems = 0;
symtab->nslots = 0;
symtab->mask = 0;
}
libsepol-3.8.1/cil/src/cil_symtab.h000066400000000000000000000070311476211737200172040ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef __CIL_SYMTAB_H_
#define __CIL_SYMTAB_H_
#include
#include
#include "cil_tree.h"
struct cil_symtab_datum {
struct cil_list *nodes;
char *name;
char *fqn;
symtab_t *symtab;
};
#define DATUM(d) ((struct cil_symtab_datum *)(d))
#define NODE(n) ((struct cil_tree_node *)(DATUM(n)->nodes->head->data))
#define FLAVOR(f) (NODE(f)->flavor)
struct cil_complex_symtab_key {
intptr_t key1;
intptr_t key2;
intptr_t key3;
intptr_t key4;
};
struct cil_complex_symtab_datum {
void *data;
};
struct cil_complex_symtab_node {
struct cil_complex_symtab_key *ckey;
struct cil_complex_symtab_datum *datum;
struct cil_complex_symtab_node *next;
};
struct cil_complex_symtab {
struct cil_complex_symtab_node **htable;
uint32_t nelems;
uint32_t nslots;
uint32_t mask;
};
void cil_symtab_init(symtab_t *symtab, unsigned int size);
void cil_symtab_datum_init(struct cil_symtab_datum *datum);
void cil_symtab_datum_destroy(struct cil_symtab_datum *datum);
void cil_symtab_datum_remove_node(struct cil_symtab_datum *datum, struct cil_tree_node *node);
int cil_symtab_insert(symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node);
void cil_symtab_remove_datum(struct cil_symtab_datum *datum);
int cil_symtab_get_datum(symtab_t *symtab, char *key, struct cil_symtab_datum **datum);
int cil_symtab_map(symtab_t *symtab,
int (*apply) (hashtab_key_t k, hashtab_datum_t d, void *args),
void *args);
void cil_symtab_destroy(symtab_t *symtab);
void cil_complex_symtab_init(struct cil_complex_symtab *symtab, unsigned int size);
int cil_complex_symtab_insert(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum *datum);
void cil_complex_symtab_search(struct cil_complex_symtab *symtab, struct cil_complex_symtab_key *ckey, struct cil_complex_symtab_datum **out);
void cil_complex_symtab_destroy(struct cil_complex_symtab *symtab);
#endif
libsepol-3.8.1/cil/src/cil_tree.c000066400000000000000000000222771476211737200166500ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_parser.h"
#include "cil_strpool.h"
struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **info_kind, uint32_t *hll_line, char **path)
{
int rc;
if (!node) {
goto exit;
}
node = node->parent;
while (node) {
if (node->flavor == CIL_NODE && node->data == NULL) {
if (node->cl_head && node->cl_head->data == CIL_KEY_SRC_INFO) {
if (!node->cl_head->next || !node->cl_head->next->next || !node->cl_head->next->next->next) {
goto exit;
}
/* Parse Tree */
*info_kind = node->cl_head->next->data;
rc = cil_string_to_uint32(node->cl_head->next->next->data, hll_line, 10);
if (rc != SEPOL_OK) {
goto exit;
}
*path = node->cl_head->next->next->next->data;
return node;
}
node = node->parent;
} else if (node->flavor == CIL_SRC_INFO) {
/* AST */
struct cil_src_info *info = node->data;
*info_kind = info->kind;
*hll_line = info->hll_line;
*path = info->path;
return node;
} else {
if (node->flavor == CIL_CALL) {
struct cil_call *call = node->data;
node = NODE(call->macro);
} else if (node->flavor == CIL_BLOCKINHERIT) {
struct cil_blockinherit *inherit = node->data;
node = NODE(inherit->block);
} else {
node = node->parent;
}
}
}
exit:
*info_kind = NULL;
*hll_line = 0;
*path = NULL;
return NULL;
}
char *cil_tree_get_cil_path(struct cil_tree_node *node)
{
char *info_kind;
uint32_t hll_line;
char *path;
while (node) {
node = cil_tree_get_next_path(node, &info_kind, &hll_line, &path);
if (node && info_kind == CIL_KEY_SRC_CIL) {
return path;
}
}
return NULL;
}
__attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
cil_vlog(lvl, msg, ap);
va_end(ap);
if (node) {
char *path = NULL;
uint32_t hll_offset = node->hll_offset;
path = cil_tree_get_cil_path(node);
if (path != NULL) {
cil_log(lvl, " at %s:%u", path, node->line);
}
while (node) {
do {
char *info_kind;
uint32_t hll_line;
node = cil_tree_get_next_path(node, &info_kind, &hll_line, &path);
if (!node || info_kind == CIL_KEY_SRC_CIL) {
break;
}
if (info_kind == CIL_KEY_SRC_HLL_LMS) {
hll_line += hll_offset - node->hll_offset - 1;
}
cil_log(lvl," from %s:%u", path, hll_line);
} while (1);
}
}
cil_log(lvl,"\n");
}
int cil_tree_subtree_has_decl(struct cil_tree_node *node)
{
while (node) {
if (node->flavor >= CIL_MIN_DECLARATIVE) {
return CIL_TRUE;
}
if (node->cl_head != NULL) {
if (cil_tree_subtree_has_decl(node->cl_head))
return CIL_TRUE;
}
node = node->next;
}
return CIL_FALSE;
}
int cil_tree_init(struct cil_tree **tree)
{
struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));
cil_tree_node_init(&new_tree->root);
*tree = new_tree;
return SEPOL_OK;
}
void cil_tree_destroy(struct cil_tree **tree)
{
if (tree == NULL || *tree == NULL) {
return;
}
cil_tree_subtree_destroy((*tree)->root);
free(*tree);
*tree = NULL;
}
void cil_tree_subtree_destroy(struct cil_tree_node *node)
{
cil_tree_children_destroy(node);
cil_tree_node_destroy(&node);
}
void cil_tree_children_destroy(struct cil_tree_node *node)
{
struct cil_tree_node *curr, *next;
if (!node) {
return;
}
curr = node->cl_head;
while (curr) {
next = curr->next;
cil_tree_children_destroy(curr);
cil_tree_node_destroy(&curr);
curr = next;
}
node->cl_head = NULL;
node->cl_tail = NULL;
}
void cil_tree_node_init(struct cil_tree_node **node)
{
struct cil_tree_node *new_node = cil_malloc(sizeof(*new_node));
new_node->cl_head = NULL;
new_node->cl_tail = NULL;
new_node->parent = NULL;
new_node->data = NULL;
new_node->next = NULL;
new_node->flavor = CIL_ROOT;
new_node->line = 0;
new_node->hll_offset = 0;
*node = new_node;
}
void cil_tree_node_destroy(struct cil_tree_node **node)
{
struct cil_symtab_datum *datum;
if (node == NULL || *node == NULL) {
return;
}
if ((*node)->flavor >= CIL_MIN_DECLARATIVE) {
datum = (*node)->data;
cil_symtab_datum_remove_node(datum, *node);
if (datum->nodes == NULL) {
cil_destroy_data(&(*node)->data, (*node)->flavor);
}
} else {
cil_destroy_data(&(*node)->data, (*node)->flavor);
}
free(*node);
*node = NULL;
}
void cil_tree_node_remove(struct cil_tree_node *node)
{
struct cil_tree_node *parent, *curr;
if (node == NULL || node->parent == NULL) {
return;
}
parent = node->parent;
if (parent->cl_head == node) {
if (parent->cl_tail == node) {
parent->cl_tail = NULL;
}
parent->cl_head = node->next;
cil_tree_node_destroy(&node);
return;
}
curr = parent->cl_head;
while (curr && curr->next != node) {
curr = curr->next;
}
if (curr == NULL) {
return;
}
if (parent->cl_tail == node) {
parent->cl_tail = curr;
}
curr->next = node->next;
cil_tree_node_destroy(&node);
}
/* Perform depth-first walk of the tree
Parameters:
start_node: root node to start walking from
process_node: function to call when visiting a node
Takes parameters:
node: node being visited
finished: boolean indicating to the tree walker that it should move on from this branch
extra_args: additional data
first_child: Function to call before entering list of children
Takes parameters:
node: node of first child
extra args: additional data
last_child: Function to call when finished with the last child of a node's children
extra_args: any additional data to be passed to the helper functions
*/
static int cil_tree_walk_core(struct cil_tree_node *node,
int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
int (*first_child)(struct cil_tree_node *node, void *extra_args),
int (*last_child)(struct cil_tree_node *node, void *extra_args),
void *extra_args)
{
int rc = SEPOL_ERR;
while (node) {
uint32_t finished = CIL_TREE_SKIP_NOTHING;
if (process_node != NULL) {
rc = (*process_node)(node, &finished, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
if (finished & CIL_TREE_SKIP_NEXT) {
return SEPOL_OK;
}
if (node->cl_head != NULL && !(finished & CIL_TREE_SKIP_HEAD)) {
rc = cil_tree_walk(node, process_node, first_child, last_child, extra_args);
if (rc != SEPOL_OK) {
return rc;
}
}
node = node->next;
}
return SEPOL_OK;
}
int cil_tree_walk(struct cil_tree_node *node,
int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
int (*first_child)(struct cil_tree_node *node, void *extra_args),
int (*last_child)(struct cil_tree_node *node, void *extra_args),
void *extra_args)
{
int rc = SEPOL_ERR;
if (!node || !node->cl_head) {
return SEPOL_OK;
}
if (first_child != NULL) {
rc = (*first_child)(node->cl_head, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
rc = cil_tree_walk_core(node->cl_head, process_node, first_child, last_child, extra_args);
if (rc != SEPOL_OK) {
return rc;
}
if (last_child != NULL) {
rc = (*last_child)(node->cl_tail, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
return SEPOL_OK;
}
libsepol-3.8.1/cil/src/cil_tree.h000066400000000000000000000064461476211737200166550ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_TREE_H_
#define CIL_TREE_H_
#include
#include "cil_flavor.h"
#include "cil_list.h"
struct cil_tree {
struct cil_tree_node *root;
};
struct cil_tree_node {
struct cil_tree_node *parent;
struct cil_tree_node *cl_head; //Head of child_list
struct cil_tree_node *cl_tail; //Tail of child_list
struct cil_tree_node *next; //Each element in the list points to the next element
enum cil_flavor flavor;
uint32_t line;
uint32_t hll_offset;
void *data;
};
struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **info_kind, uint32_t *hll_line, char **path);
char *cil_tree_get_cil_path(struct cil_tree_node *node);
__attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
int cil_tree_subtree_has_decl(struct cil_tree_node *node);
int cil_tree_init(struct cil_tree **tree);
void cil_tree_destroy(struct cil_tree **tree);
void cil_tree_subtree_destroy(struct cil_tree_node *node);
void cil_tree_children_destroy(struct cil_tree_node *node);
void cil_tree_node_init(struct cil_tree_node **node);
void cil_tree_node_destroy(struct cil_tree_node **node);
void cil_tree_node_remove(struct cil_tree_node *node);
//finished values
#define CIL_TREE_SKIP_NOTHING 0
#define CIL_TREE_SKIP_NEXT 1
#define CIL_TREE_SKIP_HEAD 2
#define CIL_TREE_SKIP_ALL (CIL_TREE_SKIP_NOTHING | CIL_TREE_SKIP_NEXT | CIL_TREE_SKIP_HEAD)
int cil_tree_walk(struct cil_tree_node *start_node, int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args), int (*first_child)(struct cil_tree_node *node, void *extra_args), int (*last_child)(struct cil_tree_node *node, void *extra_args), void *extra_args);
#endif /* CIL_TREE_H_ */
libsepol-3.8.1/cil/src/cil_verify.c000066400000000000000000001425351476211737200172150ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_mem.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_find.h"
#include "cil_stack.h"
#include "cil_verify.h"
static int __cil_is_reserved_name(const char *name, enum cil_flavor flavor)
{
switch (flavor) {
case CIL_BOOL:
case CIL_TUNABLE:
if ((name == CIL_KEY_EQ) || (name == CIL_KEY_NEQ))
return CIL_TRUE;
break;
case CIL_PERM:
case CIL_MAP_PERM:
case CIL_USER:
case CIL_USERATTRIBUTE:
case CIL_ROLE:
case CIL_ROLEATTRIBUTE:
if (name == CIL_KEY_ALL)
return CIL_TRUE;
break;
case CIL_TYPE:
case CIL_TYPEATTRIBUTE:
case CIL_TYPEALIAS:
if ((name == CIL_KEY_ALL) || (name == CIL_KEY_SELF) || (name == CIL_KEY_NOTSELF)
|| (name == CIL_KEY_OTHER))
return CIL_TRUE;
break;
case CIL_CAT:
case CIL_CATSET:
case CIL_CATALIAS:
case CIL_PERMISSIONX:
if ((name == CIL_KEY_ALL) || (name == CIL_KEY_RANGE))
return CIL_TRUE;
break;
default:
/* All of these are not used in expressions */
return CIL_FALSE;
break;
}
/* Everything not under the default case is also checked for these */
if ((name == CIL_KEY_AND) || (name == CIL_KEY_OR) || (name == CIL_KEY_NOT) || (name == CIL_KEY_XOR)) {
return CIL_TRUE;
}
return CIL_FALSE;
}
int cil_verify_name(const struct cil_db *db, const char *name, enum cil_flavor flavor)
{
int rc = SEPOL_ERR;
int len;
int i = 0;
if (name == NULL) {
cil_log(CIL_ERR, "Name is NULL\n");
goto exit;
}
len = strlen(name);
if (len >= CIL_MAX_NAME_LENGTH) {
cil_log(CIL_ERR, "Name length greater than max name length of %d",
CIL_MAX_NAME_LENGTH);
rc = SEPOL_ERR;
goto exit;
}
if (!isalpha(name[0])) {
cil_log(CIL_ERR, "First character in %s is not a letter\n", name);
goto exit;
}
if (db->qualified_names == CIL_FALSE) {
for (i = 1; i < len; i++) {
if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') {
cil_log(CIL_ERR, "Invalid character \"%c\" in %s\n", name[i], name);
goto exit;
}
}
} else {
for (i = 1; i < len; i++) {
if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-' && name[i] != '.') {
cil_log(CIL_ERR, "Invalid character \"%c\" in %s\n", name[i], name);
goto exit;
}
}
}
if (__cil_is_reserved_name(name, flavor)) {
cil_log(CIL_ERR, "Name %s is a reserved word\n", name);
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Invalid name\n");
return rc;
}
int __cil_verify_syntax(struct cil_tree_node *parse_current, enum cil_syntax s[], size_t len)
{
struct cil_tree_node *c = parse_current;
size_t i = 0;
while (i < len && c != NULL) {
if ((s[i] & CIL_SYN_STRING) && c->data != NULL && c->cl_head == NULL) {
c = c->next;
i++;
} else if ((s[i] & CIL_SYN_LIST) && c->data == NULL && c->cl_head != NULL) {
c = c->next;
i++;
} else if ((s[i] & CIL_SYN_EMPTY_LIST) && c->data == NULL && c->cl_head == NULL) {
c = c->next;
i++;
} else if ((s[i] & CIL_SYN_N_LISTS) || (s[i] & CIL_SYN_N_STRINGS)) {
while (c != NULL) {
if ((s[i] & CIL_SYN_N_LISTS) && c->data == NULL && c->cl_head != NULL) {
c = c->next;
} else if ((s[i] & CIL_SYN_N_STRINGS) && c->data != NULL && c->cl_head == NULL) {
c = c->next;
} else {
goto exit;
}
}
i++;
break; /* Only CIL_SYN_END allowed after these */
} else {
goto exit;
}
}
if (i < len && (s[i] & CIL_SYN_END) && c == NULL) {
return SEPOL_OK;
}
exit:
cil_log(CIL_ERR, "Invalid syntax\n");
return SEPOL_ERR;
}
int cil_verify_expr_syntax(struct cil_tree_node *current, enum cil_flavor op, enum cil_flavor expr_flavor)
{
int rc;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_STRING | CIL_SYN_LIST,
CIL_SYN_END
};
int syntax_len = sizeof(syntax)/sizeof(*syntax);
switch (op) {
case CIL_NOT:
syntax[2] = CIL_SYN_END;
syntax_len = 3;
break;
case CIL_AND:
case CIL_OR:
case CIL_XOR:
break;
case CIL_EQ:
case CIL_NEQ:
if (expr_flavor != CIL_BOOL && expr_flavor != CIL_TUNABLE ) {
cil_log(CIL_ERR,"Invalid operator (%s) for set expression\n", (char*)current->data);
goto exit;
}
break;
case CIL_ALL:
if (expr_flavor == CIL_BOOL || expr_flavor == CIL_TUNABLE) {
cil_log(CIL_ERR,"Invalid operator (%s) for boolean or tunable expression\n", (char*)current->data);
goto exit;
}
syntax[1] = CIL_SYN_END;
syntax_len = 2;
break;
case CIL_RANGE:
if (expr_flavor != CIL_CAT && expr_flavor != CIL_PERMISSIONX) {
cil_log(CIL_ERR,"Operator (%s) only valid for catset and permissionx expression\n", (char*)current->data);
goto exit;
}
syntax[1] = CIL_SYN_STRING;
syntax[2] = CIL_SYN_STRING;
break;
case CIL_NONE: /* String or List */
syntax[0] = CIL_SYN_N_STRINGS | CIL_SYN_N_LISTS;
syntax[1] = CIL_SYN_END;
syntax_len = 2;
break;
default:
cil_log(CIL_ERR,"Unexpected value (%s) for expression operator\n", (char*)current->data);
goto exit;
}
rc = __cil_verify_syntax(current, syntax, syntax_len);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
int cil_verify_constraint_leaf_expr_syntax(enum cil_flavor l_flavor, enum cil_flavor r_flavor, enum cil_flavor op, enum cil_flavor expr_flavor)
{
if (r_flavor == CIL_STRING || r_flavor == CIL_LIST) {
if (l_flavor == CIL_CONS_L1 || l_flavor == CIL_CONS_L2 || l_flavor == CIL_CONS_H1 || l_flavor == CIL_CONS_H2 ) {
cil_log(CIL_ERR, "l1, l2, h1, and h2 cannot be used on the left side with a string or list on the right side\n");
goto exit;
} else if (l_flavor == CIL_CONS_U3 || l_flavor == CIL_CONS_R3 || l_flavor == CIL_CONS_T3) {
if (expr_flavor != CIL_VALIDATETRANS && expr_flavor != CIL_MLSVALIDATETRANS) {
cil_log(CIL_ERR, "u3, r3, and t3 can only be used with (mls)validatetrans rules\n");
goto exit;
}
}
} else {
if (r_flavor == CIL_CONS_U1 || r_flavor == CIL_CONS_R1 || r_flavor == CIL_CONS_T1) {
cil_log(CIL_ERR, "u1, r1, and t1 are not allowed on the right side\n");
goto exit;
} else if (r_flavor == CIL_CONS_U3 || r_flavor == CIL_CONS_R3 || r_flavor == CIL_CONS_T3) {
cil_log(CIL_ERR, "u3, r3, and t3 are not allowed on the right side\n");
goto exit;
} else if (r_flavor == CIL_CONS_U2) {
if (op != CIL_EQ && op != CIL_NEQ) {
cil_log(CIL_ERR, "u2 on the right side must be used with eq or neq as the operator\n");
goto exit;
} else if (l_flavor != CIL_CONS_U1) {
cil_log(CIL_ERR, "u2 on the right side must be used with u1 on the left\n");
goto exit;
}
} else if (r_flavor == CIL_CONS_R2) {
if (l_flavor != CIL_CONS_R1) {
cil_log(CIL_ERR, "r2 on the right side must be used with r1 on the left\n");
goto exit;
}
} else if (r_flavor == CIL_CONS_T2) {
if (op != CIL_EQ && op != CIL_NEQ) {
cil_log(CIL_ERR, "t2 on the right side must be used with eq or neq as the operator\n");
goto exit;
} else if (l_flavor != CIL_CONS_T1) {
cil_log(CIL_ERR, "t2 on the right side must be used with t1 on the left\n");
goto exit;
}
} else if (r_flavor == CIL_CONS_L2) {
if (l_flavor != CIL_CONS_L1 && l_flavor != CIL_CONS_H1) {
cil_log(CIL_ERR, "l2 on the right side must be used with l1 or h1 on the left\n");
goto exit;
}
} else if (r_flavor == CIL_CONS_H2) {
if (l_flavor != CIL_CONS_L1 && l_flavor != CIL_CONS_L2 && l_flavor != CIL_CONS_H1 ) {
cil_log(CIL_ERR, "h2 on the right side must be used with l1, l2, or h1 on the left\n");
goto exit;
}
} else if (r_flavor == CIL_CONS_H1) {
if (l_flavor != CIL_CONS_L1) {
cil_log(CIL_ERR, "h1 on the right side must be used with l1 on the left\n");
goto exit;
}
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
int cil_verify_constraint_expr_syntax(struct cil_tree_node *current, enum cil_flavor op)
{
int rc;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_END,
CIL_SYN_END,
CIL_SYN_END
};
int syntax_len = sizeof(syntax)/sizeof(*syntax);
switch (op) {
case CIL_NOT:
syntax[1] = CIL_SYN_LIST;
syntax_len--;
break;
case CIL_AND:
case CIL_OR:
syntax[1] = CIL_SYN_LIST;
syntax[2] = CIL_SYN_LIST;
break;
case CIL_EQ:
case CIL_NEQ:
syntax[1] = CIL_SYN_STRING;
syntax[2] = CIL_SYN_STRING | CIL_SYN_LIST;
break;
case CIL_CONS_DOM:
case CIL_CONS_DOMBY:
case CIL_CONS_INCOMP:
syntax[1] = CIL_SYN_STRING;
syntax[2] = CIL_SYN_STRING;
break;
default:
cil_log(CIL_ERR, "Invalid operator (%s) for constraint expression\n", (char*)current->data);
goto exit;
}
rc = __cil_verify_syntax(current, syntax, syntax_len);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Invalid constraint syntax\n");
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
int cil_verify_conditional_blocks(struct cil_tree_node *current)
{
int found_true = CIL_FALSE;
int found_false = CIL_FALSE;
if (current->cl_head->data == CIL_KEY_CONDTRUE) {
found_true = CIL_TRUE;
} else if (current->cl_head->data == CIL_KEY_CONDFALSE) {
found_false = CIL_TRUE;
} else {
cil_tree_log(current, CIL_ERR, "Expected true or false block in conditional");
return SEPOL_ERR;
}
current = current->next;
if (current != NULL) {
if (current->cl_head->data == CIL_KEY_CONDTRUE) {
if (found_true) {
cil_tree_log(current, CIL_ERR, "More than one true block in conditional");
return SEPOL_ERR;
}
} else if (current->cl_head->data == CIL_KEY_CONDFALSE) {
if (found_false) {
cil_tree_log(current, CIL_ERR, "More than one false block in conditional");
return SEPOL_ERR;
}
} else {
cil_tree_log(current, CIL_ERR, "Expected true or false block in conditional");
return SEPOL_ERR;
}
}
return SEPOL_OK;
}
int cil_verify_decl_does_not_shadow_macro_parameter(struct cil_macro *macro, struct cil_tree_node *node, const char *name)
{
struct cil_list_item *item;
struct cil_list *param_list = macro->params;
if (param_list != NULL) {
cil_list_for_each(item, param_list) {
struct cil_param *param = item->data;
if (param->str == name) {
if (param->flavor == node->flavor) {
cil_log(CIL_ERR, "Declaration of %s %s shadows a macro parameter with the same flavor\n", cil_node_to_string(node), name);
return SEPOL_ERR;
} else {
cil_log(CIL_WARN, "Declaration of %s %s has same name as a macro parameter with a different flavor\n", cil_node_to_string(node), name);
}
}
}
}
return SEPOL_OK;
}
static int cil_verify_no_self_reference(enum cil_flavor flavor, struct cil_symtab_datum *datum, struct cil_stack *stack);
static int __verify_no_self_reference_in_expr(struct cil_list *expr, struct cil_stack *stack)
{
struct cil_list_item *item;
int rc = SEPOL_OK;
if (!expr) {
return SEPOL_OK;
}
cil_list_for_each(item, expr) {
if (item->flavor == CIL_DATUM) {
struct cil_symtab_datum* datum = item->data;
rc = cil_verify_no_self_reference(FLAVOR(datum), datum, stack);
} else if (item->flavor == CIL_LIST) {
rc = __verify_no_self_reference_in_expr(item->data, stack);
}
if (rc != SEPOL_OK) {
return SEPOL_ERR;
}
}
return SEPOL_OK;
}
static int cil_verify_no_self_reference(enum cil_flavor flavor, struct cil_symtab_datum *datum, struct cil_stack *stack)
{
struct cil_stack_item *item;
int i = 0;
int rc = SEPOL_OK;
cil_stack_for_each(stack, i, item) {
struct cil_symtab_datum *prev = item->data;
if (datum == prev) {
cil_tree_log(NODE(datum), CIL_ERR, "Self-reference found for %s", datum->name);
return SEPOL_ERR;
}
}
switch (flavor) {
case CIL_USERATTRIBUTE: {
struct cil_userattribute *attr = (struct cil_userattribute *)datum;
cil_stack_push(stack, CIL_DATUM, datum);
rc = __verify_no_self_reference_in_expr(attr->expr_list, stack);
cil_stack_pop(stack);
break;
}
case CIL_ROLEATTRIBUTE: {
struct cil_roleattribute *attr = (struct cil_roleattribute *)datum;
cil_stack_push(stack, CIL_DATUM, datum);
rc = __verify_no_self_reference_in_expr(attr->expr_list, stack);
cil_stack_pop(stack);
break;
}
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = (struct cil_typeattribute *)datum;
cil_stack_push(stack, CIL_DATUM, datum);
rc = __verify_no_self_reference_in_expr(attr->expr_list, stack);
cil_stack_pop(stack);
break;
}
case CIL_CATSET: {
struct cil_catset *set = (struct cil_catset *)datum;
cil_stack_push(stack, CIL_DATUM, datum);
rc = __verify_no_self_reference_in_expr(set->cats->datum_expr, stack);
cil_stack_pop(stack);
break;
}
default:
break;
}
return rc;
}
int __cil_verify_ranges(struct cil_list *list)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
struct cil_list_item *range = NULL;
if (list == NULL || list->head == NULL) {
goto exit;
}
cil_list_for_each(curr, list) {
/* range */
if (curr->flavor == CIL_LIST) {
range = ((struct cil_list*)curr->data)->head;
if (range == NULL || range->next == NULL || range->next->next != NULL) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR,"Invalid Range syntax\n");
return rc;
}
int cil_verify_completed_ordered_list(struct cil_list *complete, struct cil_list *ordered_lists)
{
struct cil_list_item *cprev, *ccurr, *cnext;
int found_prev, found_next;
int rc = SEPOL_OK;
found_prev = CIL_FALSE;
found_next = CIL_FALSE;
cprev = NULL;
ccurr = complete->head;
cnext = ccurr ? ccurr->next : NULL;
while (ccurr) {
struct cil_tree_node *node;
struct cil_ordered *ordered;
struct cil_list_item *curr_list, *oprev, *ocurr, *onext;
int change = CIL_FALSE;
cil_list_for_each(curr_list, ordered_lists) {
node = curr_list->data;
ordered = node->data;
oprev = NULL;
cil_list_for_each(ocurr, ordered->datums) {
onext = ocurr ? ocurr->next : NULL;
if (ccurr->data == ocurr->data) {
if (found_prev == CIL_FALSE && ((!cprev && !oprev) ||
(cprev && oprev && cprev->data == oprev->data))) {
found_prev = CIL_TRUE;
change = CIL_TRUE;
}
if (found_next == CIL_FALSE && ((!cnext && !onext) ||
(cnext && onext && cnext->data == onext->data))) {
found_next = CIL_TRUE;
change = CIL_TRUE;
}
if (found_prev && found_next) {
cprev = ccurr;
ccurr = cnext;
cnext = ccurr ? ccurr->next : NULL;
found_prev = CIL_FALSE;
found_next = CIL_FALSE;
if (!ccurr) {
/* Went through the whole list */
return rc;
}
}
}
oprev = ocurr;
}
}
if (!change) {
rc = SEPOL_ERR;
cil_log(CIL_ERR, "Unable to verify the order of %s\n", DATUM(ccurr->data)->fqn);
cil_log(CIL_ERR, "Found in the following ordering rules:\n");
cil_list_for_each(curr_list, ordered_lists) {
node = curr_list->data;
ordered = node->data;
cil_list_for_each(ocurr, ordered->datums) {
if (ccurr->data == ocurr->data) {
cil_tree_log(node, CIL_ERR, " ");
}
}
}
cprev = ccurr;
ccurr = cnext;
cnext = ccurr ? ccurr->next : NULL;
found_prev = CIL_FALSE;
found_next = CIL_FALSE;
}
}
return rc;
}
struct cil_args_verify_order {
uint32_t *flavor;
};
int __cil_verify_ordered_node_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *extra_args)
{
struct cil_args_verify_order *args = extra_args;
uint32_t *flavor = args->flavor;
if (node->flavor == *flavor) {
if (node->flavor == CIL_SID) {
struct cil_sid *sid = node->data;
if (sid->ordered == CIL_FALSE) {
cil_tree_log(node, CIL_ERR, "SID %s not in sidorder statement", sid->datum.name);
return SEPOL_ERR;
}
} else if (node->flavor == CIL_CLASS) {
struct cil_class *class = node->data;
if (class->ordered == CIL_FALSE) {
cil_tree_log(node, CIL_ERR, "Class %s not in classorder statement", class->datum.name);
return SEPOL_ERR;
}
} else if (node->flavor == CIL_CAT) {
struct cil_cat *cat = node->data;
if (cat->ordered == CIL_FALSE) {
cil_tree_log(node, CIL_ERR, "Category %s not in categoryorder statement", cat->datum.name);
return SEPOL_ERR;
}
} else if (node->flavor == CIL_SENS) {
struct cil_sens *sens = node->data;
if (sens->ordered == CIL_FALSE) {
cil_tree_log(node, CIL_ERR, "Sensitivity %s not in sensitivityorder statement", sens->datum.name);
return SEPOL_ERR;
}
}
}
return SEPOL_OK;
}
int __cil_verify_ordered(struct cil_tree_node *current, enum cil_flavor flavor)
{
struct cil_args_verify_order extra_args;
int rc = SEPOL_ERR;
extra_args.flavor = &flavor;
rc = cil_tree_walk(current, __cil_verify_ordered_node_helper, NULL, NULL, &extra_args);
return rc;
}
int __cil_verify_initsids(struct cil_list *sids)
{
int rc = SEPOL_OK;
struct cil_list_item *i;
if (sids->head == NULL) {
cil_log(CIL_ERR, "At least one initial sid must be defined in the policy\n");
return SEPOL_ERR;
}
cil_list_for_each(i, sids) {
struct cil_sid *sid = i->data;
if (sid->context == NULL) {
struct cil_tree_node *node = sid->datum.nodes->head->data;
cil_tree_log(node, CIL_INFO, "No context assigned to SID %s, omitting from policy",sid->datum.name);
}
}
return rc;
}
static int __cil_is_cat_in_cats(struct cil_cat *cat, struct cil_cats *cats)
{
struct cil_list_item *i;
cil_list_for_each(i, cats->datum_expr) {
struct cil_cat *c = i->data;
if (c == cat) {
return CIL_TRUE;
}
}
return CIL_FALSE;
}
static int __cil_verify_cat_in_cats(struct cil_cat *cat, struct cil_cats *cats)
{
if (__cil_is_cat_in_cats(cat, cats) != CIL_TRUE) {
cil_log(CIL_ERR, "Failed to find category %s in category list\n", cat->datum.name);
return SEPOL_ERR;
}
return SEPOL_OK;
}
static int __cil_verify_cats_associated_with_sens(struct cil_sens *sens, struct cil_cats *cats)
{
int rc = SEPOL_OK;
struct cil_list_item *i, *j;
if (!cats) {
return SEPOL_OK;
}
if (!sens->cats_list) {
cil_log(CIL_ERR, "No categories can be used with sensitivity %s\n", sens->datum.name);
return SEPOL_ERR;
}
cil_list_for_each(i, cats->datum_expr) {
struct cil_cat *cat = i->data;
int ok = CIL_FALSE;
cil_list_for_each(j, sens->cats_list) {
if (__cil_is_cat_in_cats(cat, j->data) == CIL_TRUE) {
ok = CIL_TRUE;
break;
}
}
if (ok != CIL_TRUE) {
cil_log(CIL_ERR, "Category %s cannot be used with sensitivity %s\n",
cat->datum.name, sens->datum.name);
rc = SEPOL_ERR;
}
}
return rc;
}
static int __cil_verify_levelrange_sensitivity(struct cil_db *db, struct cil_sens *low, struct cil_sens *high)
{
struct cil_list_item *curr;
int found = CIL_FALSE;
int rc = SEPOL_ERR;
cil_list_for_each(curr, db->sensitivityorder) {
if (curr->data == low) {
found = CIL_TRUE;
}
if ((found == CIL_TRUE) && (curr->data == high)) {
break;
}
}
if (found != CIL_TRUE || curr == NULL) {
goto exit;
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Sensitivity %s does not dominate %s\n",
high->datum.name, low->datum.name);
return rc;
}
static int __cil_verify_levelrange_cats(struct cil_cats *low, struct cil_cats *high)
{
int rc = SEPOL_ERR;
struct cil_list_item *item;
if (low == NULL || (low == NULL && high == NULL)) {
return SEPOL_OK;
}
if (high == NULL) {
rc = SEPOL_ERR;
goto exit;
}
cil_list_for_each(item, low->datum_expr) {
rc = __cil_verify_cat_in_cats(item->data, high);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Low level category set must be a subset of the high level category set\n");
return rc;
}
static int __cil_verify_levelrange(struct cil_db *db, struct cil_levelrange *lr)
{
int rc = SEPOL_ERR;
rc = __cil_verify_levelrange_sensitivity(db, lr->low->sens, lr->high->sens);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_verify_levelrange_cats(lr->low->cats, lr->high->cats);
if (rc != SEPOL_OK) {
goto exit;
}
rc = __cil_verify_cats_associated_with_sens(lr->low->sens, lr->low->cats);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Low level sensitivity and categories are not associated\n");
goto exit;
}
rc = __cil_verify_cats_associated_with_sens(lr->high->sens, lr->high->cats);
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "High level sensitivity and categories are not associated\n");
goto exit;
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_verify_named_levelrange(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_levelrange *lr = node->data;
rc = __cil_verify_levelrange(db, lr);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid named range");
return rc;
}
static int __cil_verify_user_pre_eval(struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_user *user = node->data;
if (user->dftlevel == NULL) {
cil_log(CIL_ERR, "User %s does not have a default level\n", user->datum.name);
goto exit;
} else if (user->range == NULL) {
cil_log(CIL_ERR, "User %s does not have a level range\n", user->datum.name);
goto exit;
} else if (user->bounds != NULL) {
int steps = 0;
int limit = 2;
struct cil_user *u1 = user;
struct cil_user *u2 = user->bounds;
while (u2 != NULL) {
if (u1 == u2) {
cil_log(CIL_ERR, "Circular bounds found for user %s\n", u1->datum.name);
goto exit;
}
if (steps == limit) {
steps = 0;
limit *= 2;
u1 = u2;
}
u2 = u2->bounds;
steps++;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid user");
return rc;
}
static int __cil_verify_user_post_eval(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_user *user = node->data;
/* Verify user range only if anonymous */
if (user->range->datum.name == NULL) {
rc = __cil_verify_levelrange(db, user->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid user");
return rc;
}
static int __cil_verify_role(struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_role *role = node->data;
int steps = 0;
int limit = 2;
struct cil_role *r1 = role;
struct cil_role *r2 = role->bounds;
while (r2 != NULL) {
if (r1 == r2) {
cil_log(CIL_ERR, "Circular bounds found for role %s\n", r1->datum.name);
goto exit;
}
if (steps == limit) {
steps = 0;
limit *= 2;
r1 = r2;
}
r2 = r2->bounds;
steps++;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid role");
return rc;
}
static int __cil_verify_type(struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_type *type = node->data;
int steps = 0;
int limit = 2;
struct cil_type *t1 = type;
struct cil_type *t2 = type->bounds;
while (t2 != NULL) {
if (t1 == t2) {
cil_log(CIL_ERR, "Circular bounds found for type %s\n", t1->datum.name);
goto exit;
}
if (steps == limit) {
steps = 0;
limit *= 2;
t1 = t2;
}
t2 = t2->bounds;
steps++;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid type");
return rc;
}
static int __cil_verify_context(struct cil_db *db, struct cil_context *ctx)
{
int rc = SEPOL_ERR;
struct cil_user *user = ctx->user;
struct cil_role *role = ctx->role;
struct cil_type *type = ctx->type;
struct cil_level *user_low = user->range->low;
struct cil_level *user_high = user->range->high;
struct cil_level *ctx_low = ctx->range->low;
struct cil_level *ctx_high = ctx->range->high;
struct cil_list *sensitivityorder = db->sensitivityorder;
struct cil_list_item *curr;
int found = CIL_FALSE;
if (user->roles != NULL) {
if (!ebitmap_get_bit(user->roles, role->value)) {
cil_log(CIL_ERR, "Role %s is invalid for user %s\n", ctx->role_str, ctx->user_str);
rc = SEPOL_ERR;
goto exit;
}
} else {
cil_log(CIL_ERR, "No roles given to the user %s\n", ctx->user_str);
rc = SEPOL_ERR;
goto exit;
}
if (role->types != NULL) {
if (!ebitmap_get_bit(role->types, type->value)) {
cil_log(CIL_ERR, "Type %s is invalid for role %s\n", ctx->type_str, ctx->role_str);
rc = SEPOL_ERR;
goto exit;
}
} else {
cil_log(CIL_ERR, "No types associated with role %s\n", ctx->role_str);
rc = SEPOL_ERR;
goto exit;
}
/* Verify range only when anonymous */
if (ctx->range->datum.name == NULL) {
rc = __cil_verify_levelrange(db, ctx->range);
if (rc != SEPOL_OK) {
goto exit;
}
}
for (curr = sensitivityorder->head; curr != NULL; curr = curr->next) {
struct cil_sens *sens = curr->data;
if (found == CIL_FALSE) {
if (sens == user_low->sens) {
found = CIL_TRUE;
} else if (sens == ctx_low->sens) {
cil_log(CIL_ERR, "Range %s is invalid for user %s\n",
ctx->range_str, ctx->user_str);
rc = SEPOL_ERR;
goto exit;
}
}
if (found == CIL_TRUE) {
if (sens == ctx_high->sens) {
break;
} else if (sens == user_high->sens) {
cil_log(CIL_ERR, "Range %s is invalid for user %s\n",
ctx->range_str, ctx->user_str);
rc = SEPOL_ERR;
goto exit;
}
}
}
return SEPOL_OK;
exit:
cil_log(CIL_ERR, "Invalid context\n");
return rc;
}
static int __cil_verify_named_context(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_context *ctx = node->data;
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid named context");
return rc;
}
/*
static int __cil_verify_rule(struct cil_tree_node *node, struct cil_complex_symtab *symtab)
{
int rc = SEPOL_ERR;
struct cil_type_rule *typerule = NULL;
struct cil_roletransition *roletrans = NULL;
struct cil_complex_symtab_key ckey;
switch (node->flavor) {
case CIL_ROLETRANSITION: {
roletrans = node->data;
ckey.key1 = (intptr_t)roletrans->src;
ckey.key2 = (intptr_t)roletrans->tgt;
ckey.key3 = (intptr_t)roletrans->obj;
ckey.key4 = CIL_ROLETRANSITION;
break;
}
case CIL_TYPE_RULE: {
typerule = node->data;
ckey.key1 = (intptr_t)typerule->src;
ckey.key2 = (intptr_t)typerule->tgt;
ckey.key3 = (intptr_t)typerule->obj;
ckey.key4 = (intptr_t)typerule->rule_kind;
break;
}
default:
break;
}
rc = cil_complex_symtab_insert(symtab, &ckey, NULL);
if (rc == SEPOL_EEXIST) {
struct cil_complex_symtab_datum *datum = NULL;
cil_complex_symtab_search(symtab, &ckey, &datum);
if (datum == NULL) {
cil_tree_log(node, CIL_ERR, "Duplicate rule defined");
rc = SEPOL_ERR;
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid rule");
return rc;
}
*/
static int __cil_verify_booleanif_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, __attribute__((unused)) void *extra_args)
{
int rc = SEPOL_ERR;
struct cil_tree_node *rule_node = node;
struct cil_booleanif *bif = node->parent->parent->data;
switch (rule_node->flavor) {
case CIL_AVRULE:
case CIL_AVRULEX: {
struct cil_avrule *avrule = NULL;
avrule = rule_node->data;
if (avrule->rule_kind == CIL_AVRULE_NEVERALLOW) {
if (bif->preserved_tunable) {
cil_tree_log(node, CIL_ERR, "Neverallow found in tunableif block (treated as a booleanif due to preserve-tunables)");
} else {
cil_tree_log(node, CIL_ERR, "Neverallow found in booleanif block");
}
rc = SEPOL_ERR;
goto exit;
}
break;
}
case CIL_DENY_RULE:
if (bif->preserved_tunable) {
cil_tree_log(node, CIL_ERR, "Not allowed to have a deny rule in a tunableif block (treated as a booleanif due to preserve-tunables)");
} else {
cil_tree_log(node, CIL_ERR, "Not allowed to have deny rule in a booleanif block");
}
rc = SEPOL_ERR;
goto exit;
break;
case CIL_TYPE_RULE: /*
struct cil_type_rule *typerule = NULL;
struct cil_tree_node *temp_node = NULL;
struct cil_complex_symtab *symtab = extra_args;
struct cil_complex_symtab_key ckey;
struct cil_complex_symtab_datum datum;
typerule = rule_node->data;
ckey.key1 = (intptr_t)typerule->src;
ckey.key2 = (intptr_t)typerule->tgt;
ckey.key3 = (intptr_t)typerule->obj;
ckey.key4 = (intptr_t)typerule->rule_kind;
datum.data = node;
rc = cil_complex_symtab_insert(symtab, &ckey, &datum);
if (rc != SEPOL_OK) {
goto exit;
}
for (temp_node = rule_node->next;
temp_node != NULL;
temp_node = temp_node->next) {
if (temp_node->flavor == CIL_TYPE_RULE) {
typerule = temp_node->data;
if ((intptr_t)typerule->src == ckey.key1 &&
(intptr_t)typerule->tgt == ckey.key2 &&
(intptr_t)typerule->obj == ckey.key3 &&
(intptr_t)typerule->rule_kind == ckey.key4) {
cil_log(CIL_ERR, "Duplicate type rule found (line: %d)\n", node->line);
rc = SEPOL_ERR;
goto exit;
}
}
}
break;*/
//TODO Fix duplicate type_rule detection
break;
case CIL_CALL:
//Fall through to check content of call
break;
case CIL_TUNABLEIF:
//Fall through
break;
case CIL_NAMETYPETRANSITION:
/* While type transitions with file component are not allowed in
booleanif statements if they don't have "*" as the file. We
can't check that here. Or at least we won't right now. */
break;
default: {
const char * flavor = cil_node_to_string(node);
if (bif->preserved_tunable) {
cil_tree_log(node, CIL_ERR, "Invalid %s statement in tunableif (treated as a booleanif due to preserve-tunables)", flavor);
} else {
cil_tree_log(node, CIL_ERR, "Invalid %s statement in booleanif", flavor);
}
goto exit;
}
}
rc = SEPOL_OK;
exit:
return rc;
}
static int __cil_verify_booleanif(struct cil_tree_node *node, struct cil_complex_symtab *symtab)
{
int rc = SEPOL_ERR;
struct cil_booleanif *bif = (struct cil_booleanif*)node->data;
struct cil_tree_node *cond_block = node->cl_head;
while (cond_block != NULL) {
rc = cil_tree_walk(cond_block, __cil_verify_booleanif_helper, NULL, NULL, symtab);
if (rc != SEPOL_OK) {
goto exit;
}
cond_block = cond_block->next;
}
return SEPOL_OK;
exit:
if (bif->preserved_tunable) {
cil_tree_log(node, CIL_ERR, "Invalid tunableif (treated as a booleanif due to preserve-tunables)");
} else {
cil_tree_log(node, CIL_ERR, "Invalid booleanif");
}
return rc;
}
static int __cil_verify_netifcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_netifcon *netif = node->data;
struct cil_context *if_ctx = netif->if_context;
struct cil_context *pkt_ctx = netif->packet_context;
/* Verify only when anonymous */
if (if_ctx->datum.name == NULL) {
rc = __cil_verify_context(db, if_ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
/* Verify only when anonymous */
if (pkt_ctx->datum.name == NULL) {
rc = __cil_verify_context(db, pkt_ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid netifcon");
return rc;
}
static int __cil_verify_ibendportcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_ibendportcon *ib_end_port = node->data;
struct cil_context *ctx = ib_end_port->context;
/* Verify only when anonymous */
if (!ctx->datum.name) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid ibendportcon");
return rc;
}
static int __cil_verify_genfscon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_genfscon *genfs = node->data;
struct cil_context *ctx = genfs->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid genfscon");
return rc;
}
static int __cil_verify_filecon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_filecon *file = node->data;
struct cil_context *ctx = file->context;
if (ctx == NULL) {
rc = SEPOL_OK;
goto exit;
}
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Invalid filecon");
goto exit;
}
}
return SEPOL_OK;
exit:
return rc;
}
static int __cil_verify_nodecon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_nodecon *nodecon = node->data;
struct cil_context *ctx = nodecon->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid nodecon");
return rc;
}
static int __cil_verify_ibpkeycon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_ibpkeycon *pkey = node->data;
struct cil_context *ctx = pkey->context;
/* Verify only when anonymous */
if (!ctx->datum.name) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK)
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid ibpkeycon");
return rc;
}
static int __cil_verify_portcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_portcon *port = node->data;
struct cil_context *ctx = port->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid portcon");
return rc;
}
static int __cil_verify_pirqcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_pirqcon *pirq = node->data;
struct cil_context *ctx = pirq->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid pirqcon");
return rc;
}
static int __cil_verify_iomemcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_iomemcon *iomem = node->data;
struct cil_context *ctx = iomem->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid iomemcon");
return rc;
}
static int __cil_verify_ioportcon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_ioportcon *ioport = node->data;
struct cil_context *ctx = ioport->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid ioportcon");
return rc;
}
static int __cil_verify_pcidevicecon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_pcidevicecon *pcidev = node->data;
struct cil_context *ctx = pcidev->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid pcidevicecon");
return rc;
}
static int __cil_verify_devicetreecon(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_devicetreecon *dt = node->data;
struct cil_context *ctx = dt->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid devicetreecon");
return rc;
}
static int __cil_verify_fsuse(struct cil_db *db, struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_fsuse *fsuse = node->data;
struct cil_context *ctx = fsuse->context;
/* Verify only when anonymous */
if (ctx->datum.name == NULL) {
rc = __cil_verify_context(db, ctx);
if (rc != SEPOL_OK) {
goto exit;
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid fsuse");
return rc;
}
static int __cil_verify_permissionx(struct cil_permissionx *permx, struct cil_tree_node *node)
{
int rc;
struct cil_list *classes = NULL;
struct cil_list_item *item;
struct cil_class *class;
struct cil_symtab_datum *perm_datum;
char *kind_str;
switch (permx->kind) {
case CIL_PERMX_KIND_IOCTL:
kind_str = CIL_KEY_IOCTL;
break;
case CIL_PERMX_KIND_NLMSG:
kind_str = CIL_KEY_NLMSG;
break;
default:
cil_tree_log(node, CIL_ERR, "Invalid permissionx kind (%d)", permx->kind);
rc = SEPOL_ERR;
goto exit;
}
classes = cil_expand_class(permx->obj);
cil_list_for_each(item, classes) {
class = item->data;
rc = cil_symtab_get_datum(&class->perms, kind_str, &perm_datum);
if (rc == SEPOL_ENOENT) {
if (class->common != NULL) {
rc = cil_symtab_get_datum(&class->common->perms, kind_str, &perm_datum);
}
if (rc == SEPOL_ENOENT) {
cil_tree_log(node, CIL_ERR, "Invalid permissionx: %s is not a permission of class %s", kind_str, class->datum.name);
rc = SEPOL_ERR;
goto exit;
}
}
}
rc = SEPOL_OK;
exit:
if (classes != NULL) {
cil_list_destroy(&classes, CIL_FALSE);
}
return rc;
}
static int __cil_verify_avrulex(struct cil_tree_node *node)
{
struct cil_avrule *avrulex = node->data;
return __cil_verify_permissionx(avrulex->perms.x.permx, node);
}
static int __cil_verify_class(struct cil_tree_node *node)
{
int rc = SEPOL_ERR;
struct cil_class *class = node->data;
if (class->common != NULL) {
struct cil_class *common = class->common;
struct cil_tree_node *common_node = common->datum.nodes->head->data;
struct cil_tree_node *curr_com_perm = NULL;
for (curr_com_perm = common_node->cl_head;
curr_com_perm != NULL;
curr_com_perm = curr_com_perm->next) {
struct cil_perm *com_perm = curr_com_perm->data;
struct cil_tree_node *curr_class_perm = NULL;
for (curr_class_perm = node->cl_head;
curr_class_perm != NULL;
curr_class_perm = curr_class_perm->next) {
struct cil_perm *class_perm = curr_class_perm->data;
if (com_perm->datum.name == class_perm->datum.name) {
cil_log(CIL_ERR, "Duplicate permissions between %s common and class declarations\n", class_perm->datum.name);
goto exit;
}
}
}
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid class");
return rc;
}
static int __cil_verify_policycap(struct cil_tree_node *node)
{
int rc;
struct cil_policycap *polcap = node->data;
rc = sepol_polcap_getnum((const char*)polcap->datum.name);
if (rc == SEPOL_ERR) {
goto exit;
}
return SEPOL_OK;
exit:
cil_tree_log(node, CIL_ERR, "Invalid policycap (%s)", (const char*)polcap->datum.name);
return rc;
}
int __cil_verify_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
int rc = SEPOL_ERR;
int *avrule_cnt = 0;
int *handleunknown;
int *mls;
int *nseuserdflt = 0;
int *pass = 0;
struct cil_args_verify *args = extra_args;
struct cil_complex_symtab *csymtab = NULL;
struct cil_db *db = NULL;
if (node == NULL || extra_args == NULL) {
goto exit;
}
db = args->db;
avrule_cnt = args->avrule_cnt;
handleunknown = args->handleunknown;
mls = args->mls;
nseuserdflt = args->nseuserdflt;
csymtab = args->csymtab;
pass = args->pass;
if (node->flavor == CIL_MACRO) {
*finished = CIL_TREE_SKIP_HEAD;
rc = SEPOL_OK;
goto exit;
} else if (node->flavor == CIL_BLOCK) {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
rc = SEPOL_OK;
goto exit;
}
switch (*pass) {
case 0: {
switch (node->flavor) {
case CIL_USER:
rc = __cil_verify_user_post_eval(db, node);
break;
case CIL_SELINUXUSERDEFAULT:
(*nseuserdflt)++;
rc = SEPOL_OK;
break;
case CIL_ROLE:
rc = __cil_verify_role(node);
break;
case CIL_TYPE:
rc = __cil_verify_type(node);
break;
case CIL_AVRULE:
(*avrule_cnt)++;
rc = SEPOL_OK;
break;
case CIL_HANDLEUNKNOWN:
if (*handleunknown != -1) {
cil_log(CIL_ERR, "Policy can not have more than one handleunknown\n");
rc = SEPOL_ERR;
} else {
*handleunknown = ((struct cil_handleunknown*)node->data)->handle_unknown;
rc = SEPOL_OK;
}
break;
case CIL_MLS:
if (*mls != -1) {
cil_log(CIL_ERR, "Policy can not have more than one mls\n");
rc = SEPOL_ERR;
} else {
*mls = ((struct cil_mls*)node->data)->value;
rc = SEPOL_OK;
}
break;
case CIL_ROLETRANSITION:
rc = SEPOL_OK; //TODO __cil_verify_rule doesn't work quite right
//rc = __cil_verify_rule(node, csymtab);
break;
case CIL_TYPE_RULE:
rc = SEPOL_OK; //TODO __cil_verify_rule doesn't work quite right
//rc = __cil_verify_rule(node, csymtab);
break;
case CIL_BOOLEANIF:
rc = __cil_verify_booleanif(node, csymtab);
*finished = CIL_TREE_SKIP_HEAD;
break;
case CIL_LEVELRANGE:
rc = __cil_verify_named_levelrange(db, node);
break;
case CIL_CLASS:
rc = __cil_verify_class(node);
break;
case CIL_POLICYCAP:
rc = __cil_verify_policycap(node);
break;
default:
rc = SEPOL_OK;
break;
}
break;
}
case 1: {
switch (node->flavor) {
case CIL_CONTEXT:
rc = __cil_verify_named_context(db, node);
break;
case CIL_NETIFCON:
rc = __cil_verify_netifcon(db, node);
break;
case CIL_GENFSCON:
rc = __cil_verify_genfscon(db, node);
break;
case CIL_FILECON:
rc = __cil_verify_filecon(db, node);
break;
case CIL_NODECON:
rc = __cil_verify_nodecon(db, node);
break;
case CIL_IBPKEYCON:
rc = __cil_verify_ibpkeycon(db, node);
break;
case CIL_IBENDPORTCON:
rc = __cil_verify_ibendportcon(db, node);
break;
case CIL_PORTCON:
rc = __cil_verify_portcon(db, node);
break;
case CIL_PIRQCON:
rc = __cil_verify_pirqcon(db, node);
break;
case CIL_IOMEMCON:
rc = __cil_verify_iomemcon(db, node);
break;
case CIL_IOPORTCON:
rc = __cil_verify_ioportcon(db, node);
break;
case CIL_PCIDEVICECON:
rc = __cil_verify_pcidevicecon(db, node);
break;
case CIL_DEVICETREECON:
rc = __cil_verify_devicetreecon(db, node);
break;
case CIL_FSUSE:
rc = __cil_verify_fsuse(db, node);
break;
case CIL_AVRULEX:
rc = __cil_verify_avrulex(node);
break;
case CIL_PERMISSIONX:
rc = __cil_verify_permissionx(node->data, node);
break;
case CIL_RANGETRANSITION:
rc = SEPOL_OK;
break;
default:
rc = SEPOL_OK;
break;
}
break;
}
default:
rc = SEPOL_ERR;
}
exit:
return rc;
}
static int __add_perm_to_list(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_list *perm_list = (struct cil_list *)args;
cil_list_append(perm_list, CIL_DATUM, d);
return SEPOL_OK;
}
static int __cil_verify_classperms(struct cil_list *classperms, struct cil_symtab_datum *orig, struct cil_symtab_datum *cur, unsigned steps, unsigned limit);
static int __cil_verify_map_perm(struct cil_class *class, struct cil_perm *perm, struct cil_symtab_datum *orig, unsigned steps, unsigned limit)
{
int rc;
if (!perm->classperms) {
cil_tree_log(NODE(class), CIL_ERR, "No class permissions for map class %s, permission %s", DATUM(class)->name, DATUM(perm)->name);
goto exit;
}
rc = __cil_verify_classperms(perm->classperms, orig, &perm->datum, steps, limit);
if (rc != SEPOL_OK) {
cil_tree_log(NODE(class), CIL_ERR, "There was an error verifying class permissions for map class %s, permission %s", DATUM(class)->name, DATUM(perm)->name);
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_verify_perms(struct cil_class *class, struct cil_list *perms, struct cil_symtab_datum *orig, unsigned steps, unsigned limit)
{
int rc = SEPOL_ERR;
int count = 0;
struct cil_list_item *i = NULL;
if (!perms) {
cil_tree_log(NODE(class), CIL_ERR, "No permissions for class %s in class permissions", DATUM(class)->name);
goto exit;
}
cil_list_for_each(i, perms) {
count++;
if (i->flavor == CIL_LIST) {
rc = __cil_verify_perms(class, i->data, orig, steps, limit);
if (rc != SEPOL_OK) {
goto exit;
}
} else if (i->flavor == CIL_DATUM) {
struct cil_perm *perm = i->data;
if (FLAVOR(perm) == CIL_MAP_PERM) {
rc = __cil_verify_map_perm(class, perm, orig, steps, limit);
if (rc != SEPOL_OK) {
goto exit;
}
}
} else if (i->flavor == CIL_OP) {
enum cil_flavor op = (enum cil_flavor)(uintptr_t)i->data;
if (op == CIL_ALL) {
struct cil_list *perm_list;
struct cil_list_item *j = NULL;
int count2 = 0;
cil_list_init(&perm_list, CIL_MAP_PERM);
cil_symtab_map(&class->perms, __add_perm_to_list, perm_list);
if (class->common != NULL) {
cil_symtab_map(&class->common->perms, __add_perm_to_list, perm_list);
}
cil_list_for_each(j, perm_list) {
count2++;
struct cil_perm *perm = j->data;
if (FLAVOR(perm) == CIL_MAP_PERM) {
rc = __cil_verify_map_perm(class, perm, orig, steps, limit);
if (rc != SEPOL_OK) {
cil_list_destroy(&perm_list, CIL_FALSE);
goto exit;
}
}
}
cil_list_destroy(&perm_list, CIL_FALSE);
if (count2 == 0) {
cil_tree_log(NODE(class), CIL_ERR, "Operator \"all\" used for %s which has no permissions associated with it", DATUM(class)->name);
goto exit;
}
}
} else {
cil_tree_log(NODE(class), CIL_ERR, "Permission list for %s has an unexpected flavor: %d", DATUM(class)->name, i->flavor);
goto exit;
}
}
if (count == 0) {
cil_tree_log(NODE(class), CIL_ERR, "Empty permissions list for class %s in class permissions", DATUM(class)->name);
goto exit;
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_verify_classperms(struct cil_list *classperms, struct cil_symtab_datum *orig, struct cil_symtab_datum *cur, unsigned steps, unsigned limit)
{
int rc;
struct cil_list_item *i;
if (classperms == NULL) {
goto exit;
}
if (steps > 0 && orig == cur) {
cil_tree_log(NODE(cur), CIL_ERR, "Found circular class permissions involving %s", cur->name);
goto exit;
} else {
steps++;
if (steps > limit) {
steps = 1;
limit *= 2;
orig = cur;
}
}
cil_list_for_each(i, classperms) {
if (i->flavor == CIL_CLASSPERMS) {
struct cil_classperms *cp = i->data;
rc = __cil_verify_perms(cp->class, cp->perms, orig, steps, limit);
if (rc != SEPOL_OK) {
goto exit;
}
} else { /* SET */
struct cil_classperms_set *cp_set = i->data;
struct cil_classpermission *cp = cp_set->set;
if (!cp->classperms) {
cil_tree_log(NODE(cur), CIL_ERR, "Classpermission %s does not have a classpermissionset", DATUM(cp)->name);
}
rc = __cil_verify_classperms(cp->classperms, orig, &cp->datum, steps, limit);
if (rc != SEPOL_OK) {
goto exit;
}
}
}
return SEPOL_OK;
exit:
return SEPOL_ERR;
}
static int __cil_verify_classpermission(struct cil_tree_node *node)
{
int rc;
struct cil_classpermission *cp = node->data;
rc = __cil_verify_classperms(cp->classperms, &cp->datum, &cp->datum, 0, 2);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_ERR, "Error verifying class permissions for classpermission %s", DATUM(cp)->name);
}
return rc;
}
struct cil_verify_map_args {
struct cil_class *class;
struct cil_tree_node *node;
int rc;
};
static int __verify_map_perm_classperms(__attribute__((unused)) hashtab_key_t k, hashtab_datum_t d, void *args)
{
struct cil_verify_map_args *map_args = args;
struct cil_perm *cmp = (struct cil_perm *)d;
int rc;
rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &cmp->datum, 0, 2);
if (rc != SEPOL_OK) {
cil_tree_log(NODE(cmp), CIL_ERR, "Error verifying class permissions for map class %s, permission %s", DATUM(map_args->class)->name, DATUM(cmp)->name);
map_args->rc = rc;
}
return SEPOL_OK;
}
static int __cil_verify_map_class(struct cil_tree_node *node)
{
struct cil_class *mc = node->data;
struct cil_verify_map_args map_args;
map_args.class = mc;
map_args.node = node;
map_args.rc = SEPOL_OK;
cil_symtab_map(&mc->perms, __verify_map_perm_classperms, &map_args);
if (map_args.rc != SEPOL_OK) {
return SEPOL_ERR;
}
return SEPOL_OK;
}
int __cil_pre_verify_helper(struct cil_tree_node *node, uint32_t *finished, __attribute__((unused)) void *extra_args)
{
int rc = SEPOL_OK;
switch (node->flavor) {
case CIL_MACRO: {
*finished = CIL_TREE_SKIP_HEAD;
break;
}
case CIL_BLOCK: {
struct cil_block *blk = node->data;
if (blk->is_abstract == CIL_TRUE) {
*finished = CIL_TREE_SKIP_HEAD;
}
break;
}
case CIL_USER:
rc = __cil_verify_user_pre_eval(node);
break;
case CIL_MAP_CLASS:
rc = __cil_verify_map_class(node);
break;
case CIL_CLASSPERMISSION:
rc = __cil_verify_classpermission(node);
break;
case CIL_USERATTRIBUTE:
case CIL_ROLEATTRIBUTE:
case CIL_TYPEATTRIBUTE:
case CIL_CATSET: {
struct cil_stack *stack;
cil_stack_init(&stack);
rc = cil_verify_no_self_reference(node->flavor, node->data, stack);
cil_stack_destroy(&stack);
break;
}
default:
rc = SEPOL_OK;
break;
}
return rc;
}
libsepol-3.8.1/cil/src/cil_verify.h000066400000000000000000000067441476211737200172230ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_VERIFY_H_
#define CIL_VERIFY_H_
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_tree.h"
#include "cil_list.h"
enum cil_syntax {
CIL_SYN_STRING = 1 << 0,
CIL_SYN_LIST = 1 << 1,
CIL_SYN_EMPTY_LIST = 1 << 2,
CIL_SYN_N_LISTS = 1 << 3,
CIL_SYN_N_STRINGS = 1 << 4,
CIL_SYN_END = 1 << 5
};
struct cil_args_verify {
struct cil_db *db;
struct cil_complex_symtab *csymtab;
int *avrule_cnt;
int *handleunknown;
int *mls;
int *nseuserdflt;
int *pass;
};
int cil_verify_name(const struct cil_db *db, const char *name, enum cil_flavor flavor);
int __cil_verify_syntax(struct cil_tree_node *parse_current, enum cil_syntax s[], size_t len);
int cil_verify_expr_syntax(struct cil_tree_node *current, enum cil_flavor op, enum cil_flavor expr_flavor);
int cil_verify_constraint_leaf_expr_syntax(enum cil_flavor l_flavor, enum cil_flavor r_flavor, enum cil_flavor op, enum cil_flavor expr_flavor);
int cil_verify_constraint_expr_syntax(struct cil_tree_node *current, enum cil_flavor op);
int cil_verify_conditional_blocks(struct cil_tree_node *current);
int cil_verify_decl_does_not_shadow_macro_parameter(struct cil_macro *macro, struct cil_tree_node *node, const char *name);
int __cil_verify_ranges(struct cil_list *list);
int cil_verify_completed_ordered_list(struct cil_list *complete, struct cil_list *ordered_lists);
int __cil_verify_ordered_node_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args);
int __cil_verify_ordered(struct cil_tree_node *current, enum cil_flavor flavor);
int __cil_verify_initsids(struct cil_list *sids);
int __cil_verify_senscat(struct cil_sens *sens, struct cil_cat *cat);
int __cil_verify_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *extra_args);
int __cil_pre_verify_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *extra_args);
#endif
libsepol-3.8.1/cil/src/cil_write_ast.c000066400000000000000000001326251476211737200177110ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_list.h"
#include "cil_log.h"
#include "cil_symtab.h"
#include "cil_tree.h"
#include "cil_write_ast.h"
static inline const char *datum_or_str(struct cil_symtab_datum *datum, const char *str)
{
return datum && datum->fqn ? datum->fqn : str;
}
static inline const char *datum_to_str(struct cil_symtab_datum *datum)
{
return datum ? datum->fqn : "";
}
static void write_expr(FILE *out, struct cil_list *expr)
{
struct cil_list_item *curr;
int notfirst = 0;
fprintf(out, "(");
cil_list_for_each(curr, expr) {
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
switch (curr->flavor) {
case CIL_LIST:
write_expr(out, curr->data);
break;
case CIL_STRING:
fprintf(out, "%s", (char *)curr->data);
break;
case CIL_DATUM:
case CIL_TYPE:
case CIL_ROLE:
case CIL_USER:
case CIL_SENS:
case CIL_CAT:
case CIL_BOOL:
case CIL_CLASS:
case CIL_MAP_CLASS:
case CIL_DECLARED_STRING:
fprintf(out, "%s", datum_to_str(curr->data));
break;
case CIL_OP: {
const char *op_str;
enum cil_flavor op_flavor = (enum cil_flavor)(uintptr_t)curr->data;
switch (op_flavor) {
case CIL_AND:
op_str = CIL_KEY_AND;
break;
case CIL_OR:
op_str = CIL_KEY_OR;
break;
case CIL_NOT:
op_str = CIL_KEY_NOT;
break;
case CIL_ALL:
op_str = CIL_KEY_ALL;
break;
case CIL_EQ:
op_str = CIL_KEY_EQ;
break;
case CIL_NEQ:
op_str = CIL_KEY_NEQ;
break;
case CIL_XOR:
op_str = CIL_KEY_XOR;
break;
case CIL_RANGE:
op_str = CIL_KEY_RANGE;
break;
case CIL_CONS_DOM:
op_str = CIL_KEY_CONS_DOM;
break;
case CIL_CONS_DOMBY:
op_str = CIL_KEY_CONS_DOMBY;
break;
case CIL_CONS_INCOMP:
op_str = CIL_KEY_CONS_INCOMP;
break;
default:
op_str = "";
break;
}
fprintf(out, "%s", op_str);
break;
}
case CIL_CONS_OPERAND: {
const char *operand_str;
enum cil_flavor operand_flavor = (enum cil_flavor)(uintptr_t)curr->data;
switch (operand_flavor) {
case CIL_CONS_U1:
operand_str = CIL_KEY_CONS_U1;
break;
case CIL_CONS_U2:
operand_str = CIL_KEY_CONS_U2;
break;
case CIL_CONS_U3:
operand_str = CIL_KEY_CONS_U3;
break;
case CIL_CONS_T1:
operand_str = CIL_KEY_CONS_T1;
break;
case CIL_CONS_T2:
operand_str = CIL_KEY_CONS_T2;
break;
case CIL_CONS_T3:
operand_str = CIL_KEY_CONS_T3;
break;
case CIL_CONS_R1:
operand_str = CIL_KEY_CONS_R1;
break;
case CIL_CONS_R2:
operand_str = CIL_KEY_CONS_R2;
break;
case CIL_CONS_R3:
operand_str = CIL_KEY_CONS_R3;
break;
case CIL_CONS_L1:
operand_str = CIL_KEY_CONS_L1;
break;
case CIL_CONS_L2:
operand_str = CIL_KEY_CONS_L2;
break;
case CIL_CONS_H1:
operand_str = CIL_KEY_CONS_H1;
break;
case CIL_CONS_H2:
operand_str = CIL_KEY_CONS_H2;
break;
default:
operand_str = "";
break;
}
fprintf(out, "%s", operand_str);
break;
}
default:
fprintf(out, "");
break;
}
}
fprintf(out, ")");
}
static void write_node_list(FILE *out, struct cil_tree_node *current)
{
int notfirst = 0;
fprintf(out, "(");
while (current) {
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
fprintf(out, "%s", datum_to_str(current->data));
current = current->next;
}
fprintf(out, ")");
}
static void write_string_list(FILE *out, struct cil_list *list)
{
struct cil_list_item *curr;
int notfirst = 0;
if (!list) {
fprintf(out, "()");
return;
}
fprintf(out, "(");
cil_list_for_each(curr, list) {
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
fprintf(out, "%s", (char*)curr->data);
}
fprintf(out, ")");
}
static void write_datum_list(FILE *out, struct cil_list *list)
{
struct cil_list_item *curr;
int notfirst = 0;
if (!list) {
fprintf(out, "()");
return;
}
fprintf(out, "(");
cil_list_for_each(curr, list) {
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
fprintf(out, "%s", datum_to_str(curr->data));
}
fprintf(out, ")");
}
static void write_classperms(FILE *out, struct cil_classperms *cp)
{
if (!cp) {
fprintf(out, "()");
return;
}
fprintf(out, "(%s ", datum_or_str(DATUM(cp->class), cp->class_str));
if (cp->perms)
write_expr(out, cp->perms);
else
write_expr(out, cp->perm_strs);
fprintf(out, ")");
}
static void write_classperms_list(FILE *out, struct cil_list *cp_list)
{
struct cil_list_item *curr;
int notfirst = 0;
int num = 0;
if (!cp_list) {
fprintf(out, "()");
return;
}
cil_list_for_each(curr, cp_list) {
num++;
}
if (num > 1)
fprintf(out, "(");
cil_list_for_each(curr, cp_list) {
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
if (curr->flavor == CIL_CLASSPERMS) {
write_classperms(out, curr->data);
} else {
struct cil_classperms_set *cp_set = curr->data;
struct cil_classpermission *cp = cp_set->set;
if (cp) {
if (cp->datum.name)
fprintf(out, "%s", datum_to_str(DATUM(cp)));
else
write_classperms_list(out,cp->classperms);
} else {
fprintf(out, "%s", cp_set->set_str);
}
}
}
if (num > 1)
fprintf(out, ")");
}
static void write_permx(FILE *out, struct cil_permissionx *permx)
{
if (permx->datum.name) {
fprintf(out, "%s", datum_to_str(DATUM(permx)));
} else {
fprintf(out, "(");
if (permx->kind == CIL_PERMX_KIND_IOCTL) {
fprintf(out, "ioctl ");
} else if (permx->kind == CIL_PERMX_KIND_NLMSG) {
fprintf(out, "nlmsg ");
} else {
fprintf(out, " ");
}
fprintf(out, "%s ", datum_or_str(DATUM(permx->obj), permx->obj_str));
write_expr(out, permx->expr_str);
fprintf(out, ")");
}
}
static void write_cats(FILE *out, struct cil_cats *cats)
{
if (cats->datum_expr) {
write_expr(out, cats->datum_expr);
} else {
write_expr(out, cats->str_expr);
}
}
static void write_level(FILE *out, struct cil_level *level, int print_name)
{
if (print_name && level->datum.name) {
fprintf(out, "%s", datum_to_str(DATUM(level)));
} else {
fprintf(out, "(");
fprintf(out, "%s", datum_or_str(DATUM(level->sens), level->sens_str));
if (level->cats) {
fprintf(out, " ");
write_cats(out, level->cats);
}
fprintf(out, ")");
}
}
static void write_range(FILE *out, struct cil_levelrange *range, int print_name)
{
if (print_name && range->datum.name) {
fprintf(out, "%s", datum_to_str(DATUM(range)));
} else {
fprintf(out, "(");
if (range->low)
write_level(out, range->low, CIL_TRUE);
else
fprintf(out, "%s", range->low_str);
fprintf(out, " ");
if (range->high)
write_level(out, range->high, CIL_TRUE);
else
fprintf(out, "%s", range->high_str);
fprintf(out, ")");
}
}
static void write_context(FILE *out, struct cil_context *context, int print_name)
{
if (print_name && context->datum.name) {
fprintf(out, "%s", datum_to_str(DATUM(context)));
} else {
fprintf(out, "(");
fprintf(out, "%s ", datum_or_str(DATUM(context->user), context->user_str));
fprintf(out, "%s ", datum_or_str(DATUM(context->role), context->role_str));
fprintf(out, "%s ", datum_or_str(DATUM(context->type), context->type_str));
if (context->range)
write_range(out, context->range, CIL_TRUE);
else
fprintf(out, "%s", context->range_str);
fprintf(out, ")");
}
}
static void write_ipaddr(FILE *out, struct cil_ipaddr *ipaddr)
{
if (ipaddr->datum.name) {
fprintf(out, "%s", datum_to_str(DATUM(ipaddr)));
} else {
char buf[256];
if (inet_ntop(ipaddr->family, &ipaddr->ip, buf, 256) == NULL)
strcpy(buf, "");
fprintf(out, "(%s)", buf);
}
}
static void write_constrain(FILE *out, struct cil_constrain *cons)
{
write_classperms_list(out, cons->classperms);
fprintf(out, " ");
if (cons->datum_expr)
write_expr(out, cons->datum_expr);
else
write_expr(out, cons->str_expr);
}
static void write_call_args(FILE *out, struct cil_list *args)
{
struct cil_list_item *item;
int notfirst = 0;
fprintf(out, "(");
cil_list_for_each(item, args) {
struct cil_args* arg = item->data;
enum cil_flavor arg_flavor = arg->flavor;
if (notfirst)
fprintf(out, " ");
else
notfirst = 1;
switch (arg_flavor) {
case CIL_TYPE:
case CIL_ROLE:
case CIL_USER:
case CIL_SENS:
case CIL_CAT:
case CIL_BOOL:
case CIL_CLASS:
case CIL_MAP_CLASS: {
fprintf(out, "%s", datum_or_str(DATUM(arg->arg), arg->arg_str));
break;
}
case CIL_DECLARED_STRING: {
if (arg->arg) {
fprintf(out, "\"%s\" ", DATUM(arg->arg)->fqn);
} else {
fprintf(out, "%s ", arg->arg_str);
}
break;
}
case CIL_CATSET: {
if (arg->arg) {
struct cil_catset *catset = (struct cil_catset *)arg->arg;
write_cats(out, catset->cats);
} else {
fprintf(out, "%s", arg->arg_str);
}
break;
}
case CIL_LEVEL: {
if (arg->arg) {
struct cil_level *level = (struct cil_level *)arg->arg;
write_level(out, level, CIL_TRUE);
} else {
fprintf(out, "%s", arg->arg_str);
}
break;
}
case CIL_LEVELRANGE: {
if (arg->arg) {
struct cil_levelrange *range = (struct cil_levelrange *)arg->arg;
write_range(out, range, CIL_TRUE);
} else {
fprintf(out, "%s", arg->arg_str);
}
break;
}
case CIL_IPADDR: {
if (arg->arg) {
struct cil_ipaddr *addr = (struct cil_ipaddr *)arg->arg;
write_ipaddr(out, addr);
} else {
fprintf(out, "%s", arg->arg_str);
}
break;
}
case CIL_CLASSPERMISSION: {
if (arg->arg) {
struct cil_classpermission *cp = (struct cil_classpermission *)arg->arg;
if (cp->datum.name)
fprintf(out, "%s", datum_to_str(DATUM(cp)));
else
write_classperms_list(out, cp->classperms);
} else {
fprintf(out, "%s", arg->arg_str);
}
break;
}
default:
fprintf(out, "", datum_or_str(DATUM(arg->arg), arg->arg_str));
break;
}
}
fprintf(out, ")");
}
static void write_call_args_tree(FILE *out, struct cil_tree_node *arg_node)
{
while (arg_node) {
if (arg_node->data) {
fprintf(out, "%s", (char *)arg_node->data);
} else if (arg_node->cl_head) {
fprintf(out, "(");
write_call_args_tree(out, arg_node->cl_head);
fprintf(out, ")");
}
if (arg_node->next)
fprintf(out, " ");
arg_node = arg_node->next;
}
}
static const char *macro_param_flavor_to_string(enum cil_flavor flavor)
{
const char *str;
switch(flavor) {
case CIL_TYPE:
str = CIL_KEY_TYPE;
break;
case CIL_ROLE:
str = CIL_KEY_ROLE;
break;
case CIL_USER:
str = CIL_KEY_USER;
break;
case CIL_SENS:
str = CIL_KEY_SENSITIVITY;
break;
case CIL_CAT:
str = CIL_KEY_CATEGORY;
break;
case CIL_CATSET:
str = CIL_KEY_CATSET;
break;
case CIL_LEVEL:
str = CIL_KEY_LEVEL;
break;
case CIL_LEVELRANGE:
str = CIL_KEY_LEVELRANGE;
break;
case CIL_CLASS:
str = CIL_KEY_CLASS;
break;
case CIL_IPADDR:
str = CIL_KEY_IPADDR;
break;
case CIL_MAP_CLASS:
str = CIL_KEY_MAP_CLASS;
break;
case CIL_CLASSPERMISSION:
str = CIL_KEY_CLASSPERMISSION;
break;
case CIL_BOOL:
str = CIL_KEY_BOOL;
break;
case CIL_DECLARED_STRING:
str = CIL_KEY_STRING;
break;
default:
str = "";
break;
}
return str;
}
static void cil_write_src_info_node(FILE *out, struct cil_tree_node *node)
{
struct cil_src_info *info = node->data;
if (info->kind == CIL_KEY_SRC_CIL || info->kind == CIL_KEY_SRC_HLL_LMS) {
fprintf(out, ";;* lms %u %s\n", info->hll_line, info->path);
} else if (info->kind == CIL_KEY_SRC_HLL_LMX) {
fprintf(out, ";;* lmx %u %s\n", info->hll_line, info->path);
} else {
fprintf(out, ";;* %u %s\n", info->hll_line, info->path);
}
}
void cil_write_ast_node(FILE *out, struct cil_tree_node *node)
{
if (!node->data) {
return;
}
switch(node->flavor) {
case CIL_NODE: {
fprintf(out, "%s\n", (char *)node->data);
break;
}
case CIL_BLOCK: {
struct cil_block *block = node->data;
fprintf(out, "(block %s", datum_to_str(DATUM(block)));
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_BLOCKINHERIT: {
struct cil_blockinherit *inherit = node->data;
fprintf(out, "(blockinherit %s)\n", datum_or_str(DATUM(inherit->block), inherit->block_str));
break;
}
case CIL_IN: {
struct cil_in *in = node->data;
fprintf(out, "(in %s", datum_or_str(DATUM(in->block), in->block_str));
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_OPTIONAL: {
struct cil_optional *optional = node->data;
fprintf(out, "(optional %s", datum_to_str(DATUM(optional)));
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_BOOLEANIF: {
struct cil_booleanif *bif = node->data;
fprintf(out, "(booleanif ");
if (bif->datum_expr)
write_expr(out, bif->datum_expr);
else
write_expr(out, bif->str_expr);
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_TUNABLEIF: {
struct cil_tunableif *tif = node->data;
fprintf(out, "(tunableif ");
if (tif->datum_expr)
write_expr(out, tif->datum_expr);
else
write_expr(out, tif->str_expr);
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_CONDBLOCK: {
struct cil_condblock *cb = node->data;
fprintf(out, "(%s", cb->flavor == CIL_CONDTRUE ? "true" : "false");
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_MACRO: {
struct cil_macro *macro = node->data;
struct cil_list_item *curr;
fprintf(out, "(macro %s (", datum_to_str(DATUM(macro)));
if (macro->params) {
cil_list_for_each(curr, macro->params) {
struct cil_param *param = curr->data;
fprintf(out, "(%s %s)", macro_param_flavor_to_string(param->flavor), param->str);
}
}
fprintf(out, ")");
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_CALL: {
struct cil_call *call = node->data;
fprintf(out, "(call %s", datum_or_str(DATUM(call->macro), call->macro_str));
if (call->args) {
fprintf(out, " ");
write_call_args(out, call->args);
} else if (call->args_tree) {
fprintf(out, " ");
write_call_args_tree(out, call->args_tree->root);
}
if (!node->cl_head)
fprintf(out, ")");
fprintf(out, "\n");
break;
}
case CIL_BLOCKABSTRACT: {
struct cil_blockabstract *abstract = node->data;
fprintf(out, "(blockabstract %s)\n", datum_or_str(DATUM(abstract->block), abstract->block_str));
break;
}
case CIL_MLS: {
struct cil_mls *mls = node->data;
fprintf(out, "(mls %s)\n", mls->value ? "true" : "false");
break;
}
case CIL_HANDLEUNKNOWN: {
struct cil_handleunknown *unknown = node->data;
fprintf(out, "(handleunknown ");
if (unknown->handle_unknown == SEPOL_ALLOW_UNKNOWN)
fprintf(out, "%s", CIL_KEY_HANDLEUNKNOWN_ALLOW);
else if (unknown->handle_unknown == SEPOL_DENY_UNKNOWN)
fprintf(out, "%s", CIL_KEY_HANDLEUNKNOWN_DENY);
else if (unknown->handle_unknown == SEPOL_REJECT_UNKNOWN)
fprintf(out, "%s", CIL_KEY_HANDLEUNKNOWN_REJECT);
else
fprintf(out, "");
fprintf(out, ")\n");
break;
}
case CIL_DEFAULTUSER: {
struct cil_default *def = node->data;
fprintf(out, "(defaultuser ");
if (def->class_datums)
write_datum_list(out, def->class_datums);
else
write_string_list(out, def->class_strs);
if (def->object == CIL_DEFAULT_SOURCE)
fprintf(out, " source");
else if (def->object == CIL_DEFAULT_TARGET)
fprintf(out, " target");
else
fprintf(out, " ");
fprintf(out, ")\n");
break;
}
case CIL_DEFAULTROLE: {
struct cil_default *def = node->data;
fprintf(out, "(defaultrole ");
if (def->class_datums)
write_datum_list(out, def->class_datums);
else
write_string_list(out, def->class_strs);
if (def->object == CIL_DEFAULT_SOURCE)
fprintf(out, " source");
else if (def->object == CIL_DEFAULT_TARGET)
fprintf(out, " target");
else
fprintf(out, " ");
fprintf(out, ")\n");
break;
}
case CIL_DEFAULTTYPE: {
struct cil_default *def = node->data;
fprintf(out, "(defaulttype ");
if (def->class_datums)
write_datum_list(out, def->class_datums);
else
write_string_list(out, def->class_strs);
if (def->object == CIL_DEFAULT_SOURCE)
fprintf(out, " source");
else if (def->object == CIL_DEFAULT_TARGET)
fprintf(out, " target");
else
fprintf(out, " ");
fprintf(out, ")\n");
break;
}
case CIL_DEFAULTRANGE: {
struct cil_defaultrange *def = node->data;
fprintf(out, "(defaultrange ");
if (def->class_datums)
write_datum_list(out, def->class_datums);
else
write_string_list(out, def->class_strs);
if (def->object_range == CIL_DEFAULT_SOURCE_LOW)
fprintf(out, " source low");
else if (def->object_range == CIL_DEFAULT_SOURCE_HIGH)
fprintf(out, " source high");
else if (def->object_range == CIL_DEFAULT_SOURCE_LOW_HIGH)
fprintf(out, " source low-high");
else if (def->object_range == CIL_DEFAULT_TARGET_LOW)
fprintf(out, " target low");
else if (def->object_range == CIL_DEFAULT_TARGET_HIGH)
fprintf(out, " target high");
else if (def->object_range == CIL_DEFAULT_TARGET_LOW_HIGH)
fprintf(out, " target low-high");
else
fprintf(out, " ");
fprintf(out, ")\n");
break;
}
case CIL_CLASS: {
struct cil_class *class = node->data;
fprintf(out, "(class %s ", datum_to_str(DATUM(class)));
write_node_list(out, node->cl_head);
fprintf(out, ")\n");
break;
}
case CIL_CLASSORDER: {
struct cil_ordered *ordered = node->data;
fprintf(out, "(classorder ");
if (ordered->datums) {
write_datum_list(out, ordered->datums);
} else {
write_string_list(out, ordered->strs);
}
fprintf(out, ")\n");
break;
}
case CIL_COMMON: {
struct cil_class *common = node->data;
fprintf(out, "(common %s ", datum_to_str(DATUM(common)));
write_node_list(out, node->cl_head);
fprintf(out, ")\n");
break;
}
case CIL_CLASSCOMMON: {
struct cil_classcommon *cc = node->data;
fprintf(out, "(classcommon %s ", datum_or_str(DATUM(cc->class), cc->class_str));
fprintf(out, "%s", datum_or_str(DATUM(cc->common), cc->common_str));
fprintf(out, ")\n");
break;
}
case CIL_CLASSPERMISSION: {
struct cil_classpermission *cp = node->data;
fprintf(out, "(classpermission %s)\n", datum_to_str(DATUM(cp)));
break;
}
case CIL_CLASSPERMISSIONSET: {
struct cil_classpermissionset *cps = node->data;
fprintf(out, "(classpermissionset %s ", datum_or_str(DATUM(cps->set), cps->set_str));
write_classperms_list(out, cps->classperms);
fprintf(out, ")\n");
break;
}
case CIL_MAP_CLASS: {
struct cil_class *map = node->data;
fprintf(out, "(classmap %s ", datum_to_str(DATUM(map)));
write_node_list(out, node->cl_head);
fprintf(out, ")\n");
break;
}
case CIL_CLASSMAPPING: {
struct cil_classmapping *mapping = node->data;
fprintf(out, "(classmapping %s ", datum_or_str(DATUM(mapping->map_class), mapping->map_class_str));
fprintf(out, "%s ", datum_or_str(DATUM(mapping->map_perm), mapping->map_perm_str));
write_classperms_list(out, mapping->classperms);
fprintf(out, ")\n");
break;
}
case CIL_PERMISSIONX: {
struct cil_permissionx *permx = node->data;
fprintf(out, "(permissionx %s (", datum_to_str(DATUM(permx)));
if (permx->kind == CIL_PERMX_KIND_IOCTL) {
fprintf(out, "ioctl ");
} else if (permx->kind == CIL_PERMX_KIND_NLMSG) {
fprintf(out, "nlmsg ");
} else {
fprintf(out, " ");
}
fprintf(out, "%s ", datum_or_str(DATUM(permx->obj), permx->obj_str));
write_expr(out, permx->expr_str);
fprintf(out, "))\n");
break;
}
case CIL_SID: {
struct cil_sid *sid = node->data;
fprintf(out, "(sid %s)\n", datum_to_str(DATUM(sid)));
break;
}
case CIL_SIDCONTEXT: {
struct cil_sidcontext *sidcon = node->data;
fprintf(out, "(sidcontext %s ", datum_or_str(DATUM(sidcon->sid), sidcon->sid_str));
if (sidcon->context)
write_context(out, sidcon->context, CIL_TRUE);
else
fprintf(out, "%s", sidcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_SIDORDER: {
struct cil_ordered *ordered = node->data;
fprintf(out, "(sidorder ");
if (ordered->datums) {
write_datum_list(out, ordered->datums);
} else {
write_string_list(out, ordered->strs);
}
fprintf(out, ")\n");
break;
}
case CIL_BOOL: {
struct cil_bool *boolean = node->data;
fprintf(out, "(boolean %s %s)\n", datum_to_str(DATUM(boolean)), boolean->value ? "true" : "false");
break;
}
case CIL_TUNABLE: {
struct cil_tunable *tunable = node->data;
fprintf(out, "(tunable %s %s)\n", datum_to_str(DATUM(tunable)), tunable->value ? "true" : "false");
break;
}
case CIL_SENS: {
struct cil_sens *sens = node->data;
fprintf(out, "(sensitivity %s)\n", datum_to_str(DATUM(sens)));
break;
}
case CIL_SENSALIAS: {
struct cil_alias *alias = node->data;
fprintf(out, "(sensitivityalias %s)\n", datum_to_str(DATUM(alias)));
break;
}
case CIL_SENSALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
fprintf(out, "(sensitivityaliasactual %s ", datum_or_str(DATUM(aliasactual->alias), aliasactual->alias_str));
fprintf(out, "%s", datum_or_str(DATUM(aliasactual->actual), aliasactual->actual_str));
fprintf(out, ")\n");
break;
}
case CIL_CAT: {
struct cil_cat *cat = node->data;
fprintf(out, "(category %s)\n", datum_to_str(DATUM(cat)));
break;
}
case CIL_CATALIAS: {
struct cil_alias *alias = node->data;
fprintf(out, "(categoryalias %s)\n", datum_to_str(DATUM(alias)));
break;
}
case CIL_CATALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
fprintf(out, "(categoryaliasactual %s ", datum_or_str(DATUM(aliasactual->alias), aliasactual->alias_str));
fprintf(out, "%s", datum_or_str(DATUM(aliasactual->actual), aliasactual->actual_str));
fprintf(out, ")\n");
break;
}
case CIL_CATSET: {
struct cil_catset *catset = node->data;
fprintf(out, "(categoryset %s ", datum_to_str(DATUM(catset)));
write_cats(out, catset->cats);
fprintf(out, ")\n");
break;
}
case CIL_CATORDER: {
struct cil_ordered *ordered = node->data;
fprintf(out, "(categoryorder ");
if (ordered->datums) {
write_datum_list(out, ordered->datums);
} else {
write_string_list(out, ordered->strs);
}
fprintf(out, ")\n");
break;
}
case CIL_SENSCAT: {
struct cil_senscat *senscat = node->data;
fprintf(out, "(sensitivitycategory ");
fprintf(out, "%s ", datum_or_str(DATUM(senscat->sens), senscat->sens_str));
write_cats(out, senscat->cats);
fprintf(out, ")\n");
break;
}
case CIL_SENSITIVITYORDER: {
struct cil_ordered *ordered = node->data;
fprintf(out, "(sensitivityorder ");
if (ordered->datums) {
write_datum_list(out, ordered->datums);
} else {
write_string_list(out, ordered->strs);
}
fprintf(out, ")\n");
break;
}
case CIL_LEVEL: {
struct cil_level *level = node->data;
fprintf(out, "(level %s ", datum_to_str(&level->datum));
write_level(out, level, CIL_FALSE);
fprintf(out, ")\n");
break;
}
case CIL_LEVELRANGE: {
struct cil_levelrange *lvlrange = node->data;
fprintf(out, "(levelrange %s ", datum_to_str(DATUM(lvlrange)));
write_range(out, lvlrange, CIL_FALSE);
fprintf(out, ")\n");
break;
}
case CIL_USER: {
struct cil_user *user = node->data;
fprintf(out, "(user %s)\n", datum_to_str(DATUM(user)));
break;
}
case CIL_USERATTRIBUTE: {
struct cil_userattribute *attr = node->data;
fprintf(out, "(userattribute %s)\n", datum_to_str(DATUM(attr)));
break;
}
case CIL_USERATTRIBUTESET: {
struct cil_userattributeset *attr = node->data;
fprintf(out, "(userattributeset %s ", datum_or_str(DATUM(attr->attr), attr->attr_str));
if (attr->datum_expr)
write_expr(out, attr->datum_expr);
else
write_expr(out, attr->str_expr);
fprintf(out, ")\n");
break;
}
case CIL_USERROLE: {
struct cil_userrole *userrole = node->data;
fprintf(out, "(userrole ");
fprintf(out, "%s ", datum_or_str(DATUM(userrole->user), userrole->user_str));
fprintf(out, "%s", datum_or_str(DATUM(userrole->role), userrole->role_str));
fprintf(out, ")\n");
break;
}
case CIL_USERLEVEL: {
struct cil_userlevel *userlevel = node->data;
fprintf(out, "(userlevel %s ", datum_or_str(DATUM(userlevel->user), userlevel->user_str));
if (userlevel->level)
write_level(out, userlevel->level, CIL_TRUE);
else
fprintf(out, "%s", userlevel->level_str);
fprintf(out, ")\n");
break;
}
case CIL_USERRANGE: {
struct cil_userrange *userrange = node->data;
fprintf(out, "(userrange %s ", datum_or_str(DATUM(userrange->user), userrange->user_str));
if (userrange->range)
write_range(out, userrange->range, CIL_TRUE);
else
fprintf(out, "%s", userrange->range_str);
fprintf(out, ")\n");
break;
}
case CIL_USERBOUNDS: {
struct cil_bounds *bounds = node->data;
fprintf(out, "(userbounds ");
fprintf(out, "%s ", datum_or_str(DATUM(bounds->parent), bounds->parent_str));
fprintf(out, "%s)\n", datum_or_str(DATUM(bounds->child), bounds->child_str));
break;
}
case CIL_USERPREFIX: {
struct cil_userprefix *prefix = node->data;
fprintf(out, "(userprefix ");
fprintf(out, "%s ", datum_or_str(DATUM(prefix->user), prefix->user_str));
fprintf(out, "%s)\n", prefix->prefix_str);
break;
}
case CIL_SELINUXUSER: {
struct cil_selinuxuser *selinuxuser = node->data;
fprintf(out, "(selinuxuser %s ", selinuxuser->name_str);
fprintf(out, "%s ", datum_or_str(DATUM(selinuxuser->user), selinuxuser->user_str));
if (selinuxuser->range)
write_range(out, selinuxuser->range, CIL_TRUE);
else
fprintf(out, "%s", selinuxuser->range_str);
fprintf(out, ")\n");
break;
}
case CIL_SELINUXUSERDEFAULT: {
struct cil_selinuxuser *selinuxuser = node->data;
fprintf(out, "(selinuxuserdefault ");
fprintf(out, "%s ", datum_or_str(DATUM(selinuxuser->user), selinuxuser->user_str));
if (selinuxuser->range)
write_range(out, selinuxuser->range, CIL_TRUE);
else
fprintf(out, "%s", selinuxuser->range_str);
fprintf(out, ")\n");
break;
}
case CIL_ROLE: {
fprintf(out, "(role %s)\n", datum_to_str(node->data));
break;
}
case CIL_ROLEATTRIBUTE: {
fprintf(out, "(roleattribute %s)\n", datum_to_str(node->data));
break;
}
case CIL_ROLEATTRIBUTESET: {
struct cil_roleattributeset *attr = node->data;
fprintf(out, "(roleattributeset %s ", datum_or_str(DATUM(attr->attr), attr->attr_str));
if (attr->datum_expr)
write_expr(out, attr->datum_expr);
else
write_expr(out, attr->str_expr);
fprintf(out, ")\n");
break;
}
case CIL_ROLETYPE: {
struct cil_roletype *roletype = node->data;
fprintf(out, "(roletype ");
fprintf(out, "%s ", datum_or_str(DATUM(roletype->role), roletype->role_str));
fprintf(out, "%s", datum_or_str(DATUM(roletype->type), roletype->type_str));
fprintf(out, ")\n");
break;
}
case CIL_ROLEBOUNDS: {
struct cil_bounds *bounds = node->data;
fprintf(out, "(rolebounds ");
fprintf(out, "%s ", datum_or_str(DATUM(bounds->parent), bounds->parent_str));
fprintf(out, "%s)\n", datum_or_str(DATUM(bounds->child), bounds->child_str));
break;
}
case CIL_TYPE: {
fprintf(out, "(type %s)\n", datum_to_str(node->data));
break;
}
case CIL_TYPEALIAS: {
fprintf(out, "(typealias %s)\n", datum_to_str(node->data));
break;
}
case CIL_TYPEALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
fprintf(out, "(typealiasactual %s ", datum_or_str(DATUM(aliasactual->alias), aliasactual->alias_str));
fprintf(out, "%s", datum_or_str(DATUM(aliasactual->actual), aliasactual->actual_str));
fprintf(out, ")\n");
break;
}
case CIL_TYPEATTRIBUTE: {
fprintf(out, "(typeattribute %s)\n", datum_to_str(node->data));
break;
}
case CIL_TYPEATTRIBUTESET: {
struct cil_typeattributeset *attr = node->data;
fprintf(out, "(typeattributeset %s ", datum_or_str(DATUM(attr->attr), attr->attr_str));
if (attr->datum_expr)
write_expr(out, attr->datum_expr);
else
write_expr(out, attr->str_expr);
fprintf(out, ")\n");
break;
}
case CIL_EXPANDTYPEATTRIBUTE: {
struct cil_expandtypeattribute *attr = node->data;
fprintf(out, "(expandtypeattribute ");
if (attr->attr_datums)
write_expr(out, attr->attr_datums);
else
write_expr(out, attr->attr_strs);
fprintf(out, " %s)\n", attr->expand ? "true" : "false");
break;
}
case CIL_TYPEPERMISSIVE: {
struct cil_typepermissive *tp = node->data;
fprintf(out, "(typepermissive ");
fprintf(out, "%s", datum_or_str(DATUM(tp->type), tp->type_str));
fprintf(out, ")\n");
break;
}
case CIL_TYPEBOUNDS: {
struct cil_bounds *bounds = node->data;
fprintf(out, "(typebounds ");
fprintf(out, "%s ", datum_or_str(DATUM(bounds->parent), bounds->parent_str));
fprintf(out, "%s)\n", datum_or_str(DATUM(bounds->child), bounds->child_str));
break;
}
case CIL_ROLEALLOW: {
struct cil_roleallow *roleallow = node->data;
fprintf(out, "(roleallow ");
fprintf(out, "%s ", datum_or_str(DATUM(roleallow->src), roleallow->src_str));
fprintf(out, "%s", datum_or_str(DATUM(roleallow->tgt), roleallow->tgt_str));
fprintf(out, ")\n");
break;
}
case CIL_ROLETRANSITION: {
struct cil_roletransition *roletrans = node->data;
fprintf(out, "(roletransition ");
fprintf(out, "%s ", datum_or_str(DATUM(roletrans->src), roletrans->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(roletrans->tgt), roletrans->tgt_str));
fprintf(out, "%s ", datum_or_str(DATUM(roletrans->obj), roletrans->obj_str));
fprintf(out, "%s", datum_or_str(DATUM(roletrans->result), roletrans->result_str));
fprintf(out, ")\n");
break;
}
case CIL_AVRULE: {
struct cil_avrule *rule = node->data;
if (rule->rule_kind == AVRULE_ALLOWED)
fprintf(out, "(allow ");
else if (rule->rule_kind == AVRULE_AUDITALLOW)
fprintf(out, "(auditallow ");
else if (rule->rule_kind == AVRULE_DONTAUDIT)
fprintf(out, "(dontaudit ");
else if (rule->rule_kind == AVRULE_NEVERALLOW)
fprintf(out, "(neverallow ");
else
fprintf(out, "( ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
write_classperms_list(out, rule->perms.classperms);
fprintf(out, ")\n");
break;
}
case CIL_AVRULEX: {
struct cil_avrule *rule = node->data;
if (rule->rule_kind == AVRULE_ALLOWED)
fprintf(out, "(allowx ");
else if (rule->rule_kind == AVRULE_AUDITALLOW)
fprintf(out, "(auditallowx ");
else if (rule->rule_kind == AVRULE_DONTAUDIT)
fprintf(out, "(dontauditx ");
else if (rule->rule_kind == AVRULE_NEVERALLOW)
fprintf(out, "(neverallowx ");
else
fprintf(out, "( ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
if (rule->perms.x.permx_str) {
fprintf(out, "%s",rule->perms.x.permx_str);
} else {
write_permx(out, rule->perms.x.permx);
}
fprintf(out, ")\n");
break;
}
case CIL_DENY_RULE: {
struct cil_deny_rule *rule = node->data;
fprintf(out, "(deny ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
write_classperms_list(out, rule->classperms);
fprintf(out, ")\n");
break;
}
case CIL_TYPE_RULE: {
struct cil_type_rule *rule = node->data;
if (rule->rule_kind == AVRULE_TRANSITION)
fprintf(out, "(typetransition ");
else if (rule->rule_kind == AVRULE_MEMBER)
fprintf(out, "(typemember ");
else if (rule->rule_kind == AVRULE_CHANGE)
fprintf(out, "(typechange ");
else
fprintf(out, "( ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->obj), rule->obj_str));
fprintf(out, "%s", datum_or_str(DATUM(rule->result), rule->result_str));
fprintf(out, ")\n");
break;
}
case CIL_NAMETYPETRANSITION: {
struct cil_nametypetransition *rule = node->data;
fprintf(out, "(typetransition ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->obj), rule->obj_str));
if (rule->name) {
fprintf(out, "\"%s\" ", DATUM(rule->name)->fqn);
} else {
fprintf(out, "%s ", rule->name_str);
}
fprintf(out, "%s", datum_or_str(DATUM(rule->result), rule->result_str));
fprintf(out, ")\n");
break;
}
case CIL_RANGETRANSITION: {
struct cil_rangetransition *rule = node->data;
fprintf(out, "(rangetransition ");
fprintf(out, "%s ", datum_or_str(DATUM(rule->src), rule->src_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->exec), rule->exec_str));
fprintf(out, "%s ", datum_or_str(DATUM(rule->obj), rule->obj_str));
if (rule->range)
write_range(out, rule->range, CIL_TRUE);
else
fprintf(out, "%s", rule->range_str);
fprintf(out, ")\n");
break;
}
case CIL_CONSTRAIN: {
struct cil_constrain *cons = node->data;
fprintf(out, "(constrain ");
write_constrain(out, cons);
fprintf(out, ")\n");
break;
}
case CIL_MLSCONSTRAIN: {
struct cil_constrain *cons = node->data;
fprintf(out, "(mlsconstrain ");
write_constrain(out, cons);
fprintf(out, ")\n");
break;
}
case CIL_VALIDATETRANS: {
struct cil_validatetrans *vt = node->data;
fprintf(out, "(validatetrans ");
fprintf(out, "%s ", datum_or_str(DATUM(vt->class), vt->class_str));
if (vt->datum_expr)
write_expr(out, vt->datum_expr);
else
write_expr(out, vt->str_expr);
fprintf(out, ")\n");
break;
}
case CIL_MLSVALIDATETRANS: {
struct cil_validatetrans *vt = node->data;
fprintf(out, "(mlsvalidatetrans ");
fprintf(out, "%s ", datum_or_str(DATUM(vt->class), vt->class_str));
if (vt->datum_expr)
write_expr(out, vt->datum_expr);
else
write_expr(out, vt->str_expr);
fprintf(out, ")\n");
break;
}
case CIL_CONTEXT: {
struct cil_context *context = node->data;
fprintf(out, "(context %s ", datum_to_str(DATUM(context)));
write_context(out, context, CIL_FALSE);
fprintf(out, ")\n");
break;
}
case CIL_FILECON: {
struct cil_filecon *filecon = node->data;
fprintf(out, "(filecon ");
if (filecon->path) {
fprintf(out, "\"%s\" ", DATUM(filecon->path)->fqn);
} else {
fprintf(out, "%s ", filecon->path_str);
}
switch (filecon->type) {
case CIL_FILECON_ANY:
fprintf(out, "%s ", CIL_KEY_ANY);
break;
case CIL_FILECON_FILE:
fprintf(out, "%s ", CIL_KEY_FILE);
break;
case CIL_FILECON_DIR:
fprintf(out, "%s ", CIL_KEY_DIR);
break;
case CIL_FILECON_CHAR:
fprintf(out, "%s ", CIL_KEY_CHAR);
break;
case CIL_FILECON_BLOCK:
fprintf(out, "%s ", CIL_KEY_BLOCK);
break;
case CIL_FILECON_SOCKET:
fprintf(out, "%s ", CIL_KEY_SOCKET);
break;
case CIL_FILECON_PIPE:
fprintf(out, "%s ", CIL_KEY_PIPE);
break;
case CIL_FILECON_SYMLINK:
fprintf(out, "%s ", CIL_KEY_SYMLINK);
break;
default:
fprintf(out, " ");
}
if (filecon->context)
write_context(out, filecon->context, CIL_TRUE);
else if (filecon->context_str)
fprintf(out, "%s", filecon->context_str);
else
fprintf(out, "()");
fprintf(out, ")\n");
break;
}
case CIL_IBPKEYCON: {
struct cil_ibpkeycon *ibpkeycon = node->data;
fprintf(out, "(ibpkeycon %s ", ibpkeycon->subnet_prefix_str);
fprintf(out, "(%d %d) ", ibpkeycon->pkey_low, ibpkeycon->pkey_high);
if (ibpkeycon->context)
write_context(out, ibpkeycon->context, CIL_TRUE);
else if (ibpkeycon->context_str)
fprintf(out, "%s", ibpkeycon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_PORTCON: {
struct cil_portcon *portcon = node->data;
fprintf(out, "(portcon ");
if (portcon->proto == CIL_PROTOCOL_UDP)
fprintf(out, " udp ");
else if (portcon->proto == CIL_PROTOCOL_TCP)
fprintf(out, " tcp ");
else if (portcon->proto == CIL_PROTOCOL_DCCP)
fprintf(out, "dccp ");
else if (portcon->proto == CIL_PROTOCOL_SCTP)
fprintf(out, "sctp ");
else
fprintf(out, " ");
if (portcon->port_low == portcon->port_high)
fprintf(out, "%d ", portcon->port_low);
else
fprintf(out, "(%d %d) ", portcon->port_low, portcon->port_high);
if (portcon->context)
write_context(out, portcon->context, CIL_TRUE);
else
fprintf(out, "%s", portcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_NODECON: {
struct cil_nodecon *nodecon = node->data;
fprintf(out, "(nodecon ");
if (nodecon->addr)
write_ipaddr(out, nodecon->addr);
else
fprintf(out, "%s ", nodecon->addr_str);
fprintf(out, " ");
if (nodecon->mask)
write_ipaddr(out, nodecon->mask);
else
fprintf(out, "%s ", nodecon->mask_str);
fprintf(out, " ");
if (nodecon->context)
write_context(out, nodecon->context, CIL_TRUE);
else
fprintf(out, "%s", nodecon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_GENFSCON: {
struct cil_genfscon *genfscon = node->data;
fprintf(out, "(genfscon ");
fprintf(out, "%s \"%s\" ", genfscon->fs_str, genfscon->path_str);
if (genfscon->file_type != CIL_FILECON_ANY) {
switch (genfscon->file_type) {
case CIL_FILECON_FILE:
fprintf(out, "%s ", CIL_KEY_FILE);
break;
case CIL_FILECON_DIR:
fprintf(out, "%s ", CIL_KEY_DIR);
break;
case CIL_FILECON_CHAR:
fprintf(out, "%s ", CIL_KEY_CHAR);
break;
case CIL_FILECON_BLOCK:
fprintf(out, "%s ", CIL_KEY_BLOCK);
break;
case CIL_FILECON_SOCKET:
fprintf(out, "%s ", CIL_KEY_SOCKET);
break;
case CIL_FILECON_PIPE:
fprintf(out, "%s ", CIL_KEY_PIPE);
break;
case CIL_FILECON_SYMLINK:
fprintf(out, "%s ", CIL_KEY_SYMLINK);
break;
default:
fprintf(out, " ");
}
}
if (genfscon->context)
write_context(out, genfscon->context, CIL_TRUE);
else
fprintf(out, "%s", genfscon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_NETIFCON: {
struct cil_netifcon *netifcon = node->data;
fprintf(out, "(netifcon %s ", netifcon->interface_str);
if (netifcon->if_context)
write_context(out, netifcon->if_context, CIL_TRUE);
else
fprintf(out, "%s", netifcon->if_context_str);
fprintf(out, " ");
if (netifcon->packet_context)
write_context(out, netifcon->packet_context, CIL_TRUE);
else
fprintf(out, "%s", netifcon->packet_context_str);
fprintf(out, ")\n");
break;
}
case CIL_IBENDPORTCON: {
struct cil_ibendportcon *ibendportcon = node->data;
fprintf(out, "(ibendportcon %s %u ", ibendportcon->dev_name_str, ibendportcon->port);
if (ibendportcon->context)
write_context(out, ibendportcon->context, CIL_TRUE);
else
fprintf(out, "%s", ibendportcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_PIRQCON: {
struct cil_pirqcon *pirqcon = node->data;
fprintf(out, "(pirqcon %d ", pirqcon->pirq);
if (pirqcon->context)
write_context(out, pirqcon->context, CIL_TRUE);
else
fprintf(out, "%s", pirqcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_IOMEMCON: {
struct cil_iomemcon *iomemcon = node->data;
fprintf(out, "(iomemcon (%"PRId64" %"PRId64") ", iomemcon->iomem_low, iomemcon->iomem_high);
if (iomemcon->context)
write_context(out, iomemcon->context, CIL_TRUE);
else
fprintf(out, "%s", iomemcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_IOPORTCON: {
struct cil_ioportcon *ioportcon = node->data;
fprintf(out, "(ioportcon ");
if (ioportcon->ioport_low == ioportcon->ioport_high)
fprintf(out, "%d ", ioportcon->ioport_low);
else
fprintf(out, "(%d %d) ", ioportcon->ioport_low, ioportcon->ioport_high);
if (ioportcon->context)
write_context(out, ioportcon->context, CIL_TRUE);
else
fprintf(out, "%s", ioportcon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_PCIDEVICECON: {
struct cil_pcidevicecon *pcidevicecon = node->data;
fprintf(out, "(pcidevicecon %d ", pcidevicecon->dev);
if (pcidevicecon->context)
write_context(out, pcidevicecon->context, CIL_TRUE);
else
fprintf(out, "%s", pcidevicecon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_DEVICETREECON: {
struct cil_devicetreecon *devicetreecon = node->data;
fprintf(out, "(devicetreecon \"%s\" ", devicetreecon->path);
if (devicetreecon->context)
write_context(out, devicetreecon->context, CIL_TRUE);
else
fprintf(out, "%s", devicetreecon->context_str);
fprintf(out, ")\n");
break;
}
case CIL_FSUSE: {
struct cil_fsuse *fsuse = node->data;
fprintf(out, "(fsuse ");
if (fsuse->type == CIL_FSUSE_XATTR)
fprintf(out, "xattr ");
else if (fsuse->type == CIL_FSUSE_TASK)
fprintf(out, "task ");
else if (fsuse->type == CIL_FSUSE_TRANS)
fprintf(out, "trans ");
else
fprintf(out, " ");
fprintf(out, "%s ", fsuse->fs_str);
if (fsuse->context)
write_context(out, fsuse->context, CIL_TRUE);
else
fprintf(out, "%s", fsuse->context_str);
fprintf(out, ")\n");
break;
}
case CIL_POLICYCAP: {
struct cil_policycap *polcap = node->data;
fprintf(out, "(policycap %s)\n", polcap->datum.name);
break;
}
case CIL_IPADDR: {
struct cil_ipaddr *ipaddr = node->data;
char buf[256];
if (inet_ntop(ipaddr->family, &ipaddr->ip, buf, 256) == NULL)
strcpy(buf, "");
fprintf(out, "(ipaddr %s %s)\n", datum_to_str(&ipaddr->datum), buf);
break;
}
default :
fprintf(out, "()\n", cil_node_to_string(node));
break;
}
}
/*
* Tree walk data and helper functions for writing the AST of the various phases
*/
struct cil_write_ast_args {
FILE *out;
int depth;
};
/*
* Helper functions for writing the parse AST
*/
static int __write_parse_ast_node_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
fprintf(args->out, "%*s", args->depth*4, "");
if (!node->data) {
if (node->cl_head)
fprintf(args->out, "(\n");
else
fprintf(args->out, "()\n");
} else {
char *str = (char *)node->data;
size_t len = strlen(str);
size_t i;
for (i = 0; i < len; i++) {
if (isspace(str[i])) {
fprintf(args->out, "\"%s\"\n", str);
return SEPOL_OK;
}
}
fprintf(args->out, "%s\n", (char *)node->data);
}
return SEPOL_OK;
}
static int __write_parse_ast_first_child_helper(struct cil_tree_node *node, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
struct cil_tree_node *parent = node->parent;
if (parent->flavor != CIL_ROOT) {
args->depth++;
}
return SEPOL_OK;
}
static int __write_parse_ast_last_child_helper(struct cil_tree_node *node, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
struct cil_tree_node *parent = node->parent;
if (parent->flavor == CIL_ROOT) {
return SEPOL_OK;
}
args->depth--;
fprintf(args->out, "%*s", args->depth*4, "");
fprintf(args->out, ")\n");
return SEPOL_OK;
}
/*
* Helper functions for writing the CIL AST for the build and resolve phases
*/
static int __write_cil_ast_node_helper(struct cil_tree_node *node, uint32_t *finished, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
if (node->flavor == CIL_SRC_INFO) {
cil_write_src_info_node(args->out, node);
return SEPOL_OK;
}
fprintf(args->out, "%*s", args->depth*4, "");
cil_write_ast_node(args->out, node);
if (node->flavor == CIL_CLASS || node->flavor == CIL_COMMON || node->flavor == CIL_MAP_CLASS) {
*finished = CIL_TREE_SKIP_HEAD;
}
return SEPOL_OK;
}
static int __write_cil_ast_first_child_helper(struct cil_tree_node *node, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
struct cil_tree_node *parent = node->parent;
if (parent->flavor != CIL_SRC_INFO && parent->flavor != CIL_ROOT) {
args->depth++;
}
return SEPOL_OK;
}
static int __write_cil_ast_last_child_helper(struct cil_tree_node *node, void *extra_args)
{
struct cil_write_ast_args *args = extra_args;
struct cil_tree_node *parent = node->parent;
if (parent->flavor == CIL_ROOT) {
return SEPOL_OK;
} else if (parent->flavor == CIL_SRC_INFO) {
fprintf(args->out, ";;* lme\n");
return SEPOL_OK;
}
args->depth--;
fprintf(args->out, "%*s", args->depth*4, "");
fprintf(args->out, ")\n");
return SEPOL_OK;
}
int cil_write_ast(FILE *out, enum cil_write_ast_phase phase, struct cil_tree_node *node)
{
struct cil_write_ast_args extra_args;
int rc;
extra_args.out = out;
extra_args.depth = 0;
if (phase == CIL_WRITE_AST_PHASE_PARSE) {
rc = cil_tree_walk(node, __write_parse_ast_node_helper, __write_parse_ast_first_child_helper, __write_parse_ast_last_child_helper, &extra_args);
} else {
rc = cil_tree_walk(node, __write_cil_ast_node_helper, __write_cil_ast_first_child_helper, __write_cil_ast_last_child_helper, &extra_args);
}
if (rc != SEPOL_OK) {
cil_log(CIL_ERR, "Failed to write AST\n");
return SEPOL_ERR;
}
return SEPOL_OK;
}
libsepol-3.8.1/cil/src/cil_write_ast.h000066400000000000000000000037621476211737200177150ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CIL_WRITE_AST_H_
#define CIL_WRITE_AST_H_
#include
#include "cil_tree.h"
enum cil_write_ast_phase {
CIL_WRITE_AST_PHASE_PARSE = 0,
CIL_WRITE_AST_PHASE_BUILD,
CIL_WRITE_AST_PHASE_RESOLVE,
CIL_WRITE_AST_PHASE_POST,
};
void cil_write_ast_node(FILE *out, struct cil_tree_node *node);
int cil_write_ast(FILE *out, enum cil_write_ast_phase phase, struct cil_tree_node *node);
#endif /* CIL_WRITE_AST_H_ */
libsepol-3.8.1/cil/test/000077500000000000000000000000001476211737200150745ustar00rootroot00000000000000libsepol-3.8.1/cil/test/integration_testing/000077500000000000000000000000001476211737200211545ustar00rootroot00000000000000libsepol-3.8.1/cil/test/integration_testing/mls_policy.cil000066400000000000000000000047111476211737200240220ustar00rootroot00000000000000(class testing (read open close write exec))
(class fooclass (read open close write exec))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(categoryalias c0 cat)
(categoryorder (c0 c1 c2 c3 c4))
(categoryset catset (c0 c2 c3))
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivityalias s3 sens)
(dominance (s0 s1 s2 s3))
(sensitivitycategory s0 (c0 c2 c3))
(sensitivitycategory s0 (cat))
; the following causes a segfault
;(sensitivitycategory sens (c2))
(type foo_t)
(type typea_t)
(type typeb_t)
(type typec_t)
(role foo_r)
(role rolea_r)
(role roleb_r)
(user foo_u)
(user user_u)
(userrole foo_u foo_r)
(level low (s0 catset))
(level high (s0 (c0)))
(level test_l (s0 (cat)))
(sid test_sid)
(sidcontext test_sid (foo_u foo_r foo_t (s0 (c0)) (s0 (c0))))
(sid test_sid_anon_l)
(sidcontext test_sid_anon_l (foo_u foo_r foo_t low high))
(context con (foo_u foo_r foo_t low high))
(context con_anon_l (foo_u foo_r foo_t (s0 (c0)) high))
(fsuse xattr ext3 con)
(fsuse xattr ext3 con_anon_l)
(netifcon eth0 con con_anon_l)
(ipaddr ip_v4 192.25.35.200)
(ipaddr netmask 192.168.1.1)
(ipaddr ip_v6 2001:0DB8:AC10:FE01::)
(ipaddr netmask_v6 2001:0DE0:DA88:2222::)
; will need anon levels
(nodecon ip_v4 netmask con)
(nodecon ip_v6 netmask_v6 con_anon_l)
;needs anon levels
(portcon type 25 con)
(filecon root path file con)
(genfscon type path con)
(netifcon eth0 con con_anon_l)
(typemember typea_t typeb_t testing typec_t)
(typechange typea_t typeb_t testing typec_t)
(typetransition typea_t typeb_t testing typec_t)
(permissionset permset (open close))
(allow typea_t typeb_t testing (write))
(allow typea_t typeb_t testing permset)
(roleallow rolea_r roleb_r)
(rolebounds rolea_r roleb_r)
(roletransition foo_r foo_t testing rolea_r)
(level l2 (s0 (c0)))
(level h2 (s0 (c0)))
(mlsconstrain (fooclass testing)(open close)(eq l2 h2))
(common fooclass (open))
(classcommon fooclass fooclass)
(rangetransition typea_t typeb_t fooclass low high)
(nametypetransition string typea_t typeb_t fooclass foo_t)
(typepermissive foo_t)
(typebounds typea_t typeb_t)
(block test_b
(typealias .test_b.test typea_t)
(type test))
(attribute attrs)
(attributetypes attrs (foo_t))
(roletype foo_r foo_t)
(userbounds user_u foo_u)
(userrole user_u foo_r)
(bool foo_b true)
(bool baz_b false)
(booleanif (&& foo_b baz_b)
(allow typea_t typeb_t fooclass(read)))
;(class baz (read))
;(booleanif (&& foo_b baz_b)
; (allow foo_b baz_b fooclass (read)))
libsepol-3.8.1/cil/test/integration_testing/nonmls.cil000066400000000000000000000032761476211737200231630ustar00rootroot00000000000000(class testing (read open close write exec))
(class fooclass (read open close write exec))
(type foo_t)
(type typea_t)
(type typeb_t)
(type typec_t)
(role foo_r)
(role rolea_r)
(role roleb_r)
(user foo_u)
(user user_u)
(userrole foo_u foo_r)
(sid test_sid)
;(sidcontext test_sid (foo_u foo_r foo_t (s0 (c0)) (s0 (c0))))
;(sid test_sid_anon_l)
;(fsuse xattr ext3 con)
;(fsuse xattr ext3 con_anon_l)
;(netifcon eth0 con con_anon_l)
(ipaddr ip_v4 192.25.35.200)
(ipaddr netmask 192.168.1.1)
(ipaddr ip_v6 2001:0DB8:AC10:FE01::)
(ipaddr netmask_v6 2001:0DE0:DA88:2222::)
; will need anon levels
;(nodecon ip_v4 netmask con)
;(nodecon ip_v6 netmask_v6 con_anon_l)
;needs anon levels
;(portcon type 25 con)
;(filecon root path file con)
;(genfscon type path con)
;(netifcon eth0 con con_anon_l)
(typemember typea_t typeb_t testing typec_t)
(typechange typea_t typeb_t testing typec_t)
(typetransition typea_t typeb_t testing typec_t)
(permissionset permset (open close))
(allow typea_t typeb_t testing (write))
(allow typea_t typeb_t testing permset)
(roleallow rolea_r roleb_r)
(rolebounds rolea_r roleb_r)
(roletransition foo_r foo_t testing rolea_r)
(common fooclass (open))
(classcommon fooclass fooclass)
(nametypetransition string typea_t typeb_t fooclass foo_t)
(typepermissive foo_t)
(typebounds typea_t typeb_t)
(block test_b
(typealias .test_b.test typea_t)
(type test))
(attribute attrs)
(attributetypes attrs (foo_t))
(roletype foo_r foo_t)
(userbounds user_u foo_u)
(userrole user_u foo_r)
;(bool foo_b true)
;(bool baz_b false)
;(booleanif (&& foo_b baz_b)
; (allow typea_t typeb_t fooclass(read)))
;(class baz (read))
;(booleanif (&& foo_b baz_b)
; (allow foo_b baz_b fooclass (read)))
libsepol-3.8.1/cil/test/integration_testing/nonmls.conf000066400000000000000000000013701476211737200233320ustar00rootroot00000000000000
class testing
class fooclass
sid test_sid
#end
#sid decl
sid security
class testing
{
read
open
close
write
exec
}
class fooclass
{
read
open
close
write
exec
}
#end
#attribs
attribute attrs;
#end
type foo_t, attrs;
type typea_t;
type typeb_t;
type typec_t;
#end
bool foo_b true;
bool baz_b false;
#end
role foo_r types foo_t;
role rolea_r;
role roleb_r;
#end
#role decl
allow typea_t typeb_t : testing write;
allow typea_t typeb_t : testing {open close};
type_transition typea_t typeb_t : testing typec_t;
#end
#audit rules
#dontaudit {kernel} unknown : dir search;
allow rolea_r roleb_r;
#end
#rbac stuff
#allow system {guest local_user};
#allow local_user guest;
user foo_u roles foo_r;
#end
sid test_sid foo_u:foo_r:foo_t
libsepol-3.8.1/cil/test/integration_testing/ordered_lists_bad1.cil000066400000000000000000000013051476211737200253750ustar00rootroot00000000000000; Minimum policy
; ****************************
(class foo (read))
(type bar)
(allow bar self (foo (read)))
; ****************************
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivity s4)
(sensitivity s5)
(sensitivity s6)
(sensitivity s7)
(sensitivity s8)
(sensitivity s9)
(dominance (s2 s3 s4))
(dominance (s1 s2 s4 s5))
(dominance (s5 s6 s8))
(dominance (s6 s7 s8 s9))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(category c5)
(category c6)
(category c7)
(category c8)
(category c9)
(categoryorder (c1 c3))
(categoryorder (c1 c2 c3))
(categoryorder (c5 c6 c7))
(categoryorder (c3 c4 c5))
(categoryorder (c7 c8 c9))
(categoryorder (c0 c1))
libsepol-3.8.1/cil/test/integration_testing/ordered_lists_bad2.cil000066400000000000000000000013021476211737200253730ustar00rootroot00000000000000; Minimum policy
; ****************************
(class foo (read))
(type bar)
(allow bar self (foo (read)))
; ****************************
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivity s4)
(sensitivity s5)
(sensitivity s6)
(sensitivity s7)
(sensitivity s8)
(sensitivity s9)
(dominance (s2 s3 s4))
(dominance (s1 s2 s4 s5))
(dominance (s5 s6 s8))
(dominance (s6 s7 s8 s9))
(dominance (s0 s1))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(category c5)
(category c6)
(category c7)
(category c8)
(category c9)
(categoryorder (c1 c3))
(categoryorder (c1 c2 c3))
(categoryorder (c5 c6 c7))
(categoryorder (c3 c4 c5))
(categoryorder (c7 c8 c9))
libsepol-3.8.1/cil/test/integration_testing/ordered_lists_bad3.cil000066400000000000000000000013261476211737200254020ustar00rootroot00000000000000; Minimum policy
; ****************************
(class foo (read))
(type bar)
(allow bar self (foo (read)))
; ****************************
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivity s4)
(sensitivity s5)
(sensitivity s6)
(sensitivity s7)
(sensitivity s8)
(sensitivity s9)
(dominance (s2 s3 s4))
(dominance (s1 s2 s5))
(dominance (s5 s6 s8))
(dominance (s6 s7 s8 s9))
(dominance (s0 s1))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(category c5)
(category c6)
(category c7)
(category c8)
(category c9)
(categoryorder (c1 c3))
(categoryorder (c1 c2 c3))
(categoryorder (c5 c6 c7))
(categoryorder (c3 c4 c5))
(categoryorder (c7 c8 c9))
(categoryorder (c0 c1))
libsepol-3.8.1/cil/test/integration_testing/ordered_lists_easy.cil000066400000000000000000000011461476211737200255320ustar00rootroot00000000000000; Minimum policy
; ****************************
(class foo (read))
(type bar)
(allow bar self (foo (read)))
; ****************************
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivity s4)
(sensitivity s5)
(sensitivity s6)
(sensitivity s7)
(sensitivity s8)
(sensitivity s9)
(dominance (s0 s1 s2 s3 s4 s5 s6 s7 s8 s9))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(category c5)
(category c6)
(category c7)
(category c8)
(category c9)
(categoryorder (c2 c3 c4 c5))
(categoryorder (c0 c1 c2 c3))
(categoryorder (c5 c6 c7))
(categoryorder (c7 c8 c9))
libsepol-3.8.1/cil/test/integration_testing/ordered_lists_hard.cil000066400000000000000000000013311476211737200255030ustar00rootroot00000000000000; Minimum policy
; ****************************
(class foo (read))
(type bar)
(allow bar self (foo (read)))
; ****************************
(sensitivity s0)
(sensitivity s1)
(sensitivity s2)
(sensitivity s3)
(sensitivity s4)
(sensitivity s5)
(sensitivity s6)
(sensitivity s7)
(sensitivity s8)
(sensitivity s9)
(dominance (s2 s3 s4))
(dominance (s1 s2 s4 s5))
(dominance (s5 s6 s8))
(dominance (s6 s7 s8 s9))
(dominance (s0 s1))
(category c0)
(category c1)
(category c2)
(category c3)
(category c4)
(category c5)
(category c6)
(category c7)
(category c8)
(category c9)
(categoryorder (c1 c3))
(categoryorder (c1 c2 c3))
(categoryorder (c5 c6 c7))
(categoryorder (c3 c4 c5))
(categoryorder (c7 c8 c9))
(categoryorder (c0 c1))
libsepol-3.8.1/cil/test/integration_testing/small.cil000066400000000000000000000000761476211737200227600ustar00rootroot00000000000000(class foo (read))
(type bar)
(allow bar self (foo (read)))
libsepol-3.8.1/cil/test/unit/000077500000000000000000000000001476211737200160535ustar00rootroot00000000000000libsepol-3.8.1/cil/test/unit/AllTests.c000066400000000000000000000055731476211737200177640ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "../../src/cil_log.h"
CuSuite* CilTreeGetSuite(void);
CuSuite* CilTreeGetResolveSuite(void);
CuSuite* CilTreeGetBuildSuite(void);
CuSuite* CilTestFullCil(void);
void RunAllTests(void) {
/* disable cil log output */
cil_set_log_level(0);
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
CuSuite* suiteResolve = CuSuiteNew();
CuSuite* suiteBuild = CuSuiteNew();
CuSuite* suiteIntegration = CuSuiteNew();
CuSuiteAddSuite(suite, CilTreeGetSuite());
CuSuiteAddSuite(suiteResolve, CilTreeGetResolveSuite());
CuSuiteAddSuite(suiteBuild, CilTreeGetBuildSuite());
CuSuiteAddSuite(suiteIntegration, CilTestFullCil());
CuSuiteRun(suite);
CuSuiteDetails(suite, output);
CuSuiteSummary(suite, output);
CuSuiteRun(suiteResolve);
CuSuiteDetails(suiteResolve, output);
CuSuiteSummary(suiteResolve, output);
CuSuiteRun(suiteBuild);
CuSuiteDetails(suiteBuild, output);
CuSuiteSummary(suiteBuild, output);
CuSuiteRun(suiteIntegration);
CuSuiteDetails(suiteIntegration, output);
CuSuiteSummary(suiteIntegration, output);
printf("\n%s\n", output->buffer);
}
int main(__attribute__((unused)) int argc, __attribute__((unused)) char *argv[]) {
RunAllTests();
return 0;
}
libsepol-3.8.1/cil/test/unit/CilTest.c000066400000000000000000003150531476211737200175750ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include
#include
#include
#include
#include
#include "CuTest.h"
#include "CilTest.h"
#include "../../src/cil_internal.h"
#include "test_cil.h"
#include "test_cil_tree.h"
#include "test_cil_list.h"
#include "test_cil_symtab.h"
#include "test_cil_parser.h"
#include "test_cil_lexer.h"
#include "test_cil_build_ast.h"
#include "test_cil_resolve_ast.h"
#include "test_cil_fqn.h"
#include "test_cil_copy_ast.h"
#include "test_cil_post.h"
#include "test_integration.h"
void set_cil_file_data(struct cil_file_data **data) {
struct cil_file_data *new_data = malloc(sizeof(*new_data));
FILE *file;
struct stat filedata;
uint32_t file_size;
char *buffer;
file = fopen("test/policy.cil", "r");
if (!file) {
fprintf(stderr, "Could not open file\n");
exit(1);
}
if (stat("test/policy.cil", &filedata) == -1) {
printf("Could not stat file\n");
exit(1);
}
file_size = filedata.st_size;
buffer = malloc(file_size + 2);
if(fread(buffer, file_size, 1, file) < 1) {
exit(1);
}
memset(buffer+file_size, 0, 2);
fclose(file);
new_data->buffer = buffer;
new_data->file_size = file_size;
*data = new_data;
}
void gen_test_tree(struct cil_tree **test_root, char *line[]) {
struct cil_tree *new_tree = malloc(sizeof(*new_tree));
struct cil_tree_node *node, *item, *current;
cil_tree_init(&new_tree);
new_tree->root->flavor = CIL_ROOT;
current = new_tree->root;
char **i = line;
do {
if (*i[0] == '(') {
cil_tree_node_init(&node);
node->parent = current;
node->flavor = CIL_PARSE_NODE;
node->line = 0;
if (current->cl_head == NULL)
current->cl_head = node;
else
current->cl_tail->next = node;
current->cl_tail = node;
current = node;
}
else if (*i[0] == ')')
current = current->parent;
else {
cil_tree_node_init(&item);
item->parent = current;
item->data = cil_strdup(*i);
item->flavor = CIL_PARSE_NODE;
item->line = 0;
if (current->cl_head == NULL) {
current->cl_head = item;
}
else {
current->cl_tail->next = item;
}
current->cl_tail = item;
}
i++;
} while(*i != NULL);
*test_root = new_tree;
}
void test_symtab_init(CuTest *tc) {
struct cil_db *test_new_db;
test_new_db = malloc(sizeof(*test_new_db));
uint32_t rc = 0, i =0;
for (i = 0; i < CIL_SYM_NUM; i++) {
rc = symtab_init(&test_new_db->symtab[i], cil_sym_sizes[CIL_SYM_ARRAY_ROOT][i]);
CuAssertIntEquals(tc, 0, rc);
// TODO CDS add checks to make sure the symtab looks correct
}
free(test_new_db);
}
void test_symtab_init_no_table_neg(CuTest *tc) {
struct cil_db *test_new_db;
test_new_db = malloc(sizeof(*test_new_db));
int rc = symtab_init(&test_new_db->symtab[0], (uint32_t)SIZE_MAX);
CuAssertIntEquals(tc, -1, rc);
free(test_new_db);
}
CuSuite* CilTreeGetResolveSuite(void) {
CuSuite* suite = CuSuiteNew();
/* test_cil_resolve_ast.c */
SUITE_ADD_TEST(suite, test_cil_resolve_ast_curr_null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm_nodes_inval_perm_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_name);
SUITE_ADD_TEST(suite, test_cil_resolve_name_invalid_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_type_in_multiple_attrs);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_multiple_excludes_with_not);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_multiple_types_with_and);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_using_attr);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_name_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_undef_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_not);
SUITE_ADD_TEST(suite, test_cil_resolve_typeattributeset_undef_type_not_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typeattributeset);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typeattributeset_undef_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typealias);
SUITE_ADD_TEST(suite, test_cil_resolve_typealias_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typealias);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typealias_notype_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typebounds);
SUITE_ADD_TEST(suite, test_cil_resolve_typebounds_repeatbind_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typebounds_type1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typebounds_type2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typebounds);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typebounds_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_typepermissive);
SUITE_ADD_TEST(suite, test_cil_resolve_typepermissive_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typepermissive);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_typepermissive_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nametypetransition);
SUITE_ADD_TEST(suite, test_cil_resolve_nametypetransition_src_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nametypetransition_tgt_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nametypetransition_class_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nametypetransition_dest_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nametypetransition);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nametypetransition_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_namedrange);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_namedrange_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_namedrange_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_namedrange_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_type1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_type2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_class_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_call_level_l_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_call_level_l_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_call_level_h_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_call_level_h_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_level_l_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_level_h_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_anon_level_l);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_anon_level_l_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_anon_level_h);
SUITE_ADD_TEST(suite, test_cil_resolve_rangetransition_anon_level_h_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_rangetransition);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_rangetransition_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classcommon);
SUITE_ADD_TEST(suite, test_cil_resolve_classcommon_no_class_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classcommon_no_common_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_classcommon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_classcommon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_named);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_anon_inmacro);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_anon_inmacro_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_named_classmapname_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_anon_classmapname_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classmapping_anon_permset_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rolebounds);
SUITE_ADD_TEST(suite, test_cil_resolve_rolebounds_exists_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rolebounds_role1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_rolebounds_role2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_rolebounds);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_rolebounds_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_sensalias);
SUITE_ADD_TEST(suite, test_cil_resolve_sensalias_sensdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_sensalias);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_sensalias_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catalias);
SUITE_ADD_TEST(suite, test_cil_resolve_catalias_catdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catalias);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catalias_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catorder);
SUITE_ADD_TEST(suite, test_cil_resolve_catorder_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catorder);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catorder_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_dominance);
SUITE_ADD_TEST(suite, test_cil_resolve_dominance_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_dominance);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_dominance_neg);
//TODO: test for __cil_set_order
SUITE_ADD_TEST(suite, test_cil_resolve_catset);
SUITE_ADD_TEST(suite, test_cil_resolve_catset_catlist_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catset);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catset_catlist_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catrange);
SUITE_ADD_TEST(suite, test_cil_resolve_catrange_catloworder_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catrange_cathighorder_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catrange_cat1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_catrange_cat2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catrange);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_catrange_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_catrange_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_catsetname);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_catsetname_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_sublist);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_missingsens_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_category_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_senscat_currrangecat);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_senscat);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_senscat_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_level);
SUITE_ADD_TEST(suite, test_cil_resolve_level_catlist);
SUITE_ADD_TEST(suite, test_cil_resolve_level_catset);
SUITE_ADD_TEST(suite, test_cil_resolve_level_catset_name_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_level_sens_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_level_cat_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_level_senscat_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_level);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_level_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_namedlvl);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_namedlvl_low_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_namedlvl_high_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_anonlvl);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_anonlvl_low_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_levelrange_anonlvl_high_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_levelrange);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_levelrange_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_constrain);
SUITE_ADD_TEST(suite, test_cil_resolve_constrain_class_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_constrain_perm_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_constrain_perm_resolve_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_constrain);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_constrain_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_mlsconstrain);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_mlsconstrain_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context);
SUITE_ADD_TEST(suite, test_cil_resolve_context_macro);
SUITE_ADD_TEST(suite, test_cil_resolve_context_macro_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context_namedrange);
SUITE_ADD_TEST(suite, test_cil_resolve_context_namedrange_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context_user_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context_role_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_context_anon_level_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_context);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roletransition);
SUITE_ADD_TEST(suite, test_cil_resolve_roletransition_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roletransition_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roletransition_resultdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletransition);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletransition_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletransition_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletransition_resultdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roleallow);
SUITE_ADD_TEST(suite, test_cil_resolve_roleallow_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roleallow_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roleallow);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roleallow_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_named);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_named_namedpermlist);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_named_permlist_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_named_unnamedcps_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_anon_namedpermlist);
SUITE_ADD_TEST(suite, test_cil_resolve_classpermset_anon_permlist_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_permset);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_permset_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_permset_permdne_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_firsttype_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_secondtype_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_class_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_avrule_perm_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_avrule);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_avrule_src_nores_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_avrule_tgt_nores_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_avrule_class_nores_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_avrule_datum_null_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_transition);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_transition_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_transition_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_transition_objdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_transition_resultdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_transition);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_transition_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_change);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_change_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_change_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_change_objdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_change_resultdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_change);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_change_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_member);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_member_srcdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_member_tgtdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_member_objdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_type_rule_member_resultdecl_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_member);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_type_rule_member_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_filecon);
SUITE_ADD_TEST(suite, test_cil_resolve_filecon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_filecon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_filecon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_filecon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_filecon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_portcon);
SUITE_ADD_TEST(suite, test_cil_resolve_portcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_portcon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_portcon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_portcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_portcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_genfscon);
SUITE_ADD_TEST(suite, test_cil_resolve_genfscon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_genfscon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_genfscon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_genfscon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_genfscon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_ipv4);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_ipv6);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anonipaddr_ipv4);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anonnetmask_ipv4);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anonipaddr_ipv6);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anonnetmask_ipv6);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_diffipfam_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_ipaddr_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_netmask_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_nodecon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nodecon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nodecon_ipaddr_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nodecon_netmask_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon_otf_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon_interface_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon_unnamed);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon_unnamed_packet_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_netifcon_unnamed_otf_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_netifcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_netifcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_pirqcon);
SUITE_ADD_TEST(suite, test_cil_resolve_pirqcon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_pirqcon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_pirqcon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_pirqcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_pirqcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_iomemcon);
SUITE_ADD_TEST(suite, test_cil_resolve_iomemcon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_iomemcon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_iomemcon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_iomemcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_iomemcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ioportcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ioportcon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ioportcon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_ioportcon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_ioportcon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_ioportcon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_pcidevicecon);
SUITE_ADD_TEST(suite, test_cil_resolve_pcidevicecon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_pcidevicecon_anon_context);
SUITE_ADD_TEST(suite, test_cil_resolve_pcidevicecon_anon_context_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_pcidevicecon);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_pcidevicecon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_fsuse);
SUITE_ADD_TEST(suite, test_cil_resolve_fsuse_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_fsuse_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_fsuse_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_fsuse);
//SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_fsuse_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_sidcontext);
SUITE_ADD_TEST(suite, test_cil_resolve_sidcontext_named_levels);
SUITE_ADD_TEST(suite, test_cil_resolve_sidcontext_named_context);
SUITE_ADD_TEST(suite, test_cil_resolve_sidcontext_named_context_wrongname_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_sidcontext_named_context_invaliduser_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_sidcontext);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_sidcontext_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_blockinherit);
SUITE_ADD_TEST(suite, test_cil_resolve_blockinherit_blockstrdne_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_blockinherit);
SUITE_ADD_TEST(suite, test_cil_resolve_in_block);
SUITE_ADD_TEST(suite, test_cil_resolve_in_blockstrdne_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_in_macro);
SUITE_ADD_TEST(suite, test_cil_resolve_in_optional);
//SUITE_ADD_TEST(suite, test_cil_resolve_call1_noparam);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_type);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_role);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_user);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_sens);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_cat);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_catset);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_catset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_catset_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_class);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_classmap);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_permset);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_permset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_classpermset_named);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_classpermset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_classpermset_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_level);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_level_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_level_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_ipaddr);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_ipaddr_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_ipaddr_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_unknown_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_unknowncall_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_extraargs_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_copy_dup);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_missing_arg_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_paramsflavor_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call1_unknownflavor_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_call1);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_call1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_type);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_role);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_user);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_sens);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_cat);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_catset);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_catset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_permset);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_permset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_classpermset_named);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_classpermset_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_class);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_classmap);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_level);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_level_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_ipaddr);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_ipaddr_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_call2_unknown_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_call2);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_call2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_multipleparams);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_diffflavor);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_callnull_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_namenull_neg);
//SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_callargsnull_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_name_call_args_name_neg);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_bools);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_tunables);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_type);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_role);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_user);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_neg);
// SUITE_ADD_TEST(suite, test_cil_resolve_expr_stack_emptystr_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_boolif);
SUITE_ADD_TEST(suite, test_cil_resolve_boolif_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_boolif);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_boolif_neg);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_and);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_not);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_or);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_xor);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_eq);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_neq);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_oper1);
SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_oper2);
//SUITE_ADD_TEST(suite, test_cil_evaluate_expr_stack_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_tunif_false);
SUITE_ADD_TEST(suite, test_cil_resolve_tunif_true);
SUITE_ADD_TEST(suite, test_cil_resolve_tunif_resolveexpr_neg);
//SUITE_ADD_TEST(suite, test_cil_resolve_tunif_evaluateexpr_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_tunif);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_tunif_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userbounds);
SUITE_ADD_TEST(suite, test_cil_resolve_userbounds_exists_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userbounds_user1_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userbounds_user2_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userbounds);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userbounds_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roletype);
SUITE_ADD_TEST(suite, test_cil_resolve_roletype_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_roletype_role_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletype);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletype_role_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_roletype_type_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrole);
SUITE_ADD_TEST(suite, test_cil_resolve_userrole_user_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrole_role_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userrole);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userrole_user_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userrole_role_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_macro);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_macro_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_level_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_level_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_user_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userlevel_level_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userlevel);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userlevel_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_macro);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_macro_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_range_anon);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_range_anon_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_user_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_userrange_range_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userrange);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_userrange_neg);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_optional_enabled);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_optional_disabled);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_block);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_user);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_role);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_type);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_typealias);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_common);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_class);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_bool);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_sens);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_cat);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_catset);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_sid);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_macro);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_context);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_level);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_policycap);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_perm);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_catalias);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_sensalias);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_tunable);
SUITE_ADD_TEST(suite, test_cil_disable_children_helper_unknown);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_callstack);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_call);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_optional);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_macro);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_optstack);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_optstack_tunable_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_optstack_macro_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_nodenull_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_extraargsnull_neg);
SUITE_ADD_TEST(suite, test_cil_resolve_ast_node_helper_optfailedtoresolve);
return suite;
}
CuSuite* CilTreeGetBuildSuite(void) {
CuSuite* suite = CuSuiteNew();
/* test_cil_build_ast.c */
SUITE_ADD_TEST(suite, test_cil_build_ast);
SUITE_ADD_TEST(suite, test_cil_build_ast_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_treenull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_suberr_neg);
SUITE_ADD_TEST(suite, test_cil_parse_to_list);
SUITE_ADD_TEST(suite, test_cil_parse_to_list_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_parse_to_list_listnull_neg);
SUITE_ADD_TEST(suite, test_cil_set_to_list);
SUITE_ADD_TEST(suite, test_cil_set_to_list_listnull_neg);
SUITE_ADD_TEST(suite, test_cil_set_to_list_tree_node_null_neg);
SUITE_ADD_TEST(suite, test_cil_set_to_list_cl_head_null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block);
SUITE_ADD_TEST(suite, test_cil_gen_block_justblock_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block_treenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block_nodenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_block_nodeparentnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_block);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_block_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_namelist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_namenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_blockinherit_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_blockinherit);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_blockinherit_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm);
SUITE_ADD_TEST(suite, test_cil_gen_perm_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm_nodenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset);
SUITE_ADD_TEST(suite, test_cil_gen_permset_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_noperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_emptyperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_permset_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_permset);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_permset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_perm_nodes);
SUITE_ADD_TEST(suite, test_cil_gen_perm_nodes_failgen_neg);
SUITE_ADD_TEST(suite, test_cil_fill_permset);
SUITE_ADD_TEST(suite, test_cil_fill_permset_sublist_neg);
SUITE_ADD_TEST(suite, test_cil_fill_permset_startpermnull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_permset_permsetnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_in);
SUITE_ADD_TEST(suite, test_cil_gen_in_blockstrnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_in_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_in_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_in_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_in_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_in);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_in_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class);
SUITE_ADD_TEST(suite, test_cil_gen_class_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_nodenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_noclassname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_namesublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_noperms);
SUITE_ADD_TEST(suite, test_cil_gen_class_permsnotinlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_extrapermlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_class_listinlist_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_class);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_class_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_anonperms);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_anonperms_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_namedperms);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_extra_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_emptypermslist_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_noperms_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_classnodenull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_classpermset_cpsnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_noperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_emptyperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classpermset_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classpermset);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classpermset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_perm);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_perm_dupeperm_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_perm_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_perm_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_perm_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_emptyperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmap_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classmap);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classmap_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_anonpermset);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_anonpermset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_namedpermset);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_noclassmapname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_noclassmapperm_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_nopermissionsets_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classmapping_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classmapping);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_classmapping_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common);
SUITE_ADD_TEST(suite, test_cil_gen_common_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_twoperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_permsublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_common_noperms_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_common);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_common_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid);
SUITE_ADD_TEST(suite, test_cil_gen_sid_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sid_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sid);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sid_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_namedcontext);
// SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_halfcontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_empty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_dblname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_pcurrnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sidcontext_astnodenull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sidcontext);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sidcontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type);
SUITE_ADD_TEST(suite, test_cil_gen_type_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattribute);
SUITE_ADD_TEST(suite, test_cil_gen_typeattribute_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattribute_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattribute_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattribute_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typeattribute);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typeattribute_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_notype1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_type1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_notype2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_type2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typebounds_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typebounds);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typebounds_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_typeinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typepermissive_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typepermissive);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typepermissive_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_nostr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_strinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_nosrc_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_srcinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_notgt_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_tgtinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_classinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_nodest_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_destinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nametypetransition_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_nametypetransition);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_nametypetransition_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_namedtransition);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_anon_low_l);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_anon_low_l_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_anon_high_l);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_anon_high_l_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_nofirsttype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_firsttype_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_nosecondtype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_secondtype_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_class_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_nolevel_l_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_nolevel_h_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rangetransition_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_rangetransition);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_rangetransition_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_and);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_or);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_xor);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_not);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_not_noexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_not_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_eq);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_neq);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_nested);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_nested_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_nested_emptyargs_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_nested_missingoperator_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_arg1null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_arg2null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_extraarg_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_expr_stack_stacknull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_multiplebools_true);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_multiplebools_false);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_multiplebools_unknowncond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_true);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_false);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_unknowncond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_nested);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_nested_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_extra_parens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_nocond);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_nocond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_notruelist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_boolif_empty_cond_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_boolif);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_boolif_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_multiplebools_true);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_multiplebools_false);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_multiplebools_unknowncond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_true);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_false);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_unknowncond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_nocond);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_nested);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_nested_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_extra_parens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_nocond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_tunif_notruelist_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_tunif);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_tunif_neg);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_true);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_false);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_nocond_neg);
SUITE_ADD_TEST(suite, test_cil_gen_condblock_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_condblock_true);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_condblock_true_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_condblock_false);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_condblock_false_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typealias);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_incomplete_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_incomplete_neg2);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_extratype_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typealias);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typealias_notype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typealias_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_and_two_types);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_not);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_exclude_attr);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_exclude_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_emptylists_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_listinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_typeattributeset_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typeattributeset);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_typeattributeset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_notype1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_type1_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_notype2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_type2_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userbounds_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userbounds);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userbounds_neg);
SUITE_ADD_TEST(suite, test_cil_gen_role);
SUITE_ADD_TEST(suite, test_cil_gen_role_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_role_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_role_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_role_extrarole_neg);
SUITE_ADD_TEST(suite, test_cil_gen_role_noname_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_role);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_role_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_srcnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_tgtnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_resultnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletransition_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roletransition);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roletransition_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_true);
SUITE_ADD_TEST(suite, test_cil_gen_bool_tunable_true);
SUITE_ADD_TEST(suite, test_cil_gen_bool_false);
SUITE_ADD_TEST(suite, test_cil_gen_bool_tunable_false);
SUITE_ADD_TEST(suite, test_cil_gen_bool_none_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_notbool_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_boolname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_extraname_false_neg);
SUITE_ADD_TEST(suite, test_cil_gen_bool_extraname_true_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_bool);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_bool_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_bool_tunable);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_bool_tunable_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_t1type);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_t1t1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_t2type);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_t2t2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_r1role);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_r1r1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_r2role);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_r2r2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_t1t2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_r1r2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_r1r2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_u1u2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_u1user);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_u1u1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_u2user);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_u2u2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l2h2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l1l2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l1h1);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l1h2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_h1l2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_h1h2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_h1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l1l1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_l1l2_constrain_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_l1l2_constrain_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_leftkeyword_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_eq2_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_noteq_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_not);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_not_noexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_not_emptyparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_not_extraparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_noexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_emptyfirstparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_missingsecondexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_emptysecondparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_or_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_noexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_emptyfirstparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_missingsecondexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_emptysecondparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_and_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_dom_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_domby_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp_noexpr1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp_expr1inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp_noexpr2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp_expr2inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incomp_extraexpr_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_stacknull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_operatorinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expr_stack_incorrectcall_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_srcnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_tgtnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roleallow_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roleallow);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roleallow_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_norole1_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_role1_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_norole2_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_role2_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_rolebounds_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_rolebounds);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_rolebounds_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_permset);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_permset_anon);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_sourceparens);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_sourceemptyparen_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_targetparens);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_targetemptyparen_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_sourcedomainnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_targetdomainnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_objectclassnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_permsnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_avrule_twolists_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_allow);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_allow_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_auditallow);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_auditallow_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_dontaudit);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_dontaudit_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_neverallow);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_avrule_neverallow_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_srcnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_tgtnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_objnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_resultnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_transition_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_transition);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_transition_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_srcnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_tgtnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_objnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_resultnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_change_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_change);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_change_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_srcnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_tgtnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_objnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_resultnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_type_rule_member_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_member);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_type_rule_member_neg);
SUITE_ADD_TEST(suite, test_cil_gen_user);
SUITE_ADD_TEST(suite, test_cil_gen_user_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_user_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_user_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_user_nouser_neg);
SUITE_ADD_TEST(suite, test_cil_gen_user_xsinfo_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_user);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_user_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_anon_level);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_anon_level_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_usernull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_userrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_levelnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_levelrangeempty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userlevel_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userlevel);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userlevel_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_named);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_anon);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_usernull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_anonuser_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_rangenamenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_anonrangeinvalid_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_anonrangeempty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrange_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userrange);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_sensnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_senslist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensitivity_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sensitivity);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sensitivity_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_sensnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_senslist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_aliasnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_aliaslist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_sensalias_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sensalias);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_sensalias_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category);
SUITE_ADD_TEST(suite, test_cil_gen_category_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category_catnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category_catlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_category_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_category);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_category_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset);
SUITE_ADD_TEST(suite, test_cil_gen_catset_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_namenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_setnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_namelist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_nodefail_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_notset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catset_settolistfail_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catset);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_catnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_aliasnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catalias_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catalias);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catalias_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_norange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_emptyrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_extrarange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catrange_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catrange);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_empty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_rolelist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_roletype_sublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_roletype_typelist_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roletype);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_roletype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_empty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_userlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_userrole_sublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_userrole_rolelist_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userrole);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_userrole_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_missingclassname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_noperms_neg);
SUITE_ADD_TEST(suite, test_cil_gen_classcommon_extraperms_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_classcommon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_classcommon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_missingcats_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_nosublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_catorder_nestedcat_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catorder);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_catorder_neg);
SUITE_ADD_TEST(suite, test_cil_gen_dominance);
SUITE_ADD_TEST(suite, test_cil_gen_dominance_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_dominance_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_dominance_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_dominance_nosensitivities_neg);
SUITE_ADD_TEST(suite, test_cil_gen_dominance_nosublist_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_dominance);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_dominance_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_nosublist);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_nosensitivities_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_sublist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_senscat_nocat_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_senscat);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_senscat_neg);
SUITE_ADD_TEST(suite, test_cil_fill_level);
SUITE_ADD_TEST(suite, test_cil_fill_level_sensnull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_level_levelnull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_level_nocat);
SUITE_ADD_TEST(suite, test_cil_fill_level_emptycat_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level);
SUITE_ADD_TEST(suite, test_cil_gen_level_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_emptysensparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_emptycat_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_nosens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_level_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_level);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_level_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_rangeinvalid_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_namenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_rangenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_rangeempty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_levelrange_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_levelrange);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_levelrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_classset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_classset_noperm_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_classset_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_permset_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_permset_noclass_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_permset_noperm_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_expression_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_constrain_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_constrain);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_constrain_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_mlsconstrain);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_mlsconstrain_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context);
SUITE_ADD_TEST(suite, test_cil_fill_context_unnamedlvl);
SUITE_ADD_TEST(suite, test_cil_fill_context_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_nouser_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_norole_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_notype_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_nolowlvl_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_nohighlvl_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_unnamedlvl_nocontextlow_neg);
SUITE_ADD_TEST(suite, test_cil_fill_context_unnamedlvl_nocontexthigh_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context);
SUITE_ADD_TEST(suite, test_cil_gen_context_notinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_extralevel_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_emptycontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_doubleparen_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_norole_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_roleinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_notype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_typeinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_nolevels_neg);
// SUITE_ADD_TEST(suite, test_cil_gen_context_nosecondlevel_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_nouser_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_context_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_context);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_context_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_file);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_dir);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_char);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_block);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_socket);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_pipe);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_symlink);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_any);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_anon_context);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_str1null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_str1_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_str2null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_str2_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_classnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_class_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_contextnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_context_neg);
SUITE_ADD_TEST(suite, test_cil_gen_filecon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_filecon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_filecon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_udp);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_tcp);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_unknownprotocol_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_anon_context);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_portrange);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_portrange_one_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_portrange_morethanone_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_singleport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_lowport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_highport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_str1null_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_str1parens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_portnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_contextnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_context_neg);
SUITE_ADD_TEST(suite, test_cil_gen_portcon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_portcon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_portcon_neg);
SUITE_ADD_TEST(suite, test_cil_fill_ipaddr);
SUITE_ADD_TEST(suite, test_cil_fill_ipaddr_addrnodenull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_ipaddr_addrnull_neg);
SUITE_ADD_TEST(suite, test_cil_fill_ipaddr_addrinparens_neg);
SUITE_ADD_TEST(suite, test_cil_fill_ipaddr_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_anon_context);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_ipnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_ipanon);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_ipanon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_netmasknull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_netmaskanon);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_netmaskanon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_contextnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_context_neg);
SUITE_ADD_TEST(suite, test_cil_gen_nodecon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_nodecon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_nodecon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_anon_context);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_typenull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_typeparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_pathnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_pathparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_contextnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_context_neg);
SUITE_ADD_TEST(suite, test_cil_gen_genfscon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_genfscon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_genfscon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_nested);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_nested_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_nested_emptysecondlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_extra_nested_secondlist_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_nested_missingobjects_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_nested_secondnested_missingobjects_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_ethmissing_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_interfacemissing_neg);
SUITE_ADD_TEST(suite, test_cil_gen_netifcon_packetmissing_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_netifcon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_netifcon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_pirqnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_nopirq_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_pirqrange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_anoncontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pirqcon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_pirqcon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_pirqcon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange_firstnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange_secondnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange_empty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange_singleiomem_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemrange_morethantwoiomem_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_iomemnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_noiomem_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_anoncontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_iomemcon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_iomemcon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_iomemcon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange_firstnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange_secondnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange_empty_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange_singleioport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportrange_morethantwoioport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_ioportnotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_noioport_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_anoncontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ioportcon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_ioportcon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_ioportcon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_pcidevicenotint_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_nopcidevice_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_pcidevicerange_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_anoncontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_pcidevicecon_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_pcidevicecon);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_pcidevicecon_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_anoncontext);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_anoncontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_xattr);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_task);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_transition);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_invalidtype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_notype_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_typeinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_nofilesystem_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_filesysteminparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_nocontext_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_emptyconparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_fsuse_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_fsuse);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_fsuse_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_noparams);
SUITE_ADD_TEST(suite, test_cil_gen_macro_type);
SUITE_ADD_TEST(suite, test_cil_gen_macro_role);
SUITE_ADD_TEST(suite, test_cil_gen_macro_user);
SUITE_ADD_TEST(suite, test_cil_gen_macro_sensitivity);
SUITE_ADD_TEST(suite, test_cil_gen_macro_category);
SUITE_ADD_TEST(suite, test_cil_gen_macro_catset);
SUITE_ADD_TEST(suite, test_cil_gen_macro_level);
SUITE_ADD_TEST(suite, test_cil_gen_macro_class);
SUITE_ADD_TEST(suite, test_cil_gen_macro_classmap);
SUITE_ADD_TEST(suite, test_cil_gen_macro_permset);
SUITE_ADD_TEST(suite, test_cil_gen_macro_duplicate);
SUITE_ADD_TEST(suite, test_cil_gen_macro_duplicate_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_unknown_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_unnamed_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_noparam_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_nosecondparam_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_noparam_name_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_emptyparam_neg);
SUITE_ADD_TEST(suite, test_cil_gen_macro_paramcontainsperiod_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_macro);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_macro_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_macro_nested_macro_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_macro_nested_tunif_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call);
SUITE_ADD_TEST(suite, test_cil_gen_call_noargs);
SUITE_ADD_TEST(suite, test_cil_gen_call_anon);
SUITE_ADD_TEST(suite, test_cil_gen_call_empty_call_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call_name_inparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_call_noname_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_call);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_call_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional);
SUITE_ADD_TEST(suite, test_cil_gen_optional_emptyoptional);
SUITE_ADD_TEST(suite, test_cil_gen_optional_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_unnamed_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_optional_norule_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_optional);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_optional_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_policycap_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_policycap);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_policycap_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_ipv4);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_ipv4_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_ipv6);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_ipv6_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_noname_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_nameinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_noip_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_ipinparens_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_extra_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_dbnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_currnull_neg);
SUITE_ADD_TEST(suite, test_cil_gen_ipaddr_astnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_ipaddr);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_gen_ipaddr_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_node_helper_extraargsnull_neg);
SUITE_ADD_TEST(suite, test_cil_build_ast_last_child_helper);
SUITE_ADD_TEST(suite, test_cil_build_ast_last_child_helper_extraargsnull_neg);
return suite;
}
CuSuite* CilTreeGetSuite(void) {
CuSuite* suite = CuSuiteNew();
/* CilTest.c */
SUITE_ADD_TEST(suite, test_symtab_init);
SUITE_ADD_TEST(suite, test_symtab_init_no_table_neg);
/* test_cil.c */
SUITE_ADD_TEST(suite, test_cil_symtab_array_init);
SUITE_ADD_TEST(suite, test_cil_db_init);
SUITE_ADD_TEST(suite, test_cil_get_symtab_block);
SUITE_ADD_TEST(suite, test_cil_get_symtab_class);
SUITE_ADD_TEST(suite, test_cil_get_symtab_root);
SUITE_ADD_TEST(suite, test_cil_get_symtab_flavor_neg);
SUITE_ADD_TEST(suite, test_cil_get_symtab_null_neg);
SUITE_ADD_TEST(suite, test_cil_get_symtab_node_null_neg);
SUITE_ADD_TEST(suite, test_cil_get_symtab_parent_null_neg);
/* test_cil_list.c */
SUITE_ADD_TEST(suite, test_cil_list_append_item);
SUITE_ADD_TEST(suite, test_cil_list_append_item_append);
SUITE_ADD_TEST(suite, test_cil_list_append_item_append_extra);
SUITE_ADD_TEST(suite, test_cil_list_append_item_listnull_neg);
SUITE_ADD_TEST(suite, test_cil_list_append_item_itemnull_neg);
SUITE_ADD_TEST(suite, test_cil_list_prepend_item_prepend);
SUITE_ADD_TEST(suite, test_cil_list_prepend_item_prepend_neg);
SUITE_ADD_TEST(suite, test_cil_list_prepend_item_listnull_neg);
SUITE_ADD_TEST(suite, test_cil_list_prepend_item_itemnull_neg);
/* test_cil_symtab.c */
SUITE_ADD_TEST(suite, test_cil_symtab_insert);
/* test_cil_tree.c */
SUITE_ADD_TEST(suite, test_cil_tree_init);
SUITE_ADD_TEST(suite, test_cil_tree_node_init);
/* test_cil_lexer.c */
SUITE_ADD_TEST(suite, test_cil_lexer_setup);
SUITE_ADD_TEST(suite, test_cil_lexer_next);
/* test_cil_parser.c */
SUITE_ADD_TEST(suite, test_cil_parser);
/* test_cil_fqn.c */
SUITE_ADD_TEST(suite, test_cil_qualify_name);
SUITE_ADD_TEST(suite, test_cil_qualify_name_cil_flavor);
/* test cil_copy_ast.c */
SUITE_ADD_TEST(suite, test_cil_copy_list);
SUITE_ADD_TEST(suite, test_cil_copy_list_sublist);
SUITE_ADD_TEST(suite, test_cil_copy_list_sublist_extra);
SUITE_ADD_TEST(suite, test_cil_copy_list_orignull_neg);
SUITE_ADD_TEST(suite, test_cil_copy_block);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_block);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_block_merge);
SUITE_ADD_TEST(suite, test_cil_copy_perm);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_perm);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_perm_neg);
SUITE_ADD_TEST(suite, test_cil_copy_class);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_class);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_class_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_common);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_common);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_common_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_classcommon);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_classcommon);
SUITE_ADD_TEST(suite, test_cil_copy_sid);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sid);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sid_merge);
SUITE_ADD_TEST(suite, test_cil_copy_sidcontext);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sidcontext);
SUITE_ADD_TEST(suite, test_cil_copy_user);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_user);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_user_merge);
SUITE_ADD_TEST(suite, test_cil_copy_role);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_role);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_role_merge);
SUITE_ADD_TEST(suite, test_cil_copy_userrole);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_userrole);
SUITE_ADD_TEST(suite, test_cil_copy_type);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_type);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_type_merge);
SUITE_ADD_TEST(suite, test_cil_copy_typeattribute);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_typeattribute);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_typeattribute_merge);
SUITE_ADD_TEST(suite, test_cil_copy_typealias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_typealias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_typealias_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_bool);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_bool);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_bool_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_avrule);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_avrule);
SUITE_ADD_TEST(suite, test_cil_copy_type_rule);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_type_rule);
SUITE_ADD_TEST(suite, test_cil_copy_sens);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sens);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sens_merge);
SUITE_ADD_TEST(suite, test_cil_copy_sensalias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sensalias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_sensalias_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_cat);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_cat);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_cat_merge);
SUITE_ADD_TEST(suite, test_cil_copy_catalias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_catalias);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_catalias_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_senscat);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_senscat);
SUITE_ADD_TEST(suite, test_cil_copy_catorder);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_catorder);
SUITE_ADD_TEST(suite, test_cil_copy_dominance);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_dominance);
SUITE_ADD_TEST(suite, test_cil_copy_level);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_level);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_level_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_fill_level);
SUITE_ADD_TEST(suite, test_cil_copy_context);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_context);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_context_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_netifcon);
SUITE_ADD_TEST(suite, test_cil_copy_netifcon_nested);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_netifcon);
SUITE_ADD_TEST(suite, test_cil_copy_fill_context);
SUITE_ADD_TEST(suite, test_cil_copy_fill_context_anonrange);
SUITE_ADD_TEST(suite, test_cil_copy_call);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_call);
SUITE_ADD_TEST(suite, test_cil_copy_optional);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_optional);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_optional_merge);
SUITE_ADD_TEST(suite, test_cil_copy_nodecon);
SUITE_ADD_TEST(suite, test_cil_copy_nodecon_anon);
SUITE_ADD_TEST(suite, test_cil_copy_fill_ipaddr);
SUITE_ADD_TEST(suite, test_cil_copy_ipaddr);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_ipaddr);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_ipaddr_dup_neg);
SUITE_ADD_TEST(suite, test_cil_copy_conditional);
SUITE_ADD_TEST(suite, test_cil_copy_boolif);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_boolif);
SUITE_ADD_TEST(suite, test_cil_copy_constrain);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_mlsconstrain);
//SUITE_ADD_TEST(suite, test_cil_copy_ast);
//SUITE_ADD_TEST(suite, test_cil_copy_ast_neg);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_orignull_neg);
SUITE_ADD_TEST(suite, test_cil_copy_node_helper_extraargsnull_neg);
/* test_post.c */
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_meta_a_not_b);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_meta_b_not_a);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_meta_a_and_b_strlen_a_greater_b);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_meta_a_and_b_strlen_b_greater_a);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_type_atype_greater_btype);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_type_btype_greater_atype);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_stemlen_a_greater_b);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_stemlen_b_greater_a);
SUITE_ADD_TEST(suite, test_cil_post_filecon_compare_equal);
SUITE_ADD_TEST(suite, test_cil_post_genfscon_compare_atypestr_greater_btypestr);
SUITE_ADD_TEST(suite, test_cil_post_genfscon_compare_btypestr_greater_atypestr);
SUITE_ADD_TEST(suite, test_cil_post_genfscon_compare_apathstr_greater_bpathstr);
SUITE_ADD_TEST(suite, test_cil_post_genfscon_compare_bpathstr_greater_apathstr);
SUITE_ADD_TEST(suite, test_cil_post_genfscon_compare_equal);
SUITE_ADD_TEST(suite, test_cil_post_netifcon_compare_a_greater_b);
SUITE_ADD_TEST(suite, test_cil_post_netifcon_compare_b_greater_a);
SUITE_ADD_TEST(suite, test_cil_post_netifcon_compare_equal);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv4_bipv6);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv6_bipv4);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv4_greaterthan_bipv4);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv4_lessthan_bipv4);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_amaskipv4_greaterthan_bmaskipv4);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_amaskipv4_lessthan_bmaskipv4);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv6_greaterthan_bipv6);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_aipv6_lessthan_bipv6);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_amaskipv6_greaterthan_bmaskipv6);
SUITE_ADD_TEST(suite, test_cil_post_nodecon_compare_amaskipv6_lessthan_bmaskipv6);
SUITE_ADD_TEST(suite, test_cil_post_fsuse_compare_type_a_greater_b);
SUITE_ADD_TEST(suite, test_cil_post_fsuse_compare_type_b_greater_a);
SUITE_ADD_TEST(suite, test_cil_post_fsuse_compare_fsstr_a_greater_b);
SUITE_ADD_TEST(suite, test_cil_post_fsuse_compare_fsstr_b_greater_a);
SUITE_ADD_TEST(suite, test_cil_post_fsuse_compare_equal);
return suite;
}
CuSuite* CilTestFullCil(void) {
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_min_policy);
SUITE_ADD_TEST(suite, test_integration);
return suite;
}
libsepol-3.8.1/cil/test/unit/CilTest.h000066400000000000000000000035501476211737200175760ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef CILTEST_H_
#define CILTEST_H_
#include "../../src/cil_tree.h"
// TODO Check more in the data structures
struct cil_file_data {
char *buffer;
uint32_t file_size;
};
void set_cil_file_data(struct cil_file_data **);
void gen_test_tree(struct cil_tree **, char **);
#endif
libsepol-3.8.1/cil/test/unit/CuTest.c000066400000000000000000000215131476211737200174300ustar00rootroot00000000000000/*
* Copyright (c) 2003 Asim Jalis
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in
* a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include
#include
#include
#include
#include
#include
#include "CuTest.h"
/*-------------------------------------------------------------------------*
* CuStr
*-------------------------------------------------------------------------*/
char* CuStrAlloc(int size)
{
char* newStr = (char*) malloc( sizeof(char) * (size) );
return newStr;
}
char* CuStrCopy(const char* old)
{
int len = strlen(old);
char* newStr = CuStrAlloc(len + 1);
strcpy(newStr, old);
return newStr;
}
/*-------------------------------------------------------------------------*
* CuString
*-------------------------------------------------------------------------*/
void CuStringInit(CuString* str)
{
str->length = 0;
str->size = STRING_MAX;
str->buffer = (char*) malloc(sizeof(char) * str->size);
str->buffer[0] = '\0';
}
CuString* CuStringNew(void)
{
CuString* str = (CuString*) malloc(sizeof(CuString));
str->length = 0;
str->size = STRING_MAX;
str->buffer = (char*) malloc(sizeof(char) * str->size);
str->buffer[0] = '\0';
return str;
}
void CuStringDelete(CuString *str)
{
if (!str) return;
free(str->buffer);
free(str);
}
void CuStringResize(CuString* str, int newSize)
{
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
str->size = newSize;
}
void CuStringAppend(CuString* str, const char* text)
{
int length;
if (text == NULL) {
text = "NULL";
}
length = strlen(text);
if (str->length + length + 1 >= str->size)
CuStringResize(str, str->length + length + 1 + STRING_INC);
str->length += length;
strcat(str->buffer, text);
}
void CuStringAppendChar(CuString* str, char ch)
{
char text[2];
text[0] = ch;
text[1] = '\0';
CuStringAppend(str, text);
}
__attribute__ ((format (printf, 2, 3))) void CuStringAppendFormat(CuString* str, const char* format, ...)
{
va_list argp;
char buf[HUGE_STRING_LEN];
va_start(argp, format);
vsprintf(buf, format, argp);
va_end(argp);
CuStringAppend(str, buf);
}
void CuStringInsert(CuString* str, const char* text, int pos)
{
int length = strlen(text);
if (pos > str->length)
pos = str->length;
if (str->length + length + 1 >= str->size)
CuStringResize(str, str->length + length + 1 + STRING_INC);
memmove(str->buffer + pos + length, str->buffer + pos, (str->length - pos) + 1);
str->length += length;
memcpy(str->buffer + pos, text, length);
}
/*-------------------------------------------------------------------------*
* CuTest
*-------------------------------------------------------------------------*/
void CuTestInit(CuTest* t, const char* name, TestFunction function)
{
t->name = CuStrCopy(name);
t->failed = 0;
t->ran = 0;
t->message = NULL;
t->function = function;
t->jumpBuf = NULL;
}
CuTest* CuTestNew(const char* name, TestFunction function)
{
CuTest* tc = CU_ALLOC(CuTest);
CuTestInit(tc, name, function);
return tc;
}
void CuTestDelete(CuTest *t)
{
if (!t) return;
free(t->name);
free(t);
}
void CuTestRun(CuTest* tc)
{
jmp_buf buf;
tc->jumpBuf = &buf;
if (setjmp(buf) == 0)
{
tc->ran = 1;
(tc->function)(tc);
}
tc->jumpBuf = 0;
}
static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* string)
{
char buf[HUGE_STRING_LEN];
sprintf(buf, "%s:%d: ", file, line);
CuStringInsert(string, buf, 0);
tc->failed = 1;
tc->message = string->buffer;
if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
}
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message)
{
CuString string;
CuStringInit(&string);
if (message2 != NULL)
{
CuStringAppend(&string, message2);
CuStringAppend(&string, ": ");
}
CuStringAppend(&string, message);
CuFailInternal(tc, file, line, &string);
}
void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition)
{
if (condition) return;
CuFail_Line(tc, file, line, NULL, message);
}
void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
const char* expected, const char* actual)
{
CuString string;
if ((expected == NULL && actual == NULL) ||
(expected != NULL && actual != NULL &&
strcmp(expected, actual) == 0))
{
return;
}
CuStringInit(&string);
if (message != NULL)
{
CuStringAppend(&string, message);
CuStringAppend(&string, ": ");
}
CuStringAppend(&string, "expected <");
CuStringAppend(&string, expected);
CuStringAppend(&string, "> but was <");
CuStringAppend(&string, actual);
CuStringAppend(&string, ">");
CuFailInternal(tc, file, line, &string);
}
void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
int expected, int actual)
{
char buf[STRING_MAX];
if (expected == actual) return;
sprintf(buf, "expected <%d> but was <%d>", expected, actual);
CuFail_Line(tc, file, line, message, buf);
}
void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
double expected, double actual, double delta)
{
char buf[STRING_MAX];
if (fabs(expected - actual) <= delta) return;
sprintf(buf, "expected <%f> but was <%f>", expected, actual);
CuFail_Line(tc, file, line, message, buf);
}
void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
void* expected, void* actual)
{
char buf[STRING_MAX];
if (expected == actual) return;
sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
CuFail_Line(tc, file, line, message, buf);
}
/*-------------------------------------------------------------------------*
* CuSuite
*-------------------------------------------------------------------------*/
void CuSuiteInit(CuSuite* testSuite)
{
testSuite->count = 0;
testSuite->failCount = 0;
memset(testSuite->list, 0, sizeof(testSuite->list));
}
CuSuite* CuSuiteNew(void)
{
CuSuite* testSuite = CU_ALLOC(CuSuite);
CuSuiteInit(testSuite);
return testSuite;
}
void CuSuiteDelete(CuSuite *testSuite)
{
unsigned int n;
for (n=0; n < MAX_TEST_CASES; n++)
{
if (testSuite->list[n])
{
CuTestDelete(testSuite->list[n]);
}
}
free(testSuite);
}
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
{
assert(testSuite->count < MAX_TEST_CASES);
testSuite->list[testSuite->count] = testCase;
testSuite->count++;
}
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
{
int i;
for (i = 0 ; i < testSuite2->count ; ++i)
{
CuTest* testCase = testSuite2->list[i];
CuSuiteAdd(testSuite, testCase);
}
}
void CuSuiteRun(CuSuite* testSuite)
{
int i;
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
CuTestRun(testCase);
if (testCase->failed) { testSuite->failCount += 1; }
}
}
void CuSuiteSummary(CuSuite* testSuite, CuString* summary)
{
int i;
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
CuStringAppend(summary, testCase->failed ? "F" : ".");
}
CuStringAppend(summary, "\n\n");
}
void CuSuiteDetails(CuSuite* testSuite, CuString* details)
{
int i;
int failCount = 0;
if (testSuite->failCount == 0)
{
int passCount = testSuite->count - testSuite->failCount;
const char* testWord = passCount == 1 ? "test" : "tests";
CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord);
}
else
{
if (testSuite->failCount == 1)
CuStringAppend(details, "There was 1 failure:\n");
else
CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount);
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
if (testCase->failed)
{
failCount++;
CuStringAppendFormat(details, "%d) %s: %s\n",
failCount, testCase->name, testCase->message);
}
}
CuStringAppend(details, "\n!!!FAILURES!!!\n");
CuStringAppendFormat(details, "Runs: %d ", testSuite->count);
CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount);
CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
}
}
libsepol-3.8.1/cil/test/unit/CuTest.h000066400000000000000000000116141476211737200174360ustar00rootroot00000000000000/*
* Copyright (c) 2003 Asim Jalis
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in
* a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CU_TEST_H
#define CU_TEST_H
#include
#include
#define CUTEST_VERSION "CuTest 1.5"
/* CuString */
char* CuStrAlloc(int size);
char* CuStrCopy(const char* old);
#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
#define HUGE_STRING_LEN 8192
#define STRING_MAX 256
#define STRING_INC 256
typedef struct
{
int length;
int size;
char* buffer;
} CuString;
void CuStringInit(CuString* str);
CuString* CuStringNew(void);
void CuStringRead(CuString* str, const char* path);
void CuStringAppend(CuString* str, const char* text);
void CuStringAppendChar(CuString* str, char ch);
void CuStringAppendFormat(CuString* str, const char* format, ...);
void CuStringInsert(CuString* str, const char* text, int pos);
void CuStringResize(CuString* str, int newSize);
void CuStringDelete(CuString* str);
/* CuTest */
typedef struct CuTest CuTest;
typedef void (*TestFunction)(CuTest *);
struct CuTest
{
char* name;
TestFunction function;
int failed;
int ran;
const char* message;
jmp_buf *jumpBuf;
};
void CuTestInit(CuTest* t, const char* name, TestFunction function);
CuTest* CuTestNew(const char* name, TestFunction function);
void CuTestRun(CuTest* tc);
void CuTestDelete(CuTest *t);
/* Internal versions of assert functions -- use the public versions */
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition);
void CuAssertStrEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
const char* expected, const char* actual);
void CuAssertIntEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
int expected, int actual);
void CuAssertDblEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
double expected, double actual, double delta);
void CuAssertPtrEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
void* expected, void* actual);
/* public assert functions */
#define CuFail(tc, ms) CuFail_Line( (tc), __FILE__, __LINE__, NULL, (ms))
#define CuAssert(tc, ms, cond) CuAssert_Line((tc), __FILE__, __LINE__, (ms), (cond))
#define CuAssertTrue(tc, cond) CuAssert_Line((tc), __FILE__, __LINE__, "assert failed", (cond))
#define CuAssertStrEquals(tc,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl))
#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl))
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL))
#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL))
/* CuSuite */
#define MAX_TEST_CASES 1024
#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
typedef struct
{
int count;
CuTest* list[MAX_TEST_CASES];
int failCount;
} CuSuite;
void CuSuiteInit(CuSuite* testSuite);
CuSuite* CuSuiteNew(void);
void CuSuiteDelete(CuSuite *testSuite);
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
void CuSuiteRun(CuSuite* testSuite);
void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
void CuSuiteDetails(CuSuite* testSuite, CuString* details);
#endif /* CU_TEST_H */
libsepol-3.8.1/cil/test/unit/test_cil.c000066400000000000000000000125311476211737200200270ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "test_cil.h"
#include "../../src/cil_internal.h"
#include "../../src/cil_tree.h"
void test_cil_symtab_array_init(CuTest *tc) {
struct cil_db *test_new_db;
test_new_db = malloc(sizeof(*test_new_db));
cil_symtab_array_init(test_new_db->symtab, cil_sym_sizes[CIL_SYM_ARRAY_ROOT]);
CuAssertPtrNotNull(tc, test_new_db->symtab);
free(test_new_db);
}
void test_cil_db_init(CuTest *tc) {
struct cil_db *test_db;
cil_db_init(&test_db);
CuAssertPtrNotNull(tc, test_db->ast);
CuAssertPtrNotNull(tc, test_db->symtab);
CuAssertPtrNotNull(tc, test_db->symtab);
}
// TODO: Reach SEPOL_ERR return in cil_db_init ( currently can't produce a method to do so )
void test_cil_get_symtab_block(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->parent->flavor = CIL_BLOCK;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, symtab);
}
void test_cil_get_symtab_class(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->parent->flavor = CIL_CLASS;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, symtab);
}
void test_cil_get_symtab_root(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->parent->flavor = CIL_ROOT;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, symtab);
}
void test_cil_get_symtab_flavor_neg(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->parent->flavor = 1234567;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertPtrEquals(tc, symtab, NULL);
}
void test_cil_get_symtab_null_neg(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = NULL;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertPtrEquals(tc, symtab, NULL);
}
void test_cil_get_symtab_node_null_neg(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_get_symtab(test_db, test_ast_node, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertPtrEquals(tc, symtab, NULL);
CuAssertPtrEquals(tc, test_ast_node, NULL);
}
void test_cil_get_symtab_parent_null_neg(CuTest *tc) {
symtab_t *symtab = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = NULL;
test_ast_node->line = 1;
int rc = cil_get_symtab(test_db, test_ast_node->parent, &symtab, CIL_SYM_BLOCKS);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertPtrEquals(tc, symtab, NULL);
}
libsepol-3.8.1/cil/test/unit/test_cil.h000066400000000000000000000041301476211737200200300ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_H_
#define TEST_CIL_H_
#include "CuTest.h"
void test_cil_symtab_array_init(CuTest *);
void test_cil_symtab_array_init_null_symtab_neg(CuTest *);
void test_cil_db_init(CuTest *);
void test_cil_get_symtab_block(CuTest *);
void test_cil_get_symtab_class(CuTest *);
void test_cil_get_symtab_root(CuTest *);
void test_cil_get_symtab_flavor_neg(CuTest *);
void test_cil_get_symtab_null_neg(CuTest *);
void test_cil_get_symtab_node_null_neg(CuTest *);
void test_cil_get_symtab_parent_null_neg(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_build_ast.c000066400000000000000000021564561476211737200220760ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "CilTest.h"
#include "test_cil_build_ast.h"
#include "../../src/cil_build_ast.h"
#include "../../src/cil_tree.h"
int __cil_build_ast_node_helper(struct cil_tree_node *, uint32_t *, void *);
int __cil_build_ast_last_child_helper(__attribute__((unused)) struct cil_tree_node *parse_current, void *);
//int __cil_build_constrain_tree(struct cil_tree_node *parse_current, struct cil_tree_node *expr_root);
struct cil_args_build {
struct cil_tree_node *ast;
struct cil_db *db;
struct cil_tree_node *macro;
struct cil_tree_node *tifstack;
};
struct cil_args_build *gen_build_args(struct cil_tree_node *node, struct cil_db *db, struct cil_tree_node * macro, struct cil_tree_node *tifstack)
{
struct cil_args_build *args = cil_malloc(sizeof(*args));
args->ast = node;
args->db = db;
args->macro = macro;
args->tifstack = tifstack;
return args;
}
// First seen in cil_gen_common
void test_cil_parse_to_list(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
struct cil_avrule *test_avrule;
cil_avrule_init(&test_avrule);
test_avrule->rule_kind = CIL_AVRULE_ALLOWED;
test_avrule->src_str = cil_strdup(test_current->next->data);
test_avrule->tgt_str = cil_strdup(test_current->next->next->data);
cil_classpermset_init(&test_avrule->classpermset);
test_avrule->classpermset->class_str = cil_strdup(test_current->next->next->next->cl_head->data);
cil_permset_init(&test_avrule->classpermset->permset);
cil_list_init(&test_avrule->classpermset->permset->perms_list_str);
test_current = test_current->next->next->next->cl_head->next->cl_head;
int rc = cil_parse_to_list(test_current, test_avrule->classpermset->permset->perms_list_str, CIL_AST_STR);
CuAssertIntEquals(tc, SEPOL_OK, rc);
cil_destroy_avrule(test_avrule);
}
void test_cil_parse_to_list_currnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
struct cil_avrule *test_avrule;
cil_avrule_init(&test_avrule);
test_avrule->rule_kind = CIL_AVRULE_ALLOWED;
test_avrule->src_str = cil_strdup(test_current->next->data);
test_avrule->tgt_str = cil_strdup(test_current->next->next->data);
cil_classpermset_init(&test_avrule->classpermset);
test_avrule->classpermset->class_str = cil_strdup(test_current->next->next->next->cl_head->data);
cil_permset_init(&test_avrule->classpermset->permset);
cil_list_init(&test_avrule->classpermset->permset->perms_list_str);
test_current = NULL;
int rc = cil_parse_to_list(test_current, test_avrule->classpermset->permset->perms_list_str, CIL_AST_STR);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
cil_destroy_avrule(test_avrule);
}
void test_cil_parse_to_list_listnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
struct cil_avrule *test_avrule;
cil_avrule_init(&test_avrule);
test_avrule->rule_kind = CIL_AVRULE_ALLOWED;
test_avrule->src_str = cil_strdup(test_current->next->data);
test_avrule->tgt_str = cil_strdup(test_current->next->next->data);
cil_classpermset_init(&test_avrule->classpermset);
test_avrule->classpermset->class_str = cil_strdup(test_current->next->next->next->cl_head->data);
cil_permset_init(&test_avrule->classpermset->permset);
test_current = test_current->next->next->next->cl_head->next->cl_head;
int rc = cil_parse_to_list(test_current, test_avrule->classpermset->permset->perms_list_str, CIL_AST_STR);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
cil_destroy_avrule(test_avrule);
}
void test_cil_set_to_list(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", "(", "foo3", ")", ")", NULL};
struct cil_tree *test_tree;
struct cil_list *cil_l = NULL;
struct cil_list *sub_list = NULL;
gen_test_tree(&test_tree, line);
cil_list_init(&cil_l);
int rc = cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
sub_list = (struct cil_list *)cil_l->head->next->next->data;
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertStrEquals(tc, "foo1", (char*)cil_l->head->data);
CuAssertStrEquals(tc, "foo2", (char*)cil_l->head->next->data);
CuAssertStrEquals(tc, "foo3", (char*)sub_list->head->data);
}
void test_cil_set_to_list_tree_node_null_neg(CuTest *tc) {
struct cil_list *cil_l = NULL;
int rc = cil_set_to_list(NULL, cil_l, 1);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_set_to_list_cl_head_null_neg(CuTest *tc) {
char *line[] = {"(", "foo", "bar", ")", NULL};
struct cil_list *cil_l;
struct cil_tree *test_tree = NULL;
cil_list_init(&cil_l);
gen_test_tree(&test_tree, line);
test_tree->root->cl_head = NULL;
int rc = cil_set_to_list(test_tree->root, cil_l, 1);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_set_to_list_listnull_neg(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", "foo3", ")", NULL};
struct cil_tree *test_tree = NULL;
gen_test_tree(&test_tree, line);
int rc = cil_set_to_list(test_tree->root, NULL, 1);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, ((struct cil_block*)test_ast_node->data)->is_abstract, 0);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_BLOCK);
}
void test_cil_gen_block_justblock_neg(CuTest *tc) {
char *line[] = {"(", "block", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block_noname_neg(CuTest *tc) {
char *line[] = {"(", "block", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "block", "foo", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block_treenull_neg(CuTest *tc) {
char *line[] = {"(", "block", "foo", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_tree->root->cl_head->cl_head = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block_nodenull_neg(CuTest *tc) {
char *line[] = {"(", "block", "foo", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_block_nodeparentnull_neg(CuTest *tc) {
char *line[] = {"(", "block", "foo", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = NULL;
test_ast_node->line = 1;
int rc = cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_destroy_block(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
cil_destroy_block((struct cil_block*)test_ast_node->data);
CuAssertPtrEquals(tc, NULL,test_ast_node->data);
}
void test_cil_gen_blockinherit(CuTest *tc) {
char *line[] = {"(", "blockinherit", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_blockinherit_namelist_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_blockinherit_namenull_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_blockinherit_extra_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", "foo", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_blockinherit_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", "foo", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_blockinherit_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_blockinherit_astnull_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", "foo", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_blockinherit(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_perm(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_class *new_node;
cil_class_init(&new_node);
struct cil_tree_node *new_tree_node;
cil_tree_node_init(&new_tree_node);
new_tree_node->data = new_node;
new_tree_node->flavor = CIL_CLASS;
test_ast_node->parent = new_tree_node;
test_ast_node->line = 1;
int rc = cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node);
int rc1 = cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next, test_ast_node);
int rc2 = cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next->next, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc1);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_gen_perm_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
int rc = 0;
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current_perm = NULL;
struct cil_tree_node *test_new_ast = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
test_current_perm = test_tree->root->cl_head->cl_head->next->next->cl_head;
cil_tree_node_init(&test_new_ast);
test_new_ast->parent = test_ast_node;
test_new_ast->line = test_current_perm->line;
rc = cil_gen_perm(test_db, test_current_perm, test_new_ast);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_perm_currnull_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
int rc = 0;
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current_perm = NULL;
struct cil_tree_node *test_new_ast = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_current_perm = NULL;
cil_tree_node_init(&test_new_ast);
test_new_ast->parent = test_ast_node;
rc = cil_gen_perm(test_db, test_current_perm, test_new_ast);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_perm_astnull_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_class *new_node;
cil_class_init(&new_node);
struct cil_tree_node *new_tree_node;
cil_tree_node_init(&new_tree_node);
new_tree_node->data = new_node;
new_tree_node->flavor = CIL_CLASS;
int rc = cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_perm_nodenull_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
int rc = 0;
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_current_perm = NULL;
struct cil_tree_node *test_new_ast = NULL;
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
test_current_perm = test_tree->root->cl_head->cl_head->next->next->cl_head;
cil_tree_node_init(&test_new_ast);
test_new_ast->parent = test_ast_node;
test_new_ast->line = test_current_perm->line;
rc = cil_gen_perm(test_db, test_current_perm, test_new_ast);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_permset_noname_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "(", "foo", ")", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_noperms_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_emptyperms_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_extra_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_permset_astnull_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_permset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_perm_nodes(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_perm_nodes(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node, CIL_PERM);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_perm_nodes_failgen_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
cil_symtab_destroy(&test_cls->perms);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_perm_nodes(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node, CIL_PERM);
CuAssertIntEquals(tc, SEPOL_ENOMEM, rc);
}
void test_cil_gen_perm_nodes_inval_perm_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "(", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_perm_nodes(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node, CIL_PERM);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_permset(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_permset *permset;
cil_permset_init(&permset);
int rc = cil_fill_permset(test_tree->root->cl_head->cl_head->next->next->cl_head, permset);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_permset_sublist_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_permset *permset;
cil_permset_init(&permset);
int rc = cil_fill_permset(test_tree->root->cl_head->cl_head->next->next->cl_head, permset);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_permset_startpermnull_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_permset *permset;
cil_permset_init(&permset);
int rc = cil_fill_permset(test_tree->root->cl_head->cl_head->next->next->cl_head, permset);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_permset_permsetnull_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_permset *permset = NULL;
int rc = cil_fill_permset(test_tree->root->cl_head->cl_head->next->next->cl_head, permset);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_in(CuTest *tc) {
char *line[] = {"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_in_blockstrnull_neg(CuTest *tc) {
char *line[] = {"(", "in", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_in_extra_neg(CuTest *tc) {
char *line[] = {"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_in_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_in_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_in_astnull_neg(CuTest *tc) {
char *line[] = {"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_in(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->cl_tail);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_CLASS);
}
void test_cil_gen_class_noname_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_nodenull_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_currnull_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_tree->root->cl_head->cl_head = NULL;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_noclass_neg(CuTest *tc) {
char *line[] = {"(", "test", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_noclassname_neg(CuTest *tc) {
char *line[] = {"(", "class", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_namesublist_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_noperms(CuTest *tc) {
char *line[] = {"(", "class", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_class_permsnotinlist_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "read", "write", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_extrapermlist_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", "(", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_class_listinlist_neg(CuTest *tc) {
char *line[] = {"(", "class", "test", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_anonperms(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_classpermset_anonperms_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "write", "(", "extra", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_namedperms(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "perms", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_classpermset_extra_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "write", ")", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_emptypermslist_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_noperms_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_noclass_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_classnodenull_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_classpermset_cpsnull_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_classpermset *cps = NULL;
int rc = cil_fill_classpermset(test_tree->root->cl_head->cl_head->next->next->cl_head, cps);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classpermset_noname_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "(", "foo", ")", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_noclass_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_noperms_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", "char", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_emptyperms_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_extra_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", "read", "(", "write", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classpermset_astnull_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classpermset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_perm(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_classmap *map = NULL;
cil_classmap_init(&map);
test_ast_node->flavor = CIL_CLASSMAP;
test_ast_node->data = map;
struct cil_tree_node *test_ast_node_a;
cil_tree_node_init(&test_ast_node_a);
test_ast_node_a->parent = test_ast_node;
test_ast_node_a->line = test_tree->root->cl_head->cl_head->next->next->cl_head->line;
test_ast_node_a->path = test_tree->root->cl_head->cl_head->next->next->cl_head->path;
int rc = cil_gen_classmap_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node_a);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classmap_perm_dupeperm_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_ast_node_a;
cil_tree_node_init(&test_ast_node_a);
test_ast_node_a->parent = test_ast_node;
test_ast_node_a->line = test_tree->root->cl_head->cl_head->next->next->cl_head->line;
test_ast_node_a->path = test_tree->root->cl_head->cl_head->next->next->cl_head->path;
int rc = cil_gen_classmap_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node_a);
CuAssertIntEquals(tc, SEPOL_EEXIST, rc);
}
void test_cil_gen_classmap_perm_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_ast_node_a;
cil_tree_node_init(&test_ast_node_a);
test_ast_node_a->parent = test_ast_node;
test_ast_node_a->line = test_tree->root->cl_head->cl_head->line;
test_ast_node_a->path = test_tree->root->cl_head->cl_head->path;
test_db = NULL;
int rc = cil_gen_classmap_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node_a);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_perm_currnull_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_ast_node_a;
cil_tree_node_init(&test_ast_node_a);
test_ast_node_a->parent = test_ast_node;
test_ast_node_a->line = test_tree->root->cl_head->cl_head->line;
test_ast_node_a->path = test_tree->root->cl_head->cl_head->path;
int rc = cil_gen_classmap_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node_a);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_perm_astnull_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_ast_node_a = NULL;
int rc = cil_gen_classmap_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node_a);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classmap_extra_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_noname_neg(CuTest *tc) {
char *line[] = {"(", "classmap", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_emptyperms_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmap_astnull_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classmap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_anonpermset(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read",
"(", "file", "(", "open", "read", "getattr", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classmapping_anonpermset_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read",
"(", "file", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_namedpermset(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classmapping_noclassmapname_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_noclassmapperm_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_nopermissionsets_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read",
"(", "file", "(", "open", "read", "getattr", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classmapping_astnull_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read",
"(", "file", "(", "open", "read", "getattr", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classmapping(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_COMMON);
}
void test_cil_gen_common_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_astnull_neg(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_noname_neg(CuTest *tc) {
char *line[] = {"(", "common", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_twoperms_neg(CuTest *tc) {
char *line[] = {"(", "common", "foo", "(", "write", ")", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_permsublist_neg(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_common_noperms_neg(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid(CuTest *tc) {
char *line[] = {"(", "sid", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_sid_noname_neg(CuTest *tc) {
char *line[] = {"(", "sid", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "sid", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid_extra_neg(CuTest *tc) {
char *line[] = {"(", "sid", "foo", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sid", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sid_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sid", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah", "blah", "blah", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_SIDCONTEXT);
}
void test_cil_gen_sidcontext_namedcontext(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "something", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_SIDCONTEXT);
}
void test_cil_gen_sidcontext_halfcontext_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah", "blah", "blah", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_noname_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "(", "blah", "blah", "blah", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_empty_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_dblname_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "test2", "(", "blah", "blah", "blah", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah", "blah", "blah", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_pcurrnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sidcontext_astnodenull_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah", "blah", "blah", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, NULL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type(CuTest *tc) {
char *line[] = {"(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPE);
}
void test_cil_gen_type_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_astnull_neg(CuTest *tc) {
char *line[] = {"(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_extra_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", "bar," ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattribute(CuTest *tc) {
char *line[] = {"(", "typeattribute", "test", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPEATTRIBUTE);
}
void test_cil_gen_typeattribute_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattribute_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattribute_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattribute_extra_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "foo", "bar," ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_typebounds_notype1_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_type1inparens_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "(", "type_a", ")", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_notype2_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_type2inparens_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", "(", "type_b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_extra_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", "type_b", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typebounds_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_typebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive(CuTest *tc) {
char *line[] = {"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_typepermissive_noname_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive_typeinparens_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", "(", "type_a", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive_extra_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", "type_a", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typepermissive_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_typepermissive(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_nametypetransition_strinparens_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "(", "str", ")", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_nostr_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_srcinparens_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "(", "foo", ")", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_nosrc_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_tgtinparens_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "(", "bar", ")", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_notgt_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_classinparens_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "(", "file", ")", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_noclass_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_destinparens_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "(", "foobar", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_nodest_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_extra_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nametypetransition_astnull_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_nametypetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_rangetransition_namedtransition(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "namedtrans", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_rangetransition_anon_low_l(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "(", "s0", "(", "c0", ")", ")", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_rangetransition_anon_low_l_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "(", "s0", "(", ")", ")", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_anon_high_l(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_rangetransition_anon_high_l_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "(", "s0", "(", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_astnull_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_nofirsttype_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_firsttype_inparens_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "(", "type_a_t", ")", "type_b_t", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_nosecondtype_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_secondtype_inparens_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "(", "type_b_t", ")", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_noclass_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_class_inparens_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "(", "class", ")", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_nolevel_l_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_nolevel_h_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rangetransition_extra_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a_t", "type_b_t", "class", "(", "low_l", "high_l", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rangetransition(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_and(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_or(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "or", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_xor(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "xor", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_not(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "not", "foo", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_not_noexpr_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "not", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_not_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "not", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_eq(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "eq", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_neq(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "neq", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_nested(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "or", "(","neq", "foo", "bar", ")", "(", "eq", "baz", "boo", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_expr_stack_nested_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "(","neq", "foo", "bar", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_nested_emptyargs_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "eq", "(", ")", "(", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_nested_missingoperator_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "or", "(","foo", "bar", ")", "(", "eq", "baz", "boo", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_arg1null_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "eq", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_arg2null_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "eq", "foo", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_extraarg_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "eq", "foo", "bar", "extra", ")",
"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_currnull_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_booleanif *bif;
cil_boolif_init(&bif);
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, &bif->expr_stack);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_expr_stack_stacknull_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "xor", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_expr_stack(test_tree->root->cl_head->cl_head->next, CIL_BOOL, NULL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_multiplebools_true(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_multiplebools_false(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "false", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_multiplebools_unknowncond_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "dne", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_true(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_false(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "false", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_unknowncond_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "dne", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_nested(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "(", "or", "foo", "bar", ")", "baz", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_nested_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "(", "or", "foo", "bar", ")", "baz", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_extra_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "(", "or", "foo", "bar", ")", "baz", "beef", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_extra_parens_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "(", "or", "foo", "bar", ")", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_nocond(CuTest *tc) {
char *line[] = {"(", "booleanif", "baz",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_boolif_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "**", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_astnull_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_nocond_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_notruelist_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_boolif_empty_cond_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_multiplebools_true(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_multiplebools_false(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "false", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_multiplebools_unknowncond_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")",
"(", "dne", "(", "allow", "foo", "bar", "(", "write", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_true(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_false(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "false", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_unknowncond_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "dne", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_nocond(CuTest *tc) {
char *line[] = {"(", "tunableif", "baz",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_nested(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "(", "or", "foo", "bar", ")", "baz", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_tunif_nested_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "(", "or", "foo", "bar", ")", "baz", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_extra_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "(", "or", "foo", "bar", ")", "baz", "beef", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_extra_parens_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "(", "or", "foo", "bar", ")", ")",
"(", "true", "(", "allow", "foo", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "**", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_astnull_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true", "(", "allow", "foo", "bar", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_nocond_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_tunif_notruelist_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_tunif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_condblock_true(CuTest *tc) {
char *line[] = {"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDTRUE);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_condblock_false(CuTest *tc) {
char *line[] = {"(", "false", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDFALSE);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_condblock_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "false", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDFALSE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_condblock_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDFALSE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_condblock_astnull_neg(CuTest *tc) {
char *line[] = {"(", "false", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDFALSE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_condblock_nocond_neg(CuTest *tc) {
char *line[] = {"(", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDTRUE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_condblock_extra_neg(CuTest *tc) {
char *line[] = {"(", "true", "(", "allow", "foo", "bar", "baz", "(", "read", ")", ")", "Extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_condblock(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_CONDTRUE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertStrEquals(tc, ((struct cil_typealias*)test_ast_node->data)->type_str, test_tree->root->cl_head->cl_head->next->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPEALIAS);
}
void test_cil_gen_typealias_incomplete_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias_incomplete_neg2(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias_extratype_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "foo", "extra_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typealias_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "test_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
}
void test_cil_gen_typeattributeset_and_two_types(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "and", "test_t", "test2_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
}
void test_cil_gen_typeattributeset_not(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "not", "notypes_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
}
void test_cil_gen_typeattributeset_exclude_attr(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "not", "attr", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
}
void test_cil_gen_typeattributeset_exclude_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "not", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "not", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "not", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_noname_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "(", "filetypes", ")", "(", "test_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_emptylists_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_listinparens_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "(", "test_t", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_typeattributeset_extra_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "test_t", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_typeattributeset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userbounds(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_gen_userbounds_notype1_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_type1_inparens_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "(", "user1", ")", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_notype2_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_type2_inparens_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "(", "user2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_extra_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "user2", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_userbounds_astnull_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_userbounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_role(CuTest *tc) {
char *line[] = {"(", "role", "test_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_ROLE);
}
void test_cil_gen_role_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "role", "test_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_role_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_role_astnull_neg(CuTest *tc) {
char *line[] = {"(", "role", "test_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_role_extrarole_neg(CuTest *tc) {
char *line[] = {"(", "role", "test_r", "extra_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_role_noname_neg(CuTest *tc) {
char *line[] = {"(", "role", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_ROLETRANSITION);
}
void test_cil_gen_roletransition_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletransition(NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition_astnull_neg (CuTest *tc) {
char *line[] = {"(", "roletransition" "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition_srcnull_neg(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition_tgtnull_neg(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next->next = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition_resultnull_neg(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next->next->next->next = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletransition_extra_neg(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletransition(test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_true(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, ((struct cil_bool*)test_ast_node->data)->value, 1);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_BOOL);
}
void test_cil_gen_bool_tunable_true(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_TUNABLE);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, ((struct cil_bool*)test_ast_node->data)->value, 1);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TUNABLE);
}
void test_cil_gen_bool_false(CuTest *tc) {
char *line[] = {"(", "boolean", "bar", "false", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, ((struct cil_bool*)test_ast_node->data)->value, 0);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_BOOL);
}
void test_cil_gen_bool_tunable_false(CuTest *tc) {
char *line[] = {"(", "tunable", "bar", "false", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_TUNABLE);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, ((struct cil_bool*)test_ast_node->data)->value, 0);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TUNABLE);
}
void test_cil_gen_bool_none_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_astnull_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_notbool_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_boolname_neg(CuTest *tc) {
char *line[] = {"(", "boolean", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_extraname_false_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "false", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_bool_extraname_true_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_t1type(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_t1t1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "t1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_t2type(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t2", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_t2t2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t2", "t2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_r1role(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_r1r1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_r2role(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r2", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_r2r2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r2", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_t1t2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "t2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_r1r2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_r1r2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_u1u2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u1", "u2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_u1user(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u1", "user_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_u1u1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u1", "u1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_u2user(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u2", "user_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_u2u2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u2", "u2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l2h2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l1l2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l1h1(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "h1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l1h2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_h1l2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "h1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_h1h2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "h1", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq_h1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "h1", "l1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l1l1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_l1l2_constrain_neg(CuTest *tc) {
char *line[] = {"(", "constrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_CONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_l1l2_constrain_neg(CuTest *tc) {
char *line[] = {"(", "constrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_CONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_leftkeyword_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "h2", "h1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_eq2_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_noteq(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_noteq_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_noteq_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_noteq_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_noteq_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_noteq_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "neq", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_not(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "not", "(", "neq", "l2", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_not_noexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "not", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_not_emptyparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "not", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_not_extraparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "not", "(", "neq", "l2", "h2", ")", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or",
"(", "neq", "l1", "l2", ")", "(", "neq", "l1", "h1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_or_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or",
"(", "foo", ")", "(", "neq", "l1", "h1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or_noexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or_emptyfirstparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or_missingsecondexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or", "(", "foo", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or_emptysecondparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or", "(", "foo", ")", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_or_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "or", "(", "foo", ")", "(", "foo", ")", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and",
"(", "neq", "l1", "l2", ")", "(", "neq", "l1", "h1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_and_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and",
"(", "foo", ")", "(", "neq", "l1", "h1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and_noexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and_emptyfirstparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and_missingsecondexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and", "(", "foo", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and_emptysecondparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and", "(", "foo", ")", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_and_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "and", "(", "foo", ")", "(", "foo", ")", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_dom(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_dom_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_dom_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_dom_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_dom_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_dom_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dom", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_domby(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_domby_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_domby_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_domby_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_domby_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_domby_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "domby", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incomp(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_expr_stack_incomp_noexpr1_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incomp_expr1inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", "(", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incomp_noexpr2_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", "l1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incomp_expr2inparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", "l1", "(", "h2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incomp_extraexpr_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "incomp", "foo", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_currnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_stacknull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, NULL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_operatorinparens_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "(", "eq", ")", "t1", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expr_stack_incorrectcall_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *parse_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *cons;
cil_constrain_init(&cons);
cil_classpermset_init(&cons->classpermset);
cil_fill_classpermset(parse_current->next->cl_head, cons->classpermset);
int rc = cil_gen_expr_stack(parse_current->next->next->cl_head->next->next, CIL_MLSCONSTRAIN, &cons->expr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow(CuTest *tc) {
char *line[] = {"(", "roleallow", "staff_r", "sysadm_r", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertStrEquals(tc, ((struct cil_roleallow*)test_ast_node->data)->src_str, test_current->next->data);
CuAssertStrEquals(tc, ((struct cil_roleallow*)test_ast_node->data)->tgt_str, test_current->next->next->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_ROLEALLOW);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_roleallow_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_roleallow(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow_astnull_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow_srcnull_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow_tgtnull_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roleallow_extra_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "foo", "bar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roleallow(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_rolebounds(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_gen_rolebounds_norole1_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_role1_inparens_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "(", "role1", ")", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_norole2_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_role2_inparens_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "(", "role2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_extra_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "role2", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_rolebounds_astnull_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_rolebounds(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
void test_cil_gen_avrule(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertStrEquals(tc, ((struct cil_avrule*)test_ast_node->data)->src_str, test_current->next->data);
CuAssertStrEquals(tc, ((struct cil_avrule*)test_ast_node->data)->tgt_str, test_current->next->next->data);
CuAssertStrEquals(tc, ((struct cil_avrule*)test_ast_node->data)->classpermset->class_str, test_current->next->next->next->cl_head->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_AVRULE);
CuAssertPtrNotNull(tc, ((struct cil_avrule*)test_ast_node->data)->classpermset->permset->perms_list_str);
struct cil_list_item *test_list = ((struct cil_avrule*)test_ast_node->data)->classpermset->permset->perms_list_str->head;
test_current = test_current->next->next->next->cl_head->next->cl_head;
while(test_list != NULL) {
CuAssertIntEquals(tc, test_list->flavor, CIL_AST_STR);
CuAssertStrEquals(tc, test_list->data, test_current->data );
test_list = test_list->next;
test_current = test_current->next;
}
}
void test_cil_gen_avrule_permset(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "permset", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_avrule_permset_anon(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_avrule_extra_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "permset", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_sourceparens(CuTest *tc) {
char *line[] = {"(", "allow", "(", "test", ")", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_sourceemptyparen_neg(CuTest *tc) {
char *line[] = {"(", "allow", "(", ")", "bar", "file", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_targetparens(CuTest *tc) {
char *line[] = {"(", "allow", "test", "(", "foo", ")", "bar", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_targetemptyparen_neg(CuTest *tc) {
char *line[] = {"(", "allow", "bar", "(", ")", "file", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_astnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "bar", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_sourcedomainnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_targetdomainnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_objectclassnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_permsnull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "foo", "bar", "(", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_avrule_twolists_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "bar", "(", "write", ")", "(", "read", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
int rc = cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->src_str, test_tree->root->cl_head->cl_head->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->tgt_str, test_tree->root->cl_head->cl_head->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->obj_str, test_tree->root->cl_head->cl_head->next->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->result_str, test_tree->root->cl_head->cl_head->next->next->next->next->data);
CuAssertIntEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->rule_kind, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPE_RULE);
}
void test_cil_gen_type_rule_transition_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_type_rule(NULL, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_srcnull_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_tgtnull_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_objnull_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_resultnull_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_transition_extra_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->src_str, test_tree->root->cl_head->cl_head->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->tgt_str, test_tree->root->cl_head->cl_head->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->obj_str, test_tree->root->cl_head->cl_head->next->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->result_str, test_tree->root->cl_head->cl_head->next->next->next->next->data);
CuAssertIntEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->rule_kind, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPE_RULE);
}
void test_cil_gen_type_rule_change_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_type_rule(NULL, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_srcnull_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_tgtnull_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_objnull_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_resultnull_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_change_extra_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_CHANGE);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->src_str, test_tree->root->cl_head->cl_head->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->tgt_str, test_tree->root->cl_head->cl_head->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->obj_str, test_tree->root->cl_head->cl_head->next->next->next->data);
CuAssertStrEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->result_str, test_tree->root->cl_head->cl_head->next->next->next->next->data);
CuAssertIntEquals(tc, ((struct cil_type_rule*)test_ast_node->data)->rule_kind, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_TYPE_RULE);
}
void test_cil_gen_type_rule_member_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_type_rule(NULL, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_astnull_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_srcnull_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_tgtnull_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_objnull_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_resultnull_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
test_tree->root->cl_head->cl_head->next->next->next->next = NULL;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_type_rule_member_extra_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_MEMBER);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_user(CuTest *tc) {
char *line[] = {"(", "user", "sysadm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, CIL_USER, test_ast_node->flavor);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertPtrEquals(tc, test_ast_node, ((struct cil_symtab_datum*)test_ast_node->data)->node);
CuAssertStrEquals(tc, test_tree->root->cl_head->cl_head->next->data, ((struct cil_symtab_datum*)test_ast_node->data)->name);
}
void test_cil_gen_user_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "user", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_user_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_user_astnull_neg(CuTest *tc) {
char *line[] = {"(", "user", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_user_nouser_neg(CuTest *tc) {
char *line[] = {"(", "user", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_user_xsinfo_neg(CuTest *tc) {
char *line[] = {"(", "user", "sysadm", "xsinfo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", "lvl_l", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_userlevel_anon_level(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", "(", "s0", "(", "c0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_userlevel_anon_level_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", "(", "s0", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_usernull_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_userrange_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "(", "user", ")", "level", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_levelnull_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_levelrangeempty_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_extra_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user_u", "level", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user", "level", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userlevel_astnull_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "user", "level", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_userlevel(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_named(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_userrange_anon(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_userrange_usernull_neg(CuTest *tc) {
char *line[] = {"(", "userrange", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_anonuser_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "(", "user_u", ")", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_rangenamenull_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_anonrangeinvalid_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", "(", "low", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_anonrangeempty_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_extra_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user_u", "(", "low", "high", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrange_astnull_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "user", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_userrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_ast_node->data);
CuAssertIntEquals(tc, test_ast_node->flavor, CIL_SENS);
}
void test_cil_gen_sensitivity_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_sensitivity(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity_sensnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity_senslist_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "(", "s0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensitivity_extra_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_sensalias_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_currnull_neg(CuTest *tc) {
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_sensalias(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init (&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_sensnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_senslist_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "(", "s0", "s1", ")", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_aliasnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_aliaslist_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "(", "alias", "alias2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_sensalias_extra_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_category_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category_astnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category_currnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_category(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category_catnull_neg(CuTest *tc){
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category_catlist_neg(CuTest *tc){
char *line[] = {"(", "category", "(", "c0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_category_extra_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_catset_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_currnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_astnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_namenull_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_setnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_namelist_neg(CuTest *tc) { //This should fail before gen_node call - additional syntax checks are needed
char *line[] = {"(", "categoryset", "(", "somecats", ")", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_extra_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_notset_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "blah", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
// TODO: This doesn't actually test failure of gen_node
void test_cil_gen_catset_nodefail_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "(", "c3", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catset_settolistfail_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catset(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_catalias_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias_currnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catalias(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias_astnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias_catnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias_aliasnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root->cl_head->cl_head->next->next = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catalias_extra_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_catrange_noname_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_norange_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_emptyrange_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_extrarange_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, NULL, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_astnull_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catrange_extra_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype(CuTest *tc) {
char *line[] = {"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_roletype_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype_astnull_neg(CuTest *tc) {
char *line[] = {"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype_empty_neg(CuTest *tc) {
char *line[] = {"(", "roletype", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype_rolelist_neg(CuTest *tc) {
char *line[] = {"(", "roletype", "(", "admin_r", ")", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
// TODO
// Not sure this is actually testing roletype
// I think this will just test that type is null
void test_cil_gen_roletype_roletype_sublist_neg(CuTest *tc) {
char *line[] = {"(", "(", "roletype", "admin_r", ")", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_roletype_typelist_neg(CuTest *tc) {
char *line[] = {"(", "roletype", "admin_r", "(", "admin_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_roletype(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_userrole_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole_astnull_neg(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole_empty_neg(CuTest *tc) {
char *line[] = {"(", "userrole", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole_userlist_neg(CuTest *tc) {
char *line[] = {"(", "userrole", "(", "staff_u", ")", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
//TODO: see above
void test_cil_gen_userrole_userrole_sublist_neg(CuTest *tc) {
char *line[] = {"(", "(", "userrole", "staff_u", ")", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_userrole_rolelist_neg(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "(", "staff_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_classcommon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon_missingclassname_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon_noperms_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_classcommon_extraperms_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
int rc = cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_catorder_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db = NULL;
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder_currnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder_astnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node = NULL;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder_missingcats_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder_nosublist_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "c0", "c255", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_catorder_nestedcat_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "(", "c255", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_dominance_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_dominance_currnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_dominance_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_dominance_nosensitivities_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_dominance_nosublist_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "s0", "s2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_senscat_nosublist(CuTest *tc) {
char *line[] = {"(", "sensitivitycategory", "s1", "c0", "c255", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_senscat_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat_currnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat_nosensitivities_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat_sublist_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "(", "c255", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_senscat_nocat_neg(CuTest *tc) {
char *line[] = {"(", "sensitivitycategory", "s1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_senscat(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_level(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_level *test_level;
cil_level_init(&test_level);
int rc = cil_fill_level(test_tree->root->cl_head->next->next->cl_head->next->next->cl_head, test_level);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_level_sensnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_level *test_level;
cil_level_init(&test_level);
int rc = cil_fill_level(test_tree->root->cl_head->next->next->cl_head->next->next, test_level);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_level_levelnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_level *test_level = NULL;
int rc = cil_fill_level(test_tree->root->cl_head->next->next->cl_head->next->next->cl_head, test_level);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_level_nocat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_level *test_level;
cil_level_init(&test_level);
int rc = cil_fill_level(test_tree->root->cl_head->next->next->cl_head->next->next->cl_head, test_level);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_level_emptycat_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_level *test_level;
cil_level_init(&test_level);
int rc = cil_fill_level(test_tree->root->cl_head->next->next->cl_head->next->next->cl_head, test_level);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_level_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "level", "(", "low", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_emptysensparens_neg(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_extra_neg(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", "s0", "(", "c0", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_emptycat_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_noname_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_nosens_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_currnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_level_astnull_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_level(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_levelrange_rangeinvalid_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_namenull_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_rangenull_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_rangeempty_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_extra_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_levelrange_astnull_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_levelrange(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_constrain_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "dne", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_classset_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_classset_noclass_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_classset_noperm_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_permset_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_permset_noclass_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_permset_noperm_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_expression_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_constrain_astnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "node_lo_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_context_unnamedlvl(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "node_lo_t", "(", "(", "s0", ")", "(", "s0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_context_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "node_lo_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context = NULL;
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_nouser_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_norole_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_notype_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_nolowlvl_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_nohighlvl_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "type_t", "(", "low", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_unnamedlvl_nocontextlow_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "type_t", "(", "s0", "(", ")", ")", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_context_unnamedlvl_nocontexthigh_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "type_t", "low", "(", "s0", "(", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_context *test_context;
cil_context_init(&test_context);
int rc = cil_fill_context(test_tree->root->cl_head->cl_head->next->next->cl_head, test_context);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_context_notinparens_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_extralevel_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_emptycontext_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_extra_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", "(", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_doubleparen_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "(", "system_u", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_norole_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_roleinparens_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "(", "role_r", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_notype_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_typeinparens_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "role_r", "(", "type_t", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_nolevels_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "role_r", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_nosecondlevel_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "role_r", "type_t", "(", "low", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_noname_neg(CuTest *tc) {
char *line[] = {"(", "context", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_nouser_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "node_lo_t", "(", "s0", ")", "(", "s0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_context_astnull_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "system_u", "object_r", "node_lo_t", "(", "s0", ")", "(", "s0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_dir(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "dir", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_file(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_char(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "char", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_block(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "block", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_socket(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "socket", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_pipe(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "pipe", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_symlink(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "symlink", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_any(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "any", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "dne", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_anon_context(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_filecon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_str1null_neg(CuTest *tc) {
char *line[] = {"(", "filecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_str1_inparens_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "(", "root", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_str2null_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_str2_inparens_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "(", "path", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_classnull_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_class_inparens_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "(", "file", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_contextnull_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_context_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "(", "system_u", "object_r", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_filecon_extra_neg(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "context", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_filecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_udp(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "80", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_portcon_tcp(CuTest *tc) {
char *line[] = {"(", "portcon", "tcp", "80", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_portcon_unknownprotocol_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "unknown", "80", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_anon_context(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "80", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_portcon_portrange(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "25", "75", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_portcon_portrange_one_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "0", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_portrange_morethanone_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "0", "1", "2", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_singleport_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "foo", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_lowport_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "foo", "90", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_highport_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "80", "foo", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "0", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "(", "0", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_str1null_neg(CuTest *tc) {
char *line[] = {"(", "portcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_str1parens_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "(", "80", ")", "port", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_portnull_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_contextnull_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "port", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_context_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "80", "(", "system_u", "object_r", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_portcon_extra_neg(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "80", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_portcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_ipaddr(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_nodecon *nodecon;
cil_nodecon_init(&nodecon);
cil_ipaddr_init(&nodecon->addr);
int rc = cil_fill_ipaddr(test_tree->root->cl_head->cl_head->next->cl_head, nodecon->addr);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_fill_ipaddr_addrnodenull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_nodecon *nodecon;
cil_nodecon_init(&nodecon);
cil_ipaddr_init(&nodecon->addr);
int rc = cil_fill_ipaddr(NULL, nodecon->addr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_ipaddr_addrnull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_nodecon *nodecon;
cil_nodecon_init(&nodecon);
nodecon->addr = NULL;
int rc = cil_fill_ipaddr(test_tree->root->cl_head->cl_head->next->cl_head, nodecon->addr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_ipaddr_addrinparens_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "(", "192.168.1.1", ")", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_nodecon *nodecon;
cil_nodecon_init(&nodecon);
cil_ipaddr_init(&nodecon->addr);
int rc = cil_fill_ipaddr(test_tree->root->cl_head->cl_head->next->cl_head, nodecon->addr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_fill_ipaddr_extra_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", "extra", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_nodecon *nodecon;
cil_nodecon_init(&nodecon);
cil_ipaddr_init(&nodecon->addr);
int rc = cil_fill_ipaddr(test_tree->root->cl_head->cl_head->next->cl_head, nodecon->addr);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_nodecon_anon_context(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_nodecon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_ipnull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_ipanon(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_nodecon_ipanon_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.1.1", ")", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_netmasknull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_netmaskanon(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "(", "255.255.255.4", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_nodecon_netmaskanon_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "(", "str0", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_contextnull_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_context_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "(", "system_u", "object_r", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_nodecon_extra_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "(", "system_u", "object_r", "type_t", "(", "low", "high", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_genfscon_anon_context(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_genfscon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_typenull_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_typeparens_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "(", "type", ")", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_pathnull_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_pathparens_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "(", "path", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_contextnull_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_context_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "(", "system_u", "object_r", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_genfscon_extra_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_genfscon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_netifcon_nested(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_netifcon_nested_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "(", "eth1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_nested_emptysecondlist_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_extra_nested_secondlist_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "extra",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_nested_missingobjects_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_nested_secondnested_missingobjects_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_ethmissing_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_interfacemissing_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_netifcon_packetmissing_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_pirqcon_pirqnotint_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "notint", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_nopirq_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_pirqrange_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "(", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_anoncontext_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "(", "con", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_extra_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pirqcon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_pirqcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_iomemcon_iomemrange(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", "1", "2", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_iomemcon_iomemrange_firstnotint_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", "foo", "2", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_iomemrange_secondnotint_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", "1", "foo", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_iomemrange_empty_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_iomemrange_singleiomem_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_iomemrange_morethantwoiomem_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "(", "1", "2", "3", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_iomemnotint_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "notint", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_noiomem_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_anoncontext_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "(", "con", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_extra_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_iomemcon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_iomemcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_ioportcon_ioportrange(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", "1", "2", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_ioportcon_ioportrange_firstnotint_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", "foo", "2", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_ioportrange_secondnotint_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", "1", "foo", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_ioportrange_empty_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_ioportrange_singleioport_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_ioportrange_morethantwoioport_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "(", "1", "2", "3", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_ioportnotint_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "notint", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_noioport_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_anoncontext_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "(", "con", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_extra_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ioportcon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_ioportcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_pcidevicecon_pcidevicenotint_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "notint", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_nopcidevice_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_pcidevicerange_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "(", "1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_anoncontext_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "(", "con", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_extra_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_pcidevicecon_astnull_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_pcidevicecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_anoncontext(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_fsuse_anoncontext_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "(", "system_u", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_xattr(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_fsuse_task(CuTest *tc) {
char *line[] = {"(", "fsuse", "task", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_fsuse_transition(CuTest *tc) {
char *line[] = {"(", "fsuse", "trans", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_fsuse_invalidtype_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "foo", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_notype_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_typeinparens_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "(", "xattr", ")", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_nofilesystem_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_filesysteminparens_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "(", "ext3", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_emptyconparens_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_extra_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "con", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_fsuse_astnull_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_fsuse(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_noparams(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", ")", "(", "type", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_type(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a", ")", ")", "(", "type", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_role(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "role", "a", ")", ")", "(", "role", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_user(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "user", "a", ")", ")", "(", "user", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_sensitivity(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "sensitivity", "a", ")", ")", "(", "sensitivity", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_category(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "category", "a", ")", ")", "(", "category", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_catset(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "categoryset", "a", ")", ")", "(", "categoryset", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_level(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "level", "a", ")", ")", "(", "level", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_class(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "class", "a", ")", ")", "(", "class", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_classmap(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "classmap", "a", ")", ")", "(", "classmap", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_permset(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "permissionset", "a", ")", ")",
"(", "allow", "foo", "bar", "baz", "a", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_duplicate(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "class", "a",")", "(", "class", "x", ")", ")", "(", "class", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_macro_duplicate_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "class", "a",")", "(", "class", "a", ")", ")", "(", "class", "b", "(", "read," ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_unknown_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "foo", "a", ")", ")", "(", "foo", "b", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "foo", "a", ")", ")", "(", "foo", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_astnull_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "foo", "a", ")", ")", "(", "foo", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node = NULL;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_unnamed_neg(CuTest *tc) {
char *line[] = {"(", "macro", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_noparam_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_nosecondparam_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "foo", "a", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_noparam_name_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_emptyparam_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", ")", ")", "(", "foo", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_macro_paramcontainsperiod_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a.", ")", ")", "(", "type", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_macro(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_call_noargs(CuTest *tc) {
char *line[] = {"(", "call", "mm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_call_anon(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_call_empty_call_neg(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call_astnull_neg(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call_name_inparens_neg(CuTest *tc) {
char *line[] = {"(", "call", "(", "mm", ")", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_call_noname_neg(CuTest *tc) {
char *line[] = {"(", "call", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_optional_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_astnull_neg(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_unnamed_neg(CuTest *tc) {
char *line[] = {"(", "optional", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_extra_neg(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "optional", "(", "opt", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_optional_emptyoptional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_optional_norule_neg(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap(CuTest *tc) {
char *line[] = {"(", "policycap", "open_perms", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_policycap_noname_neg(CuTest *tc) {
char *line[] = {"(", "policycap", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "policycap", "(", "pol", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_extra_neg(CuTest *tc) {
char *line[] = {"(", "policycap", "pol", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "policycap", "pol", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_astnull_neg(CuTest *tc) {
char *line[] = {"(", "policycap", "pol", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_policycap_neg(CuTest *tc) {
char *line[] = {"(", "policycap", "pol", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_policycap(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_ipv4(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_ipaddr_ipv4_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", ".168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_ipv6(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_gen_ipaddr_ipv6_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "2001:0db8:85a3:0000:0000:8a2e:0370:::7334", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_noname_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_nameinparens_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "(", "ip", ")", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_noip_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_ipinparens_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "(", "192.168.1.1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_extra_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db = NULL;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_currnull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_gen_ipaddr_astnull_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
/*
cil_build_ast test cases
*/
void test_cil_build_ast(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_build_ast(test_db, test_tree->root, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_dbnull_neg(CuTest *tc) {
char *line[] = {"(", "test", "\"qstring\"", ")", ";comment", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *null_db = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_build_ast(null_db, test_tree->root, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_astnull_neg(CuTest *tc) {
char *line[] = {"(", "test", "\"qstring\"", ")", ";comment", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
test_db->ast->root = NULL;
int rc = cil_build_ast(test_db, test_tree->root, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_suberr_neg(CuTest *tc) {
char *line[] = {"(", "block", "test", "(", "block", "(", "type", "log", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = cil_build_ast(test_db, test_tree->root, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_treenull_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "bar", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
test_tree->root = NULL;
struct cil_db *test_db;
cil_db_init(&test_db);
test_db->ast->root = NULL;
int rc = cil_build_ast(test_db, test_tree->root, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_block(CuTest *tc) {
char *line[] = {"(", "block", "test", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_block_neg(CuTest *tc) {
char *line[] = {"(", "block", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_blockinherit(CuTest *tc) {
char *line[] = {"(", "blockinherit", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_blockinherit_neg(CuTest *tc) {
char *line[] = {"(", "blockinherit", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_permset(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, CIL_TREE_SKIP_NEXT, finished);
}
void test_cil_build_ast_node_helper_permset_neg(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_in(CuTest *tc) {
char *line[] = {"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_in_neg(CuTest *tc) {
char *line[] = {"(", "in", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_class(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_class_neg(CuTest *tc) {
char *line[] = {"(", "class", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_classpermset(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", "(", "read", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, CIL_TREE_SKIP_NEXT, finished);
}
void test_cil_build_ast_node_helper_classpermset_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_classmap(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_classmap_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_classmapping(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_classmapping_neg(CuTest *tc) {
char *line[] = {"(", "classmapping", "files", "read", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_common(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_common_neg(CuTest *tc) {
char *line[] = {"(", "common", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sid(CuTest *tc) {
char *line[] = {"(", "sid", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_sid_neg(CuTest *tc) {
char *line[] = {"(", "sid", "(", "blah", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sidcontext(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah", "blah", "blah", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_sidcontext_neg(CuTest *tc) {
char *line[] = {"(", "sidcontext", "(", "blah", "blah", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_user(CuTest *tc) {
char *line[] = {"(", "user", "jimmypage", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_user_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo", "bar", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_userlevel(CuTest *tc) {
char *line[] = {"(", "userlevel", "johnpauljones", "level", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_userlevel_neg(CuTest *tc) {
char *line[] = {"(", "userlevel", "johnpauljones", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_userrange(CuTest *tc) {
char *line[] = {"(", "userrange", "johnpauljones", "range", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_userrange_neg(CuTest *tc) {
char *line[] = {"(", "userrange", "johnpauljones", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type(CuTest *tc) {
char *line[] = {"(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_neg(CuTest *tc) {
char *line[] = {"(", "type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_attribute(CuTest *tc) {
char *line[] = {"(", "typeattribute", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_attribute_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typebounds(CuTest *tc) {
char *line[] = {"(", "typebounds", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typebounds_neg(CuTest *tc) {
char *line[] = {"(", "typebounds", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typepermissive(CuTest *tc) {
char *line[] = {"(", "typepermissive", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typepermissive_neg(CuTest *tc) {
char *line[] = {"(", "typepermissive", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_nametypetransition(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_nametypetransition_neg(CuTest *tc) {
char *line[] = {"(", "nametypetransition", "str", "foo", "bar", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_rangetransition(CuTest *tc) {
char *line[] = {"(", "rangetransition", "type_a", "type_b", "class", "(", "low_l", "high_l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_rangetransition_neg(CuTest *tc) {
char *line[] = {"(", "rangetransition", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_boolif(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_boolif_neg(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "*&", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_condblock_true(CuTest *tc) {
char *line[] = {"(", "true", "(", "allow", "foo", "bar", "baz", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_condblock_true_neg(CuTest *tc) {
char *line[] = {"(", "true", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_condblock_false(CuTest *tc) {
char *line[] = {"(", "false", "(", "allow", "foo", "bar", "baz", "(", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_condblock_false_neg(CuTest *tc) {
char *line[] = {"(", "false", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_tunif(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_tunif_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "*&", "foo", "bar", ")",
"(", "allow", "foo", "bar", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typealias(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typealias_notype_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typeattribute(CuTest *tc)
{
char *line[] = {"(", "typeattribute", "type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typeattribute_neg(CuTest *tc)
{
char *line[] = {"(", "typeattribute", ".fail.type", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_typeattributeset(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "filetypes", "(", "and", "test_t", "test2_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_typeattributeset_neg(CuTest *tc) {
char *line[] = {"(", "typeattributeset", "files", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_userbounds(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_userbounds_neg(CuTest *tc) {
char *line[] = {"(", "userbounds", "user1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_role(CuTest *tc) {
char *line[] = {"(", "role", "test_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_role_neg(CuTest *tc) {
char *line[] = {"(", "role", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_roletransition(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_roletransition_neg(CuTest *tc) {
char *line[] = {"(", "roletransition", "foo_r", "bar_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_roleallow(CuTest *tc) {
char *line[] = {"(", "roleallow", "staff_r", "sysadm_r", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_roleallow_neg(CuTest *tc) {
char *line[] = {"(", "roleallow", "staff_r", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_rolebounds(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_rolebounds_neg(CuTest *tc) {
char *line[] = {"(", "rolebounds", "role1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_avrule_allow(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_avrule_allow_neg(CuTest *tc) {
char *line[] = {"(", "allow", "foo", "bar", "(", "read", "write", ")", "blah", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_avrule_auditallow(CuTest *tc) {
char *line[] = {"(", "auditallow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_avrule_auditallow_neg(CuTest *tc) {
char *line[] = {"(", "auditallow", "foo", "bar", "(", "read", "write", ")", "blah", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_avrule_dontaudit(CuTest *tc) {
char *line[] = {"(", "dontaudit", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_avrule_dontaudit_neg(CuTest *tc) {
char *line[] = {"(", "dontaudit", "foo", "bar", "(", "read", "write", ")", "blah", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_avrule_neverallow(CuTest *tc) {
char *line[] = {"(", "neverallow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_avrule_neverallow_neg(CuTest *tc) {
char *line[] = {"(", "neverallow", "foo", "bar", "(", "read", "write", ")", "blah", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_transition(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_transition_neg(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_change(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_change_neg(CuTest *tc) {
char *line[] = {"(", "typechange", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_member(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_type_rule_member_neg(CuTest *tc) {
char *line[] = {"(", "typemember", "foo", "bar", "file", "foobar", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_bool(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_bool_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_bool_tunable(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_bool_tunable_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sensitivity(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sensitivity_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_sensalias_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_category(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_category_neg(CuTest *tc) {
char *line[] = {"(", "category", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_catset(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_catset_neg(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_catorder(CuTest *tc) {
char *line[] = {"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_catorder_neg(CuTest *tc) {
char *line[] = {"(", "categoryorder", "c0", "c1", "c2", "extra", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_catalias(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_catalias_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "range", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_catrange(CuTest *tc) {
char *line[] = {"(", "categoryrange", "range", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 1, finished);
}
void test_cil_build_ast_node_helper_catrange_neg(CuTest *tc) {
char *line[] = {"(", "categoryrange", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_build_ast_node_helper_roletype(CuTest *tc) {
char *line[] = {"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_roletype_neg(CuTest *tc) {
char *line[] = {"(", "roletype", "(", "admin_r", ")", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_userrole(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_userrole_neg(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "(", "staff_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_classcommon(CuTest *tc) {
char *line[] = {"(", "classcommon", "foo", "foo", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_classcommon_neg(CuTest *tc) {
char *line[] = {"(", "classcommon", "staff_u", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_dominance_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->next->next->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_senscat_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->next->next->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_level(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_level_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "low", "(", "s0", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->next->next->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_levelrange(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_levelrange_neg(CuTest *tc) {
char *line[] = {"(", "levelrange", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_constrain(CuTest *tc) {
char *line[] = {"(", "constrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_constrain_neg(CuTest *tc) {
char *line[] = {"(", "constrain", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_mlsconstrain(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_mlsconstrain_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_context(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", "node_lo_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_context_neg(CuTest *tc) {
char *line[] = {"(", "context", "localhost_node_label", "(", "system_u", "object_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_filecon(CuTest *tc) {
char *line[] = {"(", "filecon", "root", "path", "file", "context", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_filecon_neg(CuTest *tc) {
char *line[] = {"(", "filecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_portcon(CuTest *tc) {
char *line[] = {"(", "portcon", "udp", "25", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_portcon_neg(CuTest *tc) {
char *line[] = {"(", "portcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_nodecon(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_nodecon_neg(CuTest *tc) {
char *line[] = {"(", "nodecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_genfscon(CuTest *tc) {
char *line[] = {"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_genfscon_neg(CuTest *tc) {
char *line[] = {"(", "genfscon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_netifcon(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_netifcon_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_pirqcon(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_pirqcon_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_iomemcon(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_iomemcon_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_ioportcon(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_ioportcon_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_pcidevicecon(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_pcidevicecon_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_fsuse(CuTest *tc) {
char *line[] = {"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_fsuse_neg(CuTest *tc) {
char *line[] = {"(", "fsuse", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_macro(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a", ")", ")", "(", "type", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_macro_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_macro_nested_macro_neg(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a", ")", ")", "(", "type", "b", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_macro *macro;
cil_macro_init(¯o);
struct cil_tree_node *macronode;
cil_tree_node_init(¯onode);
macronode->data = macro;
macronode->flavor = CIL_MACRO;
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, macronode, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
cil_db_destroy(&test_db);
cil_destroy_macro(macro);
}
void test_cil_build_ast_node_helper_gen_macro_nested_tunif_neg(CuTest *tc) {
char *line[] = {"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "allow", "foo", "bar", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_macro *macro;
cil_macro_init(¯o);
struct cil_tree_node *macronode;
cil_tree_node_init(¯onode);
macronode->data = macro;
macronode->flavor = CIL_MACRO;
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, macronode, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
cil_db_destroy(&test_db);
cil_destroy_macro(macro);
}
void test_cil_build_ast_node_helper_gen_call(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_call_neg(CuTest *tc) {
char *line[] = {"(", "call", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_optional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_optional_neg(CuTest *tc) {
char *line[] = {"(", "optional", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_policycap(CuTest *tc) {
char *line[] = {"(", "policycap", "open_perms", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 1);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_policycap_neg(CuTest *tc) {
char *line[] = {"(", "policycap", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_gen_ipaddr(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_node_helper_gen_ipaddr_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_node_helper_extraargsnull_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_args_build *extra_args = NULL;
uint32_t finished = 0;
int rc = __cil_build_ast_node_helper(test_tree->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_build_ast_last_child_helper(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_args_build *extra_args = gen_build_args(test_db->ast->root, test_db, NULL, NULL);
int rc = __cil_build_ast_last_child_helper(test_tree->root->cl_head->cl_head, extra_args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_build_ast_last_child_helper_extraargsnull_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
int rc = __cil_build_ast_last_child_helper(test_tree->root->cl_head->cl_head, NULL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
libsepol-3.8.1/cil/test/unit/test_cil_build_ast.h000066400000000000000000001562351476211737200220740ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_BUILD_AST_H_
#define TEST_CIL_BUILD_AST_H_
#include "CuTest.h"
void test_cil_parse_to_list(CuTest *);
void test_cil_parse_to_list_currnull_neg(CuTest *);
void test_cil_parse_to_list_listnull_neg(CuTest *);
void test_cil_set_to_list(CuTest *);
void test_cil_set_to_list_tree_node_null_neg(CuTest *);
void test_cil_set_to_list_cl_head_null_neg(CuTest *);
void test_cil_set_to_list_listnull_neg(CuTest *);
void test_cil_gen_block(CuTest *);
void test_cil_gen_block_justblock_neg(CuTest *);
void test_cil_gen_block_noname_neg(CuTest *);
void test_cil_gen_block_dbnull_neg(CuTest *);
void test_cil_gen_block_treenull_neg(CuTest *);
void test_cil_gen_block_nodenull_neg(CuTest *);
void test_cil_gen_block_nodeparentnull_neg(CuTest *);
void test_cil_destroy_block(CuTest *);
void test_cil_gen_blockinherit(CuTest *);
void test_cil_gen_blockinherit_namelist_neg(CuTest *);
void test_cil_gen_blockinherit_namenull_neg(CuTest *);
void test_cil_gen_blockinherit_extra_neg(CuTest *);
void test_cil_gen_blockinherit_dbnull_neg(CuTest *);
void test_cil_gen_blockinherit_currnull_neg(CuTest *);
void test_cil_gen_blockinherit_astnull_neg(CuTest *);
void test_cil_gen_perm(CuTest *);
void test_cil_gen_perm_noname_neg(CuTest *);
void test_cil_gen_perm_dbnull_neg(CuTest *);
void test_cil_gen_perm_currnull_neg(CuTest *);
void test_cil_gen_perm_astnull_neg(CuTest *);
void test_cil_gen_perm_nodenull_neg(CuTest *);
void test_cil_gen_permset(CuTest *);
void test_cil_gen_permset_noname_neg(CuTest *);
void test_cil_gen_permset_nameinparens_neg(CuTest *);
void test_cil_gen_permset_noperms_neg(CuTest *);
void test_cil_gen_permset_emptyperms_neg(CuTest *);
void test_cil_gen_permset_extra_neg(CuTest *);
void test_cil_gen_permset_dbnull_neg(CuTest *);
void test_cil_gen_permset_currnull_neg(CuTest *);
void test_cil_gen_permset_astnull_neg(CuTest *);
void test_cil_gen_perm_nodes(CuTest *);
void test_cil_gen_perm_nodes_failgen_neg(CuTest *);
void test_cil_gen_perm_nodes_inval_perm_neg(CuTest *);
void test_cil_fill_permset(CuTest *);
void test_cil_fill_permset_sublist_neg(CuTest *);
void test_cil_fill_permset_startpermnull_neg(CuTest *);
void test_cil_fill_permset_permsetnull_neg(CuTest *);
void test_cil_gen_in(CuTest *);
void test_cil_gen_in_blockstrnull_neg(CuTest *);
void test_cil_gen_in_extra_neg(CuTest *);
void test_cil_gen_in_dbnull_neg(CuTest *);
void test_cil_gen_in_currnull_neg(CuTest *);
void test_cil_gen_in_astnull_neg(CuTest *);
void test_cil_gen_class(CuTest *);
void test_cil_gen_class_noname_neg(CuTest *);
void test_cil_gen_class_nodenull_neg(CuTest *);
void test_cil_gen_class_dbnull_neg(CuTest *);
void test_cil_gen_class_currnull_neg(CuTest *);
void test_cil_gen_class_noclass_neg(CuTest *);
void test_cil_gen_class_noclassname_neg(CuTest *);
void test_cil_gen_class_namesublist_neg(CuTest *);
void test_cil_gen_class_noperms(CuTest *);
void test_cil_gen_class_permsnotinlist_neg(CuTest *);
void test_cil_gen_class_extrapermlist_neg(CuTest *);
void test_cil_gen_class_listinlist_neg(CuTest *);
void test_cil_fill_classpermset_anonperms(CuTest *);
void test_cil_fill_classpermset_anonperms_neg(CuTest *);
void test_cil_fill_classpermset_namedperms(CuTest *);
void test_cil_fill_classpermset_extra_neg(CuTest *);
void test_cil_fill_classpermset_emptypermslist_neg(CuTest *);
void test_cil_fill_classpermset_noperms_neg(CuTest *);
void test_cil_fill_classpermset_noclass_neg(CuTest *);
void test_cil_fill_classpermset_classnodenull_neg(CuTest *);
void test_cil_fill_classpermset_cpsnull_neg(CuTest *);
void test_cil_gen_classpermset(CuTest *);
void test_cil_gen_classpermset_noname_neg(CuTest *);
void test_cil_gen_classpermset_nameinparens_neg(CuTest *);
void test_cil_gen_classpermset_noclass_neg(CuTest *);
void test_cil_gen_classpermset_noperms_neg(CuTest *);
void test_cil_gen_classpermset_emptyperms_neg(CuTest *);
void test_cil_gen_classpermset_extra_neg(CuTest *);
void test_cil_gen_classpermset_dbnull_neg(CuTest *);
void test_cil_gen_classpermset_currnull_neg(CuTest *);
void test_cil_gen_classpermset_astnull_neg(CuTest *);
void test_cil_gen_classmap_perm(CuTest *);
void test_cil_gen_classmap_perm_dupeperm_neg(CuTest *);
void test_cil_gen_classmap_perm_dbnull_neg(CuTest *tc);
void test_cil_gen_classmap_perm_currnull_neg(CuTest *tc);
void test_cil_gen_classmap_perm_astnull_neg(CuTest *tc);
void test_cil_gen_classmap(CuTest *);
void test_cil_gen_classmap_extra_neg(CuTest *);
void test_cil_gen_classmap_noname_neg(CuTest *);
void test_cil_gen_classmap_emptyperms_neg(CuTest *);
void test_cil_gen_classmap_dbnull_neg(CuTest *tc);
void test_cil_gen_classmap_currnull_neg(CuTest *tc);
void test_cil_gen_classmap_astnull_neg(CuTest *tc);
void test_cil_gen_classmapping_anonpermset(CuTest *);
void test_cil_gen_classmapping_anonpermset_neg(CuTest *);
void test_cil_gen_classmapping_namedpermset(CuTest *);
void test_cil_gen_classmapping_noclassmapname_neg(CuTest *);
void test_cil_gen_classmapping_noclassmapperm_neg(CuTest *);
void test_cil_gen_classmapping_nopermissionsets_neg(CuTest *);
void test_cil_gen_classmapping_emptyperms_neg(CuTest *);
void test_cil_gen_classmapping_dbnull_neg(CuTest *tc);
void test_cil_gen_classmapping_currnull_neg(CuTest *tc);
void test_cil_gen_classmapping_astnull_neg(CuTest *tc);
void test_cil_gen_common(CuTest *);
void test_cil_gen_common_dbnull_neg(CuTest *tc);
void test_cil_gen_common_currnull_neg(CuTest *tc);
void test_cil_gen_common_astnull_neg(CuTest *tc);
void test_cil_gen_common_noname_neg(CuTest *tc);
void test_cil_gen_common_twoperms_neg(CuTest *tc);
void test_cil_gen_common_permsublist_neg(CuTest *tc);
void test_cil_gen_common_noperms_neg(CuTest *tc);
void test_cil_gen_sid(CuTest *);
void test_cil_gen_sid_noname_neg(CuTest *);
void test_cil_gen_sid_nameinparens_neg(CuTest *);
void test_cil_gen_sid_extra_neg(CuTest *);
void test_cil_gen_sid_dbnull_neg(CuTest *);
void test_cil_gen_sid_currnull_neg(CuTest *);
void test_cil_gen_sid_astnull_neg(CuTest *);
void test_cil_gen_sidcontext(CuTest *);
void test_cil_gen_sidcontext_namedcontext(CuTest *);
void test_cil_gen_sidcontext_halfcontext_neg(CuTest *);
void test_cil_gen_sidcontext_noname_neg(CuTest *);
void test_cil_gen_sidcontext_empty_neg(CuTest *);
void test_cil_gen_sidcontext_nocontext_neg(CuTest *);
void test_cil_gen_sidcontext_dblname_neg(CuTest *);
void test_cil_gen_sidcontext_dbnull_neg(CuTest *);
void test_cil_gen_sidcontext_pcurrnull_neg(CuTest *);
void test_cil_gen_sidcontext_astnodenull_neg(CuTest *);
void test_cil_gen_type(CuTest *);
void test_cil_gen_type_neg(CuTest *);
void test_cil_gen_type_dbnull_neg(CuTest *tc);
void test_cil_gen_type_currnull_neg(CuTest *tc);
void test_cil_gen_type_astnull_neg(CuTest *tc);
void test_cil_gen_type_extra_neg(CuTest *tc);
void test_cil_gen_typeattribute(CuTest *);
void test_cil_gen_typeattribute_dbnull_neg(CuTest *tc);
void test_cil_gen_typeattribute_currnull_neg(CuTest *tc);
void test_cil_gen_typeattribute_astnull_neg(CuTest *tc);
void test_cil_gen_typeattribute_extra_neg(CuTest *tc);
void test_cil_gen_typeattr(CuTest *);
void test_cil_gen_typeattr_dbnull_neg(CuTest *);
void test_cil_gen_typeattr_currnull_neg(CuTest *);
void test_cil_gen_typeattr_astnull_neg(CuTest *);
void test_cil_gen_typeattr_typenull_neg(CuTest *);
void test_cil_gen_typeattr_attrnull_neg(CuTest *);
void test_cil_gen_typeattr_attrlist_neg(CuTest *);
void test_cil_gen_typeattr_extra_neg(CuTest *);
void test_cil_gen_typebounds(CuTest *);
void test_cil_gen_typebounds_notype1_neg(CuTest *);
void test_cil_gen_typebounds_type1inparens_neg(CuTest *);
void test_cil_gen_typebounds_notype2_neg(CuTest *);
void test_cil_gen_typebounds_type2inparens_neg(CuTest *);
void test_cil_gen_typebounds_extra_neg(CuTest *);
void test_cil_gen_typebounds_dbnull_neg(CuTest *);
void test_cil_gen_typebounds_currnull_neg(CuTest *);
void test_cil_gen_typebounds_astnull_neg(CuTest *);
void test_cil_gen_typepermissive(CuTest *);
void test_cil_gen_typepermissive_noname_neg(CuTest *);
void test_cil_gen_typepermissive_typeinparens_neg(CuTest *);
void test_cil_gen_typepermissive_extra_neg(CuTest *);
void test_cil_gen_typepermissive_dbnull_neg(CuTest *);
void test_cil_gen_typepermissive_currnull_neg(CuTest *);
void test_cil_gen_typepermissive_astnull_neg(CuTest *);
void test_cil_gen_nametypetransition(CuTest *);
void test_cil_gen_nametypetransition_nostr_neg(CuTest *);
void test_cil_gen_nametypetransition_strinparens_neg(CuTest *);
void test_cil_gen_nametypetransition_nosrc_neg(CuTest *);
void test_cil_gen_nametypetransition_srcinparens_neg(CuTest *);
void test_cil_gen_nametypetransition_notgt_neg(CuTest *);
void test_cil_gen_nametypetransition_tgtinparens_neg(CuTest *);
void test_cil_gen_nametypetransition_noclass_neg(CuTest *);
void test_cil_gen_nametypetransition_classinparens_neg(CuTest *);
void test_cil_gen_nametypetransition_nodest_neg(CuTest *);
void test_cil_gen_nametypetransition_destinparens_neg(CuTest *);
void test_cil_gen_nametypetransition_extra_neg(CuTest *);
void test_cil_gen_nametypetransition_dbnull_neg(CuTest *);
void test_cil_gen_nametypetransition_currnull_neg(CuTest *);
void test_cil_gen_nametypetransition_astnull_neg(CuTest *);
void test_cil_gen_rangetransition(CuTest *);
void test_cil_gen_rangetransition_namedtransition(CuTest *);
void test_cil_gen_rangetransition_anon_low_l(CuTest *);
void test_cil_gen_rangetransition_anon_low_l_neg(CuTest *);
void test_cil_gen_rangetransition_anon_high_l(CuTest *);
void test_cil_gen_rangetransition_anon_high_l_neg(CuTest *);
void test_cil_gen_rangetransition_dbnull_neg(CuTest *);
void test_cil_gen_rangetransition_currnull_neg(CuTest *);
void test_cil_gen_rangetransition_astnull_neg(CuTest *);
void test_cil_gen_rangetransition_nofirsttype_neg(CuTest *);
void test_cil_gen_rangetransition_firsttype_inparens_neg(CuTest *);
void test_cil_gen_rangetransition_nosecondtype_neg(CuTest *);
void test_cil_gen_rangetransition_secondtype_inparens_neg(CuTest *);
void test_cil_gen_rangetransition_noclass_neg(CuTest *);
void test_cil_gen_rangetransition_class_inparens_neg(CuTest *);
void test_cil_gen_rangetransition_nolevel_l_neg(CuTest *);
void test_cil_gen_rangetransition_nolevel_h_neg(CuTest *);
void test_cil_gen_rangetransition_extra_neg(CuTest *);
void test_cil_gen_expr_stack_and(CuTest *);
void test_cil_gen_expr_stack_or(CuTest *);
void test_cil_gen_expr_stack_xor(CuTest *);
void test_cil_gen_expr_stack_not(CuTest *);
void test_cil_gen_expr_stack_not_noexpr_neg(CuTest *);
void test_cil_gen_expr_stack_not_extraexpr_neg(CuTest *);
void test_cil_gen_expr_stack_eq(CuTest *);
void test_cil_gen_expr_stack_neq(CuTest *);
void test_cil_gen_expr_stack_nested(CuTest *);
void test_cil_gen_expr_stack_nested_neg(CuTest *);
void test_cil_gen_expr_stack_nested_emptyargs_neg(CuTest *);
void test_cil_gen_expr_stack_nested_missingoperator_neg(CuTest *);
void test_cil_gen_expr_stack_arg1null_neg(CuTest *);
void test_cil_gen_expr_stack_arg2null_neg(CuTest *);
void test_cil_gen_expr_stack_extraarg_neg(CuTest *);
void test_cil_gen_expr_stack_currnull_neg(CuTest *);
void test_cil_gen_expr_stack_stacknull_neg(CuTest *);
void test_cil_gen_boolif_multiplebools_true(CuTest *);
void test_cil_gen_boolif_multiplebools_false(CuTest *);
void test_cil_gen_boolif_multiplebools_unknowncond_neg(CuTest *);
void test_cil_gen_boolif_true(CuTest *);
void test_cil_gen_boolif_false(CuTest *);
void test_cil_gen_boolif_unknowncond_neg(CuTest *);
void test_cil_gen_boolif_nested(CuTest *);
void test_cil_gen_boolif_nested_neg(CuTest *);
void test_cil_gen_boolif_extra_neg(CuTest *);
void test_cil_gen_boolif_extra_parens_neg(CuTest *);
void test_cil_gen_boolif_nocond(CuTest *);
void test_cil_gen_boolif_neg(CuTest *);
void test_cil_gen_boolif_dbnull_neg(CuTest *);
void test_cil_gen_boolif_currnull_neg(CuTest *);
void test_cil_gen_boolif_astnull_neg(CuTest *);
void test_cil_gen_boolif_nocond_neg(CuTest *);
void test_cil_gen_boolif_notruelist_neg(CuTest *);
void test_cil_gen_boolif_empty_cond_neg(CuTest *);
void test_cil_gen_else(CuTest *);
void test_cil_gen_else_neg(CuTest *);
void test_cil_gen_else_dbnull_neg(CuTest *);
void test_cil_gen_else_currnull_neg(CuTest *);
void test_cil_gen_else_astnull_neg(CuTest *);
void test_cil_gen_tunif_multiplebools_true(CuTest *);
void test_cil_gen_tunif_multiplebools_false(CuTest *);
void test_cil_gen_tunif_multiplebools_unknowncond_neg(CuTest *);
void test_cil_gen_tunif_true(CuTest *);
void test_cil_gen_tunif_false(CuTest *);
void test_cil_gen_tunif_unknowncond_neg(CuTest *);
void test_cil_gen_tunif_nocond(CuTest *);
void test_cil_gen_tunif_nested(CuTest *);
void test_cil_gen_tunif_nested_neg(CuTest *);
void test_cil_gen_tunif_extra_neg(CuTest *);
void test_cil_gen_tunif_extra_parens_neg(CuTest *);
void test_cil_gen_tunif_neg(CuTest *);
void test_cil_gen_tunif_dbnull_neg(CuTest *);
void test_cil_gen_tunif_currnull_neg(CuTest *);
void test_cil_gen_tunif_astnull_neg(CuTest *);
void test_cil_gen_tunif_nocond_neg(CuTest *);
void test_cil_gen_tunif_notruelist_neg(CuTest *);
void test_cil_gen_condblock_true(CuTest *);
void test_cil_gen_condblock_false(CuTest *);
void test_cil_gen_condblock_dbnull_neg(CuTest *);
void test_cil_gen_condblock_currnull_neg(CuTest *);
void test_cil_gen_condblock_astnull_neg(CuTest *);
void test_cil_gen_condblock_nocond_neg(CuTest *);
void test_cil_gen_condblock_extra_neg(CuTest *);
void test_cil_gen_typealias(CuTest *);
void test_cil_gen_typealias_incomplete_neg(CuTest *);
void test_cil_gen_typealias_incomplete_neg2(CuTest *);
void test_cil_gen_typealias_extratype_neg(CuTest *);
void test_cil_gen_typealias_dbnull_neg(CuTest *tc);
void test_cil_gen_typealias_currnull_neg(CuTest *tc);
void test_cil_gen_typealias_astnull_neg(CuTest *tc);
void test_cil_gen_typeattributeset(CuTest *);
void test_cil_gen_typeattributeset_and_two_types(CuTest *);
void test_cil_gen_typeattributeset_not(CuTest *);
void test_cil_gen_typeattributeset_exclude_attr(CuTest *);
void test_cil_gen_typeattributeset_exclude_neg(CuTest *);
void test_cil_gen_typeattributeset_dbnull_neg(CuTest *);
void test_cil_gen_typeattributeset_currnull_neg(CuTest *);
void test_cil_gen_typeattributeset_astnull_neg(CuTest *);
void test_cil_gen_typeattributeset_noname_neg(CuTest *);
void test_cil_gen_typeattributeset_nameinparens_neg(CuTest *);
void test_cil_gen_typeattributeset_emptylists_neg(CuTest *);
void test_cil_gen_typeattributeset_listinparens_neg(CuTest *);
void test_cil_gen_typeattributeset_extra_neg(CuTest *);
void test_cil_gen_userbounds(CuTest *);
void test_cil_gen_userbounds_notype1_neg(CuTest *);
void test_cil_gen_userbounds_type1_inparens_neg(CuTest *);
void test_cil_gen_userbounds_notype2_neg(CuTest *);
void test_cil_gen_userbounds_type2_inparens_neg(CuTest *);
void test_cil_gen_userbounds_extra_neg(CuTest *);
void test_cil_gen_userbounds_dbnull_neg(CuTest *);
void test_cil_gen_userbounds_currnull_neg(CuTest *);
void test_cil_gen_userbounds_astnull_neg(CuTest *);
void test_cil_gen_role(CuTest *);
void test_cil_gen_role_dbnull_neg(CuTest *tc);
void test_cil_gen_role_currnull_neg(CuTest *tc);
void test_cil_gen_role_astnull_neg(CuTest *tc);
void test_cil_gen_role_extrarole_neg(CuTest *tc);
void test_cil_gen_role_noname_neg(CuTest *tc);
void test_cil_gen_roletransition(CuTest *);
void test_cil_gen_roletransition_currnull_neg(CuTest *);
void test_cil_gen_roletransition_astnull_neg(CuTest *);
void test_cil_gen_roletransition_srcnull_neg(CuTest *);
void test_cil_gen_roletransition_tgtnull_neg(CuTest *);
void test_cil_gen_roletransition_resultnull_neg(CuTest *);
void test_cil_gen_roletransition_extra_neg(CuTest *);
void test_cil_gen_bool_true(CuTest *);
void test_cil_gen_bool_tunable_true(CuTest *);
void test_cil_gen_bool_false(CuTest *);
void test_cil_gen_bool_tunable_false(CuTest *);
void test_cil_gen_bool_none_neg(CuTest *);
void test_cil_gen_bool_dbnull_neg(CuTest *);
void test_cil_gen_bool_currnull_neg(CuTest *);
void test_cil_gen_bool_astnull_neg(CuTest *);
void test_cil_gen_bool_notbool_neg(CuTest *);
void test_cil_gen_bool_boolname_neg(CuTest *);
void test_cil_gen_bool_extraname_false_neg(CuTest *);
void test_cil_gen_bool_extraname_true_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_t1type(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_t1t1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_t2type(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_t2t2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_r1role(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_r1r1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_r2role(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_r2r2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_t1t2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_r1r2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_r1r2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_u1u2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_u1user(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_u1u1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_u2user(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_u2u2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l2h2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l1l2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l1h1(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l1h2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_h1l2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_h1h2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_h1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l1l1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_l1l2_constrain_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_l1l2_constrain_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_leftkeyword_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_eq2_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_noteq_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_not(CuTest *);
void test_cil_gen_constrain_expr_stack_not_noexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_not_emptyparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_not_extraparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or(CuTest *);
void test_cil_gen_constrain_expr_stack_or_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or_noexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or_emptyfirstparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or_missingsecondexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or_emptysecondparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_or_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and(CuTest *);
void test_cil_gen_constrain_expr_stack_and_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and_noexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and_emptyfirstparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and_missingsecondexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and_emptysecondparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_and_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_dom(CuTest *);
void test_cil_gen_constrain_expr_stack_dom_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_dom_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_dom_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_dom_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_dom_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_domby(CuTest *);
void test_cil_gen_constrain_expr_stack_domby_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_domby_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_domby_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_domby_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_domby_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp_noexpr1_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp_expr1inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp_noexpr2_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp_expr2inparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incomp_extraexpr_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_currnull_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_stacknull_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_operatorinparens_neg(CuTest *);
void test_cil_gen_constrain_expr_stack_incorrectcall_neg(CuTest *);
void test_cil_gen_roleallow(CuTest *);
void test_cil_gen_roleallow_dbnull_neg(CuTest *);
void test_cil_gen_roleallow_currnull_neg(CuTest *);
void test_cil_gen_roleallow_astnull_neg(CuTest *);
void test_cil_gen_roleallow_srcnull_neg(CuTest *);
void test_cil_gen_roleallow_tgtnull_neg(CuTest *);
void test_cil_gen_roleallow_extra_neg(CuTest *);
void test_cil_gen_rolebounds(CuTest *);
void test_cil_gen_rolebounds_norole1_neg(CuTest *);
void test_cil_gen_rolebounds_role1_inparens_neg(CuTest *);
void test_cil_gen_rolebounds_norole2_neg(CuTest *);
void test_cil_gen_rolebounds_role2_inparens_neg(CuTest *);
void test_cil_gen_rolebounds_extra_neg(CuTest *);
void test_cil_gen_rolebounds_dbnull_neg(CuTest *);
void test_cil_gen_rolebounds_currnull_neg(CuTest *);
void test_cil_gen_rolebounds_astnull_neg(CuTest *);
void test_cil_gen_avrule(CuTest *);
void test_cil_gen_avrule_permset(CuTest *);
void test_cil_gen_avrule_permset_anon(CuTest *);
void test_cil_gen_avrule_extra_neg(CuTest *);
void test_cil_gen_avrule_sourceparens(CuTest *);
void test_cil_gen_avrule_sourceemptyparen_neg(CuTest *);
void test_cil_gen_avrule_targetparens(CuTest *);
void test_cil_gen_avrule_targetemptyparen_neg(CuTest *);
void test_cil_gen_avrule_currnull_neg(CuTest *tc);
void test_cil_gen_avrule_astnull_neg(CuTest *tc);
void test_cil_gen_avrule_sourcedomainnull_neg(CuTest *tc);
void test_cil_gen_avrule_targetdomainnull_neg(CuTest *tc);
void test_cil_gen_avrule_objectclassnull_neg(CuTest *tc);
void test_cil_gen_avrule_permsnull_neg(CuTest *tc);
void test_cil_gen_avrule_twolists_neg(CuTest *);
//TODO: add cases to cover parse_current->next->cl_head != NULL || parse_current->next->next->cl_head != NULL
// || parse_current->next->next->next->cl_head != NULL
void test_cil_gen_type_rule_transition(CuTest *);
void test_cil_gen_type_rule_transition_currnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_astnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_srcnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_tgtnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_objnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_resultnull_neg(CuTest *);
void test_cil_gen_type_rule_transition_extra_neg(CuTest *);
void test_cil_gen_type_rule_change(CuTest *);
void test_cil_gen_type_rule_change_currnull_neg(CuTest *);
void test_cil_gen_type_rule_change_astnull_neg(CuTest *);
void test_cil_gen_type_rule_change_srcnull_neg(CuTest *);
void test_cil_gen_type_rule_change_tgtnull_neg(CuTest *);
void test_cil_gen_type_rule_change_objnull_neg(CuTest *);
void test_cil_gen_type_rule_change_resultnull_neg(CuTest *);
void test_cil_gen_type_rule_change_extra_neg(CuTest *);
void test_cil_gen_type_rule_member(CuTest *);
void test_cil_gen_type_rule_member_currnull_neg(CuTest *);
void test_cil_gen_type_rule_member_astnull_neg(CuTest *);
void test_cil_gen_type_rule_member_srcnull_neg(CuTest *);
void test_cil_gen_type_rule_member_tgtnull_neg(CuTest *);
void test_cil_gen_type_rule_member_objnull_neg(CuTest *);
void test_cil_gen_type_rule_member_resultnull_neg(CuTest *);
void test_cil_gen_type_rule_member_extra_neg(CuTest *);
void test_cil_gen_user(CuTest *);
void test_cil_gen_user_dbnull_neg(CuTest *);
void test_cil_gen_user_currnull_neg(CuTest *);
void test_cil_gen_user_astnull_neg(CuTest *);
void test_cil_gen_user_nouser_neg(CuTest *);
void test_cil_gen_user_xsinfo_neg(CuTest *);
void test_cil_gen_userlevel(CuTest *);
void test_cil_gen_userlevel_anon_level(CuTest *);
void test_cil_gen_userlevel_anon_level_neg(CuTest *);
void test_cil_gen_userlevel_usernull_neg(CuTest *);
void test_cil_gen_userlevel_userrange_neg(CuTest *);
void test_cil_gen_userlevel_levelnull_neg(CuTest *);
void test_cil_gen_userlevel_levelrangeempty_neg(CuTest *);
void test_cil_gen_userlevel_extra_neg(CuTest *);
void test_cil_gen_userlevel_dbnull_neg(CuTest *);
void test_cil_gen_userlevel_currnull_neg(CuTest *);
void test_cil_gen_userlevel_astnull_neg(CuTest *);
void test_cil_gen_userrange_named(CuTest *);
void test_cil_gen_userrange_anon(CuTest *);
void test_cil_gen_userrange_usernull_neg(CuTest *);
void test_cil_gen_userrange_anonuser_neg(CuTest *);
void test_cil_gen_userrange_rangenamenull_neg(CuTest *);
void test_cil_gen_userrange_anonrangeinvalid_neg(CuTest *);
void test_cil_gen_userrange_anonrangeempty_neg(CuTest *);
void test_cil_gen_userrange_extra_neg(CuTest *);
void test_cil_gen_userrange_dbnull_neg(CuTest *);
void test_cil_gen_userrange_currnull_neg(CuTest *);
void test_cil_gen_userrange_astnull_neg(CuTest *);
void test_cil_gen_sensitivity(CuTest *);
void test_cil_gen_sensitivity_dbnull_neg(CuTest *);
void test_cil_gen_sensitivity_currnull_neg(CuTest *);
void test_cil_gen_sensitivity_astnull_neg(CuTest *);
void test_cil_gen_sensitivity_sensnull_neg(CuTest *);
void test_cil_gen_sensitivity_senslist_neg(CuTest *);
void test_cil_gen_sensitivity_extra_neg(CuTest *);
void test_cil_gen_sensalias(CuTest *);
void test_cil_gen_sensalias_dbnull_neg(CuTest *);
void test_cil_gen_sensalias_currnull_neg(CuTest *);
void test_cil_gen_sensalias_astnull_neg(CuTest *);
void test_cil_gen_sensalias_sensnull_neg(CuTest *);
void test_cil_gen_sensalias_senslist_neg(CuTest *);
void test_cil_gen_sensalias_aliasnull_neg(CuTest *);
void test_cil_gen_sensalias_aliaslist_neg(CuTest *);
void test_cil_gen_sensalias_extra_neg(CuTest *);
void test_cil_gen_category(CuTest *);
void test_cil_gen_category_dbnull_neg(CuTest *);
void test_cil_gen_category_astnull_neg(CuTest *);
void test_cil_gen_category_currnull_neg(CuTest *);
void test_cil_gen_category_catnull_neg(CuTest *);
void test_cil_gen_category_catlist_neg(CuTest *);
void test_cil_gen_category_extra_neg(CuTest *);
void test_cil_gen_catset(CuTest *);
void test_cil_gen_catset_dbnull_neg(CuTest *);
void test_cil_gen_catset_currnull_neg(CuTest *);
void test_cil_gen_catset_astnull_neg(CuTest *);
void test_cil_gen_catset_namenull_neg(CuTest *);
void test_cil_gen_catset_setnull_neg(CuTest *);
void test_cil_gen_catset_namelist_neg(CuTest *);
void test_cil_gen_catset_extra_neg(CuTest *);
void test_cil_gen_catset_nodefail_neg(CuTest *);
void test_cil_gen_catset_notset_neg(CuTest *);
void test_cil_gen_catset_settolistfail_neg(CuTest *);
void test_cil_gen_catalias(CuTest *);
void test_cil_gen_catalias_dbnull_neg(CuTest *);
void test_cil_gen_catalias_currnull_neg(CuTest *);
void test_cil_gen_catalias_astnull_neg(CuTest *);
void test_cil_gen_catalias_catnull_neg(CuTest *);
void test_cil_gen_catalias_aliasnull_neg(CuTest *);
void test_cil_gen_catalias_extra_neg(CuTest *);
void test_cil_gen_catrange(CuTest *);
void test_cil_gen_catrange_noname_neg(CuTest *);
void test_cil_gen_catrange_norange_neg(CuTest *);
void test_cil_gen_catrange_emptyrange_neg(CuTest *);
void test_cil_gen_catrange_extrarange_neg(CuTest *);
void test_cil_gen_catrange_dbnull_neg(CuTest *);
void test_cil_gen_catrange_currnull_neg(CuTest *);
void test_cil_gen_catrange_astnull_neg(CuTest *);
void test_cil_gen_catrange_extra_neg(CuTest *);
void test_cil_gen_roletype(CuTest *tc);
void test_cil_gen_roletype_currnull_neg(CuTest *tc);
void test_cil_gen_roletype_dbnull_neg(CuTest *tc);
void test_cil_gen_roletype_astnull_neg(CuTest *tc);
void test_cil_gen_roletype_empty_neg(CuTest *tc);
void test_cil_gen_roletype_rolelist_neg(CuTest *tc);
void test_cil_gen_roletype_roletype_sublist_neg(CuTest *tc);
void test_cil_gen_roletype_typelist_neg(CuTest *tc);
void test_cil_gen_userrole(CuTest *tc);
void test_cil_gen_userrole_currnull_neg(CuTest *tc);
void test_cil_gen_userrole_dbnull_neg(CuTest *tc);
void test_cil_gen_userrole_astnull_neg(CuTest *tc);
void test_cil_gen_userrole_empty_neg(CuTest *tc);
void test_cil_gen_userrole_userlist_neg(CuTest *tc);
void test_cil_gen_userrole_userrole_sublist_neg(CuTest *tc);
void test_cil_gen_userrole_rolelist_neg(CuTest *tc);
void test_cil_gen_classcommon(CuTest *tc);
void test_cil_gen_classcommon_dbnull_neg(CuTest *tc);
void test_cil_gen_classcommon_currnull_neg(CuTest *tc);
void test_cil_gen_classcommon_astnull_neg(CuTest *tc);
void test_cil_gen_classcommon_missingclassname_neg(CuTest *tc);
void test_cil_gen_classcommon_noperms_neg(CuTest *tc);
void test_cil_gen_classcommon_extraperms_neg(CuTest *tc);
void test_cil_gen_catorder(CuTest *tc);
void test_cil_gen_catorder_dbnull_neg(CuTest *tc);
void test_cil_gen_catorder_currnull_neg(CuTest *tc);
void test_cil_gen_catorder_astnull_neg(CuTest *tc);
void test_cil_gen_catorder_missingcats_neg(CuTest *tc);
void test_cil_gen_catorder_nosublist_neg(CuTest *tc);
void test_cil_gen_catorder_nestedcat_neg(CuTest *tc);
void test_cil_gen_dominance(CuTest *tc);
void test_cil_gen_dominance_dbnull_neg(CuTest *tc);
void test_cil_gen_dominance_currnull_neg(CuTest *tc);
void test_cil_gen_dominance_astnull_neg(CuTest *tc);
void test_cil_gen_dominance_nosensitivities_neg(CuTest *tc);
void test_cil_gen_dominance_nosublist_neg(CuTest *tc);
void test_cil_gen_senscat(CuTest *tc);
void test_cil_gen_senscat_nosublist(CuTest *);
void test_cil_gen_senscat_dbnull_neg(CuTest *tc);
void test_cil_gen_senscat_currnull_neg(CuTest *tc);
void test_cil_gen_senscat_astnull_neg(CuTest *tc);
void test_cil_gen_senscat_nosensitivities_neg(CuTest *tc);
void test_cil_gen_senscat_sublist_neg(CuTest *);
void test_cil_gen_senscat_nocat_neg(CuTest *);
void test_cil_fill_level(CuTest *tc);
void test_cil_fill_level_sensnull_neg(CuTest *tc);
void test_cil_fill_level_levelnull_neg(CuTest *tc);
void test_cil_fill_level_nocat(CuTest *tc);
void test_cil_fill_level_emptycat_neg(CuTest *tc);
void test_cil_gen_level(CuTest *tc);
void test_cil_gen_level_nameinparens_neg(CuTest *tc);
void test_cil_gen_level_emptysensparens_neg(CuTest *tc);
void test_cil_gen_level_extra_neg(CuTest *tc);
void test_cil_gen_level_emptycat_neg(CuTest *tc);
void test_cil_gen_level_noname_neg(CuTest *tc);
void test_cil_gen_level_nosens_neg(CuTest *tc);
void test_cil_gen_level_dbnull_neg(CuTest *tc);
void test_cil_gen_level_currnull_neg(CuTest *tc);
void test_cil_gen_level_astnull_neg(CuTest *tc);
void test_cil_gen_levelrange(CuTest *tc);
void test_cil_gen_levelrange_rangeinvalid_neg(CuTest *tc);
void test_cil_gen_levelrange_namenull_neg(CuTest *tc);
void test_cil_gen_levelrange_rangenull_neg(CuTest *tc);
void test_cil_gen_levelrange_rangeempty_neg(CuTest *tc);
void test_cil_gen_levelrange_extra_neg(CuTest *tc);
void test_cil_gen_levelrange_dbnull_neg(CuTest *tc);
void test_cil_gen_levelrange_currnull_neg(CuTest *tc);
void test_cil_gen_levelrange_astnull_neg(CuTest *tc);
void test_cil_gen_constrain(CuTest *tc);
void test_cil_gen_constrain_neg(CuTest *tc);
void test_cil_gen_constrain_classset_neg(CuTest *tc);
void test_cil_gen_constrain_classset_noclass_neg(CuTest *tc);
void test_cil_gen_constrain_classset_noperm_neg(CuTest *tc);
void test_cil_gen_constrain_permset_neg(CuTest *tc);
void test_cil_gen_constrain_permset_noclass_neg(CuTest *tc);
void test_cil_gen_constrain_permset_noperm_neg(CuTest *tc);
void test_cil_gen_constrain_expression_neg(CuTest *tc);
void test_cil_gen_constrain_dbnull_neg(CuTest *tc);
void test_cil_gen_constrain_currnull_neg(CuTest *tc);
void test_cil_gen_constrain_astnull_neg(CuTest *tc);
void test_cil_fill_context(CuTest *tc);
void test_cil_fill_context_unnamedlvl(CuTest *tc);
void test_cil_fill_context_nocontext_neg(CuTest *tc);
void test_cil_fill_context_nouser_neg(CuTest *tc);
void test_cil_fill_context_norole_neg(CuTest *tc);
void test_cil_fill_context_notype_neg(CuTest *tc);
void test_cil_fill_context_nolowlvl_neg(CuTest *tc);
void test_cil_fill_context_nohighlvl_neg(CuTest *tc);
void test_cil_fill_context_unnamedlvl_nocontextlow_neg(CuTest *tc);
void test_cil_fill_context_unnamedlvl_nocontexthigh_neg(CuTest *tc);
void test_cil_gen_context(CuTest *tc);
void test_cil_gen_context_notinparens_neg(CuTest *tc);
void test_cil_gen_context_extralevel_neg(CuTest *tc);
void test_cil_gen_context_emptycontext_neg(CuTest *tc);
void test_cil_gen_context_extra_neg(CuTest *tc);
void test_cil_gen_context_doubleparen_neg(CuTest *tc);
void test_cil_gen_context_norole_neg(CuTest *tc);
void test_cil_gen_context_roleinparens_neg(CuTest *tc);
void test_cil_gen_context_notype_neg(CuTest *tc);
void test_cil_gen_context_typeinparens_neg(CuTest *tc);
void test_cil_gen_context_nolevels_neg(CuTest *tc);
void test_cil_gen_context_nosecondlevel_neg(CuTest *tc);
void test_cil_gen_context_noname_neg(CuTest *tc);
void test_cil_gen_context_nouser_neg(CuTest *tc);
void test_cil_gen_context_dbnull_neg(CuTest *tc);
void test_cil_gen_context_currnull_neg(CuTest *tc);
void test_cil_gen_context_astnull_neg(CuTest *tc);
void test_cil_gen_filecon_file(CuTest *tc);
void test_cil_gen_filecon_dir(CuTest *tc);
void test_cil_gen_filecon_char(CuTest *tc);
void test_cil_gen_filecon_block(CuTest *tc);
void test_cil_gen_filecon_socket(CuTest *tc);
void test_cil_gen_filecon_pipe(CuTest *tc);
void test_cil_gen_filecon_symlink(CuTest *tc);
void test_cil_gen_filecon_any(CuTest *tc);
void test_cil_gen_filecon_neg(CuTest *tc);
void test_cil_gen_filecon_anon_context(CuTest *tc);
void test_cil_gen_filecon_dbnull_neg(CuTest *tc);
void test_cil_gen_filecon_currnull_neg(CuTest *tc);
void test_cil_gen_filecon_astnull_neg(CuTest *tc);
void test_cil_gen_filecon_str1null_neg(CuTest *tc);
void test_cil_gen_filecon_str1_inparens_neg(CuTest *tc);
void test_cil_gen_filecon_str2null_neg(CuTest *tc);
void test_cil_gen_filecon_str2_inparens_neg(CuTest *tc);
void test_cil_gen_filecon_classnull_neg(CuTest *tc);
void test_cil_gen_filecon_class_inparens_neg(CuTest *tc);
void test_cil_gen_filecon_contextnull_neg(CuTest *tc);
void test_cil_gen_filecon_context_neg(CuTest *tc);
void test_cil_gen_filecon_extra_neg(CuTest *tc);
void test_cil_gen_portcon_udp(CuTest *tc);
void test_cil_gen_portcon_tcp(CuTest *tc);
void test_cil_gen_portcon_unknownprotocol_neg(CuTest *tc);
void test_cil_gen_portcon_anon_context(CuTest *tc);
void test_cil_gen_portcon_portrange(CuTest *tc);
void test_cil_gen_portcon_portrange_one_neg(CuTest *tc);
void test_cil_gen_portcon_portrange_morethanone_neg(CuTest *tc);
void test_cil_gen_portcon_singleport_neg(CuTest *tc);
void test_cil_gen_portcon_lowport_neg(CuTest *tc);
void test_cil_gen_portcon_highport_neg(CuTest *tc);
void test_cil_gen_portcon_dbnull_neg(CuTest *tc);
void test_cil_gen_portcon_currnull_neg(CuTest *tc);
void test_cil_gen_portcon_astnull_neg(CuTest *tc);
void test_cil_gen_portcon_str1null_neg(CuTest *tc);
void test_cil_gen_portcon_str1parens_neg(CuTest *tc);
void test_cil_gen_portcon_portnull_neg(CuTest *tc);
void test_cil_gen_portcon_contextnull_neg(CuTest *tc);
void test_cil_gen_portcon_context_neg(CuTest *tc);
void test_cil_gen_portcon_extra_neg(CuTest *tc);
void test_cil_fill_ipaddr(CuTest *tc);
void test_cil_fill_ipaddr_addrnodenull_neg(CuTest *tc);
void test_cil_fill_ipaddr_addrnull_neg(CuTest *tc);
void test_cil_fill_ipaddr_addrinparens_neg(CuTest *tc);
void test_cil_fill_ipaddr_extra_neg(CuTest *tc);
void test_cil_gen_nodecon(CuTest *tc);
void test_cil_gen_nodecon_anon_context(CuTest *tc);
void test_cil_gen_nodecon_dbnull_neg(CuTest *tc);
void test_cil_gen_nodecon_currnull_neg(CuTest *tc);
void test_cil_gen_nodecon_astnull_neg(CuTest *tc);
void test_cil_gen_nodecon_ipnull_neg(CuTest *tc);
void test_cil_gen_nodecon_ipanon(CuTest *tc);
void test_cil_gen_nodecon_ipanon_neg(CuTest *tc);
void test_cil_gen_nodecon_netmasknull_neg(CuTest *tc);
void test_cil_gen_nodecon_netmaskanon(CuTest *tc);
void test_cil_gen_nodecon_netmaskanon_neg(CuTest *tc);
void test_cil_gen_nodecon_contextnull_neg(CuTest *tc);
void test_cil_gen_nodecon_context_neg(CuTest *tc);
void test_cil_gen_nodecon_extra_neg(CuTest *tc);
void test_cil_gen_genfscon(CuTest *tc);
void test_cil_gen_genfscon_anon_context(CuTest *tc);
void test_cil_gen_genfscon_dbnull_neg(CuTest *tc);
void test_cil_gen_genfscon_currnull_neg(CuTest *tc);
void test_cil_gen_genfscon_astnull_neg(CuTest *tc);
void test_cil_gen_genfscon_typenull_neg(CuTest *tc);
void test_cil_gen_genfscon_typeparens_neg(CuTest *tc);
void test_cil_gen_genfscon_pathnull_neg(CuTest *tc);
void test_cil_gen_genfscon_pathparens_neg(CuTest *tc);
void test_cil_gen_genfscon_contextnull_neg(CuTest *tc);
void test_cil_gen_genfscon_context_neg(CuTest *tc);
void test_cil_gen_genfscon_extra_neg(CuTest *tc);
void test_cil_gen_netifcon(CuTest *tc);
void test_cil_gen_netifcon_nested(CuTest *tc);
void test_cil_gen_netifcon_nested_neg(CuTest *tc);
void test_cil_gen_netifcon_nested_emptysecondlist_neg(CuTest *tc);
void test_cil_gen_netifcon_extra_nested_secondlist_neg(CuTest *tc);
void test_cil_gen_netifcon_nested_missingobjects_neg(CuTest *tc);
void test_cil_gen_netifcon_nested_secondnested_missingobjects_neg(CuTest *tc);
void test_cil_gen_netifcon_dbnull_neg(CuTest *tc);
void test_cil_gen_netifcon_currnull_neg(CuTest *tc);
void test_cil_gen_netifcon_astnull_neg(CuTest *tc);
void test_cil_gen_netifcon_ethmissing_neg(CuTest *tc);
void test_cil_gen_netifcon_interfacemissing_neg(CuTest *tc);
void test_cil_gen_netifcon_packetmissing_neg(CuTest *tc);
void test_cil_gen_pirqcon(CuTest *tc);
void test_cil_gen_pirqcon_pirqnotint_neg(CuTest *tc);
void test_cil_gen_pirqcon_nopirq_neg(CuTest *tc);
void test_cil_gen_pirqcon_pirqrange_neg(CuTest *tc);
void test_cil_gen_pirqcon_nocontext_neg(CuTest *tc);
void test_cil_gen_pirqcon_anoncontext_neg(CuTest *tc);
void test_cil_gen_pirqcon_extra_neg(CuTest *tc);
void test_cil_gen_pirqcon_dbnull_neg(CuTest *tc);
void test_cil_gen_pirqcon_currnull_neg(CuTest *tc);
void test_cil_gen_pirqcon_astnull_neg(CuTest *tc);
void test_cil_gen_iomemcon(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange_firstnotint_neg(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange_secondnotint_neg(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange_empty_neg(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange_singleiomem_neg(CuTest *tc);
void test_cil_gen_iomemcon_iomemrange_morethantwoiomem_neg(CuTest *tc);
void test_cil_gen_iomemcon_iomemnotint_neg(CuTest *tc);
void test_cil_gen_iomemcon_noiomem_neg(CuTest *tc);
void test_cil_gen_iomemcon_nocontext_neg(CuTest *tc);
void test_cil_gen_iomemcon_anoncontext_neg(CuTest *tc);
void test_cil_gen_iomemcon_extra_neg(CuTest *tc);
void test_cil_gen_iomemcon_dbnull_neg(CuTest *tc);
void test_cil_gen_iomemcon_currnull_neg(CuTest *tc);
void test_cil_gen_iomemcon_astnull_neg(CuTest *tc);
void test_cil_gen_ioportcon(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange_firstnotint_neg(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange_secondnotint_neg(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange_empty_neg(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange_singleioport_neg(CuTest *tc);
void test_cil_gen_ioportcon_ioportrange_morethantwoioport_neg(CuTest *tc);
void test_cil_gen_ioportcon_ioportnotint_neg(CuTest *tc);
void test_cil_gen_ioportcon_noioport_neg(CuTest *tc);
void test_cil_gen_ioportcon_nocontext_neg(CuTest *tc);
void test_cil_gen_ioportcon_anoncontext_neg(CuTest *tc);
void test_cil_gen_ioportcon_extra_neg(CuTest *tc);
void test_cil_gen_ioportcon_dbnull_neg(CuTest *tc);
void test_cil_gen_ioportcon_currnull_neg(CuTest *tc);
void test_cil_gen_ioportcon_astnull_neg(CuTest *tc);
void test_cil_gen_pcidevicecon(CuTest *tc);
void test_cil_gen_pcidevicecon_pcidevicenotint_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_nopcidevice_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_pcidevicerange_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_nocontext_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_anoncontext_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_extra_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_dbnull_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_currnull_neg(CuTest *tc);
void test_cil_gen_pcidevicecon_astnull_neg(CuTest *tc);
void test_cil_gen_fsuse_anoncontext(CuTest *tc);
void test_cil_gen_fsuse_anoncontext_neg(CuTest *tc);
void test_cil_gen_fsuse_xattr(CuTest *tc);
void test_cil_gen_fsuse_task(CuTest *tc);
void test_cil_gen_fsuse_transition(CuTest *tc);
void test_cil_gen_fsuse_invalidtype_neg(CuTest *tc);
void test_cil_gen_fsuse_notype_neg(CuTest *tc);
void test_cil_gen_fsuse_typeinparens_neg(CuTest *tc);
void test_cil_gen_fsuse_nofilesystem_neg(CuTest *tc);
void test_cil_gen_fsuse_filesysteminparens_neg(CuTest *tc);
void test_cil_gen_fsuse_nocontext_neg(CuTest *tc);
void test_cil_gen_fsuse_emptyconparens_neg(CuTest *tc);
void test_cil_gen_fsuse_extra_neg(CuTest *tc);
void test_cil_gen_fsuse_dbnull_neg(CuTest *tc);
void test_cil_gen_fsuse_currnull_neg(CuTest *tc);
void test_cil_gen_fsuse_astnull_neg(CuTest *tc);
void test_cil_gen_macro_noparams(CuTest *tc);
void test_cil_gen_macro_type(CuTest *tc);
void test_cil_gen_macro_role(CuTest *tc);
void test_cil_gen_macro_user(CuTest *tc);
void test_cil_gen_macro_sensitivity(CuTest *tc);
void test_cil_gen_macro_category(CuTest *tc);
void test_cil_gen_macro_catset(CuTest *tc);
void test_cil_gen_macro_level(CuTest *tc);
void test_cil_gen_macro_class(CuTest *tc);
void test_cil_gen_macro_classmap(CuTest *tc);
void test_cil_gen_macro_permset(CuTest *tc);
void test_cil_gen_macro_duplicate(CuTest *tc);
void test_cil_gen_macro_duplicate_neg(CuTest *tc);
void test_cil_gen_macro_unknown_neg(CuTest *tc);
void test_cil_gen_macro_dbnull_neg(CuTest *tc);
void test_cil_gen_macro_currnull_neg(CuTest *tc);
void test_cil_gen_macro_astnull_neg(CuTest *tc);
void test_cil_gen_macro_unnamed_neg(CuTest *tc);
void test_cil_gen_macro_noparam_name_neg(CuTest *tc);
void test_cil_gen_macro_noparam_neg(CuTest *tc);
void test_cil_gen_macro_nosecondparam_neg(CuTest *tc);
void test_cil_gen_macro_emptyparam_neg(CuTest *tc);
void test_cil_gen_macro_paramcontainsperiod_neg(CuTest *tc);
void test_cil_gen_call(CuTest *tc);
void test_cil_gen_call_noargs(CuTest *tc);
void test_cil_gen_call_anon(CuTest *tc);
void test_cil_gen_call_empty_call_neg(CuTest *tc);
void test_cil_gen_call_dbnull_neg(CuTest *tc);
void test_cil_gen_call_currnull_neg(CuTest *tc);
void test_cil_gen_call_astnull_neg(CuTest *tc);
void test_cil_gen_call_name_inparens_neg(CuTest *tc);
void test_cil_gen_call_noname_neg(CuTest *tc);
void test_cil_gen_optional(CuTest *tc);
void test_cil_gen_optional_emptyoptional(CuTest *tc);
void test_cil_gen_optional_dbnull_neg(CuTest *tc);
void test_cil_gen_optional_currnull_neg(CuTest *tc);
void test_cil_gen_optional_astnull_neg(CuTest *tc);
void test_cil_gen_optional_unnamed_neg(CuTest *tc);
void test_cil_gen_optional_extra_neg(CuTest *tc);
void test_cil_gen_optional_nameinparens_neg(CuTest *tc);
void test_cil_gen_optional_norule_neg(CuTest *tc);
void test_cil_gen_policycap(CuTest *tc);
void test_cil_gen_policycap_noname_neg(CuTest *tc);
void test_cil_gen_policycap_nameinparens_neg(CuTest *tc);
void test_cil_gen_policycap_extra_neg(CuTest *tc);
void test_cil_gen_policycap_dbnull_neg(CuTest *tc);
void test_cil_gen_policycap_currnull_neg(CuTest *tc);
void test_cil_gen_policycap_astnull_neg(CuTest *tc);
void test_cil_gen_ipaddr_ipv4(CuTest *tc);
void test_cil_gen_ipaddr_ipv4_neg(CuTest *tc);
void test_cil_gen_ipaddr_ipv6(CuTest *tc);
void test_cil_gen_ipaddr_ipv6_neg(CuTest *tc);
void test_cil_gen_ipaddr_noname_neg(CuTest *tc);
void test_cil_gen_ipaddr_nameinparens_neg(CuTest *tc);
void test_cil_gen_ipaddr_noip_neg(CuTest *tc);
void test_cil_gen_ipaddr_ipinparens_neg(CuTest *tc);
void test_cil_gen_ipaddr_extra_neg(CuTest *tc);
void test_cil_gen_ipaddr_dbnull_neg(CuTest *tc);
void test_cil_gen_ipaddr_currnull_neg(CuTest *tc);
void test_cil_gen_ipaddr_astnull_neg(CuTest *tc);
/*
cil_build_ast test cases
*/
void test_cil_build_ast(CuTest *);
void test_cil_build_ast_dbnull_neg(CuTest *);
void test_cil_build_ast_astnull_neg(CuTest *);
void test_cil_build_ast_suberr_neg(CuTest *);
void test_cil_build_ast_treenull_neg(CuTest *);
void test_cil_build_ast_node_helper_block(CuTest *);
void test_cil_build_ast_node_helper_block_neg(CuTest *);
void test_cil_build_ast_node_helper_blockinherit(CuTest *);
void test_cil_build_ast_node_helper_blockinherit_neg(CuTest *);
void test_cil_build_ast_node_helper_permset(CuTest *);
void test_cil_build_ast_node_helper_permset_neg(CuTest *);
void test_cil_build_ast_node_helper_in(CuTest *);
void test_cil_build_ast_node_helper_in_neg(CuTest *);
void test_cil_build_ast_node_helper_class(CuTest *);
void test_cil_build_ast_node_helper_class_neg(CuTest *);
void test_cil_build_ast_node_helper_classpermset(CuTest *);
void test_cil_build_ast_node_helper_classpermset_neg(CuTest *);
void test_cil_build_ast_node_helper_classmap(CuTest *);
void test_cil_build_ast_node_helper_classmap_neg(CuTest *);
void test_cil_build_ast_node_helper_classmapping(CuTest *);
void test_cil_build_ast_node_helper_classmapping_neg(CuTest *);
void test_cil_build_ast_node_helper_common(CuTest *);
void test_cil_build_ast_node_helper_common_neg(CuTest *);
void test_cil_build_ast_node_helper_sid(CuTest *);
void test_cil_build_ast_node_helper_sid_neg(CuTest *);
void test_cil_build_ast_node_helper_sidcontext(CuTest *);
void test_cil_build_ast_node_helper_sidcontext_neg(CuTest *);
void test_cil_build_ast_node_helper_user(CuTest *);
void test_cil_build_ast_node_helper_user_neg(CuTest *);
void test_cil_build_ast_node_helper_userlevel(CuTest *);
void test_cil_build_ast_node_helper_userlevel_neg(CuTest *);
void test_cil_build_ast_node_helper_userrange(CuTest *);
void test_cil_build_ast_node_helper_userrange_neg(CuTest *);
void test_cil_build_ast_node_helper_type(CuTest *);
void test_cil_build_ast_node_helper_type_neg(CuTest *);
void test_cil_build_ast_node_helper_typeattribute(CuTest *);
void test_cil_build_ast_node_helper_typeattribute_neg(CuTest *);
void test_cil_build_ast_node_helper_boolif(CuTest *);
void test_cil_build_ast_node_helper_boolif_neg(CuTest *);
void test_cil_build_ast_node_helper_tunif(CuTest *);
void test_cil_build_ast_node_helper_tunif_neg(CuTest *);
void test_cil_build_ast_node_helper_condblock_true(CuTest *);
void test_cil_build_ast_node_helper_condblock_true_neg(CuTest *);
void test_cil_build_ast_node_helper_condblock_false(CuTest *);
void test_cil_build_ast_node_helper_condblock_false_neg(CuTest *);
void test_cil_build_ast_node_helper_typealias(CuTest *);
void test_cil_build_ast_node_helper_typealias_notype_neg(CuTest *);
void test_cil_build_ast_node_helper_typebounds(CuTest *);
void test_cil_build_ast_node_helper_typebounds_neg(CuTest *);
void test_cil_build_ast_node_helper_typepermissive(CuTest *);
void test_cil_build_ast_node_helper_typepermissive_neg(CuTest *);
void test_cil_build_ast_node_helper_nametypetransition(CuTest *);
void test_cil_build_ast_node_helper_nametypetransition_neg(CuTest *);
void test_cil_build_ast_node_helper_rangetransition(CuTest *);
void test_cil_build_ast_node_helper_rangetransition_neg(CuTest *);
void test_cil_build_ast_node_helper_typeattributeset(CuTest *);
void test_cil_build_ast_node_helper_typeattributeset_neg(CuTest *);
void test_cil_build_ast_node_helper_userbounds(CuTest *);
void test_cil_build_ast_node_helper_userbounds_neg(CuTest *);
void test_cil_build_ast_node_helper_role(CuTest *);
void test_cil_build_ast_node_helper_role_neg(CuTest *);
void test_cil_build_ast_node_helper_roletransition(CuTest *);
void test_cil_build_ast_node_helper_roletransition_neg(CuTest *);
void test_cil_build_ast_node_helper_roleallow(CuTest *);
void test_cil_build_ast_node_helper_roleallow_neg(CuTest *);
void test_cil_build_ast_node_helper_rolebounds(CuTest *);
void test_cil_build_ast_node_helper_rolebounds_neg(CuTest *);
void test_cil_build_ast_node_helper_avrule_allow(CuTest *);
void test_cil_build_ast_node_helper_avrule_allow_neg(CuTest *);
void test_cil_build_ast_node_helper_avrule_auditallow(CuTest *);
void test_cil_build_ast_node_helper_avrule_auditallow_neg(CuTest *);
void test_cil_build_ast_node_helper_avrule_dontaudit(CuTest *);
void test_cil_build_ast_node_helper_avrule_dontaudit_neg(CuTest *);
void test_cil_build_ast_node_helper_avrule_neverallow(CuTest *);
void test_cil_build_ast_node_helper_avrule_neverallow_neg(CuTest *);
void test_cil_build_ast_node_helper_type_rule_transition(CuTest *);
void test_cil_build_ast_node_helper_type_rule_transition_neg(CuTest *);
void test_cil_build_ast_node_helper_type_rule_change(CuTest *);
void test_cil_build_ast_node_helper_type_rule_change_neg(CuTest *);
void test_cil_build_ast_node_helper_type_rule_member(CuTest *);
void test_cil_build_ast_node_helper_type_rule_member_neg(CuTest *);
void test_cil_build_ast_node_helper_bool(CuTest *);
void test_cil_build_ast_node_helper_bool_neg(CuTest *);
void test_cil_build_ast_node_helper_bool_tunable(CuTest *);
void test_cil_build_ast_node_helper_bool_tunable_neg(CuTest *);
void test_cil_build_ast_node_helper_else(CuTest *);
void test_cil_build_ast_node_helper_else_neg(CuTest *);
void test_cil_build_ast_node_helper_sensitivity(CuTest *);
void test_cil_build_ast_node_helper_sensitivity_neg(CuTest *);
void test_cil_build_ast_node_helper_sensalias(CuTest *);
void test_cil_build_ast_node_helper_sensalias_neg(CuTest *);
void test_cil_build_ast_node_helper_category(CuTest *);
void test_cil_build_ast_node_helper_category_neg(CuTest *);
void test_cil_build_ast_node_helper_catset(CuTest *tc);
void test_cil_build_ast_node_helper_catset_neg(CuTest *tc);
void test_cil_build_ast_node_helper_catorder(CuTest *tc);
void test_cil_build_ast_node_helper_catorder_neg(CuTest *tc);
void test_cil_build_ast_node_helper_catalias(CuTest *tc);
void test_cil_build_ast_node_helper_catalias_neg(CuTest *tc);
void test_cil_build_ast_node_helper_catrange(CuTest *tc);
void test_cil_build_ast_node_helper_catrange_neg(CuTest *tc);
void test_cil_build_ast_node_helper_roletype(CuTest *tc);
void test_cil_build_ast_node_helper_roletype_neg(CuTest *tc);
void test_cil_build_ast_node_helper_userrole(CuTest *tc);
void test_cil_build_ast_node_helper_userrole_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_classcommon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_classcommon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_dominance(CuTest *tc);
void test_cil_build_ast_node_helper_gen_dominance_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_senscat(CuTest *tc);
void test_cil_build_ast_node_helper_gen_senscat_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_level(CuTest *tc);
void test_cil_build_ast_node_helper_gen_level_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_levelrange(CuTest *tc);
void test_cil_build_ast_node_helper_gen_levelrange_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_constrain(CuTest *tc);
void test_cil_build_ast_node_helper_gen_constrain_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_mlsconstrain(CuTest *tc);
void test_cil_build_ast_node_helper_gen_mlsconstrain_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_context(CuTest *tc);
void test_cil_build_ast_node_helper_gen_context_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_filecon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_filecon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_portcon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_portcon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_nodecon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_nodecon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_genfscon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_genfscon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_netifcon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_netifcon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_pirqcon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_pirqcon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_iomemcon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_iomemcon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_ioportcon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_ioportcon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_pcidevicecon(CuTest *tc);
void test_cil_build_ast_node_helper_gen_pcidevicecon_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_fsuse(CuTest *tc);
void test_cil_build_ast_node_helper_gen_fsuse_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_macro(CuTest *tc);
void test_cil_build_ast_node_helper_gen_macro_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_macro_nested_macro_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_macro_nested_tunif_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_call(CuTest *tc);
void test_cil_build_ast_node_helper_gen_call_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_optional(CuTest *tc);
void test_cil_build_ast_node_helper_gen_optional_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_policycap(CuTest *tc);
void test_cil_build_ast_node_helper_gen_policycap_neg(CuTest *tc);
void test_cil_build_ast_node_helper_gen_ipaddr(CuTest *tc);
void test_cil_build_ast_node_helper_gen_ipaddr_neg(CuTest *tc);
void test_cil_build_ast_node_helper_extraargsnull_neg(CuTest *);
void test_cil_build_ast_last_child_helper(CuTest *);
void test_cil_build_ast_last_child_helper_extraargsnull_neg(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_copy_ast.c000066400000000000000000002323711476211737200217360ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include "CuTest.h"
#include "CilTest.h"
#include "../../src/cil_internal.h"
#include "../../src/cil_copy_ast.h"
#include "../../src/cil_build_ast.h"
#include "../../src/cil_resolve_ast.h"
#define CIL_TEST_SYM_SIZE 1
int __cil_copy_node_helper(struct cil_tree_node *orig, uint32_t *finished, void *extra_args);
struct cil_args_copy {
struct cil_tree_node *dest;
struct cil_db *db;
};
struct cil_args_copy *gen_copy_args(struct cil_tree_node *node, struct cil_db *db)
{
struct cil_args_copy *args = cil_malloc(sizeof(*args));
args->dest = node;
args->db = db;
return args;
}
void test_cil_copy_list(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", ")", NULL};
struct cil_tree *test_tree;
struct cil_list *cil_l;
gen_test_tree(&test_tree, line);
cil_list_init(&cil_l);
cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
struct cil_list *copy_list;
cil_list_init(©_list);
int rc =cil_copy_list(cil_l, ©_list);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
}
void test_cil_copy_list_sublist(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", "(", "foo3", ")", ")", NULL};
struct cil_tree *test_tree;
struct cil_list *cil_l;
gen_test_tree(&test_tree, line);
cil_list_init(&cil_l);
cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
struct cil_list *copy_list;
cil_list_init(©_list);
int rc = cil_copy_list(cil_l, ©_list);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
CuAssertStrEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->data, ((struct cil_list *)cil_l->head->next->next->data)->head->data);
CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
CuAssertIntEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->flavor, ((struct cil_list *)cil_l->head->next->next->data)->head->flavor);
}
void test_cil_copy_list_sublist_extra(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", "(", "foo3", ")", "foo4", ")", NULL};
struct cil_tree *test_tree;
struct cil_list *cil_l;
gen_test_tree(&test_tree, line);
cil_list_init(&cil_l);
cil_set_to_list(test_tree->root->cl_head, cil_l, 1);
struct cil_list *copy_list;
cil_list_init(©_list);
int rc = cil_copy_list(cil_l, ©_list);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, copy_list->head->data, cil_l->head->data);
CuAssertStrEquals(tc, copy_list->head->next->data, cil_l->head->next->data);
CuAssertStrEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->data, ((struct cil_list *)cil_l->head->next->next->data)->head->data);
CuAssertStrEquals(tc, copy_list->head->next->next->next->data, cil_l->head->next->next->next->data);
CuAssertIntEquals(tc, copy_list->head->flavor, cil_l->head->flavor);
CuAssertIntEquals(tc, copy_list->head->next->flavor, cil_l->head->next->flavor);
CuAssertIntEquals(tc, ((struct cil_list *)copy_list->head->next->next->data)->head->flavor, ((struct cil_list *)cil_l->head->next->next->data)->head->flavor);
CuAssertIntEquals(tc, copy_list->head->next->next->next->flavor, cil_l->head->next->next->next->flavor);
}
void test_cil_copy_list_orignull_neg(CuTest *tc) {
char *line[] = {"(", "foo1", "foo2", ")", NULL};
struct cil_tree *test_tree;
struct cil_list *cil_l = NULL;
gen_test_tree(&test_tree, line);
struct cil_list *copy_list;
cil_list_init(©_list);
int rc = cil_copy_list(cil_l, ©_list);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
CuAssertPtrEquals(tc, copy_list->head, NULL);
}
void test_cil_copy_block(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_block(test_db, test_tree->root->cl_head->cl_head, test_ast_node, 0);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, cil_sym_sizes[CIL_SYM_ARRAY_BLOCK][CIL_SYM_BLOCKS]);
int rc = cil_copy_block(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_perm(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_class *new_node;
cil_class_init(&new_node);
struct cil_tree_node *new_tree_node;
cil_tree_node_init(&new_tree_node);
new_tree_node->data = new_node;
new_tree_node->flavor = CIL_CLASS;
test_ast_node->parent = new_tree_node;
test_ast_node->line = 1;
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_CLASS_SYM_SIZE);
cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head, test_ast_node);
int rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next, test_ast_node);
rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
cil_gen_perm(test_db, test_tree->root->cl_head->cl_head->next->next->cl_head->next->next, test_ast_node);
rc = cil_copy_perm(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_class(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_class(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_CLASS_SYM_SIZE);
int rc = cil_copy_class(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_common(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_common(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_CLASS_SYM_SIZE);
int rc = cil_copy_common(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_classcommon(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
char *test_key = test_tree->root->cl_head->cl_head->next->data;
struct cil_class *test_cls;
cil_class_init(&test_cls);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_insert(&test_db->symtab[CIL_SYM_CLASSES], (hashtab_key_t)test_key, (struct cil_symtab_datum*)test_cls, test_ast_node);
test_ast_node->data = test_cls;
test_ast_node->flavor = CIL_CLASS;
cil_gen_classcommon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_classcommon *test_copy;
cil_classcommon_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_CLASS_SYM_SIZE);
int rc = cil_copy_classcommon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_classcommon *)test_ast_node->data)->class_str, test_copy->class_str);
CuAssertStrEquals(tc, ((struct cil_classcommon *)test_ast_node->data)->common_str, test_copy->common_str);
}
void test_cil_copy_sid(CuTest *tc) {
char *line[] = {"(", "sid", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_sid(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_sid(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_sidcontext(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_sidcontext(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_sidcontext(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_user *)test_copy->data)->datum.name,
((struct cil_user *)test_ast_node->data)->datum.name);
}
void test_cil_copy_user(CuTest *tc) {
char *line[] = {"(", "user", "sysadm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_user(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_user(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_role(CuTest *tc) {
char *line[] = {"(", "role", "role_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_role(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_role(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_userrole(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_userrole(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_userrole *test_copy;
cil_userrole_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_userrole(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_userrole *)test_ast_node->data)->user_str, test_copy->user_str);
CuAssertStrEquals(tc, ((struct cil_userrole *)test_ast_node->data)->role_str, test_copy->role_str);
}
void test_cil_copy_type(CuTest *tc) {
char *line[] = {"(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_type(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_type(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_typealias(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_typealias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_typealias(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_typeattribute(CuTest *tc) {
char *line[] = {"(", "typettribute", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_typeattribute(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_typeattribute(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_bool(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_bool(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_BOOL);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_bool(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertIntEquals(tc, ((struct cil_bool *)test_copy->data)->value,
((struct cil_bool *)test_ast_node->data)->value);
}
void test_cil_copy_type_rule(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_type_rule(test_tree->root->cl_head->cl_head, test_ast_node, CIL_TYPE_TRANSITION);
struct cil_type_rule *test_copy;
cil_type_rule_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_type_rule(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertIntEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->rule_kind, test_copy->rule_kind);
CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->src_str, test_copy->src_str);
CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->tgt_str, test_copy->tgt_str);
CuAssertStrEquals(tc, ((struct cil_type_rule *)test_ast_node->data)->obj_str, test_copy->obj_str);
}
void test_cil_copy_avrule(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
cil_gen_avrule(test_current, test_ast_node, CIL_AVRULE_ALLOWED);
struct cil_avrule *test_copy;
cil_avrule_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_avrule(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->rule_kind, test_copy->rule_kind);
CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->src_str, test_copy->src_str);
CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->tgt_str, test_copy->tgt_str);
CuAssertStrEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->class_str, test_copy->classpermset->class_str);
CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->flavor, test_copy->classpermset->permset->perms_list_str->head->flavor);
CuAssertStrEquals(tc, (char*)((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->data, (char*)test_copy->classpermset->permset->perms_list_str->head->data);
CuAssertIntEquals(tc, ((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->next->flavor, test_copy->classpermset->permset->perms_list_str->head->next->flavor);
CuAssertStrEquals(tc, (char*)((struct cil_avrule *)test_ast_node->data)->classpermset->permset->perms_list_str->head->next->data, (char*)test_copy->classpermset->permset->perms_list_str->head->next->data);
}
void test_cil_copy_sens(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_sensitivity(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_sens(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_sensalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_sensalias(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_sensalias *)test_copy->data)->sens_str,
((struct cil_sensalias *)test_ast_node->data)->sens_str);
}
void test_cil_copy_cat(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_category(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_cat(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_catalias(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_catalias(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_catalias(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_catalias *)test_copy->data)->cat_str,
((struct cil_catalias *)test_ast_node->data)->cat_str);
}
void test_cil_copy_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_senscat(test_db, test_tree->root->cl_head->next->next->next->next->next->next->cl_head, test_ast_node);
struct cil_senscat *test_copy;
cil_senscat_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_senscat(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_senscat *)test_ast_node->data)->sens_str, test_copy->sens_str);
CuAssertStrEquals(tc, (char*)((struct cil_senscat *)test_ast_node->data)->catset->cat_list_str->head->data,
(char*)test_copy->catset->cat_list_str->head->data);
CuAssertStrEquals(tc, (char*)((struct cil_senscat *)test_ast_node->data)->catset->cat_list_str->head->next->data,
(char*)test_copy->catset->cat_list_str->head->next->data);
}
void test_cil_copy_catorder(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_catorder(test_db, test_tree->root->cl_head->next->next->cl_head, test_ast_node);
struct cil_catorder *test_copy;
cil_catorder_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_catorder(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, (char*)((struct cil_catorder *)test_ast_node->data)->cat_list_str->head->data, (char*)test_copy->cat_list_str->head->data);
CuAssertStrEquals(tc, (char*)((struct cil_catorder *)test_ast_node->data)->cat_list_str->head->next->data, (char*)test_copy->cat_list_str->head->next->data);
}
void test_cil_copy_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_dominance(test_db, test_tree->root->cl_head->next->next->next->cl_head, test_ast_node);
struct cil_sens_dominates *test_copy;
cil_sens_dominates_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_dominance(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, (char*)((struct cil_sens_dominates *)test_ast_node->data)->sens_list_str->head->data, (char*)test_copy->sens_list_str->head->data);
CuAssertStrEquals(tc, (char*)((struct cil_sens_dominates *)test_ast_node->data)->sens_list_str->head->next->data, (char*)test_copy->sens_list_str->head->next->data);
}
void test_cil_copy_level(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_level(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_fill_level(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_level(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
cil_level_init((struct cil_level**)&test_copy->data);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_fill_level((struct cil_level*)test_ast_node->data, (struct cil_level*)test_copy->data);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_level *)test_copy->data)->sens_str,
((struct cil_level *)test_ast_node->data)->sens_str);
}
void test_cil_copy_context(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_context(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_netifcon(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_netifcon *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_netifcon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, test_copy->interface_str,
((struct cil_netifcon *)test_ast_node->data)->interface_str);
CuAssertStrEquals(tc, test_copy->if_context_str,
((struct cil_netifcon *)test_ast_node->data)->if_context_str);
CuAssertStrEquals(tc, test_copy->packet_context_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context_str);
}
void test_cil_copy_netifcon_nested(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_netifcon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_netifcon *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_netifcon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, test_copy->interface_str,
((struct cil_netifcon *)test_ast_node->data)->interface_str);
CuAssertStrEquals(tc, test_copy->if_context_str,
((struct cil_netifcon *)test_ast_node->data)->if_context_str);
CuAssertStrEquals(tc, test_copy->packet_context_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context_str);
CuAssertStrEquals(tc, test_copy->packet_context->user_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context->user_str);
CuAssertStrEquals(tc, test_copy->packet_context->role_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context->role_str);
CuAssertStrEquals(tc, test_copy->packet_context->type_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context->type_str);
CuAssertStrEquals(tc, test_copy->packet_context->range_str,
((struct cil_netifcon *)test_ast_node->data)->packet_context->range_str);
}
void test_cil_copy_fill_context(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "range", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
cil_context_init((struct cil_context**)&test_copy->data);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_fill_context((struct cil_context*)test_ast_node->data, (struct cil_context*)test_copy->data);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->user_str,
((struct cil_context *)test_ast_node->data)->user_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->role_str,
((struct cil_context *)test_ast_node->data)->role_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->type_str,
((struct cil_context *)test_ast_node->data)->type_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->range_str,
((struct cil_context *)test_ast_node->data)->range_str);
}
void test_cil_copy_fill_context_anonrange(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_context(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
cil_context_init((struct cil_context**)&test_copy->data);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_fill_context((struct cil_context*)test_ast_node->data, (struct cil_context*)test_copy->data);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->user_str,
((struct cil_context *)test_ast_node->data)->user_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->role_str,
((struct cil_context *)test_ast_node->data)->role_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->type_str,
((struct cil_context *)test_ast_node->data)->type_str);
CuAssertStrEquals(tc, ((struct cil_context *)test_copy->data)->range_str,
((struct cil_context *)test_ast_node->data)->range_str);
}
void test_cil_copy_call(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_call(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_call *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_call(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, test_copy->macro_str, ((struct cil_call *)test_ast_node->data)->macro_str);
}
void test_cil_copy_optional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_optional(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_optional(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_nodecon(CuTest *tc) {
char *line[] = {"(", "nodecon", "ipaddr", "ipaddr", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_nodecon *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_nodecon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, test_copy->addr_str,
((struct cil_nodecon *)test_ast_node->data)->addr_str);
CuAssertStrEquals(tc, test_copy->mask_str,
((struct cil_nodecon *)test_ast_node->data)->mask_str);
CuAssertStrEquals(tc, test_copy->context_str,
((struct cil_nodecon *)test_ast_node->data)->context_str);
}
void test_cil_copy_nodecon_anon(CuTest *tc) {
char *line[] = {"(", "nodecon", "(", "192.168.1.1", ")", "(", "192.168.1.1", ")", "(", "user", "role", "type", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_nodecon(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_nodecon *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_nodecon(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, test_copy->addr_str,
((struct cil_nodecon *)test_ast_node->data)->addr_str);
CuAssertStrEquals(tc, test_copy->mask_str,
((struct cil_nodecon *)test_ast_node->data)->mask_str);
CuAssertStrEquals(tc, test_copy->context_str,
((struct cil_nodecon *)test_ast_node->data)->context_str);
}
void test_cil_copy_fill_ipaddr(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
struct cil_ipaddr *new;
cil_ipaddr_init(&new);
struct cil_ipaddr *old;
cil_ipaddr_init(&new);
old = (struct cil_ipaddr*)test_ast_node->data;
int rc = cil_copy_fill_ipaddr(old, new);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertIntEquals(tc, old->family, new->family);
}
void test_cil_copy_ipaddr(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_ipaddr(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_tree_node *test_copy;
cil_tree_node_init(&test_copy);
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_ipaddr(test_db, test_ast_node->data, &test_copy->data, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_conditional(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_list_item *curr_old;
curr_old = ((struct cil_booleanif*)test_ast_node->data)->expr_stack->head;
struct cil_conditional *cond_new;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_conditional(test_db, curr_old->data, (void**)&cond_new, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_conditional*)curr_old->data)->str, cond_new->str);
CuAssertIntEquals(tc, ((struct cil_conditional*)curr_old->data)->flavor, cond_new->flavor);
}
void test_cil_copy_boolif(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_boolif(test_db, test_tree->root->cl_head->cl_head, test_ast_node);
struct cil_booleanif *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_boolif(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_constrain(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
struct cil_constrain *test_copy;
symtab_t sym;
symtab_init(&sym, CIL_TEST_SYM_SIZE);
int rc = cil_copy_constrain(test_db, test_ast_node->data, (void**)&test_copy, &sym);
CuAssertIntEquals(tc, rc, SEPOL_OK);
CuAssertStrEquals(tc, ((struct cil_constrain*)test_copy)->classpermset->class_str, ((struct cil_constrain *)test_ast_node->data)->classpermset->class_str);
}
/*
void test_cil_copy_ast(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *test_copy;
cil_constrain_init(&test_copy);
cil_list_init(&test_copy->expr);
int rc = cil_copy_ast(((struct cil_constrain *)test_ast_node->data)->expr, test_copy->expr);
CuAssertIntEquals(tc, rc, SEPOL_OK);
}
void test_cil_copy_ast_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_gen_constrain(test_db, test_tree->root->cl_head->cl_head, test_ast_node, CIL_MLSCONSTRAIN);
struct cil_tree_node *test_current;
test_current = test_tree->root->cl_head->cl_head;
struct cil_constrain *test_copy;
cil_constrain_init(&test_copy);
cil_list_init(&test_copy->expr);
int rc = cil_copy_ast(((struct cil_constrain *)test_ast_node->data)->expr, test_copy->expr);
CuAssertIntEquals(tc, rc, SEPOL_ERR);
}
*/
/* node_helper functions */
void test_cil_copy_node_helper_block(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_block_merge(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_perm(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_class *test_class;
cil_class_init(&test_class);
struct cil_tree_node *parent_node;
cil_tree_node_init(&parent_node);
parent_node->flavor = CIL_CLASS;
parent_node->data = test_class;
struct cil_tree_node *root;
cil_tree_node_init(&root);
root->flavor = CIL_ROOT;
parent_node->parent = root;
struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_perm_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_class(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_class_dup_neg(CuTest *tc) {
char *line[] = {"(", "class", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_common(CuTest *tc) {
char *line[] = {"(", "common", "test", "(", "read", "write", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_common_dup_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", "write", "open", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_classcommon(CuTest *tc) {
char *line[] = {"(", "classcommon", "file", "file", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sid(CuTest *tc) {
char *line[] = {"(", "sid", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sid_merge(CuTest *tc) {
char *line[] = {"(", "sid", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sidcontext(CuTest *tc) {
char *line[] = {"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_user(CuTest *tc) {
char *line[] = {"(", "user", "sysadm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_user_merge(CuTest *tc) {
char *line[] = {"(", "user", "sysadm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_role(CuTest *tc) {
char *line[] = {"(", "role", "role_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_role_merge(CuTest *tc) {
char *line[] = {"(", "role", "role_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_userrole(CuTest *tc) {
char *line[] = {"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_type(CuTest *tc) {
char *line[] = {"(", "type", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_type_merge(CuTest *tc) {
char *line[] = {"(", "type", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_typeattribute(CuTest *tc) {
char *line[] = {"(", "typeattribute", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_typeattribute_merge(CuTest *tc) {
char *line[] = {"(", "typeattribute", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_typealias(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_typealias_dup_neg(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_bool(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_bool_dup_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_avrule(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "file", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_type_rule(CuTest *tc) {
char *line[] = {"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sens(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sens_merge(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_sensalias_dup_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_cat(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_cat_merge(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_catalias(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_catalias_dup_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_senscat *test_senscat;
cil_senscat_init(&test_senscat);
struct cil_tree_node *parent_node;
cil_tree_node_init(&parent_node);
parent_node->flavor = CIL_SENSCAT;
parent_node->data = test_senscat;
struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_catorder(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_catorder *test_catorder;
cil_catorder_init(&test_catorder);
struct cil_tree_node *parent_node;
cil_tree_node_init(&parent_node);
parent_node->flavor = CIL_CATORDER;
parent_node->data = test_catorder;
struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_sens *test_sens;
cil_sens_init(&test_sens);
struct cil_tree_node *parent_node;
cil_tree_node_init(&parent_node);
parent_node->flavor = CIL_SENS;
parent_node->data = test_sens;
struct cil_args_copy *extra_args = gen_copy_args(parent_node, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_level(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_level_dup_neg(CuTest *tc) {
char *line[] = {"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_context(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_context_dup_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_netifcon(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_call(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_optional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_optional_merge(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_ipaddr(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_ipaddr_dup_neg(CuTest *tc) {
char *line[] = {"(", "ipaddr", "ip", "192.168.1.1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db->ast->root, test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_boolif(CuTest *tc) {
char *line[] = {"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_mlsconstrain(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, finished, 0);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_copy_node_helper_orignull_neg(CuTest *tc) {
char *line[] = {"(", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
uint32_t finished = 0;
struct cil_args_copy *extra_args = gen_copy_args(test_db2->ast->root, test_db2);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_copy_node_helper_extraargsnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "l1", "l2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_db *test_db2;
cil_db_init(&test_db2);
struct cil_args_copy *extra_args = NULL;
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_copy_node_helper(test_db->ast->root->cl_head, &finished, extra_args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
libsepol-3.8.1/cil/test/unit/test_cil_copy_ast.h000066400000000000000000000147131476211737200217410ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_COPY_AST_H_
#define TEST_CIL_COPY_AST_H_
#include "CuTest.h"
void test_cil_copy_list(CuTest *);
void test_cil_copy_list_sublist(CuTest *);
void test_cil_copy_list_sublist_extra(CuTest *);
void test_cil_copy_list_orignull_neg(CuTest *);
void test_cil_copy_block(CuTest *);
void test_cil_copy_node_helper_block(CuTest *tc);
void test_cil_copy_node_helper_block_merge(CuTest *tc);
void test_cil_copy_perm(CuTest *);
void test_cil_copy_node_helper_perm(CuTest *tc);
void test_cil_copy_node_helper_perm_neg(CuTest *tc);
void test_cil_copy_class(CuTest *);
void test_cil_copy_node_helper_class(CuTest *tc);
void test_cil_copy_node_helper_class_dup_neg(CuTest *tc);
void test_cil_copy_common(CuTest *);
void test_cil_copy_node_helper_common(CuTest *tc);
void test_cil_copy_node_helper_common_dup_neg(CuTest *tc);
void test_cil_copy_classcommon(CuTest *);
void test_cil_copy_node_helper_classcommon(CuTest *tc);
void test_cil_copy_sid(CuTest *);
void test_cil_copy_node_helper_sid(CuTest *tc);
void test_cil_copy_node_helper_sid_merge(CuTest *tc);
void test_cil_copy_sidcontext(CuTest *);
void test_cil_copy_node_helper_sidcontext(CuTest *tc);
void test_cil_copy_user(CuTest *);
void test_cil_copy_node_helper_user(CuTest *tc);
void test_cil_copy_node_helper_user_merge(CuTest *tc);
void test_cil_copy_role(CuTest *);
void test_cil_copy_node_helper_role(CuTest *tc);
void test_cil_copy_node_helper_role_merge(CuTest *tc);
void test_cil_copy_userrole(CuTest *);
void test_cil_copy_node_helper_userrole(CuTest *tc);
void test_cil_copy_type(CuTest *);
void test_cil_copy_node_helper_type(CuTest *tc);
void test_cil_copy_node_helper_type_merge(CuTest *tc);
void test_cil_copy_typeattribute(CuTest *);
void test_cil_copy_node_helper_typeattribute(CuTest *tc);
void test_cil_copy_node_helper_typeattribute_merge(CuTest *tc);
void test_cil_copy_typealias(CuTest *);
void test_cil_copy_node_helper_typealias(CuTest *tc);
void test_cil_copy_node_helper_typealias_dup_neg(CuTest *tc);
void test_cil_copy_bool(CuTest *);
void test_cil_copy_node_helper_bool(CuTest *tc);
void test_cil_copy_node_helper_bool_dup_neg(CuTest *tc);
void test_cil_copy_avrule(CuTest *);
void test_cil_copy_node_helper_avrule(CuTest *tc);
void test_cil_copy_type_rule(CuTest *);
void test_cil_copy_node_helper_type_rule(CuTest *tc);
void test_cil_copy_sens(CuTest *);
void test_cil_copy_node_helper_sens(CuTest *tc);
void test_cil_copy_node_helper_sens_merge(CuTest *tc);
void test_cil_copy_sensalias(CuTest *);
void test_cil_copy_node_helper_sensalias(CuTest *tc);
void test_cil_copy_node_helper_sensalias_dup_neg(CuTest *tc);
void test_cil_copy_cat(CuTest *);
void test_cil_copy_node_helper_cat(CuTest *tc);
void test_cil_copy_node_helper_cat_merge(CuTest *tc);
void test_cil_copy_catalias(CuTest *);
void test_cil_copy_node_helper_catalias(CuTest *tc);
void test_cil_copy_node_helper_catalias_dup_neg(CuTest *tc);
void test_cil_copy_senscat(CuTest *);
void test_cil_copy_node_helper_senscat(CuTest *tc);
void test_cil_copy_catorder(CuTest *);
void test_cil_copy_node_helper_catorder(CuTest *tc);
void test_cil_copy_dominance(CuTest *);
void test_cil_copy_node_helper_dominance(CuTest *tc);
void test_cil_copy_level(CuTest *);
void test_cil_copy_node_helper_level(CuTest *tc);
void test_cil_copy_node_helper_level_dup_neg(CuTest *tc);
void test_cil_copy_fill_level(CuTest *);
void test_cil_copy_context(CuTest *);
void test_cil_copy_node_helper_context(CuTest *tc);
void test_cil_copy_node_helper_context_dup_neg(CuTest *tc);
void test_cil_copy_netifcon(CuTest *);
void test_cil_copy_netifcon_nested(CuTest *);
void test_cil_copy_node_helper_netifcon(CuTest *tc);
void test_cil_copy_node_helper_netifcon_merge(CuTest *tc);
void test_cil_copy_fill_context(CuTest *);
void test_cil_copy_fill_context_anonrange(CuTest *);
void test_cil_copy_call(CuTest *);
void test_cil_copy_node_helper_call(CuTest *tc);
void test_cil_copy_optional(CuTest *);
void test_cil_copy_node_helper_optional(CuTest *tc);
void test_cil_copy_node_helper_optional_merge(CuTest *tc);
void test_cil_copy_nodecon(CuTest *);
void test_cil_copy_nodecon_anon(CuTest *);
void test_cil_copy_fill_ipaddr(CuTest *);
void test_cil_copy_ipaddr(CuTest *);
void test_cil_copy_node_helper_ipaddr(CuTest *tc);
void test_cil_copy_node_helper_ipaddr_dup_neg(CuTest *tc);
void test_cil_copy_conditional(CuTest *);
void test_cil_copy_boolif(CuTest *);
void test_cil_copy_node_helper_boolif(CuTest *tc);
void test_cil_copy_constrain(CuTest *);
void test_cil_copy_node_helper_mlsconstrain(CuTest *tc);
void test_cil_copy_ast(CuTest *);
void test_cil_copy_ast_neg(CuTest *);
void test_cil_copy_node_helper_orignull_neg(CuTest *tc);
void test_cil_copy_node_helper_extraargsnull_neg(CuTest *tc);
void test_cil_copy_data_helper(CuTest *tc);
void test_cil_copy_data_helper_getparentsymtab_neg(CuTest *tc);
void test_cil_copy_data_helper_duplicatedb_neg(CuTest *tc);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_fqn.c000066400000000000000000000055201476211737200206730ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "CilTest.h"
#include "../../src/cil_fqn.h"
#include "../../src/cil_build_ast.h"
void test_cil_qualify_name(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "context", "con", "(", "blah_u", "blah_r", "blah_t", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "sid", "test", "con", NULL};
struct cil_tree *tree;
gen_test_tree(&tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, tree->root, test_db->ast->root);
int rc = cil_fqn_qualify(test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_qualify_name_cil_flavor(CuTest *tc) {
char *line[] = {"(", "class", "file", "inherits", "file",
"(", "open", ")", ")", NULL};
struct cil_tree *tree;
gen_test_tree(&tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, tree->root, test_db->ast->root);
int rc = cil_fqn_qualify(test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
libsepol-3.8.1/cil/test/unit/test_cil_fqn.h000066400000000000000000000033621476211737200207020ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_FQN_H_
#define TEST_CIL_FQN_H_
#include "CuTest.h"
void test_cil_qualify_name(CuTest *);
void test_cil_qualify_name_cil_flavor(CuTest *tc);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_lexer.c000066400000000000000000000067321476211737200212340ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "test_cil_lexer.h"
#include "../../src/cil_lexer.h"
void test_cil_lexer_setup(CuTest *tc) {
char *test_str = "(test \"qstring\");comment\n";
uint32_t str_size = strlen(test_str);
char *buffer = malloc(str_size + 2);
memset(buffer+str_size, 0, 2);
strncpy(buffer, test_str, str_size);
int rc = cil_lexer_setup(buffer, str_size + 2);
CuAssertIntEquals(tc, SEPOL_OK, rc);
free(buffer);
}
void test_cil_lexer_next(CuTest *tc) {
char *test_str = "(test \"qstring\") ;comment\n";
uint32_t str_size = strlen(test_str);
char *buffer = malloc(str_size + 2);
memset(buffer+str_size, 0, 2);
strcpy(buffer, test_str);
cil_lexer_setup(buffer, str_size + 2);
struct token test_tok;
int rc = cil_lexer_next(&test_tok);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, OPAREN, test_tok.type);
CuAssertStrEquals(tc, "(", test_tok.value);
CuAssertIntEquals(tc, 1, test_tok.line);
rc = cil_lexer_next(&test_tok);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SYMBOL, test_tok.type);
CuAssertStrEquals(tc, "test", test_tok.value);
CuAssertIntEquals(tc, 1, test_tok.line);
rc = cil_lexer_next(&test_tok);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, QSTRING, test_tok.type);
CuAssertStrEquals(tc, "\"qstring\"", test_tok.value);
CuAssertIntEquals(tc, 1, test_tok.line);
rc = cil_lexer_next(&test_tok);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, CPAREN, test_tok.type);
CuAssertStrEquals(tc, ")", test_tok.value);
CuAssertIntEquals(tc, 1, test_tok.line);
rc = cil_lexer_next(&test_tok);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, COMMENT, test_tok.type);
CuAssertStrEquals(tc, ";comment", test_tok.value);
CuAssertIntEquals(tc, 1, test_tok.line);
free(buffer);
}
libsepol-3.8.1/cil/test/unit/test_cil_lexer.h000066400000000000000000000033471476211737200212400ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_LEXER_H_
#define TEST_CIL_LEXER_H_
#include "CuTest.h"
void test_cil_lexer_setup(CuTest *);
void test_cil_lexer_next(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_list.c000066400000000000000000000256071476211737200210720ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include "CuTest.h"
#include "CilTest.h"
#include "../../src/cil_internal.h"
#include "../../src/cil_build_ast.h"
void test_cil_list_init(CuTest *tc) {
struct cil_avrule *test_avrule = malloc(sizeof(*test_avrule));
cil_classpermset_init(&test_avrule->classpermset);
cil_permset_init(&test_avrule->classpermset->permset);
cil_list_init(&test_avrule->classpermset->permset->perms_list_str);
CuAssertPtrNotNull(tc, test_avrule->classpermset->permset->perms_list_str);
cil_destroy_avrule(test_avrule);
}
void test_cil_list_append_item(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_append_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_list_append_item_append(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_append_item(test_class_list, test_new_item);
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head->next;
int rc2 = cil_list_append_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_list_append_item_append_extra(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", "process", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_append_item(test_class_list, test_new_item);
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head->next;
int rc2 = cil_list_append_item(test_class_list, test_new_item);
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head->next->next;
int rc3 = cil_list_append_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_list_append_item_listnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list = NULL;
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_append_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_list_append_item_itemnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item = NULL;
int rc = cil_list_append_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_list_prepend_item(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_prepend_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_list_prepend_item_prepend(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_prepend_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_list_prepend_item_prepend_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", "process", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
struct cil_list_item *test_new_item_next;
cil_list_item_init(&test_new_item_next);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head->next;
test_new_item->next = test_new_item_next;
int rc = cil_list_prepend_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_list_prepend_item_listnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list = NULL;
struct cil_list_item *test_new_item;
cil_list_item_init(&test_new_item);
test_new_item->flavor = CIL_CLASS;
test_new_item->data = test_tree->root->cl_head->cl_head->next->cl_head;
int rc = cil_list_prepend_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_list_prepend_item_itemnull_neg(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "dir", ")", "(", "create", "relabelto", ")", "(", "eq", "12", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
struct cil_list *test_class_list;
cil_list_init(&test_class_list);
struct cil_list_item *test_new_item = NULL;
int rc = cil_list_prepend_item(test_class_list, test_new_item);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
libsepol-3.8.1/cil/test/unit/test_cil_list.h000066400000000000000000000042361476211737200210720ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_LIST_H_
#define TEST_CIL_LIST_H_
#include "CuTest.h"
void test_cil_list_item_init(CuTest *);
void test_cil_list_append_item(CuTest *);
void test_cil_list_append_item_append(CuTest *);
void test_cil_list_append_item_append_extra(CuTest *);
void test_cil_list_append_item_listnull_neg(CuTest *);
void test_cil_list_append_item_itemnull_neg(CuTest *);
void test_cil_list_prepend_item_prepend(CuTest *);
void test_cil_list_prepend_item_prepend_neg(CuTest *);
void test_cil_list_prepend_item_listnull_neg(CuTest *);
void test_cil_list_prepend_item_itemnull_neg(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_parser.c000066400000000000000000000043601476211737200214040ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "CilTest.h"
#include "test_cil_parser.h"
#include "../../src/cil_parser.h"
#include "../../src/cil_internal.h"
// TODO rewrite to use the gen_tree function
void test_cil_parser(CuTest *tc) {
int rc = 0;
struct cil_file_data *data;
struct cil_tree *test_parse_root;
cil_tree_init(&test_parse_root);
struct cil_db *test_db;
cil_db_init(&test_db);
set_cil_file_data(&data);
rc = cil_parser("policy.cil", data->buffer, data->file_size + 2, &test_parse_root);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_parse_root);
// TODO add checking of the parse tree that is returned
}
libsepol-3.8.1/cil/test/unit/test_cil_parser.h000066400000000000000000000033001476211737200214020ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_PARSER_H_
#define TEST_CIL_PARSER_H_
#include "CuTest.h"
void test_cil_parser(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_post.c000066400000000000000000000506661476211737200211070ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "CilTest.h"
#include "test_cil_post.h"
#include "../../src/cil_post.h"
#include "../../src/cil_internal.h"
void test_cil_post_filecon_compare_meta_a_not_b(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = "ba.r";
afilecon->path_str = "foo";
bfilecon->root_str = "barr";
bfilecon->path_str = "foo";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_filecon_compare_meta_b_not_a(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = "bar";
afilecon->path_str = "foo";
bfilecon->root_str = "ba.rr";
bfilecon->path_str = "foo";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_filecon_compare_meta_a_and_b_strlen_a_greater_b(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = ".\\$";
afilecon->path_str = ".$({";
bfilecon->root_str = ".?";
bfilecon->path_str = ".";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_filecon_compare_type_atype_greater_btype(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = ".\\$";
afilecon->path_str = ".$({";
afilecon->type = CIL_FILECON_CHAR;
bfilecon->root_str = ".\\$";
bfilecon->path_str = ".$({";
bfilecon->type = CIL_FILECON_DIR;
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_filecon_compare_type_btype_greater_atype(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = ".\\$";
afilecon->path_str = ".$({";
afilecon->type = CIL_FILECON_DIR;
bfilecon->root_str = ".\\$";
bfilecon->path_str = ".$({";
bfilecon->type = CIL_FILECON_CHAR;
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_filecon_compare_meta_a_and_b_strlen_b_greater_a(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = ".";
afilecon->path_str = ".";
bfilecon->root_str = ".*+|[({";
bfilecon->path_str = ".";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_filecon_compare_stemlen_a_greater_b(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = "bar";
afilecon->path_str = "foo";
bfilecon->root_str = "barr";
bfilecon->path_str = "foo";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_filecon_compare_stemlen_b_greater_a(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = "barre";
afilecon->path_str = "foo";
bfilecon->root_str = "barr";
bfilecon->path_str = "foo";
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_filecon_compare_equal(CuTest *tc) {
struct cil_filecon *afilecon;
cil_filecon_init(&afilecon);
struct cil_filecon *bfilecon;
cil_filecon_init(&bfilecon);
afilecon->root_str = ".\\$";
afilecon->path_str = ".$({";
afilecon->type = CIL_FILECON_DIR;
bfilecon->root_str = ".\\$";
bfilecon->path_str = ".$({";
bfilecon->type = CIL_FILECON_DIR;
int rc = cil_post_filecon_compare(&afilecon, &bfilecon);
CuAssertIntEquals(tc, 0, rc);
}
void test_cil_post_portcon_compare_atotal_greater_btotal(CuTest *tc) {
struct cil_portcon *aportcon;
cil_portcon_init(&aportcon);
struct cil_portcon *bportcon;
cil_portcon_init(&bportcon);
aportcon->port_low = 15;
aportcon->port_high = 30;
bportcon->port_low = 10;
bportcon->port_high = 11;
int rc = cil_post_portcon_compare(&aportcon, &bportcon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_portcon_compare_btotal_greater_atotal(CuTest *tc) {
struct cil_portcon *aportcon;
cil_portcon_init(&aportcon);
struct cil_portcon *bportcon;
cil_portcon_init(&bportcon);
aportcon->port_low = 5;
aportcon->port_high = 5;
bportcon->port_low = 11;
bportcon->port_high = 20;
int rc = cil_post_portcon_compare(&aportcon, &bportcon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_portcon_compare_aportlow_greater_bportlow(CuTest *tc) {
struct cil_portcon *aportcon;
cil_portcon_init(&aportcon);
struct cil_portcon *bportcon;
cil_portcon_init(&bportcon);
aportcon->port_low = 30;
aportcon->port_high = 33;
bportcon->port_low = 17;
bportcon->port_high = 20;
int rc = cil_post_portcon_compare(&aportcon, &bportcon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_portcon_compare_bportlow_greater_aportlow(CuTest *tc) {
struct cil_portcon *aportcon;
cil_portcon_init(&aportcon);
struct cil_portcon *bportcon;
cil_portcon_init(&bportcon);
aportcon->port_low = 5;
aportcon->port_high = 8;
bportcon->port_low = 17;
bportcon->port_high = 20;
int rc = cil_post_portcon_compare(&aportcon, &bportcon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_portcon_compare_equal(CuTest *tc) {
struct cil_portcon *aportcon;
cil_portcon_init(&aportcon);
struct cil_portcon *bportcon;
cil_portcon_init(&bportcon);
aportcon->port_low = 17;
aportcon->port_high = 20;
bportcon->port_low = 17;
bportcon->port_high = 20;
int rc = cil_post_portcon_compare(&aportcon, &bportcon);
CuAssertTrue(tc, rc == 0);
}
void test_cil_post_genfscon_compare_atypestr_greater_btypestr(CuTest *tc) {
struct cil_genfscon *agenfscon;
cil_genfscon_init(&agenfscon);
agenfscon->fs_str = "aaaa";
struct cil_genfscon *bgenfscon;
cil_genfscon_init(&bgenfscon);
bgenfscon->fs_str = "bbbb";
int rc = cil_post_genfscon_compare(&agenfscon, &bgenfscon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_genfscon_compare_btypestr_greater_atypestr(CuTest *tc) {
struct cil_genfscon *agenfscon;
cil_genfscon_init(&agenfscon);
agenfscon->fs_str = "bbbb";
struct cil_genfscon *bgenfscon;
cil_genfscon_init(&bgenfscon);
bgenfscon->fs_str = "aaaa";
int rc = cil_post_genfscon_compare(&agenfscon, &bgenfscon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_genfscon_compare_apathstr_greater_bpathstr(CuTest *tc) {
struct cil_genfscon *agenfscon;
cil_genfscon_init(&agenfscon);
agenfscon->fs_str = "aaaa";
agenfscon->path_str = "ff";
struct cil_genfscon *bgenfscon;
cil_genfscon_init(&bgenfscon);
bgenfscon->fs_str = "aaaa";
bgenfscon->path_str = "gg";
int rc = cil_post_genfscon_compare(&agenfscon, &bgenfscon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_genfscon_compare_bpathstr_greater_apathstr(CuTest *tc) {
struct cil_genfscon *agenfscon;
cil_genfscon_init(&agenfscon);
agenfscon->fs_str = "bbbb";
agenfscon->path_str = "cccc";
struct cil_genfscon *bgenfscon;
cil_genfscon_init(&bgenfscon);
bgenfscon->fs_str = "bbbb";
bgenfscon->path_str = "aaaa";
int rc = cil_post_genfscon_compare(&agenfscon, &bgenfscon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_genfscon_compare_equal(CuTest *tc) {
struct cil_genfscon *agenfscon;
cil_genfscon_init(&agenfscon);
agenfscon->fs_str = "bbbb";
agenfscon->path_str = "cccc";
struct cil_genfscon *bgenfscon;
cil_genfscon_init(&bgenfscon);
bgenfscon->fs_str = "bbbb";
bgenfscon->path_str = "cccc";
int rc = cil_post_genfscon_compare(&agenfscon, &bgenfscon);
CuAssertIntEquals(tc, 0, rc);
}
void test_cil_post_netifcon_compare_a_greater_b(CuTest *tc) {
struct cil_netifcon *anetifcon;
cil_netifcon_init(&anetifcon);
anetifcon->interface_str = "aaa";
struct cil_netifcon *bnetifcon;
cil_netifcon_init(&bnetifcon);
bnetifcon->interface_str = "bbb";
int rc = cil_post_netifcon_compare(&anetifcon, &bnetifcon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_netifcon_compare_b_greater_a(CuTest *tc) {
struct cil_netifcon *anetifcon;
cil_netifcon_init(&anetifcon);
anetifcon->interface_str = "bbb";
struct cil_netifcon *bnetifcon;
cil_netifcon_init(&bnetifcon);
bnetifcon->interface_str = "aaa";
int rc = cil_post_netifcon_compare(&anetifcon, &bnetifcon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_netifcon_compare_equal(CuTest *tc) {
struct cil_netifcon *anetifcon;
cil_netifcon_init(&anetifcon);
anetifcon->interface_str = "aaa";
struct cil_netifcon *bnetifcon;
cil_netifcon_init(&bnetifcon);
bnetifcon->interface_str = "aaa";
int rc = cil_post_netifcon_compare(&anetifcon, &bnetifcon);
CuAssertTrue(tc, rc == 0);
}
void test_cil_post_nodecon_compare_aipv4_bipv6(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 103;
anodecon->mask->ip.v4.s_addr = 100;
anodecon->addr->family = AF_INET;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET6;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_nodecon_compare_aipv6_bipv4(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 103;
anodecon->mask->ip.v4.s_addr = 100;
anodecon->addr->family = AF_INET6;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_nodecon_compare_aipv4_greaterthan_bipv4(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 103;
anodecon->mask->ip.v4.s_addr = 100;
anodecon->addr->family = AF_INET;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_nodecon_compare_aipv4_lessthan_bipv4(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 99;
anodecon->mask->ip.v4.s_addr = 100;
anodecon->addr->family = AF_INET;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_nodecon_compare_amaskipv4_greaterthan_bmaskipv4(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 103;
anodecon->mask->ip.v4.s_addr = 101;
anodecon->addr->family = AF_INET;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_nodecon_compare_amaskipv4_lessthan_bmaskipv4(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v4.s_addr = 99;
anodecon->mask->ip.v4.s_addr = 99;
anodecon->addr->family = AF_INET;
bnodecon->addr->ip.v4.s_addr = 100;
bnodecon->mask->ip.v4.s_addr = 100;
bnodecon->addr->family = AF_INET;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_nodecon_compare_aipv6_greaterthan_bipv6(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v6.s6_addr[0] = '5';
anodecon->mask->ip.v6.s6_addr[0] = '9';
anodecon->addr->family = AF_INET6;
bnodecon->addr->ip.v6.s6_addr[0] = '3';
bnodecon->mask->ip.v6.s6_addr[0] = '9';
bnodecon->addr->family = AF_INET6;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_nodecon_compare_aipv6_lessthan_bipv6(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v6.s6_addr[0] = '3';
anodecon->mask->ip.v6.s6_addr[0] = '1';
anodecon->addr->family = AF_INET6;
bnodecon->addr->ip.v6.s6_addr[0] = '5';
bnodecon->mask->ip.v6.s6_addr[0] = '1';
bnodecon->addr->family = AF_INET6;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_nodecon_compare_amaskipv6_greaterthan_bmaskipv6(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v6.s6_addr[0] = '1';
anodecon->mask->ip.v6.s6_addr[0] = '4';
anodecon->addr->family = AF_INET6;
bnodecon->addr->ip.v6.s6_addr[0] = '1';
bnodecon->mask->ip.v6.s6_addr[0] = '3';
bnodecon->addr->family = AF_INET6;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_nodecon_compare_amaskipv6_lessthan_bmaskipv6(CuTest *tc) {
struct cil_nodecon *anodecon;
cil_nodecon_init(&anodecon);
cil_ipaddr_init(&anodecon->addr);
cil_ipaddr_init(&anodecon->mask);
struct cil_nodecon *bnodecon;
cil_nodecon_init(&bnodecon);
cil_ipaddr_init(&bnodecon->addr);
cil_ipaddr_init(&bnodecon->mask);
anodecon->addr->ip.v6.s6_addr[0] = '5';
anodecon->mask->ip.v6.s6_addr[0] = '1';
anodecon->addr->family = AF_INET6;
bnodecon->addr->ip.v6.s6_addr[0] = '5';
bnodecon->mask->ip.v6.s6_addr[0] = '6';
bnodecon->addr->family = AF_INET6;
int rc = cil_post_nodecon_compare(&anodecon, &bnodecon);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_fsuse_compare_type_a_greater_b(CuTest *tc) {
struct cil_fsuse *afsuse;
cil_fsuse_init(&afsuse);
afsuse->type = CIL_FSUSE_XATTR;
struct cil_fsuse *bfsuse;
cil_fsuse_init(&bfsuse);
bfsuse->type = CIL_FSUSE_TASK;
int rc = cil_post_fsuse_compare(&afsuse, &bfsuse);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_fsuse_compare_type_b_greater_a(CuTest *tc) {
struct cil_fsuse *afsuse;
cil_fsuse_init(&afsuse);
afsuse->type = CIL_FSUSE_TASK;
struct cil_fsuse *bfsuse;
cil_fsuse_init(&bfsuse);
bfsuse->type = CIL_FSUSE_XATTR;
int rc = cil_post_fsuse_compare(&afsuse, &bfsuse);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_fsuse_compare_fsstr_a_greater_b(CuTest *tc) {
struct cil_fsuse *afsuse;
cil_fsuse_init(&afsuse);
afsuse->type = CIL_FSUSE_XATTR;
afsuse->fs_str = "aaa";
struct cil_fsuse *bfsuse;
cil_fsuse_init(&bfsuse);
bfsuse->type = CIL_FSUSE_XATTR;
bfsuse->fs_str = "bbb";
int rc = cil_post_fsuse_compare(&afsuse, &bfsuse);
CuAssertTrue(tc, rc < 0);
}
void test_cil_post_fsuse_compare_fsstr_b_greater_a(CuTest *tc) {
struct cil_fsuse *afsuse;
cil_fsuse_init(&afsuse);
afsuse->type = CIL_FSUSE_XATTR;
afsuse->fs_str = "bbb";
struct cil_fsuse *bfsuse;
cil_fsuse_init(&bfsuse);
bfsuse->type = CIL_FSUSE_XATTR;
bfsuse->fs_str = "aaa";
int rc = cil_post_fsuse_compare(&afsuse, &bfsuse);
CuAssertTrue(tc, rc > 0);
}
void test_cil_post_fsuse_compare_equal(CuTest *tc) {
struct cil_fsuse *afsuse;
cil_fsuse_init(&afsuse);
afsuse->type = CIL_FSUSE_XATTR;
afsuse->fs_str = "foo";
struct cil_fsuse *bfsuse;
cil_fsuse_init(&bfsuse);
bfsuse->type = CIL_FSUSE_XATTR;
bfsuse->fs_str = "foo";
int rc = cil_post_fsuse_compare(&afsuse, &bfsuse);
CuAssertTrue(tc, rc == 0);
}
libsepol-3.8.1/cil/test/unit/test_cil_post.h000066400000000000000000000101701476211737200210760ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_POLICY_H_
#define TEST_CIL_POLICY_H_
#include "CuTest.h"
void test_cil_post_filecon_compare_meta_a_not_b(CuTest *tc);
void test_cil_post_filecon_compare_meta_b_not_a(CuTest *tc);
void test_cil_post_filecon_compare_meta_a_and_b_strlen_a_greater_b(CuTest *tc);
void test_cil_post_filecon_compare_meta_a_and_b_strlen_b_greater_a(CuTest *tc);
void test_cil_post_filecon_compare_type_atype_greater_btype(CuTest *tc);
void test_cil_post_filecon_compare_type_btype_greater_atype(CuTest *tc);
void test_cil_post_filecon_compare_stemlen_a_greater_b(CuTest *tc);
void test_cil_post_filecon_compare_stemlen_b_greater_a(CuTest *tc);
void test_cil_post_filecon_compare_equal(CuTest *tc);
void test_cil_post_portcon_compare_atotal_greater_btotal(CuTest *tc);
void test_cil_post_portcon_compare_btotal_greater_atotal(CuTest *tc);
void test_cil_post_portcon_compare_aportlow_greater_bportlow(CuTest *tc);
void test_cil_post_portcon_compare_bportlow_greater_aportlow(CuTest *tc);
void test_cil_post_portcon_compare_equal(CuTest *tc);
void test_cil_post_genfscon_compare_atypestr_greater_btypestr(CuTest *tc);
void test_cil_post_genfscon_compare_btypestr_greater_atypestr(CuTest *tc);
void test_cil_post_genfscon_compare_apathstr_greater_bpathstr(CuTest *tc);
void test_cil_post_genfscon_compare_bpathstr_greater_apathstr(CuTest *tc);
void test_cil_post_genfscon_compare_equal(CuTest *tc);
void test_cil_post_netifcon_compare_a_greater_b(CuTest *tc);
void test_cil_post_netifcon_compare_b_greater_a(CuTest *tc);
void test_cil_post_netifcon_compare_equal(CuTest *tc);
void test_cil_post_nodecon_compare_aipv4_bipv6(CuTest *tc);
void test_cil_post_nodecon_compare_aipv6_bipv4(CuTest *tc);
void test_cil_post_nodecon_compare_aipv4_greaterthan_bipv4(CuTest *tc);
void test_cil_post_nodecon_compare_aipv4_lessthan_bipv4(CuTest *tc);
void test_cil_post_nodecon_compare_amaskipv4_greaterthan_bmaskipv4(CuTest *tc);
void test_cil_post_nodecon_compare_amaskipv4_lessthan_bmaskipv4(CuTest *tc);
void test_cil_post_nodecon_compare_aipv6_greaterthan_bipv6(CuTest *tc);
void test_cil_post_nodecon_compare_aipv6_lessthan_bipv6(CuTest *tc);
void test_cil_post_nodecon_compare_amaskipv6_greaterthan_bmaskipv6(CuTest *tc);
void test_cil_post_nodecon_compare_amaskipv6_lessthan_bmaskipv6(CuTest *tc);
void test_cil_post_fsuse_compare_type_a_greater_b(CuTest *tc);
void test_cil_post_fsuse_compare_type_b_greater_a(CuTest *tc);
void test_cil_post_fsuse_compare_fsstr_a_greater_b(CuTest *tc);
void test_cil_post_fsuse_compare_fsstr_b_greater_a(CuTest *tc);
void test_cil_post_fsuse_compare_equal(CuTest *tc);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_resolve_ast.c000066400000000000000000014225521476211737200224460ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "CilTest.h"
#include "../../src/cil_build_ast.h"
#include "../../src/cil_resolve_ast.h"
#include "../../src/cil_verify.h"
#include "../../src/cil_internal.h"
/* this all needs to be moved to a private header file */
int __cil_resolve_ast_node_helper(struct cil_tree_node *, uint32_t *, void *);
int __cil_disable_children_helper(struct cil_tree_node *node, __attribute__((unused)) uint32_t *finished, void *);
struct cil_args_resolve {
struct cil_db *db;
enum cil_pass pass;
uint32_t *changed;
struct cil_tree_node *callstack;
struct cil_tree_node *optstack;
struct cil_tree_node *macro;
};
struct cil_args_resolve *gen_resolve_args(struct cil_db *db, enum cil_pass pass, uint32_t *changed, struct cil_tree_node *calls, struct cil_tree_node *opts, struct cil_tree_node *macro)
{
struct cil_args_resolve *args = cil_malloc(sizeof(*args));
args->db = db;
args->pass = pass;
args->changed = changed;
args->callstack = calls;
args->optstack = opts;
args->macro = macro;
return args;
}
void test_cil_resolve_name(CuTest *tc) {
char *line[] = { "(", "block", "foo",
"(", "typealias", "test", "type_t", ")",
"(", "type", "test", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_curr = test_db->ast->root->cl_head->cl_head;
struct cil_typealias *test_alias = (struct cil_typealias*)test_curr->data;
struct cil_tree_node *type_node = NULL;
int rc = cil_resolve_name(test_curr, test_alias->type_str, CIL_SYM_TYPES, args, &type_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_name_invalid_type_neg(CuTest *tc) {
char *line[] = { "(", "block", "foo",
"(", "typealias", "foo.test2", "type_t", ")",
"(", "type", "test", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_curr = test_db->ast->root->cl_head->cl_head;
struct cil_typealias *test_alias = (struct cil_typealias*)test_curr->data;
struct cil_tree_node *type_node = NULL;
int rc = cil_resolve_name(test_curr, test_alias->type_str, CIL_SYM_TYPES, args, &type_node);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_curr_null_neg(CuTest *tc) {
struct cil_db *test_db;
cil_db_init(&test_db);
test_db->ast->root = NULL;
int rc = cil_resolve_ast(test_db, test_db->ast->root);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
/*
cil_resolve test cases
*/
void test_cil_resolve_roleallow(CuTest *tc) {
char *line[] = {"(", "role", "foo", ")", \
"(", "role", "bar", ")", \
"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roleallow(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_roleallow_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "bar", ")", \
"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc1=cil_build_ast(test_db, test_tree->root, test_db->ast->root);
rc1 = rc1;
int rc = cil_resolve_roleallow(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roleallow_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo", ")", \
"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roleallow(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classmapping_anon(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "open", ")", ")",
"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "(", "file", "(", "open", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classmapping_anon_inmacro(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "(", "file", "(", "open", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
args->pass = CIL_PASS_CALL1;
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next;
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_classmapping_anon_inmacro_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "(", "DNE", "(", "open", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
args->pass = CIL_PASS_CALL1;
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next;
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_classmapping_named(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "classpermissionset", "char_w", "(", "char", "(", "read", ")", ")", ")",
"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classmapping_named_classmapname_neg(CuTest *tc) {
char *line[] = {"(", "classpermissionset", "char_w", "(", "char", "(", "read", ")", ")", ")",
"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classmapping_anon_classmapname_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "open", ")", ")",
"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "dne", "read", "(", "file", "(", "open", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classmapping_anon_permset_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "open", ")", ")",
"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "(", "dne", "(", "open", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classmapping(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rolebounds(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "role", "role2", ")",
"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rolebounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_rolebounds_exists_neg(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "role", "role2", ")",
"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_rolebounds(test_db->ast->root->cl_head->next->next, args);
int rc = cil_resolve_rolebounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_rolebounds_role1_neg(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "role", "role2", ")",
"(", "rolebounds", "role_DNE", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rolebounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rolebounds_role2_neg(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "role", "role2", ")",
"(", "rolebounds", "role1", "role_DNE", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rolebounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_sensalias(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_sensalias_sensdecl_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_sensalias(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_catalias(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_catalias(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_catalias_catdecl_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_catalias(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_catorder(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c3", ")",
"(", "categoryorder", "(", "c0", "c3", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
int rc = cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
int rc2 = cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_resolve_catorder_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c3", ")",
"(", "categoryorder", "(", "c5", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
int rc = cil_resolve_dominance(test_db->ast->root->cl_head->next->next->next, args);
int rc2 = cil_resolve_dominance(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_resolve_dominance_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s6", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_dominance(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_cat_list(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_list *test_cat_list;
cil_list_init(&test_cat_list);
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_cat_list_catlistnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_list *test_cat_list;
cil_list_init(&test_cat_list);
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->data;
test_catset->cat_list_str = NULL;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_cat_list_rescatlistnull_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_list *test_cat_list = NULL;
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_cat_list_catrange(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")",
"(", "categoryset", "somecats", "(", "c0", "(", "c1", "c2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
struct cil_list *test_cat_list;
cil_list_init(&test_cat_list);
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_cat_list_catrange_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")",
"(", "categoryset", "somecats", "(", "c0", "(", "c2", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_list *test_cat_list;
cil_list_init(&test_cat_list);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MLS;
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_cat_list_catname_neg(CuTest *tc) {
char *line[] = {"(", "category", "c5", ")",
"(", "category", "c6", ")",
"(", "category", "c7", ")",
"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")",
"(", "categoryset", "somecats", "(", "c0", "(", "c1", "c2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MLS;
struct cil_list *test_cat_list;
cil_list_init(&test_cat_list);
struct cil_catset *test_catset = (struct cil_catset*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_cat_list(test_db->ast->root->cl_head->next->next->next->next, test_catset->cat_list_str, test_cat_list, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_catset(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_catset *test_catset = (struct cil_catset *)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_catset(test_db->ast->root->cl_head->next->next->next, test_catset, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_catset_catlist_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", "c4", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_catset *test_catset = (struct cil_catset *)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_catset(test_db->ast->root->cl_head->next->next->next, test_catset, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_catrange(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_catrange(test_db->ast->root->cl_head->next->next->next, (struct cil_catrange*)test_db->ast->root->cl_head->next->next->next->data, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_catrange_catloworder_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
test_db->catorder->head = test_db->catorder->head->next;
test_db->catorder->head->next = NULL;
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_catrange(test_db->ast->root->cl_head->next->next->next, (struct cil_catrange*)test_db->ast->root->cl_head->next->next->next->data, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_catrange_cathighorder_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c255", "c0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_catrange(test_db->ast->root->cl_head->next->next->next, (struct cil_catrange*)test_db->ast->root->cl_head->next->next->next->data, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_catrange_cat1_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c12", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_catrange(test_db->ast->root->cl_head->next->next->next, (struct cil_catrange*)test_db->ast->root->cl_head->next->next->next->data, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_catrange_cat2_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c0", "c23", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_catrange(test_db->ast->root->cl_head->next->next->next, (struct cil_catrange*)test_db->ast->root->cl_head->next->next->next->data, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_senscat_catrange_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "category", "c500", ")",
"(", "categoryorder", "(", "c0", "c255", "c500", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "(", "c255", "c5", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MLS;
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_senscat_catsetname(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "category", "c500", ")",
"(", "categoryset", "foo", "(", "c0", "c255", "c500", ")", ")",
"(", "categoryorder", "(", "c0", "c255", "c500", ")", ")",
"(", "sensitivitycategory", "s1", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_catset *test_catset = (struct cil_catset *)test_db->ast->root->cl_head->next->next->next->next->next->data;
cil_resolve_catset(test_db->ast->root->cl_head->next->next->next->next->next, test_catset, args);
args->pass = CIL_PASS_MISC2;
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_senscat_catsetname_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "category", "c500", ")",
"(", "sensitivitycategory", "s1", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_senscat_sublist(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c1", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "(", "c1", "c255", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_senscat_missingsens_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_senscat_category_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c5", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_senscat_currrangecat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c1", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "(", "c1", "c255", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MISC2;
int rc = cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_level(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
int rc2 = cil_resolve_level(level->next, (struct cil_level*)level->next->data, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_resolve_level_catlist(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "categoryorder", "(", "c0", "c1", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", "c1", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c0", "c1", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", "c1", ")", ")", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_level_catset(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "cats", "(", "c0", "c1", "c2", ")", ")",
"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "cats", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "cats", ")", ")",
"(", "level", "high", "(", "s0", "(", "cats", ")", ")", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
struct cil_catset *cs = (struct cil_catset *)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_catorder(test_db->ast->root->cl_head->next->next->next->next, args);
args->pass = CIL_PASS_MLS;
cil_resolve_catset(test_db->ast->root->cl_head->next->next->next, cs, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_level_catset_name_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "cats", "(", "c0", "c1", "c2", ")", ")",
"(", "categoryorder", "(", "c0", "c1", "c2", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "cats", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "dne", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_level_sens_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s1", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s1", "(", "c0", ")", ")", ")",
"(", "sid", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
int rc2 = cil_resolve_level(level->next, (struct cil_level*)level->next->data, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc2);
}
void test_cil_resolve_level_cat_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c1", ")", ")", ")",
"(", "sid", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
int rc2 = cil_resolve_level(level->next, (struct cil_level*)level->next->data, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc2);
}
void test_cil_resolve_level_senscat_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s1", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "sid", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_level(level, (struct cil_level*)level->data, args);
int rc2 = cil_resolve_level(level->next, (struct cil_level*)level->next->data, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, SEPOL_ERR, rc2);
}
void test_cil_resolve_levelrange_namedlvl(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "range", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->next->next->data;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_levelrange_namedlvl_low_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "range", "(", "DNE", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->next->next->data;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_levelrange_namedlvl_high_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "range", "(", "low", "DNE", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->next->next->data;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_levelrange_anonlvl(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_levelrange_anonlvl_low_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "DNE", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->data;
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_levelrange_anonlvl_high_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "dne", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
struct cil_levelrange *lvlrange = (struct cil_levelrange *)test_db->ast->root->cl_head->next->next->next->data;
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_levelrange(test_db->ast->root->cl_head->next->next->next, lvlrange, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_constrain(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_constrain(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_constrain_class_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "foo", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_constrain(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_constrain_perm_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_constrain(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_constrain_perm_resolve_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "file", "(", "foo", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_constrain(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_context(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_context_macro(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "macro", "mm", "(", "(", "levelrange", "range", ")", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "range", ")", ")", ")",
"(", "call", "mm", "(", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->cl_head->data;
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, test_context, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_context_macro_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "macro", "mm", "(", "(", "levelrange", "range", ")", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "range", ")", ")", ")",
"(", "call", "mm", "(", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "DNE", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->cl_head->data;
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_context_namedrange(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "range", "(", "low", "high", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "range", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_context_namedrange_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "range", "(", "low", "high", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "DNE", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_context_user_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_context_role_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_context_type_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_context_anon_level_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "DNE", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_context *test_context = (struct cil_context*)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->data;
int rc = cil_resolve_context(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, test_context, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roletransition(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "type", "bar_t", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_roletransition_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "bar_t", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletransition(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roletransition_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletransition(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roletransition_resultdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "type", "bar_t", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletransition(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typeattributeset_type_in_multiple_attrs(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "typeattribute", "attrs2", ")",
"(", "type", "type_t", ")",
"(", "typeattributeset", "attrs2", "type_t", ")",
"(", "typeattributeset", "attrs", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next->next->next, args);
int rc2 = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_resolve_typeattributeset_multiple_excludes_with_not(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "typeattribute", "attrs2", ")",
"(", "type", "type_t", ")",
"(", "type", "type_b", ")",
"(", "type", "type_a", ")",
"(", "typeattributeset", "attrs", "(", "and", "type_a", "type_b", ")", ")",
"(", "typeattributeset", "attrs2", "(", "not", "attrs", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typeattributeset_multiple_types_with_and(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "type", "type_t", ")",
"(", "type", "type_tt", ")",
"(", "typeattributeset", "attrs", "(", "and", "type_t", "type_tt", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typeattributeset_using_attr(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "typeattribute", "attr_a", ")",
"(", "typeattributeset", "attrs", "attr_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typeattributeset_name_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_t", ")",
"(", "typeattributeset", "attrs", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typeattributeset_undef_type_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "typeattributeset", "attrs", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typeattributeset_not(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "type", "type_t", ")",
"(", "type", "t_t", ")",
"(", "typeattributeset", "attrs", "(", "not", "t_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typeattributeset_undef_type_not_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "type", "type_t", ")",
"(", "typeattributeset", "attrs", "(", "not", "t_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_typeattributeset(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typealias(CuTest *tc) {
char *line[] = {"(", "block", "foo",
"(", "typealias", ".foo.test", "type_t", ")",
"(", "type", "test", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typealias(test_db->ast->root->cl_head->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typealias_neg(CuTest *tc) {
char *line[] = {"(", "block", "foo",
"(", "typealias", ".foo", "apache_alias", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typealias(test_db->ast->root->cl_head->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typebounds(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typebounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typebounds_repeatbind_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typebounds(test_db->ast->root->cl_head->next->next, args);
int rc2 = cil_resolve_typebounds(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_ERR, rc2);
}
void test_cil_resolve_typebounds_type1_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typebounds(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typebounds_type2_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typebounds(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_typepermissive(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typepermissive(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_typepermissive_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "typepermissive", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_typepermissive(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nametypetransition(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nametypetransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nametypetransition_src_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "wrong", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nametypetransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nametypetransition_tgt_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "wrong", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nametypetransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nametypetransition_class_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "bar", "wrong", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nametypetransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nametypetransition_dest_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "bar", "file", "wrong", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nametypetransition(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_rangetransition_namedrange_anon(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "levelrange", "l", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "l", ")", ")",
"(", "call", "mm", "(", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_namedrange_anon_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "levelrange", "l", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "l", ")", ")",
"(", "call", "mm", "(", "(", "DNE", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_namedrange(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "foo_range", "(", "low", "high", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "foo_range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_rangetransition_namedrange_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "levelrange", "foo_range", "(", "low", "high", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "DNE", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_type1_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_DNE", "type_b", "class_", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_type2_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_DNE", "class_", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_class_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_DNE", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_call_level_l_anon(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "l", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "l", "high", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_call_level_l_anon_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "l", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "l", "high", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c4", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_call_level_h_anon(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "h", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "h", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_call_level_h_anon_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "h", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "h", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c4", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next->next;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_rangetransition_level_l_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low_DNE", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_level_h_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "high_DNE", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_anon_level_l(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "(", "s0", "(", "c0", ")", ")", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_rangetransition_anon_level_l_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "(", "s0", "(", "c_DNE", ")", ")", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_rangetransition_anon_level_h(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_rangetransition_anon_level_h_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "(", "s_DNE", "(", "c0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_rangetransition(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classcommon(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", ")", ")",
"(", "common", "file", "(", "write", ")", ")",
"(", "classcommon", "file", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classcommon(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classcommon_no_class_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "classcommon", "foo", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classcommon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classcommon_no_common_neg(CuTest *tc) {
char *line[] = {"(", "common", "foo", "(", "read", ")", ")",
"(", "classcommon", "foo", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_classcommon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classpermset_named(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "char", "(", "read", ")", ")",
"(", "classpermissionset", "char_w", "(", "char", "(", "read", ")", ")", ")",
"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = test_db->ast->root->cl_head->next->next->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next->next->next, cps, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classpermset_named_namedpermlist(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "char", "(", "read", ")", ")",
"(", "classpermissionset", "char_w", "(", "char", "baz", ")", ")",
"(", "permissionset", "baz", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = test_db->ast->root->cl_head->next->next->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next->next->next, cps, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classpermset_named_permlist_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "char", "(", "read", ")", ")",
"(", "classpermissionset", "char_w", "(", "dne", "(", "read", ")", ")", ")",
"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = test_db->ast->root->cl_head->next->next->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next->next->next, cps, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_classpermset_named_unnamedcps_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "char", "(", "read", ")", ")",
"(", "classpermissionset", "char_w", "(", "char", "(", "read", ")", ")", ")",
"(", "classmapping", "files", "read", "char_w", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps;
cil_classpermset_init(&cps);
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next->next->next, cps, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_classpermset_anon(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "(", "char", "(", "read", ")", ")", ")",
"(", "class", "char", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = ((struct cil_classmapping*)test_db->ast->root->cl_head->next->data)->classpermsets_str->head->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next, cps, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classpermset_anon_namedpermlist(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "(", "char", "baz", ")", ")",
"(", "permissionset", "baz", "(", "read", ")", ")",
"(", "class", "char", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = ((struct cil_classmapping*)test_db->ast->root->cl_head->next->data)->classpermsets_str->head->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next, cps, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_classpermset_anon_permlist_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "classmapping", "files", "read", "(", "char", "(", "dne", ")", ")", ")",
"(", "class", "char", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_classpermset *cps = ((struct cil_classmapping*)test_db->ast->root->cl_head->next->data)->classpermsets_str->head->data;
int rc = cil_resolve_classpermset(test_db->ast->root->cl_head->next, cps, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_avrule_permset(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "permissionset", "baz", "(", "open", "write", ")", ")",
"(", "allow", "test", "foo", "(", "bar", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_avrule_permset_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "permissionset", "baz", "(", "open", "close", ")", ")",
"(", "allow", "test", "foo", "(", "bar", "dne", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule_permset_permdne_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "permissionset", "baz", "(", "open", "dne", ")", ")",
"(", "allow", "test", "foo", "(", "bar", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule_firsttype_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "fail1", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule_secondtype_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "fail2", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule_class_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "fail3", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_avrule_perm_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "bar", "(", "execute", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_avrule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_transition(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_type_rule_transition_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_transition_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_transition_objdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_transition_resultdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_change(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_type_rule_change_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_change_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_change_objdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_change_resultdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_member(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_type_rule_member_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_member_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_member_objdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_type_rule_member_resultdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_type_rule(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_filecon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "filecon", "root", "path", "file", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_filecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_filecon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "filecon", "root", "path", "file", "conn", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_filecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_filecon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "filecon", "root", "path", "file", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_filecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_filecon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "filecon", "root", "path", "file", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_filecon(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_portcon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "portcon", "udp", "25", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_portcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_portcon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "portcon", "udp", "25", "conn", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_portcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_portcon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "portcon", "udp", "25", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_portcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_portcon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "portcon", "udp", "25", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_portcon(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_genfscon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_genfscon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_genfscon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "genfscon", "type", "path", "conn", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_genfscon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_genfscon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "genfscon", "type", "path", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_genfscon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_genfscon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "genfscon", "type", "path", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_genfscon(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nodecon_ipv4(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "ip", "netmask", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_ipv6(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "2001:0DB8:AC10:FE01::", ")",
"(", "ipaddr", "netmask", "2001:0DB8:AC10:FE01::", ")",
"(", "nodecon", "ip", "netmask", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_anonipaddr_ipv4(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "(", "192.168.1.1", ")", "netmask", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_anonnetmask_ipv4(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "nodecon", "ip", "(", "192.168.1.1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_anonipaddr_ipv6(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "netmask", "2001:0DB8:AC10:FE01::", ")",
"(", "nodecon", "(", "2001:0DB8:AC10:FE01::", ")", "netmask", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_anonnetmask_ipv6(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "2001:0DB8:AC10:FE01::", ")",
"(", "nodecon", "ip", "(", "2001:0DB8:AC10:FE01::", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_diffipfam_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "2001:0DB8:AC10:FE01::", ")",
"(", "nodecon", "ip", "(", "192.168.1.1", ")", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_nodecon_context_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "n", "netmask", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nodecon_ipaddr_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "ip", "n", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nodecon_netmask_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "nodecon", "ip", "ip", "conn", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_nodecon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "nodecon", "ip", "ip", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_nodecon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "nodecon", "ip", "ip", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_nodecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_netifcon(CuTest *tc) {
char *line[] = {"(", "context", "if_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_netifcon_otf_neg(CuTest *tc) {
char *line[] = {"(", "context", "if_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_netifcon_interface_neg(CuTest *tc) {
char *line[] = {"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_netifcon_unnamed(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_netifcon_unnamed_packet_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_netifcon_unnamed_otf_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")",
"(", "system_u", "foo_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_netifcon_sublist_secondlist_missing_neg(CuTest *tc) {
char *line[] = {"(", "netifcon", "eth1",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_netifcon(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_pirqcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pirqcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_pirqcon_context_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pirqcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pirqcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_pirqcon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "etc_t", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "pirqcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_pirqcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_pirqcon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "pirqcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pirqcon(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_iomemcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_iomemcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_iomemcon_context_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "iomemcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_iomemcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_iomemcon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "etc_t", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "iomemcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_iomemcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_iomemcon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "iomemcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_iomemcon(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ioportcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_ioportcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ioportcon_context_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "ioportcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_ioportcon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ioportcon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "etc_t", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "ioportcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_ioportcon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ioportcon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "ioportcon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_ioportcon(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_pcidevicecon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pcidevicecon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_pcidevicecon_context_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pcidevicecon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pcidevicecon(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_pcidevicecon_anon_context(CuTest *tc) {
char *line[] = {"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "etc_t", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "pcidevicecon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_pcidevicecon(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_pcidevicecon_anon_context_neg(CuTest *tc) {
char *line[] = {"(", "pcidevicecon", "1", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_pcidevicecon(test_db->ast->root->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_fsuse(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con", "(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")",
"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_fsuse(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_fsuse_nocontext_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con", "(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")",
"(", "fsuse", "xattr", "ext3", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_fsuse(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_fsuse_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con", "(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")",
"(", "fsuse", "xattr", "ext3", "conn", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_fsuse(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_fsuse_anon(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "fsuse", "xattr", "ext3", "(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_fsuse(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_fsuse_anon_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "fsuse", "xattr", "ext3", "(", "system_uu", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_fsuse(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_sidcontext(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "sid", "test", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_sidcontext(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_sidcontext_named_levels(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "sid", "test", ")",
"(", "sidcontext", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *level = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
cil_resolve_level(level, (struct cil_level*)level->data, args);
cil_resolve_level(level->next, (struct cil_level*)level->next->data, args);
int rc = cil_resolve_sidcontext(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_sidcontext_named_context(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "context", "con", "(", "blah_u", "blah_r", "blah_t", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")",
"(", "sid", "test", ")",
"(", "sidcontext", "test", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *context = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
cil_resolve_context(context, (struct cil_context*)context->data, args);
int rc = cil_resolve_sidcontext(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_sidcontext_named_context_wrongname_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "context", "con", "(", "blah_u", "blah_r", "blah_t", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")",
"(", "sid", "test", ")",
"(", "sidcontext", "test", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
struct cil_tree_node *context = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
cil_resolve_context(context, (struct cil_context*)context->data, args);
int rc = cil_resolve_sidcontext(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_sidcontext_named_context_invaliduser_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "sid", "test", ")",
"(", "sidcontext", "test", "(", "", "blah_r", "blah_t", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_sidcontext(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_blockinherit(CuTest *tc) {
char *line[] = {"(", "block", "baz", "(", "type", "b", ")", ")",
"(", "block", "foo", "(", "type", "a", ")",
"(", "blockinherit", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_blockinherit(test_db->ast->root->cl_head->next->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_blockinherit_blockstrdne_neg(CuTest *tc) {
char *line[] = {"(", "block", "baz", "(", "type", "b", ")", ")",
"(", "block", "foo", "(", "type", "a", ")",
"(", "blockinherit", "dne", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_blockinherit(test_db->ast->root->cl_head->next->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_in_block(CuTest *tc) {
char *line[] = {"(", "class", "char", "(", "read", ")", ")",
"(", "block", "foo", "(", "type", "a", ")", ")",
"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_in(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_in_blockstrdne_neg(CuTest *tc) {
char *line[] = {"(", "class", "char", "(", "read", ")", ")",
"(", "in", "foo", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_in(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_in_macro(CuTest *tc) {
char *line[] = {"(", "class", "char", "(", "read", "write", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "allow", "foo", "bar", "(", "file", "(", "write", ")", ")", ")", ")",
"(", "in", "mm", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_in(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_in_optional(CuTest *tc) {
char *line[] = {"(", "class", "char", "(", "read", "write", ")", ")",
"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")",
"(", "in", "opt", "(", "allow", "test", "baz", "(", "char", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_in(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_noparam(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", ")", ")",
"(", "type", "b", ")",
"(", "allow", "qaz", "b", "file", "(", "read", ")", ")", ")",
"(", "call", "mm", "(", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_type(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_role(CuTest *tc) {
char *line[] = {"(", "role", "role_r", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "role", "a", ")", ")",
"(", "role", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_user(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "user", "a", ")", ")",
"(", "user", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "user_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_sens(CuTest *tc) {
char *line[] = {"(", "sensitivity", "sens", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "sensitivity", "a", ")", ")",
"(", "sensitivity", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "sens", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_cat(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "category", "a", ")", ")",
"(", "category", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "c0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_catset(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")",
"(", "macro", "mm", "(", "(", "categoryset", "foo", ")", ")",
"(", "level", "bar", "(", "s0", "foo", ")", ")", ")",
"(", "call", "mm", "(", "somecats", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_catset_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "macro", "mm", "(", "(", "categoryset", "foo", ")", ")",
"(", "level", "bar", "(", "s0", "foo", ")", ")", ")",
"(", "call", "mm", "(", "(", "c0", "c1", "c2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_catset_anon_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "macro", "mm", "(", "(", "categoryset", "foo", ")", ")",
"(", "level", "bar", "(", "s0", "foo", ")", ")", ")",
"(", "call", "mm", "(", "(", "c5", "(", "c2", ")", "c4", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_level(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", "(", "level", "lvl_h", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")", ")",
"(", "call", "mm", "(", "l", "h", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_level_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "h", ")", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_level_anon_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "h", ")", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", "(", "c5", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_ipaddr(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "lvl_l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "lvl_h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.0.1", ")",
"(", "ipaddr", "ip", "192.168.0.1", ")",
"(", "macro", "mm", "(", "(", "ipaddr", "addr", ")", ")",
"(", "nodecon", "addr", "netmask", "con", ")", ")",
"(", "call", "mm", "(", "ip", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_ipaddr_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "lvl_l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "lvl_h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.0.1", ")",
"(", "macro", "mm", "(", "(", "ipaddr", "addr", ")", ")",
"(", "nodecon", "addr", "netmask", "con", ")", ")",
"(", "call", "mm", "(", "(", "192.168.1.1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_ipaddr_anon_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "lvl_l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "lvl_h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.0.1", ")",
"(", "macro", "mm", "(", "(", "ipaddr", "addr", ")", ")",
"(", "nodecon", "addr", "netmask", "con", ")", ")",
"(", "call", "mm", "(", "(", "192.1.1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_class(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_classmap(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classmap", "a", ")", ")",
"(", "classmapping", "a", "read", "(", "file", "(", "open", ")", ")", ")", ")",
"(", "call", "mm", "(", "(", "read", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_permset(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "open", ")", ")",
"(", "type", "dead", ")",
"(", "type", "bar", ")",
"(", "class", "baz", "(", "close", "read", "open", ")", ")",
"(", "macro", "mm", "(", "(", "permissionset", "a", ")", ")",
"(", "allow", "dead", "bar", "(", "baz", "a", ")", ")", ")",
"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_permset_anon(CuTest *tc) {
char *line[] = {"(", "type", "dead", ")",
"(", "type", "bar", ")",
"(", "class", "baz", "(", "close", "read", "open", ")", ")",
"(", "macro", "mm", "(", "(", "permissionset", "a", ")", ")",
"(", "allow", "dead", "bar", "(", "baz", "a", ")", ")", ")",
"(", "call", "mm", "(", "(", "read", "open", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_classpermset_named(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "classpermissionset", "char_w", "(", "file", "(", "open", ")", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "char_w", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_classpermset_anon(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "(", "file", "(", "open", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_classpermset_anon_neg(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "(", "file", "(", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_unknown_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *macro_node = NULL;
cil_resolve_name(test_db->ast->root->cl_head->next->next->next, ((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data)->macro_str, CIL_SYM_BLOCKS, args, ¯o_node);
((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data)->macro = (struct cil_macro*)macro_node->data;
free(((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data)->macro_str);
((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data)->macro_str = NULL;
((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data)->macro->params->head->flavor = CIL_NETIFCON;
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_unknowncall_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "m", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_call1_extraargs_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "foo", "bar", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_copy_dup(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "qaz", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call1_missing_arg_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", "(", "level", "lvl_h", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")", ")",
"(", "call", "mm", "(", "l", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_paramsflavor_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *macro_node = NULL;
struct cil_call *new_call = ((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data);
cil_resolve_name(test_db->ast->root->cl_head->next->next->next, new_call->macro_str, CIL_SYM_BLOCKS, args, ¯o_node);
new_call->macro = (struct cil_macro*)macro_node->data;
struct cil_list_item *item = new_call->macro->params->head;
item->flavor = CIL_CONTEXT;
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call1_unknownflavor_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *macro_node = NULL;
struct cil_call *new_call = ((struct cil_call*)test_db->ast->root->cl_head->next->next->next->data);
cil_resolve_name(test_db->ast->root->cl_head->next->next->next, new_call->macro_str, CIL_SYM_BLOCKS, args, ¯o_node);
new_call->macro = (struct cil_macro*)macro_node->data;
struct cil_list_item *item = new_call->macro->params->head;
((struct cil_param*)item->data)->flavor = CIL_CONTEXT;
int rc = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call2_type(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_role(CuTest *tc) {
char *line[] = {"(", "role", "role_r", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "role", "a", ")", ")",
"(", "role", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_user(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "user", "a", ")", ")",
"(", "user", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "user_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_sens(CuTest *tc) {
char *line[] = {"(", "sensitivity", "sens", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "sensitivity", "a", ")", ")",
"(", "sensitivity", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "sens", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_cat(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "category", "a", ")", ")",
"(", "category", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "c0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_catset(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")",
"(", "macro", "mm", "(", "(", "categoryset", "foo", ")", ")",
"(", "level", "bar", "(", "s0", "foo", ")", ")", ")",
"(", "call", "mm", "(", "somecats", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_catset_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "macro", "mm", "(", "(", "categoryset", "foo", ")", ")",
"(", "level", "bar", "(", "s0", "foo", ")", ")", ")",
"(", "call", "mm", "(", "(", "c0", "c1", "c2", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_permset(CuTest *tc) {
char *line[] = {"(", "permissionset", "foo", "(", "read", "open", ")", ")",
"(", "class", "dead", "(", "close", ")", ")",
"(", "class", "bar", "(", "close", ")", ")",
"(", "class", "baz", "(", "close", ")", ")",
"(", "macro", "mm", "(", "(", "permissionset", "a", ")", ")",
"(", "allow", "dead", "bar", "(", "baz", "a", ")", ")", ")",
"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_permset_anon(CuTest *tc) {
char *line[] = {"(", "class", "dead", "(", "close", ")", ")",
"(", "class", "bar", "(", "close", ")", ")",
"(", "class", "baz", "(", "close", ")", ")",
"(", "macro", "mm", "(", "(", "permissionset", "a", ")", ")",
"(", "allow", "dead", "bar", "(", "baz", "a", ")", ")", ")",
"(", "call", "mm", "(", "(", "read", "open", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_classpermset_named(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "classpermissionset", "char_w", "(", "file", "(", "open", ")", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "char_w", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_classpermset_anon(CuTest *tc) {
char *line[] = {"(", "classmap", "files", "(", "read", ")", ")",
"(", "class", "file", "(", "open", ")", ")",
"(", "macro", "mm", "(", "(", "classpermissionset", "a", ")", ")",
"(", "classmapping", "files", "read", "a", ")", ")",
"(", "call", "mm", "(", "(", "file", "(", "open", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_class(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_classmap(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "open", ")", ")",
"(", "classmap", "files", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "classmap", "a", ")", ")",
"(", "classmapping", "a", "read", "(", "file", "(", "open", ")", ")", ")", ")",
"(", "call", "mm", "(", "files", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
}
void test_cil_resolve_call2_level(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", "(", "level", "lvl_h", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")", ")",
"(", "call", "mm", "(", "l", "h", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_level_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "h", ")", ")", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_ipaddr(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "lvl_l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "lvl_h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.0.1", ")",
"(", "ipaddr", "ip", "192.168.0.1", ")",
"(", "macro", "mm", "(", "(", "ipaddr", "addr", ")", ")",
"(", "nodecon", "addr", "netmask", "con", ")", ")",
"(", "call", "mm", "(", "ip", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_ipaddr_anon(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "lvl_l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "lvl_h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")",
"(", "ipaddr", "netmask", "192.168.0.1", ")",
"(", "macro", "mm", "(", "(", "ipaddr", "addr", ")", ")",
"(", "nodecon", "addr", "netmask", "con", ")", ")",
"(", "call", "mm", "(", "(", "192.168.1.1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_call2_unknown_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", "(", "level", "lvl_h", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")", ")",
"(", "call", "mm", "(", "l", "h", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
((struct cil_args*)((struct cil_list_item *)((struct cil_call *)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->data)->args->head)->data)->flavor = CIL_SYM_UNKNOWN;
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_call2_name_neg(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "class", "a", ")", ")",
"(", "class", "b", "(", "read", ")", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_name_call_args(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->data, "a", CIL_SYM_TYPES, &test_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_name_call_args_multipleparams(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "user", "system_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "level", "l", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "h", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "level", "lvl_l", ")", "(", "level", "lvl_h", ")", ")",
"(", "context", "foo", "(", "system_u", "role_r", "type_t", "(", "lvl_l", "lvl_h", ")", ")", ")", ")",
"(", "call", "mm", "(", "l", "h", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->data, "lvl_h", CIL_SYM_LEVELS, &test_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_name_call_args_diffflavor(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->data, "qaz", CIL_LEVEL, &test_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_name_call_args_callnull_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args(NULL, "qaz", CIL_LEVEL, &test_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_name_call_args_namenull_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->data, NULL, CIL_LEVEL, &test_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_name_call_args_callargsnull_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->data, "qas", CIL_LEVEL, &test_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_name_call_args_name_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node = NULL;
//cil_tree_node_init(&test_node);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
cil_resolve_call2(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_name_call_args((struct cil_call *)test_db->ast->root->cl_head->next->next->next->data, "qas", CIL_TYPE, &test_node);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_expr_stack_bools(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_booleanif *bif = (struct cil_booleanif*)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_expr_stack(bif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_expr_stack_tunables(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_expr_stack_type(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "type", "t1", ")",
"(", "type", "type_t", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "t1", "type_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_constrain *cons = (struct cil_constrain*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_expr_stack(cons->expr, test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_expr_stack_role(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "role", "r1", ")",
"(", "role", "role_r", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "role_r", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_constrain *cons = (struct cil_constrain*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_expr_stack(cons->expr, test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_expr_stack_user(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "user", "u1", ")",
"(", "user", "user_u", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "u1", "user_u", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_constrain *cons = (struct cil_constrain*)test_db->ast->root->cl_head->next->next->next->next->data;
int rc = cil_resolve_expr_stack(cons->expr, test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_expr_stack_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "beef", "baf", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_booleanif *bif = (struct cil_booleanif*)test_db->ast->root->cl_head->next->next->next->data;
int rc = cil_resolve_expr_stack(bif->expr_stack,test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_expr_stack_emptystr_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_booleanif *bif = (struct cil_booleanif*)test_db->ast->root->cl_head->next->next->next->data;
((struct cil_conditional*)bif->expr_stack->head->data)->str = NULL;
int rc = cil_resolve_expr_stack(bif->expr_stack,test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_boolif(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_boolif(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_boolif_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "dne", "N/A", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_boolif(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_evaluate_expr_stack_and(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_not(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "not", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_or(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "or", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_xor(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "xor", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_eq(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "eq", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_neq(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "neq", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_oper1(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "tunable", "baz", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "(", "or", "foo", "bar", ")", "baz", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "jaz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_evaluate_expr_stack_oper2(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "tunable", "baz", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "baz", "(", "or", "foo", "bar", ")", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "jaz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tunableif *tif = (struct cil_tunableif*)test_db->ast->root->cl_head->next->next->next->next->data;
cil_resolve_expr_stack(tif->expr_stack, test_db->ast->root->cl_head->next->next->next->next, args);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
/*
void test_cil_evaluate_expr_stack_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "neq", "foo", "bar", ")",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint16_t result = CIL_FALSE;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
struct cil_conditional *new_cond;
cil_conditional_init(&new_cond);
new_cond->flavor = CIL_COND;
char *baz = "baz";
new_cond->str = baz;
new_cond->flavor = CIL_TUNABLE;
struct cil_tunableif *tif = test_db->ast->root->cl_head->next->next->next->next->data;
test_node->data = new_cond;
test_node->cl_head = tif->expr_stack;
tif->expr_stack->parent = test_node;
cil_resolve_expr_stack(test_db, tif->expr_stack, test_db->ast->root->cl_head->next->next->next, NULL);
int rc = cil_evaluate_expr_stack(tif->expr_stack, &result);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
*/
void test_cil_resolve_tunif_false(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "false",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_tunif(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_tunif_true(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "true", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_tunif(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_tunif_resolveexpr_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "dne", "N/A", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_tunif(test_db->ast->root->cl_head->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
/*
void test_cil_resolve_tunif_evaluateexpr_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
struct cil_conditional *new_cond;
cil_conditional_init(&new_cond);
new_cond->flavor = CIL_COND;
char *baz = "baz";
new_cond->str = baz;
new_cond->flavor = CIL_TUNABLE;
struct tunableif *tif = test_db->ast->root->cl_head->next->next->next->data;
test_node->data = new_cond;
test_node->cl_head = tif->expr_stack;
tif->expr_stack->parent = test_node;
int rc = cil_resolve_tunif(test_db, test_db->ast->root->cl_head->next->next->next, NULL);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
*/
void test_cil_resolve_userbounds(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "user", "user2", ")",
"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_userbounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userbounds_exists_neg(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "user", "user2", ")",
"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_userbounds(test_db->ast->root->cl_head->next->next, args);
int rc = cil_resolve_userbounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_userbounds_user1_neg(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "user", "user2", ")",
"(", "userbounds", "user_DNE", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_userbounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userbounds_user2_neg(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "user", "user2", ")",
"(", "userbounds", "user1", "user_DNE", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_userbounds(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roletype(CuTest *tc) {
char *line[] = {"(", "role", "admin_r", ")",
"(", "type", "admin_t", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletype(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_roletype_type_neg(CuTest *tc) {
char *line[] = {"(", "role", "admin_r", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletype(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_roletype_role_neg(CuTest *tc) {
char *line[] = {"(", "type", "admin_t", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_roletype(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userrole(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
int rc = cil_resolve_userrole(test_db->ast->root->cl_head->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userrole_user_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_userrole(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userrole_role_neg(CuTest *tc) {
char *line[] = {"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = cil_resolve_userrole(test_db->ast->root->cl_head->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userlevel(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userlevel", "foo_u", "low", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userlevel_macro(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "macro", "mm", "(", "(", "level", "l", ")", ")",
"(", "userlevel", "foo_u", "l", ")", ")",
"(", "call", "mm", "(", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
args->pass = CIL_PASS_CALL1;
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_userlevel_macro_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "macro", "mm", "(", "(", "level", "l", ")", ")",
"(", "userlevel", "foo_u", "l", ")", ")",
"(", "call", "mm", "(", "(", "DNE", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_userlevel_level_anon(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "userlevel", "foo_u", "(", "s0", "(", "c0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userlevel_level_anon_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "userlevel", "foo_u", "(", "s0", "(", "DNE", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userlevel_user_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userlevel", "DNE", "low", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userlevel_level_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userlevel", "foo_u", "DNE", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userlevel(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userrange(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "userrange", "foo_u", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userrange_macro(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "levelrange", "range", ")", ")",
"(", "userrange", "foo_u", "range", ")", ")",
"(", "call", "mm", "(", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_userrange_macro_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "macro", "mm", "(", "(", "levelrange", "range", ")", ")",
"(", "userrange", "foo_u", "range", ")", ")",
"(", "call", "mm", "(", "(", "DNE", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc2 = cil_resolve_call1(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc3 = cil_resolve_call2(test_db->ast->root->cl_head->next->next->next->next->next->next->next, args);
args->pass = CIL_PASS_MISC2;
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
args->callstack = test_db->ast->root->cl_head->next->next->next->next->next->next->next;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next->next->next->cl_head, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, SEPOL_OK, rc2);
CuAssertIntEquals(tc, SEPOL_OK, rc3);
}
void test_cil_resolve_userrange_range_anon(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userrange", "foo_u", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_userrange_range_anon_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userrange", "foo_u", "(", "DNE", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userrange_user_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "userrange", "DNE", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_userrange_range_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "userrange", "foo_u", "DNE", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_senscat(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_MISC3;
int rc = cil_resolve_userrange(test_db->ast->root->cl_head->next->next->next->next->next, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_disable_children_helper_optional_enabled(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "baz", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_optional_disabled(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "baz", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
((struct cil_optional *)test_db->ast->root->cl_head->data)->datum.state = CIL_STATE_DISABLED;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_block(CuTest *tc) {
char *line[] = {"(", "block", "a", "(", "type", "log", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_user(CuTest *tc) {
char *line[] = {"(", "user", "staff_u", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_role(CuTest *tc) {
char *line[] = {"(", "role", "role_r", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_type(CuTest *tc) {
char *line[] = {"(", "type", "type_t", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_typealias(CuTest *tc) {
char *line[] = {"(", "typealias", ".test.type", "type_t", ")", "(", "type", "test", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_common(CuTest *tc) {
char *line[] = {"(", "common", "foo", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_class(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_bool(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_sens(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_cat(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_catset(CuTest *tc) {
char *line[] = {"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_sid(CuTest *tc) {
char *line[] = {"(", "sid", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_macro(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_context(CuTest *tc) {
char *line[] = {"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_level(CuTest *tc) {
char *line[] = {"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_policycap(CuTest *tc) {
char *line[] = {"(", "policycap", "foo", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_perm(CuTest *tc) {
char *line[] = {"(", "class", "foo", "(", "read", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_catalias(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_tunable(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "false", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_disable_children_helper_unknown(CuTest *tc) {
char *line[] = {"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
uint32_t finished = 0;
int rc = __cil_disable_children_helper(test_db->ast->root->cl_head, &finished, NULL);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
/*
__cil_resolve_ast_node_helper test cases
*/
void test_cil_resolve_ast_node_helper_call1(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_call1_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "m", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_call2(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_call2_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "foo", "extra", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_boolif(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "foo", "bar", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_boolif_neg(CuTest *tc) {
char *line[] = {"(", "boolean", "foo", "true", ")",
"(", "boolean", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "booleanif", "(", "and", "dne", "N/A", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_tunif(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "foo", "bar", ")",
"(", "false",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_tunif_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")",
"(", "tunable", "bar", "false", ")",
"(", "class", "baz", "(", "read", ")", ")",
"(", "tunableif", "(", "and", "dne", "N/A", ")",
"(", "true",
"(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catorder(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryorder", "(", "c0", "c1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catorder_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryorder", "(", "c8", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_dominance(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s1", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_dominance_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "sensitivity", "s2", ")",
"(", "dominance", "(", "s0", "s6", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roleallow(CuTest *tc) {
char *line[] = {"(", "role", "foo", ")", \
"(", "role", "bar", ")", \
"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roleallow_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo", ")", \
"(", "roleallow", "foo", "bar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_sensalias(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_sensalias_neg(CuTest *tc) {
char *line[] = {"(", "sensitivityalias", "s0", "alias", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catalias(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catalias_neg(CuTest *tc) {
char *line[] = {"(", "categoryalias", "c0", "red", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catset(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "category", "c2", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catset_catlist_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c1", ")",
"(", "categoryset", "somecats", "(", "c0", "c1", "c2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catrange(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_catorder(test_db->ast->root->cl_head->next->next, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
args->pass = CIL_PASS_MLS;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_catrange_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "categoryrange", "range", "(", "c255", "c0", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MLS, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_level(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "sensitivitycategory", "s0", "(", "c1", ")", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC2;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_level_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "sensitivitycategory", "s0", "(", "c1", ")", ")",
"(", "level", "l2", "(", "s8", "(", "c1", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_levelrange(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "dominance", "(", "s0", ")", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC2;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_levelrange_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "dominance", "(", "s0", ")", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "DNE", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_constrain(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "role", "r1", ")",
"(", "role", "r2", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_constrain_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", ")", ")",
"(", "class", "dir", "(", "create", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "role", "r1", ")",
"(", "role", "r2", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "r1", "r2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_mlsconstrain(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "create", "relabelto", ")", ")",
"(", "class", "dir", "(", "create", "relabelto", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_mlsconstrain_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", ")", ")",
"(", "class", "dir", "(", "read", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c1", ")",
"(", "level", "l2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "level", "h2", "(", "s0", "(", "c1", ")", ")", ")",
"(", "mlsconstrain", "(", "file", "(", "create", "relabelto", ")", ")", "(", "eq", "l2", "h2", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_context(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_context_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con",
"(", "system_u", "object_r", "netif_t", "DNE", "high", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC1, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
__cil_verify_order(test_db->catorder, test_db->ast->root, CIL_CAT);
__cil_verify_order(test_db->dominance, test_db->ast->root, CIL_SENS);
args->pass = CIL_PASS_MLS;
cil_tree_walk(test_db->ast->root, __cil_resolve_ast_node_helper, NULL, NULL, args);
args->pass = CIL_PASS_MISC3;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, finished, 0);
}
void test_cil_resolve_ast_node_helper_senscat(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s1", "(", "c0", "c255", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_senscat_neg(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "sensitivity", "s1", ")",
"(", "dominance", "(", "s0", "s1", ")", ")",
"(", "category", "c0", ")",
"(", "category", "c255", ")",
"(", "categoryorder", "(", "c0", "c255", ")", ")",
"(", "sensitivitycategory", "s5", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roletransition(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "type", "bar_t", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roletransition_srcdecl_neg(CuTest *tc) {
char *line[] = {"(", "type", "bar_t", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roletransition_tgtdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "role", "foobar_r", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_roletransition_resultdecl_neg(CuTest *tc) {
char *line[] = {"(", "role", "foo_r", ")",
"(", "type", "bar_t", ")",
"(", "class", "process", "(", "transition", ")", ")",
"(", "roletransition", "foo_r", "bar_t", "process", "foobar_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typeattributeset(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "type", "type_t", ")",
"(", "type", "type_tt", ")",
"(", "typeattributeset", "attrs", "(", "type_t", "type_tt", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typeattributeset_undef_type_neg(CuTest *tc) {
char *line[] = {"(", "typeattribute", "attrs", ")",
"(", "type", "type_t", ")",
"(", "typeattributeset", "attrs", "(", "not", "t_t", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typealias(CuTest *tc) {
char *line[] = {"(", "block", "foo",
"(", "typealias", ".foo.test", "type_t", ")",
"(", "type", "test", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typealias_notype_neg(CuTest *tc) {
char *line[] = {"(", "block", "bar",
"(", "typealias", ".bar.test", "type_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typebounds(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typebounds_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_b", ")",
"(", "typebounds", "type_a", "type_b", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typepermissive(CuTest *tc) {
char *line[] = {"(", "type", "type_a", ")",
"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_typepermissive_neg(CuTest *tc) {
char *line[] = {"(", "type", "type_b", ")",
"(", "typepermissive", "type_a", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_rangetransition(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_a", "type_b", "class_", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_rangetransition_neg(CuTest *tc) {
char *line[] = {"(", "class", "class_", "(", "read", ")", ")",
"(", "type", "type_a", ")",
"(", "type", "type_b", ")",
"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "rangetransition", "type_DNE", "type_b", "class_", "(", "low", "high", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nametypetransition(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nametypetransition_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "type", "foobar", ")",
"(", "nametypetransition", "str", "foo", "bar", "file", "foobarrr", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_avrule(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_avrule_src_nores_neg(CuTest *tc) {
char *line[] = {"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_avrule_tgt_nores_neg(CuTest *tc) {
char *line[] = {"(", "type", "test", ")",
"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_avrule_class_nores_neg(CuTest *tc) {
char *line[] = {"(", "type", "test", ")",
"(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "bar", "(", "read", "write", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_avrule_datum_null_neg(CuTest *tc) {
char *line[] = {"(", "class", "bar", "(", "read", "write", "open", ")", ")",
"(", "type", "test", ")", "(", "type", "foo", ")",
"(", "allow", "test", "foo", "(", "bar", "(","fake", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_transition(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_transition_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typetransition", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_change(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_change_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typechange", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_member(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_type_rule_member_neg(CuTest *tc) {
char *line[] = {"(", "type", "foo", ")",
"(", "class", "file", "(", "write", ")", ")",
"(", "type", "foobar", ")",
"(", "typemember", "foo", "bar", "file", "foobar", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_userbounds(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "user", "user2", ")",
"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_userbounds_neg(CuTest *tc) {
char *line[] = {"(", "user", "user1", ")",
"(", "userbounds", "user1", "user2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_roletype(CuTest *tc) {
char *line[] = {"(", "role", "admin_r", ")",
"(", "type", "admin_t", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_roletype_role_neg(CuTest *tc) {
char *line[] = {"(", "type", "admin_t", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_roletype_type_neg(CuTest *tc) {
char *line[] = {"(", "role", "admin_r", ")",
"(", "roletype", "admin_r", "admin_t", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_userrole(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_userrole_user_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_userrole_role_neg(CuTest *tc) {
char *line[] = {"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_userlevel(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userlevel", "foo_u", "low", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_userlevel_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "userlevel", "DNE", "low", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_userrange(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "userrange", "foo_u", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_userrange_neg(CuTest *tc) {
char *line[] = {"(", "user", "foo_u", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "levelrange", "range", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")",
"(", "userrange", "DNE", "range", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_filecon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "filecon", "root", "path", "file", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_filecon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "filecon", "root", "path", "file", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_portcon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "portcon", "udp", "25", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_portcon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "portcon", "udp", "25", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_genfscon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "genfscon", "type", "path", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_genfscon_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "genfscon", "type", "path", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nodecon(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "nodecon", "ip", "ip", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nodecon_ipaddr_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "ipp", "netmask", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nodecon_netmask_neg(CuTest *tc) {
char *line[] = {"(", "user", "user_u", ")",
"(", "role", "role_r", ")",
"(", "type", "type_t", ")",
"(", "category", "c0", ")",
"(", "sensitivity", "s0", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "context", "con", "(", "user_u", "role_r", "type_t", "(", "low", "high", ")", ")", ")",
"(", "ipaddr", "ip", "192.168.1.1", ")",
"(", "ipaddr", "netmask", "192.168.1.1", ")",
"(", "nodecon", "ip", "nnetmask", "foo", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_netifcon(CuTest *tc) {
char *line[] = {"(", "context", "if_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "context", "packet_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_netifcon_neg(CuTest *tc) {
char *line[] = {"(", "context", "if_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_pirqcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pirqcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_pirqcon_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pirqcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_iomemcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "iomemcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_iomemcon_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "iomemcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_ioportcon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "ioportcon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_ioportcon_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "ioportcon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_pcidevicecon(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pcidevicecon", "1", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_pcidevicecon_neg(CuTest *tc) {
char *line[] = {"(", "context", "con", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "pcidevicecon", "1", "dne", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_fsuse(CuTest *tc) {
char *line[] = {"(", "sensitivity", "s0", ")",
"(", "category", "c0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "user", "system_u", ")",
"(", "role", "object_r", ")",
"(", "type", "netif_t", ")",
"(", "context", "con", "(", "system_u", "object_r", "netif_t", "(", "low", "high", ")", ")", ")",
"(", "fsuse", "xattr", "ext3", "con", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_fsuse_neg(CuTest *tc) {
char *line[] = {"(", "context", "if_default", "(", "system_u", "object_r", "etc_t", "(", "low", "high", ")", ")", ")",
"(", "netifcon", "eth0", "if_default", "packet_default", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_sidcontext(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "level", "low", "(", "s0", "(", "c0", ")", ")", ")",
"(", "level", "high", "(", "s0", "(", "c0", ")", ")", ")",
"(", "sid", "test", "(", "blah_u", "blah_r", "blah_t", "(", "low", "high", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_sidcontext_neg(CuTest *tc) {
char *line[] = {"(", "category", "c0", ")",
"(", "categoryorder", "(", "c0", ")", ")",
"(", "sensitivity", "s0", ")",
"(", "sensitivitycategory", "s0", "(", "c0", ")", ")",
"(", "type", "blah_t", ")",
"(", "role", "blah_r", ")",
"(", "user", "blah_u", ")",
"(", "sidcontext", "test", "(", "", "blah_r", "blah_t", "(", "(", "s0", "(", "c0", ")", ")", "(", "s0", "(", "c0", ")", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next->next->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_blockinherit(CuTest *tc) {
char *line[] = {"(", "block", "baz", "(", "type", "foo", ")", ")",
"(", "block", "bar", "(", "type", "a", ")",
"(", "blockinherit", "baz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_BLKIN, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_classcommon(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", ")", ")",
"(", "common", "file", "(", "write", ")", ")",
"(", "classcommon", "file", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_classcommon_neg(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", ")", ")",
"(", "classcommon", "file", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_rolebounds(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "role", "role2", ")",
"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_rolebounds_neg(CuTest *tc) {
char *line[] = {"(", "role", "role1", ")",
"(", "rolebounds", "role1", "role2", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ENOENT, rc);
}
void test_cil_resolve_ast_node_helper_callstack(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_tree_node *test_ast_node_call;
cil_tree_node_init(&test_ast_node_call);
test_ast_node_call->flavor = CIL_CALL;
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
__cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_call(CuTest *tc) {
char *line[] = {"(", "call", "mm", "(", "foo", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_tree_node *test_ast_node_call;
cil_tree_node_init(&test_ast_node_call);
test_ast_node_call->flavor = CIL_CALL;
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_optional(CuTest *tc) {
char *line[] = {"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_tree_node *test_ast_node_opt;
cil_tree_node_init(&test_ast_node_opt);
test_ast_node_opt->flavor = CIL_OPTIONAL;
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
// set optional to disabled
((struct cil_symtab_datum *)test_db->ast->root->cl_head->data)->state = CIL_STATE_DISABLED;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_macro(CuTest *tc) {
char *line[] = {"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_optstack(CuTest *tc) {
char *line[] = {"(", "class", "baz", "(", "read", ")", ")",
"(", "type", "foo", ")",
"(", "type", "bar", ")",
"(", "optional", "opt", "(", "allow", "foo", "bar", "(", "baz", "(", "read", ")", ")", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_tree_node *test_ast_node_opt;
cil_tree_node_init(&test_ast_node_opt);
test_ast_node_opt->flavor = CIL_OPTIONAL;
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
__cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
void test_cil_resolve_ast_node_helper_optstack_tunable_neg(CuTest *tc) {
char *line[] = {"(", "tunable", "foo", "true", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node_opt;
cil_tree_node_init(&test_ast_node_opt);
test_ast_node_opt->flavor = CIL_OPTIONAL;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, test_ast_node_opt, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_ast_node_helper_optstack_macro_neg(CuTest *tc) {
char *line[] = {"(", "type", "qaz", ")",
"(", "class", "file", "(", "read", ")", ")",
"(", "macro", "mm", "(", "(", "type", "a", ")", ")",
"(", "type", "b", ")",
"(", "allow", "a", "b", "(", "file", "(", "read", ")", ")", ")", ")",
"(", "call", "mm", "(", "qaz", ")", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node_opt;
cil_tree_node_init(&test_ast_node_opt);
test_ast_node_opt->flavor = CIL_OPTIONAL;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_CALL1, &changed, NULL, test_ast_node_opt, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
cil_resolve_call1(test_db->ast->root->cl_head->next->next, args);
args->pass = CIL_PASS_CALL2;
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
CuAssertIntEquals(tc, 0, finished);
}
void test_cil_resolve_ast_node_helper_nodenull_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_TIF, &changed, NULL, NULL, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(NULL, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_ast_node_helper_extraargsnull_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, NULL);
CuAssertIntEquals(tc, 0, finished);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_ast_node_helper_dbflavor_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_ast_node_helper_pass_neg(CuTest *tc) {
char *line[] = {"(", "role", "staff_r", ")",
"(", "user", "staff_u", ")",
"(", "userrole", "staff_u", "staff_r", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
uint32_t finished = 0;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC3, &changed, NULL, NULL, NULL);
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_ERR, rc);
}
void test_cil_resolve_ast_node_helper_optfailedtoresolve(CuTest *tc) {
char *line[] = {"(", "class", "file", "(", "read", ")", ")",
"(", "classcommon", "file", "file", ")", NULL};
struct cil_tree *test_tree;
gen_test_tree(&test_tree, line);
struct cil_db *test_db;
cil_db_init(&test_db);
struct cil_optional *opt;
cil_optional_init(&opt);
struct cil_tree_node *test_ast_node_opt;
cil_tree_node_init(&test_ast_node_opt);
test_ast_node_opt->flavor = CIL_OPTIONAL;
test_ast_node_opt->data = opt;
uint32_t changed = CIL_FALSE;
struct cil_args_resolve *args = gen_resolve_args(test_db, CIL_PASS_MISC2, &changed, NULL, test_ast_node_opt, NULL);
uint32_t finished = 0;
cil_build_ast(test_db, test_tree->root, test_db->ast->root);
int rc = __cil_resolve_ast_node_helper(test_db->ast->root->cl_head->next, &finished, args);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertIntEquals(tc, 0, finished);
}
libsepol-3.8.1/cil/test/unit/test_cil_resolve_ast.h000066400000000000000000000640471476211737200224530ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_RESOLVE_AST_H_
#define TEST_CIL_RESOLVE_AST_H_
#include "CuTest.h"
void test_cil_resolve_name(CuTest *);
void test_cil_resolve_name_invalid_type_neg(CuTest *);
void test_cil_resolve_ast_curr_null_neg(CuTest *);
/*
cil_resolve test cases
*/
void test_cil_resolve_roleallow(CuTest *);
void test_cil_resolve_roleallow_srcdecl_neg(CuTest *);
void test_cil_resolve_roleallow_tgtdecl_neg(CuTest *);
void test_cil_resolve_rolebounds(CuTest *tc);
void test_cil_resolve_rolebounds_exists_neg(CuTest *tc);
void test_cil_resolve_rolebounds_role1_neg(CuTest *tc);
void test_cil_resolve_rolebounds_role2_neg(CuTest *tc);
void test_cil_resolve_sensalias(CuTest *);
void test_cil_resolve_sensalias_sensdecl_neg(CuTest *);
void test_cil_resolve_catalias(CuTest *);
void test_cil_resolve_catalias_catdecl_neg(CuTest *);
void test_cil_resolve_catorder(CuTest *);
void test_cil_resolve_catorder_neg(CuTest *);
void test_cil_resolve_dominance(CuTest *);
void test_cil_resolve_dominance_neg(CuTest *);
void test_cil_resolve_cat_list(CuTest *);
void test_cil_resolve_cat_list_catlistnull_neg(CuTest *);
void test_cil_resolve_cat_list_rescatlistnull_neg(CuTest *);
void test_cil_resolve_cat_list_catrange(CuTest *);
void test_cil_resolve_cat_list_catrange_neg(CuTest *);
void test_cil_resolve_cat_list_catname_neg(CuTest *);
void test_cil_resolve_catset(CuTest *);
void test_cil_resolve_catset_catlist_neg(CuTest *);
void test_cil_resolve_catrange(CuTest *);
void test_cil_resolve_catrange_catloworder_neg(CuTest *);
void test_cil_resolve_catrange_cathighorder_neg(CuTest *);
void test_cil_resolve_catrange_cat1_neg(CuTest *);
void test_cil_resolve_catrange_cat2_neg(CuTest *);
void test_cil_resolve_senscat(CuTest *);
void test_cil_resolve_senscat_catrange_neg(CuTest *);
void test_cil_resolve_senscat_catsetname(CuTest *);
void test_cil_resolve_senscat_catsetname_neg(CuTest *);
void test_cil_resolve_senscat_sublist(CuTest *);
void test_cil_resolve_senscat_missingsens_neg(CuTest *);
void test_cil_resolve_senscat_sublist_neg(CuTest *);
void test_cil_resolve_senscat_category_neg(CuTest *);
void test_cil_resolve_senscat_currrangecat(CuTest *);
void test_cil_resolve_senscat_currrangecat_neg(CuTest *);
void test_cil_resolve_level(CuTest *);
void test_cil_resolve_level_catlist(CuTest *);
void test_cil_resolve_level_catset(CuTest *);
void test_cil_resolve_level_catset_name_neg(CuTest *);
void test_cil_resolve_level_sens_neg(CuTest *);
void test_cil_resolve_level_cat_neg(CuTest *);
void test_cil_resolve_level_senscat_neg(CuTest *);
void test_cil_resolve_levelrange_namedlvl(CuTest *);
void test_cil_resolve_levelrange_namedlvl_low_neg(CuTest *);
void test_cil_resolve_levelrange_namedlvl_high_neg(CuTest *);
void test_cil_resolve_levelrange_anonlvl(CuTest *);
void test_cil_resolve_levelrange_anonlvl_low_neg(CuTest *);
void test_cil_resolve_levelrange_anonlvl_high_neg(CuTest *);
void test_cil_resolve_constrain(CuTest *);
void test_cil_resolve_constrain_class_neg(CuTest *);
void test_cil_resolve_constrain_perm_neg(CuTest *);
void test_cil_resolve_constrain_perm_resolve_neg(CuTest *);
void test_cil_resolve_context(CuTest *);
void test_cil_resolve_context_macro(CuTest *);
void test_cil_resolve_context_macro_neg(CuTest *);
void test_cil_resolve_context_namedrange(CuTest *);
void test_cil_resolve_context_namedrange_neg(CuTest *);
void test_cil_resolve_context_macro_namedrange_anon(CuTest *);
void test_cil_resolve_context_user_neg(CuTest *);
void test_cil_resolve_context_role_neg(CuTest *);
void test_cil_resolve_context_type_neg(CuTest *);
void test_cil_resolve_context_anon_level_neg(CuTest *);
void test_cil_resolve_roletransition(CuTest *);
void test_cil_resolve_roletransition_srcdecl_neg(CuTest *);
void test_cil_resolve_roletransition_tgtdecl_neg(CuTest *);
void test_cil_resolve_roletransition_resultdecl_neg(CuTest *);
void test_cil_resolve_typeattributeset_type_in_multiple_attrs(CuTest *);
void test_cil_resolve_typeattributeset_multiple_excludes_with_not(CuTest *);
void test_cil_resolve_typeattributeset_multiple_types_with_and(CuTest *);
void test_cil_resolve_typeattributeset_using_attr(CuTest *);
void test_cil_resolve_typeattributeset_name_neg(CuTest *);
void test_cil_resolve_typeattributeset_undef_type_neg(CuTest *);
void test_cil_resolve_typeattributeset_not(CuTest *);
void test_cil_resolve_typeattributeset_undef_type_not_neg(CuTest *);
void test_cil_resolve_typealias(CuTest *);
void test_cil_resolve_typealias_neg(CuTest *);
void test_cil_resolve_typebounds(CuTest *);
void test_cil_resolve_typebounds_repeatbind_neg(CuTest *);
void test_cil_resolve_typebounds_type1_neg(CuTest *);
void test_cil_resolve_typebounds_type2_neg(CuTest *);
void test_cil_resolve_typepermissive(CuTest *);
void test_cil_resolve_typepermissive_neg(CuTest *);
void test_cil_resolve_nametypetransition(CuTest *);
void test_cil_resolve_nametypetransition_src_neg(CuTest *);
void test_cil_resolve_nametypetransition_tgt_neg(CuTest *);
void test_cil_resolve_nametypetransition_class_neg(CuTest *);
void test_cil_resolve_nametypetransition_dest_neg(CuTest *);
void test_cil_resolve_rangetransition(CuTest *);
void test_cil_resolve_rangetransition_namedrange(CuTest *);
void test_cil_resolve_rangetransition_namedrange_anon(CuTest *);
void test_cil_resolve_rangetransition_namedrange_anon_neg(CuTest *);
void test_cil_resolve_rangetransition_namedrange_neg(CuTest *);
void test_cil_resolve_rangetransition_type1_neg(CuTest *);
void test_cil_resolve_rangetransition_type2_neg(CuTest *);
void test_cil_resolve_rangetransition_class_neg(CuTest *);
void test_cil_resolve_rangetransition_call_level_l_anon(CuTest *);
void test_cil_resolve_rangetransition_call_level_l_anon_neg(CuTest *);
void test_cil_resolve_rangetransition_call_level_h_anon(CuTest *);
void test_cil_resolve_rangetransition_call_level_h_anon_neg(CuTest *);
void test_cil_resolve_rangetransition_level_l_neg(CuTest *);
void test_cil_resolve_rangetransition_level_h_neg(CuTest *);
void test_cil_resolve_rangetransition_anon_level_l(CuTest *);
void test_cil_resolve_rangetransition_anon_level_l_neg(CuTest *);
void test_cil_resolve_rangetransition_anon_level_h(CuTest *);
void test_cil_resolve_rangetransition_anon_level_h_neg(CuTest *);
void test_cil_resolve_classcommon(CuTest *);
void test_cil_resolve_classcommon_no_class_neg(CuTest *);
void test_cil_resolve_classcommon_neg(CuTest *);
void test_cil_resolve_classcommon_no_common_neg(CuTest *);
void test_cil_resolve_classmapping_named(CuTest *);
void test_cil_resolve_classmapping_anon(CuTest *);
void test_cil_resolve_classmapping_anon_inmacro(CuTest *);
void test_cil_resolve_classmapping_anon_inmacro_neg(CuTest *);
void test_cil_resolve_classmapping_named_classmapname_neg(CuTest *);
void test_cil_resolve_classmapping_anon_classmapname_neg(CuTest *);
void test_cil_resolve_classmapping_anon_permset_neg(CuTest *);
void test_cil_resolve_classpermset_named(CuTest *);
void test_cil_resolve_classpermset_named_namedpermlist(CuTest *);
void test_cil_resolve_classpermset_named_permlist_neg(CuTest *);
void test_cil_resolve_classpermset_named_unnamedcps_neg(CuTest *);
void test_cil_resolve_classpermset_anon(CuTest *);
void test_cil_resolve_classpermset_anon_namedpermlist(CuTest *);
void test_cil_resolve_classpermset_anon_permlist_neg(CuTest *);
void test_cil_resolve_avrule(CuTest *);
void test_cil_resolve_avrule_permset(CuTest *);
void test_cil_resolve_avrule_permset_neg(CuTest *);
void test_cil_resolve_avrule_permset_permdne_neg(CuTest *);
void test_cil_resolve_avrule_firsttype_neg(CuTest *);
void test_cil_resolve_avrule_secondtype_neg(CuTest *);
void test_cil_resolve_avrule_class_neg(CuTest *);
void test_cil_resolve_avrule_perm_neg(CuTest *);
void test_cil_resolve_type_rule_transition(CuTest *);
void test_cil_resolve_type_rule_transition_srcdecl_neg(CuTest *);
void test_cil_resolve_type_rule_transition_tgtdecl_neg(CuTest *);
void test_cil_resolve_type_rule_transition_objdecl_neg(CuTest *);
void test_cil_resolve_type_rule_transition_resultdecl_neg(CuTest *);
void test_cil_resolve_type_rule_change(CuTest *);
void test_cil_resolve_type_rule_change_srcdecl_neg(CuTest *);
void test_cil_resolve_type_rule_change_tgtdecl_neg(CuTest *);
void test_cil_resolve_type_rule_change_objdecl_neg(CuTest *);
void test_cil_resolve_type_rule_change_resultdecl_neg(CuTest *);
void test_cil_resolve_type_rule_member(CuTest *);
void test_cil_resolve_type_rule_member_srcdecl_neg(CuTest *);
void test_cil_resolve_type_rule_member_tgtdecl_neg(CuTest *);
void test_cil_resolve_type_rule_member_objdecl_neg(CuTest *);
void test_cil_resolve_type_rule_member_resultdecl_neg(CuTest *);
void test_cil_resolve_filecon(CuTest *);
void test_cil_resolve_filecon_neg(CuTest *);
void test_cil_resolve_filecon_anon_context(CuTest *);
void test_cil_resolve_filecon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_filecon(CuTest *tc);
void test_cil_resolve_ast_node_helper_filecon_neg(CuTest *tc);
void test_cil_resolve_portcon(CuTest *);
void test_cil_resolve_portcon_neg(CuTest *);
void test_cil_resolve_portcon_anon_context(CuTest *);
void test_cil_resolve_portcon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_portcon(CuTest *tc);
void test_cil_resolve_ast_node_helper_portcon_neg(CuTest *tc);
void test_cil_resolve_genfscon(CuTest *);
void test_cil_resolve_genfscon_neg(CuTest *);
void test_cil_resolve_genfscon_anon_context(CuTest *);
void test_cil_resolve_genfscon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_genfscon(CuTest *tc);
void test_cil_resolve_ast_node_helper_genfscon_neg(CuTest *tc);
void test_cil_resolve_nodecon_ipv4(CuTest *);
void test_cil_resolve_nodecon_ipv6(CuTest *);
void test_cil_resolve_nodecon_anonipaddr_ipv4(CuTest *);
void test_cil_resolve_nodecon_anonnetmask_ipv4(CuTest *);
void test_cil_resolve_nodecon_anonipaddr_ipv6(CuTest *);
void test_cil_resolve_nodecon_anonnetmask_ipv6(CuTest *);
void test_cil_resolve_nodecon_diffipfam_neg(CuTest *);
void test_cil_resolve_nodecon_context_neg(CuTest *);
void test_cil_resolve_nodecon_ipaddr_neg(CuTest *);
void test_cil_resolve_nodecon_netmask_neg(CuTest *);
void test_cil_resolve_nodecon_anon_context(CuTest *);
void test_cil_resolve_nodecon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_nodecon(CuTest *tc);
void test_cil_resolve_ast_node_helper_nodecon_ipaddr_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_nodecon_netmask_neg(CuTest *tc);
void test_cil_resolve_netifcon(CuTest *);
void test_cil_resolve_netifcon_otf_neg(CuTest *);
void test_cil_resolve_netifcon_interface_neg(CuTest *);
void test_cil_resolve_netifcon_unnamed(CuTest *);
void test_cil_resolve_netifcon_unnamed_packet_neg(CuTest *);
void test_cil_resolve_netifcon_unnamed_otf_neg(CuTest *);
void test_cil_resolve_ast_node_helper_netifcon(CuTest *tc);
void test_cil_resolve_ast_node_helper_netifcon_neg(CuTest *tc);
void test_cil_resolve_pirqcon(CuTest *);
void test_cil_resolve_pirqcon_context_neg(CuTest *);
void test_cil_resolve_pirqcon_anon_context(CuTest *);
void test_cil_resolve_pirqcon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_pirqcon(CuTest *tc);
void test_cil_resolve_ast_node_helper_pirqcon_neg(CuTest *tc);
void test_cil_resolve_iomemcon(CuTest *);
void test_cil_resolve_iomemcon_context_neg(CuTest *);
void test_cil_resolve_iomemcon_anon_context(CuTest *);
void test_cil_resolve_iomemcon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_iomemcon(CuTest *tc);
void test_cil_resolve_ast_node_helper_iomemcon_neg(CuTest *tc);
void test_cil_resolve_ioportcon(CuTest *);
void test_cil_resolve_ioportcon_context_neg(CuTest *);
void test_cil_resolve_ioportcon_anon_context(CuTest *);
void test_cil_resolve_ioportcon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_ioportcon(CuTest *tc);
void test_cil_resolve_ast_node_helper_ioportcon_neg(CuTest *tc);
void test_cil_resolve_pcidevicecon(CuTest *);
void test_cil_resolve_pcidevicecon_context_neg(CuTest *);
void test_cil_resolve_pcidevicecon_anon_context(CuTest *);
void test_cil_resolve_pcidevicecon_anon_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_pcidevicecon(CuTest *tc);
void test_cil_resolve_ast_node_helper_pcidevicecon_neg(CuTest *tc);
void test_cil_resolve_fsuse(CuTest *);
void test_cil_resolve_fsuse_neg(CuTest *);
void test_cil_resolve_fsuse_anon(CuTest *);
void test_cil_resolve_fsuse_anon_neg(CuTest *);
void test_cil_resolve_ast_node_helper_fsuse(CuTest *tc);
void test_cil_resolve_ast_node_helper_fsuse_neg(CuTest *tc);
void test_cil_resolve_sidcontext(CuTest *);
void test_cil_resolve_sidcontext_named_levels(CuTest *);
void test_cil_resolve_sidcontext_named_context(CuTest *);
void test_cil_resolve_sidcontext_named_context_wrongname_neg(CuTest *tc);
void test_cil_resolve_sidcontext_named_context_invaliduser_neg(CuTest *tc);
void test_cil_resolve_sidcontext_named_context_sidcontextnull_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_sidcontext(CuTest *tc);
void test_cil_resolve_ast_node_helper_sidcontext_neg(CuTest *tc);
void test_cil_resolve_blockinherit(CuTest *);
void test_cil_resolve_blockinherit_blockstrdne_neg(CuTest *);
void test_cil_resolve_ast_node_helper_blockinherit(CuTest *tc);
void test_cil_resolve_in_block(CuTest *);
void test_cil_resolve_in_blockstrdne_neg(CuTest *);
void test_cil_resolve_in_macro(CuTest *);
void test_cil_resolve_in_optional(CuTest *);
void test_cil_resolve_call1_noparam(CuTest *);
void test_cil_resolve_call1_type(CuTest *);
void test_cil_resolve_call1_role(CuTest *);
void test_cil_resolve_call1_user(CuTest *);
void test_cil_resolve_call1_sens(CuTest *);
void test_cil_resolve_call1_cat(CuTest *);
void test_cil_resolve_call1_catset(CuTest *);
void test_cil_resolve_call1_catset_anon(CuTest *);
void test_cil_resolve_call1_catset_anon_neg(CuTest *);
void test_cil_resolve_call1_level(CuTest *);
void test_cil_resolve_call1_class(CuTest *);
void test_cil_resolve_call1_classmap(CuTest *);
void test_cil_resolve_call1_permset(CuTest *);
void test_cil_resolve_call1_permset_anon(CuTest *);
void test_cil_resolve_call1_classpermset_named(CuTest *);
void test_cil_resolve_call1_classpermset_anon(CuTest *);
void test_cil_resolve_call1_classpermset_anon_neg(CuTest *);
void test_cil_resolve_call1_level(CuTest *);
void test_cil_resolve_call1_level_anon(CuTest *);
void test_cil_resolve_call1_level_anon_neg(CuTest *);
void test_cil_resolve_call1_ipaddr(CuTest *);
void test_cil_resolve_call1_ipaddr_anon(CuTest *);
void test_cil_resolve_call1_ipaddr_anon_neg(CuTest *);
void test_cil_resolve_call1_unknown_neg(CuTest *);
void test_cil_resolve_call1_unknowncall_neg(CuTest *);
void test_cil_resolve_call1_extraargs_neg(CuTest *);
void test_cil_resolve_call1_copy_dup(CuTest *);
void test_cil_resolve_call1_missing_arg_neg(CuTest *);
void test_cil_resolve_call1_paramsflavor_neg(CuTest *);
void test_cil_resolve_call1_unknownflavor_neg(CuTest *);
void test_cil_resolve_call2_type(CuTest *);
void test_cil_resolve_call2_role(CuTest *);
void test_cil_resolve_call2_user(CuTest *);
void test_cil_resolve_call2_sens(CuTest *);
void test_cil_resolve_call2_cat(CuTest *);
void test_cil_resolve_call2_catset(CuTest *);
void test_cil_resolve_call2_catset_anon(CuTest *);
void test_cil_resolve_call2_permset(CuTest *);
void test_cil_resolve_call2_permset_anon(CuTest *);
void test_cil_resolve_call2_classpermset_named(CuTest *);
void test_cil_resolve_call2_classpermset_anon(CuTest *);
void test_cil_resolve_call2_class(CuTest *);
void test_cil_resolve_call2_classmap(CuTest *);
void test_cil_resolve_call2_level(CuTest *);
void test_cil_resolve_call2_level_anon(CuTest *);
void test_cil_resolve_call2_ipaddr(CuTest *);
void test_cil_resolve_call2_ipaddr_anon(CuTest *);
void test_cil_resolve_call2_unknown_neg(CuTest *);
void test_cil_resolve_name_call_args(CuTest *);
void test_cil_resolve_name_call_args_multipleparams(CuTest *);
void test_cil_resolve_name_call_args_diffflavor(CuTest *);
void test_cil_resolve_name_call_args_callnull_neg(CuTest *);
void test_cil_resolve_name_call_args_namenull_neg(CuTest *);
void test_cil_resolve_name_call_args_callargsnull_neg(CuTest *);
void test_cil_resolve_name_call_args_name_neg(CuTest *);
void test_cil_resolve_expr_stack_bools(CuTest *);
void test_cil_resolve_expr_stack_tunables(CuTest *);
void test_cil_resolve_expr_stack_type(CuTest *);
void test_cil_resolve_expr_stack_role(CuTest *);
void test_cil_resolve_expr_stack_user(CuTest *);
void test_cil_resolve_expr_stack_neg(CuTest *);
void test_cil_resolve_expr_stack_emptystr_neg(CuTest *);
void test_cil_resolve_boolif(CuTest *);
void test_cil_resolve_boolif_neg(CuTest *);
void test_cil_evaluate_expr_stack_and(CuTest *);
void test_cil_evaluate_expr_stack_not(CuTest *);
void test_cil_evaluate_expr_stack_or(CuTest *);
void test_cil_evaluate_expr_stack_xor(CuTest *);
void test_cil_evaluate_expr_stack_eq(CuTest *);
void test_cil_evaluate_expr_stack_neq(CuTest *);
void test_cil_evaluate_expr_stack_oper1(CuTest *);
void test_cil_evaluate_expr_stack_oper2(CuTest *);
void test_cil_evaluate_expr_stack_neg(CuTest *);
void test_cil_resolve_tunif_false(CuTest *);
void test_cil_resolve_tunif_true(CuTest *);
void test_cil_resolve_tunif_resolveexpr_neg(CuTest *);
void test_cil_resolve_tunif_evaluateexpr_neg(CuTest *);
void test_cil_resolve_userbounds(CuTest *tc);
void test_cil_resolve_userbounds_exists_neg(CuTest *tc);
void test_cil_resolve_userbounds_user1_neg(CuTest *tc);
void test_cil_resolve_userbounds_user2_neg(CuTest *tc);
void test_cil_resolve_roletype(CuTest *tc);
void test_cil_resolve_roletype_type_neg(CuTest *tc);
void test_cil_resolve_roletype_role_neg(CuTest *tc);
void test_cil_resolve_userrole(CuTest *tc);
void test_cil_resolve_userrole_user_neg(CuTest *tc);
void test_cil_resolve_userrole_role_neg(CuTest *tc);
void test_cil_resolve_userlevel(CuTest *tc);
void test_cil_resolve_userlevel_macro(CuTest *tc);
void test_cil_resolve_userlevel_macro_neg(CuTest *tc);
void test_cil_resolve_userlevel_level_anon(CuTest *tc);
void test_cil_resolve_userlevel_level_anon_neg(CuTest *tc);
void test_cil_resolve_userlevel_user_neg(CuTest *tc);
void test_cil_resolve_userlevel_level_neg(CuTest *tc);
void test_cil_resolve_userrange(CuTest *tc);
void test_cil_resolve_userrange_macro(CuTest *tc);
void test_cil_resolve_userrange_macro_neg(CuTest *tc);
void test_cil_resolve_userrange_range_anon(CuTest *tc);
void test_cil_resolve_userrange_range_anon_neg(CuTest *tc);
void test_cil_resolve_userrange_user_neg(CuTest *tc);
void test_cil_resolve_userrange_range_neg(CuTest *tc);
void test_cil_disable_children_helper_optional_enabled(CuTest *tc);
void test_cil_disable_children_helper_optional_disabled(CuTest *tc);
void test_cil_disable_children_helper_block(CuTest *tc);
void test_cil_disable_children_helper_user(CuTest *tc);
void test_cil_disable_children_helper_role(CuTest *tc);
void test_cil_disable_children_helper_type(CuTest *tc);
void test_cil_disable_children_helper_typealias(CuTest *tc);
void test_cil_disable_children_helper_common(CuTest *tc);
void test_cil_disable_children_helper_class(CuTest *tc);
void test_cil_disable_children_helper_bool(CuTest *tc);
void test_cil_disable_children_helper_sens(CuTest *tc);
void test_cil_disable_children_helper_cat(CuTest *tc);
void test_cil_disable_children_helper_catset(CuTest *tc);
void test_cil_disable_children_helper_sid(CuTest *tc);
void test_cil_disable_children_helper_macro(CuTest *tc);
void test_cil_disable_children_helper_context(CuTest *tc);
void test_cil_disable_children_helper_level(CuTest *tc);
void test_cil_disable_children_helper_policycap(CuTest *tc);
void test_cil_disable_children_helper_perm(CuTest *tc);
void test_cil_disable_children_helper_catalias(CuTest *tc);
void test_cil_disable_children_helper_sensalias(CuTest *tc);
void test_cil_disable_children_helper_tunable(CuTest *tc);
void test_cil_disable_children_helper_unknown(CuTest *tc);
/*
__cil_resolve_ast_node_helper test cases
*/
void test_cil_resolve_ast_node_helper_call1(CuTest *);
void test_cil_resolve_ast_node_helper_call1_neg(CuTest *);
void test_cil_resolve_ast_node_helper_call2(CuTest *);
void test_cil_resolve_ast_node_helper_call2_neg(CuTest *);
void test_cil_resolve_ast_node_helper_boolif(CuTest *);
void test_cil_resolve_ast_node_helper_boolif_neg(CuTest *);
void test_cil_resolve_ast_node_helper_tunif(CuTest *);
void test_cil_resolve_ast_node_helper_tunif_neg(CuTest *);
void test_cil_resolve_ast_node_helper_catorder(CuTest *);
void test_cil_resolve_ast_node_helper_catorder_neg(CuTest *);
void test_cil_resolve_ast_node_helper_dominance(CuTest *);
void test_cil_resolve_ast_node_helper_dominance_neg(CuTest *);
void test_cil_resolve_ast_node_helper_roleallow(CuTest *);
void test_cil_resolve_ast_node_helper_roleallow_neg(CuTest *);
void test_cil_resolve_ast_node_helper_rolebounds(CuTest *tc);
void test_cil_resolve_ast_node_helper_rolebounds_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_sensalias(CuTest *);
void test_cil_resolve_ast_node_helper_sensalias_neg(CuTest *);
void test_cil_resolve_ast_node_helper_catalias(CuTest *);
void test_cil_resolve_ast_node_helper_catalias_neg(CuTest *);
void test_cil_resolve_ast_node_helper_catset(CuTest *);
void test_cil_resolve_ast_node_helper_catset_catlist_neg(CuTest *);
void test_cil_resolve_ast_node_helper_level(CuTest *);
void test_cil_resolve_ast_node_helper_level_neg(CuTest *);
void test_cil_resolve_ast_node_helper_levelrange(CuTest *);
void test_cil_resolve_ast_node_helper_levelrange_neg(CuTest *);
void test_cil_resolve_ast_node_helper_constrain(CuTest *);
void test_cil_resolve_ast_node_helper_constrain_neg(CuTest *);
void test_cil_resolve_ast_node_helper_mlsconstrain(CuTest *);
void test_cil_resolve_ast_node_helper_mlsconstrain_neg(CuTest *);
void test_cil_resolve_ast_node_helper_context(CuTest *);
void test_cil_resolve_ast_node_helper_context_neg(CuTest *);
void test_cil_resolve_ast_node_helper_catrange(CuTest *tc);
void test_cil_resolve_ast_node_helper_catrange_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_senscat(CuTest *tc);
void test_cil_resolve_ast_node_helper_senscat_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_roletransition(CuTest *);
void test_cil_resolve_ast_node_helper_roletransition_srcdecl_neg(CuTest *);
void test_cil_resolve_ast_node_helper_roletransition_tgtdecl_neg(CuTest *);
void test_cil_resolve_ast_node_helper_roletransition_resultdecl_neg(CuTest *);
void test_cil_resolve_ast_node_helper_typeattributeset(CuTest *);
void test_cil_resolve_ast_node_helper_typeattributeset_undef_type_neg(CuTest *);
void test_cil_resolve_ast_node_helper_typealias(CuTest *);
void test_cil_resolve_ast_node_helper_typealias_notype_neg(CuTest *);
void test_cil_resolve_ast_node_helper_typebounds(CuTest *);
void test_cil_resolve_ast_node_helper_typebounds_neg(CuTest *);
void test_cil_resolve_ast_node_helper_typepermissive(CuTest *);
void test_cil_resolve_ast_node_helper_typepermissive_neg(CuTest *);
void test_cil_resolve_ast_node_helper_nametypetransition(CuTest *);
void test_cil_resolve_ast_node_helper_nametypetransition_neg(CuTest *);
void test_cil_resolve_ast_node_helper_rangetransition(CuTest *);
void test_cil_resolve_ast_node_helper_rangetransition_neg(CuTest *);
void test_cil_resolve_ast_node_helper_avrule(CuTest *);
void test_cil_resolve_ast_node_helper_avrule_src_nores_neg(CuTest *);
void test_cil_resolve_ast_node_helper_avrule_tgt_nores_neg(CuTest *);
void test_cil_resolve_ast_node_helper_avrule_class_nores_neg(CuTest *);
void test_cil_resolve_ast_node_helper_avrule_datum_null_neg(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_transition(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_transition_neg(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_change(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_change_neg(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_member(CuTest *);
void test_cil_resolve_ast_node_helper_type_rule_member_neg(CuTest *);
void test_cil_resolve_ast_node_helper_userbounds(CuTest *tc);
void test_cil_resolve_ast_node_helper_userbounds_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_roletype(CuTest *tc);
void test_cil_resolve_ast_node_helper_roletype_role_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_roletype_type_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_userrole(CuTest *tc);
void test_cil_resolve_ast_node_helper_userrole_user_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_userrole_role_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_userlevel(CuTest *tc);
void test_cil_resolve_ast_node_helper_userlevel_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_userlevel(CuTest *tc);
void test_cil_resolve_ast_node_helper_userlevel_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_userrange(CuTest *tc);
void test_cil_resolve_ast_node_helper_userrange_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_classcommon(CuTest *tc);
void test_cil_resolve_ast_node_helper_classcommon_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_callstack(CuTest *tc);
void test_cil_resolve_ast_node_helper_call(CuTest *tc);
void test_cil_resolve_ast_node_helper_optional(CuTest *tc);
void test_cil_resolve_ast_node_helper_macro(CuTest *tc);
void test_cil_resolve_ast_node_helper_optstack(CuTest *tc);
void test_cil_resolve_ast_node_helper_optstack_tunable_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_optstack_macro_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_nodenull_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_extraargsnull_neg(CuTest *tc);
void test_cil_resolve_ast_node_helper_optfailedtoresolve(CuTest *tc);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_symtab.c000066400000000000000000000047271476211737200214160ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "test_cil_symtab.h"
#include "../../src/cil_tree.h"
#include "../../src/cil_symtab.h"
#include "../../src/cil_internal.h"
void test_cil_symtab_insert(CuTest *tc) {
symtab_t *test_symtab = NULL;
char* test_name = "test";
struct cil_block *test_block = malloc(sizeof(*test_block));
struct cil_tree_node *test_ast_node;
cil_tree_node_init(&test_ast_node);
struct cil_db *test_db;
cil_db_init(&test_db);
test_ast_node->parent = test_db->ast->root;
test_ast_node->line = 1;
cil_symtab_array_init(test_block->symtab, cil_sym_sizes[CIL_SYM_ARRAY_BLOCK]);
test_block->is_abstract = 0;
cil_get_symtab(test_db, test_ast_node->parent, &test_symtab, CIL_SYM_BLOCKS);
int rc = cil_symtab_insert(test_symtab, (hashtab_key_t)test_name, (struct cil_symtab_datum*)test_block, test_ast_node);
CuAssertIntEquals(tc, SEPOL_OK, rc);
}
libsepol-3.8.1/cil/test/unit/test_cil_symtab.h000066400000000000000000000033071476211737200214140ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_SYMTAB_H_
#define TEST_CIL_SYMTAB_H_
#include "CuTest.h"
void test_cil_symtab_insert(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_cil_tree.c000066400000000000000000000054211476211737200210460ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "test_cil_tree.h"
#include "../../src/cil_tree.h"
void test_cil_tree_node_init(CuTest *tc) {
struct cil_tree_node *test_node;
cil_tree_node_init(&test_node);
CuAssertPtrNotNull(tc, test_node);
CuAssertPtrEquals(tc, NULL, test_node->cl_head);
CuAssertPtrEquals(tc, NULL, test_node->cl_tail);
CuAssertPtrEquals(tc, NULL, test_node->parent);
CuAssertPtrEquals(tc, NULL, test_node->data);
CuAssertPtrEquals(tc, NULL, test_node->next);
CuAssertIntEquals(tc, 0, test_node->flavor);
CuAssertIntEquals(tc, 0, test_node->line);
free(test_node);
}
void test_cil_tree_init(CuTest *tc) {
struct cil_tree *test_tree;
int rc = cil_tree_init(&test_tree);
CuAssertIntEquals(tc, SEPOL_OK, rc);
CuAssertPtrNotNull(tc, test_tree);
CuAssertPtrEquals(tc, NULL, test_tree->root->cl_head);
CuAssertPtrEquals(tc, NULL, test_tree->root->cl_tail);
CuAssertPtrEquals(tc, NULL, test_tree->root->parent);
CuAssertPtrEquals(tc, NULL, test_tree->root->data);
CuAssertPtrEquals(tc, NULL, test_tree->root->next);
CuAssertIntEquals(tc, 0, test_tree->root->flavor);
CuAssertIntEquals(tc, 0, test_tree->root->line);
free(test_tree);
}
libsepol-3.8.1/cil/test/unit/test_cil_tree.h000066400000000000000000000033471476211737200210600ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_CIL_TREE_H_
#define TEST_CIL_TREE_H_
#include "CuTest.h"
void test_cil_tree_node_init(CuTest *);
void test_cil_tree_init(CuTest *);
#endif
libsepol-3.8.1/cil/test/unit/test_integration.c000066400000000000000000000061731476211737200216100ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include
#include "CuTest.h"
#include "test_integration.h"
#include
#include
#include
#include
#include
void test_integration(CuTest *tc) {
int status = 0, status1 = 0, status2 = 0;
status = system("./secilc -M -c 24 test/integration.cil &> /dev/null");
if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT))
printf("Call to system for secilc failed.\n");
status1 = system("checkpolicy -M -c 24 -o policy.conf.24 test/policy.conf &> /dev/null");
if (WIFSIGNALED(status1) && (WTERMSIG(status1) == SIGINT || WTERMSIG(status1) == SIGQUIT))
printf("Call to checkpolicy failed.\n");
status2 = system("sediff -q policy.24 \\; policy.conf.24 &> /dev/null");
if (WIFSIGNALED(status2) && (WTERMSIG(status2) == SIGINT || WTERMSIG(status2) == SIGQUIT))
printf("Call to sediff for secilc failed.\n");
CuAssertIntEquals(tc, 1, WIFEXITED(status));
CuAssertIntEquals(tc, 0, WEXITSTATUS(status));
CuAssertIntEquals(tc, 1, WIFEXITED(status1));
CuAssertIntEquals(tc, 0, WEXITSTATUS(status1));
CuAssertIntEquals(tc, 1, WIFEXITED(status2));
CuAssertIntEquals(tc, 0, WEXITSTATUS(status2));
}
void test_min_policy(CuTest *tc) {
int status = 0;
status = system("./secilc -M -c 24 test/policy.cil &> /dev/null");
if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT))
printf("Call to system for secilc failed.\n");
CuAssertIntEquals(tc, 1, WIFEXITED(status));
CuAssertIntEquals(tc, 0, WEXITSTATUS(status));
}
libsepol-3.8.1/cil/test/unit/test_integration.h000066400000000000000000000033411476211737200216070ustar00rootroot00000000000000/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#ifndef TEST_INTEGRATION_H
#define TEST_INTEGRATION_H
#include "CuTest.h"
void test_min_policy(CuTest *);
void test_integration(CuTest *);
#endif
libsepol-3.8.1/fuzz/000077500000000000000000000000001476211737200143445ustar00rootroot00000000000000libsepol-3.8.1/fuzz/binpolicy-fuzzer.c000066400000000000000000000047011476211737200200250ustar00rootroot00000000000000#include
#include
#include
#include
#include
#include
#include
extern int policydb_validate(sepol_handle_t *handle, const policydb_t *p);
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
// set to 1 to enable more verbose libsepol logging
#define VERBOSE 0
static int write_binary_policy(policydb_t *p, FILE *outfp)
{
struct policy_file pf;
policy_file_init(&pf);
pf.type = PF_USE_STDIO;
pf.fp = outfp;
return policydb_write(p, &pf);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
policydb_t policydb = {}, out = {};
sidtab_t sidtab = {};
struct policy_file pf;
FILE *devnull = NULL;
sepol_debug(VERBOSE);
policy_file_init(&pf);
pf.type = PF_USE_MEMORY;
pf.data = (char *) data;
pf.len = size;
if (policydb_init(&policydb))
goto exit;
if (policydb_read(&policydb, &pf, VERBOSE))
goto exit;
if (policydb_load_isids(&policydb, &sidtab))
goto exit;
if (policydb.policy_type == POLICY_KERN) {
(void) policydb_optimize(&policydb);
if (policydb_validate(NULL, &policydb) == -1)
abort();
}
if (policydb.global->branch_list)
(void) check_assertions(NULL, &policydb, policydb.global->branch_list->avrules);
(void) hierarchy_check_constraints(NULL, &policydb);
devnull = fopen("/dev/null", "we");
if (!devnull)
goto exit;
if (write_binary_policy(&policydb, devnull))
abort();
if (policydb.policy_type == POLICY_KERN) {
if (sepol_kernel_policydb_to_conf(devnull, &policydb))
abort();
if (sepol_kernel_policydb_to_cil(devnull, &policydb))
abort();
} else if (policydb.policy_type == POLICY_BASE) {
if (link_modules(NULL, &policydb, NULL, 0, VERBOSE))
goto exit;
if (policydb_init(&out))
goto exit;
if (expand_module(NULL, &policydb, &out, VERBOSE, /*check_assertions=*/0))
goto exit;
(void) check_assertions(NULL, &out, out.global->branch_list->avrules);
(void) hierarchy_check_constraints(NULL, &out);
if (write_binary_policy(&out, devnull))
abort();
if (sepol_kernel_policydb_to_conf(devnull, &out))
abort();
if (sepol_kernel_policydb_to_cil(devnull, &out))
abort();
}
exit:
if (devnull != NULL)
fclose(devnull);
policydb_destroy(&out);
policydb_destroy(&policydb);
sepol_sidtab_destroy(&sidtab);
/* Non-zero return values are reserved for future use. */
return 0;
}
libsepol-3.8.1/fuzz/policy.bin000066400000000000000000000030201476211737200163300ustar00rootroot00000000000000��|�SE Linux @@dirblk_filechr_filelnk_fileprocess
dyntransition
transition fifo_filefile sock_filesys_role@@@@object_r@@
dpkg_script_trpm_script_tsys_isidsys_user@@@@@@s0@@defaultsens@@sensdefault@@c0 @@@
@ @@@@@devpts@devtmpfs@@@libsepol-3.8.1/fuzz/secilc-fuzzer.c000066400000000000000000000034411476211737200172770ustar00rootroot00000000000000#include
#include
#include
#include
#include
#include
#include
#include
static void log_handler(__attribute__((unused)) int lvl, __attribute__((unused)) const char *msg) {
/* be quiet */
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
enum cil_log_level log_level = CIL_ERR;
struct sepol_policy_file *pf = NULL;
FILE *dev_null = NULL;
int target = SEPOL_TARGET_SELINUX;
int disable_dontaudit = 0;
int multiple_decls = 0;
int disable_neverallow = 0;
int preserve_tunables = 0;
int policyvers = POLICYDB_VERSION_MAX;
int mls = -1;
int attrs_expand_generated = 0;
struct cil_db *db = NULL;
sepol_policydb_t *pdb = NULL;
cil_set_log_level(log_level);
cil_set_log_handler(log_handler);
cil_db_init(&db);
cil_set_disable_dontaudit(db, disable_dontaudit);
cil_set_multiple_decls(db, multiple_decls);
cil_set_disable_neverallow(db, disable_neverallow);
cil_set_preserve_tunables(db, preserve_tunables);
cil_set_mls(db, mls);
cil_set_target_platform(db, target);
cil_set_policy_version(db, policyvers);
cil_set_attrs_expand_generated(db, attrs_expand_generated);
if (cil_add_file(db, "fuzz", (const char *)data, size) != SEPOL_OK)
goto exit;
if (cil_compile(db) != SEPOL_OK)
goto exit;
if (cil_build_policydb(db, &pdb) != SEPOL_OK)
goto exit;
if (sepol_policydb_optimize(pdb) != SEPOL_OK)
goto exit;
dev_null = fopen("/dev/null", "w");
if (dev_null == NULL)
goto exit;
if (sepol_policy_file_create(&pf) != 0)
goto exit;
sepol_policy_file_set_fp(pf, dev_null);
if (sepol_policydb_write(pdb, pf) != 0)
goto exit;
exit:
if (dev_null != NULL)
fclose(dev_null);
cil_db_destroy(&db);
sepol_policydb_free(pdb);
sepol_policy_file_free(pf);
return 0;
}
libsepol-3.8.1/include/000077500000000000000000000000001476211737200147715ustar00rootroot00000000000000libsepol-3.8.1/include/Makefile000066400000000000000000000011471476211737200164340ustar00rootroot00000000000000# Installation directories.
PREFIX ?= /usr
INCDIR = $(PREFIX)/include/sepol
CILDIR ?= ../cil
all:
install: all
test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
test -d $(DESTDIR)$(INCDIR)/policydb || install -m 755 -d $(DESTDIR)$(INCDIR)/policydb
test -d $(DESTDIR)$(INCDIR)/cil || install -m 755 -d $(DESTDIR)$(INCDIR)/cil
install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
indent:
../../scripts/Lindent $(wildcard sepol/*.h)
libsepol-3.8.1/include/sepol/000077500000000000000000000000001476211737200161135ustar00rootroot00000000000000libsepol-3.8.1/include/sepol/boolean_record.h000066400000000000000000000030171476211737200212420ustar00rootroot00000000000000#ifndef _SEPOL_BOOLEAN_RECORD_H_
#define _SEPOL_BOOLEAN_RECORD_H_
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_bool;
struct sepol_bool_key;
typedef struct sepol_bool sepol_bool_t;
typedef struct sepol_bool_key sepol_bool_key_t;
/* Key */
extern int sepol_bool_key_create(sepol_handle_t * handle,
const char *name, sepol_bool_key_t ** key);
extern void sepol_bool_key_unpack(const sepol_bool_key_t * key,
const char **name);
extern int sepol_bool_key_extract(sepol_handle_t * handle,
const sepol_bool_t * boolean,
sepol_bool_key_t ** key_ptr);
extern void sepol_bool_key_free(sepol_bool_key_t * key);
extern int sepol_bool_compare(const sepol_bool_t * boolean,
const sepol_bool_key_t * key);
extern int sepol_bool_compare2(const sepol_bool_t * boolean,
const sepol_bool_t * boolean2);
/* Name */
extern const char *sepol_bool_get_name(const sepol_bool_t * boolean);
extern int sepol_bool_set_name(sepol_handle_t * handle,
sepol_bool_t * boolean, const char *name);
/* Value */
extern int sepol_bool_get_value(const sepol_bool_t * boolean);
extern void sepol_bool_set_value(sepol_bool_t * boolean, int value);
/* Create/Clone/Destroy */
extern int sepol_bool_create(sepol_handle_t * handle, sepol_bool_t ** bool_ptr);
extern int sepol_bool_clone(sepol_handle_t * handle,
const sepol_bool_t * boolean,
sepol_bool_t ** bool_ptr);
extern void sepol_bool_free(sepol_bool_t * boolean);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/booleans.h000066400000000000000000000024571476211737200200760ustar00rootroot00000000000000#ifndef _SEPOL_BOOLEANS_H_
#define _SEPOL_BOOLEANS_H_
#include
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Set the specified boolean */
extern int sepol_bool_set(sepol_handle_t * handle,
sepol_policydb_t * policydb,
const sepol_bool_key_t * key,
const sepol_bool_t * data);
/* Return the number of booleans */
extern int sepol_bool_count(sepol_handle_t * handle,
const sepol_policydb_t * p, unsigned int *response);
/* Check if the specified boolean exists */
extern int sepol_bool_exists(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_bool_key_t * key, int *response);
/* Query a boolean - returns the boolean, or NULL if not found */
extern int sepol_bool_query(sepol_handle_t * handle,
const sepol_policydb_t * p,
const sepol_bool_key_t * key,
sepol_bool_t ** response);
/* Iterate the booleans
* The handler may return:
* -1 to signal an error condition,
* 1 to signal successful exit
* 0 to signal continue */
extern int sepol_bool_iterate(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
int (*fn) (const sepol_bool_t * boolean,
void *fn_arg), void *arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/context.h000066400000000000000000000013601476211737200177500ustar00rootroot00000000000000#ifndef _SEPOL_CONTEXT_H_
#define _SEPOL_CONTEXT_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* -- Deprecated -- */
extern int sepol_check_context(const char *context);
/* -- End deprecated -- */
extern int sepol_context_check(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_context_t * context);
extern int sepol_mls_contains(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const char *mls1,
const char *mls2, int *response);
extern int sepol_mls_check(sepol_handle_t * handle,
const sepol_policydb_t * policydb, const char *mls);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/context_record.h000066400000000000000000000032061476211737200213070ustar00rootroot00000000000000#ifndef _SEPOL_CONTEXT_RECORD_H_
#define _SEPOL_CONTEXT_RECORD_H_
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_context;
typedef struct sepol_context sepol_context_t;
/* We don't need a key, because the context is never stored
* in a data collection by itself */
/* User */
extern const char *sepol_context_get_user(const sepol_context_t * con);
extern int sepol_context_set_user(sepol_handle_t * handle,
sepol_context_t * con, const char *user);
/* Role */
extern const char *sepol_context_get_role(const sepol_context_t * con);
extern int sepol_context_set_role(sepol_handle_t * handle,
sepol_context_t * con, const char *role);
/* Type */
extern const char *sepol_context_get_type(const sepol_context_t * con);
extern int sepol_context_set_type(sepol_handle_t * handle,
sepol_context_t * con, const char *type);
/* MLS */
extern const char *sepol_context_get_mls(const sepol_context_t * con);
extern int sepol_context_set_mls(sepol_handle_t * handle,
sepol_context_t * con, const char *mls_range);
/* Create/Clone/Destroy */
extern int sepol_context_create(sepol_handle_t * handle,
sepol_context_t ** con_ptr);
extern int sepol_context_clone(sepol_handle_t * handle,
const sepol_context_t * con,
sepol_context_t ** con_ptr);
extern void sepol_context_free(sepol_context_t * con);
/* Parse to/from string */
extern int sepol_context_from_string(sepol_handle_t * handle,
const char *str, sepol_context_t ** con);
extern int sepol_context_to_string(sepol_handle_t * handle,
const sepol_context_t * con, char **str_ptr);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/debug.h000066400000000000000000000017171476211737200173600ustar00rootroot00000000000000#ifndef _SEPOL_DEBUG_H_
#define _SEPOL_DEBUG_H_
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Deprecated */
extern void sepol_debug(int on);
/* End deprecated */
#define SEPOL_MSG_ERR 1
#define SEPOL_MSG_WARN 2
#define SEPOL_MSG_INFO 3
extern int sepol_msg_get_level(sepol_handle_t * handle);
extern const char *sepol_msg_get_channel(sepol_handle_t * handle);
extern const char *sepol_msg_get_fname(sepol_handle_t * handle);
/* Set the messaging callback.
* By the default, the callback will print
* the message on standard output, in a
* particular format. Passing NULL here
* indicates that messaging should be suppressed */
extern void sepol_msg_set_callback(sepol_handle_t * handle,
#ifdef __GNUC__
__attribute__ ((format(printf, 3, 4)))
#endif
void (*msg_callback) (void *varg,
sepol_handle_t *
handle,
const char *fmt, ...),
void *msg_callback_arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/errcodes.h000066400000000000000000000014721476211737200200760ustar00rootroot00000000000000/* Author: Karl MacMillan */
#ifndef __sepol_errno_h__
#define __sepol_errno_h__
#include
#ifdef __cplusplus
extern "C" {
#endif
#define SEPOL_OK 0
/* These first error codes are defined for compatibility with
* previous version of libsepol. In the future, custom error
* codes that don't map to system error codes should be defined
* outside of the range of system error codes.
*/
#define SEPOL_ERR (-1)
#define SEPOL_ENOTSUP (-2) /* feature not supported in module language */
#define SEPOL_EREQ (-3) /* requirements not met */
/* Error codes that map to system error codes */
#define SEPOL_ENOMEM (-ENOMEM)
#define SEPOL_EEXIST (-EEXIST)
#define SEPOL_ENOENT (-ENOENT)
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/handle.h000066400000000000000000000025611476211737200175230ustar00rootroot00000000000000#ifndef _SEPOL_HANDLE_H_
#define _SEPOL_HANDLE_H_
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_handle;
typedef struct sepol_handle sepol_handle_t;
/* Create and return a sepol handle. */
sepol_handle_t *sepol_handle_create(void);
/* Get whether or not dontaudits will be disabled, same values as
* specified by set_disable_dontaudit. This value reflects the state
* your system will be set to upon commit, not necessarily its
* current state.*/
int sepol_get_disable_dontaudit(sepol_handle_t * sh);
/* Set whether or not to disable dontaudits, 0 is default and does
* not disable dontaudits, 1 disables them */
void sepol_set_disable_dontaudit(sepol_handle_t * sh, int disable_dontaudit);
/* Set whether module_expand() should consume the base policy passed in.
* This should reduce the amount of memory required to expand the policy. */
void sepol_set_expand_consume_base(sepol_handle_t * sh, int consume_base);
/* Destroy a sepol handle. */
void sepol_handle_destroy(sepol_handle_t *);
/* Get whether or not needless unused branch of tunables would be preserved */
int sepol_get_preserve_tunables(sepol_handle_t * sh);
/* Set whether or not to preserve the needless unused branch of tunables,
* 0 is default and discard such branch, 1 preserves them */
void sepol_set_preserve_tunables(sepol_handle_t * sh, int preserve_tunables);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/ibendport_record.h000066400000000000000000000042061476211737200216120ustar00rootroot00000000000000#ifndef _SEPOL_IBENDPORT_RECORD_H_
#define _SEPOL_IBENDPORT_RECORD_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_ibendport;
struct sepol_ibendport_key;
typedef struct sepol_ibendport sepol_ibendport_t;
typedef struct sepol_ibendport_key sepol_ibendport_key_t;
extern int sepol_ibendport_compare(const sepol_ibendport_t *ibendport,
const sepol_ibendport_key_t *key);
extern int sepol_ibendport_compare2(const sepol_ibendport_t *ibendport,
const sepol_ibendport_t *ibendport2);
extern int sepol_ibendport_key_create(sepol_handle_t *handle,
const char *ibdev_name,
int port,
sepol_ibendport_key_t **key_ptr);
extern void sepol_ibendport_key_unpack(const sepol_ibendport_key_t *key,
const char **ibdev_name,
int *port);
extern int sepol_ibendport_alloc_ibdev_name(sepol_handle_t *handle,
char **ibdev_name);
extern int sepol_ibendport_key_extract(sepol_handle_t *handle,
const sepol_ibendport_t *ibendport,
sepol_ibendport_key_t **key_ptr);
extern void sepol_ibendport_key_free(sepol_ibendport_key_t *key);
extern void sepol_ibendport_set_port(sepol_ibendport_t *ibendport, int port);
extern int sepol_ibendport_get_port(const sepol_ibendport_t *ibendport);
extern int sepol_ibendport_get_ibdev_name(sepol_handle_t *handle,
const sepol_ibendport_t *ibendport,
char **ibdev_name);
extern int sepol_ibendport_set_ibdev_name(sepol_handle_t *handle,
sepol_ibendport_t *ibendport,
const char *ibdev_name);
extern sepol_context_t *sepol_ibendport_get_con(const sepol_ibendport_t *ibendport);
extern int sepol_ibendport_set_con(sepol_handle_t *handle,
sepol_ibendport_t *ibendport,
sepol_context_t *con);
extern int sepol_ibendport_create(sepol_handle_t *handle,
sepol_ibendport_t **ibendport_ptr);
extern int sepol_ibendport_clone(sepol_handle_t *handle,
const sepol_ibendport_t *ibendport,
sepol_ibendport_t **ibendport_ptr);
extern void sepol_ibendport_free(sepol_ibendport_t *ibendport);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/ibendports.h000066400000000000000000000025531476211737200204420ustar00rootroot00000000000000#ifndef _SEPOL_IBENDPORTS_H_
#define _SEPOL_IBENDPORTS_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Return the number of ibendports */
extern int sepol_ibendport_count(sepol_handle_t *handle,
const sepol_policydb_t *p,
unsigned int *response);
/* Check if a ibendport exists */
extern int sepol_ibendport_exists(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
const sepol_ibendport_key_t *key, int *response);
/* Query a ibendport - returns the ibendport, or NULL if not found */
extern int sepol_ibendport_query(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
const sepol_ibendport_key_t *key,
sepol_ibendport_t **response);
/* Modify a ibendport, or add it, if the key is not found */
extern int sepol_ibendport_modify(sepol_handle_t *handle,
sepol_policydb_t *policydb,
const sepol_ibendport_key_t *key,
const sepol_ibendport_t *data);
/* Iterate the ibendports
* The handler may return:
* -1 to signal an error condition,
* 1 to signal successful exit
* 0 to signal continue
*/
extern int sepol_ibendport_iterate(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
int (*fn)(const sepol_ibendport_t *ibendport,
void *fn_arg), void *arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/ibpkey_record.h000066400000000000000000000043751476211737200211160ustar00rootroot00000000000000#ifndef _SEPOL_IBPKEY_RECORD_H_
#define _SEPOL_IBPKEY_RECORD_H_
#include
#include
#include
#include
#define INET6_ADDRLEN 16
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_ibpkey;
struct sepol_ibpkey_key;
typedef struct sepol_ibpkey sepol_ibpkey_t;
typedef struct sepol_ibpkey_key sepol_ibpkey_key_t;
extern int sepol_ibpkey_compare(const sepol_ibpkey_t *ibpkey,
const sepol_ibpkey_key_t *key);
extern int sepol_ibpkey_compare2(const sepol_ibpkey_t *ibpkey,
const sepol_ibpkey_t *ibpkey2);
extern int sepol_ibpkey_key_create(sepol_handle_t *handle,
const char *subnet_prefix,
int low, int high,
sepol_ibpkey_key_t **key_ptr);
extern void sepol_ibpkey_key_unpack(const sepol_ibpkey_key_t *key,
uint64_t *subnet_prefix,
int *low, int *high);
extern int sepol_ibpkey_key_extract(sepol_handle_t *handle,
const sepol_ibpkey_t *ibpkey,
sepol_ibpkey_key_t **key_ptr);
extern void sepol_ibpkey_key_free(sepol_ibpkey_key_t *key);
extern int sepol_ibpkey_get_low(const sepol_ibpkey_t *ibpkey);
extern int sepol_ibpkey_get_high(const sepol_ibpkey_t *ibpkey);
extern void sepol_ibpkey_set_pkey(sepol_ibpkey_t *ibpkey, int pkey_num);
extern void sepol_ibpkey_set_range(sepol_ibpkey_t *ibpkey, int low, int high);
extern int sepol_ibpkey_get_subnet_prefix(sepol_handle_t *handle,
const sepol_ibpkey_t *ibpkey,
char **subnet_prefix);
extern uint64_t sepol_ibpkey_get_subnet_prefix_bytes(const sepol_ibpkey_t *ibpkey);
extern int sepol_ibpkey_set_subnet_prefix(sepol_handle_t *handle,
sepol_ibpkey_t *ibpkey,
const char *subnet_prefix);
extern void sepol_ibpkey_set_subnet_prefix_bytes(sepol_ibpkey_t *ibpkey,
uint64_t subnet_prefix);
extern sepol_context_t *sepol_ibpkey_get_con(const sepol_ibpkey_t *ibpkey);
extern int sepol_ibpkey_set_con(sepol_handle_t *handle,
sepol_ibpkey_t *ibpkey, sepol_context_t *con);
extern int sepol_ibpkey_create(sepol_handle_t *handle, sepol_ibpkey_t **ibpkey_ptr);
extern int sepol_ibpkey_clone(sepol_handle_t *handle,
const sepol_ibpkey_t *ibpkey,
sepol_ibpkey_t **ibpkey_ptr);
extern void sepol_ibpkey_free(sepol_ibpkey_t *ibpkey);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/ibpkeys.h000066400000000000000000000025031476211737200177320ustar00rootroot00000000000000#ifndef _SEPOL_IBPKEYS_H_
#define _SEPOL_IBPKEYS_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Return the number of ibpkeys */
extern int sepol_ibpkey_count(sepol_handle_t *handle,
const sepol_policydb_t *p, unsigned int *response);
/* Check if a ibpkey exists */
extern int sepol_ibpkey_exists(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
const sepol_ibpkey_key_t *key, int *response);
/* Query a ibpkey - returns the ibpkey, or NULL if not found */
extern int sepol_ibpkey_query(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
const sepol_ibpkey_key_t *key,
sepol_ibpkey_t **response);
/* Modify a ibpkey, or add it, if the key is not found */
extern int sepol_ibpkey_modify(sepol_handle_t *handle,
sepol_policydb_t *policydb,
const sepol_ibpkey_key_t *key,
const sepol_ibpkey_t *data);
/* Iterate the ibpkeys
* The handler may return:
* -1 to signal an error condition,
* 1 to signal successful exit
* 0 to signal continue
*/
extern int sepol_ibpkey_iterate(sepol_handle_t *handle,
const sepol_policydb_t *policydb,
int (*fn)(const sepol_ibpkey_t *ibpkey,
void *fn_arg), void *arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/iface_record.h000066400000000000000000000034601476211737200206740ustar00rootroot00000000000000#ifndef _SEPOL_IFACE_RECORD_H_
#define _SEPOL_IFACE_RECORD_H_
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_iface;
struct sepol_iface_key;
typedef struct sepol_iface sepol_iface_t;
typedef struct sepol_iface_key sepol_iface_key_t;
/* Key */
extern int sepol_iface_compare(const sepol_iface_t * iface,
const sepol_iface_key_t * key);
extern int sepol_iface_compare2(const sepol_iface_t * iface,
const sepol_iface_t * iface2);
extern void sepol_iface_key_unpack(const sepol_iface_key_t * key,
const char **name);
extern int sepol_iface_key_create(sepol_handle_t * handle,
const char *name,
sepol_iface_key_t ** key_ptr);
extern int sepol_iface_key_extract(sepol_handle_t * handle,
const sepol_iface_t * iface,
sepol_iface_key_t ** key_ptr);
extern void sepol_iface_key_free(sepol_iface_key_t * key);
/* Name */
extern const char *sepol_iface_get_name(const sepol_iface_t * iface);
extern int sepol_iface_set_name(sepol_handle_t * handle,
sepol_iface_t * iface, const char *name);
/* Context */
extern sepol_context_t *sepol_iface_get_ifcon(const sepol_iface_t * iface);
extern int sepol_iface_set_ifcon(sepol_handle_t * handle,
sepol_iface_t * iface, sepol_context_t * con);
extern sepol_context_t *sepol_iface_get_msgcon(const sepol_iface_t * iface);
extern int sepol_iface_set_msgcon(sepol_handle_t * handle,
sepol_iface_t * iface, sepol_context_t * con);
/* Create/Clone/Destroy */
extern int sepol_iface_create(sepol_handle_t * handle,
sepol_iface_t ** iface_ptr);
extern int sepol_iface_clone(sepol_handle_t * handle,
const sepol_iface_t * iface,
sepol_iface_t ** iface_ptr);
extern void sepol_iface_free(sepol_iface_t * iface);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/interfaces.h000066400000000000000000000025731476211737200204160ustar00rootroot00000000000000#ifndef __SEPOL_INTERFACES_H_
#define __SEPOL_INTERFACES_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Return the number of interfaces */
extern int sepol_iface_count(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
unsigned int *response);
/* Check if an interface exists */
extern int sepol_iface_exists(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_iface_key_t * key, int *response);
/* Query an interface - returns the interface,
* or NULL if not found */
extern int sepol_iface_query(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_iface_key_t * key,
sepol_iface_t ** response);
/* Modify an interface, or add it, if the key
* is not found */
extern int sepol_iface_modify(sepol_handle_t * handle,
sepol_policydb_t * policydb,
const sepol_iface_key_t * key,
const sepol_iface_t * data);
/* Iterate the interfaces
* The handler may return:
* -1 to signal an error condition,
* 1 to signal successful exit
* 0 to signal continue */
extern int sepol_iface_iterate(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
int (*fn) (const sepol_iface_t * iface,
void *fn_arg), void *arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/kernel_to_cil.h000066400000000000000000000001751476211737200211000ustar00rootroot00000000000000#include
#include
int sepol_kernel_policydb_to_cil(FILE *fp, struct policydb *pdb);
libsepol-3.8.1/include/sepol/kernel_to_conf.h000066400000000000000000000001761476211737200212570ustar00rootroot00000000000000#include
#include
int sepol_kernel_policydb_to_conf(FILE *fp, struct policydb *pdb);
libsepol-3.8.1/include/sepol/module.h000066400000000000000000000051701476211737200175540ustar00rootroot00000000000000#ifndef _SEPOL_MODULE_H_
#define _SEPOL_MODULE_H_
#include
#include
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_module_package;
typedef struct sepol_module_package sepol_module_package_t;
/* Module package public interfaces. */
extern int sepol_module_package_create(sepol_module_package_t ** p);
extern void sepol_module_package_free(sepol_module_package_t * p);
extern char *sepol_module_package_get_file_contexts(sepol_module_package_t * p);
extern size_t sepol_module_package_get_file_contexts_len(sepol_module_package_t
* p);
extern int sepol_module_package_set_file_contexts(sepol_module_package_t * p,
char *data, size_t len);
extern char *sepol_module_package_get_seusers(sepol_module_package_t * p);
extern size_t sepol_module_package_get_seusers_len(sepol_module_package_t * p);
extern int sepol_module_package_set_seusers(sepol_module_package_t * p,
char *data, size_t len);
extern char *sepol_module_package_get_user_extra(sepol_module_package_t * p);
extern size_t sepol_module_package_get_user_extra_len(sepol_module_package_t *
p);
extern int sepol_module_package_set_user_extra(sepol_module_package_t * p,
char *data, size_t len);
extern char *sepol_module_package_get_netfilter_contexts(sepol_module_package_t
* p);
extern size_t
sepol_module_package_get_netfilter_contexts_len(sepol_module_package_t * p);
extern int sepol_module_package_set_netfilter_contexts(sepol_module_package_t *
p, char *data,
size_t len);
extern sepol_policydb_t *sepol_module_package_get_policy(sepol_module_package_t
* p);
extern int sepol_link_packages(sepol_handle_t * handle,
sepol_module_package_t * base,
sepol_module_package_t ** modules,
int num_modules, int verbose);
extern int sepol_module_package_read(sepol_module_package_t * mod,
struct sepol_policy_file *file,
int verbose);
extern int sepol_module_package_info(struct sepol_policy_file *file,
int *type, char **name, char **version);
extern int sepol_module_package_write(sepol_module_package_t * p,
struct sepol_policy_file *file);
/* Module linking/expanding public interfaces. */
extern int sepol_link_modules(sepol_handle_t * handle,
sepol_policydb_t * base,
sepol_policydb_t ** modules,
size_t len, int verbose);
extern int sepol_expand_module(sepol_handle_t * handle,
sepol_policydb_t * base,
sepol_policydb_t * out, int verbose, int check);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/module_to_cil.h000066400000000000000000000005111476211737200210770ustar00rootroot00000000000000#include
#include
#include
int sepol_module_policydb_to_cil(FILE *fp, struct policydb *pdb, int linked);
int sepol_module_package_to_cil(FILE *fp, struct sepol_module_package *mod_pkg);
int sepol_ppfile_to_module_package(FILE *fp, struct sepol_module_package **mod_pkg);
libsepol-3.8.1/include/sepol/node_record.h000066400000000000000000000053661476211737200205610ustar00rootroot00000000000000#ifndef _SEPOL_NODE_RECORD_H_
#define _SEPOL_NODE_RECORD_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_node;
struct sepol_node_key;
typedef struct sepol_node sepol_node_t;
typedef struct sepol_node_key sepol_node_key_t;
#define SEPOL_PROTO_IP4 0
#define SEPOL_PROTO_IP6 1
/* Key */
extern int sepol_node_compare(const sepol_node_t * node,
const sepol_node_key_t * key);
extern int sepol_node_compare2(const sepol_node_t * node,
const sepol_node_t * node2);
extern int sepol_node_key_create(sepol_handle_t * handle,
const char *addr,
const char *mask,
int proto, sepol_node_key_t ** key_ptr);
extern void sepol_node_key_unpack(const sepol_node_key_t * key,
const char **addr,
const char **mask, int *proto);
extern int sepol_node_key_extract(sepol_handle_t * handle,
const sepol_node_t * node,
sepol_node_key_t ** key_ptr);
extern void sepol_node_key_free(sepol_node_key_t * key);
/* Address */
extern int sepol_node_get_addr(sepol_handle_t * handle,
const sepol_node_t * node, char **addr);
extern int sepol_node_get_addr_bytes(sepol_handle_t * handle,
const sepol_node_t * node,
char **addr, size_t * addr_sz);
extern int sepol_node_set_addr(sepol_handle_t * handle,
sepol_node_t * node,
int proto, const char *addr);
extern int sepol_node_set_addr_bytes(sepol_handle_t * handle,
sepol_node_t * node,
const char *addr, size_t addr_sz);
/* Netmask */
extern int sepol_node_get_mask(sepol_handle_t * handle,
const sepol_node_t * node, char **mask);
extern int sepol_node_get_mask_bytes(sepol_handle_t * handle,
const sepol_node_t * node,
char **mask, size_t * mask_sz);
extern int sepol_node_set_mask(sepol_handle_t * handle,
sepol_node_t * node,
int proto, const char *mask);
extern int sepol_node_set_mask_bytes(sepol_handle_t * handle,
sepol_node_t * node,
const char *mask, size_t mask_sz);
/* Protocol */
extern int sepol_node_get_proto(const sepol_node_t * node);
extern void sepol_node_set_proto(sepol_node_t * node, int proto);
extern const char *sepol_node_get_proto_str(int proto);
/* Context */
extern sepol_context_t *sepol_node_get_con(const sepol_node_t * node);
extern int sepol_node_set_con(sepol_handle_t * handle,
sepol_node_t * node, sepol_context_t * con);
/* Create/Clone/Destroy */
extern int sepol_node_create(sepol_handle_t * handle, sepol_node_t ** node_ptr);
extern int sepol_node_clone(sepol_handle_t * handle,
const sepol_node_t * node,
sepol_node_t ** node_ptr);
extern void sepol_node_free(sepol_node_t * node);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/nodes.h000066400000000000000000000024401476211737200173740ustar00rootroot00000000000000#ifndef _SEPOL_NODES_H_
#define _SEPOL_NODES_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
/* Return the number of nodes */
extern int sepol_node_count(sepol_handle_t * handle,
const sepol_policydb_t * p, unsigned int *response);
/* Check if a node exists */
extern int sepol_node_exists(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_node_key_t * key, int *response);
/* Query a node - returns the node, or NULL if not found */
extern int sepol_node_query(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
const sepol_node_key_t * key,
sepol_node_t ** response);
/* Modify a node, or add it, if the key is not found */
extern int sepol_node_modify(sepol_handle_t * handle,
sepol_policydb_t * policydb,
const sepol_node_key_t * key,
const sepol_node_t * data);
/* Iterate the nodes
* The handler may return:
* -1 to signal an error condition,
* 1 to signal successful exit
* 0 to signal continue */
extern int sepol_node_iterate(sepol_handle_t * handle,
const sepol_policydb_t * policydb,
int (*fn) (const sepol_node_t * node,
void *fn_arg), void *arg);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/policydb.h000066400000000000000000000113151476211737200200720ustar00rootroot00000000000000#ifndef _SEPOL_POLICYDB_H_
#define _SEPOL_POLICYDB_H_
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct sepol_policy_file;
typedef struct sepol_policy_file sepol_policy_file_t;
struct sepol_policydb;
typedef struct sepol_policydb sepol_policydb_t;
/* Policy file public interfaces. */
/* Create and free memory associated with a policy file. */
extern int sepol_policy_file_create(sepol_policy_file_t ** pf);
extern void sepol_policy_file_free(sepol_policy_file_t * pf);
/*
* Set the policy file to represent a binary policy memory image.
* Subsequent operations using the policy file will read and write
* the image located at the specified address with the specified length.
* If 'len' is 0, then merely compute the necessary length upon
* subsequent policydb write operations in order to determine the
* necessary buffer size to allocate.
*/
extern void sepol_policy_file_set_mem(sepol_policy_file_t * pf,
char *data, size_t len);
/*
* Get the size of the buffer needed to store a policydb write
* previously done on this policy file.
*/
extern int sepol_policy_file_get_len(sepol_policy_file_t * pf, size_t * len);
/*
* Set the policy file to represent a FILE.
* Subsequent operations using the policy file will read and write
* to the FILE.
*/
extern void sepol_policy_file_set_fp(sepol_policy_file_t * pf, FILE * fp);
/*
* Associate a handle with a policy file, for use in
* error reporting from subsequent calls that take the
* policy file as an argument.
*/
extern void sepol_policy_file_set_handle(sepol_policy_file_t * pf,
sepol_handle_t * handle);
/* Policydb public interfaces. */
/* Create and free memory associated with a policydb. */
extern int sepol_policydb_create(sepol_policydb_t ** p);
extern void sepol_policydb_free(sepol_policydb_t * p);
/* Legal types of policies that the policydb can represent. */
#define SEPOL_POLICY_KERN 0
#define SEPOL_POLICY_BASE 1
#define SEPOL_POLICY_MOD 2
/*
* Range of policy versions for the kernel policy type supported
* by this library.
*/
extern int sepol_policy_kern_vers_min(void);
extern int sepol_policy_kern_vers_max(void);
/*
* Set the policy type as specified, and automatically initialize the
* policy version accordingly to the maximum version supported for the
* policy type.
* Returns -1 if the policy type is not legal.
*/
extern int sepol_policydb_set_typevers(sepol_policydb_t * p, unsigned int type);
/*
* Set the policy version to a different value.
* Returns -1 if the policy version is not in the supported range for
* the (previously set) policy type.
*/
extern int sepol_policydb_set_vers(sepol_policydb_t * p, unsigned int vers);
/* Set how to handle unknown class/perms. */
#define SEPOL_DENY_UNKNOWN 0
#define SEPOL_REJECT_UNKNOWN 2
#define SEPOL_ALLOW_UNKNOWN 4
extern int sepol_policydb_set_handle_unknown(sepol_policydb_t * p,
unsigned int handle_unknown);
/* Set the target platform */
#define SEPOL_TARGET_SELINUX 0
#define SEPOL_TARGET_XEN 1
extern int sepol_policydb_set_target_platform(sepol_policydb_t * p,
int target_platform);
/*
* Optimize the policy by removing redundant rules.
*/
extern int sepol_policydb_optimize(sepol_policydb_t * p);
/*
* Read a policydb from a policy file.
* This automatically sets the type and version based on the
* image contents.
*/
extern int sepol_policydb_read(sepol_policydb_t * p, sepol_policy_file_t * pf);
/*
* Write a policydb to a policy file.
* The generated image will be in the binary format corresponding
* to the policy version associated with the policydb.
*/
extern int sepol_policydb_write(sepol_policydb_t * p, sepol_policy_file_t * pf);
/*
* Extract a policydb from a binary policy memory image.
* This is equivalent to sepol_policydb_read with a policy file
* set to refer to memory.
*/
extern int sepol_policydb_from_image(sepol_handle_t * handle,
void *data, size_t len,
sepol_policydb_t * p);
/*
* Generate a binary policy memory image from a policydb.
* This is equivalent to sepol_policydb_write with a policy file
* set to refer to memory, but internally handles computing the
* necessary length and allocating an appropriately sized memory
* buffer for the caller.
*/
extern int sepol_policydb_to_image(sepol_handle_t * handle,
sepol_policydb_t * p,
void **newdata, size_t * newlen);
/*
* Check whether the policydb has MLS enabled.
*/
extern int sepol_policydb_mls_enabled(const sepol_policydb_t * p);
/*
* Check whether the compatibility mode for SELinux network
* checks should be enabled when using this policy.
*/
extern int sepol_policydb_compat_net(const sepol_policydb_t * p);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/policydb/000077500000000000000000000000001476211737200177205ustar00rootroot00000000000000libsepol-3.8.1/include/sepol/policydb/avrule_block.h000066400000000000000000000031671476211737200225500ustar00rootroot00000000000000/* Authors: Jason Tang
*
* Copyright (C) 2005 Tresys Technology, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SEPOL_AVRULE_BLOCK_H_
#define _SEPOL_AVRULE_BLOCK_H_
#include
#ifdef __cplusplus
extern "C" {
#endif
extern avrule_block_t *avrule_block_create(void);
extern void avrule_block_destroy(avrule_block_t * x);
extern avrule_decl_t *avrule_decl_create(uint32_t decl_id);
extern void avrule_decl_destroy(avrule_decl_t * x);
extern void avrule_block_list_destroy(avrule_block_t * x);
extern avrule_decl_t *get_avrule_decl(policydb_t * p, uint32_t decl_id);
extern cond_list_t *get_decl_cond_list(policydb_t * p,
avrule_decl_t * decl,
cond_list_t * cond);
extern int is_id_enabled(const char *id, const policydb_t * p, int symbol_table);
extern int is_perm_existent(const class_datum_t *cladatum, const char *perm_id);
#ifdef __cplusplus
}
#endif
#endif
libsepol-3.8.1/include/sepol/policydb/avtab.h000066400000000000000000000112721476211737200211710ustar00rootroot00000000000000
/* Author : Stephen Smalley, */
/*
* Updated: Yuichi Nakamura
* Tuned number of hash slots for avtab to reduce memory usage
*/
/* Updated: Frank Mayer and Karl MacMillan
*
* Added conditional policy language extensions
*
* Copyright (C) 2003 Tresys Technology, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* FLASK */
/*
* An access vector table (avtab) is a hash table
* of access vectors and transition types indexed
* by a type pair and a class. An access vector
* table is used to represent the type enforcement
* tables.
*/
#ifndef _SEPOL_POLICYDB_AVTAB_H_
#define _SEPOL_POLICYDB_AVTAB_H_
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
typedef struct avtab_key {
uint16_t source_type;
uint16_t target_type;
uint16_t target_class;
#define AVTAB_ALLOWED 0x0001
#define AVTAB_AUDITALLOW 0x0002
#define AVTAB_AUDITDENY 0x0004
#define AVTAB_NEVERALLOW 0x0080
#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
#define AVTAB_TRANSITION 0x0010
#define AVTAB_MEMBER 0x0020
#define AVTAB_CHANGE 0x0040
#define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
#define AVTAB_XPERMS_ALLOWED 0x0100
#define AVTAB_XPERMS_AUDITALLOW 0x0200
#define AVTAB_XPERMS_DONTAUDIT 0x0400
#define AVTAB_XPERMS_NEVERALLOW 0x0800
#define AVTAB_XPERMS (AVTAB_XPERMS_ALLOWED | AVTAB_XPERMS_AUDITALLOW | AVTAB_XPERMS_DONTAUDIT)
#define AVTAB_ENABLED_OLD 0x80000000
#define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
uint16_t specified; /* what fields are specified */
} avtab_key_t;
typedef struct avtab_extended_perms {
#define AVTAB_XPERMS_IOCTLFUNCTION 0x01
#define AVTAB_XPERMS_IOCTLDRIVER 0x02
#define AVTAB_XPERMS_NLMSG 0x03
/* extension of the avtab_key specified */
uint8_t specified;
uint8_t driver;
uint32_t perms[8];
} avtab_extended_perms_t;
typedef struct avtab_datum {
uint32_t data; /* access vector or type */
avtab_extended_perms_t *xperms;
} avtab_datum_t;
typedef struct avtab_node *avtab_ptr_t;
struct avtab_node {
avtab_key_t key;
avtab_datum_t datum;
avtab_ptr_t next;
void *parse_context; /* generic context pointer used by parser;
* not saved in binary policy */
unsigned merged; /* flag for avtab_write only;
not saved in binary policy */
};
typedef struct avtab {
avtab_ptr_t *htable;
uint32_t nel; /* number of elements */
uint32_t nslot; /* number of hash slots */
uint32_t mask; /* mask to compute hash func */
} avtab_t;
extern int avtab_init(avtab_t *);
extern int avtab_alloc(avtab_t *, uint32_t);
extern int avtab_insert(avtab_t * h, avtab_key_t * k, avtab_datum_t * d);
extern avtab_datum_t *avtab_search(avtab_t * h, avtab_key_t * k);
extern void avtab_destroy(avtab_t * h);
extern int avtab_map(const avtab_t * h,
int (*apply) (avtab_key_t * k,
avtab_datum_t * d, void *args), void *args);
extern void avtab_hash_eval(avtab_t * h, char *tag);
struct policy_file;
extern int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
int (*insert) (avtab_t * a, avtab_key_t * k,
avtab_datum_t * d, void *p), void *p);
extern int avtab_read(avtab_t * a, struct policy_file *fp, uint32_t vers);
extern avtab_ptr_t avtab_insert_nonunique(avtab_t * h, avtab_key_t * key,
avtab_datum_t * datum);
extern avtab_ptr_t avtab_insert_with_parse_context(avtab_t * h,
avtab_key_t * key,
avtab_datum_t * datum,
void *parse_context);
extern avtab_ptr_t avtab_search_node(avtab_t * h, avtab_key_t * key);
extern avtab_ptr_t avtab_search_node_next(avtab_ptr_t node, int specified);
#define MAX_AVTAB_HASH_BITS 20
#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
#define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1)
/* avtab_alloc uses one bucket per 2-4 elements, so adjust to get maximum buckets */
#define MAX_AVTAB_SIZE (MAX_AVTAB_HASH_BUCKETS << 1)
#ifdef __cplusplus
}
#endif
#endif /* _AVTAB_H_ */
/* FLASK */
libsepol-3.8.1/include/sepol/policydb/conditional.h000066400000000000000000000113651476211737200224020ustar00rootroot00000000000000/* Authors: Karl MacMillan
* Frank Mayer