17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5cb5caa98Sdjl * Common Development and Distribution License (the "License").
6cb5caa98Sdjl * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*7257d1b4Sraf
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24cb5caa98Sdjl * Use is subject to license terms.
25*7257d1b4Sraf */
26*7257d1b4Sraf
27*7257d1b4Sraf /*
287c478bd9Sstevel@tonic-gate * nis/getrpcent.c -- "nis" backend for nsswitch "rpc" database
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include "nis_common.h"
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <signal.h>
377c478bd9Sstevel@tonic-gate #include <synch.h>
387c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h>
397c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
407c478bd9Sstevel@tonic-gate #include <thread.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static int
check_name(args)437c478bd9Sstevel@tonic-gate check_name(args)
447c478bd9Sstevel@tonic-gate nss_XbyY_args_t *args;
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate struct rpcent *rpc = (struct rpcent *)args->returnval;
477c478bd9Sstevel@tonic-gate const char *name = args->key.name;
487c478bd9Sstevel@tonic-gate char **aliasp;
497c478bd9Sstevel@tonic-gate
50cb5caa98Sdjl if (rpc) {
517c478bd9Sstevel@tonic-gate if (strcmp(rpc->r_name, name) == 0) {
527c478bd9Sstevel@tonic-gate return (1);
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate for (aliasp = rpc->r_aliases; *aliasp != 0; aliasp++) {
557c478bd9Sstevel@tonic-gate if (strcmp(*aliasp, name) == 0) {
567c478bd9Sstevel@tonic-gate return (1);
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate return (0);
60cb5caa98Sdjl } else {
61cb5caa98Sdjl /*
62cb5caa98Sdjl * NSS2: nscd is running.
63cb5caa98Sdjl */
64cb5caa98Sdjl return (_nss_nis_check_name_aliases(args,
65cb5caa98Sdjl (const char *)args->buf.buffer,
66cb5caa98Sdjl strlen(args->buf.buffer)));
67cb5caa98Sdjl
68cb5caa98Sdjl }
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate static mutex_t no_byname_lock = DEFAULTMUTEX;
727c478bd9Sstevel@tonic-gate static int no_byname_map = 0;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static nss_status_t
getbyname(be,a)757c478bd9Sstevel@tonic-gate getbyname(be, a)
767c478bd9Sstevel@tonic-gate nis_backend_ptr_t be;
777c478bd9Sstevel@tonic-gate void *a;
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
807c478bd9Sstevel@tonic-gate int no_map;
817c478bd9Sstevel@tonic-gate sigset_t oldmask, newmask;
827c478bd9Sstevel@tonic-gate
83cb5caa98Sdjl (void) sigfillset(&newmask);
84*7257d1b4Sraf (void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
85*7257d1b4Sraf (void) mutex_lock(&no_byname_lock);
867c478bd9Sstevel@tonic-gate no_map = no_byname_map;
87*7257d1b4Sraf (void) mutex_unlock(&no_byname_lock);
88*7257d1b4Sraf (void) thr_sigsetmask(SIG_SETMASK, &oldmask, (sigset_t *)NULL);
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if (no_map == 0) {
917c478bd9Sstevel@tonic-gate int yp_status;
927c478bd9Sstevel@tonic-gate nss_status_t res;
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate res = _nss_nis_lookup(be, argp, 1, "rpc.byname",
957c478bd9Sstevel@tonic-gate argp->key.name, &yp_status);
967c478bd9Sstevel@tonic-gate if (yp_status == YPERR_MAP) {
97cb5caa98Sdjl (void) sigfillset(&newmask);
98*7257d1b4Sraf (void) thr_sigsetmask(SIG_SETMASK, &newmask, &oldmask);
99*7257d1b4Sraf (void) mutex_lock(&no_byname_lock);
1007c478bd9Sstevel@tonic-gate no_byname_map = 1;
101*7257d1b4Sraf (void) mutex_unlock(&no_byname_lock);
102*7257d1b4Sraf (void) thr_sigsetmask(SIG_SETMASK, &oldmask,
103cb5caa98Sdjl (sigset_t *)NULL);
1047c478bd9Sstevel@tonic-gate } else /* if (res == NSS_SUCCESS) <==== */ {
1057c478bd9Sstevel@tonic-gate return (res);
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate return (_nss_nis_XY_all(be, argp, 1, argp->key.name, check_name));
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate static nss_status_t
getbynumber(be,a)1137c478bd9Sstevel@tonic-gate getbynumber(be, a)
1147c478bd9Sstevel@tonic-gate nis_backend_ptr_t be;
1157c478bd9Sstevel@tonic-gate void *a;
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
1187c478bd9Sstevel@tonic-gate char numstr[12];
1197c478bd9Sstevel@tonic-gate
120cb5caa98Sdjl (void) sprintf(numstr, "%d", argp->key.number);
1217c478bd9Sstevel@tonic-gate return (_nss_nis_lookup(be, argp, 1, "rpc.bynumber", numstr, 0));
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate static nis_backend_op_t rpc_ops[] = {
1257c478bd9Sstevel@tonic-gate _nss_nis_destr,
1267c478bd9Sstevel@tonic-gate _nss_nis_endent,
1277c478bd9Sstevel@tonic-gate _nss_nis_setent,
1287c478bd9Sstevel@tonic-gate _nss_nis_getent_netdb,
1297c478bd9Sstevel@tonic-gate getbyname,
1307c478bd9Sstevel@tonic-gate getbynumber
1317c478bd9Sstevel@tonic-gate };
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1347c478bd9Sstevel@tonic-gate nss_backend_t *
_nss_nis_rpc_constr(dummy1,dummy2,dummy3)1357c478bd9Sstevel@tonic-gate _nss_nis_rpc_constr(dummy1, dummy2, dummy3)
1367c478bd9Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3;
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate return (_nss_nis_constr(rpc_ops,
1397c478bd9Sstevel@tonic-gate sizeof (rpc_ops) / sizeof (rpc_ops[0]),
1407c478bd9Sstevel@tonic-gate "rpc.bynumber"));
1417c478bd9Sstevel@tonic-gate }
142