1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A/*
2N/A * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A
1N/A/*
1N/A * ldapaddtsol.c
1N/A *
1N/A * Routines to add tnrhdb and tnrhtp from /etc/security/tsol into LDAP.
1N/A * Can also be used to dump entries from a ldap container in /etc format.
1N/A */
1N/A
1N/A#include <stdio.h>
1N/A#include <stdlib.h>
1N/A#include <libintl.h>
1N/A#include <string.h>
1N/A#include <nss.h>
1N/A#include <secdb.h>
1N/A#include <sys/tsol/tndb.h>
1N/A#include "ldapaddent.h"
1N/A
1N/Aextern int genent_attr(char *, int, entry_col **);
1N/A
1N/Aint
1N/Agenent_tnrhdb(char *line, int (*cback)())
1N/A{
1N/A entry_col *ecol;
1N/A tsol_rhstr_t data;
1N/A int res, retval;
1N/A
1N/A /*
1N/A * parse entry into columns
1N/A */
1N/A res = genent_attr(line, TNRHDB_NCOL, &ecol);
1N/A if (res != GENENT_OK)
1N/A return (res);
1N/A
1N/A data.address = _do_unescape(ecol[0].ec_value.ec_value_val);
2N/A data.rhstr_template = ecol[1].ec_value.ec_value_val;
1N/A if (strchr(data.address, ':') == NULL)
1N/A data.family = AF_INET;
1N/A else
1N/A data.family = AF_INET6;
1N/A
1N/A if (flags & F_VERBOSE)
1N/A (void) printf(gettext("Adding entry : %s\n"), data.address);
1N/A
1N/A retval = (*cback)(&data, 1);
1N/A if (retval)
1N/A res = GENENT_CBERR;
1N/A
1N/A free(ecol);
1N/A
1N/A return (res);
1N/A}
1N/A
1N/Avoid
1N/Adump_tnrhdb(ns_ldap_result_t *res)
1N/A{
1N/A char **value = NULL;
1N/A
1N/A value = __ns_ldap_getAttr(res->entry, "ipTnetNumber");
1N/A if (value && value[0])
1N/A (void) printf("%s", value[0]);
1N/A else
1N/A return;
1N/A
1N/A (void) putchar(':');
1N/A value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
1N/A if (value && value[0])
1N/A (void) printf("%s", value[0]);
1N/A (void) putchar('\n');
1N/A}
1N/A
1N/Aint
1N/Agenent_tnrhtp(char *line, int (*cback)())
1N/A{
1N/A entry_col *ecol;
1N/A tsol_tpstr_t data;
1N/A int res, retval;
1N/A
1N/A /*
1N/A * parse entry into columns
1N/A */
1N/A res = genent_attr(line, TNRHTP_NCOL, &ecol);
1N/A if (res != GENENT_OK)
1N/A return (res);
1N/A
2N/A data.tpstr_template = ecol[0].ec_value.ec_value_val;
1N/A data.attrs = ecol[1].ec_value.ec_value_val;
1N/A
1N/A if (flags & F_VERBOSE)
2N/A (void) printf(gettext("Adding entry : %s\n"),
2N/A data.tpstr_template);
1N/A
1N/A retval = (*cback)(&data, 1);
1N/A if (retval)
1N/A res = GENENT_CBERR;
1N/A
1N/A free(ecol);
1N/A
1N/A return (res);
1N/A}
1N/A
1N/Avoid
1N/Adump_tnrhtp(ns_ldap_result_t *res)
1N/A{
1N/A char **value = NULL;
1N/A
1N/A value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
1N/A if (value && value[0])
1N/A (void) printf("%s", value[0]);
1N/A else
1N/A return;
1N/A
1N/A (void) putchar(':');
1N/A value = __ns_ldap_getAttr(res->entry, "SolarisAttrKeyValue");
1N/A if (value && value[0])
1N/A (void) printf("%s", value[0]);
1N/A (void) putchar('\n');
1N/A}