00001 /** 00002 * @file 00003 * Public interface for computing semantic differences in te rules 00004 * (type_transition, type_change, type_member). 00005 * 00006 * @author Jeremy A. Mowery jmowery@tresys.com 00007 * @author Jason Tang jtang@tresys.com 00008 * 00009 * Copyright (C) 2006-2007 Tresys Technology, LLC 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Lesser General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2.1 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 */ 00025 00026 #ifndef POLDIFF_TERULE_DIFF_H 00027 #define POLDIFF_TERULE_DIFF_H 00028 00029 #ifdef __cplusplus 00030 extern "C" 00031 { 00032 #endif 00033 00034 #include <apol/vector.h> 00035 #include <poldiff/poldiff.h> 00036 00037 typedef struct poldiff_terule poldiff_terule_t; 00038 00039 /** 00040 * Get an array of statistics for the number of differences of each 00041 * form for TE type_change rules. 00042 * 00043 * @param diff The policy difference structure from which to get the 00044 * stats. 00045 * @param stats Array into which to write the numbers (array must be 00046 * pre-allocated). The order of the values written to the array is 00047 * as follows: number of items of form POLDIFF_FORM_ADDED, number of 00048 * POLDIFF_FORM_REMOVED, number of POLDIFF_FORM_MODIFIED, number of 00049 * POLDIFF_FORM_ADD_TYPE, and number of POLDIFF_FORM_REMOVE_TYPE. 00050 */ 00051 extern void poldiff_terule_get_stats_change(const poldiff_t * diff, size_t stats[5]); 00052 00053 /** 00054 * Get an array of statistics for the number of differences of each 00055 * form for TE type_member rules. 00056 * 00057 * @param diff The policy difference structure from which to get the 00058 * stats. 00059 * @param stats Array into which to write the numbers (array must be 00060 * pre-allocated). The order of the values written to the array is 00061 * as follows: number of items of form POLDIFF_FORM_ADDED, number of 00062 * POLDIFF_FORM_REMOVED, number of POLDIFF_FORM_MODIFIED, number of 00063 * POLDIFF_FORM_ADD_TYPE, and number of POLDIFF_FORM_REMOVE_TYPE. 00064 */ 00065 extern void poldiff_terule_get_stats_member(const poldiff_t * diff, size_t stats[5]); 00066 00067 /** 00068 * Get an array of statistics for the number of differences of each 00069 * form for TE type_transition rules. 00070 * 00071 * @param diff The policy difference structure from which to get the 00072 * stats. 00073 * @param stats Array into which to write the numbers (array must be 00074 * pre-allocated). The order of the values written to the array is 00075 * as follows: number of items of form POLDIFF_FORM_ADDED, number of 00076 * POLDIFF_FORM_REMOVED, number of POLDIFF_FORM_MODIFIED, number of 00077 * POLDIFF_FORM_ADD_TYPE, and number of POLDIFF_FORM_REMOVE_TYPE. 00078 */ 00079 extern void poldiff_terule_get_stats_trans(const poldiff_t * diff, size_t stats[5]); 00080 00081 /** 00082 * Get the vector of te rule differences from the te rule difference 00083 * summary for just type_change rules. 00084 * 00085 * @param diff The policy difference structure associated with the te 00086 * rule difference summary. 00087 * 00088 * @return A vector of elements of type poldiff_terule_t, or NULL on 00089 * error. The caller should <b>not</b> destroy the vector returned. 00090 * If the call fails, errno will be set. 00091 */ 00092 extern const apol_vector_t *poldiff_get_terule_vector_change(const poldiff_t * diff); 00093 00094 /** 00095 * Get the vector of te rule differences from the te rule difference 00096 * summary for just type_member rules. 00097 * 00098 * @param diff The policy difference structure associated with the te 00099 * rule difference summary. 00100 * 00101 * @return A vector of elements of type poldiff_terule_t, or NULL on 00102 * error. The caller should <b>not</b> destroy the vector returned. 00103 * If the call fails, errno will be set. 00104 */ 00105 extern const apol_vector_t *poldiff_get_terule_vector_member(const poldiff_t * diff); 00106 00107 /** 00108 * Get the vector of te rule differences from the te rule difference 00109 * summary for just type_transition rules. 00110 * 00111 * @param diff The policy difference structure associated with the te 00112 * rule difference summary. 00113 * 00114 * @return A vector of elements of type poldiff_terule_t, or NULL on 00115 * error. The caller should <b>not</b> destroy the vector returned. 00116 * If the call fails, errno will be set. 00117 */ 00118 extern const apol_vector_t *poldiff_get_terule_vector_trans(const poldiff_t * diff); 00119 00120 /** 00121 * Obtain a newly allocated string representation of a difference in 00122 * a te rule. 00123 * 00124 * @param diff The policy difference structure associated with the te 00125 * rule. 00126 * @param terule The te rule from which to generate the string. 00127 * 00128 * @return A string representation of te rule difference; the caller 00129 * is responsible for free()ing this string. On error, return NULL 00130 * and set errno. 00131 */ 00132 extern char *poldiff_terule_to_string(const poldiff_t * diff, const void *terule); 00133 00134 /** 00135 * Get the form of difference from a te rule diff. 00136 * 00137 * @param terule The te rule from which to get the difference form. 00138 * 00139 * @return The form of difference (one of POLDIFF_FORM_*) or 00140 * POLDIFF_FORM_NONE on error. 00141 */ 00142 extern poldiff_form_e poldiff_terule_get_form(const void *terule); 00143 00144 /** 00145 * Get the type of rule this is from a te rule diff. 00146 * 00147 * @param avrule The av rule from which to get the rule type. 00148 * 00149 * @return One of QPOL_RULE_TYPE_TRANS etc, suitable for printing via 00150 * apol_rule_type_to_str(). 00151 */ 00152 extern uint32_t poldiff_terule_get_rule_type(const poldiff_terule_t * terule); 00153 00154 /** 00155 * Get the source type from a te rule diff. 00156 * 00157 * @param terule The te rule from which to get the type. 00158 * 00159 * @return A string for the type. <b>Do not free() this string.</b> 00160 */ 00161 extern const char *poldiff_terule_get_source_type(const poldiff_terule_t * terule); 00162 00163 /** 00164 * Get the target type from a te rule diff. 00165 * 00166 * @param terule The te rule from which to get the type. 00167 * 00168 * @return A string for the type. <b>Do not free() this string.</b> 00169 */ 00170 extern const char *poldiff_terule_get_target_type(const poldiff_terule_t * terule); 00171 00172 /** 00173 * Get the object class from a te rule diff. 00174 * 00175 * @param terule The te rule from which to get the class. 00176 * 00177 * @return A string for the class. <b>Do not free() this string.</b> 00178 */ 00179 extern const char *poldiff_terule_get_object_class(const poldiff_terule_t * terule); 00180 00181 /** 00182 * Get the conditional expression from a te rule diff. Note that 00183 * this really returns a qpol_cond_t and an apol_policy_t, which may 00184 * then be used in other routines such as apol_cond_expr_render(). 00185 * 00186 * @param diff The policy difference structure from which to get the 00187 * stats. 00188 * @param terule The te rule from which to get the conditional. 00189 * @param cond Reference to the rule's conditional pointer, or NULL 00190 * if the rule is not conditional. The caller must not free() this 00191 * pointer. 00192 * @param which_list Reference to which list the rule belongs, either 00193 * 1 if in the true branch, 0 if in false. If the rule is not 00194 * conditional then this value will be set to 1. 00195 * @param p Reference to the policy from which the conditional 00196 * originated, or NULL if the rule is not conditional. The caller 00197 * must not destroy this pointer. 00198 */ 00199 extern void poldiff_terule_get_cond(const poldiff_t * diff, const poldiff_terule_t * terule, 00200 const qpol_cond_t ** cond, uint32_t * which_list, const apol_policy_t ** p); 00201 00202 /** 00203 * Get the original default type for this type rule. Note that if 00204 * this rule was added (form POLDIFF_FORM_ADDED or 00205 * POLDIFF_FORM_ADD_TYPE) then the return value will be NULL. 00206 * 00207 * @param terule The te rule diff from which to get the original 00208 * default type. 00209 * 00210 * @return Original default type. If there was no original type or 00211 * upon error then return NULL. <b>Do not free() this string.</b> 00212 */ 00213 extern const char *poldiff_terule_get_original_default(const poldiff_terule_t * terule); 00214 00215 /** 00216 * Get the modified default type for this type rule. Note that if 00217 * this rule was removed (form POLDIFF_FORM_REMOVED or 00218 * POLDIFF_FORM_REMOVE_TYPE) then the return value will be NULL. 00219 * 00220 * @param terule The te rule diff from which to get the modified 00221 * default type. 00222 * 00223 * @return Modified default type. If there was no modified type or 00224 * upon error then return NULL. <b>Do not free() this string.</b> 00225 */ 00226 extern const char *poldiff_terule_get_modified_default(const poldiff_terule_t * terule); 00227 00228 /** 00229 * Get a vector of line numbers (of type unsigned long) for this te rule 00230 * difference from the original policy. Note that if the form is 00231 * POLDIFF_FORM_ADDED or POLDIFF_FORM_ADD_TYPE then this will return NULL. 00232 * Also, if the original policy is a binary policy or line numbers are not yet 00233 * enabled then this returns NULL. 00234 * @see poldiff_enable_line_numbers() to enable line numbers. 00235 * 00236 * @param terule The te rule diff from which to get line numbers. 00237 * 00238 * @return A vector of line numbers (type unsigned long) for the rule 00239 * in the original policy, or NULL if no numbers are available. 00240 */ 00241 extern apol_vector_t *poldiff_terule_get_orig_line_numbers(const poldiff_terule_t * terule); 00242 00243 /** 00244 * Get a vector of line numbers (of type unsigned long) for this te rule 00245 * difference from the modified policy. Note that if the form is 00246 * POLDIFF_FORM_REMOVED or POLDIFF_FORM_REMOVE_TYPE then this will return 00247 * NULL. Also, if the modified policy is a binary policy or line numbers are 00248 * not yet enabled then this returns NULL. 00249 * @see poldiff_enable_line_numbers() to enable line numbers. 00250 * 00251 * @param terule The te rule diff from which to get line numbers. 00252 * 00253 * @return A vector of line numbers (type unsigned long) for the rule 00254 * in the modified policy, or NULL if no numbers are available. 00255 */ 00256 extern apol_vector_t *poldiff_terule_get_mod_line_numbers(const poldiff_terule_t * terule); 00257 00258 #ifdef __cplusplus 00259 } 00260 #endif 00261 00262 #endif /* POLDIFF_TERULE_DIFF_H */