commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. inetutils-1_8-74-g37017d7


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_8-74-g37017d7
Date: Wed, 24 Nov 2010 18:24:27 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  37017d761e09d6f71f04196de9220b24326be9f3 (commit)
       via  7c9fd5d4c255c644fa9ed2a44b6e619f2f1e83ee (commit)
      from  17819c31287e09170f7f8ac81987078f35175b1a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=37017d761e09d6f71f04196de9220b24326be9f3


commit 37017d761e09d6f71f04196de9220b24326be9f3
Author: Mats Erik Andersson <address@hidden>
Date:   Wed Nov 24 19:22:27 2010 +0100

    addrpeek: New test service for Inetd.

diff --git a/ChangeLog b/ChangeLog
index 81717cf..08c3b23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-11-24  Mats Erik Andersson <address@hidden>
 
+       * tests/addrpeek.c: New file.
+       * tests/Makefile.am: Register `addrpeek' using
+       `check_PROGRAMS', but conditioned on `ENABLE_inetd'.
+
+2010-11-24  Mats Erik Andersson <address@hidden>
+
        * src/inetd.c (prepenv): New prototype:
        `prepenv(int, struct sockaddr *, socklen_t)'.
        (prepenv): Change type of IP to `char []' of fixed length.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cce19ee..1327c5e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,6 +21,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/libinetutils 
-I$(top_srcdir)/lib
 LDADD = -L../libinetutils -linetutils  ../lib/libgnu.a
 
 check_PROGRAMS = localhost
+if ENABLE_inetd
+check_PROGRAMS += addrpeek
+endif
+
 dist_check_SCRIPTS =
 if ENABLE_ping
 dist_check_SCRIPTS += ping-localhost.sh
