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