poldiff.h File Reference


Detailed Description

Public interface for computing semantic policy differences between two policies.

The user loads two policies, the "original" and "modified" policies, and then calls poldiff_create() to obtain a poldiff object. Next call poldiff_run() to actually execute the differencing algorithm. Results are retrieved via poldiff_get_type_vector(), poldiff_get_avrule_vector(), and so forth.

Author:
Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Copyright (C) 2006-2007 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

Definition in file poldiff.h.

#include <apol/policy.h>
#include <apol/policy-query.h>
#include <apol/vector.h>
#include <stdarg.h>
#include <stdint.h>
#include <poldiff/attrib_diff.h>
#include <poldiff/avrule_diff.h>
#include <poldiff/cat_diff.h>
#include <poldiff/bool_diff.h>
#include <poldiff/class_diff.h>
#include <poldiff/level_diff.h>
#include <poldiff/range_diff.h>
#include <poldiff/range_trans_diff.h>
#include <poldiff/rbac_diff.h>
#include <poldiff/role_diff.h>
#include <poldiff/terule_diff.h>
#include <poldiff/type_diff.h>
#include <poldiff/user_diff.h>
#include <poldiff/type_map.h>
#include <poldiff/util.h>

Go to the source code of this file.


Defines

#define POLDIFF_DIFF_CLASSES   0x00000001U
#define POLDIFF_DIFF_COMMONS   0x00000002U
#define POLDIFF_DIFF_TYPES   0x00000004U
#define POLDIFF_DIFF_ATTRIBS   0x00000008U
#define POLDIFF_DIFF_ROLES   0x00000010U
#define POLDIFF_DIFF_USERS   0x00000020U
#define POLDIFF_DIFF_BOOLS   0x00000040U
#define POLDIFF_DIFF_LEVELS   0x00000080U
#define POLDIFF_DIFF_CATS   0x00000100U
#define POLDIFF_DIFF_ROLE_ALLOWS   0x00000800U
#define POLDIFF_DIFF_ROLE_TRANS   0x00001000U
#define POLDIFF_DIFF_RANGE_TRANS   0x00002000U
#define POLDIFF_DIFF_AVALLOW   0x10000000U
#define POLDIFF_DIFF_AVAUDITALLOW   0x20000000U
#define POLDIFF_DIFF_AVDONTAUDIT   0x40000000U
#define POLDIFF_DIFF_AVNEVERALLOW   0x80000000U
#define POLDIFF_DIFF_TECHANGE   0x01000000U
#define POLDIFF_DIFF_TEMEMBER   0x02000000U
#define POLDIFF_DIFF_TETRANS   0x04000000U
#define POLDIFF_DIFF_TERULES_COMPAT   0x00000400U
 deprecated
#define POLDIFF_DIFF_AVRULES_COMPAT   0x00000200U
 deprecated
#define POLDIFF_DIFF_AVRULES   (POLDIFF_DIFF_AVALLOW | POLDIFF_DIFF_AVNEVERALLOW | POLDIFF_DIFF_AVAUDITALLOW | POLDIFF_DIFF_AVDONTAUDIT)
#define POLDIFF_DIFF_TERULES   (POLDIFF_DIFF_TEMEMBER | POLDIFF_DIFF_TECHANGE | POLDIFF_DIFF_TETRANS)
#define POLDIFF_DIFF_SYMBOLS   (POLDIFF_DIFF_CLASSES|POLDIFF_DIFF_COMMONS|POLDIFF_DIFF_TYPES|POLDIFF_DIFF_ATTRIBS|POLDIFF_DIFF_ROLES|POLDIFF_DIFF_USERS|POLDIFF_DIFF_BOOLS)
#define POLDIFF_DIFF_RULES   (POLDIFF_DIFF_AVRULES|POLDIFF_DIFF_TERULES|POLDIFF_DIFF_ROLE_ALLOWS|POLDIFF_DIFF_ROLE_TRANS)
#define POLDIFF_DIFF_RBAC   (POLDIFF_DIFF_ROLES|POLDIFF_DIFF_ROLE_ALLOWS|POLDIFF_DIFF_ROLE_TRANS)
#define POLDIFF_DIFF_MLS   (POLDIFF_DIFF_LEVELS|POLDIFF_DIFF_CATS|POLDIFF_DIFF_RANGE_TRANS)
#define POLDIFF_DIFF_OCONS   0
#define POLDIFF_DIFF_REMAPPED   (POLDIFF_DIFF_TYPES|POLDIFF_DIFF_ATTRIBS|POLDIFF_DIFF_AVRULES|POLDIFF_DIFF_TERULES|POLDIFF_DIFF_ROLES|POLDIFF_DIFF_ROLE_TRANS|POLDIFF_DIFF_RANGE_TRANS|POLDIFF_DIFF_OCONS)
#define POLDIFF_DIFF_ALL   (POLDIFF_DIFF_SYMBOLS|POLDIFF_DIFF_RULES|POLDIFF_DIFF_MLS|POLDIFF_DIFF_OCONS)

Typedefs

typedef poldiff poldiff_t
typedef enum poldiff_form poldiff_form_e
 Form of a difference.
typedef void(* poldiff_handle_fn_t )(void *arg, const poldiff_t *diff, int level, const char *fmt, va_list va_args)