diff --git a/tests/addrpeek.c b/tests/addrpeek.c
new file mode 100644
index 0000000..02319b2
--- /dev/null
+++ b/tests/addrpeek.c
@@ -0,0 +1,135 @@
+/* addrpeek - testing service for Inetd: remote address, environment vars
+  Copyright (C) 2010 Free Software Foundation, Inc.
+
+  This file is part of GNU Inetutils.
+
+  GNU Inetutils is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or (at
+  your option) any later version.
+
+  GNU Inetutils is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see `http://www.gnu.org/licenses/'. */
+
+/* Written by Mats Erik Andersson.  */
+
+/* Addrpeek is a test client for examining Inetd, primarily TCP traffic.
+ * The client executes all those tasks that were listed as server
+ * arguments in the configuration file for Inetd:
+ *
+ *    addr : Reply with "Your address is $IP."
+ *    env  : Reply with all known environment variables and their values.
+ *
+ * Reasonable entries in `inetf.conf' could be
+ *
+ *    # Return numerical address of the calling client.
+ *    #
+ *    7890 stream tcp nowait nobody /tmp/addrpeek addrpeek addr
+ *    7890 stream tcp6 nowait nobody /tmp/addrpeek addrpeek addr
+ *    #
+ *    # Display all environment variables in use, and append
+ *    # the client's address at the end.
+ *    #
+ *    tcpmux stream tcp nowait nobody internal
+ *    tcpmux stream tcp6 nowait nobody internal
+ *    tcpmux/env stream tcp nowait nobody /tmp/addrpeek addrkeep env addr
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#ifndef SEPARATOR
+# define SEPARATOR "\n"
+#endif
+
+/* TODO Develop some reliable test for the existence of ENVIRON.
+ * It is detectable using HAVE_DECL_ENVIRON for GNU/Linux and
+ * GNU/kFreeBSD. It is present, but not detectable for OpenBSD
+ * and FreeBSD.
+ */
+extern char **environ;
+
+static void
+write_address (int fd)
+{
+  int type;
+  size_t len;
+  socklen_t sslen;
+  char addr[INET6_ADDRSTRLEN], answer[128];
+  struct sockaddr_storage ss;
+
+  sslen = sizeof (type);
+  getsockopt (fd, SOL_SOCKET, SO_TYPE, &type, &sslen);
+
+  if (type == SOCK_STREAM)
+    {
+      sslen = sizeof (ss);
+      getpeername (fd, (struct sockaddr *) &ss, &sslen);
+    }
+  else if (type == SOCK_DGRAM)
+    {
+      sslen = sizeof (ss);
+      recvfrom (fd, answer, sizeof (answer), 0,
+                  (struct sockaddr *) &ss, &sslen);
+      shutdown (fd, SHUT_RD);
+    }
+  else
+      return;
+
+  getnameinfo ((struct sockaddr *) &ss, sslen, addr, sizeof (addr),
+                NULL, 0, NI_NUMERICHOST);
+
+  len = snprintf (answer, sizeof (answer),
+                  "Your address is %s." SEPARATOR, addr);
+
+  sendto (fd, answer, len, 0, (struct sockaddr *) &ss, sslen);
+}
+
+void
+write_environment (int fd, char *envp[])
+{
+  for ( ; *envp; ++envp)
+    {
+      write (fd, *envp, strlen (*envp));
+      write (fd, SEPARATOR, strlen (SEPARATOR));
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+  int j;
+
+  for (j = 1; j < argc; ++j)
+    {
+      if (strncmp (argv[j], "addr", strlen ("addr")) == 0)
+        {
+          write_address (STDOUT_FILENO);
+          continue;
+        }
+
+      if (strncmp (argv[j], "env", strlen ("env")) == 0)
+        {
+          write_environment (STDOUT_FILENO, environ);
+          continue;
+        }
+    }
+
+  close (STDIN_FILENO);
+  close (STDOUT_FILENO);
+  close (STDERR_FILENO);
+
+  return EXIT_SUCCESS;
+}

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=7c9fd5d4c255c644fa9ed2a44b6e619f2f1e83ee


commit 7c9fd5d4c255c644fa9ed2a44b6e619f2f1e83ee
Author: Mats Erik Andersson <address@hidden>
Date:   Wed Nov 24 19:19:12 2010 +0100

    inetd: Environment variables also for IPv6.

diff --git a/ChangeLog b/ChangeLog
index e5eebd9..81717cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2010-11-24  Mats Erik Andersson <address@hidden>
+
+       * src/inetd.c (prepenv): New prototype:
+       `prepenv(int, struct sockaddr *, socklen_t)'.
+       (prepenv): Change type of IP to `char []' of fixed length.
+       Delete HOST.  New integer variable RET.
+       Make type of SA_SERVER depend on macro IPV6, either
+       `struct sockaddr_storage' or `struct sockaddr_in'.
+       (prepenv): Eliminate use of `inet_ntoa' and `gethostbyaddr'
+       by new calls to `getnameinfo', with and without restiction
+       to numeric results.  Debugging output for three select
+       environment variables.
+       (main): Make type of SA_CLIENT depend on macro IPV6, either
+       `struct sockaddr_storage' or `struct sockaddr_in'.  Adaptions
+       to the new prototype for `prepenv'.
+
 2010-11-22  Mats Erik Andersson <address@hidden>
 
        * src/traceroute.c: Include "xalloc.h".
diff --git a/src/inetd.c b/src/inetd.c
index c3cec04..625ebff 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -1696,15 +1696,21 @@ tcpmux (int s, struct servtab *sep)
 
 /* Set TCP environment variables, modelled after djb's ucspi-tcp tools:
    http://cr.yp.to/ucspi-tcp/environment.html
-   FIXME: This needs support for IPv6.
 */
 void
-prepenv (int ctrl, struct sockaddr_in sa_client)
+prepenv (int ctrl, struct sockaddr *sa_client, socklen_t sa_len)
 {
   char str[16];
-  char *ip;
-  struct hostent *host;
+  /* IP is used both for numeric addresses and for symbolic ones.
+   * Being statically allocated, and only for logging purposes,
+   * a full MAXPATHLEN is exaggerated, so a compromise is made.  */
+  char ip[4 * INET6_ADDRSTRLEN];
+  int ret;
+#ifdef IPV6
+  struct sockaddr_storage sa_server;
+#else
   struct sockaddr_in sa_server;
+#endif
   socklen_t len = sizeof (sa_server);
 
   setenv ("PROTO", "TCP", 1);
@@ -1719,47 +1725,58 @@ prepenv (int ctrl, struct sockaddr_in sa_client)
     syslog (LOG_WARNING, "getsockname(): %m");
   else
     {
-      ip = inet_ntoa (sa_server.sin_addr);
-      if (ip)
+      ret = getnameinfo ((struct sockaddr *) &sa_server, len,
+                         ip, sizeof (ip), str, sizeof (str),
+                         NI_NUMERICHOST | NI_NUMERICSERV);
+      if (ret == 0)
        {
          if (setenv ("TCPLOCALIP", ip, 1) < 0)
            syslog (LOG_WARNING, "setenv (TCPLOCALIP): %m");
-       }
+         else if (debug)
+           fprintf (stderr, "Assigned TCPLOCALIP = %s\n", ip);
 
-      snprintf (str, sizeof (str), "%d", ntohs (sa_server.sin_port));
-      setenv ("TCPLOCALPORT", str, 1);
+         if (setenv ("TCPLOCALPORT", str, 1) < 0)
+           syslog (LOG_WARNING, "setenv (TCPLOCALPORT): %m");
+       }
+      else
+       syslog (LOG_WARNING, "getnameinfo: %s", gai_strerror (ret));
 
       if (resolve_option)
        {
-         if ((host = gethostbyaddr ((char *) &sa_server.sin_addr,
-                                    sizeof (sa_server.sin_addr),
-                                    AF_INET)) == NULL)
-           syslog (LOG_WARNING, "gethostbyaddr: %m");
-         else if (setenv ("TCPLOCALHOST", host->h_name, 1) < 0)
+         ret = getnameinfo ((struct sockaddr *) &sa_server, len,
+                             ip, sizeof (ip), NULL, 0, 0);
+         if (ret != 0)
+           syslog (LOG_WARNING, "getnameinfo: %s", gai_strerror (ret));
+         else if (setenv ("TCPLOCALHOST", ip, 1) < 0)
            syslog (LOG_WARNING, "setenv(TCPLOCALHOST): %m");
        }
     }
 
-  ip = inet_ntoa (sa_client.sin_addr);
-  if (ip)
+  ret = getnameinfo (sa_client, sa_len, ip, sizeof (ip), str, sizeof (str),
+                     NI_NUMERICHOST | NI_NUMERICSERV);
+  if (ret == 0)
     {
       if (setenv ("TCPREMOTEIP", ip, 1) < 0)
        syslog (LOG_WARNING, "setenv(TCPREMOTEIP): %m");
-    }
+      else if (debug)
+       fprintf (stderr, "Assigned TCPREMOTEIP = %s\n", ip);
 
-  snprintf (str, sizeof (str), "%d", ntohs (sa_client.sin_port));
-  if (setenv ("TCPREMOTEPORT", str, 1) < 0)
-    syslog (LOG_WARNING, "setenv(TCPREMOTEPORT): %m");
+      if (setenv ("TCPREMOTEPORT", str, 1) < 0)
+       syslog (LOG_WARNING, "setenv(TCPREMOTEPORT): %m");
 
-  if (resolve_option)
-    {
-      if ((host = gethostbyaddr ((char *) &sa_client.sin_addr,
-                                sizeof (sa_client.sin_addr),
-                                AF_INET)) == NULL)
-       syslog (LOG_WARNING, "gethostbyaddr: %m");
-      else if (setenv ("TCPREMOTEHOST", host->h_name, 1) < 0)
-       syslog (LOG_WARNING, "setenv(TCPREMOTEHOST): %m");
+      if (resolve_option)
+       {
+         ret = getnameinfo (sa_client, sa_len, ip, sizeof (ip), NULL, 0, 0);
+         if (ret != 0)
+           syslog (LOG_WARNING, "getnameinfo: %s", gai_strerror (ret));
+         else if (setenv ("TCPREMOTEHOST", ip, 1) < 0)
+           syslog (LOG_WARNING, "setenv(TCPREMOTEHOST): %m");
+         else if (debug)
+           fprintf (stderr, "Assigned TCPREMOTEHOST = %s\n", ip);
+       }
     }
+  else
+    syslog (LOG_WARNING, "getnameinfo: %s", gai_strerror (ret));
 }
 
 
@@ -1870,7 +1887,11 @@ main (int argc, char *argv[], char *envp[])
              fprintf (stderr, "someone wants %s\n", sep->se_service);
            if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
              {
+#ifdef IPV6
+               struct sockaddr_storage sa_client;
+#else
                struct sockaddr_in sa_client;
+#endif
                socklen_t len = sizeof (sa_client);
 
                ctrl = accept (sep->se_fd, (struct sockaddr *) &sa_client,
@@ -1885,7 +1906,7 @@ main (int argc, char *argv[], char *envp[])
                    continue;
                  }
                if (env_option)
-                 prepenv (ctrl, sa_client);
+                 prepenv (ctrl, (struct sockaddr *) &sa_client, len);
              }
            else
              ctrl = sep->se_fd;

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog         |   22 +++++++++
 src/inetd.c       |   79 ++++++++++++++++++++-----------
 tests/Makefile.am |    4 ++
 tests/addrpeek.c  |  135 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 29 deletions(-)
 create mode 100644 tests/addrpeek.c


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]