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 getserv* calls in nscd
36 #define name_db ctx->nsc_db[0]
37 #define port_db ctx->nsc_db[1]
39 #define NSC_NAME_SERVICES_BYNAME "getservbyname"
40 #define NSC_NAME_SERVICES_BYPORT "getservbyport"
42 static void servname_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
43 static int servname_compar(const void *, const void *);
44 static uint_t
servname_gethash(nss_XbyY_key_t
*, int);
46 static void servport_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
47 static int servport_compar(const void *, const void *);
48 static uint_t
servport_gethash(nss_XbyY_key_t
*, int);
51 serv_init_ctx(nsc_ctx_t
*ctx
) {
52 ctx
->dbname
= NSS_DBNAM_SERVICES
;
53 ctx
->file_name
= "/etc/services";
55 name_db
= make_cache(nsc_key_other
,
56 NSS_DBOP_SERVICES_BYNAME
,
57 NSC_NAME_SERVICES_BYNAME
,
60 servname_gethash
, nsc_ht_default
, -1);
62 port_db
= make_cache(nsc_key_other
,
63 NSS_DBOP_SERVICES_BYPORT
,
64 NSC_NAME_SERVICES_BYPORT
,
67 servport_gethash
, nsc_ht_default
, -1);
71 servname_compar(const void *n1
, const void *n2
) {
75 e1
= (nsc_entry_t
*)n1
;
76 e2
= (nsc_entry_t
*)n2
;
78 /* compare protocol */
79 if (e1
->key
.serv
.proto
== NULL
&& e2
->key
.serv
.proto
)
81 if (e1
->key
.serv
.proto
&& e2
->key
.serv
.proto
== NULL
)
83 if (e1
->key
.serv
.proto
) {
84 l1
= strlen(e1
->key
.serv
.proto
);
85 l2
= strlen(e2
->key
.serv
.proto
);
86 res
= strncmp(e1
->key
.serv
.proto
, e2
->key
.serv
.proto
,
94 /* compare service name */
95 l1
= strlen(e1
->key
.serv
.serv
.name
);
96 l2
= strlen(e2
->key
.serv
.serv
.name
);
97 res
= strncmp(e1
->key
.serv
.serv
.name
, e2
->key
.serv
.serv
.name
,
99 return (_NSC_INT_KEY_CMP(res
, 0));
103 servname_gethash(nss_XbyY_key_t
*key
, int htsize
) {
104 return (ces_gethash(key
->serv
.serv
.name
, htsize
));
108 servname_getlogstr(char *name
, char *whoami
, size_t len
,
109 nss_XbyY_args_t
*argp
) {
110 (void) snprintf(whoami
, len
, "%s [key=%s, %s]",
112 argp
->key
.serv
.serv
.name
,
113 check_null(argp
->key
.serv
.proto
));
117 servport_compar(const void *n1
, const void *n2
) {
118 nsc_entry_t
*e1
, *e2
;
121 e1
= (nsc_entry_t
*)n1
;
122 e2
= (nsc_entry_t
*)n2
;
124 /* compare protocol */
125 if (e1
->key
.serv
.proto
== NULL
&& e2
->key
.serv
.proto
)
127 if (e1
->key
.serv
.proto
&& e2
->key
.serv
.proto
== NULL
)
129 if (e1
->key
.serv
.proto
) {
130 l1
= strlen(e1
->key
.serv
.proto
);
131 l2
= strlen(e2
->key
.serv
.proto
);
132 res
= strncmp(e1
->key
.serv
.proto
, e2
->key
.serv
.proto
,
141 return (_NSC_INT_KEY_CMP(e1
->key
.serv
.serv
.port
,
142 e2
->key
.serv
.serv
.port
));
146 servport_gethash(nss_XbyY_key_t
*key
, int htsize
) {
147 return (db_gethash(&key
->serv
.serv
.port
,
148 sizeof (key
->serv
.serv
.port
), htsize
));
152 servport_getlogstr(char *name
, char *whoami
, size_t len
,
153 nss_XbyY_args_t
*argp
) {
154 (void) snprintf(whoami
, len
, "%s [key=%d, %s]",
156 argp
->key
.serv
.serv
.port
,
157 check_null(argp
->key
.serv
.proto
));