Enumerations

enum  poldiff_form {
  POLDIFF_FORM_NONE, POLDIFF_FORM_ADDED, POLDIFF_FORM_REMOVED, POLDIFF_FORM_MODIFIED,
  POLDIFF_FORM_ADD_TYPE, POLDIFF_FORM_REMOVE_TYPE
}
 Form of a difference. More...

Functions

poldiff_tpoldiff_create (apol_policy_t *orig_policy, apol_policy_t *mod_policy, poldiff_handle_fn_t fn, void *callback_arg)
 Allocate and initialize a new policy difference structure.
void poldiff_destroy (poldiff_t **diff)
 Free all memory used by a policy difference structure and set it to NULL.
int poldiff_run (poldiff_t *diff, uint32_t flags)
 Run the difference algorithm for the selected policy components/rules.
int poldiff_is_run (const poldiff_t *diff, uint32_t flags)
 Determine if a particular policy component/rule diff was actually run yet or not.
int poldiff_get_stats (const poldiff_t *diff, uint32_t flags, size_t stats[5])
 Get a total of the differences of each form for a given item (or set of items).
int poldiff_enable_line_numbers (poldiff_t *diff)
 Enable line numbers for all rule differences.

Define Documentation

#define POLDIFF_DIFF_CLASSES   0x00000001U
 

Definition at line 92 of file poldiff.h.

Referenced by main(), print_class_diffs(), and print_diff().

#define POLDIFF_DIFF_COMMONS   0x00000002U
 

Definition at line 93 of file poldiff.h.

Referenced by print_common_diffs(), and print_diff().

#define POLDIFF_DIFF_TYPES   0x00000004U
 

Definition at line 94 of file poldiff.h.

Referenced by print_diff(), and print_type_diffs().

#define POLDIFF_DIFF_ATTRIBS   0x00000008U
 

Definition at line 95 of file poldiff.h.

Referenced by print_attrib_diffs(), and print_diff().

#define POLDIFF_DIFF_ROLES   0x00000010U
 

Definition at line 96 of file poldiff.h.

Referenced by print_diff(), and print_role_diffs().

#define POLDIFF_DIFF_USERS   0x00000020U
 

Definition at line 97 of file poldiff.h.

Referenced by print_diff(), and print_user_diffs().

#define POLDIFF_DIFF_BOOLS   0x00000040U
 

Definition at line 98 of file poldiff.h.

Referenced by print_bool_diffs(), and print_diff().

#define POLDIFF_DIFF_LEVELS   0x00000080U
 

Definition at line 99 of file poldiff.h.

Referenced by print_diff(), and print_level_diffs().

#define POLDIFF_DIFF_CATS   0x00000100U
 

Definition at line 100 of file poldiff.h.

Referenced by print_cat_diffs(), and print_diff().

#define POLDIFF_DIFF_ROLE_ALLOWS   0x00000800U
 

Definition at line 101 of file poldiff.h.

Referenced by print_diff(), and print_role_allow_diffs().

#define POLDIFF_DIFF_ROLE_TRANS   0x00001000U
 

Definition at line 102 of file poldiff.h.

Referenced by print_diff(), and print_role_trans_diffs().

#define POLDIFF_DIFF_RANGE_TRANS   0x00002000U
 

Definition at line 103 of file poldiff.h.

Referenced by print_diff(), and print_range_trans_diffs().

#define POLDIFF_DIFF_AVALLOW   0x10000000U
 

Definition at line 104 of file poldiff.h.

Referenced by print_avallow_diffs(), print_diff(), and result_item_create_avrules_allow().

#define POLDIFF_DIFF_AVAUDITALLOW   0x20000000U
 

Definition at line 105 of file poldiff.h.

Referenced by print_avauditallow_diffs(), print_diff(), and result_item_create_avrules_auditallow().

#define POLDIFF_DIFF_AVDONTAUDIT   0x40000000U
 

Definition at line 106 of file poldiff.h.

Referenced by print_avdontaudit_diffs(), print_diff(), and result_item_create_avrules_dontaudit().

#define POLDIFF_DIFF_AVNEVERALLOW   0x80000000U
 

Definition at line 107 of file poldiff.h.

Referenced by print_avneverallow_diffs(), print_diff(), and result_item_create_avrules_neverallow().

#define POLDIFF_DIFF_TECHANGE   0x01000000U
 

Definition at line 108 of file poldiff.h.

Referenced by print_diff(), and result_item_create_terules_change().

#define POLDIFF_DIFF_TEMEMBER   0x02000000U
 

Definition at line 109 of file poldiff.h.

Referenced by print_diff(), and result_item_create_terules_member().

#define POLDIFF_DIFF_TETRANS   0x04000000U
 

Definition at line 110 of file poldiff.h.

Referenced by print_diff(), and result_item_create_terules_trans().

#define POLDIFF_DIFF_TERULES_COMPAT   0x00000400U
 

deprecated

Definition at line 112 of file poldiff.h.

#define POLDIFF_DIFF_AVRULES_COMPAT   0x00000200U
 

deprecated

Definition at line 113 of file poldiff.h.

