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