cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * or http://www.opensolaris.org/os/licensing.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#pragma ident "%Z%%M% %I% %E% SMI"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Routines to handle tsol_getrhbyaddr calls in nscd
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <string.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <stdlib.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <sys/types.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <libtsnet.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "cache.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define tsol_rh_db ctx->nsc_db[0]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSC_NAME_TSOL_RH_BYADDR "tsol_getrhbyaddr"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int tsol_rh_compar(const void *, const void *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t tsol_rh_gethash(nss_XbyY_key_t *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void tsol_rh_getlogstr(char *, char *, size_t, nss_XbyY_args_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjltnrhdb_init_ctx(nsc_ctx_t *ctx) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->dbname = NSS_DBNAM_TSOL_RH;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->db_count = 1;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->file_name = TNRHDB_PATH;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl tsol_rh_db = make_cache(nsc_key_other,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSS_DBOP_TSOL_RH_BYADDR,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSC_NAME_TSOL_RH_BYADDR,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl tsol_rh_compar,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl tsol_rh_getlogstr,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl tsol_rh_gethash, nsc_ht_default, -1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void
cb5caa98562cf06753163f558cbcfe30b8f4673adjltsol_rh_getlogstr(char *name, char *whoami, size_t len,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nss_XbyY_args_t *argp) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(whoami, len, "%s [key=%s, len=%d, addrtype=%d]",
cb5caa98562cf06753163f558cbcfe30b8f4673adjl name, argp->key.hostaddr.addr, argp->key.hostaddr.len,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl argp->key.hostaddr.type);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int
cb5caa98562cf06753163f558cbcfe30b8f4673adjltsol_rh_compar(const void *n1, const void *n2) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *e1, *e2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int res, l1, l2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e1 = (nsc_entry_t *)n1;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e2 = (nsc_entry_t *)n2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (e1->key.hostaddr.type > e2->key.hostaddr.type)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl else if (e1->key.hostaddr.type < e2->key.hostaddr.type)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (-1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl l1 = strlen(e1->key.hostaddr.addr);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl l2 = strlen(e2->key.hostaddr.addr);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl res = strncasecmp(e1->key.hostaddr.addr, e2->key.hostaddr.addr,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (l1 > l2)?l1:l2);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (_NSC_INT_KEY_CMP(res, 0));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t
cb5caa98562cf06753163f558cbcfe30b8f4673adjltsol_rh_gethash(nss_XbyY_key_t *key, int htsize) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (db_gethash(key->hostaddr.addr,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl strlen(key->hostaddr.addr), htsize));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}