pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/net/tnftp/files Import tnftp 20050610.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0144cfbd792c
branches:  trunk
changeset: 495451:0144cfbd792c
user:      lukem <lukem%pkgsrc.org@localhost>
date:      Fri Jun 10 04:52:08 2005 +0000

description:
Import tnftp 20050610.

Security-related bug fixes:
* Convert to use getline() instead of fgets() whenever reading user input to
  ensure that an overly long input line doesn't leave excess characters for
  the next input operation to accidentally use as input.
* Zero out the password & account after we've finished with it.
* Consistently use getpass(3) (i.e, character echo suppressed) when reading
  the account data.  For some reason, historically the "login" code
  suppressed echo for Account: yet the "user" command did not!
* Improve method used in fileindir() to determine if `file' is in or under
  `dir': realpath(3) on non-NetBSD systems may fail if the target filename
  doesn't exist, so instead use realpath(3) on the parent directory of `file'.
  (The previous code was over-aggressive in preventing transfers on systems
  with a realpath(3) that had different semantics to NetBSD.)

Bug fixes:
* Display the hostname in the "getaddrinfo failed" warning.
* Only print the "Trying <address>..." message if verbose and there's more
  than one struct addrinfo in the getaddrinfo() result.
* formatbuf(): fix %m and %M to use the hostname, not the username.
* fetch_ftp(): preserve 'anonftp' across a disconnect() so that multiple ftp
  auto-fetches on the same command line login automatically.
* Improve bounds checking.
* Update various copyright notices.

Portability fixes:
* Look for dirname(3), which may be in -lgen on IRIX, and replace it if not
  found.
* Don't use non-standard: u_char, u_short, u_int, or uint.
* Use uint32_t instead of u_int32_t.
* Don't use register.
* Helps if the definition of xconnect() matches its declaration....
* Fix some cast issues highlighted by gcc 4 on OSX.4
* Use size_t instead of int where appropriate.
* Make this compile on sparc64 (size_t != int).
* Printf field widths and size_t don't always mix well, so cast to int.
  Fixes build problem for alpha.
* auto_fetch(): use an initialized volatile int to appease IRIX cc.
* Don't abuse unconstify'ing a string and writing to it, because you'll core
  dump. Also remove extra const that gives pain to the irix compiler.
* Make sure we flush after we prepare when we are unbuffered otherwise the
  prompt will not appear immediately.
* Terminate the arglist with a NULL instead of 0. (Shuts up gcc4.x)
* Use malloc(3) instead of alloca(3).
* Include "src/progressbar.h" for xsignal_restart() prototype.
* Ensure that fallback #define of __attribute__ is available.
  Fixes build problem on HP-UX with cc.
* Pull in <poll.h> or <sys/poll.h> if they exist even if we're not using poll,
  as struct pollfd might exist in those.  Fixes build problem on OSX.3.
* Use NS_INADDRSZ, NS_IN6ADDRSZ and NS_INT16SZ instead of
  equivalents without NS_ prefix.
* Use socklen_t instead of size_t where appropriate.
* Separate CPPFLAGS from CFLAGS.
* Use "long long" instead of "quad" in various comments & constants.
* Prefer poll over select when implementing replacement usleep().

diffstat:

 net/tnftp/files/libedit/filecomplete.c |  536 +++++++++++++++++++++++++++++++++
 net/tnftp/files/libedit/filecomplete.h |   52 +++
 net/tnftp/files/libedit/readline.c     |  528 +++-----------------------------
 net/tnftp/files/libnetbsd/dirname.c    |   84 +++++
 4 files changed, 728 insertions(+), 472 deletions(-)

diffs (truncated from 1374 to 300 lines):

