summaryrefslogtreecommitdiff
path: root/net/tnftp/files/libnetbsd
diff options
context:
space:
mode:
authorlukem <lukem@pkgsrc.org>2005-06-10 04:52:08 +0000
committerlukem <lukem@pkgsrc.org>2005-06-10 04:52:08 +0000
commitf6e9257fb31d458ec367d02c2ac0ce60e4f6b9a1 (patch)
treeb4d3e6d4bbf45f16b73092da942338af18b4ec7c /net/tnftp/files/libnetbsd
parent5626c2a62fafee00bb0f0b16e2b91d7052211e8a (diff)
downloadpkgsrc-f6e9257fb31d458ec367d02c2ac0ce60e4f6b9a1.tar.gz
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 (limited to 'net/tnftp/files/libnetbsd')
-rw-r--r--net/tnftp/files/libnetbsd/dirname.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/net/tnftp/files/libnetbsd/dirname.c b/net/tnftp/files/libnetbsd/dirname.c
new file mode 100644
index 00000000000..a751c0e036a
--- /dev/null
+++ b/net/tnftp/files/libnetbsd/dirname.c
@@ -0,0 +1,84 @@
+/* NetBSD: dirname.c,v 1.1 2005/06/01 15:07:55 lukem Exp */
+/* from NetBSD: dirname.c,v 1.7 2002/10/17 11:36:39 tron Exp */
+
+/*-
+ * Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Klaus Klein and Jason R. Thorpe.
+ *
+ * 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 "tnftp.h"
+
+char *
+dirname(path)
+ char *path;
+{
+ static char singledot[] = ".";
+ static char result[PATH_MAX];
+ char *lastp;
+ size_t len;
+
+ /*
+ * If `path' is a null pointer or points to an empty string,
+ * return a pointer to the string ".".
+ */
+ if ((path == NULL) || (*path == '\0'))
+ return (singledot);
+
+ /* Strip trailing slashes, if any. */
+ lastp = path + strlen(path) - 1;
+ while (lastp != path && *lastp == '/')
+ lastp--;
+
+ /* Terminate path at the last occurence of '/'. */
+ do {
+ if (*lastp == '/') {
+ /* Strip trailing slashes, if any. */
+ while (lastp != path && *lastp == '/')
+ lastp--;
+
+ /* ...and copy the result into the result buffer. */
+ len = (lastp - path) + 1 /* last char */;
+ if (len > (PATH_MAX - 1))
+ len = PATH_MAX - 1;
+
+ memcpy(result, path, len);
+ result[len] = '\0';
+
+ return (result);
+ }
+ } while (--lastp >= path);
+
+ /* No /'s found, return a pointer to the string ".". */
+ return (singledot);
+}