remap_types_dialog.h File Reference


Detailed Description

Headers for a dialog that allows users to explicitly remap/remap types.

Author:
Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Randy Wicks rwicks@tresys.com

Copyright (C) 2005-2007 Tresys Technology, LLC

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 remap_types_dialog.h.

#include "toplevel.h"

Go to the source code of this file.


Functions

int remap_types_run (toplevel_t *top)
 Display and run a dialog that allows the user to add and remove type remappings.
int remap_types_update (apol_policy_t *orig_policy, apol_policy_t *mod_policy)
 Notify the remap types dialog that the currently loaded policies have changed.

Function Documentation

int remap_types_run toplevel_t top  ) 
 

Display and run a dialog that allows the user to add and remove type remappings.

Parameters:
top Toplevel containing poldiff structure.
Returns:
Non-zero if any mapping was added or removed, zero if there were no changes.

Definition at line 454 of file remap_types_dialog.c.

References remap_types_init_combos(), remap_types_init_widgets(), remap_types_update_view(), remap_types::top, toplevel_get_glade_xml(), toplevel_get_poldiff(), toplevel_t, and toplevel::xml.

Referenced by toplevel_on_remap_types_activate(), and toplevel_on_remap_types_button_click().

00455 {
00456         struct remap_types rt;
00457         gint response;
00458         static gboolean prev_show_inferred = FALSE;
00459         static gboolean prev_show_unmapped = TRUE;
00460 
00461         memset(&rt, 0, sizeof(rt));
00462         rt.top = top;
00463         rt.xml = glade_xml_new(toplevel_get_glade_xml(rt.top), "remap_types", NULL);
00464         rt.diff = toplevel_get_poldiff(rt.top);
00465 
00466         remap_types_init_widgets(&rt);
00467         remap_types_init_combos(&rt);
00468         remap_types_update_view(&rt);
00469 
00470         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rt.show_inferred), prev_show_inferred);
00471         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rt.show_unmapped_types), prev_show_unmapped);
00472 
00473         response = gtk_dialog_run(rt.dialog);
00474 
00475         prev_show_inferred = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rt.show_inferred));
00476         prev_show_unmapped = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rt.show_unmapped_types));
00477         gtk_widget_destroy(GTK_WIDGET(rt.dialog));
00478         g_object_unref(rt.sort);
00479         g_object_unref(rt.filter);
00480         g_object_unref(rt.remaps);
00481         return rt.changed;
00482 }

int remap_types_update apol_policy_t orig_policy,
apol_policy_t mod_policy
 

Notify the remap types dialog that the currently loaded policies have changed.

This function updates its lists of types from the policies. This function must be called at least once prior to remap_types_run().

Parameters:
orig_policy Newly loaded original policy.
mod_policy Newly loaded modified policy.
Returns:
0 on success, < 0 on error.

Definition at line 510 of file remap_types_dialog.c.

References apol_policy_get_qpol(), apol_policy_t, apol_type_get_by_query(), apol_vector_destroy(), apol_vector_get_element(), apol_vector_get_size(), apol_vector_sort(), apol_vector_t, mod_policy, orig_policy, qpol_policy_t, qpol_type_get_name(), qpol_type_t, remap_types_qpol_type_cmp(), remap_types_types_filter_visible(), sediffx_policy_e, SEDIFFX_POLICY_MOD, SEDIFFX_POLICY_ORIG, types, and types_filter.

Referenced by toplevel_open_policies().

00511 {
00512         qpol_policy_t *oq = apol_policy_get_qpol(orig_policy);
00513         qpol_policy_t *mq = apol_policy_get_qpol(mod_policy);
00514         apol_vector_t *v = NULL;
00515         sediffx_policy_e which;
00516         size_t i;
00517         const qpol_type_t *t;
00518         const char *type_name;
00519         GtkTreeIter iter;
00520         int error = 0, retval = -1;
00521 
00522         for (which = SEDIFFX_POLICY_ORIG; which < SEDIFFX_POLICY_NUM; which++) {
00523                 if (types[which] == NULL) {
00524                         types[which] = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
00525                         types_filter[which] = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(types[which]), NULL));
00526                         gtk_tree_model_filter_set_visible_func(types_filter[which], remap_types_types_filter_visible, NULL, NULL);
00527                 } else {
00528                         gtk_list_store_clear(types[which]);
00529                 }
00530         }
00531 
00532         if (apol_type_get_by_query(orig_policy, NULL, &v) < 0) {
00533                 error = errno;
00534                 goto cleanup;
00535         }
00536         apol_vector_sort(v, remap_types_qpol_type_cmp, oq);
00537         for (i = 0; i < apol_vector_get_size(v); i++) {
00538                 t = apol_vector_get_element(v, i);
00539                 qpol_type_get_name(oq, t, &type_name);
00540                 gtk_list_store_append(types[SEDIFFX_POLICY_ORIG], &iter);
00541                 gtk_list_store_set(types[SEDIFFX_POLICY_ORIG], &iter, 0, type_name, -1);
00542         }
00543         apol_vector_destroy(&v);
00544 
00545         if (apol_type_get_by_query(mod_policy, NULL, &v) < 0) {
00546                 error = errno;
00547                 goto cleanup;
00548         }
00549         apol_vector_sort(v, remap_types_qpol_type_cmp, mq);
00550         for (i = 0; i < apol_vector_get_size(v); i++) {
00551                 t = apol_vector_get_element(v, i);
00552                 qpol_type_get_name(mq, t, &type_name);
00553                 gtk_list_store_append(types[SEDIFFX_POLICY_MOD], &iter);
00554                 gtk_list_store_set(types[SEDIFFX_POLICY_MOD], &iter, 0, type_name, -1);
00555         }
00556         retval = 0;
00557       cleanup:
00558         apol_vector_destroy(&v);
00559         if (retval != 0) {
00560                 errno = error;
00561                 return retval;
00562         }
00563         return retval;
00564 }