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_9_2-22-g38246a


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_2-22-g38246ac
Date: Thu, 12 Jun 2014 17:00:07 +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  38246ac903db567f149dad428403f2182ea03b4e (commit)
      from  a776a603369e644f031eee771bf388ab0edb3b91 (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=38246ac903db567f149dad428403f2182ea03b4e


commit 38246ac903db567f149dad428403f2182ea03b4e
Author: Mats Erik Andersson <address@hidden>
Date:   Thu Jun 5 23:31:56 2014 +0200

    ftp: Allow other locations of netrc file.
    
    Introduce a command line option and an environment
    variable to override the legacy location $HOME/.netrc.

diff --git a/ChangeLog b/ChangeLog
index f3a0470..9967cf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2014-06-05  Mats Erik Andersson  <address@hidden>
+
+       ftp: Alternate selection of .netrc file.
+
+       * ftp/ftp_var.h (netrc): New variable.
+       * ftp/main.c (argp_options) <-N/--netrc>: New option.
+       (parse_opt) <'N'>: New case.
+       (main): Initialize `netrc'.
+       * ftp/ruserpass.c (remote_userpass): If `netrc' is NULL,
+       check NETRC in environment.  Whenever `netrc' has content,
+       us it instead of `~/.netrc'.  Once CFILE is valid, make
+       sure that the file location is a regular file, otherwise
+       returning to the interpreter.
+
+       * tests/ftp-localhost.sh: Two new test cases, checking the
+       functionality of NETRC in environment, and the option `-N'.
+
 2014-05-16  Mats Erik Andersson  <address@hidden>
 
        ftp: Size multipliers for hash increments.
diff --git a/NEWS b/NEWS
index ec49848..ec41f5f 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,15 @@ Please send inetutils bug reports to <address@hidden>.
 
 Version 1.9.3:
 
+* ftp
+
+The internal command `hash' accepts a suffixed letter to the
+size argument, like `12k', instead of 12288. Also, the .netrc
+file can be overridden by the environment variable NETRC.
+Of even higher precedence is the new option `-N/--netrc'.
+The access to the resulting file, whatever method, is now
+denied unless it as a regular file.
+
 * syslogd
 
 A new switch `-T/--local-time' makes the service ignore a time
diff --git a/doc/inetutils.texi b/doc/inetutils.texi
index aff02e9..21a33b5 100644
--- a/doc/inetutils.texi
+++ b/doc/inetutils.texi
@@ -1381,6 +1381,15 @@ Disables file name globbing.
 @opindex --no-prompt
 Turns off interactive prompting during multiple file transfers.
 
address@hidden -N @var{netrc}
address@hidden address@hidden
address@hidden -N
address@hidden --netrc
+Set a preferred location of the @file{.netrc} file,
+thus overriding any environment setting in @env{NETRC},
+as well as the default location @file{$HOME/.netrc},
address@hidden .netrc file}.
+
 @item -n
 @itemx --no-login
 @opindex -n
@@ -2046,8 +2055,13 @@ Avoid this problem by using the binary image type.
 @flindex .netrc
 
 The @file{.netrc} file contains login and initialization information
-used by the auto-login process.  It resides in the user's home
-directory.  The following tokens are recognized; they may be separated
+used by the auto-login process.  It generally resides in the user's
+home directory, but a location outside of the home directory
+can be set using the environment variable @env{NETRC}.
+Both locations are overridden by the command line option @option{-N}.
+The selected file must be a regular file, or access will be denied.
+
+The following tokens are recognized; they may be separated
 by spaces, tabs, or new-lines:
 
 @table @samp
@@ -2108,6 +2122,10 @@ executed as the last step in the auto-login process.
 @item HOME
 Used for locating a @file{.netrc} file, if one exists.
 
address@hidden NETRC
+Alternate location of the @file{.netrc} file,
+taking precedence over the standard location.
+
 @item SHELL
 For determining the default shell interpreter.
 @end table
diff --git a/ftp/ftp_var.h b/ftp/ftp_var.h
index 02ea7ba..ebe2c10 100644
--- a/ftp/ftp_var.h
+++ b/ftp/ftp_var.h
@@ -108,6 +108,7 @@ FTP_EXTERN char bytename[32];       /* local byte size in 
ascii */
 FTP_EXTERN int bytesize;       /* local byte size in binary */
 
 FTP_EXTERN char *hostname;     /* name of host connected to */
+FTP_EXTERN char *netrc;                /* netrc file chosen on command line */
 FTP_EXTERN int unix_server;    /* server is unix, can use binary for ascii */
 FTP_EXTERN int unix_proxy;     /* proxy is unix, can use binary for ascii */
 
diff --git a/ftp/main.c b/ftp/main.c
index cb52729..a3d252e 100644
--- a/ftp/main.c
+++ b/ftp/main.c
@@ -134,6 +134,8 @@ static struct argp_option argp_options[] = {
   {"verbose", 'v', NULL, 0, "verbose output", GRP+1},
   {"ipv4", '4', NULL, 0, "contact IPv4 hosts", GRP+1},
   {"ipv6", '6', NULL, 0, "contact IPv6 hosts", GRP+1},
+  {"netrc", 'N', "NETRC", 0, "select a specific initialization file",
+   GRP+1},
 #undef GRP
   {NULL, 0, NULL, 0, NULL, 0}
 };
@@ -192,6 +194,10 @@ parse_opt (int key, char *arg, struct argp_state *state 
_GL_UNUSED_PARAMETER)
       usefamily = AF_INET6;
       break;
 
+    case 'N':
+      netrc = arg;
+      break;
+
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -228,6 +234,7 @@ main (int argc, char *argv[])
   line = NULL;                 /* reset global input */
   linelen = 0;
   argbuf = NULL;
+  netrc = NULL;
 
   /* Invoked as `pftp'?  Then set passive mode.  */
   cp = strrchr (argv[0], '/');
diff --git a/ftp/ruserpass.c b/ftp/ruserpass.c
index 2b8edec..953c853 100644
--- a/ftp/ruserpass.c
+++ b/ftp/ruserpass.c
@@ -123,6 +123,14 @@ remote_userpass (char *host, char **aname, char **apass, 
char **aacct)
   if (hdir == NULL)
     hdir = ".";
   snprintf (buf, sizeof buf, "%s/.netrc", hdir);
+
+  /* The switch `-N/--netrc' would have set this.  */
+  if (!netrc)
+    netrc = getenv ("NETRC");
+
+  if (netrc && netrc[0])
+    snprintf (buf, sizeof buf, "%s", netrc);
+
   cfile = fopen (buf, "r");
   if (cfile == NULL)
     {
@@ -131,6 +139,28 @@ remote_userpass (char *host, char **aname, char **apass, 
char **aacct)
       return (0);
     }
 
+  /* The .netrc is now opened and is thus fixed.
+   * Check that it is a regular file, and not a
+   * soft link in particular.
+   */
+  if (lstat (buf, &stb) < 0)
+    {
+      error (0, errno, "%s", buf);
+      fclose (cfile);
+      return (-1);
+    }
+
+  if (!S_ISREG (stb.st_mode))
+    {
+      if (S_ISLNK (stb.st_mode))
+       error (0, 0, "the .netrc file is symbolic link: %s", buf);
+      else
+       error (0, 0, "the .netrc file is no regular file: %s", buf);
+
+      fclose (cfile);
+      return (-1);
+    }
+
   myname = localhost ();
   if (!myname)
     myname = xstrdup ("");
diff --git a/tests/ftp-localhost.sh b/tests/ftp-localhost.sh
index 592fa1a..dc14009 100755
--- a/tests/ftp-localhost.sh
+++ b/tests/ftp-localhost.sh
@@ -393,6 +393,37 @@ HOME=$TMPDIR $FTP "$TARGET" $PORT -4 -v -p -t 
>$TMPDIR/ftp.stdout 2>&1
 
 test_report $? "$TMPDIR/ftp.stdout" "EPSV/$TARGET"
 
+# Test a passive connection: EPSV and IPv4.
+#
+# Set NETRC in environment to regulate login.
+#
+echo "EPSV to $TARGET (IPv4) using inetd, setting NETRC."
+cat <<STOP |
+rstatus
+epsv4
+dir
+`$do_transfer && test -n "$DLDIR" && echo "\
+cd $DLDIR"`
+`$do_transfer && echo "\
+lcd $TMPDIR
+image
+put $GETME $PUTME"`
+STOP
+
+NETRC=$TMPDIR/.netrc \
+  $FTP "$TARGET" $PORT -4 -v -p -t >$TMPDIR/ftp.stdout 2>&1
+
+test_report $? "$TMPDIR/ftp.stdout" "EPSV/$TARGET with NETRC"
+
+$do_transfer && \
+    if cmp -s "$TMPDIR/$GETME" "$FTPHOME$DLDIR/$PUTME"; then
+       test "${VERBOSE+yes}" && echo >&2 'Binary transfer succeeded.'
+       date "+%s" >> "$TMPDIR/$GETME"
+    else
+       echo >&2 'Binary transfer failed.'
+       exit 1
+    fi
+
 # Test an active connection: EPRT and IPv4.
 #
 echo "EPRT to $TARGET (IPv4) using inetd."
@@ -420,6 +451,21 @@ $do_transfer && \
        exit 1
     fi
 
+# Test an active connection: EPRT and IPv4.
+#
+# Use `-N' to set location of .netrc file.
+#
+echo "EPRT to $TARGET (IPv4) using inetd, apply the switch -N."
+cat <<STOP |
+rstatus
+epsv4
+dir
+STOP
+
+$FTP "$TARGET" $PORT -N"$TMPDIR/.netrc" -4 -v -t >$TMPDIR/ftp.stdout 2>&1
+
+test_report $? "$TMPDIR/ftp.stdout" "EPRT/$TARGET"
+
 # Test a passive connection: EPSV and IPv6.
 #
 echo "EPSV to $TARGET6 (IPv6) using inetd."

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

Summary of changes:
 ChangeLog              |   17 +++++++++++++++++
 NEWS                   |    9 +++++++++
 doc/inetutils.texi     |   22 ++++++++++++++++++++--
 ftp/ftp_var.h          |    1 +
 ftp/main.c             |    7 +++++++
 ftp/ruserpass.c        |   30 ++++++++++++++++++++++++++++++
 tests/ftp-localhost.sh |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 130 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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