2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A *
2N/A * lib/libsocket/inet/getservent_r.c
2N/A *
2N/A * This file defines and implements the re-entrant enumeration routines for
2N/A * services: setservent(), getservent_r(), and endservent(). They consult
2N/A * the switch policy directly and do not "share" their enumeration state
2N/A * nor the stayopen flag with the implentation of the more common
2N/A * getservbyname_r()/getservbyport_r(). The latter follows a tortuous
2N/A * route in order to be consistent with netdir_getbyYY() (see
2N/A * getservbyname_r.c and lib/libnsl/nss/netdir_inet.c).
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <sys/types.h>
2N/A#include <nss_dbdefs.h>
2N/A
2N/A/*
2N/A * str2servent is implemented in libnsl, libnsl/nss/netdir_inet.c, since
2N/A * the "engine" of the new gethost/getserv/netdir lives in libnsl.
2N/A */
2N/Aint str2servent(const char *, int, void *, char *, int);
2N/A
2N/A/*
2N/A * Unsynchronized, but it affects only
2N/A * efficiency, not correctness.
2N/A */
2N/Astatic int services_stayopen;
2N/Astatic DEFINE_NSS_DB_ROOT(db_root);
2N/Astatic DEFINE_NSS_GETENT(context);
2N/A
2N/Avoid
2N/A_nss_initf_services(nss_db_params_t *p)
2N/A{
2N/A p->name = NSS_DBNAM_SERVICES;
2N/A p->default_config = NSS_DEFCONF_SERVICES;
2N/A}
2N/A
2N/Aint
2N/Asetservent(int stay)
2N/A{
2N/A services_stayopen |= stay;
2N/A nss_setent(&db_root, _nss_initf_services, &context);
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Aendservent()
2N/A{
2N/A services_stayopen = 0;
2N/A nss_endent(&db_root, _nss_initf_services, &context);
2N/A nss_delete(&db_root);
2N/A return (0);
2N/A}
2N/A
2N/Astruct servent *
2N/Agetservent_r(struct servent *result, char *buffer, int buflen)
2N/A{
2N/A nss_XbyY_args_t arg;
2N/A nss_status_t res;
2N/A
2N/A NSS_XbyY_INIT(&arg, result, buffer, buflen, str2servent);
2N/A /*
2N/A * Setting proto to NULL here is a bit of a hack since we share
2N/A * the parsing code in the NIS+ backend with our getservbyYY()
2N/A * brethren who can search on 1-1/2 key. If they pass a NULL
2N/A * proto, the parsing code deals with it by picking the protocol
2N/A * from the first NIS+ matching object and combining all entries
2N/A * with "that" proto field. NIS+ is the only name service, so far,
2N/A * that can return multiple entries on a lookup.
2N/A */
2N/A arg.key.serv.proto = NULL;
2N/A /* === No stayopen flag; of course you stay open for iteration */
2N/A res = nss_getent(&db_root, _nss_initf_services, &context, &arg);
2N/A arg.status = res;
2N/A return (struct servent *)NSS_XbyY_FINI(&arg);
2N/A}