Jason Tang jtang@tresys.com
Brandon Whalen bwhalen@tresys.com
Randy Wicks rwicks@tresys.com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Definition in file sediffx.c.
#include <config.h>
#include "sediffx.h"
#include "toplevel.h"
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <glade/glade.h>
#include <gtk/gtk.h>
Go to the source code of this file.
Classes | |
| struct | sediffx |
| struct | delayed_main_data |
Functions | |
| void | sediffx_set_policy (sediffx_t *s, sediffx_policy_e which, apol_policy_t *policy, apol_policy_path_t *path) |
| Set one of the policies for sediffx. | |
| const apol_policy_path_t * | sediffx_get_policy_path (sediffx_t *sediffx, const sediffx_policy_e which) |
| Return the policy path for the policy given. | |
| poldiff_t * | sediffx_get_poldiff (sediffx_t *s, poldiff_handle_fn_t fn, void *arg) |
| Return the currently active poldiff object. | |
| void | sediffx_set_poldiff_run_flags (sediffx_t *s, uint32_t flags) |
| Set the flags that were used to run a poldiff. | |
| uint32_t | sediffx_get_poldiff_run_flags (sediffx_t *s) |
| Get the flags that were used to run a poldiff. | |
| void | print_version_info (void) |
| void | usage (const char *program_name, int brief) |
| gboolean | delayed_main (gpointer data) |
| void | sediffx_destroy (sediffx_t **sediffx) |
| void | sediffx_parse_command_line (int argc, char **argv, apol_policy_path_t **orig_path, apol_policy_path_t **mod_path, int *run_diff) |
| int | main (int argc, char **argv) |
Variables | |
| option const | longopts [] |
|
||||||||||||||||||||
|
Set one of the policies for sediffx. This will invalidate any currently executed poldiff_t objects.
Definition at line 55 of file sediffx.c. References apol_policy_destroy(), apol_policy_path_destroy(), apol_policy_path_t, apol_policy_t, sediffx::paths, sediffx::poldiff, poldiff_destroy(), sediffx::policies, and sediffx_t. Referenced by toplevel_open_policies(). 00056 {
00057 poldiff_destroy(&s->poldiff);
00058 if (policy != NULL) {
00059 apol_policy_destroy(&s->policies[which]);
00060 s->policies[which] = policy;
00061 if (path != s->paths[which]) {
00062 apol_policy_path_destroy(&s->paths[which]);
00063 }
00064 s->paths[which] = path;
00065 } else {
00066 apol_policy_destroy(&s->policies[which]);
00067 apol_policy_path_destroy(&s->paths[which]);
00068 }
00069 }
|
|
||||||||||||
|
Return the policy path for the policy given. If the policy has not yet been loaded then return NULL.
Definition at line 71 of file sediffx.c. References apol_policy_path_t, sediffx::paths, and sediffx_t. Referenced by toplevel_on_open_activate(), toplevel_on_open_policies_button_click(), and toplevel_update_title_bar(). 00072 {
00073 return sediffx->paths[which];
00074 }
|
|
||||||||||||||||
|
Return the currently active poldiff object. If one is not yet created or if a policy has changed since the last time this function was called, then build a new one and return it. Note that this does not actually call poldiff_run(); it is up to the caller of this function to do that.
Definition at line 76 of file sediffx.c. References sediffx::poldiff, poldiff_create(), poldiff_t, sediffx::policies, SEDIFFX_POLICY_MOD, SEDIFFX_POLICY_ORIG, and sediffx_t. Referenced by toplevel_get_poldiff(), and toplevel_run_diff_runner(). 00077 {
00078 if (s->poldiff != NULL) {
00079 return s->poldiff;
00080 }
00081 if (s->policies[SEDIFFX_POLICY_ORIG] == NULL || s->policies[SEDIFFX_POLICY_MOD] == NULL) {
00082 return NULL;
00083 }
00084 s->poldiff = poldiff_create(s->policies[SEDIFFX_POLICY_ORIG], s->policies[SEDIFFX_POLICY_MOD], fn, arg);
00085 if (s->poldiff != NULL) {
00086 /* poldiff_create() took ownership of the policies */
00087 s->policies[SEDIFFX_POLICY_ORIG] = NULL;
00088 s->policies[SEDIFFX_POLICY_MOD] = NULL;
00089 }
00090 return s->poldiff;
00091 }
|
|
||||||||||||
|
Set the flags that were used to run a poldiff. This function should be called immediately proceeding a call to poldiff_run().
Definition at line 93 of file sediffx.c. References sediffx::flags, and sediffx_t. Referenced by toplevel_run_diff_runner(). 00094 {
00095 s->flags = flags;
00096 }
|
|
|
Get the flags that were used to run a poldiff.
Definition at line 98 of file sediffx.c. References sediffx::flags, and sediffx_t. Referenced by toplevel_get_poldiff_run_flags(). 00099 {
00100 return s->flags;
00101 }
|
|
|
Definition at line 103 of file sediffx.c. References COPYRIGHT_INFO. 00104 {
00105 printf("sediffx %s\n%s\n", VERSION, COPYRIGHT_INFO);
00106 }
|
|
||||||||||||
|
Definition at line 108 of file sediffx.c. Referenced by main(), and sediffx_parse_command_line(). 00109 {
00110 printf("Usage: %s [-d] [ORIGINAL_POLICY ; MODIFIED_POLICY]\n\n", program_name);
00111 if (brief) {
00112 printf("\tTry %s --help for more help.\n\n", program_name);
00113 return;
00114 }
00115 printf("Semantically differentiate two policies. All supported policy elements\n");
00116 printf("are examined. The following options are available:\n");
00117 printf("\n");
00118 printf(" -d, --diff-now load policies and diff immediately\n");
00119 printf(" -h, --help print this help text and exit\n");
00120 printf(" -V, --version print version information and exit\n\n");
00121 }
|
|
|
Definition at line 136 of file sediffx.c. References delayed_main_data::mod_path, delayed_main_data::orig_path, delayed_main_data::run_diff, delayed_main_data::top, toplevel_open_policies(), and toplevel_run_diff(). Referenced by main(). 00137 {
00138 struct delayed_main_data *dmd = (struct delayed_main_data *)data;
00139 if (toplevel_open_policies(dmd->top, dmd->orig_path, dmd->mod_path) == 0 && dmd->run_diff) {
00140 toplevel_run_diff(dmd->top);
00141 }
00142 return FALSE;
00143 }
|
|
|
Definition at line 145 of file sediffx.c. References apol_policy_destroy(), apol_policy_path_destroy(), poldiff_destroy(), and sediffx_t. Referenced by main(). 00146 {
00147 if (sediffx != NULL && *sediffx != NULL) {
00148 int i;
00149 for (i = SEDIFFX_POLICY_ORIG; i < SEDIFFX_POLICY_NUM; i++) {
00150 apol_policy_path_destroy(&((*sediffx)->paths[i]));
00151 apol_policy_destroy(&((*sediffx)->policies[i]));
00152 }
00153 poldiff_destroy(&((*sediffx)->poldiff));
00154 free(*sediffx);
00155 *sediffx = NULL;
00156 }
00157 }
|
|
||||||||||||||||||||||||
|
Definition at line 159 of file sediffx.c. References apol_file_is_policy_path_list(), apol_policy_path_create(), apol_policy_path_create_from_file(), apol_policy_path_destroy(), apol_policy_path_t, apol_policy_path_type_e, APOL_POLICY_PATH_TYPE_MONOLITHIC, apol_vector_append(), apol_vector_create(), apol_vector_destroy(), apol_vector_t, ERR, longopts, print_version_info(), and usage(). Referenced by main(). 00161 {
00162 int optc;
00163 *orig_path = NULL;
00164 *mod_path = NULL;
00165 *run_diff = 0;
00166 while ((optc = getopt_long(argc, argv, "dhV", longopts, NULL)) != -1) {
00167 switch (optc) {
00168 case 0:
00169 break;
00170 case 'd': /* run the diff only for gui */
00171 *run_diff = 1;
00172 break;
00173 case 'h': /* help */
00174 usage(argv[0], 0);
00175 exit(EXIT_SUCCESS);
00176 case 'V': /* version */
00177 print_version_info();
00178 exit(EXIT_SUCCESS);
00179 default:
00180 usage(argv[0], 1);
00181 exit(EXIT_FAILURE);
00182 }
00183 }
00184
00185 if (argc - optind == 0) {
00186 /* here we have found no missing arguments, but
00187 * perhaps the user specified -d with no files */
00188 if (*run_diff) {
00189 usage(argv[0], 0);
00190 exit(EXIT_FAILURE);
00191 }
00192 return;
00193 } else if (argc - optind == 1) {
00194 usage(argv[0], 1);
00195 exit(EXIT_FAILURE);
00196 }
00197 if (argc - optind == 2) {
00198 /* sediffx with file names, old syntax */
00199 if (strcmp(argv[optind], ";") == 0 || strcmp(argv[optind + 1], ";") == 0) {
00200 usage(argv[0], 1);
00201 exit(EXIT_FAILURE);
00202 }
00203 *orig_path = apol_policy_path_create(APOL_POLICY_PATH_TYPE_MONOLITHIC, argv[optind], NULL);
00204 *mod_path = apol_policy_path_create(APOL_POLICY_PATH_TYPE_MONOLITHIC, argv[optind + 1], NULL);
00205 if (*orig_path == NULL || *mod_path == NULL) {
00206 ERR(NULL, "%s", strerror(errno));
00207 exit(EXIT_FAILURE);
00208 }
00209 return;
00210 }
00211
00212 /* module lists */
00213 char *orig_base_path = NULL;
00214 apol_vector_t *orig_module_paths = NULL;
00215 char *mod_base_path = NULL;
00216 apol_vector_t *mod_module_paths = NULL;
00217 apol_policy_path_type_e orig_path_type = APOL_POLICY_PATH_TYPE_MONOLITHIC;
00218 apol_policy_path_type_e mod_path_type = APOL_POLICY_PATH_TYPE_MONOLITHIC;
00219
00220 orig_base_path = argv[optind++];
00221 if (!(orig_module_paths = apol_vector_create(NULL))) {
00222 ERR(NULL, "%s", strerror(errno));
00223 goto err;
00224 }
00225 for (; argc - optind; optind++) {
00226 if (!strcmp(";", argv[optind])) {
00227 optind++;
00228 break;
00229 }
00230 if (apol_vector_append(orig_module_paths, (void *)argv[optind])) {
00231 ERR(NULL, "Error loading module %s", argv[optind]);
00232 goto err;
00233 }
00234 orig_path_type = APOL_POLICY_PATH_TYPE_MODULAR;
00235 }
00236 if (apol_file_is_policy_path_list(orig_base_path) > 0) {
00237 *orig_path = apol_policy_path_create_from_file(orig_base_path);
00238 if (*orig_path == NULL) {
00239 ERR(NULL, "%s", "invalid policy list");
00240 goto err;
00241 }
00242 } else {
00243 *orig_path = apol_policy_path_create(orig_path_type, orig_base_path, orig_module_paths);
00244 if (*orig_path == NULL) {
00245 ERR(NULL, "%s", strerror(errno));
00246 goto err;
00247 }
00248 }
00249 apol_vector_destroy(&orig_module_paths);
00250
00251 if (argc - optind == 0) {
00252 ERR(NULL, "%s", "Missing path to modified policy.");
00253 goto err;
00254 }
00255
00256 mod_base_path = argv[optind++];
00257 if (!(mod_module_paths = apol_vector_create(NULL))) {
00258 ERR(NULL, "%s", strerror(errno));
00259 goto err;
00260 }
00261 for (; argc - optind; optind++) {
00262 if (apol_vector_append(mod_module_paths, (void *)argv[optind])) {
00263 ERR(NULL, "Error loading module %s", argv[optind]);
00264 goto err;
00265 }
00266 mod_path_type = APOL_POLICY_PATH_TYPE_MODULAR;
00267 }
00268 if (apol_file_is_policy_path_list(mod_base_path) > 0) {
00269 *mod_path = apol_policy_path_create_from_file(mod_base_path);
00270 if (*mod_path == NULL) {
00271 ERR(NULL, "%s", "invalid policy list");
00272 goto err;
00273 }
00274 } else {
00275 *mod_path = apol_policy_path_create(mod_path_type, mod_base_path, mod_module_paths);
00276 if (*mod_path == NULL) {
00277 ERR(NULL, "%s", strerror(errno));
00278 goto err;
00279 }
00280 }
00281 apol_vector_destroy(&mod_module_paths);
00282 return;
00283 err:
00284 apol_policy_path_destroy(orig_path);
00285 apol_policy_path_destroy(mod_path);
00286 apol_vector_destroy(&orig_module_paths);
00287 apol_vector_destroy(&mod_module_paths);
00288 }
|
|
||||||||||||
|
Definition at line 290 of file sediffx.c. References apol_policy_path_t, delayed_main(), ERR, sediffx_destroy(), sediffx_parse_command_line(), sediffx_t, and toplevel_create(). 00291 {
00292 sediffx_t *app;
00293 apol_policy_path_t *orig_path, *mod_path;
00294 int run_diff;
00295
00296 if (!g_thread_supported())
00297 g_thread_init(NULL);
00298
00299 gtk_init(&argc, &argv);
00300 sediffx_parse_command_line(argc, argv, &orig_path, &mod_path, &run_diff);
00301 glade_init();
00302 if (!g_thread_supported())
00303 g_thread_init(NULL);
00304 if ((app = calloc(1, sizeof(*app))) == NULL || (app->top = toplevel_create(app)) == NULL) {
00305 ERR(NULL, "%s", strerror(errno));
00306 sediffx_destroy(&app);
00307 exit(EXIT_FAILURE);
00308 }
00309 if (orig_path != NULL && mod_path != NULL) {
00310 struct delayed_main_data dmd = { orig_path, mod_path, run_diff, app->top };
00311 g_idle_add(&delayed_main, &dmd);
00312 }
00313 gtk_main();
00314
00315 sediffx_destroy(&app);
00316 exit(EXIT_SUCCESS);
00317 }
|
|
|
Initial value: {
{"run-diff", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
}
Definition at line 48 of file sediffx.c. Referenced by sediffx_parse_command_line(). |