1*4887Schin #include "FEATURE/uwin"
2*4887Schin
3*4887Schin #if !_UWIN || _lib_rcmd
4*4887Schin
_STUB_rcmd()5*4887Schin void _STUB_rcmd(){}
6*4887Schin
7*4887Schin #else
8*4887Schin
9*4887Schin /*
10*4887Schin * Copyright (c) 1983
11*4887Schin * The Regents of the University of California. All rights reserved.
12*4887Schin *
13*4887Schin * Redistribution and use in source and binary forms, with or without
14*4887Schin * modification, are permitted provided that the following conditions
15*4887Schin * are met:
16*4887Schin * 1. Redistributions of source code must retain the above copyright
17*4887Schin * notice, this list of conditions and the following disclaimer.
18*4887Schin * 2. Redistributions in binary form must reproduce the above copyright
19*4887Schin * notice, this list of conditions and the following disclaimer in the
20*4887Schin * documentation and/or other materials provided with the distribution.
21*4887Schin * 3. Neither the name of the University nor the names of its contributors
22*4887Schin * may be used to endorse or promote products derived from this software
23*4887Schin * without specific prior written permission.
24*4887Schin *
25*4887Schin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26*4887Schin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*4887Schin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*4887Schin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29*4887Schin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*4887Schin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*4887Schin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*4887Schin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*4887Schin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*4887Schin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*4887Schin * SUCH DAMAGE.
36*4887Schin */
37*4887Schin
38*4887Schin #if defined(LIBC_SCCS) && !defined(lint)
39*4887Schin static char sccsid[] = "@(#)rcmd.c 5.17 (Berkeley) 6/27/88";
40*4887Schin #endif /* LIBC_SCCS and not lint */
41*4887Schin
42*4887Schin #include "rlib.h"
43*4887Schin #include <pwd.h>
44*4887Schin #include <sys/file.h>
45*4887Schin #include <sys/signal.h>
46*4887Schin #if 1
47*4887Schin #define _PATH_HEQUIV "/etc/hosts.equiv"
48*4887Schin #endif
49*4887Schin #include <sys/stat.h>
50*4887Schin
51*4887Schin #if NLS
52*4887Schin #include "nl_types.h"
53*4887Schin #endif
54*4887Schin
55*4887Schin #ifdef YP
56*4887Schin #include <rpcsvc/ypclnt.h>
57*4887Schin extern void setnetgrent(const char *);
58*4887Schin extern void endnetgrent(void);
59*4887Schin extern int getnetgrent(char **, char **, char **);
60*4887Schin static char *nisdomain = NULL;
61*4887Schin static int _checknetgrouphost(const char *, const char *, int);
62*4887Schin static int _checknetgroupuser(const char *, const char *);
63*4887Schin #endif
64*4887Schin
65*4887Schin #if defined(__EXPORT__)
66*4887Schin #define extern __EXPORT__
67*4887Schin #endif
68*4887Schin
rresvport(int * alport)69*4887Schin extern int rresvport(int *alport)
70*4887Schin {
71*4887Schin struct sockaddr_in sin;
72*4887Schin int s;
73*4887Schin
74*4887Schin sin.sin_family = AF_INET;
75*4887Schin sin.sin_addr.s_addr = INADDR_ANY;
76*4887Schin s = socket(AF_INET, SOCK_STREAM, 0);
77*4887Schin if (s < 0)
78*4887Schin return (-1);
79*4887Schin for (;;) {
80*4887Schin sin.sin_port = htons((u_short)*alport);
81*4887Schin if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
82*4887Schin return (s);
83*4887Schin if (errno != EADDRINUSE) {
84*4887Schin (void) close(s);
85*4887Schin return (-1);
86*4887Schin }
87*4887Schin (*alport)--;
88*4887Schin if (*alport == IPPORT_RESERVED/2) {
89*4887Schin (void) close(s);
90*4887Schin errno = EAGAIN; /* close */
91*4887Schin return (-1);
92*4887Schin }
93*4887Schin }
94*4887Schin }
95*4887Schin
rcmd(char ** ahost,unsigned short rport,const char * locuser,const char * remuser,const char * cmd,int * fd2p)96*4887Schin extern int rcmd(char **ahost, unsigned short rport, const char *locuser, const char *remuser, const char *cmd, int *fd2p)
97*4887Schin {
98*4887Schin int s, timo = 1;
99*4887Schin #ifdef F_SETOWN
100*4887Schin pid_t pid;
101*4887Schin #endif
102*4887Schin #ifdef _POSIX_SOURCE
103*4887Schin sigset_t set, oset;
104*4887Schin #else
105*4887Schin long oldmask;
106*4887Schin #endif
107*4887Schin struct sockaddr_in sin, from;
108*4887Schin char c;
109*4887Schin int lport = IPPORT_RESERVED - 1;
110*4887Schin struct hostent *hp;
111*4887Schin
112*4887Schin #if NLS
113*4887Schin libc_nls_init();
114*4887Schin #endif
115*4887Schin
116*4887Schin #ifdef F_SETOWN
117*4887Schin pid = getpid();
118*4887Schin #endif
119*4887Schin hp = gethostbyname(*ahost);
120*4887Schin if (hp == 0) {
121*4887Schin #if NLS
122*4887Schin fprintf(stderr, "%s: %s\n", *ahost,
123*4887Schin catgets(_libc_cat, HerrorListSet,
124*4887Schin 2, "unknown host"));
125*4887Schin #else
126*4887Schin fprintf(stderr, "%s: unknown host\n", *ahost);
127*4887Schin #endif
128*4887Schin return (-1);
129*4887Schin }
130*4887Schin *ahost = hp->h_name;
131*4887Schin #ifdef SIGURG
132*4887Schin #ifdef _POSIX_SOURCE
133*4887Schin sigemptyset (&set);
134*4887Schin sigaddset (&set, SIGURG);
135*4887Schin sigprocmask (SIG_BLOCK, &set, &oset);
136*4887Schin #else
137*4887Schin oldmask = sigblock(sigmask(SIGURG));
138*4887Schin #endif
139*4887Schin #endif
140*4887Schin for (;;) {
141*4887Schin s = rresvport(&lport);
142*4887Schin if (s < 0) {
143*4887Schin if (errno == EAGAIN)
144*4887Schin #if NLS
145*4887Schin fprintf(stderr, "socket: %s\n",
146*4887Schin catgets(_libc_cat, NetMiscSet,
147*4887Schin NetMiscAllPortsInUse,
148*4887Schin "All ports in use"));
149*4887Schin #else
150*4887Schin fprintf(stderr, "socket: All ports in use\n");
151*4887Schin #endif
152*4887Schin else
153*4887Schin #if NLS
154*4887Schin perror(catgets(_libc_cat, NetMiscSet,
155*4887Schin NetMiscRcmdSocket,
156*4887Schin "rcmd: socket"));
157*4887Schin #else
158*4887Schin perror("rcmd: socket");
159*4887Schin #endif
160*4887Schin #ifdef SIGURG
161*4887Schin #ifdef _POSIX_SOURCE
162*4887Schin sigprocmask (SIG_SETMASK, &oset,
163*4887Schin (sigset_t *)NULL);
164*4887Schin #else
165*4887Schin sigsetmask(oldmask);
166*4887Schin #endif
167*4887Schin #endif
168*4887Schin return (-1);
169*4887Schin }
170*4887Schin #ifdef F_SETOWN
171*4887Schin fcntl(s, F_SETOWN, pid);
172*4887Schin #endif
173*4887Schin sin.sin_family = hp->h_addrtype;
174*4887Schin bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, hp->h_length);
175*4887Schin sin.sin_port = rport;
176*4887Schin if (connect(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
177*4887Schin break;
178*4887Schin (void) close(s);
179*4887Schin if (errno == EADDRINUSE) {
180*4887Schin lport--;
181*4887Schin continue;
182*4887Schin }
183*4887Schin if (errno == ECONNREFUSED && timo <= 16) {
184*4887Schin sleep(timo);
185*4887Schin timo *= 2;
186*4887Schin continue;
187*4887Schin }
188*4887Schin if (hp->h_addr_list[1] != NULL) {
189*4887Schin int oerrno = errno;
190*4887Schin
191*4887Schin fprintf(stderr,
192*4887Schin #if NLS
193*4887Schin "%s %s: ", catgets(_libc_cat, NetMiscSet,
194*4887Schin NetMiscAllPortsInUse,
195*4887Schin "connect to address"),
196*4887Schin inet_ntoa(sin.sin_addr));
197*4887Schin
198*4887Schin #else
199*4887Schin
200*4887Schin "connect to address %s: ", inet_ntoa(sin.sin_addr));
201*4887Schin #endif
202*4887Schin errno = oerrno;
203*4887Schin perror(0);
204*4887Schin hp->h_addr_list++;
205*4887Schin bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr,
206*4887Schin hp->h_length);
207*4887Schin
208*4887Schin #if NLS
209*4887Schin fprintf(stderr, catgets(_libc_cat, NetMiscSet,
210*4887Schin NetMiscTrying,
211*4887Schin "Trying %s...\n"),
212*4887Schin #else
213*4887Schin fprintf(stderr, "Trying %s...\n",
214*4887Schin #endif
215*4887Schin inet_ntoa(sin.sin_addr));
216*4887Schin continue;
217*4887Schin }
218*4887Schin perror(hp->h_name);
219*4887Schin #ifdef SIGURG
220*4887Schin #ifdef _POSIX_SOURCE
221*4887Schin sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
222*4887Schin #else
223*4887Schin sigsetmask(oldmask);
224*4887Schin #endif
225*4887Schin #endif
226*4887Schin return (-1);
227*4887Schin }
228*4887Schin lport--;
229*4887Schin if (fd2p == 0) {
230*4887Schin write(s, "", 1);
231*4887Schin lport = 0;
232*4887Schin } else {
233*4887Schin char num[8];
234*4887Schin int s2 = rresvport(&lport), s3;
235*4887Schin int len = sizeof (from);
236*4887Schin
237*4887Schin if (s2 < 0)
238*4887Schin goto bad;
239*4887Schin listen(s2, 1);
240*4887Schin (void) snprintf(num, sizeof(num), "%d", lport);
241*4887Schin if (write(s, num, strlen(num)+1) != strlen(num)+1) {
242*4887Schin #if NLS
243*4887Schin perror(catgets(_libc_cat, NetMiscSet,
244*4887Schin NetMiscSettingUpStderr,
245*4887Schin "write: setting up stderr"));
246*4887Schin #else
247*4887Schin perror("write: setting up stderr");
248*4887Schin #endif
249*4887Schin (void) close(s2);
250*4887Schin goto bad;
251*4887Schin }
252*4887Schin s3 = accept(s2, (struct sockaddr *)&from, &len);
253*4887Schin (void) close(s2);
254*4887Schin if (s3 < 0) {
255*4887Schin #if NLS
256*4887Schin perror(catgets(_libc_cat, NetMiscSet,
257*4887Schin NetMiscAccept,
258*4887Schin "accept"));
259*4887Schin #else
260*4887Schin perror("accept");
261*4887Schin #endif
262*4887Schin lport = 0;
263*4887Schin goto bad;
264*4887Schin }
265*4887Schin *fd2p = s3;
266*4887Schin from.sin_port = ntohs((u_short)from.sin_port);
267*4887Schin if (from.sin_family != AF_INET ||
268*4887Schin from.sin_port >= IPPORT_RESERVED) {
269*4887Schin fprintf(stderr,
270*4887Schin #if NLS
271*4887Schin "%s\n",
272*4887Schin catgets(_libc_cat, NetMiscSet,
273*4887Schin NetMiscProtocolFailure,
274*4887Schin "socket: protocol failure in circuit setup."));
275*4887Schin #else
276*4887Schin "socket: protocol failure in circuit setup.\n");
277*4887Schin #endif
278*4887Schin goto bad2;
279*4887Schin }
280*4887Schin }
281*4887Schin (void) write(s, locuser, strlen(locuser)+1);
282*4887Schin (void) write(s, remuser, strlen(remuser)+1);
283*4887Schin (void) write(s, cmd, strlen(cmd)+1);
284*4887Schin if (read(s, &c, 1) != 1) {
285*4887Schin perror(*ahost);
286*4887Schin goto bad2;
287*4887Schin }
288*4887Schin if (c != 0) {
289*4887Schin while (read(s, &c, 1) == 1) {
290*4887Schin (void) write(2, &c, 1);
291*4887Schin if (c == '\n')
292*4887Schin break;
293*4887Schin }
294*4887Schin goto bad2;
295*4887Schin }
296*4887Schin #ifdef SIGURG
297*4887Schin #ifdef _POSIX_SOURCE
298*4887Schin sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
299*4887Schin #else
300*4887Schin sigsetmask(oldmask);
301*4887Schin #endif
302*4887Schin #endif
303*4887Schin return (s);
304*4887Schin bad2:
305*4887Schin if (lport)
306*4887Schin (void) close(*fd2p);
307*4887Schin bad:
308*4887Schin (void) close(s);
309*4887Schin #ifdef SIGURG
310*4887Schin #ifdef _POSIX_SOURCE
311*4887Schin sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
312*4887Schin #else
313*4887Schin sigsetmask(oldmask);
314*4887Schin #endif
315*4887Schin #endif
316*4887Schin return (-1);
317*4887Schin }
318*4887Schin
ruserok(const char * rhost,int superuser,const char * ruser,const char * luser)319*4887Schin extern int ruserok(const char *rhost, int superuser, const char *ruser, const char *luser)
320*4887Schin {
321*4887Schin FILE *hostf;
322*4887Schin char fhost[MAXHOSTNAMELEN];
323*4887Schin int first = 1;
324*4887Schin register const char *sp;
325*4887Schin register char *p;
326*4887Schin int baselen = -1;
327*4887Schin uid_t saveuid;
328*4887Schin
329*4887Schin saveuid = geteuid();
330*4887Schin sp = rhost;
331*4887Schin p = fhost;
332*4887Schin while (*sp) {
333*4887Schin if (*sp == '.') {
334*4887Schin if (baselen == -1)
335*4887Schin baselen = sp - rhost;
336*4887Schin *p++ = *sp++;
337*4887Schin } else {
338*4887Schin *p++ = isupper(*sp) ? tolower(*sp++) : *sp++;
339*4887Schin }
340*4887Schin }
341*4887Schin *p = '\0';
342*4887Schin hostf = superuser ? (FILE *)0 : fopen(_PATH_HEQUIV, "r");
343*4887Schin again:
344*4887Schin if (hostf) {
345*4887Schin if (!_validuser(hostf, fhost, luser, ruser, baselen)) {
346*4887Schin (void) fclose(hostf);
347*4887Schin seteuid(saveuid);
348*4887Schin return(0);
349*4887Schin }
350*4887Schin (void) fclose(hostf);
351*4887Schin }
352*4887Schin if (first == 1) {
353*4887Schin struct stat sbuf;
354*4887Schin struct passwd *pwd;
355*4887Schin char pbuf[MAXPATHLEN];
356*4887Schin
357*4887Schin first = 0;
358*4887Schin if ((pwd = getpwnam(luser)) == NULL)
359*4887Schin return(-1);
360*4887Schin (void)strcpy(pbuf, pwd->pw_dir);
361*4887Schin (void)strcat(pbuf, "/.rhosts");
362*4887Schin (void)seteuid(pwd->pw_uid);
363*4887Schin if ((hostf = fopen(pbuf, "r")) == NULL) {
364*4887Schin seteuid(saveuid);
365*4887Schin return(-1);
366*4887Schin }
367*4887Schin (void)fstat(fileno(hostf), &sbuf);
368*4887Schin if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) {
369*4887Schin fclose(hostf);
370*4887Schin seteuid(saveuid);
371*4887Schin return(-1);
372*4887Schin }
373*4887Schin goto again;
374*4887Schin }
375*4887Schin seteuid(saveuid);
376*4887Schin return (-1);
377*4887Schin }
378*4887Schin
379*4887Schin int
_validuser(FILE * hostf,const char * rhost,const char * luser,const char * ruser,int baselen)380*4887Schin _validuser(FILE *hostf, const char *rhost, const char *luser,
381*4887Schin const char *ruser, int baselen)
382*4887Schin {
383*4887Schin char *user;
384*4887Schin char ahost[MAXHOSTNAMELEN];
385*4887Schin register char *p;
386*4887Schin int hostvalid = 0;
387*4887Schin int uservalid = 0;
388*4887Schin
389*4887Schin while (fgets(ahost, sizeof (ahost), hostf)) {
390*4887Schin /* We need to get rid of all comments. */
391*4887Schin p = strchr (ahost, '#');
392*4887Schin if (p) *p = '\0';
393*4887Schin p = ahost;
394*4887Schin while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
395*4887Schin *p = isupper(*p) ? tolower(*p) : *p;
396*4887Schin p++;
397*4887Schin }
398*4887Schin if (*p == ' ' || *p == '\t') {
399*4887Schin *p++ = '\0';
400*4887Schin while (*p == ' ' || *p == '\t')
401*4887Schin p++;
402*4887Schin user = p;
403*4887Schin while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0')
404*4887Schin p++;
405*4887Schin } else
406*4887Schin user = p;
407*4887Schin *p = '\0';
408*4887Schin /* Adding new authentication -Nilendu */
409*4887Schin
410*4887Schin /* enable all host for + entry */
411*4887Schin if ('+' == ahost[0] && '\0' == ahost[1] )
412*4887Schin hostvalid = 1;
413*4887Schin
414*4887Schin /* enable all user for + entry */
415*4887Schin if ('+' == user[0] && '\0' == user[1] )
416*4887Schin uservalid = 1;
417*4887Schin
418*4887Schin /* disable all host for - entry */
419*4887Schin if ('-' == ahost[0] && '\0' == ahost[1] )
420*4887Schin hostvalid = 0;
421*4887Schin
422*4887Schin /* disable all user for - entry */
423*4887Schin if ('-' == user[0] && '\0' == user[1] )
424*4887Schin uservalid = 0;
425*4887Schin
426*4887Schin
427*4887Schin #ifdef YP
428*4887Schin /* disable host from -hostname entry */
429*4887Schin if ('-' == ahost[0] && '@' != ahost[1]
430*4887Schin && _checkhost(rhost, &ahost[1], baselen))
431*4887Schin return -1;
432*4887Schin /* disable host from -@netgroup entry for host */
433*4887Schin if ('-' == ahost[0] && '@' == ahost[1] && '\0' != ahost[2]
434*4887Schin && _checknetgrouphost(rhost, &ahost[2], baselen))
435*4887Schin return -1;
436*4887Schin /* disable user from -user entry */
437*4887Schin if ('\0' != *user && user[0] == '-' && user[1] != '@'
438*4887Schin && !strcmp(&user[1], ruser))
439*4887Schin return -1;
440*4887Schin /* disable user from -@netgroup entry for user */
441*4887Schin if ('\0' != *user && user[0] == '-' && user[1] == '@'
442*4887Schin && user[2] != '\0' && _checknetgroupuser(ruser, &user[2]))
443*4887Schin return -1;
444*4887Schin /* enable host from +@netgroup entry for host */
445*4887Schin if ('+' == ahost[0] && '@' == ahost[1] && '\0' != ahost[2])
446*4887Schin hostvalid = _checknetgrouphost(rhost, &ahost[2], baselen);
447*4887Schin else
448*4887Schin hostvalid = _checkhost(rhost, ahost, baselen);
449*4887Schin /* enable user from +@netgroup entry for user */
450*4887Schin if ('\0' != *user && user[0] == '+'
451*4887Schin && user[1] == '@' && user[2] != '\0')
452*4887Schin uservalid = _checknetgroupuser(ruser, &user[2]);
453*4887Schin else
454*4887Schin uservalid = !strcmp(ruser, *user ? user : luser);
455*4887Schin
456*4887Schin if (hostvalid && uservalid)
457*4887Schin return 0;
458*4887Schin #else
459*4887Schin hostvalid = hostvalid ? 1 : _checkhost(rhost, ahost, baselen);
460*4887Schin uservalid = uservalid ? 1 : !stricmp(ruser,*user ? user : luser);
461*4887Schin if (hostvalid && uservalid)
462*4887Schin return 0;
463*4887Schin
464*4887Schin #endif /* YP */
465*4887Schin hostvalid = uservalid = 0;
466*4887Schin }
467*4887Schin return (-1);
468*4887Schin }
469*4887Schin
470*4887Schin int
_checkhost(const char * rhost,const char * lhost,int len)471*4887Schin _checkhost(const char *rhost, const char *lhost, int len)
472*4887Schin {
473*4887Schin static char ldomain[MAXHOSTNAMELEN + 1];
474*4887Schin static char *domainp = NULL;
475*4887Schin static int nodomain = 0;
476*4887Schin register char *cp;
477*4887Schin
478*4887Schin if (len == -1)
479*4887Schin return(!strcmp(rhost, lhost));
480*4887Schin if (strncmp(rhost, lhost, len))
481*4887Schin return(0);
482*4887Schin if (!strcmp(rhost, lhost))
483*4887Schin return(1);
484*4887Schin if (*(lhost + len) != '\0')
485*4887Schin return(0);
486*4887Schin if (nodomain)
487*4887Schin return(0);
488*4887Schin if (!domainp) {
489*4887Schin if (gethostname(ldomain, sizeof(ldomain)) == -1) {
490*4887Schin nodomain = 1;
491*4887Schin return(0);
492*4887Schin }
493*4887Schin ldomain[MAXHOSTNAMELEN] = (char) 0;
494*4887Schin if ((domainp = index(ldomain, '.')) == (char *)NULL) {
495*4887Schin nodomain = 1;
496*4887Schin return(0);
497*4887Schin }
498*4887Schin for (cp = ++domainp; *cp; ++cp)
499*4887Schin if (isupper(*cp))
500*4887Schin *cp = tolower(*cp);
501*4887Schin }
502*4887Schin return(!strcmp(domainp, rhost + len +1));
503*4887Schin }
504*4887Schin
505*4887Schin #ifdef YP
506*4887Schin static int
_checknetgrouphost(const char * rhost,const char * netgr,int baselen)507*4887Schin _checknetgrouphost(const char *rhost, const char *netgr, int baselen)
508*4887Schin {
509*4887Schin char *host, *user, *domain;
510*4887Schin int status;
511*4887Schin
512*4887Schin if (NULL == nisdomain)
513*4887Schin yp_get_default_domain(&nisdomain);
514*4887Schin
515*4887Schin setnetgrent(netgr);
516*4887Schin while (1)
517*4887Schin {
518*4887Schin while (1 == (status = getnetgrent(&host, &user, &domain))
519*4887Schin && NULL == host
520*4887Schin && NULL != domain
521*4887Schin && 0 != strcmp(domain, nisdomain))
522*4887Schin ; /* find valid host entry */
523*4887Schin
524*4887Schin if (0 == status || NULL == host)
525*4887Schin {
526*4887Schin endnetgrent();
527*4887Schin return 0;
528*4887Schin }
529*4887Schin
530*4887Schin if(1 == _checkhost(rhost, host, baselen))
531*4887Schin {
532*4887Schin endnetgrent();
533*4887Schin return 1;
534*4887Schin }
535*4887Schin }
536*4887Schin }
537*4887Schin
538*4887Schin static int
_checknetgroupuser(const char * ruser,const char * netgr)539*4887Schin _checknetgroupuser(const char *ruser, const char *netgr)
540*4887Schin {
541*4887Schin char *host, *user, *domain;
542*4887Schin int status;
543*4887Schin
544*4887Schin if (NULL == nisdomain)
545*4887Schin yp_get_default_domain(&nisdomain);
546*4887Schin
547*4887Schin setnetgrent(netgr);
548*4887Schin while (1)
549*4887Schin {
550*4887Schin while (1 == (status = getnetgrent(&host, &user, &domain))
551*4887Schin && NULL == user
552*4887Schin && NULL != domain
553*4887Schin && 0 != strcmp(domain, nisdomain))
554*4887Schin ; /* find valid user entry */
555*4887Schin
556*4887Schin if (0 == status || NULL == user)
557*4887Schin {
558*4887Schin endnetgrent();
559*4887Schin return 0;
560*4887Schin }
561*4887Schin
562*4887Schin if(0 == strcmp(ruser, user))
563*4887Schin {
564*4887Schin endnetgrent();
565*4887Schin return 1;
566*4887Schin }
567*4887Schin }
568*4887Schin }
569*4887Schin #endif /* YP */
570*4887Schin
571*4887Schin #endif
572