10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
52830Sdjl * Common Development and Distribution License (the "License").
62830Sdjl * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
242830Sdjl * Use is subject to license terms.
25*6812Sraf */
26*6812Sraf
27*6812Sraf /*
280Sstevel@tonic-gate * nis/getrpcent.c -- "nis" backend for nsswitch "rpc" database
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include "nis_common.h"
340Sstevel@tonic-gate #include <stdio.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <signal.h>
370Sstevel@tonic-gate #include <synch.h>
380Sstevel@tonic-gate #include <rpc/rpcent.h>
390Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
400Sstevel@tonic-gate #include <thread.h>
410Sstevel@tonic-gate
420Sstevel@tonic-gate static int
check_name(args)430Sstevel@tonic-gate check_name(args)
440Sstevel@tonic-gate nss_XbyY_args_t *args;
450Sstevel@tonic-gate {
462830Sdjl struct rpcent *rpc = (struct rpcent *)args->returnval;
470Sstevel@tonic-gate const char *name = args->key.name;
480Sstevel@tonic-gate char **aliasp;
490Sstevel@tonic-gate
502830Sdjl if (rpc) {
512830Sdjl if (strcmp(rpc->r_name, name) == 0) {
520Sstevel@tonic-gate return (1);
530Sstevel@tonic-gate }
542830Sdjl for (aliasp = rpc->r_aliases; *aliasp != 0; aliasp++) {
552830Sdjl if (strcmp(*aliasp, name) == 0) {
562830Sdjl return (1);
572830Sdjl }
582830Sdjl }
592830Sdjl return (0);
602830Sdjl } else {
612830Sdjl /*
622830Sdjl * NSS2: nscd is running.
632830Sdjl */
642830Sdjl return (_nss_nis_check_name_aliases(args,
652830Sdjl (const char *)args->buf.buffer,
662830Sdjl strlen(args->buf.buffer)));
672830Sdjl
680Sstevel@tonic-gate }
690Sstevel@tonic-gate }
700Sstevel@tonic-gate
710Sstevel@tonic-gate static mutex_t no_byname_lock = DEFAULTMUTEX;
720Sstevel@tonic-gate static int no_byname_map = 0;
730Sstevel@tonic-gate
740Sstevel@tonic-gate static nss_status_t
getbyname(be,a)750Sstevel@tonic-gate getbyname(be, a)
760Sstevel@tonic-gate nis_backend_ptr_t be;
770Sstevel@tonic-gate void *a;
780Sstevel@tonic-gate {
792830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
800Sstevel@tonic-gate int no_map;
810Sstevel@tonic-gate sigset_t oldmask, newmask;
820Sstevel@tonic-gate
832830Sdjl (void) sigfillset(&newmask);
84*6812Sraf (void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
85*6812Sraf (void) mutex_lock(&no_byname_lock);
860Sstevel@tonic-gate no_map = no_byname_map;
87*6812Sraf (void) mutex_unlock(&no_byname_lock);
88*6812Sraf (void) thr_sigsetmask(SIG_SETMASK, &oldmask, (sigset_t *)NULL);
890Sstevel@tonic-gate
900Sstevel@tonic-gate if (no_map == 0) {
910Sstevel@tonic-gate int yp_status;
920Sstevel@tonic-gate nss_status_t res;
930Sstevel@tonic-gate
940Sstevel@tonic-gate res = _nss_nis_lookup(be, argp, 1, "rpc.byname",
952830Sdjl argp->key.name, &yp_status);
960Sstevel@tonic-gate if (yp_status == YPERR_MAP) {
972830Sdjl (void) sigfillset(&newmask);
98*6812Sraf (void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
99*6812Sraf (void) mutex_lock(&no_byname_lock);
1000Sstevel@tonic-gate no_byname_map = 1;
101*6812Sraf (void) mutex_unlock(&no_byname_lock);
102*6812Sraf (void) thr_sigsetmask(SIG_SETMASK, &oldmask,
1032830Sdjl (sigset_t *)NULL);
1040Sstevel@tonic-gate } else /* if (res == NSS_SUCCESS) <==== */ {
1050Sstevel@tonic-gate return (res);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate return (_nss_nis_XY_all(be, argp, 1, argp->key.name, check_name));
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate static nss_status_t
getbynumber(be,a)1130Sstevel@tonic-gate getbynumber(be, a)
1140Sstevel@tonic-gate nis_backend_ptr_t be;
1150Sstevel@tonic-gate void *a;
1160Sstevel@tonic-gate {
1172830Sdjl nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
1180Sstevel@tonic-gate char numstr[12];
1190Sstevel@tonic-gate
1202830Sdjl (void) sprintf(numstr, "%d", argp->key.number);
1210Sstevel@tonic-gate return (_nss_nis_lookup(be, argp, 1, "rpc.bynumber", numstr, 0));
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate static nis_backend_op_t rpc_ops[] = {
1250Sstevel@tonic-gate _nss_nis_destr,
1260Sstevel@tonic-gate _nss_nis_endent,
1270Sstevel@tonic-gate _nss_nis_setent,
1280Sstevel@tonic-gate _nss_nis_getent_netdb,
1290Sstevel@tonic-gate getbyname,
1300Sstevel@tonic-gate getbynumber
1310Sstevel@tonic-gate };
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /*ARGSUSED*/
1340Sstevel@tonic-gate nss_backend_t *
_nss_nis_rpc_constr(dummy1,dummy2,dummy3)1350Sstevel@tonic-gate _nss_nis_rpc_constr(dummy1, dummy2, dummy3)
1360Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3;
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate return (_nss_nis_constr(rpc_ops,
1390Sstevel@tonic-gate sizeof (rpc_ops) / sizeof (rpc_ops[0]),
1400Sstevel@tonic-gate "rpc.bynumber"));
1410Sstevel@tonic-gate }
142