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