ftpsserver.pl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/perl
  2. #
  3. # $Id: ftpsserver.pl,v 1.5 2003/10/29 16:27:43 bagder Exp $
  4. # This is the FTPS server designed for the curl test suite.
  5. #
  6. # It is actually just a layer that runs stunnel properly.
  7. use strict;
  8. my $stunnel = "stunnel";
  9. #
  10. # -p pemfile
  11. # -P pid dir
  12. # -d listen port
  13. # -r target port
  14. # -s stunnel path
  15. my $verbose=0; # set to 1 for debugging
  16. my $port = 8821; # just our default, weird enough
  17. my $remote_port = 8921; # test ftp-server port
  18. my $path = `pwd`;
  19. chomp $path;
  20. my $srcdir=$path;
  21. do {
  22. if($ARGV[0] eq "-v") {
  23. $verbose=1;
  24. }
  25. elsif($ARGV[0] eq "-r") {
  26. $remote_port=$ARGV[1];
  27. shift @ARGV;
  28. }
  29. elsif($ARGV[0] eq "-d") {
  30. $srcdir=$ARGV[1];
  31. shift @ARGV;
  32. }
  33. elsif($ARGV[0] eq "-s") {
  34. $stunnel=$ARGV[1];
  35. shift @ARGV;
  36. }
  37. elsif($ARGV[0] =~ /^(\d+)$/) {
  38. $port = $1;
  39. }
  40. } while(shift @ARGV);
  41. my $conffile="$path/stunnel.conf"; # stunnel configuration data
  42. my $certfile="$srcdir/stunnel.pem"; # stunnel server certificate
  43. my $pidfile="$path/.ftps.pid"; # stunnel process pid file
  44. open(CONF, ">$conffile") || return 1;
  45. print CONF "
  46. CApath=$path
  47. cert = $certfile
  48. pid = $pidfile
  49. debug = 0
  50. output = /dev/null
  51. foreground = yes
  52. [curltest]
  53. accept = $port
  54. connect = $remote_port
  55. ";
  56. close CONF;
  57. #system("chmod go-rwx $conffile $certfile"); # secure permissions
  58. # works only with stunnel versions < 4.00
  59. my $cmd="$stunnel -p $certfile -P $pidfile -d $port -r $remote_port 2>/dev/null";
  60. # use some heuristics to determine stunnel version
  61. my $version_ge_4=system("$stunnel -V 2>&1|grep '^stunnel.* on '>/dev/null 2>&1");
  62. # works only with stunnel versions >= 4.00
  63. if ($version_ge_4) { $cmd="$stunnel $conffile"; }
  64. if($verbose) {
  65. print "FTPS server: $cmd\n";
  66. }
  67. system($cmd);
  68. unlink $conffile;