/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* tnctl.c -
* Trusted Network control utility
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <fcntl.h>
#include <netdb.h>
#include <libtsnet.h>
#include <zone.h>
#include <nss_dbdefs.h>
static void process_rh(const char *);
static void process_rhl(const char *);
static void process_mlp(const char *);
static void process_tp(const char *);
static void process_tpl(const char *);
static void process_tnzone(const char *);
static void usage(void);
static void translate_inet_addr(tsol_rhent_t *, int *, char [], int);
int
{
extern char *optarg;
int chr;
/* Don't do anything if labeling is not active. */
if (!is_system_labeled())
return (0);
/* set the locale for only the messages system (all else is clean) */
#ifndef TEXT_DOMAIN /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (chr) {
case 'd':
break;
case 'f':
flush_mode = B_TRUE;
break;
case 'h':
break;
case 'H':
break;
case 'm':
break;
case 't':
break;
case 'T':
break;
case 'v':
break;
case 'z':
break;
case '?':
usage();
}
}
return (0);
}
static void
{
if (linenum > 0)
else
}
/*
* Produce ascii format of address and prefix length
*/
static void
{
void *aptr;
abuflen);
"tnctl: buffer overflow detected: %s\n"),
abuf);
}
} else {
abuflen);
"tnctl: buffer overflow detected: %s\n"),
abuf);
}
}
}
/*
* Load remote host entries from the designated file.
*/
static void
{
int alen;
/* abuf holds: <numeric-ip-addr>'/'<prefix-length>'\0' */
gettext("tnctl: failed to open %1$s: %2$s\n"),
exit(1);
}
tsol_setrhent(1);
/* First time through the loop, flush it all */
if (!success && flush_mode)
if (verbose_mode)
(void) printf("loading rh entry...\n");
perror("tnrh");
else
sizeof (abuf));
gettext("tnctl: load of remote-host entry "
"%1$s into kernel cache failed: %2$s\n"),
exit(1);
}
}
if (!success) {
gettext("tnctl: No valid tnrhdb entries found in %s\n"),
file);
}
if (error)
exit(1);
}
/*
* The argument can be either a host name, an address
* in tnrhdb address format, or a complete tnrhdb entry.
*/
static void
{
int err;
int alen;
char *errstr;
/* abuf holds: <numeric-ip-addr>'/'<prefix-length>'\0' */
const char *cp;
char *cp1;
char *cp2;
void *aptr;
/* was a template name provided on the command line? */
/* use common tnrhdb line conversion function */
sizeof (buf));
exit(1);
}
} else {
char *hostname_p;
char *prefix_p;
/* Check for a subnet prefix length */
errno = 0;
"prefix length: %s\n"), cp);
exit(2);
}
} else {
}
/* Strip any backslashes from numeric address */
if (hostname_p == NULL) {
perror("tnctl");
exit(2);
}
cp1 = hostname_p;
if (*cp1 != '\\')
cp1++;
}
*cp1 = '\0';
/* Convert address or hostname to binary af_inet6 format */
"or invalid literal address: %s\n"), hostname_p);
gettext("\t(try again later)\n"));
exit(2);
}
/* if ipv4 address, convert to af_inet format */
if (IN6_IS_ADDR_V4MAPPED(&ipv6addr)) {
} else {
}
}
/* produce ascii format of address and prefix length */
/*
* look up the entry from ldap or tnrhdb if this is a load
* request and a template name was not provided.
*/
if (!delete_mode &&
gettext("tnctl: database lookup failed for %s\n"),
abuf);
exit(1);
}
if (verbose_mode)
"loading", abuf);
/* update the tnrhdb entry in the kernel */
perror("tnrh");
gettext("tnctl: %1$s of remote-host kernel cache "
"entry %2$s failed: no such entry\n"),
abuf);
else
gettext("tnctl: %1$s of remote-host kernel cache "
"entry %2$s failed: %3$s\n"),
exit(1);
}
}
static void
{
while (!TSOL_MLP_END(mlp)) {
/*
* Usage of ?: here is ugly, but helps with
* localization.
*/
flags & TSOL_MEF_SHARED ?
gettext("tnctl: cannot set "
"shared MLP on %1$d-%2$d/%3$d: %4$s\n") :
gettext("tnctl: cannot set "
"zone-specific MLP on %1$d-%2$d/%3$d: %4$s\n"),
exit(1);
}
mlp++;
}
}
/*
* This reads the configuration for the global zone out of tnzonecfg
* and sets it in the kernel. The non-global zones are configured
* by zoneadmd.
*/
static void
{
int err;
char *errstr;
exit(1);
}
*cp = '\0';
linenum++;
if (err == LTSNET_EMPTY)
continue;
if (errors == 0) {
"parsing %s:\n"), file);
}
errors++;
continue;
}
break;
}
exit(1);
}
tsme.tsme_flags = 0;
if (flush_mode)
}
static void
{
exit(1);
}
tsol_settpent(1);
/* First time through the loop, flush it all */
if (!success && flush_mode)
if (verbose_mode)
(void) printf("tnctl: loading rhtp entry ...\n");
perror("tnrhtp");
else
"of remote-host template %1$s into kernel "
exit(1);
}
}
if (!success) {
gettext("tnctl: No valid tnrhtp entries found in %s\n"),
file);
}
if (error)
exit(1);
}
static void
{
int err;
char *errstr;
sizeof (buf));
exit(1);
}
} else if (delete_mode) {
exit(1);
}
if (verbose_mode)
"loading");
perror("tnrhtp");
gettext("tnctl: %1$s of remote-host template "
"kernel cache entry %2$s failed: no such "
"entry\n"),
else
gettext("tnctl: %1$s of remote-host template "
"kernel cache entry %2$s failed: %3$s\n"),
exit(1);
}
}
static void
{
const char *cp;
int err;
char *errstr;
char *sbuf;
if (!delete_mode) {
gettext("tnctl: need MLP list to insert\n"));
exit(2);
}
exit(2);
} else {
}
zonename);
exit(1);
}
perror("malloc");
exit(1);
}
/* LINTED: sprintf is known not to be unbounded here */
gettext("tnctl: unable to parse MLPs\n"));
exit(1);
}
}
static void
usage(void)
{
"[-h host[/prefix][:tmpl]] [-m zone:priv:share]\n\t"
"[-t tmpl[:key=val[;key=val]]] [-[HTz] file]\n"));
exit(1);
}