2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "ldap_common.h"
2N/A#include <sys/tsol/tndb.h>
2N/A
2N/A/* tnrhtp attributes filters */
2N/A#define _TNRHTP_NAME "ipTnetTemplateName"
2N/A#define _TNRHTP_ATTRS "SolarisAttrKeyValue"
2N/A#define _F_GETTNTPBYNAME "(&(objectClass=ipTnetTemplate)"\
2N/A "(!(objectClass=ipTnetHost))" \
2N/A "(ipTnetTemplateName=%s))"
2N/A#define _F_GETTNTPBYNAME_SSD "(&(%%s)(ipTnetTemplateName=%s))"
2N/A
2N/Astatic const char *tnrhtp_attrs[] = {
2N/A _TNRHTP_NAME,
2N/A _TNRHTP_ATTRS,
2N/A NULL
2N/A};
2N/A
2N/A/*
2N/A * _nss_ldap_tnrhtp2str is the data marshaling method for the tnrhtp
2N/A * (tsol_gettpbyaddr()/tsol_gettpent()) backend processes.
2N/A * This method is called after a successful ldap search has been performed.
2N/A * This method will parse the ldap search values into the file format.
2N/A *
2N/A * e.g.
2N/A *
2N/A * admin_low:host_type=unlabeled;def_label=[0x0000000000000000000000000000000000
2N/A * 0000000000000000000000000000000000];min_sl=0x00000000000000000000000000000000
2N/A * 000000000000000000000000000000000000;max_sl=0x7ffffffffffffffffffffffffffffff
2N/A * fffffffffffffffffffffffffffffffffffff;doi=0;
2N/A */
2N/Astatic int
2N/A_nss_ldap_tnrhtp2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
2N/A{
2N/A int nss_result = NSS_STR_PARSE_SUCCESS;
2N/A int len = 0;
2N/A char *buffer = NULL;
2N/A char **attrs, **template;
2N/A ns_ldap_result_t *result = be->result;
2N/A
2N/A if (result == NULL)
2N/A return (NSS_STR_PARSE_PARSE);
2N/A
2N/A template = __ns_ldap_getAttr(result->entry, _TNRHTP_NAME);
2N/A if (template == NULL || template[0] == NULL ||
2N/A (strlen(template[0]) < 1)) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_tnrhtp2str;
2N/A }
2N/A attrs = __ns_ldap_getAttr(result->entry, _TNRHTP_ATTRS);
2N/A if (attrs == NULL || attrs[0] == NULL || (strlen(attrs[0]) < 1)) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_tnrhtp2str;
2N/A }
2N/A
2N/A /* "template:attrs" */
2N/A len = strlen(template[0]) + strlen(attrs[0]) + 2;
2N/A
2N/A if (argp->buf.result != NULL) {
2N/A if ((be->buffer = calloc(1, len)) == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_tnrhtp2str;
2N/A }
2N/A be->buflen = len - 1;
2N/A buffer = be->buffer;
2N/A } else
2N/A buffer = argp->buf.buffer;
2N/A
2N/A (void) snprintf(buffer, len, "%s:%s", template[0], attrs[0]);
2N/A
2N/Aresult_tnrhtp2str:
2N/A (void) __ns_ldap_freeResult(&be->result);
2N/A return (nss_result);
2N/A}
2N/A
2N/Astatic nss_status_t
2N/Agetbyname(ldap_backend_ptr be, void *a)
2N/A{
2N/A char searchfilter[SEARCHFILTERLEN];
2N/A char userdata[SEARCHFILTERLEN];
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A
2N/A if (argp->key.name == NULL)
2N/A return (NSS_NOTFOUND);
2N/A
2N/A if (snprintf(searchfilter, SEARCHFILTERLEN, _F_GETTNTPBYNAME,
2N/A argp->key.name) < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A if (snprintf(userdata, sizeof (userdata), _F_GETTNTPBYNAME_SSD,
2N/A argp->key.name) < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return (_nss_ldap_lookup(be, argp, _TNRHTP, searchfilter, NULL,
2N/A _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t tnrhtp_ops[] = {
2N/A _nss_ldap_destr,
2N/A _nss_ldap_endent,
2N/A _nss_ldap_setent,
2N/A _nss_ldap_getent,
2N/A getbyname
2N/A};
2N/A
2N/A/* ARGSUSED */
2N/Anss_backend_t *
2N/A_nss_ldap_tnrhtp_constr(const char *dummy1,
2N/A const char *dummy2,
2N/A const char *dummy3,
2N/A const char *dummy4,
2N/A const char *dummy5)
2N/A{
2N/A return ((nss_backend_t *)_nss_ldap_constr(tnrhtp_ops,
2N/A sizeof (tnrhtp_ops)/sizeof (tnrhtp_ops[0]), _TNRHTP,
2N/A tnrhtp_attrs, _nss_ldap_tnrhtp2str));
2N/A}