2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * btohex.c - Binary to Hexadecimal string conversion.
2N/A *
2N/A * These routines convert binary labels into canonical
2N/A * hexadecimal representations of the binary form.
2N/A */
2N/A
2N/A#include <stdlib.h>
2N/A#include <strings.h>
2N/A#include <tsol/label.h>
2N/A#include <sys/tsol/label_macro.h>
2N/A
2N/Astatic char hex_buf[MAXLABELSTR];
2N/A
2N/A/*
2N/A * h_alloc - Allocate data storage for a Hexadecimal label string.
2N/A *
2N/A * Entry id = Type of label to allocate storage for.
2N/A * SUN_SL_ID - Sensitivity Label.
2N/A * SUN_CLR_ID - Clearance.
2N/A *
2N/A * Returns NULL, If unable to allocate storage.
2N/A * Address of buffer.
2N/A *
2N/A * Calls malloc;
2N/A */
2N/A
2N/Achar *
2N/Ah_alloc(unsigned char id)
2N/A{
2N/A size_t size;
2N/A
2N/A switch (id) {
2N/A
2N/A case SUN_SL_ID:
2N/A size = MAXLABELSTR;
2N/A break;
2N/A
2N/A case SUN_CLR_ID:
2N/A size = MAXLABELSTR;
2N/A break;
2N/A
2N/A default:
2N/A return (NULL);
2N/A }
2N/A
2N/A return ((char *)malloc(size));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * h_free - Free a Hexadecimal label string.
2N/A *
2N/A * Entry hex = Hexadecimal label string.
2N/A *
2N/A * Returns none.
2N/A *
2N/A * Calls free.
2N/A */
2N/A
2N/Avoid
2N/Ah_free(char *hex)
2N/A{
2N/A
2N/A if (hex == NULL)
2N/A return;
2N/A
2N/A free(hex);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * bsltoh_r - Convert a Sensitivity Label into a Hexadecimal label string.
2N/A *
2N/A * Entry label = Sensitivity Label to be translated.
2N/A * hex = Buffer to place converted label.
2N/A * len = Length of buffer.
2N/A *
2N/A * Returns NULL, If invalid label type.
2N/A * Address of buffer.
2N/A *
2N/A * Calls label_to_str, strncpy.
2N/A */
2N/A
2N/Achar *
2N/Absltoh_r(const m_label_t *label, char *hex)
2N/A{
2N/A char *h;
2N/A
2N/A if (label_to_str(label, &h, M_INTERNAL, DEF_NAMES) != 0) {
2N/A free(h);
2N/A return (NULL);
2N/A }
2N/A
2N/A (void) strncpy(hex, (const char *)h, MAXLABELSTR);
2N/A free(h);
2N/A return (hex);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * bsltoh - Convert a Sensitivity Label into a Hexadecimal label string.
2N/A *
2N/A * Entry label = Sensitivity Label to be translated.
2N/A *
2N/A * Returns NULL, If invalid label type.
2N/A * Address of statically allocated hex label string.
2N/A *
2N/A * Calls bsltoh_r.
2N/A *
2N/A * Uses hex_buf.
2N/A */
2N/A
2N/Achar *
2N/Absltoh(const m_label_t *label)
2N/A{
2N/A
2N/A return (bsltoh_r(label, hex_buf));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * bcleartoh_r - Convert a Clearance into a Hexadecimal label string.
2N/A *
2N/A * Entry clearance = Clearance to be translated.
2N/A * hex = Buffer to place converted label.
2N/A * len = Length of buffer.
2N/A *
2N/A * Returns NULL, If invalid label type.
2N/A * Address of buffer.
2N/A *
2N/A * Calls label_to_str, strncpy.
2N/A */
2N/A
2N/Achar *
2N/Abcleartoh_r(const m_label_t *clearance, char *hex)
2N/A{
2N/A char *h;
2N/A
2N/A if (label_to_str(clearance, &h, M_INTERNAL, DEF_NAMES) != 0) {
2N/A free(h);
2N/A return (NULL);
2N/A }
2N/A
2N/A (void) strncpy(hex, (const char *)h, MAXLABELSTR);
2N/A free(h);
2N/A return (hex);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * bcleartoh - Convert a Clearance into a Hexadecimal label string.
2N/A *
2N/A * Entry clearance = Clearance to be translated.
2N/A *
2N/A * Returns NULL, If invalid label type.
2N/A * Address of statically allocated hex label string.
2N/A *
2N/A * Calls bcleartoh_r.
2N/A *
2N/A * Uses hex_buf.
2N/A */
2N/A
2N/Achar *
2N/Abcleartoh(const m_label_t *clearance)
2N/A{
2N/A
2N/A return (bcleartoh_r(clearance, hex_buf));
2N/A}