diff -r 1ee602134ebd -r 0144cfbd792c net/tnftp/files/libedit/filecomplete.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/tnftp/files/libedit/filecomplete.c    Fri Jun 10 04:52:08 2005 +0000
@@ -0,0 +1,536 @@
+/*     NetBSD: filecomplete.c,v 1.2 2005/06/09 16:48:57 lukem Exp      */
+/*     from    NetBSD: filecomplete.c,v 1.5 2005/05/18 22:34:41 christos Exp   */
+
+/*-
+ * Copyright (c) 1997 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jaromir Dolecek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <string.h>
+#include <pwd.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#ifdef HAVE_VIS_H
+#include <vis.h>
+#else
+#include "np/vis.h"
+#endif
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#include "el.h"
+#include "fcns.h"              /* for EL_NUM_FCNS */
+#include "histedit.h"
+#include "filecomplete.h"
+
+static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
+    '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
+
+
+/********************************/
+/* completion functions */
+
+/*
+ * does tilde expansion of strings of type ``~user/foo''
+ * if ``user'' isn't valid user name or ``txt'' doesn't start
+ * w/ '~', returns pointer to strdup()ed copy of ``txt''
+ *
+ * it's callers's responsibility to free() returned string
+ */
+char *
+tilde_expand(char *txt)
+{
+       struct passwd pwres, *pass;
+       char *temp;
+       size_t len = 0;
+       char pwbuf[1024];
+
+       if (txt[0] != '~')
+               return (strdup(txt));
+
+       temp = strchr(txt + 1, '/');
+       if (temp == NULL) {
+               temp = strdup(txt + 1);
+               if (temp == NULL)
+                       return NULL;
+       } else {
+               len = temp - txt + 1;   /* text until string after slash */
+               temp = malloc(len);
+               if (temp == NULL)
+                       return NULL;
+               (void)strncpy(temp, txt + 1, len - 2);
+               temp[len - 2] = '\0';
+       }
+       if (temp[0] == 0) {
+               if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
+                       pass = NULL;
+       } else {
+               if (getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
+                       pass = NULL;
+       }
+       free(temp);             /* value no more needed */
+       if (pass == NULL)
+               return (strdup(txt));
+
+       /* update pointer txt to point at string immedially following */
+       /* first slash */
+       txt += len;
+
+       temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+       if (temp == NULL)
+               return NULL;
+       (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
+
+       return (temp);
+}
+
+
+/*
+ * return first found file name starting by the ``text'' or NULL if no
+ * such file can be found
+ * value of ``state'' is ignored
+ *
+ * it's caller's responsibility to free returned string
+ */
+char *
+filename_completion_function(const char *text, int state)
+{
+       static DIR *dir = NULL;
+       static char *filename = NULL, *dirname = NULL, *dirpath = NULL;
+       static size_t filename_len = 0;
+       struct dirent *entry;
+       char *temp;
+       size_t len;
+
+       if (state == 0 || dir == NULL) {
+               temp = strrchr(text, '/');
+               if (temp) {
+                       char *nptr;
+                       temp++;
+                       nptr = realloc(filename, strlen(temp) + 1);
+                       if (nptr == NULL) {
+                               free(filename);
+                               return NULL;
+                       }
+                       filename = nptr;
+                       (void)strcpy(filename, temp);
+                       len = temp - text;      /* including last slash */
+                       nptr = realloc(dirname, len + 1);
+                       if (nptr == NULL) {
+                               free(filename);
+                               return NULL;
+                       }
+                       dirname = nptr;
+                       (void)strncpy(dirname, text, len);
+                       dirname[len] = '\0';
+               } else {
+                       if (*text == 0)
+                               filename = NULL;
+                       else {
+                               filename = strdup(text);
+                               if (filename == NULL)
+                                       return NULL;
+                       }
+                       dirname = NULL;
+               }
+
+               if (dir != NULL) {
+                       (void)closedir(dir);
+                       dir = NULL;
+               }
+
+               /* support for ``~user'' syntax */
+               free(dirpath);
+
+               if (dirname == NULL && (dirname = strdup("./")) == NULL)
+                       return NULL;
+
+               if (*dirname == '~')
+                       dirpath = tilde_expand(dirname);
+               else
+                       dirpath = strdup(dirname);
+
+               if (dirpath == NULL)
+                       return NULL;
+
+               dir = opendir(dirpath);
+               if (!dir)
+                       return (NULL);  /* cannot open the directory */
+
+               /* will be used in cycle */
+               filename_len = filename ? strlen(filename) : 0;
+       }
+
+       /* find the match */
+       while ((entry = readdir(dir)) != NULL) {
+               /* skip . and .. */
+               if (entry->d_name[0] == '.' && (!entry->d_name[1]
+                   || (entry->d_name[1] == '.' && !entry->d_name[2])))
+                       continue;
+               if (filename_len == 0)
+                       break;
+               /* otherwise, get first entry where first */
+               /* filename_len characters are equal      */
+               if (entry->d_name[0] == filename[0]
+#if defined(__SVR4) || defined(__linux__)
+                   && strlen(entry->d_name) >= filename_len
+#else
+                   && entry->d_namlen >= filename_len
+#endif
+                   && strncmp(entry->d_name, filename,
+                       filename_len) == 0)
+                       break;
+       }
+
+       if (entry) {            /* match found */
+               struct stat stbuf;
+               const char *isdir = "";
+
+#if defined(__SVR4) || defined(__linux__)
+               len = strlen(entry->d_name);
+#else
+               len = entry->d_namlen;
+#endif
+               temp = malloc(strlen(dirpath) + len + 1);
+               if (temp == NULL)
+                       return NULL;
+               (void)sprintf(temp, "%s%s", dirpath, entry->d_name); /* safe */
+
+               /* test, if it's directory */
+               if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
+                       isdir = "/";
+               free(temp);
+               temp = malloc(strlen(dirname) + len + 1 + 1);
+               if (temp == NULL)
+                       return NULL;
+               (void)sprintf(temp, "%s%s%s", dirname, entry->d_name, isdir);
+       } else {
+               (void)closedir(dir);
+               dir = NULL;
+               temp = NULL;
+       }
+
+       return (temp);
+}
+
+
+
+/*
+ * returns list of completions for text given
+ * non-static for readline.
+ */
+char ** completion_matches(const char *, char *(*)(const char *, int));
+char **
+completion_matches(const char *text, char *(*genfunc)(const char *, int))
+{
+       char **match_list = NULL, *retstr, *prevstr;
+       size_t match_list_len, max_equal, which, i;
+       size_t matches;
+
+       matches = 0;
+       match_list_len = 1;
+       while ((retstr = (*genfunc) (text, (int)matches)) != NULL) {
+               /* allow for list terminator here */
+               if (matches + 3 >= match_list_len) {
+                       char **nmatch_list;
+                       while (matches + 3 >= match_list_len)
+                               match_list_len <<= 1;
+                       nmatch_list = realloc(match_list,
+                           match_list_len * sizeof(char *));
+                       if (nmatch_list == NULL) {
+                               free(match_list);
+                               return NULL;
+                       }
+                       match_list = nmatch_list;
+
+               }
+               match_list[++matches] = retstr;
+       }
+
+       if (!match_list)
+               return NULL;    /* nothing found */
+
+       /* find least denominator and insert it to match_list[0] */
+       which = 2;
+       prevstr = match_list[1];
+       max_equal = strlen(prevstr);
+       for (; which <= matches; which++) {



Home | Main Index | Thread Index | Old Index