Print this page
1666 libwrap is 32bit only
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Reviewed by: Garrett D'Amore <garrett.damore@dey-sys.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
   1 /*
   2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 #pragma ident   "%Z%%M% %I%     %E% SMI"
   7 
   8  /*
   9   * tli_host() determines the type of transport (connected, connectionless),
  10   * the transport address of a client host, and the transport address of a
  11   * server endpoint. In addition, it provides methods to map a transport
  12   * address to a printable host name or address. Socket address results are
  13   * in static memory; tli structures are allocated from the heap.
  14   * 
  15   * The result from the hostname lookup method is STRING_PARANOID when a host
  16   * pretends to have someone elses name, or when a host name is available but
  17   * could not be verified.
  18   * 
  19   * Diagnostics are reported through syslog(3).
  20   * 
  21   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  22   */
  23 
  24 #ifndef lint
  25 static char sccsid[] = "@(#) tli.c 1.15 97/03/21 19:27:25";
  26 #endif
  27 


  32 #include <sys/types.h>
  33 #include <sys/param.h>
  34 #include <sys/stream.h>
  35 #include <sys/stat.h>
  36 #include <sys/mkdev.h>
  37 #include <sys/tiuser.h>
  38 #include <sys/timod.h>
  39 #include <sys/socket.h>
  40 #include <netinet/in.h>
  41 #include <stdio.h>
  42 #include <stdlib.h>
  43 #include <unistd.h>
  44 #include <syslog.h>
  45 #include <errno.h>
  46 #include <netconfig.h>
  47 #include <netdir.h>
  48 #include <string.h>
  49 
  50 extern char *nc_sperror();
  51 extern int errno;
  52 extern char *sys_errlist[];
  53 extern int sys_nerr;
  54 extern int t_errno;
  55 extern char *t_errlist[];
  56 extern int t_nerr;
  57 
  58 /* Local stuff. */
  59 
  60 #include "tcpd.h"
  61 
  62 /* Forward declarations. */
  63 
  64 static void tli_endpoints();
  65 static struct netconfig *tli_transport();
  66 static void tli_hostname();
  67 static void tli_hostaddr();
  68 static void tli_cleanup();
  69 static char *tli_error();
  70 static void tli_sink();
  71 
  72 /* tli_host - look up endpoint addresses and install conversion methods */
  73 


 303              */
 304 
 305             if (found == 0)
 306                 tcpd_warn("host name/address mismatch: %s != %.*s",
 307                           host->addr, STRING_LENGTH, service->h_host);
 308         }
 309         STRN_CPY(host->name, found ? service->h_host : paranoid,
 310                  sizeof(host->name));
 311         netdir_free((void *) servlist, ND_HOSTSERVLIST);
 312     }
 313 }
 314 
 315 /* tli_error - convert tli error number to text */
 316 
 317 static char *tli_error()
 318 {
 319     static char buf[40];
 320 
 321     if (t_errno != TSYSERR) {
 322         if (t_errno < 0 || t_errno >= t_nerr) {
 323             sprintf(buf, "Unknown TLI error %d", t_errno);
 324             return (buf);
 325         } else {
 326             return (t_errlist[t_errno]);
 327         }
 328     } else {
 329         if (errno < 0 || errno >= sys_nerr) {
 330             sprintf(buf, "Unknown UNIX error %d", errno);
 331             return (buf);
 332         } else {
 333             return (sys_errlist[errno]);
 334         }
 335     }
 336 }
 337 
 338 /* tli_sink - absorb unreceived datagram */
 339 
 340 static void tli_sink(fd)
 341 int     fd;
 342 {
 343     struct t_unitdata *unit;
 344     int     flags;
 345 
 346     /*
 347      * Something went wrong. Absorb the datagram to keep inetd from looping.
 348      * Allocate storage for address, control and data. If that fails, sleep
 349      * for a couple of seconds in an attempt to keep inetd from looping too
 350      * fast.
 351      */
 352 
 353     if ((unit = (struct t_unitdata *) t_alloc(fd, T_UNITDATA, T_ALL)) == 0) {
 354         tcpd_warn("t_alloc: %s", tli_error());
 355         sleep(5);
   1 /*
   2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 


   6  /*
   7   * tli_host() determines the type of transport (connected, connectionless),
   8   * the transport address of a client host, and the transport address of a
   9   * server endpoint. In addition, it provides methods to map a transport
  10   * address to a printable host name or address. Socket address results are
  11   * in static memory; tli structures are allocated from the heap.
  12   * 
  13   * The result from the hostname lookup method is STRING_PARANOID when a host
  14   * pretends to have someone elses name, or when a host name is available but
  15   * could not be verified.
  16   * 
  17   * Diagnostics are reported through syslog(3).
  18   * 
  19   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  20   */
  21 
  22 #ifndef lint
  23 static char sccsid[] = "@(#) tli.c 1.15 97/03/21 19:27:25";
  24 #endif
  25 


  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/stream.h>
  33 #include <sys/stat.h>
  34 #include <sys/mkdev.h>
  35 #include <sys/tiuser.h>
  36 #include <sys/timod.h>
  37 #include <sys/socket.h>
  38 #include <netinet/in.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <unistd.h>
  42 #include <syslog.h>
  43 #include <errno.h>
  44 #include <netconfig.h>
  45 #include <netdir.h>
  46 #include <string.h>
  47 
  48 extern char *nc_sperror();
  49 extern int errno;


  50 extern int t_errno;
  51 extern char *t_errlist[];
  52 extern int t_nerr;
  53 
  54 /* Local stuff. */
  55 
  56 #include "tcpd.h"
  57 
  58 /* Forward declarations. */
  59 
  60 static void tli_endpoints();
  61 static struct netconfig *tli_transport();
  62 static void tli_hostname();
  63 static void tli_hostaddr();
  64 static void tli_cleanup();
  65 static char *tli_error();
  66 static void tli_sink();
  67 
  68 /* tli_host - look up endpoint addresses and install conversion methods */
  69 


 299              */
 300 
 301             if (found == 0)
 302                 tcpd_warn("host name/address mismatch: %s != %.*s",
 303                           host->addr, STRING_LENGTH, service->h_host);
 304         }
 305         STRN_CPY(host->name, found ? service->h_host : paranoid,
 306                  sizeof(host->name));
 307         netdir_free((void *) servlist, ND_HOSTSERVLIST);
 308     }
 309 }
 310 
 311 /* tli_error - convert tli error number to text */
 312 
 313 static char *tli_error()
 314 {
 315     static char buf[40];
 316 
 317     if (t_errno != TSYSERR) {
 318         if (t_errno < 0 || t_errno >= t_nerr) {
 319             snprintf(buf, sizeof (buf), "Unknown TLI error %d", t_errno);
 320             return (buf);
 321         } else {
 322             return (t_errlist[t_errno]);
 323         }
 324     } else {
 325         STRN_CPY(buf, strerror(errno), sizeof (buf));

 326         return (buf);


 327     }

 328 }
 329 
 330 /* tli_sink - absorb unreceived datagram */
 331 
 332 static void tli_sink(fd)
 333 int     fd;
 334 {
 335     struct t_unitdata *unit;
 336     int     flags;
 337 
 338     /*
 339      * Something went wrong. Absorb the datagram to keep inetd from looping.
 340      * Allocate storage for address, control and data. If that fails, sleep
 341      * for a couple of seconds in an attempt to keep inetd from looping too
 342      * fast.
 343      */
 344 
 345     if ((unit = (struct t_unitdata *) t_alloc(fd, T_UNITDATA, T_ALL)) == 0) {
 346         tcpd_warn("t_alloc: %s", tli_error());
 347         sleep(5);