#define POLDIFF_DIFF_AVRULES   (POLDIFF_DIFF_AVALLOW | POLDIFF_DIFF_AVNEVERALLOW | POLDIFF_DIFF_AVAUDITALLOW | POLDIFF_DIFF_AVDONTAUDIT)
 

Definition at line 115 of file poldiff.h.

Referenced by poldiff_run(), result_item_inline_link_event(), and toplevel_run_diff_runner().

#define POLDIFF_DIFF_TERULES   (POLDIFF_DIFF_TEMEMBER | POLDIFF_DIFF_TECHANGE | POLDIFF_DIFF_TETRANS)
 

Definition at line 116 of file poldiff.h.

#define POLDIFF_DIFF_SYMBOLS   (POLDIFF_DIFF_CLASSES|POLDIFF_DIFF_COMMONS|POLDIFF_DIFF_TYPES|POLDIFF_DIFF_ATTRIBS|POLDIFF_DIFF_ROLES|POLDIFF_DIFF_USERS|POLDIFF_DIFF_BOOLS)
 

Definition at line 121 of file poldiff.h.

#define POLDIFF_DIFF_RULES   (POLDIFF_DIFF_AVRULES|POLDIFF_DIFF_TERULES|POLDIFF_DIFF_ROLE_ALLOWS|POLDIFF_DIFF_ROLE_TRANS)
 

Definition at line 122 of file poldiff.h.

#define POLDIFF_DIFF_RBAC   (POLDIFF_DIFF_ROLES|POLDIFF_DIFF_ROLE_ALLOWS|POLDIFF_DIFF_ROLE_TRANS)
 

Definition at line 123 of file poldiff.h.

#define POLDIFF_DIFF_MLS   (POLDIFF_DIFF_LEVELS|POLDIFF_DIFF_CATS|POLDIFF_DIFF_RANGE_TRANS)
 

Definition at line 124 of file poldiff.h.

#define POLDIFF_DIFF_OCONS   0
 

Definition at line 125 of file poldiff.h.

#define POLDIFF_DIFF_REMAPPED   (POLDIFF_DIFF_TYPES|POLDIFF_DIFF_ATTRIBS|POLDIFF_DIFF_AVRULES|POLDIFF_DIFF_TERULES|POLDIFF_DIFF_ROLES|POLDIFF_DIFF_ROLE_TRANS|POLDIFF_DIFF_RANGE_TRANS|POLDIFF_DIFF_OCONS)
 

Definition at line 126 of file poldiff.h.

#define POLDIFF_DIFF_ALL   (POLDIFF_DIFF_SYMBOLS|POLDIFF_DIFF_RULES|POLDIFF_DIFF_MLS|POLDIFF_DIFF_OCONS)
 

Definition at line 127 of file poldiff.h.

Referenced by main().


Typedef Documentation

typedef struct poldiff poldiff_t
 

Definition at line 45 of file poldiff.h.

