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.
25 * lib/libsocket/inet/getservent_r.c
27 * This file defines and implements the re-entrant enumeration routines for
28 * services: setservent(), getservent_r(), and endservent(). They consult
29 * the switch policy directly and do not "share" their enumeration state
30 * nor the stayopen flag with the implentation of the more common
31 * getservbyname_r()/getservbyport_r(). The latter follows a tortuous
32 * route in order to be consistent with netdir_getbyYY() (see
33 * getservbyname_r.c and lib/libnsl/nss/netdir_inet.c).
36 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <sys/types.h>
39 #include <nss_dbdefs.h>
42 * str2servent is implemented in libnsl, libnsl/nss/netdir_inet.c, since
43 * the "engine" of the new gethost/getserv/netdir lives in libnsl.
45 int str2servent(const char *, int, void *, char *, int);
48 * Unsynchronized, but it affects only
49 * efficiency, not correctness.
51 static int services_stayopen
;
52 static DEFINE_NSS_DB_ROOT(db_root
);
53 static DEFINE_NSS_GETENT(context
);
56 _nss_initf_services(nss_db_params_t
*p
)
58 p
->name
= NSS_DBNAM_SERVICES
;
59 p
->default_config
= NSS_DEFCONF_SERVICES
;
65 services_stayopen
|= stay
;
66 nss_setent(&db_root
, _nss_initf_services
, &context
);
73 services_stayopen
= 0;
74 nss_endent(&db_root
, _nss_initf_services
, &context
);
80 getservent_r(struct servent
*result
, char *buffer
, int buflen
)
85 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2servent
);
87 * Setting proto to NULL here is a bit of a hack since we share
88 * the parsing code in the NIS+ backend with our getservbyYY()
89 * brethren who can search on 1-1/2 key. If they pass a NULL
90 * proto, the parsing code deals with it by picking the protocol
91 * from the first NIS+ matching object and combining all entries
92 * with "that" proto field. NIS+ is the only name service, so far,
93 * that can return multiple entries on a lookup.
95 arg
.key
.serv
.proto
= NULL
;
96 /* === No stayopen flag; of course you stay open for iteration */
97 res
= nss_getent(&db_root
, _nss_initf_services
, &context
, &arg
);
99 return (struct servent
*)NSS_XbyY_FINI(&arg
);