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]
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 gethost* calls in nscd
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
40 #define hnam_db ctx->nsc_db[0]
41 #define addr_db ctx->nsc_db[1]
43 #define NSC_NAME_HOSTS_BYNAME "gethostbyname"
44 #define NSC_NAME_HOSTS_BYADDR "gethostbyaddr"
46 static int hostaddr_compar(const void *, const void *);
47 static uint_t
hostaddr_gethash(nss_XbyY_key_t
*, int);
48 static void hostaddr_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
51 host_init_ctx(nsc_ctx_t
*ctx
) {
52 ctx
->dbname
= NSS_DBNAM_HOSTS
;
54 ctx
->file_name
= "/etc/inet/hosts";
56 hnam_db
= make_cache(nsc_key_cis
,
57 NSS_DBOP_HOSTS_BYNAME
,
58 NSC_NAME_HOSTS_BYNAME
,
59 NULL
, NULL
, NULL
, nsc_ht_default
, -1);
61 addr_db
= make_cache(nsc_key_other
,
62 NSS_DBOP_HOSTS_BYADDR
,
63 NSC_NAME_HOSTS_BYADDR
,
66 hostaddr_gethash
, nsc_ht_default
, -1);
70 hostaddr_getlogstr(char *name
, char *whoami
, size_t len
,
71 nss_XbyY_args_t
*argp
) {
72 char addr
[INET6_ADDRSTRLEN
];
74 if (inet_ntop(argp
->key
.hostaddr
.type
, argp
->key
.hostaddr
.addr
, addr
,
75 sizeof (addr
)) == NULL
) {
76 (void) snprintf(whoami
, len
, "%s", name
);
78 (void) snprintf(whoami
, len
, "%s [key=%s, addrtype=%d]",
79 name
, addr
, argp
->key
.hostaddr
.type
);
84 hostaddr_compar(const void *n1
, const void *n2
) {
88 e1
= (nsc_entry_t
*)n1
;
89 e2
= (nsc_entry_t
*)n2
;
90 l1
= e1
->key
.hostaddr
.len
;
91 l2
= e2
->key
.hostaddr
.len
;
92 res
= memcmp(e1
->key
.hostaddr
.addr
, e2
->key
.hostaddr
.addr
,
94 return ((res
) ? _NSC_INT_KEY_CMP(res
, 0) : _NSC_INT_KEY_CMP(l1
, l2
));
98 hostaddr_gethash(nss_XbyY_key_t
*key
, int htsize
) {
99 return (db_gethash(key
->hostaddr
.addr
,
100 key
->hostaddr
.len
, htsize
));