Referenced by attrib_comp(), attrib_deep_diff(), attrib_get_items(), attrib_get_types(), attrib_new_diff(), attrib_reset(), avrule_add_to_bst(), avrule_build_cond(), avrule_comp(), avrule_deep_diff(), avrule_deep_diff_allow(), avrule_deep_diff_auditallow(), avrule_deep_diff_dontaudit(), avrule_deep_diff_neverallow(), avrule_enable_line_numbers(), avrule_expand(), avrule_get_items(), avrule_get_items_allow(), avrule_get_items_auditallow(), avrule_get_items_dontaudit(), avrule_get_items_neverallow(), avrule_get_line_numbers_for_perm(), avrule_new_diff(), avrule_new_diff_allow(), avrule_new_diff_auditallow(), avrule_new_diff_dontaudit(), avrule_new_diff_neverallow(), avrule_reset(), avrule_reset_allow(), avrule_reset_auditallow(), avrule_reset_dontaudit(), avrule_reset_neverallow(), bool_comp(), bool_deep_diff(), bool_get_items(), bool_new_diff(), bool_reset(), cat_comp(), cat_deep_diff(), cat_get_items(), cat_new_diff(), cat_reset(), class_comp(), class_deep_diff(), class_get_items(), class_get_perms(), class_new_diff(), class_reset(), common_comp(), common_deep_diff(), common_get_items(), common_get_perms(), common_new_diff(), common_reset(), get_diff_total(), init_poldiff(), level_comp(), level_deep_diff(), level_deep_diff_apol_mls_levels(), level_deep_diff_cats(), level_get_cats(), level_get_items(), level_new_diff(), level_reset(), main(), make_avdiff(), make_common_diff(), make_diff(), make_ra_diff(), make_range_trans_diff(), make_rt_diff(), make_tediff(), poldiff_attrib_get_stats(), poldiff_attrib_to_string(), poldiff_avrule_get_cond(), poldiff_avrule_get_mod_line_numbers_for_perm(), poldiff_avrule_get_orig_line_numbers_for_perm(), poldiff_avrule_get_stats(), poldiff_avrule_get_stats_allow(), poldiff_avrule_get_stats_auditallow(), poldiff_avrule_get_stats_dontaudit(), poldiff_avrule_get_stats_neverallow(), poldiff_avrule_to_string(), poldiff_bool_get_stats(), poldiff_bool_to_string(), poldiff_build_bsts(), poldiff_cat_get_stats(), poldiff_cat_to_string(), poldiff_class_get_stats(), poldiff_class_to_string(), poldiff_common_get_stats(), poldiff_common_to_string(), poldiff_create(), poldiff_destroy(), poldiff_do_item_diff(), poldiff_enable_line_numbers(), poldiff_get_attrib_vector(), poldiff_get_avrule_vector(), poldiff_get_avrule_vector_allow(), poldiff_get_avrule_vector_auditallow(), poldiff_get_avrule_vector_dontaudit(), poldiff_get_avrule_vector_neverallow(), poldiff_get_bool_vector(), poldiff_get_cat_vector(), poldiff_get_class_vector(), poldiff_get_common_vector(), poldiff_get_level_vector(), poldiff_get_range_trans_vector(), poldiff_get_role_allow_vector(), poldiff_get_role_trans_vector(), poldiff_get_role_vector(), poldiff_get_stats(), poldiff_get_terule_vector(), poldiff_get_terule_vector_change(), poldiff_get_terule_vector_member(), poldiff_get_terule_vector_trans(), poldiff_get_type_vector(), poldiff_get_user_vector(), poldiff_handle_default_callback(), poldiff_handle_msg(), poldiff_is_run(), poldiff_level_get_stats(), poldiff_level_to_string(), poldiff_level_to_string_brief(), poldiff_range_to_string_brief(), poldiff_range_trans_get_stats(), poldiff_range_trans_to_string(), poldiff_role_allow_get_stats(), poldiff_role_allow_to_string(), poldiff_role_get_stats(), poldiff_role_to_string(), poldiff_role_trans_get_stats(), poldiff_role_trans_to_string(), poldiff_run(), poldiff_terule_get_cond(), poldiff_terule_get_stats(), poldiff_terule_get_stats_change(), poldiff_terule_get_stats_member(), poldiff_terule_get_stats_trans(), poldiff_terule_to_string(), poldiff_type_get_stats(), poldiff_type_remap_create(), poldiff_type_remap_entry_create(), poldiff_type_remap_entry_get_modified_types(), poldiff_type_remap_entry_get_original_types(), poldiff_type_remap_entry_remove(), poldiff_type_remap_flush(), poldiff_type_remap_get_entries(), poldiff_type_to_string(), poldiff_user_get_stats(), poldiff_user_to_string(), print_attrib_diffs(), print_avallow_diffs(), print_avauditallow_diffs(), print_avdontaudit_diffs(), print_avneverallow_diffs(), print_bool_diffs(), print_cat_diffs(), print_class_diffs(), print_common_diffs(), print_diff(), print_level_diffs(), print_range_trans_diffs(), print_role_allow_diffs(), print_role_diffs(), print_role_trans_diffs(), print_rule_diffs(), print_rule_section(), print_type_diffs(), print_user_diffs(), progress_poldiff_handle_func(), pseudo_range_trans_comp(), pseudo_role_trans_comp(), range_comp(), range_create(), range_deep_diff(), range_trans_comp(), range_trans_deep_diff(), range_trans_get_items(), range_trans_new_diff(), range_trans_reset(), result_item_get_diff(), result_item_multi_poldiff_run(), result_item_poldiff_run(), result_item_print_modified_range(), result_item_single_poldiff_run(), results_update(), role_allow_comp(), role_allow_deep_diff(), role_allow_get_items(), role_allow_new_diff(), role_allow_reset(), role_comp(), role_deep_diff(), role_get_items(), role_get_types(), role_new_diff(), role_reset(), role_trans_comp(), role_trans_deep_diff(), role_trans_get_items(), role_trans_new_diff(), role_trans_reset(), sediffx_get_poldiff(), terule_add_to_bst(), terule_bst_comp(), terule_build_cond(), terule_comp(), terule_deep_diff(), terule_deep_diff_change(), terule_deep_diff_member(), terule_deep_diff_trans(), terule_enable_line_numbers(), terule_expand(), terule_get_items(), terule_get_items_change(), terule_get_items_member(), terule_get_items_trans(), terule_new_diff(), terule_new_diff_change(), terule_new_diff_member(), terule_new_diff_trans(), terule_reset(), terule_reset_change(), terule_reset_member(), terule_reset_trans(), toplevel_get_poldiff(), toplevel_run_diff_runner(), type_comp(), type_deep_diff(), type_get_attrib_names(), type_get_items(), type_get_name(), type_map_build(), type_map_dump(), type_map_entry_append_qtypes(), type_map_get_name(), type_map_infer(), type_map_lookup(), type_map_lookup_reverse(), type_map_prim_alias_comp(), type_map_prim_aliases_comp(), type_map_primary_comp(), type_new_diff(), type_remap_vector_dump(), type_reset(), user_comp(), user_deep_diff(), user_deep_diff_default_levels(), user_deep_diff_ranges(), user_deep_diff_roles(), user_get_items(), user_get_roles(), user_new_diff(), user_reset(), and user_to_modified_string().

typedef enum poldiff_form poldiff_form_e
 

Form of a difference.

This enumeration describes the kind of change in a policy component or rule from policy1 to policy2. Differences can be additions (item present only in policy2), removals (item present only in policy1) or a modification (item present in both policies with different semantic meaning). For rules there are two more options - added or removed due to a type being added or removed; these forms differentiate these cases from those of added/removed rules where the types exist in both policies.

Referenced by build_avrule_vecs(), build_category_vecs(), build_level_vecs(), build_rangetrans_vecs(), build_roleallow_vecs(), build_roletrans_vecs(), build_terule_vecs(), build_user_vecs(), mls_user_to_string(), modified_mls_range_to_string(), poldiff_attrib_get_form(), poldiff_avrule_get_form(), poldiff_bool_get_form(), poldiff_cat_get_form(), poldiff_class_get_form(), poldiff_common_get_form(), poldiff_level_get_form(), poldiff_range_trans_get_form(), poldiff_role_allow_get_form(), poldiff_role_get_form(), poldiff_role_trans_get_form(), poldiff_terule_get_form(), poldiff_type_get_form(), poldiff_user_get_form(), result_item_get_form(), result_item_inline_link_event(), results_sort(), and results_switch_to_page().

typedef void(* poldiff_handle_fn_t)(void *arg, const poldiff_t *diff, int level, const char *fmt, va_list va_args)
 

Definition at line 73 of file poldiff.h.


Enumeration Type Documentation

enum poldiff_form
 

Form of a difference.

This enumeration describes the kind of change in a policy component or rule from policy1 to policy2. Differences can be additions (item present only in policy2), removals (item present only in policy1) or a modification (item present in both policies with different semantic meaning). For rules there are two more options - added or removed due to a type being added or removed; these forms differentiate these cases from those of added/removed rules where the types exist in both policies.

Enumeration values:
POLDIFF_FORM_NONE  only for error conditions
POLDIFF_FORM_ADDED  item was added - only in policy 2
POLDIFF_FORM_REMOVED  item was removed - only in policy 1
POLDIFF_FORM_MODIFIED  item was modified - in both policies but with different meaning
POLDIFF_FORM_ADD_TYPE  item was added due to an added type - for rules only
POLDIFF_FORM_REMOVE_TYPE  item was removed due to a removed type - for rules only

Definition at line 57 of file poldiff.h.

00058         {
00059         /** only for error conditions */
00060                 POLDIFF_FORM_NONE,
00061         /** item was added - only in policy 2 */
00062                 POLDIFF_FORM_ADDED,
00063         /** item was removed - only in policy 1 */
00064                 POLDIFF_FORM_REMOVED,
00065         /** item was modified - in both policies but with different meaning */
00066                 POLDIFF_FORM_MODIFIED,
00067         /** item was added due to an added type - for rules only */
00068                 POLDIFF_FORM_ADD_TYPE,
00069         /** item was removed due to a removed type - for rules only */
00070                 POLDIFF_FORM_REMOVE_TYPE
00071         } poldiff_form_e;


Function Documentation

poldiff_t* poldiff_create apol_policy_t orig_policy,
apol_policy_t mod_policy,
poldiff_handle_fn_t  fn,
void *  callback_arg
 

Allocate and initialize a new policy difference structure.

This function takes ownership of the supplied policies and will handle their destruction upon poldiff_destroy(). The poldiff object will be responsible for rebuilding the policy (such as if neverallows are requested). It is still safe to access elements within the policies, but avoid making changes to the policy while the poldiff object still exists.

Parameters:
orig_policy The original policy.
mod_policy The new (modified) policy.
fn Function to be called by the error handler. If NULL then write messages to standard error.
callback_arg Argument for the callback.
Returns:
a newly allocated and initialized difference structure or NULL on error; if the call fails, errno will be set. The caller is responsible for calling poldiff_destroy() to free memory used by this structure.

Definition at line 319 of file poldiff.c.

References apol_policy_get_qpol(), apol_policy_t, poldiff::attrib_diffs, attrib_summary_create(), avrule_create(), poldiff::avrule_diffs, bool_create(), poldiff::bool_diffs, cat_create(), poldiff::cat_diffs, class_create(), poldiff::class_diffs, common_create(), poldiff::common_diffs, diff, ERR, poldiff::fn, poldiff::handle_arg, level_create(), poldiff::level_diffs, poldiff::mod_pol, poldiff::mod_qpol, poldiff::orig_pol, orig_policy, poldiff::orig_qpol, poldiff_destroy(), poldiff_t, poldiff::policy_opts, QPOL_POLICY_OPTION_NO_RULES, range_trans_create(), poldiff::range_trans_diffs, role_allow_create(), poldiff::role_allow_diffs, role_create(), poldiff::role_diffs, role_trans_create(), poldiff::role_trans_diffs, terule_create(), poldiff::terule_diffs, poldiff::type_diffs, poldiff::type_map, type_map_create(), type_map_infer(), type_summary_create(), user_create(), and poldiff::user_diffs.

Referenced by init_poldiff(), main(), and sediffx_get_poldiff().

