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
2N/A/* bootparams attributes filters */
2N/A#define _B_HOSTNAME "cn"
2N/A#define _B_PARAMETER "bootparameter"
2N/A#define _F_GETBOOTPARAMBYNAME "(&(objectClass=bootableDevice)(cn=%s))"
2N/A#define _F_GETBOOTPARAMBYNAME_SSD "(&(%%s)(cn=%s))"
2N/A
2N/Astatic const char *bootparams_attrs[] = {
2N/A _B_HOSTNAME,
2N/A _B_PARAMETER,
2N/A (char *)NULL
2N/A};
2N/A
2N/A/*
2N/A * _nss_ldap_bootparams2str is the data marshaling method for the
2N/A * bootparams bootparams_getbyname 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 * A host's bootparameters are returned on one line separated by white
2N/A * space. The LDAP server stores each boot parameter as a separate entry.
2N/A * If more than one bootparameter is available, a white space separated buffer
2N/A * must be constructed and returned.
2N/A *
2N/A */
2N/A
2N/Astatic int
2N/A_nss_ldap_bootparams2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
2N/A{
2N/A uint_t i;
2N/A int buflen = 0, len = 0;
2N/A int nss_result, firsttime;
2N/A ns_ldap_attr_t *bparams;
2N/A char *buffer, **names;
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 buflen = argp->buf.buflen;
2N/A if (argp->buf.result != NULL) {
2N/A if ((be->buffer = calloc(1, buflen)) == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_bp2str;
2N/A }
2N/A buffer = be->buffer;
2N/A } else
2N/A buffer = argp->buf.buffer;
2N/A
2N/A nss_result = NSS_STR_PARSE_SUCCESS;
2N/A (void) memset(argp->buf.buffer, 0, buflen);
2N/A
2N/A names = __ns_ldap_getAttr(result->entry, _B_HOSTNAME);
2N/A if (names == NULL || names[0] == NULL ||
2N/A (strlen(names[0]) < 1)) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_bp2str;
2N/A }
2N/A bparams = __ns_ldap_getAttrStruct(result->entry, _B_PARAMETER);
2N/A if (bparams == NULL || bparams->attrvalue == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_bp2str;
2N/A }
2N/A firsttime = 1;
2N/A for (i = 0; i < bparams->value_count; i++) {
2N/A if (bparams->attrvalue[i] == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_bp2str;
2N/A }
2N/A /*
2N/A * Skip client host name. The early version of ldapaddent
2N/A * adds hostname as a boot param and it should be filtered.
2N/A */
2N/A if (strcasecmp(names[0], bparams->attrvalue[i]) != 0) {
2N/A if (firsttime) {
2N/A firsttime = 0;
2N/A len = snprintf(buffer, buflen, "%s",
2N/A bparams->attrvalue[i]);
2N/A } else
2N/A len = snprintf(buffer, buflen, " %s",
2N/A bparams->attrvalue[i]);
2N/A TEST_AND_ADJUST(len, buffer, buflen, result_bp2str);
2N/A }
2N/A }
2N/A /* The front end marshaller doesn't need to copy trailing nulls */
2N/A if (argp->buf.result != NULL)
2N/A be->buflen = strlen(be->buffer);
2N/A
2N/Aresult_bp2str:
2N/A
2N/A (void) __ns_ldap_freeResult(&be->result);
2N/A return (nss_result);
2N/A}
2N/A
2N/A/*
2N/A * getbyname gets bootparameters by host name. This function constructs an
2N/A * ldap search filter using the host name invocation parameter and the
2N/A * getbootparambyname search filter defined. Once the filter is
2N/A * constructed, we search for matching entries and marshal the data
2N/A * results into argp->buf.buffer for the frontend process. The function
2N/A * _nss_ldap_bootparams2ent performs the data marshaling.
2N/A *
2N/A * RFC 2307, An Approach for Using LDAP as a Network Information Service,
2N/A * indicates that dn's be fully qualified. Host name searches will be on
2N/A * fully qualified host names (e.g., foo.bar.sun.com).
2N/A */
2N/A
2N/Astatic nss_status_t
2N/Agetbyname(ldap_backend_ptr be, void *a)
2N/A{
2N/A char hostname[3 * MAXHOSTNAMELEN];
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A char searchfilter[SEARCHFILTERLEN];
2N/A char userdata[SEARCHFILTERLEN];
2N/A int ret;
2N/A
2N/A if (_ldap_filter_name(hostname, argp->key.name, sizeof (hostname)) != 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(searchfilter, sizeof (searchfilter),
2N/A _F_GETBOOTPARAMBYNAME, hostname);
2N/A if (ret >= sizeof (searchfilter) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(userdata, sizeof (userdata),
2N/A _F_GETBOOTPARAMBYNAME_SSD, hostname);
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A return ((nss_status_t)_nss_ldap_lookup(be, argp,
2N/A _BOOTPARAMS, searchfilter, NULL,
2N/A _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t bootparams_ops[] = {
2N/A _nss_ldap_destr,
2N/A getbyname
2N/A};
2N/A
2N/A
2N/A/*
2N/A * _nss_ldap_bootparams_constr is where life begins. This function calls
2N/A * the generic ldap constructor function to define and build the abstract
2N/A * data types required to support ldap operations.
2N/A */
2N/A
2N/A/*ARGSUSED0*/
2N/Anss_backend_t *
2N/A_nss_ldap_bootparams_constr(const char *dummy1, const char *dummy2,
2N/A const char *dummy3)
2N/A{
2N/A
2N/A return ((nss_backend_t *)_nss_ldap_constr(bootparams_ops,
2N/A sizeof (bootparams_ops)/sizeof (bootparams_ops[0]),
2N/A _BOOTPARAMS, bootparams_attrs, _nss_ldap_bootparams2str));
2N/A}