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 <rpc/rpcent.h>
2N/A#include "ns_internal.h"
2N/A#include "ldap_common.h"
2N/A
2N/A/* rpc attributes filters */
2N/A#define _R_NAME "cn"
2N/A#define _R_NUMBER "oncrpcnumber"
2N/A
2N/A
2N/A#define _F_GETRPCBYNAME "(&(objectClass=oncRpc)(cn=%s))"
2N/A#define _F_GETRPCBYNAME_SSD "(&(%%s)(cn=%s))"
2N/A#define _F_GETRPCBYNUMBER "(&(objectClass=oncRpc)(oncRpcNumber=%d))"
2N/A#define _F_GETRPCBYNUMBER_SSD "(&(%%s)(oncRpcNumber=%d))"
2N/A
2N/Astatic const char *rpc_attrs[] = {
2N/A _R_NAME,
2N/A _R_NUMBER,
2N/A (char *)NULL
2N/A};
2N/A
2N/A/*
2N/A * _nss_ldap_rpc2str is the data marshaling method for the rpc getXbyY
2N/A * (e.g., getbyname(), getbynumber(), getrpcent()) 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 * e.g.
2N/A *
2N/A * nfs_acl 100227
2N/A * snmp 100122 na.snmp snmp-cmc snmp-synoptics snmp-unisys snmp-utk
2N/A */
2N/Astatic int
2N/A_nss_ldap_rpc2str(ldap_backend_ptr be, nss_XbyY_args_t *argp)
2N/A{
2N/A uint_t i;
2N/A int nss_result;
2N/A int buflen = 0, len;
2N/A char *cname = NULL;
2N/A char *buffer = NULL;
2N/A ns_ldap_result_t *result = be->result;
2N/A ns_ldap_attr_t *names;
2N/A char **rpcnumber;
2N/A
2N/A if (result == NULL)
2N/A return (NSS_STR_PARSE_PARSE);
2N/A nss_result = NSS_STR_PARSE_SUCCESS;
2N/A (void) memset(argp->buf.buffer, 0, buflen);
2N/A
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_rpc2str;
2N/A }
2N/A buffer = be->buffer;
2N/A } else
2N/A buffer = argp->buf.buffer;
2N/A
2N/A
2N/A names = __ns_ldap_getAttrStruct(result->entry, _R_NAME);
2N/A if (names == NULL || names->attrvalue == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_rpc2str;
2N/A }
2N/A /* Get the canonical rpc name */
2N/A cname = __s_api_get_canonical_name(result->entry, names, 1);
2N/A if (cname == NULL || (len = strlen(cname)) < 1) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_rpc2str;
2N/A }
2N/A rpcnumber = __ns_ldap_getAttr(result->entry, _R_NUMBER);
2N/A if (rpcnumber == NULL || rpcnumber[0] == NULL ||
2N/A (len = strlen(rpcnumber[0])) < 1) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_rpc2str;
2N/A }
2N/A len = snprintf(buffer, buflen, "%s %s", cname, rpcnumber[0]);
2N/A TEST_AND_ADJUST(len, buffer, buflen, result_rpc2str);
2N/A /* Append aliases */
2N/A for (i = 0; i < names->value_count; i++) {
2N/A if (names->attrvalue[i] == NULL) {
2N/A nss_result = NSS_STR_PARSE_PARSE;
2N/A goto result_rpc2str;
2N/A }
2N/A /* Skip the canonical name */
2N/A if (strcasecmp(names->attrvalue[i], cname) != 0) {
2N/A len = snprintf(buffer, buflen, " %s",
2N/A names->attrvalue[i]);
2N/A TEST_AND_ADJUST(len, buffer, buflen, result_rpc2str);
2N/A }
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_rpc2str:
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 struct rpcent values by rpc name. This function
2N/A * constructs an ldap search filter using the rpc name invocation
2N/A * parameter and the getrpcbyname search filter defined. Once the
2N/A * filter is constructed, we search for a matching entry and marshal
2N/A * the data results into *rpc = (struct rpcent *)argp->buf.result.
2N/A * The function _nss_ldap_rpc2ent performs the data marshaling.
2N/A */
2N/A
2N/Astatic nss_status_t
2N/Agetbyname(ldap_backend_ptr be, void *a)
2N/A{
2N/A nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
2N/A char searchfilter[SEARCHFILTERLEN];
2N/A char userdata[SEARCHFILTERLEN];
2N/A char name[SEARCHFILTERLEN];
2N/A int ret;
2N/A
2N/A if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A ret = snprintf(searchfilter, sizeof (searchfilter), _F_GETRPCBYNAME,
2N/A name);
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), _F_GETRPCBYNAME_SSD, name);
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return ((nss_status_t)_nss_ldap_lookup(be, argp, _RPC, searchfilter,
2N/A NULL, _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * getbynumber gets struct rpcent values by rpc number. This function
2N/A * constructs an ldap search filter using the rpc number invocation
2N/A * parameter and the getrpcbynumber search filter defined. Once the
2N/A * filter is constructed, we search for a matching entry and marshal
2N/A * the data results into *rpc = (struct rpcent *)argp->buf.result.
2N/A * The function _nss_ldap_rpc2ent performs the data marshaling.
2N/A */
2N/A
2N/Astatic nss_status_t
2N/Agetbynumber(ldap_backend_ptr be, void *a)
2N/A{
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 ret = snprintf(searchfilter, sizeof (searchfilter),
2N/A _F_GETRPCBYNUMBER, argp->key.number);
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_GETRPCBYNUMBER_SSD, argp->key.number);
2N/A if (ret >= sizeof (userdata) || ret < 0)
2N/A return ((nss_status_t)NSS_NOTFOUND);
2N/A
2N/A return ((nss_status_t)_nss_ldap_lookup(be, argp, _RPC, searchfilter,
2N/A NULL, _merge_SSD_filter, userdata));
2N/A}
2N/A
2N/A
2N/Astatic ldap_backend_op_t rpc_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 getbynumber
2N/A};
2N/A
2N/A
2N/A/*
2N/A * _nss_ldap_rpc_constr is where life begins. This function calls the generic
2N/A * ldap constructor function to define and build the abstract data types
2N/A * required to support ldap operations.
2N/A */
2N/A
2N/A/*ARGSUSED0*/
2N/Anss_backend_t *
2N/A_nss_ldap_rpc_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(rpc_ops,
2N/A sizeof (rpc_ops)/sizeof (rpc_ops[0]),
2N/A _RPC, rpc_attrs, _nss_ldap_rpc2str));
2N/A}