tnctl.c revision f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * CDDL HEADER START
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * The contents of this file are subject to the terms of the
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Common Development and Distribution License (the "License").
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * You may not use this file except in compliance with the License.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * or http://www.opensolaris.org/os/licensing.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * See the License for the specific language governing permissions
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * and limitations under the License.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * When distributing Covered Code, include this CDDL HEADER in each
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * If applicable, add the following below this CDDL HEADER, with the
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * fields enclosed by brackets "[]" replaced with your own identifying
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * information: Portions Copyright [yyyy] [name of copyright owner]
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * CDDL HEADER END
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Use is subject to license terms.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#pragma ident "%Z%%M% %I% %E% SMI"
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * tnctl.c -
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Trusted Network control utility
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <stdio.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <stdlib.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <stddef.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <unistd.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <string.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <errno.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <locale.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <fcntl.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <sys/types.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <sys/param.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <sys/socket.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <netinet/in.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <arpa/inet.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <netdb.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <libtsnet.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <zone.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#include <nss_dbdefs.h>
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_rh(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_rhl(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_mlp(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_tp(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_tpl(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void process_tnzone(const char *);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void usage(void);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic boolean_t verbose_mode;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic boolean_t delete_mode;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic boolean_t flush_mode;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaint
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricamain(int argc, char **argv)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica extern char *optarg;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int chr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* Don't do anything if labeling is not active. */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!is_system_labeled())
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica return (0);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* set the locale for only the messages system (all else is clean) */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) setlocale(LC_ALL, "");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#ifndef TEXT_DOMAIN /* Should be defined by cc -D */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica#endif
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) textdomain(TEXT_DOMAIN);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while ((chr = getopt(argc, argv, "dfh:H:m:t:T:vz:")) != EOF) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica switch (chr) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'd':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode = B_TRUE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'f':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica flush_mode = B_TRUE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'h':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_rh(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'H':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_rhl(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'm':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_mlp(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 't':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_tp(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'T':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_tpl(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'v':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica verbose_mode = B_TRUE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case 'z':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica process_tnzone(optarg);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica case '?':
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica usage();
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica return (0);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprint_error(int linenum, int err, const char *errstr)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (linenum > 0)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("line %1$d: %2$s:\n"), linenum,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_strerror(err, errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnctl: parsing error: %s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_strerror(err, errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, "%.32s\n", errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Load remote host entries from the designated file.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_rhl(const char *file)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica boolean_t success = B_FALSE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_rhent_t *rhentp = NULL;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica FILE *fp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((fp = fopen(file, "r")) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: failed to open %1$s: %2$s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica file, strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_setrhent(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while (rhentp = tsol_fgetrhent(fp)) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* First time through the loop, flush it all */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!success && flush_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) tnrh(TNDB_FLUSH, NULL);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica success = B_TRUE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (verbose_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) printf("loading rh entry...\n");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tnrh(TNDB_LOAD, rhentp) != 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fclose(fp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (errno == EFAULT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("tnrh");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: load of remote-host entry "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "%1$s into kernel cache failed: %2$s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhentp->rh_template, strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_endrhent();
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freerhent(rhentp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!success) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: No valid tnrhdb entries found in %s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica file);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fclose(fp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_endrhent();
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * The argument can be either a host name, an address
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * in tnrhdb address format, or a complete tnrhdb entry.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_rh(const char *hostname)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_rhstr_t rhstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_rhent_t rhent;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_rhent_t *rhentp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int err;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int alen;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *errstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* abuf holds: <numeric-ip-addr>'/'<prefix-length>'\0' */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char abuf[INET6_ADDRSTRLEN+5];
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica const char *cp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *cp1;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *cp2;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica void *aptr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char buf[NSS_BUFLEN_TSOL_RH];
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica struct in6_addr ipv6addr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* was a template name provided on the command line? */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((cp = strrchr(hostname, ':')) != NULL && cp != hostname &&
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp[-1] != '\\') {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* use common tnrhdb line conversion function */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) str_to_rhstr(hostname, strlen(hostname), &rhstr, buf,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica sizeof (buf));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhentp = rhstr_to_ent(&rhstr, &err, &errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhentp == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica print_error(0, err, errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *hostname_p;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *prefix_p;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica struct hostent *hp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* Check for a subnet prefix length */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((prefix_p = strchr(hostname, '/')) != NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp1 = prefix_p + 1;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica errno = 0;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_prefix = strtol(cp1, &cp2, 0);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (*cp2 != '\0' || errno != 0 || rhent.rh_prefix < 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnct: invalid "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "prefix length: %s\n"), cp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(2);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_prefix = -1;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* Strip any backslashes from numeric address */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica hostname_p = malloc(strlen(hostname)+1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (hostname_p == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("tnctl");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(2);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp1 = hostname_p;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while (*hostname != '\0' && *hostname != '/') {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *cp1 = *hostname++;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (*cp1 != '\\')
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp1++;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *cp1 = '\0';
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* Convert address or hostname to binary af_inet6 format */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica hp = getipnodebyname(hostname_p, AF_INET6,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica AI_ALL | AI_ADDRCONFIG | AI_V4MAPPED, &err);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (hp == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnctl: unknown host "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "or invalid literal address: %s\n"), hostname_p);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (err == TRY_AGAIN)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("\t(try again later)\n"));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(2);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica free(hostname_p);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) memcpy(&ipv6addr, hp->h_addr, hp->h_length);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* if ipv4 address, convert to af_inet format */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (IN6_IS_ADDR_V4MAPPED(&ipv6addr)) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_address.ta_family = AF_INET;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica IN6_V4MAPPED_TO_INADDR(&ipv6addr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica &rhent.rh_address.ta_addr_v4);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhent.rh_prefix == -1)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_prefix = 32;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_address.ta_family = AF_INET6;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_address.ta_addr_v6 = ipv6addr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhent.rh_prefix == -1)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_prefix = 128;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_template[0] = '\0';
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhentp = &rhent;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* produce ascii format of address and prefix length */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhentp->rh_address.ta_family == AF_INET6) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica aptr = &(rhentp->rh_address.ta_addr_v6);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica alen = sizeof (ipv6addr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) inet_ntop(rhentp->rh_address.ta_family, aptr, abuf,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica sizeof (abuf));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhentp->rh_prefix != 128) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp1 = abuf + strlen(abuf);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) sprintf(cp1, "/%d", rhentp->rh_prefix);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica aptr = &(rhentp->rh_address.ta_addr_v4);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica alen = sizeof (rhent.rh_address.ta_addr_v4);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) inet_ntop(rhentp->rh_address.ta_family, aptr, abuf,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica sizeof (abuf));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhentp->rh_prefix != 32) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica cp1 = abuf + strlen(abuf);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) sprintf(cp1, "/%d", rhentp->rh_prefix);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * look up the entry from ldap or tnrhdb if this is a load
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * request and a template name was not provided.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!delete_mode &&
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhentp->rh_template[0] == '\0' &&
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (rhentp = tsol_getrhbyaddr(abuf, alen,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica rhent.rh_address.ta_family)) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: database lookup failed for %s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica abuf);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (verbose_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) printf("%s rh entry %s\n", delete_mode ? "deleting" :
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "loading", abuf);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* update the tnrhdb entry in the kernel */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tnrh(delete_mode ? TNDB_DELETE : TNDB_LOAD, rhentp) != 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (errno == EFAULT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("tnrh");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else if (errno == ENOENT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: %1$s of remote-host kernel cache "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "entry %2$s failed: no such entry\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? gettext("delete") : gettext("load"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica abuf);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: %1$s of remote-host kernel cache "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "entry %2$s failed: %3$s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? gettext("delete") : gettext("load"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica abuf, strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (rhentp != &rhent)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freerhent(rhentp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricahandle_mlps(zoneid_t zoneid, tsol_mlp_t *mlp, int flags, int cmd)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_mlpent_t tsme;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsme.tsme_zoneid = zoneid;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsme.tsme_flags = flags;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while (!TSOL_MLP_END(mlp)) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsme.tsme_mlp = *mlp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tnmlp(cmd, &tsme) != 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * Usage of ?: here is ugly, but helps with
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * localization.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica flags & TSOL_MEF_SHARED ?
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: cannot set "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "shared MLP on %1$d-%2$d/%3$d: %4$s\n") :
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: cannot set "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "zone-specific MLP on %1$d-%2$d/%3$d: %4$s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica mlp->mlp_port, mlp->mlp_port_upper, mlp->mlp_ipp,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica mlp++;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica/*
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * This reads the configuration for the global zone out of tnzonecfg
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * and sets it in the kernel. The non-global zones are configured
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica * by zoneadmd.
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_tnzone(const char *file)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_zcent_t *zc;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_mlpent_t tsme;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int err;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *errstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica FILE *fp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char line[2048], *cp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int linenum, errors;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((fp = fopen(file, "r")) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: failed to open %s: %s\n"), file,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica linenum = errors = 0;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica zc = NULL;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while (fgets(line, sizeof (line), fp) != NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((cp = strchr(line, '\n')) != NULL)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica *cp = '\0';
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica linenum++;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((zc = tsol_sgetzcent(line, &err, &errstr)) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (err == LTSNET_EMPTY)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica continue;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (errors == 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int errtmp = errno;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnctl: errors "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "parsing %s:\n"), file);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica errno = errtmp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica print_error(linenum, err, errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica errors++;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica continue;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (strcasecmp(zc->zc_name, "global") == 0)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica break;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freezcent(zc);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fclose(fp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (zc == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: cannot find global zone in %s\n"), file);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsme.tsme_zoneid = GLOBAL_ZONEID;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsme.tsme_flags = 0;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (flush_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) tnmlp(TNDB_FLUSH, &tsme);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica handle_mlps(GLOBAL_ZONEID, zc->zc_private_mlp, 0, TNDB_LOAD);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica handle_mlps(GLOBAL_ZONEID, zc->zc_shared_mlp, TSOL_MEF_SHARED,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica TNDB_LOAD);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freezcent(zc);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_tpl(const char *file)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica FILE *fp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica boolean_t success = B_FALSE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_tpent_t *tpentp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((fp = fopen(file, "r")) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: failed to open %s: %s\n"), file,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_settpent(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica while (tpentp = tsol_fgettpent(fp)) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* First time through the loop, flush it all */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!success && flush_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) tnrhtp(TNDB_FLUSH, NULL);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica success = B_TRUE;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (verbose_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) printf("tnctl: loading rhtp entry ...\n");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tnrhtp(TNDB_LOAD, tpentp) != 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fclose(fp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (errno == EFAULT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("tnrhtp");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnctl: load "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "of remote-host template %1$s into kernel "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "cache failed: %2$s\n"), tpentp->name,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_endtpent();
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freetpent(tpentp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!success) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: No valid tnrhtp entries found in %s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica file);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fclose(fp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_endtpent();
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_tp(const char *template)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_tpstr_t tpstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_tpent_t tpent;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_tpent_t *tpentp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int err;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *errstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char buf[NSS_BUFLEN_TSOL_TP];
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (strchr(template, ':') != NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) str_to_tpstr(template, strlen(template), &tpstr, buf,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica sizeof (buf));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tpentp = tpstr_to_ent(&tpstr, &err, &errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tpentp == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica print_error(0, err, errstr);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else if (delete_mode) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) memset(&tpent, 0, sizeof (tpent));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tpentp = &tpent;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) strlcpy(tpentp->name, template, sizeof (tpentp->name));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else if ((tpentp = tsol_gettpbyname(template)) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: template %s not found\n"), template);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (verbose_mode)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) printf("%s rhtp entry ...\n", delete_mode ? "deleting" :
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "loading");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tnrhtp(delete_mode ? TNDB_DELETE : TNDB_LOAD, tpentp) != 0) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (errno == EFAULT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("tnrhtp");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else if (errno == ENOENT)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: %1$s of remote-host template "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "kernel cache entry %2$s failed: no such "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "entry\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? gettext("delete") : gettext("load"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tpentp->name);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica else
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: %1$s of remote-host template "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "kernel cache entry %2$s failed: %3$s\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? gettext("delete") : gettext("load"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tpentp->name, strerror(errno));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (tpentp != &tpent)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freetpent(tpentp);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricaprocess_mlp(const char *str)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica const char *cp;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char zonename[ZONENAME_MAX];
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica zoneid_t zoneid;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_zcent_t *zc;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica int err;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *errstr;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica char *sbuf;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((cp = strchr(str, ':')) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (!delete_mode) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: need MLP list to insert\n"));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(2);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) strlcpy(zonename, str, sizeof (zonename));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else if (cp - str >= ZONENAME_MAX) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tnctl: illegal zone name\n"));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(2);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica } else {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) memcpy(zonename, str, cp - str);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica zonename[cp - str] = '\0';
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica str = cp + 1;
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((zoneid = getzoneidbyname(zonename)) == -1) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("tninfo: zone '%s' unknown\n"),
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica zonename);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica sbuf = malloc(strlen(zonename) + sizeof (":ADMIN_LOW:0:") +
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica strlen(str));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if (sbuf == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica perror("malloc");
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica /* LINTED: sprintf is known not to be unbounded here */
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) sprintf(sbuf, "%s:ADMIN_LOW:0:%s", zonename, str);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica if ((zc = tsol_sgetzcent(sbuf, &err, &errstr)) == NULL) {
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica gettext("tnctl: unable to parse MLPs\n"));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica }
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica handle_mlps(zoneid, zc->zc_private_mlp, 0,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? TNDB_DELETE : TNDB_LOAD);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica handle_mlps(zoneid, zc->zc_shared_mlp, TSOL_MEF_SHARED,
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica delete_mode ? TNDB_DELETE : TNDB_LOAD);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica tsol_freezcent(zc);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricastatic void
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01ricausage(void)
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica{
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica (void) fprintf(stderr, gettext("usage: tnctl [-dfv] "
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "[-h host[/prefix][:tmpl]] [-m zone:priv:share]\n\t"
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica "[-t tmpl[:key=val[;key=val]]] [-[HTz] file]\n"));
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica exit(1);
f875b4ebb1dd9fdbeb043557cab38ab3bf7f6e01rica}