tsol_sgettpent.c revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk/*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER START
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * The contents of this file are subject to the terms of the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Common Development and Distribution License (the "License").
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You may not use this file except in compliance with the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * or http://www.opensolaris.org/os/licensing.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * See the License for the specific language governing permissions
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * and limitations under the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * When distributing Covered Code, include this CDDL HEADER in each
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * If applicable, add the following below this CDDL HEADER, with the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * fields enclosed by brackets "[]" replaced with your own identifying
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * information: Portions Copyright [yyyy] [name of copyright owner]
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER END
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk/*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Use is subject to license terms.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * From "tsol_tndb_parser.c 7.24 01/09/05 SMI; TSOL 2.x"
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * These functions parse entries in the "tnrhtp" (remote host template) file.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Each entry in this file has two fields, separated by a colon. The first
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * field is the template name. The second is a list of "key=value" attributes,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * separated by semicolons.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * In order to help preserve sanity, we do not allow more than one unescaped
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * colon in a line, nor any unescaped '=' or ';' characters in the template
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * name. Such things are indicative of typing errors, not intentional
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * configuration.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#pragma ident "%Z%%M% %I% %E% SMI"
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <stdio.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <ctype.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <stdlib.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <stddef.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <string.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <strings.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <libtsnet.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <tsol/label.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <sys/types.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <nss.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <secdb.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#include <errno.h>
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkstatic int
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkget_tn_doi(tsol_tpent_t *tpentp, kva_t *kv)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *cp;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *val = NULL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_DOI);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_DOI);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk errno = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_doi = strtol(val, &cp, 0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (errno != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_SYSERR);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (*cp != '\0')
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_DOI);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkstatic int
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkget_tn_sl_range(brange_t *range, char *min, char *max)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk int err = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (min == NULL && max == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_RANGE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (min == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_LOWERBOUND);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (max == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_UPPERBOUND);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (stobsl(min, &range->lower_bound, NO_CORRECTION, &err) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_LOWERBOUND);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (stobsl(max, &range->upper_bound, NO_CORRECTION, &err) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_UPPERBOUND);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (!bldominates(&range->upper_bound, &range->lower_bound))
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_RANGE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkstatic int
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkget_tn_sl_set(blset_t *labelset, char *setstr)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk int sc, err;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *tokp, *finally;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk bslabel_t *labels;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) memset(labelset, 0, sizeof (blset_t));
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk labels = (bslabel_t *)labelset;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tokp = strtok_r(setstr, TNDB_COMMA, &finally);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk for (sc = 0; tokp != NULL && sc < NSLS_MAX; sc++) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (stobsl(tokp, &labels[sc], NO_CORRECTION, &err) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_LABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tokp = strtok_r(NULL, TNDB_COMMA, &finally);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (tokp != NULL && sc >= NSLS_MAX)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_SET_TOO_BIG);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkstatic int
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkparse_remainder(tsol_tpent_t *tpentp, kva_t *kv)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk int err = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *val = NULL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *val2 = NULL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_HOSTTYPE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_HOSTTYPE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (strcasecmp(val, TP_UNLABELED) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->host_type = UNLABELED;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk else if (strcasecmp(val, TP_CIPSO) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->host_type = SUN_CIPSO;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk else
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_HOSTTYPE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * parse fields by host type -
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * add on to the following if statement for each new host type.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (tpentp->host_type == UNLABELED) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_unl = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * doi
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if ((err = get_tn_doi(tpentp, kv)) != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_unl |= TSOL_MSK_CIPSO_DOI;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * default label
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_DEFLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_NO_LABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (stobsl(val, &tpentp->tp_def_label, NO_CORRECTION,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk &err) == 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_ILL_LABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_unl |= TSOL_MSK_DEF_LABEL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * check label range
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_MINLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val2 = kva_match(kv, TP_MAXLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val == NULL && val2 == NULL) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * This is the old format. Use ADMIN_LOW to SL of the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * default label as the gw_sl_range.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk bsllow(&tpentp->tp_gw_sl_range.lower_bound);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_gw_sl_range.upper_bound =
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_def_label;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk } else {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk err = get_tn_sl_range(&tpentp->tp_gw_sl_range, val,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val2);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (err != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_unl |= TSOL_MSK_SL_RANGE_TSOL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * also label set, if present. (optional)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_SET);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val != NULL) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk err = get_tn_sl_set(&tpentp->tp_gw_sl_set, val);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (err != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_cipso |= TSOL_MSK_SL_RANGE_TSOL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk } else {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_cipso = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * doi
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if ((err = get_tn_doi(tpentp, kv)) != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_cipso |= TSOL_MSK_CIPSO_DOI;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * label range
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_MINLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val2 = kva_match(kv, TP_MAXLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk err = get_tn_sl_range(&tpentp->tp_sl_range_cipso, val, val2);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (err != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_cipso |= TSOL_MSK_SL_RANGE_TSOL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * also label set, if present. (optional)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_SET);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val != NULL) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk err = get_tn_sl_set(&tpentp->tp_sl_set_cipso, val);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (err != 0)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (err);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tpentp->tp_mask_cipso |= TSOL_MSK_SL_RANGE_TSOL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /* CIPSO entries don't support default labels */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk val = kva_match(kv, TP_DEFLABEL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (val != NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (LTSNET_BAD_TYPE);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpktsol_tpent_t *
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpktpstr_to_ent(tsol_tpstr_t *tpstrp, int *errp, char **errstrp)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk int err = 0;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *errstr;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *template = tpstrp->template;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *attrs = tpstrp->attrs;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk kva_t *kv;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tsol_tpent_t *tpentp = NULL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * The user can specify NULL pointers for these. Make sure that we
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * don't have to deal with checking for NULL everywhere by just
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * pointing to our own variables if the user gives NULL.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (errp == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk errp = &err;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (errstrp == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk errstrp = &errstr;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /* The default, unless we find a more specific error locus. */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errstrp = template;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (template == NULL || *template == '#' || *template == '\n') {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errp = LTSNET_EMPTY;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (attrs && *attrs != '\0' && *attrs != '#' && *attrs != '\n')
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errstrp = attrs;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk else if (template == NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errstrp = " ";
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk goto err_ret;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (*template == '\0') {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errp = LTSNET_NO_NAME;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (attrs && *attrs != '\0' && *attrs != '#' && *attrs != '\n')
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errstrp = attrs;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk goto err_ret;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (attrs == NULL || *attrs == '\0' || *attrs == '#' ||
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *attrs == '\n') {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errp = LTSNET_NO_ATTRS;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk goto err_ret;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if ((tpentp = calloc(1, sizeof (*tpentp))) == NULL) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errp = LTSNET_SYSERR;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (NULL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (strlcpy(tpentp->name, template, sizeof (tpentp->name)) >=
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk sizeof (tpentp->name))
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk goto err_ret;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk kv = _str2kva(attrs, KV_ASSIGN, KV_DELIMITER);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errp = parse_remainder(tpentp, kv);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk _kva_free(kv);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (*errp == 0) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#ifdef DEBUG
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) fprintf(stdout, "tpstr_to_ent: %s:%s\n", tpentp->name,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk attrs);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (tpentp);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk }
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkerr_ret:
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk err = errno;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk tsol_freetpent(tpentp);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk errno = err;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#ifdef DEBUG
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) fprintf(stderr, "\ntpstr_to_ent: %s:%s\n",
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk *errstrp, (char *)tsol_strerror(*errp, errno));
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (NULL);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkvoid
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpktsol_freetpent(tsol_tpent_t *tp)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk{
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (tp != NULL)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk free(tp);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk}