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
05ec503e
Commit
05ec503e
authored
24 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
QUIT works, and now I can run a unix ftp client against the server and it
runs pretty good
parent
4b8fd86f
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
+28
-13
28 additions, 13 deletions
tests/ftpserver.pl
with
28 additions
and
13 deletions
tests/ftpserver.pl
+
28
−
13
View file @
05ec503e
#!/usr/bin/perl
#
# $Id$
# This is the FTP server designed for the curl test suite.
#
# It is meant to excersive curl, it is not meant to become a fully working
# or even very standard compliant server.
#
# You may optionally specify port on the command line, otherwise it'll
# default to port 8921.
#
use
Socket
;
use
Carp
;
use
FileHandle
;
...
...
@@ -12,6 +23,8 @@ open(FTPLOG, ">log/ftpd.log") ||
sub
logmsg
{
print
FTPLOG
@_
;
}
sub
ftpmsg
{
print
INPUT
@_
;
}
my
$verbose
=
0
;
# set to 1 for debugging
my
$port
=
8921
;
# just a default
...
...
@@ -46,7 +59,7 @@ my $paddr;
sub
REAPER
{
$waitedpid
=
wait
;
$SIG
{
CHLD
}
=
\
&REAPER
;
# loathe sysV
#
logmsg "reaped $waitedpid" . ($? ? " with exit $?" :
''
);
logmsg
"
reaped
$waitedpid
"
.
(
$?
?
"
with exit $?
\n
"
:
"
\n
"
);
}
# USER is ok in fresh state
...
...
@@ -58,6 +71,7 @@ my %commandok = ( "USER" => "fresh",
"
LIST
"
=>
"
twosock
",
"
RETR
"
=>
"
twosock
",
"
CWD
"
=>
"
loggedin
",
"
QUIT
"
=>
"
loggedin|twosock
",
);
# initially, we're in 'fresh' state
...
...
@@ -74,7 +88,7 @@ my %displaytext = ('USER' => '331 We are happy you popped in!', # output FTP lin
'
TYPE
'
=>
'
200 I modify TYPE as you wanted
',
'
LIST
'
=>
'
150 here comes a directory
',
'
CWD
'
=>
'
250 CWD command successful.
',
'
QUIT
'
=>
'
221 bye bye baby
',
);
# callback functions for certain commands
...
...
@@ -182,6 +196,10 @@ sub PASV_command {
}
$port
++
;
# try next port please
}
if
(
11000
==
$port
)
{
print
"
500 no free ports!
\r\n
";
exit
;
}
listen
(
Server2
,
SOMAXCONN
)
||
die
"
listen: $!
";
printf
("
227 Entering Passive Mode (127,0,0,1,%d,%d)
\n
",
...
...
@@ -194,7 +212,7 @@ sub PASV_command {
my
(
$port
,
$iaddr
)
=
sockaddr_in
(
$paddr
);
my
$name
=
gethostbyaddr
(
$iaddr
,
AF_INET
);
logmsg
"
connection from
$name
[
",
inet_ntoa
(
$iaddr
),
"
] at port
$port
\n
";
logmsg
"
data
connection from
$name
[
",
inet_ntoa
(
$iaddr
),
"
] at port
$port
\n
";
open
(
STDOUT
,
"
>&Client2
")
||
die
"
can't dup client to stdout
";
...
...
@@ -232,8 +250,8 @@ sub PORT_command {
if
(
$arg
!~
/(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/
)
{
logmsg
"
bad PORT-line:
$arg
\n
";
print
"
314
silly you, go away
\r\n
";
return
1
;
print
"
500
silly you, go away
\r\n
";
exit
;
}
my
$iaddr
=
inet_aton
("
$1.$2.$3.$4
");
my
$paddr
=
sockaddr_in
((
$
5
<<
8
)
+
$
6
,
$iaddr
);
...
...
@@ -307,26 +325,25 @@ for ( $waitedpid = 0;
last
unless
defined
(
$_
=
<
STDIN
>
);
ftpmsg
$_
;
# Remove trailing CRLF.
s/[\n\r]+$//
;
unless
(
m/^([A-Z]{3,4})\s?(.*)/i
)
{
print
STDERR
"
badly formed command received:
"
.
$_
;
exit
0
;
print
"
500 '
$_
': command not understood.
\r\n
";
next
;
}
my
$FTPCMD
=
$
1
;
my
$FTPARG
=
$
2
;
my
$full
=
$_
;
logmsg
"
GOT: ($1)
$_
\n
";
print
INPUT
"
$$:
$full
\n
";
my
$ok
=
$commandok
{
$FTPCMD
};
if
(
$ok
!~
/$state/
)
{
print
"
314
$FTPCMD
not OK
(
$ok
)
in state:
$state
!
\r\n
";
ex
i
t
;
print
"
500
$FTPCMD
not OK in state:
$state
!
\r\n
";
n
ext
;
}
my
$newstate
=
$statechange
{
$FTPCMD
};
...
...
@@ -363,12 +380,10 @@ for ( $waitedpid = 0;
sub
spawn
{
my
$coderef
=
shift
;
unless
(
@
_
==
0
&&
$coderef
&&
ref
(
$coderef
)
eq
'
CODE
')
{
confess
"
usage: spawn CODEREF
";
}
my
$pid
;
if
(
!
defined
(
$pid
=
fork
))
{
logmsg
"
cannot fork: $!
\n
";
...
...
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