public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] fix container_ftp.pl
@ 2012-08-02 16:34 Simon Xu
  2012-08-08  8:30 ` DAN LI
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Xu @ 2012-08-02 16:34 UTC (permalink / raw)
  To: ltp-list; +Cc: OEL-QA_WW

container_ftp.pl has several problems:

* ftp users can't cd to a temporary dir in /tmp
* ftp->cwd($dir) will always fail
* if we do 'chdir $dir', 'rmdir("$dir")' will fail
* 'ftp->put' should be 'ftp->get'

Signed-off-by: Simon Xu <xu.simon@oracle.com>
---
 testcases/kernel/containers/netns/container_ftp.pl | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/containers/netns/container_ftp.pl b/testcases/kernel/containers/netns/container_ftp.pl
index 89a35b5..98742f3 100644
--- a/testcases/kernel/containers/netns/container_ftp.pl
+++ b/testcases/kernel/containers/netns/container_ftp.pl
@@ -23,6 +23,7 @@
 
 use File::Temp 'tempdir';
 use Net::FTP;
+use File::Path;
 
 if ($#ARGV == -1) {
 	print "usage: $0 host\n";
@@ -35,7 +36,7 @@ my $i = 0;
 my $kount = 51;
 my $file="junkfile";
 
-my $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/tmp";
+my $tmpdir = "/var/ftp";
 
 my $dir;
 $dir = tempdir("container_ftp.XXXXXXX", DIR => $tmpdir);
@@ -47,8 +48,7 @@ if (chmod(0777, $dir) == 0) {
 	push @ERRORS, "Failed to change mode for temporary directory: $!\n";
 	printerr();
 }
-chdir $dir;
-system("dd if=/dev/zero of=$file bs=512 count=10 > /dev/null 2>&1 ");
+system("dd if=/dev/zero of=$dir/$file bs=512 count=10 > /dev/null 2>&1 ");
 
 while ( $i < $kount )
 {
@@ -61,13 +61,15 @@ while ( $i < $kount )
         $ftp->quit if $newerr;
         printerr() if $newerr; 
 
-        $ftp->cwd($dir) or $newerr=1; 
+        $basedir = `basename "$dir"`;
+        chomp $basedir;
+        $ftp->cwd($basedir) or $newerr=1; 
         push @ERRORS, "Can't cd  $!\n" if $newerr;
         $ftp->quit if $newerr;
         printerr() if $newerr; 
 
         $newname = $file . "_" . $i ;
-        $ftp->put($file,$newname) or $newerr=1;
+        $ftp->get($file,$newname) or $newerr=1;
         push @ERRORS, "Can't get file $file $!\n" if $newerr;
         printerr() if $newerr;
 
@@ -82,6 +84,5 @@ sub printerr {
 }
 
 END {
-	unlink("$dir/$file");
-	rmdir("$dir");
+	rmtree("$dir");
 }
-- 
1.7.11.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/1] fix container_ftp.pl
  2012-08-02 16:34 [LTP] [PATCH 1/1] fix container_ftp.pl Simon Xu
@ 2012-08-08  8:30 ` DAN LI
  2012-08-08  8:52   ` Simon Xu
  0 siblings, 1 reply; 5+ messages in thread
From: DAN LI @ 2012-08-08  8:30 UTC (permalink / raw)
  To: Simon Xu; +Cc: ltp-list, OEL-QA_WW

On 08/03/2012 12:34 AM, Simon Xu wrote:
> container_ftp.pl has several problems:
>
> * ftp users can't cd to a temporary dir in /tmp
> * ftp->cwd($dir) will always fail
> * if we do 'chdir $dir', 'rmdir("$dir")' will fail
> * 'ftp->put' should be 'ftp->get'
>
> Signed-off-by: Simon Xu <xu.simon@oracle.com>
> ---
>   testcases/kernel/containers/netns/container_ftp.pl | 15 ++++++++-------
>   1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/containers/netns/container_ftp.pl b/testcases/kernel/containers/netns/container_ftp.pl
> index 89a35b5..98742f3 100644
> --- a/testcases/kernel/containers/netns/container_ftp.pl
> +++ b/testcases/kernel/containers/netns/container_ftp.pl
> @@ -23,6 +23,7 @@
>   
>   use File::Temp 'tempdir';
>   use Net::FTP;
> +use File::Path;
>   
>   if ($#ARGV == -1) {
>   	print "usage: $0 host\n";
> @@ -35,7 +36,7 @@ my $i = 0;
>   my $kount = 51;
>   my $file="junkfile";
>   
> -my $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/tmp";
> +my $tmpdir = "/var/ftp";
hi, Simon

I tested container_ftp.pl as follow:
********************************************************
#./container_ftp.pl    knownhost_with_vsftpd
********************************************************
and failed at "$ftp->cwd" either with this fix or without it.

So,did i get the wrong way to test this script ,or,something wrong
still exists.
>   
>   my $dir;
>   $dir = tempdir("container_ftp.XXXXXXX", DIR => $tmpdir);
> @@ -47,8 +48,7 @@ if (chmod(0777, $dir) == 0) {
>   	push @ERRORS, "Failed to change mode for temporary directory: $!\n";
>   	printerr();
>   }
> -chdir $dir;
> -system("dd if=/dev/zero of=$file bs=512 count=10 > /dev/null 2>&1 ");
> +system("dd if=/dev/zero of=$dir/$file bs=512 count=10 > /dev/null 2>&1 ");
>   
>   while ( $i < $kount )
>   {
> @@ -61,13 +61,15 @@ while ( $i < $kount )
>           $ftp->quit if $newerr;
>           printerr() if $newerr;
>   
> -        $ftp->cwd($dir) or $newerr=1;
> +        $basedir = `basename "$dir"`;
> +        chomp $basedir;
> +        $ftp->cwd($basedir) or $newerr=1;
>           push @ERRORS, "Can't cd  $!\n" if $newerr;
>           $ftp->quit if $newerr;
>           printerr() if $newerr;
>   
>           $newname = $file . "_" . $i ;
> -        $ftp->put($file,$newname) or $newerr=1;
> +        $ftp->get($file,$newname) or $newerr=1;
>           push @ERRORS, "Can't get file $file $!\n" if $newerr;
>           printerr() if $newerr;
>   
> @@ -82,6 +84,5 @@ sub printerr {
>   }
>   
>   END {
> -	unlink("$dir/$file");
> -	rmdir("$dir");
> +	rmtree("$dir");
>   }



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/1] fix container_ftp.pl
  2012-08-08  8:30 ` DAN LI
