xref: /titanic_52/usr/src/cmd/ldap/ns_ldap/ldapaddtsol.c (revision b02e9a2d4d2071d770e5aa9ae8f83f2bbe1f2ced)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * ldapaddtsol.c
30  *
31  * Routines to add tnrhdb and tnrhtp from /etc/security/tsol into LDAP.
32  * Can also be used to dump entries from a ldap container in /etc format.
33  */
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <libintl.h>
38 #include <string.h>
39 #include <nss.h>
40 #include <secdb.h>
41 #include <sys/tsol/tndb.h>
42 #include "ldapaddent.h"
43 
44 extern  int	genent_attr(char *, int, entry_col **);
45 
46 int
47 genent_tnrhdb(char *line, int (*cback)())
48 {
49 	entry_col	*ecol;
50 	tsol_rhstr_t	data;
51 	int		res, retval;
52 
53 	/*
54 	 * parse entry into columns
55 	 */
56 	res = genent_attr(line, TNRHDB_NCOL, &ecol);
57 	if (res != GENENT_OK)
58 		return (res);
59 
60 	data.address = _do_unescape(ecol[0].ec_value.ec_value_val);
61 	data.template = ecol[1].ec_value.ec_value_val;
62 	if (strchr(data.address, ':') == NULL)
63 		data.family = AF_INET;
64 	else
65 		data.family = AF_INET6;
66 
67 	if (flags & F_VERBOSE)
68 		(void) printf(gettext("Adding entry : %s\n"), data.address);
69 
70 	retval = (*cback)(&data, 1);
71 	if (retval)
72 		res = GENENT_CBERR;
73 
74 	free(ecol);
75 
76 	return (res);
77 }
78 
79 void
80 dump_tnrhdb(ns_ldap_result_t *res)
81 {
82 	char	**value = NULL;
83 
84 	value = __ns_ldap_getAttr(res->entry, "ipTnetNumber");
85 	if (value && value[0])
86 		(void) printf("%s", value[0]);
87 	else
88 		return;
89 
90 	(void) putchar(':');
91 	value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
92 	if (value && value[0])
93 		(void) printf("%s", value[0]);
94 	(void) putchar('\n');
95 }
96 
97 int
98 genent_tnrhtp(char *line, int (*cback)())
99 {
100 	entry_col	*ecol;
101 	tsol_tpstr_t	data;
102 	int		res, retval;
103 
104 	/*
105 	 * parse entry into columns
106 	 */
107 	res = genent_attr(line, TNRHTP_NCOL, &ecol);
108 	if (res != GENENT_OK)
109 		return (res);
110 
111 	data.template = ecol[0].ec_value.ec_value_val;
112 	data.attrs = ecol[1].ec_value.ec_value_val;
113 
114 	if (flags & F_VERBOSE)
115 		(void) printf(gettext("Adding entry : %s\n"), data.template);
116 
117 	retval = (*cback)(&data, 1);
118 	if (retval)
119 		res = GENENT_CBERR;
120 
121 	free(ecol);
122 
123 	return (res);
124 }
125 
126 void
127 dump_tnrhtp(ns_ldap_result_t *res)
128 {
129 	char	**value = NULL;
130 
131 	value = __ns_ldap_getAttr(res->entry, "ipTnetTemplateName");
132 	if (value && value[0])
133 		(void) printf("%s", value[0]);
134 	else
135 		return;
136 
137 	(void) putchar(':');
138 	value = __ns_ldap_getAttr(res->entry, "SolarisAttrKeyValue");
139 	if (value && value[0])
140 		(void) printf("%s", value[0]);
141 	(void) putchar('\n');
142 }
143