145916cd2Sjpk /*
245916cd2Sjpk * CDDL HEADER START
345916cd2Sjpk *
445916cd2Sjpk * The contents of this file are subject to the terms of the
545916cd2Sjpk * Common Development and Distribution License (the "License").
645916cd2Sjpk * You may not use this file except in compliance with the License.
745916cd2Sjpk *
845916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
945916cd2Sjpk * or http://www.opensolaris.org/os/licensing.
1045916cd2Sjpk * See the License for the specific language governing permissions
1145916cd2Sjpk * and limitations under the License.
1245916cd2Sjpk *
1345916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each
1445916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1545916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the
1645916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying
1745916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner]
1845916cd2Sjpk *
1945916cd2Sjpk * CDDL HEADER END
2045916cd2Sjpk */
2145916cd2Sjpk /*
2245916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2345916cd2Sjpk * Use is subject to license terms.
2445916cd2Sjpk */
2545916cd2Sjpk
2645916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI"
2745916cd2Sjpk
2845916cd2Sjpk #include "ldap_common.h"
2945916cd2Sjpk #include <sys/tsol/tndb.h>
3045916cd2Sjpk
3145916cd2Sjpk /* tnrhtp attributes filters */
3245916cd2Sjpk #define _TNRHTP_NAME "ipTnetTemplateName"
3345916cd2Sjpk #define _TNRHTP_ATTRS "SolarisAttrKeyValue"
3445916cd2Sjpk #define _F_GETTNTPBYNAME "(&(objectClass=ipTnetTemplate)"\
35*cb5caa98Sdjl "(!(objectClass=ipTnetHost))" \
3645916cd2Sjpk "(ipTnetTemplateName=%s))"
3745916cd2Sjpk #define _F_GETTNTPBYNAME_SSD "(&(%%s)(ipTnetTemplateName=%s))"
3845916cd2Sjpk
3945916cd2Sjpk static const char *tnrhtp_attrs[] = {
4045916cd2Sjpk _TNRHTP_NAME,
4145916cd2Sjpk _TNRHTP_ATTRS,
4245916cd2Sjpk NULL
4345916cd2Sjpk };
4445916cd2Sjpk
45*cb5caa98Sdjl /*
46*cb5caa98Sdjl * _nss_ldap_tnrhtp2str is the data marshaling method for the tnrhtp
47*cb5caa98Sdjl * (tsol_gettpbyaddr()/tsol_gettpent()) backend processes.
48*cb5caa98Sdjl * This method is called after a successful ldap search has been performed.
49*cb5caa98Sdjl * This method will parse the ldap search values into the file format.
50*cb5caa98Sdjl *
51*cb5caa98Sdjl * e.g.
52*cb5caa98Sdjl *
53*cb5caa98Sdjl * admin_low:host_type=unlabeled;def_label=[0x0000000000000000000000000000000000
54*cb5caa98Sdjl * 0000000000000000000000000000000000];min_sl=0x00000000000000000000000000000000
55*cb5caa98Sdjl * 000000000000000000000000000000000000;max_sl=0x7ffffffffffffffffffffffffffffff
56*cb5caa98Sdjl * fffffffffffffffffffffffffffffffffffff;doi=0;
57*cb5caa98Sdjl */
5845916cd2Sjpk static int
_nss_ldap_tnrhtp2str(ldap_backend_ptr be,nss_XbyY_args_t * argp)59*cb5caa98Sdjl _nss_ldap_tnrhtp2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
6045916cd2Sjpk {
61*cb5caa98Sdjl int nss_result = NSS_STR_PARSE_SUCCESS;
6245916cd2Sjpk int len = 0;
6345916cd2Sjpk char *buffer = NULL;
64*cb5caa98Sdjl char **attrs, **template;
6545916cd2Sjpk ns_ldap_result_t *result = be->result;
6645916cd2Sjpk
67*cb5caa98Sdjl if (result == NULL)
68*cb5caa98Sdjl return (NSS_STR_PARSE_PARSE);
69*cb5caa98Sdjl
70*cb5caa98Sdjl template = __ns_ldap_getAttr(result->entry, _TNRHTP_NAME);
71*cb5caa98Sdjl if (template == NULL || template[0] == NULL ||
72*cb5caa98Sdjl (strlen(template[0]) < 1)) {
73*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE;
74*cb5caa98Sdjl goto result_tnrhtp2str;
75*cb5caa98Sdjl }
76*cb5caa98Sdjl attrs = __ns_ldap_getAttr(result->entry, _TNRHTP_ATTRS);
77*cb5caa98Sdjl if (attrs == NULL || attrs[0] == NULL || (strlen(attrs[0]) < 1)) {
78*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE;
79*cb5caa98Sdjl goto result_tnrhtp2str;
80*cb5caa98Sdjl }
81*cb5caa98Sdjl
82*cb5caa98Sdjl /* "template:attrs" */
83*cb5caa98Sdjl len = strlen(template[0]) + strlen(attrs[0]) + 2;
84*cb5caa98Sdjl
85*cb5caa98Sdjl if (argp->buf.result != NULL) {
86*cb5caa98Sdjl if ((be->buffer = calloc(1, len)) == NULL) {
87*cb5caa98Sdjl nss_result = NSS_STR_PARSE_PARSE;
88*cb5caa98Sdjl goto result_tnrhtp2str;
89*cb5caa98Sdjl }
90*cb5caa98Sdjl be->buflen = len - 1;
91*cb5caa98Sdjl buffer = be->buffer;
92*cb5caa98Sdjl } else
9345916cd2Sjpk buffer = argp->buf.buffer;
9445916cd2Sjpk
95*cb5caa98Sdjl (void) snprintf(buffer, len, "%s:%s", template[0], attrs[0]);
9645916cd2Sjpk
97*cb5caa98Sdjl result_tnrhtp2str:
9845916cd2Sjpk (void) __ns_ldap_freeResult(&be->result);
9945916cd2Sjpk return (nss_result);
10045916cd2Sjpk }
10145916cd2Sjpk
10245916cd2Sjpk static nss_status_t
getbyname(ldap_backend_ptr be,void * a)10345916cd2Sjpk getbyname(ldap_backend_ptr be, void *a)
10445916cd2Sjpk {
10545916cd2Sjpk char searchfilter[SEARCHFILTERLEN];
10645916cd2Sjpk char userdata[SEARCHFILTERLEN];
10745916cd2Sjpk nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
10845916cd2Sjpk
109*cb5caa98Sdjl if (argp->key.name == NULL)
110*cb5caa98Sdjl return (NSS_NOTFOUND);
11145916cd2Sjpk
11245916cd2Sjpk if (snprintf(searchfilter, SEARCHFILTERLEN, _F_GETTNTPBYNAME,
11345916cd2Sjpk argp->key.name) < 0)
11445916cd2Sjpk return ((nss_status_t)NSS_NOTFOUND);
11545916cd2Sjpk
11645916cd2Sjpk if (snprintf(userdata, sizeof (userdata), _F_GETTNTPBYNAME_SSD,
11745916cd2Sjpk argp->key.name) < 0)
11845916cd2Sjpk return ((nss_status_t)NSS_NOTFOUND);
11945916cd2Sjpk
12045916cd2Sjpk return (_nss_ldap_lookup(be, argp, _TNRHTP, searchfilter, NULL,
12145916cd2Sjpk _merge_SSD_filter, userdata));
12245916cd2Sjpk }
12345916cd2Sjpk
12445916cd2Sjpk
12545916cd2Sjpk static ldap_backend_op_t tnrhtp_ops[] = {
12645916cd2Sjpk _nss_ldap_destr,
12745916cd2Sjpk _nss_ldap_endent,
12845916cd2Sjpk _nss_ldap_setent,
12945916cd2Sjpk _nss_ldap_getent,
13045916cd2Sjpk getbyname
13145916cd2Sjpk };
13245916cd2Sjpk
133*cb5caa98Sdjl /* ARGSUSED */
13445916cd2Sjpk nss_backend_t *
_nss_ldap_tnrhtp_constr(const char * dummy1,const char * dummy2,const char * dummy3,const char * dummy4,const char * dummy5)13545916cd2Sjpk _nss_ldap_tnrhtp_constr(const char *dummy1,
13645916cd2Sjpk const char *dummy2,
13745916cd2Sjpk const char *dummy3,
13845916cd2Sjpk const char *dummy4,
13945916cd2Sjpk const char *dummy5)
14045916cd2Sjpk {
14145916cd2Sjpk return ((nss_backend_t *)_nss_ldap_constr(tnrhtp_ops,
14245916cd2Sjpk sizeof (tnrhtp_ops)/sizeof (tnrhtp_ops[0]), _TNRHTP,
143*cb5caa98Sdjl tnrhtp_attrs, _nss_ldap_tnrhtp2str));
14445916cd2Sjpk }
145