1*45916cd2Sjpk /*
2*45916cd2Sjpk  * CDDL HEADER START
3*45916cd2Sjpk  *
4*45916cd2Sjpk  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
7*45916cd2Sjpk  *
8*45916cd2Sjpk  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*45916cd2Sjpk  * or http://www.opensolaris.org/os/licensing.
10*45916cd2Sjpk  * See the License for the specific language governing permissions
11*45916cd2Sjpk  * and limitations under the License.
12*45916cd2Sjpk  *
13*45916cd2Sjpk  * When distributing Covered Code, include this CDDL HEADER in each
14*45916cd2Sjpk  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*45916cd2Sjpk  * If applicable, add the following below this CDDL HEADER, with the
16*45916cd2Sjpk  * fields enclosed by brackets "[]" replaced with your own identifying
17*45916cd2Sjpk  * information: Portions Copyright [yyyy] [name of copyright owner]
18*45916cd2Sjpk  *
19*45916cd2Sjpk  * CDDL HEADER END
20*45916cd2Sjpk  */
21*45916cd2Sjpk /*
22*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*45916cd2Sjpk  * Use is subject to license terms.
24*45916cd2Sjpk  */
25*45916cd2Sjpk 
26*45916cd2Sjpk #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*45916cd2Sjpk 
28*45916cd2Sjpk /*
29*45916cd2Sjpk  * ldapaddtsol.c
30*45916cd2Sjpk  *
31*45916cd2Sjpk  * Routines to add tnrhdb and tnrhtp from /etc/security/tsol into LDAP.
32*45916cd2Sjpk  * Can also be used to dump entries from a ldap container in /etc format.
33*45916cd2Sjpk  */
34*45916cd2Sjpk 
35*45916cd2Sjpk #include <stdio.h>
36*45916cd2Sjpk #include <stdlib.h>
37*45916cd2Sjpk #include <libintl.h>
38*45916cd2Sjpk #include <string.h>
39*45916cd2Sjpk #include <nss.h>
40*45916cd2Sjpk #include <secdb.h>
41*45916cd2Sjpk #include <sys/tsol/tndb.h>
42*45916cd2Sjpk #include "ldapaddent.h"
43*45916cd2Sjpk 
44*45916cd2Sjpk extern  int	genent_attr(char *, int, entry_col **);
45*45916cd2Sjpk 
46*45916cd2Sjpk int
genent_tnrhdb(char * line,int (* cback)())47*45916cd2Sjpk genent_tnrhdb(char *line, int (*cback)())
48*45916cd2Sjpk {
49*45916cd2Sjpk 	entry_col	*ecol;
50*45916cd2Sjpk 	tsol_rhstr_t	data;
51*45916cd2Sjpk 	int		res, retval;
52*45916cd2Sjpk 
53*45916cd2Sjpk 	/*
54*45916cd2Sjpk 	 * parse entry into columns
55*45916cd2Sjpk 	 */
56*45916cd2Sjpk 	res = genent_attr(line, TNRHDB_NCOL, &ecol);
57*45916cd2Sjpk 	if (res != GENENT_OK)
58*45916cd2Sjpk 		return (res);
59*45916cd2Sjpk 
60*45916cd2Sjpk 	data.address = _do_unescape(ecol[0].ec_value.ec_value_val);
61*45916cd2Sjpk 	data.template = ecol[1].ec_value.ec_value_val;
62*45916cd2Sjpk 	if (strchr(data.address, ':') == NULL)
63*45916cd2Sjpk 		data.family = AF_INET;
64*45916cd2Sjpk 	else
65*45916cd2Sjpk 		data.family = AF_INET6;
66*45916cd2Sjpk 
67*45916cd2Sjpk 	if (flags & F_VERBOSE)
68*45916cd2Sjpk 		(void) printf(gettext("Adding entry : %s\n"), data.address);
69*45916cd2Sjpk 
70*45916cd2Sjpk 	retval = (*cback)(&data, 1);
71*45916cd2Sjpk 	if (retval)
72*45916cd2Sjpk 		res = GENENT_CBERR;
73*45916cd2Sjpk 
74*45916cd2Sjpk 	free(ecol);
75*45916cd2Sjpk 
76*45916cd2Sjpk 	return (res);
77*45916cd2Sjpk }
78*45916cd2Sjpk 
79*45916cd2Sjpk void
dump_tnrhdb(ns_ldap_result_t * res)80*45916cd2Sjpk dump_tnrhdb(ns_ldap_result_t *res)
81*45916cd2Sjpk {
82*45916cd2Sjpk 	char	**value = NULL;
83*45916cd2Sjpk 
84*45916cd2Sjpk 	value = __ns_ldap_getAttr(res->entry, "ipTnetNumber");
85*45916cd2Sjpk 	if (value && value[0])
86*45916cd2Sjpk 		(void) printf("%s", value[0]);
87*45916cd2Sjpk 	else
88*45916cd2Sjpk 		return;
89*45916cd2Sjpk 
90*45916cd2Sjpk 	(void) putchar(':');
91*45916cd2Sjpk 	value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
92*45916cd2Sjpk 	if (value && value[0])
93*45916cd2Sjpk 		(void) printf("%s", value[0]);
94*45916cd2Sjpk 	(void) putchar('\n');
95*45916cd2Sjpk }
96*45916cd2Sjpk 
97*45916cd2Sjpk int
genent_tnrhtp(char * line,int (* cback)())98*45916cd2Sjpk genent_tnrhtp(char *line, int (*cback)())
99*45916cd2Sjpk {
100*45916cd2Sjpk 	entry_col	*ecol;
101*45916cd2Sjpk 	tsol_tpstr_t	data;
102*45916cd2Sjpk 	int		res, retval;
103*45916cd2Sjpk 
104*45916cd2Sjpk 	/*
105*45916cd2Sjpk 	 * parse entry into columns
106*45916cd2Sjpk 	 */
107*45916cd2Sjpk 	res = genent_attr(line, TNRHTP_NCOL, &ecol);
108*45916cd2Sjpk 	if (res != GENENT_OK)
109*45916cd2Sjpk 		return (res);
110*45916cd2Sjpk 
111*45916cd2Sjpk 	data.template = ecol[0].ec_value.ec_value_val;
112*45916cd2Sjpk 	data.attrs = ecol[1].ec_value.ec_value_val;
113*45916cd2Sjpk 
114*45916cd2Sjpk 	if (flags & F_VERBOSE)
115*45916cd2Sjpk 		(void) printf(gettext("Adding entry : %s\n"), data.template);
116*45916cd2Sjpk 
117*45916cd2Sjpk 	retval = (*cback)(&data, 1);
118*45916cd2Sjpk 	if (retval)
119*45916cd2Sjpk 		res = GENENT_CBERR;
120*45916cd2Sjpk 
121*45916cd2Sjpk 	free(ecol);
122*45916cd2Sjpk 
123*45916cd2Sjpk 	return (res);
124*45916cd2Sjpk }
125*45916cd2Sjpk 
126*45916cd2Sjpk void
dump_tnrhtp(ns_ldap_result_t * res)127*45916cd2Sjpk dump_tnrhtp(ns_ldap_result_t *res)
128*45916cd2Sjpk {
129*45916cd2Sjpk 	char	**value = NULL;
130*45916cd2Sjpk 
131*45916cd2Sjpk 	value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
132*45916cd2Sjpk 	if (value && value[0])
133*45916cd2Sjpk 		(void) printf("%s", value[0]);
134*45916cd2Sjpk 	else
135*45916cd2Sjpk 		return;
136*45916cd2Sjpk 
137*45916cd2Sjpk 	(void) putchar(':');
138*45916cd2Sjpk 	value = __ns_ldap_getAttr(res->entry, "SolarisAttrKeyValue");
139*45916cd2Sjpk 	if (value && value[0])
140*45916cd2Sjpk 		(void) printf("%s", value[0]);
141*45916cd2Sjpk 	(void) putchar('\n');
142*45916cd2Sjpk }
143