00320 {
00321         poldiff_t *diff = NULL;
00322         int error;
00323 
00324         if (!orig_policy || !mod_policy) {
00325                 ERR(NULL, "%s", strerror(EINVAL));
00326                 errno = EINVAL;
00327                 return NULL;
00328         }
00329 
00330         if (!(diff = calloc(1, sizeof(poldiff_t)))) {
00331                 ERR(NULL, "%s", strerror(ENOMEM));
00332                 errno = ENOMEM;
00333                 return NULL;
00334         }
00335         diff->orig_pol = orig_policy;
00336         diff->mod_pol = mod_policy;
00337         diff->orig_qpol = apol_policy_get_qpol(diff->orig_pol);
00338         diff->mod_qpol = apol_policy_get_qpol(diff->mod_pol);
00339         diff->fn = fn;
00340         diff->handle_arg = callback_arg;
00341         if ((diff->type_map = type_map_create()) == NULL) {
00342                 ERR(diff, "%s", strerror(ENOMEM));
00343                 poldiff_destroy(&diff);
00344                 errno = ENOMEM;
00345                 return NULL;
00346         }
00347         if (type_map_infer(diff) < 0) {
00348                 error = errno;
00349                 poldiff_destroy(&diff);
00350                 errno = error;
00351                 return NULL;
00352         }
00353 
00354         if ((diff->attrib_diffs = attrib_summary_create()) == NULL ||
00355             (diff->avrule_diffs[AVRULE_OFFSET_ALLOW] = avrule_create()) == NULL ||
00356             (diff->avrule_diffs[AVRULE_OFFSET_AUDITALLOW] = avrule_create()) == NULL ||
00357             (diff->avrule_diffs[AVRULE_OFFSET_DONTAUDIT] = avrule_create()) == NULL ||
00358             (diff->avrule_diffs[AVRULE_OFFSET_NEVERALLOW] = avrule_create()) == NULL ||
00359             (diff->bool_diffs = bool_create()) == NULL ||
00360             (diff->cat_diffs = cat_create()) == NULL ||
00361             (diff->class_diffs = class_create()) == NULL ||
00362             (diff->common_diffs = common_create()) == NULL ||
00363             (diff->level_diffs = level_create()) == NULL ||
00364             (diff->range_trans_diffs = range_trans_create()) == NULL ||
00365             (diff->role_diffs = role_create()) == NULL ||
00366             (diff->role_allow_diffs = role_allow_create()) == NULL ||
00367             (diff->role_trans_diffs = role_trans_create()) == NULL ||
00368             (diff->terule_diffs[TERULE_OFFSET_CHANGE] = terule_create()) == NULL ||
00369             (diff->terule_diffs[TERULE_OFFSET_MEMBER] = terule_create()) == NULL ||
00370             (diff->terule_diffs[TERULE_OFFSET_TRANS] = terule_create()) == NULL ||
00371             (diff->type_diffs = type_summary_create()) == NULL || (diff->user_diffs = user_create()) == NULL) {
00372                 ERR(diff, "%s", strerror(ENOMEM));
00373                 poldiff_destroy(&diff);
00374                 errno = ENOMEM;
00375                 return NULL;
00376         }
00377 
00378         diff->policy_opts = QPOL_POLICY_OPTION_NO_RULES | QPOL_POLICY_OPTION_NO_NEVERALLOWS;
00379         return diff;
00380 }

void poldiff_destroy poldiff_t **  diff  ) 
 

Free all memory used by a policy difference structure and set it to NULL.

Parameters:
diff Reference pointer to the difference structure to destroy. This pointer will be set to NULL. (If already NULL, function is a no-op.)

Definition at line 382 of file poldiff.c.

References apol_bst_destroy(), apol_policy_destroy(), attrib_summary_destroy(), avrule_destroy(), AVRULE_OFFSET_ALLOW, AVRULE_OFFSET_AUDITALLOW, AVRULE_OFFSET_DONTAUDIT, AVRULE_OFFSET_NEVERALLOW, bool_destroy(), cat_destroy(), class_destroy(), common_destroy(), diff, level_destroy(), poldiff_t, range_trans_destroy(), role_allow_destroy(), role_destroy(), role_trans_destroy(), terule_destroy(), TERULE_OFFSET_CHANGE, TERULE_OFFSET_MEMBER, TERULE_OFFSET_TRANS, type_map_destroy(), type_summary_destroy(), and user_destroy().

Referenced by init_poldiff(), main(), poldiff_cleanup(), poldiff_create(), sediffx_destroy(), and sediffx_set_policy().

00383 {
00384         if (!diff || !(*diff))
00385                 return;
00386         apol_policy_destroy(&(*diff)->orig_pol);
00387         apol_policy_destroy(&(*diff)->mod_pol);
00388         apol_bst_destroy(&(*diff)->class_bst);
00389         apol_bst_destroy(&(*diff)->perm_bst);
00390         apol_bst_destroy(&(*diff)->bool_bst);
00391 
00392         type_map_destroy(&(*diff)->type_map);
00393         attrib_summary_destroy(&(*diff)->attrib_diffs);
00394         avrule_destroy(&(*diff)->avrule_diffs[AVRULE_OFFSET_ALLOW]);
00395         avrule_destroy(&(*diff)->avrule_diffs[AVRULE_OFFSET_AUDITALLOW]);
00396         avrule_destroy(&(*diff)->avrule_diffs[AVRULE_OFFSET_DONTAUDIT]);
00397         avrule_destroy(&(*diff)->avrule_diffs[AVRULE_OFFSET_NEVERALLOW]);
00398         bool_destroy(&(*diff)->bool_diffs);
00399         cat_destroy(&(*diff)->cat_diffs);
00400         class_destroy(&(*diff)->class_diffs);
00401         common_destroy(&(*diff)->common_diffs);
00402         level_destroy(&(*diff)->level_diffs);
00403         range_trans_destroy(&(*diff)->range_trans_diffs);
00404         role_destroy(&(*diff)->role_diffs);
00405         role_allow_destroy(&(*diff)->role_allow_diffs);
00406         role_trans_destroy(&(*diff)->role_trans_diffs);
00407         user_destroy(&(*diff)->user_diffs);
00408         terule_destroy(&(*diff)->terule_diffs[TERULE_OFFSET_CHANGE]);
00409         terule_destroy(&(*diff)->terule_diffs[TERULE_OFFSET_MEMBER]);
00410         terule_destroy(&(*diff)->terule_diffs[TERULE_OFFSET_TRANS]);
00411         type_summary_destroy(&(*diff)->type_diffs);
00412         free(*diff);
00413         *diff = NULL;
00414 }