@ 2012-08-08  8:52   ` Simon Xu
  2012-08-08  9:55     ` DAN LI
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Xu @ 2012-08-08  8:52 UTC (permalink / raw)
  To: DAN LI; +Cc: ltp-list

On 2012/8/8 16:30, DAN LI wrote:
> On 08/03/2012 12:34 AM, Simon Xu wrote:
>> container_ftp.pl has several problems:
>>
>> * ftp users can't cd to a temporary dir in /tmp
>> * ftp->cwd($dir) will always fail
>> * if we do 'chdir $dir', 'rmdir("$dir")' will fail
>> * 'ftp->put' should be 'ftp->get'
>>
>> Signed-off-by: Simon Xu <xu.simon@oracle.com>
>> ---
>>   testcases/kernel/containers/netns/container_ftp.pl | 15 
>> ++++++++-------
>>   1 file changed, 8 insertions(+), 7 deletions(-)
>>
>> diff --git a/testcases/kernel/containers/netns/container_ftp.pl 
>> b/testcases/kernel/containers/netns/container_ftp.pl
>> index 89a35b5..98742f3 100644
>> --- a/testcases/kernel/containers/netns/container_ftp.pl
>> +++ b/testcases/kernel/containers/netns/container_ftp.pl
>> @@ -23,6 +23,7 @@
>>     use File::Temp 'tempdir';
>>   use Net::FTP;
>> +use File::Path;
>>     if ($#ARGV == -1) {
>>       print "usage: $0 host\n";
>> @@ -35,7 +36,7 @@ my $i = 0;
>>   my $kount = 51;
>>   my $file="junkfile";
>>   -my $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/tmp";
>> +my $tmpdir = "/var/ftp";
> hi, Simon
>
> I tested container_ftp.pl as follow:
> ********************************************************
> #./container_ftp.pl    knownhost_with_vsftpd
> ********************************************************
> and failed at "$ftp->cwd" either with this fix or without it.
>
> So,did i get the wrong way to test this script ,or,something wrong
> still exists.

Could you print the value of $dir before "$ftp->cwd"?  And try ftp login 
as anonymous user, and see if you can cd to the value.

Thanks
Simon

>>     my $dir;
>>   $dir = tempdir("container_ftp.XXXXXXX", DIR => $tmpdir);
>> @@ -47,8 +48,7 @@ if (chmod(0777, $dir) == 0) {
>>       push @ERRORS, "Failed to change mode for temporary directory: 
>> $!\n";
>>       printerr();
>>   }
>> -chdir $dir;
>> -system("dd if=/dev/zero of=$file bs=512 count=10 > /dev/null 2>&1 ");
>> +system("dd if=/dev/zero of=$dir/$file bs=512 count=10 > /dev/null 
>> 2>&1 ");
>>     while ( $i < $kount )
>>   {
>> @@ -61,13 +61,15 @@ while ( $i < $kount )
>>           $ftp->quit if $newerr;
>>           printerr() if $newerr;
>>   -        $ftp->cwd($dir) or $newerr=1;
>> +        $basedir = `basename "$dir"`;
>> +        chomp $basedir;
>> +        $ftp->cwd($basedir) or $newerr=1;
>>           push @ERRORS, "Can't cd  $!\n" if $newerr;
>>           $ftp->quit if $newerr;
>>           printerr() if $newerr;
>>             $newname = $file . "_" . $i ;
>> -        $ftp->put($file,$newname) or $newerr=1;
>> +        $ftp->get($file,$newname) or $newerr=1;
>>           push @ERRORS, "Can't get file $file $!\n" if $newerr;
>>           printerr() if $newerr;
>>   @@ -82,6 +84,5 @@ sub printerr {
>>   }
>>     END {
>> -    unlink("$dir/$file");
>> -    rmdir("$dir");
>> +    rmtree("$dir");
>>   }
>
>


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/1] fix container_ftp.pl
  2012-08-08  8:52   ` Simon Xu
@ 2012-08-08  9:55     ` DAN LI
  2012-08-08 10:07       ` Wanlong Gao
  0 siblings, 1 reply; 5+ messages in thread
From: DAN LI @ 2012-08-08  9:55 UTC (permalink / raw)
  To: Simon Xu; +Cc: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 3246 bytes --]

On 08/08/2012 04:52 PM, Simon Xu wrote:
> On 2012/8/8 16:30, DAN LI wrote:
>> On 08/03/2012 12:34 AM, Simon Xu wrote:
>>> container_ftp.pl has several problems:
>>>
>>> * ftp users can't cd to a temporary dir in /tmp
>>> * ftp->cwd($dir) will always fail
>>> * if we do 'chdir $dir', 'rmdir("$dir")' will fail
>>> * 'ftp->put' should be 'ftp->get'
>>>
>>> Signed-off-by: Simon Xu <xu.simon@oracle.com>
>>> ---
>>>   testcases/kernel/containers/netns/container_ftp.pl | 15 
>>> ++++++++-------
>>>   1 file changed, 8 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/testcases/kernel/containers/netns/container_ftp.pl 
>>> b/testcases/kernel/containers/netns/container_ftp.pl
>>> index 89a35b5..98742f3 100644
>>> --- a/testcases/kernel/containers/netns/container_ftp.pl
>>> +++ b/testcases/kernel/containers/netns/container_ftp.pl
>>> @@ -23,6 +23,7 @@
>>>     use File::Temp 'tempdir';
>>>   use Net::FTP;
>>> +use File::Path;
>>>     if ($#ARGV == -1) {
>>>       print "usage: $0 host\n";
>>> @@ -35,7 +36,7 @@ my $i = 0;
>>>   my $kount = 51;
>>>   my $file="junkfile";
>>>   -my $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/tmp";
>>> +my $tmpdir = "/var/ftp";
>> hi, Simon
>>
>> I tested container_ftp.pl as follow:
>> ********************************************************
>> #./container_ftp.pl    knownhost_with_vsftpd
>> ********************************************************
>> and failed at "$ftp->cwd" either with this fix or without it.
>>
>> So,did i get the wrong way to test this script ,or,something wrong
>> still exists.
>
> Could you print the value of $dir before "$ftp->cwd"?  And try ftp 
> login as anonymous user, and see if you can cd to the value.
>
Thanks for your quick reply and sorry for my careless.
I try operations as you suggested,and find the problem that dir created 
for test is not available
for any user expect root.

So, now i test and confirm this fix works fine.

Thanks
DAN LI
> Thanks
> Simon
>
>>>     my $dir;
>>>   $dir = tempdir("container_ftp.XXXXXXX", DIR => $tmpdir);
>>> @@ -47,8 +48,7 @@ if (chmod(0777, $dir) == 0) {
>>>       push @ERRORS, "Failed to change mode for temporary directory: 
>>> $!\n";
>>>       printerr();
>>>   }
>>> -chdir $dir;
>>> -system("dd if=/dev/zero of=$file bs=512 count=10 > /dev/null 2>&1 ");
>>> +system("dd if=/dev/zero of=$dir/$file bs=512 count=10 > /dev/null 
>>> 2>&1 ");
>>>     while ( $i < $kount )
>>>   {
>>> @@ -61,13 +61,15 @@ while ( $i < $kount )
>>>           $ftp->quit if $newerr;
>>>           printerr() if $newerr;
>>>   -        $ftp->cwd($dir) or $newerr=1;
>>> +        $basedir = `basename "$dir"`;
>>> +        chomp $basedir;
>>> +        $ftp->cwd($basedir) or $newerr=1;
>>>           push @ERRORS, "Can't cd  $!\n" if $newerr;
>>>           $ftp->quit if $newerr;
>>>           printerr() if $newerr;
>>>             $newname = $file . "_" . $i ;
>>> -        $ftp->put($file,$newname) or $newerr=1;
>>> +        $ftp->get($file,$newname) or $newerr=1;
>>>           push @ERRORS, "Can't get file $file $!\n" if $newerr;
>>>           printerr() if $newerr;
>>>   @@ -82,6 +84,5 @@ sub printerr {
>>>   }
>>>     END {
>>> -    unlink("$dir/$file");
>>> -    rmdir("$dir");
>>> +    rmtree("$dir");
>>>   }
>>
>>
>
>



[-- Attachment #1.2: Type: text/html, Size: 7048 bytes --]

[-- Attachment #2: Type: text/plain, Size: 395 bytes --]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/1] fix container_ftp.pl
  2012-08-08  9:55     ` DAN LI
@ 2012-08-08 10:07       ` Wanlong Gao
  0 siblings, 0 replies; 5+ messages in thread
From: Wanlong Gao @ 2012-08-08 10:07 UTC (permalink / raw)
  To: DAN LI; +Cc: ltp-list

On 08/08/2012 05:55 PM, DAN LI wrote:
> On 08/08/2012 04:52 PM, Simon Xu wrote:
>> On 2012/8/8 16:30, DAN LI wrote:
>>> On 08/03/2012 12:34 AM, Simon Xu wrote:
>>>> container_ftp.pl has several problems:
>>>>
>>>> * ftp users can't cd to a temporary dir in /tmp
>>>> * ftp->cwd($dir) will always fail
>>>> * if we do 'chdir $dir', 'rmdir("$dir")' will fail
>>>> * 'ftp->put' should be 'ftp->get'
>>>>
>>>> Signed-off-by: Simon Xu <xu.simon@oracle.com>
>>>> ---
>>>>   testcases/kernel/containers/netns/container_ftp.pl | 15 ++++++++-------
>>>>   1 file changed, 8 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/testcases/kernel/containers/netns/container_ftp.pl b/testcases/kernel/containers/netns/container_ftp.pl
>>>> index 89a35b5..98742f3 100644
>>>> --- a/testcases/kernel/containers/netns/container_ftp.pl
>>>> +++ b/testcases/kernel/containers/netns/container_ftp.pl
>>>> @@ -23,6 +23,7 @@
>>>>     use File::Temp 'tempdir';
>>>>   use Net::FTP;
>>>> +use File::Path;
>>>>     if ($#ARGV == -1) {
>>>>       print "usage: $0 host\n";
>>>> @@ -35,7 +36,7 @@ my $i = 0;
>>>>   my $kount = 51;
>>>>   my $file="junkfile";
>>>>   -my $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/tmp";
>>>> +my $tmpdir = "/var/ftp";
>>> hi, Simon
>>>
>>> I tested container_ftp.pl as follow:
>>> ********************************************************
>>> #./container_ftp.pl    knownhost_with_vsftpd
>>> ********************************************************
>>> and failed at "$ftp->cwd" either with this fix or without it.
>>>
>>> So,did i get the wrong way to test this script ,or,something wrong
>>> still exists.
>>
>> Could you print the value of $dir before "$ftp->cwd"?  And try ftp login as anonymous user, and see if you can cd to the value.
>>
> Thanks for your quick reply and sorry for my careless.
> I try operations as you suggested,and find the problem that dir created for test is not available
> for any user expect root.
> 
> So, now i test and confirm this fix works fine.

OK, pushed with your Reviewed-by and removed the tailing spaces. Thank you all.

Wanlong Gao

> 
> Thanks
> DAN LI
>> Thanks
>> Simon


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-08 10:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-02 16:34 [LTP] [PATCH 1/1] fix container_ftp.pl Simon Xu
2012-08-08  8:30 ` DAN LI
2012-08-08  8:52   ` Simon Xu
2012-08-08  9:55     ` DAN LI
2012-08-08 10:07       ` Wanlong Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox