xref: /onnv-gate/usr/src/lib/nsswitch/ldap/common/tsol_gettpent.c (revision 2830:5228d1267a01)
11676Sjpk /*
21676Sjpk  * CDDL HEADER START
31676Sjpk  *
41676Sjpk  * The contents of this file are subject to the terms of the
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * You may not use this file except in compliance with the License.
71676Sjpk  *
81676Sjpk  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91676Sjpk  * or http://www.opensolaris.org/os/licensing.
101676Sjpk  * See the License for the specific language governing permissions
111676Sjpk  * and limitations under the License.
121676Sjpk  *
131676Sjpk  * When distributing Covered Code, include this CDDL HEADER in each
141676Sjpk  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151676Sjpk  * If applicable, add the following below this CDDL HEADER, with the
161676Sjpk  * fields enclosed by brackets "[]" replaced with your own identifying
171676Sjpk  * information: Portions Copyright [yyyy] [name of copyright owner]
181676Sjpk  *
191676Sjpk  * CDDL HEADER END
201676Sjpk  */
211676Sjpk /*
221676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
231676Sjpk  * Use is subject to license terms.
241676Sjpk  */
251676Sjpk 
261676Sjpk #pragma ident	"%Z%%M%	%I%	%E% SMI"
271676Sjpk 
281676Sjpk #include "ldap_common.h"
291676Sjpk #include <sys/tsol/tndb.h>
301676Sjpk 
311676Sjpk /* tnrhtp attributes filters */
321676Sjpk #define	_TNRHTP_NAME		"ipTnetTemplateName"
331676Sjpk #define	_TNRHTP_ATTRS		"SolarisAttrKeyValue"
341676Sjpk #define	_F_GETTNTPBYNAME	"(&(objectClass=ipTnetTemplate)"\
35*2830Sdjl 				"(!(objectClass=ipTnetHost))" \
361676Sjpk 				"(ipTnetTemplateName=%s))"
371676Sjpk #define	_F_GETTNTPBYNAME_SSD	"(&(%%s)(ipTnetTemplateName=%s))"
381676Sjpk 
391676Sjpk static const char *tnrhtp_attrs[] = {
401676Sjpk 	_TNRHTP_NAME,
411676Sjpk 	_TNRHTP_ATTRS,
421676Sjpk 	NULL
431676Sjpk };
441676Sjpk 
45*2830Sdjl /*
46*2830Sdjl  * _nss_ldap_tnrhtp2str is the data marshaling method for the tnrhtp
47*2830Sdjl  * (tsol_gettpbyaddr()/tsol_gettpent()) backend processes.
48*2830Sdjl  * This method is called after a successful ldap search has been performed.
49*2830Sdjl  * This method will parse the ldap search values into the file format.
50*2830Sdjl  *
51*2830Sdjl  * e.g.
52*2830Sdjl  *
53*2830Sdjl  * admin_low:host_type=unlabeled;def_label=[0x0000000000000000000000000000000000
54*2830Sdjl  * 0000000000000000000000000000000000];min_sl=0x00000000000000000000000000000000
55*2830Sdjl  * 000000000000000000000000000000000000;max_sl=0x7ffffffffffffffffffffffffffffff
56*2830Sdjl  * fffffffffffffffffffffffffffffffffffff;doi=0;
57*2830Sdjl  */
581676Sjpk static int
_nss_ldap_tnrhtp2str(ldap_backend_ptr be,nss_XbyY_args_t * argp)59*2830Sdjl _nss_ldap_tnrhtp2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
601676Sjpk {
61*2830Sdjl 	int			nss_result = NSS_STR_PARSE_SUCCESS;
621676Sjpk 	int			len = 0;
631676Sjpk 	char			*buffer = NULL;
64*2830Sdjl 	char			**attrs, **template;
651676Sjpk 	ns_ldap_result_t	*result = be->result;
661676Sjpk 
67*2830Sdjl 	if (result == NULL)
68*2830Sdjl 		return (NSS_STR_PARSE_PARSE);
69*2830Sdjl 
70*2830Sdjl 	template = __ns_ldap_getAttr(result->entry, _TNRHTP_NAME);
71*2830Sdjl 	if (template == NULL || template[0] == NULL ||
72*2830Sdjl 			(strlen(template[0]) < 1)) {
73*2830Sdjl 		nss_result = NSS_STR_PARSE_PARSE;
74*2830Sdjl 		goto result_tnrhtp2str;
751676Sjpk 	}
76*2830Sdjl 	attrs = __ns_ldap_getAttr(result->entry, _TNRHTP_ATTRS);
77*2830Sdjl 	if (attrs == NULL || attrs[0] == NULL || (strlen(attrs[0]) < 1)) {
781676Sjpk 		nss_result = NSS_STR_PARSE_PARSE;
79*2830Sdjl 		goto result_tnrhtp2str;
801676Sjpk 	}
81*2830Sdjl 
82*2830Sdjl 	/* "template:attrs" */
83*2830Sdjl 	len = strlen(template[0]) + strlen(attrs[0]) + 2;
84*2830Sdjl 
85*2830Sdjl 	if (argp->buf.result != NULL) {
86*2830Sdjl 		if ((be->buffer = calloc(1, len)) == NULL) {
87*2830Sdjl 			nss_result = NSS_STR_PARSE_PARSE;
88*2830Sdjl 			goto result_tnrhtp2str;
891676Sjpk 		}
90*2830Sdjl 		be->buflen = len - 1;
91*2830Sdjl 		buffer = be->buffer;
92*2830Sdjl 	} else
93*2830Sdjl 		buffer = argp->buf.buffer;
941676Sjpk 
95*2830Sdjl 	(void) snprintf(buffer, len, "%s:%s", template[0], attrs[0]);
961676Sjpk 
97*2830Sdjl result_tnrhtp2str:
981676Sjpk 	(void) __ns_ldap_freeResult(&be->result);
991676Sjpk 	return (nss_result);
1001676Sjpk }
1011676Sjpk 
1021676Sjpk static nss_status_t
getbyname(ldap_backend_ptr be,void * a)1031676Sjpk getbyname(ldap_backend_ptr be, void *a)
1041676Sjpk {
1051676Sjpk 	char		searchfilter[SEARCHFILTERLEN];
1061676Sjpk 	char		userdata[SEARCHFILTERLEN];
1071676Sjpk 	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
1081676Sjpk 
109*2830Sdjl 	if (argp->key.name == NULL)
110*2830Sdjl 		return (NSS_NOTFOUND);
1111676Sjpk 
1121676Sjpk 	if (snprintf(searchfilter, SEARCHFILTERLEN, _F_GETTNTPBYNAME,
1131676Sjpk 	    argp->key.name) < 0)
1141676Sjpk 		return ((nss_status_t)NSS_NOTFOUND);
1151676Sjpk 
1161676Sjpk 	if (snprintf(userdata, sizeof (userdata), _F_GETTNTPBYNAME_SSD,
1171676Sjpk 	    argp->key.name) < 0)
1181676Sjpk 		return ((nss_status_t)NSS_NOTFOUND);
1191676Sjpk 
1201676Sjpk 	return (_nss_ldap_lookup(be, argp, _TNRHTP, searchfilter, NULL,
1211676Sjpk 	    _merge_SSD_filter, userdata));
1221676Sjpk }
1231676Sjpk 
1241676Sjpk 
1251676Sjpk static ldap_backend_op_t tnrhtp_ops[] = {
1261676Sjpk 	_nss_ldap_destr,
1271676Sjpk 	_nss_ldap_endent,
1281676Sjpk 	_nss_ldap_setent,
1291676Sjpk 	_nss_ldap_getent,
1301676Sjpk 	getbyname
1311676Sjpk };
1321676Sjpk 
133*2830Sdjl /* ARGSUSED */
1341676Sjpk nss_backend_t *
_nss_ldap_tnrhtp_constr(const char * dummy1,const char * dummy2,const char * dummy3,const char * dummy4,const char * dummy5)1351676Sjpk _nss_ldap_tnrhtp_constr(const char *dummy1,
1361676Sjpk     const char *dummy2,
1371676Sjpk     const char *dummy3,
1381676Sjpk     const char *dummy4,
1391676Sjpk     const char *dummy5)
1401676Sjpk {
1411676Sjpk 	return ((nss_backend_t *)_nss_ldap_constr(tnrhtp_ops,
1421676Sjpk 		sizeof (tnrhtp_ops)/sizeof (tnrhtp_ops[0]), _TNRHTP,
143*2830Sdjl 		tnrhtp_attrs, _nss_ldap_tnrhtp2str));
1441676Sjpk }
145