16507
|
1 |
Index: src/selectlabel.c
|
|
2 |
===================================================================
|
|
3 |
--- src/selectlabel.c (revision 0)
|
|
4 |
+++ src/selectlabel.c (revision 14)
|
|
5 |
@@ -0,0 +1,171 @@
|
|
6 |
+/* Solaris Trusted Extensions GNOME desktop library.
|
|
7 |
+
|
|
8 |
+ Copyright (C) 2009 Sun Microsystems, Inc. All Rights Reserved.
|
|
9 |
+
|
|
10 |
+ The contents of this library are subject to the terms of the
|
|
11 |
+ GNU Lesser General Public License version 2 (the "License")
|
|
12 |
+ as published by the Free Software Foundation. You may not use
|
|
13 |
+ this library except in compliance with the License.
|
|
14 |
+
|
|
15 |
+ You should have received a copy of the License along with this
|
|
16 |
+ library; see the file COPYING. If not,you can obtain a copy
|
|
17 |
+ at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html or by writing
|
|
18 |
+ to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 |
+ Boston, MA 02111-1307, USA. See the License for specific language
|
|
20 |
+ governing permissions and limitations under the License.
|
|
21 |
+*/
|
|
22 |
+
|
|
23 |
+#include <config.h>
|
|
24 |
+#include <glib.h>
|
|
25 |
+#include <gtk/gtk.h>
|
|
26 |
+#include <stdlib.h>
|
|
27 |
+#include <strings.h>
|
|
28 |
+#include <tsol/label.h>
|
|
29 |
+#include <sys/tsol/label_macro.h>
|
|
30 |
+#include "label_builder.h"
|
|
31 |
+
|
|
32 |
+int
|
|
33 |
+main (int argc, char *argv[])
|
|
34 |
+{
|
|
35 |
+ GtkWidget *lbuilder;
|
|
36 |
+ GOptionContext *context;
|
|
37 |
+ m_label_t *lower = NULL, *upper = NULL, *def = NULL, *label = NULL;
|
|
38 |
+ int label_type;
|
|
39 |
+ int err;
|
|
40 |
+ uint_t flags;
|
|
41 |
+ uint_t format_flags;
|
|
42 |
+ GError *error = NULL;
|
|
43 |
+ char *min = NULL, *max = NULL, *defstr = NULL, *accredcheck = NULL;
|
|
44 |
+ char *modestr = NULL, *format = NULL, *title = NULL, *text=NULL;
|
|
45 |
+ char *labelstr;
|
|
46 |
+ int mode, checkar;
|
|
47 |
+
|
|
48 |
+ const GOptionEntry options [] = {
|
|
49 |
+ { "min", 'n', 0, G_OPTION_ARG_STRING, &min,
|
|
50 |
+ "Minimim Label (Required)", "label string" },
|
|
51 |
+ { "max", 'x', 0, G_OPTION_ARG_STRING, &max,
|
|
52 |
+ "Maximum Label (Required)", "label string" },
|
|
53 |
+ { "default", 'd', 0, G_OPTION_ARG_STRING, &defstr,
|
|
54 |
+ "Default Selected Label", "label string" },
|
|
55 |
+ { "accredcheck", 'a', 0, G_OPTION_ARG_STRING, &accredcheck,
|
|
56 |
+ "Enable Accreditation checking", "[yes|no]" },
|
|
57 |
+ { "mode", 'm', 0, G_OPTION_ARG_STRING, &modestr,
|
|
58 |
+ "Clearance or Sensitivity mode", "[clearance|sensitivity]" },
|
|
59 |
+ { "format", 'f', 0, G_OPTION_ARG_STRING, &format,
|
|
60 |
+ "Internal or Human Readable format", "[internal|human]" },
|
|
61 |
+ { "title", 'i', 0, G_OPTION_ARG_STRING, &title,
|
|
62 |
+ "Window title", "title" },
|
|
63 |
+ { "text", 't', 0, G_OPTION_ARG_STRING, &text,
|
|
64 |
+ "Operation description", "text" },
|
|
65 |
+ { NULL }
|
|
66 |
+ };
|
|
67 |
+
|
|
68 |
+ if (!is_system_labeled ()) {
|
|
69 |
+ g_printerr ("This command is only available if the system is "
|
|
70 |
+ "configured with Trusted Extensions\n");
|
|
71 |
+ return 3;
|
|
72 |
+ }
|
|
73 |
+
|
|
74 |
+ context = g_option_context_new (NULL);
|
|
75 |
+ g_option_context_add_main_entries (context, options, NULL);
|
|
76 |
+
|
|
77 |
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
|
|
78 |
+ g_printerr ("Could not parse arguments: %s\n", error->message);
|
|
79 |
+ g_error_free (error);
|
|
80 |
+ return 1;
|
|
81 |
+ }
|
|
82 |
+
|
|
83 |
+ if (!min || !max) {
|
|
84 |
+ g_printerr ("You must specify both min and max labels\n\n%s",
|
|
85 |
+ g_option_context_get_help (context, TRUE, NULL));
|
|
86 |
+ return 1;
|
|
87 |
+ }
|
|
88 |
+
|
|
89 |
+ g_option_context_free (context);
|
|
90 |
+
|
|
91 |
+ if (!defstr) {
|
|
92 |
+ defstr = g_strdup (max);
|
|
93 |
+ }
|
|
94 |
+
|
|
95 |
+ if (modestr && strncmp (modestr, "clearance", 9) == 0) {
|
|
96 |
+ mode = LBUILD_MODE_CLR;
|
|
97 |
+ label_type = USER_CLEAR;
|
|
98 |
+ } else {
|
|
99 |
+ mode = LBUILD_MODE_SL;
|
|
100 |
+ label_type = MAC_LABEL;
|
|
101 |
+ }
|
|
102 |
+
|
|
103 |
+ if (format && strncmp (format, "human", 8) == 0) {
|
|
104 |
+ format_flags = M_LABEL;
|
|
105 |
+ } else {
|
|
106 |
+ format_flags = M_INTERNAL;
|
|
107 |
+ }
|
|
108 |
+
|
|
109 |
+ if (accredcheck && strncmp (accredcheck, "yes", 3) == 0) {
|
|
110 |
+ flags = L_DEFAULT | L_CHECK_AR;
|
|
111 |
+ } else {
|
|
112 |
+ flags = L_DEFAULT;
|
|
113 |
+ }
|
|
114 |
+
|
|
115 |
+ if (str_to_label (min, &lower, label_type, flags, &err) < 0) {
|
|
116 |
+ g_printerr ("%s: Can not convert minimum label\n", argv[0]);
|
|
117 |
+ if (err == M_OUTSIDE_AR) {
|
|
118 |
+ g_printerr ("Label is outside the accreditation range");
|
|
119 |
+ return (4);
|
|
120 |
+ }
|
|
121 |
+ return (2);
|
|
122 |
+ }
|
|
123 |
+
|
|
124 |
+ if (str_to_label (max, &upper, label_type, flags, &err) < 0) {
|
|
125 |
+ g_printerr ("%s: Can not convert maximum label\n", argv[0]);
|
|
126 |
+ if (err == M_OUTSIDE_AR) {
|
|
127 |
+ g_printerr ("Label is outside the accreditation range");
|
|
128 |
+ return (4);
|
|
129 |
+ }
|
|
130 |
+ return (2);
|
|
131 |
+ }
|
|
132 |
+
|
|
133 |
+ if (str_to_label (defstr, &def, label_type, flags, &err)<0){
|
|
134 |
+ g_printerr ("%s: Can not convert default label\n", argv[0]);
|
|
135 |
+ if (err == M_OUTSIDE_AR) {
|
|
136 |
+ g_printerr ("Label is outside the accreditation range");
|
|
137 |
+ return (4);
|
|
138 |
+ }
|
|
139 |
+ return (2);
|
|
140 |
+ }
|
|
141 |
+
|
|
142 |
+ gtk_init (&argc, &argv);
|
|
143 |
+
|
|
144 |
+ lbuilder = g_object_new (GNOME_TYPE_LABEL_BUILDER, "mode", mode,
|
|
145 |
+ "message", text ? text : "Select a Label",
|
|
146 |
+ "lower", lower, "upper", upper, NULL);
|
|
147 |
+
|
|
148 |
+ gtk_window_set_title (GTK_WINDOW (lbuilder),
|
|
149 |
+ title ? title : "Label Selector");
|
|
150 |
+
|
|
151 |
+ g_object_set (G_OBJECT (lbuilder), "sl", def, NULL);
|
|
152 |
+
|
|
153 |
+ gtk_widget_show_all (lbuilder);
|
|
154 |
+
|
|
155 |
+ switch (gtk_dialog_run (GTK_DIALOG (lbuilder))) {
|
|
156 |
+ case GTK_RESPONSE_OK:
|
|
157 |
+ g_object_get (G_OBJECT (lbuilder), "sl", &label, NULL);
|
|
158 |
+ if (label_to_str (label, &labelstr, format_flags, DEF_NAMES<0)){
|
|
159 |
+ g_printerr ("%s: Can not convert selected label",
|
|
160 |
+ argv[0]);
|
|
161 |
+ exit (2);
|
|
162 |
+ }
|
|
163 |
+ g_print ("%s\n", labelstr);
|
|
164 |
+ gtk_widget_destroy (GTK_WIDGET (lbuilder));
|
|
165 |
+ break;
|
|
166 |
+ case GTK_RESPONSE_CANCEL:
|
|
167 |
+ gtk_widget_destroy (GTK_WIDGET (lbuilder));
|
|
168 |
+ exit (5);
|
|
169 |
+ break;
|
|
170 |
+ case GTK_RESPONSE_HELP:
|
|
171 |
+ default:
|
|
172 |
+ break;
|
|
173 |
+ }
|
|
174 |
+
|
|
175 |
+ return 0;
|
|
176 |
+}
|
|
177 |
Index: src/Makefile.am
|
|
178 |
===================================================================
|
|
179 |
--- src/Makefile.am (revision 13)
|
|
180 |
+++ src/Makefile.am (working copy)
|
|
181 |
@@ -52,3 +52,10 @@
|
|
182 |
test_LDADD = libgnometsol.la
|
|
183 |
test_DEPENDENCIES = libgnometsol.la
|
|
184 |
|
|
185 |
+bin_PROGRAMS = tgnome-selectlabel
|
|
186 |
+
|
|
187 |
+tgnome_selectlabel_SOURCES = selectlabel.c
|
|
188 |
+tgnome_selectlabel_LDADD = libgnometsol.la
|
|
189 |
+tgnome_selectlabel_DEPENDENCIES = libgnometsol.la
|
|
190 |
+
|
|
191 |
+
|