Source-Changes-HG archive

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

[src/trunk]: src/distrib/utils/sysinst * when encoding an FTP url, if the pat...



details:   https://anonhg.NetBSD.org/src/rev/c30a4ed9f5d5
branches:  trunk
changeset: 473774:c30a4ed9f5d5
user:      cgd <cgd%NetBSD.org@localhost>
date:      Fri Jun 18 23:26:40 1999 +0000

description:
* when encoding an FTP url, if the path starts with a / put a %2F at the
  start of the URL so that the request will start from / (rather than
  relative to the login directory; makes things work better for
  non-anonymous FTP).  To make it clearer what's going on, make the
  default path (used to get distribution bits) relative.  (according
  to the 1.4 LAST_MINUTE file, this is OK.)
* Also, %-encode passwords in FTP URLs (doesn't help actual security, but
  makes it slightly harder to figure out a password by reading over
  somebody's shoulder).

diffstat:

 distrib/utils/sysinst/defs.h |   4 +-
 distrib/utils/sysinst/net.c  |  45 +++++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 17 deletions(-)

diffs (121 lines):

diff -r b759df5a79f9 -r c30a4ed9f5d5 distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Fri Jun 18 23:14:01 1999 +0000
+++ b/distrib/utils/sysinst/defs.h      Fri Jun 18 23:26:40 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.40 1999/04/13 20:17:47 bouyer Exp $ */
+/*     $NetBSD: defs.h,v 1.41 1999/06/18 23:26:40 cgd Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -173,7 +173,7 @@
 
 EXTERN char ext_dir[STRSIZE] INIT("");
 EXTERN char ftp_host[STRSIZE] INIT("ftp.netbsd.org");
-EXTERN char ftp_dir[STRSIZE]  INIT("/pub/NetBSD/NetBSD-");
+EXTERN char ftp_dir[STRSIZE]  INIT("pub/NetBSD/NetBSD-");
 EXTERN char ftp_prefix[STRSIZE] INIT("/binary/sets");
 EXTERN char ftp_user[STRSIZE] INIT("ftp");
 EXTERN char ftp_pass[STRSIZE] INIT("");
diff -r b759df5a79f9 -r c30a4ed9f5d5 distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c       Fri Jun 18 23:14:01 1999 +0000
+++ b/distrib/utils/sysinst/net.c       Fri Jun 18 23:26:40 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.44 1999/04/13 20:17:48 bouyer Exp $  */
+/*     $NetBSD: net.c,v 1.45 1999/06/18 23:26:40 cgd Exp $     */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -56,7 +56,8 @@
 /* URL encode unsafe characters.  */
 
 static char *url_encode __P((char *dst, const char *src, size_t len,
-                               const char *safe_chars));
+                               const char *safe_chars,
+                               int encode_leading_slash));
 
 /* Get the list of network interfaces. */
 
@@ -74,12 +75,13 @@
  * len is the length of the destination buffer.  The result will be
  * truncated if necessary to fit in the destination buffer.
  *
- * safe_chars is a string of characters that should not be encoded.  Any
- * characters in this string, as well as any alphanumeric characters,
- * will be copied from src to dst without encoding.  Some potentially
- * useful settings for this parameter are:
+ * safe_chars is a string of characters that should not be encoded.  If
+ * safe_chars is non-NULL, any characters in safe_chars as well as any
+ * alphanumeric characters will be copied from src to dst without
+ * encoding.  Some potentially useful settings for this parameter are:
  *
- *     NULL or ""      Everything except alphanumerics are encoded
+ *     NULL            Everything is encoded (even alphanumerics)
+ *     ""              Everything except alphanumerics are encoded
  *     "/"             Alphanumerics and '/' remain unencoded
  *     "$-_.+!*'(),"   Consistent with a strict reading of RFC 1738
  *     "$-_.+!*'(),/"  As above, except '/' is not encoded
@@ -109,17 +111,29 @@
 
 static char *
 url_encode(char *dst, const char *src, size_t len,
-       const char *safe_chars)
+       const char *safe_chars, int encode_leading_slash)
 {
        char *p = dst;
+       const char *initialsrc = src;
 
-       if (safe_chars == NULL)
-               safe_chars = "";
        /* Remove any initial '/'s if present */
        while (*src == '/')
                src++;
+
+       /*
+        * If encoding of a leading slash was desired, and there was in
+        * fact one or more leading shashes, encode one in the output string.
+        */
+       if (encode_leading_slash && (src != initialsrc)) {
+               if (len < 3)
+                       goto done;
+               sprintf(p, "%%%02X", '/');
+               p += 3;
+       }
+
        while (--len > 0 && *src != '\0') {
-               if (isalnum(*src) || strchr(safe_chars, *src)) {
+               if (safe_chars != NULL &&
+                   (isalnum(*src) || strchr(safe_chars, *src))) {
                        *p++ = *src++;
                } else {
                        /* encode this char */
@@ -130,6 +144,7 @@
                        len -= 2;
                }
        }
+done:
        *p = '\0';
        return dst;
 }
@@ -429,18 +444,18 @@
                            "/usr/bin/ftp -a ftp://%s/%s/%s";,
                            ftp_host,
                            url_encode(ftp_dir_encoded, ftp_dir, STRSIZE,
-                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH),
+                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
                            filename);
                else {
                        ret = run_prog(0, 1, NULL, 
                            "/usr/bin/ftp ftp://%s:%s@%s/%s/%s";,
                            url_encode(ftp_user_encoded, ftp_user, STRSIZE,
-                                       RFC1738_SAFE_LESS_SHELL),
+                                       RFC1738_SAFE_LESS_SHELL, 0),
                            url_encode(ftp_pass_encoded, ftp_pass, STRSIZE,
-                                       RFC1738_SAFE_LESS_SHELL),
+                                       NULL, 0),
                            ftp_host,
                            url_encode(ftp_dir_encoded, ftp_dir, STRSIZE,
-                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH),
+                                       RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
                            filename);
                }
                if (ret) {



Home | Main Index | Thread Index | Old Index