stob.c revision a6080eb58dc0a9948e87d1bd3773da387e2c64ca
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* String to binary label translations.
*/
#include <ctype.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "labeld.h"
+ (buf))
#if !defined(TEXT_DOMAIN) /* should be defined by Makefiles */
#define TEXT_DOMAIN "SYS_TEST"
#endif /* TEXT_DOMAIN */
/* short hands */
#define IS_ADMIN_LOW(sl) \
#define IS_ADMIN_HIGH(sh) \
#define ISHEX(f, s) \
(((f) & NO_CORRECTION) == ((f) | NO_CORRECTION))) && \
(((s)[0] == '0') && (((s)[1] == 'x') || ((s)[1] == 'X'))))
/*
* stobsl - Translate Sensitivity Label string to a Binary Sensitivity
* Label.
*
* Entry string = Sensitivity Label string to be translated.
* label = Address of Binary Sensitivity Label to be initialized or
* updated.
* flags = Flags to control translation:
* NO_CORRECTION implies NEW_LABEL.
* NEW_LABEL, Initialize the label to a valid empty
* Sensitivity Label structure.
* NO_CORRECTION, Initialize the label to a valid
* empty Sensitivity Label structure.
* Prohibit correction to the Sensitivity Label.
* Other, pass existing Sensitivity Label through for
* modification.
*
* Exit label = Translated (updated) Binary Sensitivity Label.
* error = If error reported, the error indicator,
* -1, Unable to access label encodings file;
* 0, Invalid binary label passed;
* >0, Position after the first character in
* string of error, 1 indicates entire string.
* Otherwise, unchanged.
*
* Returns 0, If error.
* 1, If successful.
*
* Calls __call_labeld(STOBSL), ISHEX, htobsl, strlen,
* isspace,
* strncasecmp.
*
* Uses ADMIN_HIGH, ADMIN_LOW.
*/
int
{
int rval;
char *s = (char *)string;
while (isspace(*s))
s++;
/* accept a leading '[' */
if (*s == '[') {
s++;
while (isspace(*s))
s++;
}
return (1);
} else {
*error = 1;
return (0);
}
}
*error = -1;
return (0);
}
}
/* free allocated buffer */
}
/*
* reterr == 0, OK,
* reterr < 0, invalid binary label,
* reterr > 0 error position, 1 == whole string
*/
if (err == 0) {
return (1);
} else if (err < 0) {
err = 0;
}
return (0);
/* free allocated buffer */
}
/* server not present */
/* special case Admin High and Admin Low */
if (IS_ADMIN_LOW(s)) {
} else if (IS_ADMIN_HIGH(s)) {
} else {
goto err1;
}
return (1);
}
/* free allocated buffer */
}
err1:
*error = -1;
return (0);
} /* stobsl */
/*
* stobclear - Translate Clearance string to a Binary Clearance.
*
* Entry string = Clearance string to be translated.
* clearance = Address of Binary Clearance to be initialized or
* updated.
* flags = Flags to control translation:
* NO_CORRECTION implies NEW_LABEL.
* NEW_LABEL, Initialize the label to a valid empty
* Sensitivity Label structure.
* NO_CORRECTION, Initialize the label to a valid
* empty Sensitivity Label structure.
* Prohibit correction to the Sensitivity Label.
* Other, pass existing Sensitivity Label through for
* modification.
*
* Exit clearance = Translated (updated) Binary Clearance.
* error = If error reported, the error indicator,
* -1, Unable to access label encodings file;
* 0, Invalid binary label passed;
* >0, Position after the first character in
* string of error, 1 indicates entire string.
* Otherwise, unchanged.
*
* Returns 0, If error.
* 1, If successful.
*
* Calls __call_labeld(STOBCLEAR), ISHEX, htobsl, strlen,
* isspace,
* strncasecmp.
*
* Uses ADMIN_HIGH, ADMIN_LOW.
*/
int
{
int rval;
return (1);
} else {
*error = 1;
return (0);
}
}
*error = -1;
return (0);
}
}
/* free allocated buffer */
}
/*
* reterr == 0, OK,
* reterr < 0, invalid binary label,
* reterr > 0 error position, 1 == whole string
*/
if (err == 0) {
return (1);
} else if (err < 0) {
err = 0;
}
return (0);
char *s = (char *)string;
/* free allocated buffer */
}
/* server not present */
/* special case Admin High and Admin Low */
while (isspace(*s))
s++;
if (IS_ADMIN_LOW(s)) {
} else if (IS_ADMIN_HIGH(s)) {
} else {
goto err1;
}
return (1);
}
/* free allocated buffer */
}
err1:
*error = -1;
return (0);
} /* stobclear */