int poldiff_run poldiff_t diff,
uint32_t  flags
 

Run the difference algorithm for the selected policy components/rules.

Parameters:
diff The policy difference structure for which to compute the differences.
flags Bit-wise or'd set of POLDIFF_DIFF_* from above indicating the components and rules for which to compute the difference. If an item has already been computed the flag for that item is ignored.
Returns:
0 on success or < 0 on error; if the call fails, errno will be set and the only defined operation on the difference structure is poldiff_destroy().

Definition at line 513 of file poldiff.c.

References component_records, diff, poldiff::diff_status, ERR, poldiff_component_record::flag_bit, INFO, poldiff::line_numbers_enabled, poldiff::mod_qpol, poldiff::orig_qpol, poldiff_component_record_t, POLDIFF_DIFF_AVRULES, poldiff_do_item_diff(), poldiff_t, poldiff::policy_opts, qpol_policy_rebuild(), poldiff::remapped, poldiff_component_record::reset, and type_map_build().

Referenced by init_poldiff(), main(), and toplevel_run_diff_runner().

00514 {
00515         size_t i, num_items;
00516 
00517         if (!flags)
00518                 return 0;              /* nothing to do */
00519 
00520         if (!diff) {
00521                 ERR(diff, "%s", strerror(EINVAL));
00522                 errno = EINVAL;
00523                 return -1;
00524         }
00525 
00526         int policy_opts = diff->policy_opts;
00527         if (flags & (POLDIFF_DIFF_AVRULES | POLDIFF_DIFF_TERULES)) {
00528                 policy_opts &= ~(QPOL_POLICY_OPTION_NO_RULES);
00529         }
00530         if (flags & POLDIFF_DIFF_AVNEVERALLOW) {
00531                 policy_opts &= ~(QPOL_POLICY_OPTION_NO_NEVERALLOWS);
00532         }
00533         if (policy_opts != diff->policy_opts) {
00534                 INFO(diff, "%s", "Loading rules from original policy.");
00535                 if (qpol_policy_rebuild(diff->orig_qpol, policy_opts)) {
00536                         return -1;
00537                 }
00538                 INFO(diff, "%s", "Loading rules from modified policy.");
00539                 if (qpol_policy_rebuild(diff->mod_qpol, policy_opts)) {
00540                         return -1;
00541                 }
00542                 // force flushing of existing pointers into policies
00543                 diff->remapped = 1;
00544                 diff->policy_opts = policy_opts;
00545         }
00546 
00547         num_items = sizeof(component_records) / sizeof(poldiff_component_record_t);
00548         if (diff->remapped) {
00549                 for (i = 0; i < num_items; i++) {
00550                         if (component_records[i].flag_bit & POLDIFF_DIFF_REMAPPED) {
00551                                 INFO(diff, "Resetting %s diff.", component_records[i].item_name);
00552                                 if (component_records[i].reset(diff))
00553                                         return -1;
00554                         }
00555                 }
00556                 diff->diff_status &= ~(POLDIFF_DIFF_REMAPPED);
00557                 diff->remapped = 0;
00558         }
00559 
00560         INFO(diff, "%s", "Building type map.");
00561         if (type_map_build(diff)) {
00562                 return -1;
00563         }
00564 
00565         diff->line_numbers_enabled = 0;
00566         for (i = 0; i < num_items; i++) {
00567                 /* item requested but not yet run */
00568                 if ((flags & component_records[i].flag_bit) && !(component_records[i].flag_bit & diff->diff_status)) {
00569                         INFO(diff, "Running %s diff.", component_records[i].item_name);
00570                         if (poldiff_do_item_diff(diff, &(component_records[i]))) {
00571                                 return -1;
00572                         }
00573                 }
00574         }
00575 
00576         return 0;
00577 }

int poldiff_is_run const poldiff_t diff,
uint32_t  flags
 

Determine if a particular policy component/rule diff was actually run yet or not.

Parameters:
diff The policy difference structure for which to compute the differences.
flags Bit-wise or'd set of POLDIFF_DIFF_* from above indicating which components/rules diffs were run.
Returns:
1 if all indicated diffs were run, 0 if any were not, < 0 on error.

Definition at line 579 of file poldiff.c.

References diff, poldiff::diff_status, ERR, and poldiff_t.

