Ignore:
Timestamp:
11/11/11 13:17:43 (19 months ago)
Author:
BrainSlayer
Message:

update proftp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/proftpd/tests/t/lib/ProFTPD/Tests/Modules/mod_exec.pm

    r15154 r17876  
    22 
    33use lib qw(t/lib); 
    4 use base qw(Test::Unit::TestCase ProFTPD::TestSuite::Child); 
     4use base qw(ProFTPD::TestSuite::Child); 
    55use strict; 
    66 
    7 use File::Path qw(mkpath rmtree); 
     7use File::Copy; 
    88use File::Spec; 
    99use IO::Handle; 
     
    8282  }, 
    8383 
     84  exec_on_cmd_var_A_bug3479 => { 
     85    order => ++$order, 
     86    test_class => [qw(bug forking mod_vroot)], 
     87  }, 
     88 
    8489}; 
    8590 
     
    9095sub list_tests { 
    9196  return testsuite_get_runnable_tests($TESTS); 
    92 } 
    93  
    94 sub set_up { 
    95   my $self = shift; 
    96   $self->{tmpdir} = testsuite_get_tmp_dir(); 
    97  
    98   # Create temporary scratch dir 
    99   eval { mkpath($self->{tmpdir}) }; 
    100   if ($@) { 
    101     my $abs_path = File::Spec->rel2abs($self->{tmpdir}); 
    102     die("Can't create dir $abs_path: $@"); 
    103   } 
    104 } 
    105  
    106 sub tear_down { 
    107   my $self = shift; 
    108  
    109   # Remove temporary scratch dir 
    110   if ($self->{tmpdir}) { 
    111     eval { rmtree($self->{tmpdir}) }; 
    112   } 
    113  
    114   undef $self; 
    11597} 
    11698 
     
    587569 
    588570      my $buf; 
    589       while ($conn->read($buf, 8192)) { 
     571      while ($conn->read($buf, 8192, 30)) { 
    590572      } 
    591573      $conn->close(); 
     
    18821864} 
    18831865 
     1866sub exec_on_cmd_var_A_bug3479 { 
     1867  my $self = shift; 
     1868  my $tmpdir = $self->{tmpdir}; 
     1869 
     1870  my $config_file = "$tmpdir/exec.conf"; 
     1871  my $pid_file = File::Spec->rel2abs("$tmpdir/exec.pid"); 
     1872  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/exec.scoreboard"); 
     1873 
     1874  my $log_file = File::Spec->rel2abs('tests.log'); 
     1875 
     1876  my $auth_user_file = File::Spec->rel2abs("$tmpdir/exec.passwd"); 
     1877  my $auth_group_file = File::Spec->rel2abs("$tmpdir/exec.group"); 
     1878 
     1879  my ($user, $group) = config_get_identity(); 
     1880 
     1881  my $passwd = 'ftp@nospam.org'; 
     1882  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1883  my $uid = 500; 
     1884  my $gid = 500; 
     1885 
     1886  # Make sure that, if we're running as root, that the home directory has 
     1887  # permissions/privs set for the account we create 
     1888  if ($< == 0) { 
     1889    unless (chmod(0755, $home_dir)) { 
     1890      die("Can't set perms on $home_dir to 0755: $!"); 
     1891    } 
     1892 
     1893    unless (chown($uid, $gid, $home_dir)) { 
     1894      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1895    } 
     1896  } 
     1897 
     1898  auth_user_write($auth_user_file, $user, 'foo', $uid, $gid, $home_dir, 
     1899    '/bin/bash'); 
     1900  auth_group_write($auth_group_file, $group, $gid, $user); 
     1901 
     1902  my $cmd_file = File::Spec->rel2abs("$tmpdir/cmd.txt"); 
     1903 
     1904  my $config = { 
     1905    PidFile => $pid_file, 
     1906    ScoreboardFile => $scoreboard_file, 
     1907    SystemLog => $log_file, 
     1908 
     1909    AuthUserFile => $auth_user_file, 
     1910    AuthGroupFile => $auth_group_file, 
     1911 
     1912    Anonymous => { 
     1913      $home_dir => { 
     1914        User => $user, 
     1915        Group => $group, 
     1916        UserAlias => "anonymous $user", 
     1917        RequireValidShell => 'off', 
     1918      }, 
     1919    }, 
     1920 
     1921    IfModules => { 
     1922      'mod_delay.c' => { 
     1923        DelayEngine => 'off', 
     1924      }, 
     1925 
     1926      'mod_exec.c' => { 
     1927        ExecEngine => 'on', 
     1928        ExecLog => $log_file, 
     1929        ExecTimeout => 1, 
     1930        ExecOnCommand => "LIST,NLST /bin/bash -c \"echo %A > $cmd_file\"", 
     1931      }, 
     1932 
     1933      'mod_vroot.c' => { 
     1934        VRootEngine => 'on', 
     1935      }, 
     1936    }, 
     1937  }; 
     1938 
     1939  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1940 
     1941  # Open pipes, for use between the parent and child processes.  Specifically, 
     1942  # the child will indicate when it's done with its test by writing a message 
     1943  # to the parent. 
     1944  my ($rfh, $wfh); 
     1945  unless (pipe($rfh, $wfh)) { 
     1946    die("Can't open pipe: $!"); 
     1947  } 
     1948 
     1949  my $ex; 
     1950 
     1951  # Fork child 
     1952  $self->handle_sigchld(); 
     1953  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1954  if ($pid) { 
     1955    eval { 
     1956      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1957      $client->login('anonymous', $passwd); 
     1958      $client->list(); 
     1959      $client->quit(); 
     1960    }; 
     1961 
     1962    if ($@) { 
     1963      $ex = $@; 
     1964    } 
     1965 
     1966    $wfh->print("done\n"); 
     1967    $wfh->flush(); 
     1968 
     1969  } else { 
     1970    eval { server_wait($config_file, $rfh) }; 
     1971    if ($@) { 
     1972      warn($@); 
     1973      exit 1; 
     1974    } 
     1975 
     1976    exit 0; 
     1977  } 
     1978 
     1979  # Stop server 
     1980  server_stop($pid_file); 
     1981 
     1982  $self->assert_child_ok($pid); 
     1983 
     1984  if ($ex) { 
     1985    die($ex); 
     1986  } 
     1987 
     1988  if (open(my $fh, "< $cmd_file")) { 
     1989    my $line = <$fh>; 
     1990    close($fh); 
     1991 
     1992    chomp($line); 
     1993 
     1994    $self->assert($line eq $passwd, 
     1995      test_msg("Expected '$passwd', got '$line'")); 
     1996 
     1997  } else { 
     1998    die("Can't read $cmd_file: $!"); 
     1999  } 
     2000 
     2001  unlink($log_file); 
     2002} 
     2003 
    188420041; 
Note: See TracChangeset for help on using the changeset viewer.