httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r581493 - in /httpd/mod_ftp/trunk: include/mod_ftp.h modules/ftp/ftp_util.c
Date Wed, 03 Oct 2007 04:43:50 GMT
Author: wrowe
Date: Tue Oct  2 21:43:49 2007
New Revision: 581493

URL: http://svn.apache.org/viewvc?rev=581493&view=rev
Log:
We require a new parser, apr_eprt_decode() to break apart |AF|IP|port|
sequences.  This isn't quite a generic parser, all three elts are 
manditory.  We do not try to validate IP yet for completeness, only
that it matches digits and the appropriate IP elt seperators.

Modified:
    httpd/mod_ftp/trunk/include/mod_ftp.h
    httpd/mod_ftp/trunk/modules/ftp/ftp_util.c

Modified: httpd/mod_ftp/trunk/include/mod_ftp.h
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/include/mod_ftp.h?rev=581493&r1=581492&r2=581493&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/include/mod_ftp.h (original)
+++ httpd/mod_ftp/trunk/include/mod_ftp.h Tue Oct  2 21:43:49 2007
@@ -401,6 +401,8 @@
  *
  * ftp_util.c
  */
+int ftp_eprt_decode(apr_int32_t *family, char **addr, apr_port_t *port,
+                    char *arg);
 struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern);
 
 void ftp_set_authorization(request_rec *r);

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_util.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_util.c?rev=581493&r1=581492&r2=581493&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_util.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_util.c Tue Oct  2 21:43:49 2007
@@ -29,6 +29,69 @@
 #include <sys/stat.h> /* For file perms */
 
 
+/* Warning; the *arg is consumed, manipulated and must have the same lifetime
+ * as the desired *addr results!
+ */
+int ftp_eprt_decode(apr_int32_t *family, char **addr, apr_port_t *port,
+                    char *arg)
+{
+    char *argv, delim = *arg, sep = '\0';
+
+    if (delim <= ' ' || delim > 126)
+        return FTP_REPLY_SYNTAX_ERROR;
+
+    ++arg;
+    argv = arg;
+    while (isdigit(*arg)) ++arg;
+    if (*arg != delim)
+        return FTP_REPLY_SYNTAX_ERROR;
+    *(arg++) = '\0';
+    if (*argv) {
+        if (strcmp(argv, "1") == 0)
+            *family = APR_INET;
+#if APR_HAVE_IPV6
+        else if (strcmp(argv, "2") == 0)
+            *family = APR_INET6;
+#endif
+        else if (isdigit(argv[0]))
+            return FTP_REPLY_BAD_PROTOCOL;
+        else
+            return FTP_REPLY_SYNTAX_ERROR;
+    }
+
+    if (*family == APR_INET)
+        sep = '.';
+#if APR_HAVE_IPV6
+    else if (*family == APR_INET6)
+        sep = ':';
+#endif
+    else
+        return FTP_REPLY_BAD_PROTOCOL;
+    
+    argv = arg;
+    if (*arg == delim)
+        return FTP_REPLY_SYNTAX_ERROR;
+    while (isdigit(*arg) || (*arg == sep)) ++arg;
+    if (*arg != delim)
+        return FTP_REPLY_SYNTAX_ERROR;
+    *(arg++) = '\0';
+    *addr = argv;
+
+    argv = arg;
+    if (*arg == delim)
+        return FTP_REPLY_SYNTAX_ERROR;
+    while (isdigit(*arg)) ++arg;
+    if (*arg != delim)
+        return FTP_REPLY_SYNTAX_ERROR;
+    *(arg++) = '\0';
+    if (*argv)
+        *port = atoi(argv);
+
+    if (*arg)
+        return FTP_REPLY_SYNTAX_ERROR;
+    return FTP_REPLY_COMMAND_OK;
+}
+
 static char *ftp_modestring_get(char *mode, apr_filetype_e typ, 
                                       apr_fileperms_t perms)
 {



Mime
View raw message