Referenced by result_item_role_trans_get_forms(), and result_item_single_get_forms().

00580 {
00581         if (!flags)
00582                 return 1;              /* nothing to do */
00583 
00584         if (!diff) {
00585                 ERR(diff, "%s", strerror(EINVAL));
00586                 errno = EINVAL;
00587                 return -1;
00588         }
00589         if ((diff->diff_status & flags) == flags) {
00590                 return 1;
00591         }
00592         return 0;
00593 }

int poldiff_get_stats const poldiff_t diff,
uint32_t  flags,
size_t  stats[5]
 

Get a total of the differences of each form for a given item (or set of items).

Parameters:
diff The policy difference structure from which to get the stats.
flags Bit-wise or'd set of POLDIFF_DIFF_* from above indicating the items for which to get the total differences. If more that one bit is set differences of the same form are totaled for all specified items.
stats Array into which to write the numbers (array must be pre-allocated). The order of the values written to the array is as follows: number of items of form POLDIFF_FORM_ADDED, number of POLDIFF_FORM_REMOVED, number of POLDIFF_FORM_MODIFIED, number of form POLDIFF_FORM_ADD_TYPE, and number of POLDIFF_FORM_REMOVE_TYPE.
Returns:
0 on success and < 0 on error; if the call fails, errno will be set.

Definition at line 595 of file poldiff.c.

References component_records, diff, ERR, poldiff_component_record::flag_bit, poldiff_component_record::get_stats, poldiff_component_record_t, and poldiff_t.

Referenced by get_diff_total(), result_item_role_trans_get_forms(), and result_item_single_get_forms().

00596 {
00597         size_t i, j, num_items, tmp_stats[5] = { 0, 0, 0, 0, 0 };
00598 
00599         if (!diff || !flags) {
00600                 ERR(diff, "%s", strerror(EINVAL));
00601                 errno = EINVAL;
00602                 return -1;
00603         }
00604 
00605         stats[0] = stats[1] = stats[2] = stats[3] = stats[4] = 0;
00606 
00607         num_items = sizeof(component_records) / sizeof(poldiff_component_record_t);
00608         for (i = 0; i < num_items; i++) {
00609                 if (flags & component_records[i].flag_bit) {
00610                         component_records[i].get_stats(diff, tmp_stats);
00611                         for (j = 0; j < 5; j++)
00612                                 stats[j] += tmp_stats[j];
00613                 }
00614         }
00615 
00616         return 0;
00617 }

int poldiff_enable_line_numbers poldiff_t diff  ) 
 

Enable line numbers for all rule differences.

If not called, line numbers will not be available when displaying differences. This function is safe to call multiple times and will have no effect after the first time. It also has no effect if one policy (or both of them) does not support line numbers. Be aware that line numbers will need to be re-enabled each time poldiff_run() is called.

Parameters:
diff The policy difference structure.
Returns:
0 on success and < 0 on failure; if the call fails, errno will be set and the difference structure should be destroyed.

Definition at line 619 of file poldiff.c.

References avrule_enable_line_numbers(), AVRULE_OFFSET_ALLOW, AVRULE_OFFSET_AUDITALLOW, AVRULE_OFFSET_DONTAUDIT, AVRULE_OFFSET_NEVERALLOW, diff, poldiff::line_numbers_enabled, poldiff::mod_qpol, poldiff::orig_qpol, poldiff_t, qpol_policy_build_syn_rule_table(), terule_enable_line_numbers(), TERULE_OFFSET_CHANGE, TERULE_OFFSET_MEMBER, and TERULE_OFFSET_TRANS.

Referenced by toplevel_run_diff_runner().

00620 {
00621         int retval;
00622         if (diff == NULL) {
00623                 errno = EINVAL;
00624                 return -1;
00625         }
00626         if (!diff->line_numbers_enabled) {
00627                 if (qpol_policy_build_syn_rule_table(diff->orig_qpol))
00628                         return -1;
00629                 if (qpol_policy_build_syn_rule_table(diff->mod_qpol))
00630                         return -1;
00631                 if ((retval = avrule_enable_line_numbers(diff, AVRULE_OFFSET_ALLOW)) < 0) {
00632                         return retval;
00633                 }
00634                 if ((retval = avrule_enable_line_numbers(diff, AVRULE_OFFSET_AUDITALLOW)) < 0) {
00635                         return retval;
00636                 }
00637                 if ((retval = avrule_enable_line_numbers(diff, AVRULE_OFFSET_DONTAUDIT)) < 0) {
00638                         return retval;
00639                 }
00640                 if ((retval = avrule_enable_line_numbers(diff, AVRULE_OFFSET_NEVERALLOW)) < 0) {
00641                         return retval;
00642                 }
00643                 if ((retval = terule_enable_line_numbers(diff, TERULE_OFFSET_CHANGE)) < 0) {
00644                         return retval;
00645                 }
00646                 if ((retval = terule_enable_line_numbers(diff, TERULE_OFFSET_MEMBER)) < 0) {
00647                         return retval;
00648                 }
00649                 if ((retval = terule_enable_line_numbers(diff, TERULE_OFFSET_TRANS)) < 0) {
00650                         return retval;
00651                 }
00652                 diff->line_numbers_enabled = 1;
00653         }
00654         return 0;
00655 }