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