]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ftp/Parsing.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 09 File Transfer Protocol (FTP) */
12 #include "ftp/Parsing.h"
13 #include "ip/Address.h"
15 #include "SquidConfig.h"
18 Ftp::ParseIpPort(const char *buf
, const char *forceIp
, Ip::Address
&addr
)
22 const int n
= sscanf(buf
, "%d,%d,%d,%d,%d,%d",
23 &h1
, &h2
, &h3
, &h4
, &p1
, &p2
);
25 if (n
!= 6 || p1
< 0 || p2
< 0 || p1
> 255 || p2
> 255)
29 addr
= forceIp
; // but the above code still validates the IP we got
31 static char ipBuf
[1024];
32 snprintf(ipBuf
, sizeof(ipBuf
), "%d.%d.%d.%d", h1
, h2
, h3
, h4
);
39 const int port
= ((p1
<< 8) + p2
);
44 if (Config
.Ftp
.sanitycheck
&& port
< 1024)
52 Ftp::ParseProtoIpPort(const char *buf
, Ip::Address
&addr
)
55 const char delim
= *buf
;
56 const char *s
= buf
+ 1;
58 const int proto
= strtol(s
, const_cast<char**>(&e
), 10);
59 if ((proto
!= 1 && proto
!= 2) || *e
!= delim
)
64 char ip
[MAX_IPSTRLEN
];
65 if (static_cast<size_t>(e
- s
) >= sizeof(ip
))
67 strncpy(ip
, s
, e
- s
);
74 if ((proto
== 2) != addr
.isIPv6()) // proto ID mismatches address version
77 s
= e
+ 1; // skip port delimiter
78 const int port
= strtol(s
, const_cast<char**>(&e
), 10);
79 if (port
< 0 || *e
!= '|')
82 if (Config
.Ftp
.sanitycheck
&& port
< 1024)
90 Ftp::UnescapeDoubleQuoted(const char *quotedPath
)
94 const char *s
= quotedPath
;
97 bool parseDone
= false;
99 if (const char *e
= strchr(s
, '"')) {
100 path
.append(s
, e
- s
);
107 } else { //parse error
113 return path
.content();