misc.c revision e34b029407ed5ec566196ede3f54256d7868dd10
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* From "misc.c 5.15 00/05/31 SMI; TSOL 2.x"
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Miscellaneous user interfaces to trusted label functions.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <libintl.h>
#include <libtsnet.h>
#define MAX_STRING_SIZE 256
#define MAX_ATTR_LEN 1024
/*
* Parse off an entry from a line. Entry is stored in 'outbuf'. Returned
* value is a pointer to the first unprocessed input character from 'instr'.
*/
const char *
const char *delimit)
{
char chr;
/*
* User may specify outlen as 0 to skip over a field without storing
* it anywhere. Otherwise, we need at least one byte for the
* terminating NUL plus one byte to store another byte from instr.
*/
if (!escape_state) {
if (chr == '\\') {
continue;
}
break;
break;
}
if (outlen > 0) {
outlen--;
}
}
if (outlen != 1)
instr--;
if (escape_state)
instr--;
if (outlen > 0)
*outbuf = '\0';
return (instr);
}
const char *
{
const char *sl_str;
static const char unknown_str[] = "UNKNOWN";
return (unknown_str);
return (sl_str);
}
static const char *rtsa_keywords[] = {
#define SAK_MINSL 0
"min_sl",
#define SAK_MAXSL 1
"max_sl",
#define SAK_DOI 2
"doi",
#define SAK_CIPSO 3
"cipso",
#define SAK_SL 4
"sl",
#define SAK_INVAL 5
};
const char *
{
slen = 0;
*line = '\0';
continue;
if (!(i & mask))
continue;
if (slen != 0)
switch (i & mask) {
case RTSA_MINSL:
if ((mask & RTSA_MAXSL) &&
"sl=%s",
mask ^= RTSA_MAXSL;
break;
}
break;
case RTSA_MAXSL:
break;
case RTSA_DOI:
break;
case RTSA_CIPSO:
break;
}
}
return (line);
}
{
int key;
char attrbuf[MAX_ATTR_LEN];
const char **keyword;
int err;
while (*options != '\0') {
if (attrbuf[0] == '\0') {
*errp = LTSNET_ILL_ENTRY;
return (B_FALSE);
}
break;
*errp = LTSNET_ILL_KEY;
return (B_FALSE);
}
return (B_FALSE);
}
if (*valptr == '=') {
valptr++;
valptr, ",=");
if (*nxtopt == '=') {
return (B_FALSE);
}
}
if (*nxtopt == ',')
nxtopt++;
switch (key) {
case SAK_MINSL:
if (mask & RTSA_MINSL) {
*errp = LTSNET_DUP_KEY;
return (B_FALSE);
}
&err) != 1) {
return (B_FALSE);
}
mask |= RTSA_MINSL;
break;
case SAK_MAXSL:
if (mask & RTSA_MAXSL) {
*errp = LTSNET_DUP_KEY;
return (B_FALSE);
}
&err) != 1) {
return (B_FALSE);
}
mask |= RTSA_MAXSL;
break;
case SAK_SL:
*errp = LTSNET_DUP_KEY;
return (B_FALSE);
}
&err) != 1) {
*errp = LTSNET_ILL_LABEL;
return (B_FALSE);
}
break;
case SAK_DOI:
*errp = LTSNET_DUP_KEY;
return (B_FALSE);
}
errno = 0;
*errp = LTSNET_ILL_DOI;
return (B_FALSE);
}
break;
case SAK_CIPSO:
if (mask & RTSA_CIPSO) {
*errp = LTSNET_DUP_KEY;
return (B_FALSE);
}
mask |= RTSA_CIPSO;
break;
}
}
/* Defaults to CIPSO if not specified */
mask |= RTSA_CIPSO;
/* If RTSA_CIPSO is specified, RTSA_DOI must be specified */
*errp = LTSNET_NO_DOI;
return (B_FALSE);
}
/* SL range must be specified */
*errp = LTSNET_NO_RANGE;
return (B_FALSE);
}
if (!(mask & RTSA_MINSL)) {
return (B_FALSE);
}
if (!(mask & RTSA_MAXSL)) {
return (B_FALSE);
}
/* SL range must have upper bound dominating lower bound */
*errp = LTSNET_ILL_RANGE;
return (B_FALSE);
}
if (mask & RTSA_MINSL)
if (mask & RTSA_MAXSL)
return (B_TRUE);
}
/* Keep in sync with libtsnet.h */
static const char *tsol_errlist[] = {
"No error",
"System error",
"Empty string or end of list",
"Entry is malformed",
"Missing name",
"Missing attributes",
"Illegal name",
"Illegal keyword delimiter",
"Unknown keyword",
"Duplicate keyword",
"Illegal value delimiter",
"Missing host type",
"Illegal host type",
"Missing label",
"Illegal label",
"Missing label range",
"Illegal label range",
"No lower bound in range",
"Illegal lower bound in range",
"No upper bound in range",
"Illegal upper bound in range",
"Missing DOI",
"Illegal DOI",
"Too many entries in set",
"Illegal flag",
"Illegal MLP specification",
"Unacceptable keyword for type"
};
const char *
{
if (libtserr == LTSNET_SYSERR)
return (gettext("Unknown error"));
}