8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / nscd / gettnrhdb.c
blobb42a51b6e85d9c5dd4fc340dd18da2d961fa078c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines to handle tsol_getrhbyaddr calls in nscd
32 #include <string.h>
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <libtsnet.h>
36 #include "cache.h"
38 #define tsol_rh_db ctx->nsc_db[0]
40 #define NSC_NAME_TSOL_RH_BYADDR "tsol_getrhbyaddr"
42 static int tsol_rh_compar(const void *, const void *);
43 static uint_t tsol_rh_gethash(nss_XbyY_key_t *, int);
44 static void tsol_rh_getlogstr(char *, char *, size_t, nss_XbyY_args_t *);
46 void
47 tnrhdb_init_ctx(nsc_ctx_t *ctx) {
48 ctx->dbname = NSS_DBNAM_TSOL_RH;
49 ctx->db_count = 1;
50 ctx->file_name = TNRHDB_PATH;
52 tsol_rh_db = make_cache(nsc_key_other,
53 NSS_DBOP_TSOL_RH_BYADDR,
54 NSC_NAME_TSOL_RH_BYADDR,
55 tsol_rh_compar,
56 tsol_rh_getlogstr,
57 tsol_rh_gethash, nsc_ht_default, -1);
60 static void
61 tsol_rh_getlogstr(char *name, char *whoami, size_t len,
62 nss_XbyY_args_t *argp) {
64 (void) snprintf(whoami, len, "%s [key=%s, len=%d, addrtype=%d]",
65 name, argp->key.hostaddr.addr, argp->key.hostaddr.len,
66 argp->key.hostaddr.type);
69 static int
70 tsol_rh_compar(const void *n1, const void *n2) {
71 nsc_entry_t *e1, *e2;
72 int res, l1, l2;
74 e1 = (nsc_entry_t *)n1;
75 e2 = (nsc_entry_t *)n2;
77 if (e1->key.hostaddr.type > e2->key.hostaddr.type)
78 return (1);
79 else if (e1->key.hostaddr.type < e2->key.hostaddr.type)
80 return (-1);
82 l1 = strlen(e1->key.hostaddr.addr);
83 l2 = strlen(e2->key.hostaddr.addr);
84 res = strncasecmp(e1->key.hostaddr.addr, e2->key.hostaddr.addr,
85 (l1 > l2)?l1:l2);
86 return (_NSC_INT_KEY_CMP(res, 0));
89 static uint_t
90 tsol_rh_gethash(nss_XbyY_key_t *key, int htsize) {
91 return (db_gethash(key->hostaddr.addr,
92 strlen(key->hostaddr.addr), htsize));