FTP: misc fixes resulting from my testing.

- "total ..." lines can have values bigger than 32-bit
- some servers use "l" as a flag in permission listing
- some servers prepend garbage to the month column
- NetWare directory listings can have spaces in file names
- one additional variant of VMS error message

BUG=none

Review URL: https://codereview.chromium.org/11418296

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170996 0039d316-1c4b-4281-b951-d872f2087c98
parent 2097a5e3
total 395136991232
drwx-wx-wx 10 ftpadmin ftpusers 256 May 27 2010 downloads
d
downloads
-1
2010
5
27
0
0
total 0
- [RWCEAFMS] bodi 1588 Oct 28 22:21 leltar.as
- [RWCEAFMS] bodi 19440 Oct 28 22:21 leltarVizellatas.as
- [RWCEAFMS] bodi 38795 Oct 28 22:21 leltarVizelvezetes.as
- [RWCEAFMS] bodi 227 Jan 06 2010 Olvass_el.txt
- [RWCEAFMS] dora 19300888 Jan 15 2011 vegleges.pdf
d [RWCEAFMS] Fulop 512 Nov 10 2011 DHI
d [RWCEAFMS] bodi 512 Aug 02 11:48 English
d [RWCEAFMS] clement 512 Jun 24 2011 Floodrisk
d [RWCEAFMS] bodi 512 Mar 10 14:53 HC_MIR_FD
d [RWCEAFMS] bodi 512 Oct 08 15:59 HCWP614-11
d [RWCEAFMS] knolmar 512 Mar 26 15:10 Mike
d [RWCEAFMS] daniel 512 May 17 2010 NVP anyagok
d [RWCEAFMS] bodi 512 Sep 15 2010 Oktatas
d [RWCEAFMS] buzas 512 Oct 09 12:47 processing_modflow
d [RWCEAFMS] peterbud 512 Mar 24 2010 Prospektushoz
d [RWCEAFMS] bodi 512 Sep 05 2011 sewcad
d [RWCEAFMS] bodi 512 May 09 08:50 szakmernok
d [RWCEAFMS] daniel 512 Aug 03 18:53 tomi
d [RWCEAFMS] bodi 512 Sep 20 21:10 Virtualis-GEP
d [RWCEAFMS] clement 512 Sep 26 12:31 Vizrajzi evkonyvek
d [RWCEAFMS] darabos 512 Jul 09 2011 VKKI-Tanulmanyok
-
leltar.as
1588
1994
10
28
22
21
-
leltarVizellatas.as
19440
1994
10
28
22
21
-
leltarVizelvezetes.as
38795
1994
10
28
22
21
-
Olvass_el.txt
227
2010
1
6
0
0
-
vegleges.pdf
19300888
2011
1
15
0
0
d
DHI
-1
2011
11
10
0
0
d
English
-1
1994
8
2
11
48
d
Floodrisk
-1
2011
6
24
0
0
d
HC_MIR_FD
-1
1994
3
10
14
53
d
HCWP614-11
-1
1994
10
8
15
59
d
Mike
-1
1994
3
26
15
10
d
NVP anyagok
-1
2010
5
17
0
0
d
Oktatas
-1
2010
9
15
0
0
d
processing_modflow
-1
1994
10
9
12
47
d
Prospektushoz
-1
2010
3
24
0
0
d
sewcad
-1
2011
9
5
0
0
d
szakmernok
-1
1994
5
9
8
50
d
tomi
-1
1994
8
3
18
53
d
Virtualis-GEP
-1
1994
9
20
21
10
d
Vizrajzi evkonyvek
-1
1994
9
26
12
31
d
VKKI-Tanulmanyok
-1
2011
7
9
0
0
......@@ -24,12 +24,13 @@ bool LooksLikeUnixPermission(const string16& text) {
// r - file is readable
// w - file is writable
// x - file is executable
// s or S - setuid/setgid bit set
// s, S or l - setuid/setgid bit set
// t or T - "sticky" bit set
return ((text[0] == 'r' || text[0] == '-') &&
(text[1] == 'w' || text[1] == '-') &&
(text[2] == 'x' || text[2] == 's' || text[2] == 'S' ||
text[2] == 't' || text[2] == 'T' || text[2] == '-'));
(text[2] == 'x' || text[2] == '-' ||
text[2] == 's' || text[2] == 'S' || text[2] == 'l' ||
text[2] == 't' || text[2] == 'T'));
}
bool LooksLikeUnixPermissionsListing(const string16& text) {
......@@ -180,8 +181,8 @@ bool ParseFtpDirectoryListingLs(
if (columns.size() == 2 && !received_total_line) {
received_total_line = true;
int total_number;
if (!base::StringToInt(columns[1], &total_number))
int64 total_number;
if (!base::StringToInt64(columns[1], &total_number))
return false;
if (total_number < 0)
return false;
......
......@@ -124,6 +124,18 @@ TEST_F(FtpDirectoryListingParserLsTest, Good) {
{ "-rwxrwxrwx 2 root root 4096 2012-02-07 00:31 notas_servico",
FtpDirectoryListingEntry::FILE, "notas_servico", 4096,
2012, 2, 7, 0, 31 },
// Weird permission bits.
{ "drwx--l--- 2 0 10 512 Dec 22 1994 swetzel",
FtpDirectoryListingEntry::DIRECTORY, "swetzel", -1,
1994, 12, 22, 0, 0 },
// Garbage in date (but still parseable).
{ "lrw-rw-rw- 1 user group 542 "
"/t11/member/incomingFeb 8 2007 "
"Shortcut to incoming.lnk -> /t11/member/incoming",
FtpDirectoryListingEntry::SYMLINK, "Shortcut to incoming.lnk", -1,
2007, 2, 8, 0, 0 },
};
for (size_t i = 0; i < arraysize(good_cases); i++) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
......
......@@ -49,7 +49,7 @@ bool ParseFtpDirectoryListingNetware(
std::vector<string16> columns;
base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns);
if (columns.size() != 8)
if (columns.size() < 8)
return false;
FtpDirectoryListingEntry entry;
......@@ -83,7 +83,7 @@ bool ParseFtpDirectoryListingNetware(
return false;
}
entry.name = columns[7];
entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 7);
entries->push_back(entry);
}
......
......@@ -24,6 +24,9 @@ TEST_F(FtpDirectoryListingParserNetwareTest, Good) {
{ "- [RW------] ftpadmin 123 Nov 11 18:25 afile",
FtpDirectoryListingEntry::FILE, "afile", 123,
1994, 11, 11, 18, 25 },
{ "d [RWCEAFMS] daniel 512 May 17 2010 NVP anyagok",
FtpDirectoryListingEntry::DIRECTORY, "NVP anyagok", -1,
2010, 5, 17, 0, 0 },
};
for (size_t i = 0; i < arraysize(good_cases); i++) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
......
......@@ -137,9 +137,11 @@ const char* kTestFiles[] = {
"dir-listing-ls-28", // Hylafax FTP server
"dir-listing-ls-29",
"dir-listing-ls-30",
"dir-listing-netware-1",
"dir-listing-netware-2",
"dir-listing-netware-3", // Spaces in file names.
"dir-listing-os2-1",
"dir-listing-vms-1",
"dir-listing-vms-2",
......
......@@ -124,6 +124,7 @@ bool LooksLikeVmsUserIdentificationCode(const string16& input) {
bool LooksLikePermissionDeniedError(const string16& text) {
static const char* kPermissionDeniedMessages[] = {
"%RMS-E-PRV",
"%SYSTEM-F-NOPRIV",
"privilege",
};
......
......@@ -203,8 +203,15 @@ bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day,
base::Time* result) {
base::Time::Exploded time_exploded = { 0 };
if (!AbbreviatedMonthToNumber(month, &time_exploded.month))
return false;
if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) {
// Work around garbage sent by some servers in the same column
// as the month. Take just last 3 characters of the string.
if (month.length() < 3 ||
!AbbreviatedMonthToNumber(month.substr(month.length() - 3),
&time_exploded.month)) {
return false;
}
}
if (!base::StringToInt(day, &time_exploded.day_of_month))
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment