17258N/AIndex: src/selectlabel.c
17258N/A===================================================================
17258N/A--- src/selectlabel.c (revision 0)
17258N/A+++ src/selectlabel.c (revision 14)
17258N/A@@ -0,0 +1,171 @@
17258N/A+/* Solaris Trusted Extensions GNOME desktop library.
17258N/A+
17258N/A+ Copyright (C) 2009 Sun Microsystems, Inc. All Rights Reserved.
17258N/A+
17258N/A+ The contents of this library are subject to the terms of the
17258N/A+ GNU Lesser General Public License version 2 (the "License")
17258N/A+ as published by the Free Software Foundation. You may not use
17258N/A+ this library except in compliance with the License.
17258N/A+
17258N/A+ You should have received a copy of the License along with this
17258N/A+ library; see the file COPYING. If not,you can obtain a copy
17258N/A+ at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html or by writing
17258N/A+ to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17258N/A+ Boston, MA 02111-1307, USA. See the License for specific language
17258N/A+ governing permissions and limitations under the License.
17258N/A+*/
17258N/A+
17258N/A+#include <config.h>
17258N/A+#include <glib.h>
17258N/A+#include <gtk/gtk.h>
17258N/A+#include <stdlib.h>
17258N/A+#include <strings.h>
17258N/A+#include <tsol/label.h>
17258N/A+#include <sys/tsol/label_macro.h>
17258N/A+#include "label_builder.h"
17258N/A+
17258N/A+int
17258N/A+main (int argc, char *argv[])
17258N/A+{
17258N/A+ GtkWidget *lbuilder;
17258N/A+ GOptionContext *context;
17258N/A+ m_label_t *lower = NULL, *upper = NULL, *def = NULL, *label = NULL;
17258N/A+ int label_type;
17258N/A+ int err;
17258N/A+ uint_t flags;
17258N/A+ uint_t format_flags;
17258N/A+ GError *error = NULL;
17258N/A+ char *min = NULL, *max = NULL, *defstr = NULL, *accredcheck = NULL;
17258N/A+ char *modestr = NULL, *format = NULL, *title = NULL, *text=NULL;
17258N/A+ char *labelstr;
17258N/A+ int mode, checkar;
17258N/A+
17258N/A+ const GOptionEntry options [] = {
17258N/A+ { "min", 'n', 0, G_OPTION_ARG_STRING, &min,
17258N/A+ "Minimim Label (Required)", "label string" },
17258N/A+ { "max", 'x', 0, G_OPTION_ARG_STRING, &max,
17258N/A+ "Maximum Label (Required)", "label string" },
17258N/A+ { "default", 'd', 0, G_OPTION_ARG_STRING, &defstr,
17258N/A+ "Default Selected Label", "label string" },
17258N/A+ { "accredcheck", 'a', 0, G_OPTION_ARG_STRING, &accredcheck,
17258N/A+ "Enable Accreditation checking", "[yes|no]" },
17258N/A+ { "mode", 'm', 0, G_OPTION_ARG_STRING, &modestr,
17258N/A+ "Clearance or Sensitivity mode", "[clearance|sensitivity]" },
17258N/A+ { "format", 'f', 0, G_OPTION_ARG_STRING, &format,
17258N/A+ "Internal or Human Readable format", "[internal|human]" },
17258N/A+ { "title", 'i', 0, G_OPTION_ARG_STRING, &title,
17258N/A+ "Window title", "title" },
17258N/A+ { "text", 't', 0, G_OPTION_ARG_STRING, &text,
17258N/A+ "Operation description", "text" },
17258N/A+ { NULL }
17258N/A+ };
17258N/A+
17258N/A+ if (!is_system_labeled ()) {
17258N/A+ g_printerr ("This command is only available if the system is "
17258N/A+ "configured with Trusted Extensions\n");
17258N/A+ return 3;
17258N/A+ }
17258N/A+
17258N/A+ context = g_option_context_new (NULL);
17258N/A+ g_option_context_add_main_entries (context, options, NULL);
17258N/A+
17258N/A+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
17258N/A+ g_printerr ("Could not parse arguments: %s\n", error->message);
17258N/A+ g_error_free (error);
17258N/A+ return 1;
17258N/A+ }
17258N/A+
17258N/A+ if (!min || !max) {
17258N/A+ g_printerr ("You must specify both min and max labels\n\n%s",
17258N/A+ g_option_context_get_help (context, TRUE, NULL));
17258N/A+ return 1;
17258N/A+ }
17258N/A+
17258N/A+ g_option_context_free (context);
17258N/A+
17258N/A+ if (!defstr) {
17258N/A+ defstr = g_strdup (max);
17258N/A+ }
17258N/A+
17258N/A+ if (modestr && strncmp (modestr, "clearance", 9) == 0) {
17258N/A+ mode = LBUILD_MODE_CLR;
17258N/A+ label_type = USER_CLEAR;
17258N/A+ } else {
17258N/A+ mode = LBUILD_MODE_SL;
17258N/A+ label_type = MAC_LABEL;
17258N/A+ }
17258N/A+
17258N/A+ if (format && strncmp (format, "human", 8) == 0) {
17258N/A+ format_flags = M_LABEL;
17258N/A+ } else {
17258N/A+ format_flags = M_INTERNAL;
17258N/A+ }
17258N/A+
17258N/A+ if (accredcheck && strncmp (accredcheck, "yes", 3) == 0) {
17258N/A+ flags = L_DEFAULT | L_CHECK_AR;
17258N/A+ } else {
17258N/A+ flags = L_DEFAULT;
17258N/A+ }
17258N/A+
17258N/A+ if (str_to_label (min, &lower, label_type, flags, &err) < 0) {
17258N/A+ g_printerr ("%s: Can not convert minimum label\n", argv[0]);
17258N/A+ if (err == M_OUTSIDE_AR) {
17258N/A+ g_printerr ("Label is outside the accreditation range");
17258N/A+ return (4);
17258N/A+ }
17258N/A+ return (2);
17258N/A+ }
17258N/A+
17258N/A+ if (str_to_label (max, &upper, label_type, flags, &err) < 0) {
17258N/A+ g_printerr ("%s: Can not convert maximum label\n", argv[0]);
17258N/A+ if (err == M_OUTSIDE_AR) {
17258N/A+ g_printerr ("Label is outside the accreditation range");
17258N/A+ return (4);
17258N/A+ }
17258N/A+ return (2);
17258N/A+ }
17258N/A+
17258N/A+ if (str_to_label (defstr, &def, label_type, flags, &err)<0){
17258N/A+ g_printerr ("%s: Can not convert default label\n", argv[0]);
17258N/A+ if (err == M_OUTSIDE_AR) {
17258N/A+ g_printerr ("Label is outside the accreditation range");
17258N/A+ return (4);
17258N/A+ }
17258N/A+ return (2);
17258N/A+ }
17258N/A+
17258N/A+ gtk_init (&argc, &argv);
17258N/A+
17258N/A+ lbuilder = g_object_new (GNOME_TYPE_LABEL_BUILDER, "mode", mode,
17258N/A+ "message", text ? text : "Select a Label",
17258N/A+ "lower", lower, "upper", upper, NULL);
17258N/A+
17258N/A+ gtk_window_set_title (GTK_WINDOW (lbuilder),
17258N/A+ title ? title : "Label Selector");
17258N/A+
17258N/A+ g_object_set (G_OBJECT (lbuilder), "sl", def, NULL);
17258N/A+
17258N/A+ gtk_widget_show_all (lbuilder);
17258N/A+
17258N/A+ switch (gtk_dialog_run (GTK_DIALOG (lbuilder))) {
17258N/A+ case GTK_RESPONSE_OK:
17258N/A+ g_object_get (G_OBJECT (lbuilder), "sl", &label, NULL);
17258N/A+ if (label_to_str (label, &labelstr, format_flags, DEF_NAMES<0)){
17258N/A+ g_printerr ("%s: Can not convert selected label",
17258N/A+ argv[0]);
17258N/A+ exit (2);
17258N/A+ }
17258N/A+ g_print ("%s\n", labelstr);
17258N/A+ gtk_widget_destroy (GTK_WIDGET (lbuilder));
17258N/A+ break;
17258N/A+ case GTK_RESPONSE_CANCEL:
17258N/A+ gtk_widget_destroy (GTK_WIDGET (lbuilder));
17258N/A+ exit (5);
17258N/A+ break;
17258N/A+ case GTK_RESPONSE_HELP:
17258N/A+ default:
17258N/A+ break;
17258N/A+ }
17258N/A+
17258N/A+ return 0;
17258N/A+}
17258N/AIndex: src/Makefile.am
17258N/A===================================================================
17258N/A--- src/Makefile.am (revision 13)
17258N/A+++ src/Makefile.am (working copy)
17258N/A@@ -52,3 +52,10 @@
17258N/A test_LDADD = libgnometsol.la
17258N/A test_DEPENDENCIES = libgnometsol.la
17258N/A
17258N/A+bin_PROGRAMS = tgnome-selectlabel
17258N/A+
17258N/A+tgnome_selectlabel_SOURCES = selectlabel.c
17258N/A+tgnome_selectlabel_LDADD = libgnometsol.la
17258N/A+tgnome_selectlabel_DEPENDENCIES = libgnometsol.la
17258N/A+
17258N/A+