]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/inet/rpc/rcmd.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / inet / rpc / rcmd.c
1 /*
2  * Copyright (C) 1998 WIDE Project.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the project nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 /*
30  * Copyright (c) 1983, 1993, 1994
31  *      The Regents of the University of California.  All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 4. Neither the name of the University nor the names of its contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  */
57
58 #if 0
59 static char sccsid[] = "@(#)rcmd.c      8.3 (Berkeley) 3/26/94";
60 #endif /* LIBC_SCCS and not lint */
61
62 #define __UCLIBC_HIDE_DEPRECATED__
63 #include <features.h>
64 #include <sys/param.h>
65 #include <sys/poll.h>
66 #include <sys/socket.h>
67 #include <sys/stat.h>
68
69 #include <netinet/in.h>
70 #include <arpa/inet.h>
71
72 #include <signal.h>
73 #include <fcntl.h>
74 #include <netdb.h>
75 #include <unistd.h>
76 #include <pwd.h>
77 #include <errno.h>
78 #include <stdio.h>
79 #include <ctype.h>
80 #include <string.h>
81 #include <libintl.h>
82 #include <stdlib.h>
83 #ifdef __UCLIBC_HAS_WCHAR__
84 #include <wchar.h>
85 #endif
86 #include <sys/uio.h>
87 #include <bits/uClibc_alloc.h>
88
89 /* sigsetmask and sigblock are not provided anymore, until this file is corrected,
90  * include the sources */
91 #include "../../signal/sigblock.c"
92 #include "../../signal/sigsetmask.c"
93
94
95 /* some forward declarations */
96 static int __ivaliduser2(FILE *hostf, u_int32_t raddr,
97                          const char *luser, const char *ruser, const char *rhost);
98 static int iruserok2 (u_int32_t raddr, int superuser, const char *ruser,
99                       const char *luser, const char *rhost);
100
101
102 int rcmd(char **ahost, u_short rport, const char *locuser, const char *remuser,
103                  const char *cmd, int *fd2p)
104 {
105 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
106         int herr;
107         struct hostent hostbuf;
108         size_t hstbuflen;
109         char *tmphstbuf;
110 #endif
111         struct hostent *hp;
112         struct sockaddr_in sin, from;
113         struct pollfd pfd[2];
114         int32_t oldmask;
115         pid_t pid;
116         int s, lport, timo;
117         char c;
118
119         pid = getpid();
120
121 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
122         hstbuflen = 1024;
123         tmphstbuf = stack_heap_alloc(hstbuflen);
124
125         while (gethostbyname_r (*ahost, &hostbuf, tmphstbuf,
126                     hstbuflen, &hp, &herr) != 0 || hp == NULL)
127         {
128             if (herr != NETDB_INTERNAL || errno != ERANGE)
129             {
130                 __set_h_errno (herr);
131                 stack_heap_free(tmphstbuf);
132                 herror(*ahost);
133                 return -1;
134             }
135             else
136             {
137                 /* Enlarge the buffer.  */
138                 hstbuflen *= 2;
139                 stack_heap_free(tmphstbuf);
140                 tmphstbuf = stack_heap_alloc(hstbuflen);
141             }
142         }
143         stack_heap_free(tmphstbuf);
144 #else /* call the non-reentrant version */
145         if ((hp = gethostbyname(*ahost)) == NULL) {
146             return -1;
147         }
148 #endif
149         pfd[0].events = POLLIN;
150         pfd[1].events = POLLIN;
151
152         *ahost = hp->h_name;
153         oldmask = sigblock(__sigmask(SIGURG)); /* sigblock */
154         for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
155                 s = rresvport(&lport);
156                 if (s < 0) {
157                         if (errno == EAGAIN)
158                             (void)fprintf(stderr,
159                                           "rcmd: socket: All ports in use\n");
160                         else
161                             (void)fprintf(stderr, "rcmd: socket: %m\n");
162                         sigsetmask(oldmask); /* sigsetmask */
163                         return -1;
164                 }
165                 fcntl(s, F_SETOWN, pid);
166                 sin.sin_family = hp->h_addrtype;
167                 memmove(&sin.sin_addr, hp->h_addr_list[0],
168                       MIN (sizeof (sin.sin_addr), hp->h_length));
169                 sin.sin_port = rport;
170                 if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) /* __connect */
171                         break;
172                 (void)close(s);
173                 if (errno == EADDRINUSE) {
174                         lport--;
175                         continue;
176                 }
177                 if (errno == ECONNREFUSED && timo <= 16) {
178                         (void)sleep(timo); /* __sleep */
179                         timo *= 2;
180                         continue;
181                 }
182                 if (hp->h_addr_list[1] != NULL) {
183                         int oerrno = errno;
184
185                         (void)fprintf(stderr, "connect to address %s: ",
186                             inet_ntoa(sin.sin_addr));
187                         __set_errno (oerrno);
188                         perror(0);
189                         hp->h_addr_list++;
190                         memmove(&sin.sin_addr, hp->h_addr_list[0],
191                               MIN (sizeof (sin.sin_addr), hp->h_length));
192                         (void)fprintf(stderr, "Trying %s...\n",
193                             inet_ntoa(sin.sin_addr));
194                         continue;
195                 }
196                 (void)fprintf(stderr, "%s: %m\n", hp->h_name);
197                 sigsetmask(oldmask); /* __sigsetmask */
198                 return -1;
199         }
200         lport--;
201         if (fd2p == 0) {
202                 write(s, "", 1);
203                 lport = 0;
204         } else {
205                 char num[8];
206                 int s2 = rresvport(&lport), s3;
207                 socklen_t len = sizeof(from);
208
209                 if (s2 < 0)
210                         goto bad;
211                 listen(s2, 1);
212                 (void)snprintf(num, sizeof(num), "%d", lport); /* __snprintf */
213                 if (write(s, num, strlen(num)+1) != strlen(num)+1) {
214                         (void)fprintf(stderr,
215                                       "rcmd: write (setting up stderr): %m\n");
216                         (void)close(s2);
217                         goto bad;
218                 }
219                 pfd[0].fd = s;
220                 pfd[1].fd = s2;
221                 __set_errno (0);
222                 if (poll (pfd, 2, -1) < 1 || (pfd[1].revents & POLLIN) == 0){
223                     if (errno != 0)
224                         (void)fprintf(stderr, "rcmd: poll (setting up stderr): %m\n");
225                     else
226                         (void)fprintf(stderr, "poll: protocol failure in circuit setup\n");
227                         (void)close(s2);
228                         goto bad;
229                 }
230                 s3 = accept(s2, (struct sockaddr *)&from, &len);
231                 (void)close(s2);
232                 if (s3 < 0) {
233                         (void)fprintf(stderr,
234                             "rcmd: accept: %m\n");
235                         lport = 0;
236                         goto bad;
237                 }
238                 *fd2p = s3;
239                 from.sin_port = ntohs((u_short)from.sin_port);
240                 if (from.sin_family != AF_INET ||
241                     from.sin_port >= IPPORT_RESERVED ||
242                     from.sin_port < IPPORT_RESERVED / 2) {
243                         (void)fprintf(stderr,
244                             "socket: protocol failure in circuit setup\n");
245                         goto bad2;
246                 }
247         }
248         (void)write(s, locuser, strlen(locuser)+1);
249         (void)write(s, remuser, strlen(remuser)+1);
250         (void)write(s, cmd, strlen(cmd)+1);
251         if (read(s, &c, 1) != 1) {
252                 (void)fprintf(stderr,
253                     "rcmd: %s: %m\n", *ahost);
254                 goto bad2;
255         }
256         if (c != 0) {
257                 while (read(s, &c, 1) == 1) {
258                         (void)write(STDERR_FILENO, &c, 1);
259                         if (c == '\n')
260                                 break;
261                 }
262                 goto bad2;
263         }
264         sigsetmask(oldmask);
265         return s;
266 bad2:
267         if (lport)
268                 (void)close(*fd2p);
269 bad:
270         (void)close(s);
271         sigsetmask(oldmask);
272         return -1;
273 }
274
275 int rresvport(int *alport)
276 {
277     struct sockaddr_in sin;
278     int s;
279
280     sin.sin_family = AF_INET;
281     sin.sin_addr.s_addr = INADDR_ANY;
282     s = socket(AF_INET, SOCK_STREAM, 0);
283     if (s < 0)
284         return -1;
285     for (;;) {
286         sin.sin_port = htons((u_short)*alport);
287         if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
288             return s;
289         if (errno != EADDRINUSE) {
290             (void)close(s);
291             return -1;
292         }
293         (*alport)--;
294         if (*alport == IPPORT_RESERVED/2) {
295             (void)close(s);
296             __set_errno (EAGAIN);               /* close */
297             return -1;
298         }
299     }
300
301     return -1;
302 }
303 libc_hidden_def(rresvport)
304
305 /* This needs to be exported ... while it is not a documented interface
306  * for rcp related apps, it's a required one that is used to control the
307  * rhost behavior.  Legacy sucks.
308  */
309 int  __check_rhosts_file = 1;
310
311 int ruserok(const char *rhost, int superuser, const char *ruser,
312                         const char *luser)
313 {
314         struct hostent *hp;
315         u_int32_t addr;
316         char **ap;
317 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
318         size_t buflen;
319         char *buffer;
320         int herr;
321         struct hostent hostbuf;
322 #endif
323
324 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
325         buflen = 1024;
326         buffer = stack_heap_alloc(buflen);
327
328         while (gethostbyname_r (rhost, &hostbuf, buffer,
329                     buflen, &hp, &herr) != 0 || hp == NULL)
330         {
331             if (herr != NETDB_INTERNAL || errno != ERANGE) {
332                 stack_heap_free(buffer);
333                 return -1;
334             } else
335             {
336                 /* Enlarge the buffer.  */
337                 buflen *= 2;
338                 stack_heap_free(buffer);
339                 buffer = stack_heap_alloc(buflen);
340             }
341         }
342         stack_heap_free(buffer);
343 #else
344         if ((hp = gethostbyname(rhost)) == NULL) {
345                 return -1;
346         }
347 #endif
348         for (ap = hp->h_addr_list; *ap; ++ap) {
349                 memmove(&addr, *ap, sizeof(addr));
350                 if (iruserok2(addr, superuser, ruser, luser, rhost) == 0)
351                         return 0;
352         }
353         return -1;
354 }
355
356
357 /* Extremely paranoid file open function. */
358 static FILE *
359 iruserfopen (const char *file, uid_t okuser)
360 {
361   struct stat st;
362   char *cp = NULL;
363   FILE *res = NULL;
364
365   /* If not a regular file, if owned by someone other than user or
366      root, if writeable by anyone but the owner, or if hardlinked
367      anywhere, quit.  */
368   if (lstat (file, &st))
369     cp = "lstat failed";
370   else if (!S_ISREG (st.st_mode))
371     cp = "not regular file";
372   else
373     {
374       res = fopen (file, "r");
375       if (!res)
376         cp = "cannot open";
377       else if (fstat (fileno (res), &st) < 0)
378         cp = "fstat failed";
379       else if (st.st_uid && st.st_uid != okuser)
380         cp = "bad owner";
381       else if (st.st_mode & (S_IWGRP|S_IWOTH))
382         cp = "writeable by other than owner";
383       else if (st.st_nlink > 1)
384         cp = "hard linked somewhere";
385     }
386
387   /* If there were any problems, quit.  */
388   if (cp != NULL)
389     {
390       if (res)
391         fclose (res);
392       return NULL;
393     }
394
395   return res;
396 }
397
398
399 /*
400  * New .rhosts strategy: We are passed an ip address. We spin through
401  * hosts.equiv and .rhosts looking for a match. When the .rhosts only
402  * has ip addresses, we don't have to trust a nameserver.  When it
403  * contains hostnames, we spin through the list of addresses the nameserver
404  * gives us and look for a match.
405  *
406  * Returns 0 if ok, -1 if not ok.
407  */
408 static int
409 iruserok2 (u_int32_t raddr, int superuser, const char *ruser, const char *luser,
410                    const char *rhost)
411 {
412         FILE *hostf = NULL;
413         int isbad = -1;
414
415         if (!superuser)
416                 hostf = iruserfopen (_PATH_HEQUIV, 0);
417
418         if (hostf) {
419                 isbad = __ivaliduser2 (hostf, raddr, luser, ruser, rhost);
420                 fclose (hostf);
421
422                 if (!isbad)
423                         return 0;
424         }
425
426         if (__check_rhosts_file || superuser) {
427                 char *pbuf;
428                 struct passwd *pwd;
429                 size_t dirlen;
430                 uid_t uid;
431
432 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
433                 size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
434                 struct passwd pwdbuf;
435                 char *buffer = stack_heap_alloc(buflen);
436
437                 if (getpwnam_r (luser, &pwdbuf, buffer,
438                             buflen, &pwd) != 0 || pwd == NULL)
439                 {
440                         stack_heap_free(buffer);
441                         return -1;
442                 }
443                 stack_heap_free(buffer);
444 #else
445                 if ((pwd = getpwnam(luser)) == NULL)
446                         return -1;
447 #endif
448
449                 dirlen = strlen (pwd->pw_dir);
450                 pbuf = malloc (dirlen + sizeof "/.rhosts");
451                 strcpy (pbuf, pwd->pw_dir);
452                 strcat (pbuf, "/.rhosts");
453
454                 /* Change effective uid while reading .rhosts.  If root and
455                    reading an NFS mounted file system, can't read files that
456                    are protected read/write owner only.  */
457                 uid = geteuid ();
458                 seteuid (pwd->pw_uid);
459                 hostf = iruserfopen (pbuf, pwd->pw_uid);
460                 free(pbuf);
461
462                 if (hostf != NULL) {
463                         isbad = __ivaliduser2 (hostf, raddr, luser, ruser, rhost);
464                         fclose (hostf);
465                 }
466
467                 seteuid (uid);
468                 return isbad;
469         }
470         return -1;
471 }
472
473 /* This is the exported version.  */
474 int iruserok (u_int32_t raddr, int superuser, const char * ruser, const char * luser);
475 int iruserok (u_int32_t raddr, int superuser, const char * ruser, const char * luser)
476 {
477         return iruserok2 (raddr, superuser, ruser, luser, "-");
478 }
479
480
481 /*
482  * XXX
483  * Don't make static, used by lpd(8).
484  *
485  * This function is not used anymore. It is only present because lpd(8)
486  * calls it (!?!). We simply call __invaliduser2() with an illegal rhost
487  * argument. This means that netgroups won't work in .rhost/hosts.equiv
488  * files. If you want lpd to work with netgroups, fix lpd to use ruserok()
489  * or PAM.
490  * Returns 0 if ok, -1 if not ok.
491  */
492 int
493 __ivaliduser(FILE *hostf, u_int32_t raddr, const char *luser, const char *ruser);
494 int
495 __ivaliduser(FILE *hostf, u_int32_t raddr, const char *luser, const char *ruser)
496 {
497         return __ivaliduser2(hostf, raddr, luser, ruser, "-");
498 }
499
500
501 /* Returns 1 on positive match, 0 on no match, -1 on negative match.  */
502 static int
503 __icheckhost (u_int32_t raddr, char *lhost, const char *rhost)
504 {
505         struct hostent *hp;
506         u_int32_t laddr;
507         int negate=1;    /* Multiply return with this to get -1 instead of 1 */
508         char **pp;
509
510 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
511         int save_errno;
512         size_t buflen;
513         char *buffer;
514         struct hostent hostbuf;
515         int herr;
516 #endif
517
518 #ifdef HAVE_NETGROUP
519         /* Check nis netgroup.  */
520         if (strncmp ("+@", lhost, 2) == 0)
521                 return innetgr (&lhost[2], rhost, NULL, NULL);
522
523         if (strncmp ("-@", lhost, 2) == 0)
524                 return -innetgr (&lhost[2], rhost, NULL, NULL);
525 #endif /* HAVE_NETGROUP */
526
527         /* -host */
528         if (strncmp ("-", lhost,1) == 0) {
529                 negate = -1;
530                 lhost++;
531         } else if (strcmp ("+",lhost) == 0) {
532                 return 1;                    /* asking for trouble, but ok.. */
533         }
534
535         /* Try for raw ip address first. */
536         if (isdigit (*lhost) && (laddr = inet_addr (lhost)) != INADDR_NONE)
537                 return negate * (! (raddr ^ laddr));
538
539         /* Better be a hostname. */
540 #ifdef __UCLIBC_HAS_REENTRANT_RPC__
541         buflen = 1024;
542         buffer = malloc(buflen);
543         save_errno = errno;
544
545         while (gethostbyname_r (lhost, &hostbuf, buffer, buflen, &hp, &herr)
546                != 0) {
547             free(buffer);
548             return (0);
549         }
550         free(buffer);
551         __set_errno (save_errno);
552 #else
553         hp = gethostbyname(lhost);
554 #endif /* __UCLIBC_HAS_REENTRANT_RPC__ */
555
556         if (hp == NULL)
557                 return 0;
558
559         /* Spin through ip addresses. */
560         for (pp = hp->h_addr_list; *pp; ++pp)
561                 if (!memcmp (&raddr, *pp, sizeof (u_int32_t)))
562                         return negate;
563
564         /* No match. */
565         return (0);
566 }
567
568 /* Returns 1 on positive match, 0 on no match, -1 on negative match.  */
569 static int
570 __icheckuser (const char *luser, const char *ruser)
571 {
572
573     /*
574       luser is user entry from .rhosts/hosts.equiv file
575       ruser is user id on remote host
576       */
577
578 #ifdef HAVE_NETGROUP
579     /* [-+]@netgroup */
580     if (strncmp ("+@", luser, 2) == 0)
581         return innetgr (&luser[2], NULL, ruser, NULL);
582
583     if (strncmp ("-@", luser,2) == 0)
584         return -innetgr (&luser[2], NULL, ruser, NULL);
585 #endif /* HAVE_NETGROUP */
586
587     /* -user */
588     if (strncmp ("-", luser, 1) == 0)
589         return -(strcmp (&luser[1], ruser) == 0);
590
591     /* + */
592     if (strcmp ("+", luser) == 0)
593         return 1;
594
595     /* simple string match */
596     return strcmp (ruser, luser) == 0;
597 }
598
599 /*
600  * Returns 1 for blank lines (or only comment lines) and 0 otherwise
601  */
602 static int
603 __isempty(char *p)
604 {
605     while (*p && isspace (*p)) {
606         ++p;
607     }
608
609     return (*p == '\0' || *p == '#') ? 1 : 0 ;
610 }
611
612 /*
613  * Returns 0 if positive match, -1 if _not_ ok.
614  */
615 static int
616 __ivaliduser2(FILE *hostf, u_int32_t raddr,     const char *luser,
617                           const char *ruser, const char *rhost)
618 {
619     register const char *user;
620     register char *p;
621     int hcheck, ucheck;
622     char *buf = NULL;
623     size_t bufsize = 0;
624     int retval = -1;
625
626     while (getline (&buf, &bufsize, hostf) > 0) {
627         buf[bufsize - 1] = '\0'; /* Make sure it's terminated.  */
628         p = buf;
629
630         /* Skip empty or comment lines */
631         if (__isempty (p)) {
632             continue;
633         }
634
635         /* Skip lines that are too long. */
636         if (strchr (p, '\n') == NULL) {
637             int ch = getc_unlocked (hostf);
638
639             while (ch != '\n' && ch != EOF)
640               ch = getc_unlocked (hostf);
641             continue;
642         }
643
644         for (;*p && !isspace(*p); ++p) {
645             *p = tolower (*p);
646         }
647
648         /* Next we want to find the permitted name for the remote user.  */
649         if (*p == ' ' || *p == '\t') {
650             /* <nul> terminate hostname and skip spaces */
651             for (*p++='\0'; *p && isspace (*p); ++p);
652
653             user = p;                   /* this is the user's name */
654             while (*p && !isspace (*p))
655                 ++p;                    /* find end of user's name */
656         } else
657             user = p;
658
659         *p = '\0';              /* <nul> terminate username (+host?) */
660
661         /* buf -> host(?) ; user -> username(?) */
662
663         /* First check host part */
664         hcheck = __icheckhost (raddr, buf, rhost);
665
666         if (hcheck < 0)
667             break;
668
669         if (hcheck) {
670             /* Then check user part */
671             if (! (*user))
672                 user = luser;
673
674             ucheck = __icheckuser (user, ruser);
675
676             /* Positive 'host user' match? */
677             if (ucheck > 0) {
678                 retval = 0;
679                 break;
680             }
681
682             /* Negative 'host -user' match? */
683             if (ucheck < 0)
684                 break;
685
686             /* Neither, go on looking for match */
687         }
688     }
689
690     free (buf);
691
692     return retval;
693 }