Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
54e72463
Commit
54e72463
authored
23 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
cleaned up, now closes the listener port in PASV and it doesn't re-use the
same passive port number
parent
9b3b0506
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/ftpserver.pl
+29
-22
29 additions, 22 deletions
tests/ftpserver.pl
with
29 additions
and
22 deletions
tests/ftpserver.pl
+
29
−
22
View file @
54e72463
...
...
@@ -3,7 +3,7 @@
# $Id$
# This is the FTP server designed for the curl test suite.
#
# It is meant to ex
c
er
siv
e curl, it is not meant to be
come
a fully working
# It is meant to exer
cis
e curl, it is not meant to be a fully working
# or even very standard compliant server.
#
# You may optionally specify port on the command line, otherwise it'll
...
...
@@ -115,6 +115,14 @@ my %commandfunc = ( 'PORT' => \&PORT_command,
'
APPE
'
=>
\
&STOR_command
,
# append looks like upload
);
my
$rest
=
0
;
sub
REST_command
{
$rest
=
$_
[
0
];
}
sub
LIST_command
{
# print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n";
# this is a built-in fake-dir ;-)
my
@ftpdir
=
("
total 20
\r\n
",
"
drwxr-xr-x 8 98 98 512 Oct 22 13:06 .
\r\n
",
...
...
@@ -128,14 +136,6 @@ my @ftpdir=("total 20\r\n",
"
drwxrwxrwx 2 98 1 512 Oct 30 14:33 pub
\r\n
",
"
dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr
\r\n
");
my
$rest
=
0
;
sub
REST_command
{
$rest
=
$_
[
0
];
}
sub
LIST_command
{
# print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n";
logmsg
"
$$: pass data to child pid
\n
";
for
(
@ftpdir
)
{
print
SOCK
$_
;
...
...
@@ -257,17 +257,26 @@ sub STOR_command {
return
0
;
}
my
$pasvport
=
9000
;
sub
PASV_command
{
socket
(
Server2
,
PF_INET
,
SOCK_STREAM
,
$proto
)
||
die
"
socket: $!
";
setsockopt
(
Server2
,
SOL_SOCKET
,
SO_REUSEADDR
,
pack
("
l
",
1
))
||
die
"
setsockopt: $!
";
while
(
$port
<
11000
)
{
if
(
bind
(
Server2
,
sockaddr_in
(
$port
,
INADDR_ANY
)))
{
my
$ok
=
0
;
$pasvport
++
;
# don't reuse the previous
for
(
1
..
10
)
{
if
(
$pasvport
>
65535
)
{
$pasvport
=
1025
;
}
if
(
bind
(
Server2
,
sockaddr_in
(
$pasvport
,
INADDR_ANY
)))
{
$ok
=
1
;
last
;
}
$port
+
+
;
# try
next
port please
$
pasv
port
+
=
3
;
# try
another
port please
}
if
(
11000
==
$port
)
{
if
(
!
$ok
)
{
print
"
500 no free ports!
\r\n
";
logmsg
"
couldn't find free port
\n
";
return
0
;
...
...
@@ -275,18 +284,17 @@ sub PASV_command {
listen
(
Server2
,
SOMAXCONN
)
||
die
"
listen: $!
";
printf
("
227 Entering Passive Mode (127,0,0,1,%d,%d)
\n
",
(
$port
/
256
),
(
$port
%
256
));
my
$waitedpid
;
my
$paddr
;
(
$pasvport
/
256
),
(
$pasvport
%
256
));
$paddr
=
accept
(
SOCK
,
Server2
);
my
(
$port
,
$iaddr
)
=
sockaddr_in
(
$paddr
);
my
$paddr
=
accept
(
SOCK
,
Server2
);
my
(
$
i
port
,
$iaddr
)
=
sockaddr_in
(
$paddr
);
my
$name
=
gethostbyaddr
(
$iaddr
,
AF_INET
);
lo
gmsg
"
$$: data connection from
$name
[
",
inet_ntoa
(
$iaddr
),
"
] at port
$port
\n
";
c
lo
se
(
Server2
);
# close the listener when its served its purpose!
return
\
&SOCK
;
logmsg
"
$$: data connection from
$name
[
",
inet_ntoa
(
$iaddr
),
"
] at port
$iport
\n
";
return
;
}
sub
PORT_command
{
...
...
@@ -435,5 +443,4 @@ for ( $waitedpid = 0;
}
# while(1)
close
(
Client
);
close
(
Client2
);
close
(
Server2
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment