1*45916cd2Sjpk /*
2*45916cd2Sjpk * CDDL HEADER START
3*45916cd2Sjpk *
4*45916cd2Sjpk * The contents of this file are subject to the terms of the
5*45916cd2Sjpk * Common Development and Distribution License (the "License").
6*45916cd2Sjpk * You may not use this file except in compliance with the License.
7*45916cd2Sjpk *
8*45916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*45916cd2Sjpk * or http://www.opensolaris.org/os/licensing.
10*45916cd2Sjpk * See the License for the specific language governing permissions
11*45916cd2Sjpk * and limitations under the License.
12*45916cd2Sjpk *
13*45916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each
14*45916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*45916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the
16*45916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying
17*45916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner]
18*45916cd2Sjpk *
19*45916cd2Sjpk * CDDL HEADER END
20*45916cd2Sjpk */
21*45916cd2Sjpk /*
22*45916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*45916cd2Sjpk * Use is subject to license terms.
24*45916cd2Sjpk */
25*45916cd2Sjpk
26*45916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI"
27*45916cd2Sjpk
28*45916cd2Sjpk /*
29*45916cd2Sjpk * hextob.c - Hexadecimal string to binary label conversion.
30*45916cd2Sjpk *
31*45916cd2Sjpk * These routines convert canonical hexadecimal representations
32*45916cd2Sjpk * of internal labels into binary form.
33*45916cd2Sjpk *
34*45916cd2Sjpk */
35*45916cd2Sjpk
36*45916cd2Sjpk #include <stdio.h>
37*45916cd2Sjpk #include <string.h>
38*45916cd2Sjpk #include <ctype.h>
39*45916cd2Sjpk
40*45916cd2Sjpk #include <tsol/label.h>
41*45916cd2Sjpk #include <sys/tsol/label_macro.h>
42*45916cd2Sjpk
43*45916cd2Sjpk /*
44*45916cd2Sjpk * htobsl - Convert a Hexadecimal label string to a Sensitivity Label.
45*45916cd2Sjpk *
46*45916cd2Sjpk * Entry s = Hexadecimal label string to be converted.
47*45916cd2Sjpk *
48*45916cd2Sjpk * Exit label = Sensitivity Label converted, if successful.
49*45916cd2Sjpk * Unchanged, if not successful.
50*45916cd2Sjpk *
51*45916cd2Sjpk * Returns 1, If successful.
52*45916cd2Sjpk * 0, Otherwise.
53*45916cd2Sjpk *
54*45916cd2Sjpk * Calls str_to_label, m_label_free.
55*45916cd2Sjpk */
56*45916cd2Sjpk
57*45916cd2Sjpk int
htobsl(const char * s,m_label_t * label)58*45916cd2Sjpk htobsl(const char *s, m_label_t *label)
59*45916cd2Sjpk {
60*45916cd2Sjpk m_label_t *l = NULL;
61*45916cd2Sjpk
62*45916cd2Sjpk if (str_to_label(s, &l, MAC_LABEL, L_NO_CORRECTION, NULL) == -1) {
63*45916cd2Sjpk m_label_free(l);
64*45916cd2Sjpk return (0);
65*45916cd2Sjpk }
66*45916cd2Sjpk *label = *l;
67*45916cd2Sjpk m_label_free(l);
68*45916cd2Sjpk return (1);
69*45916cd2Sjpk }
70*45916cd2Sjpk
71*45916cd2Sjpk /*
72*45916cd2Sjpk * htobclear - Convert a Hexadecimal label string to a Clearance.
73*45916cd2Sjpk *
74*45916cd2Sjpk * Entry s = Hexadecimal label string to be converted.
75*45916cd2Sjpk *
76*45916cd2Sjpk * Exit clearance = Clearnace converted, if successful.
77*45916cd2Sjpk * Unchanged, if not successful.
78*45916cd2Sjpk *
79*45916cd2Sjpk * Returns 1, If successful.
80*45916cd2Sjpk * 0, Otherwise.
81*45916cd2Sjpk *
82*45916cd2Sjpk * Calls str_to_label, m_label_free.
83*45916cd2Sjpk */
84*45916cd2Sjpk
85*45916cd2Sjpk int
htobclear(const char * s,m_label_t * clearance)86*45916cd2Sjpk htobclear(const char *s, m_label_t *clearance)
87*45916cd2Sjpk {
88*45916cd2Sjpk m_label_t *c = NULL;
89*45916cd2Sjpk
90*45916cd2Sjpk if (str_to_label(s, &c, USER_CLEAR, L_NO_CORRECTION, NULL) == -1) {
91*45916cd2Sjpk m_label_free(c);
92*45916cd2Sjpk return (0);
93*45916cd2Sjpk }
94*45916cd2Sjpk *clearance = *c;
95*45916cd2Sjpk m_label_free(c);
96*45916cd2Sjpk return (1);
97*45916cd2Sjpk }
98