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_site_misc.pm

    r14672 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::Path qw(mkpath); 
    88use File::Spec; 
    99use IO::Handle; 
     
    5555  }, 
    5656 
     57  site_misc_mkdir_failed_bug3518 => { 
     58    order => ++$order, 
     59    test_class => [qw(bug forking)], 
     60  }, 
     61 
     62  site_misc_rmdir_failed_bug3518 => { 
     63    order => ++$order, 
     64    test_class => [qw(bug forking)], 
     65  }, 
     66 
     67  site_misc_symlink_failed_bug3518 => { 
     68    order => ++$order, 
     69    test_class => [qw(bug forking)], 
     70  }, 
     71 
     72  site_misc_utime_failed_bug3518 => { 
     73    order => ++$order, 
     74    test_class => [qw(bug forking)], 
     75  }, 
     76 
     77  site_misc_mkdir_failed_bug3519 => { 
     78    order => ++$order, 
     79    test_class => [qw(bug forking)], 
     80  }, 
     81 
     82  site_misc_rmdir_failed_bug3519 => { 
     83    order => ++$order, 
     84    test_class => [qw(bug forking)], 
     85  }, 
     86 
     87  site_misc_symlink_failed_bug3519 => { 
     88    order => ++$order, 
     89    test_class => [qw(bug forking)], 
     90  }, 
     91 
     92  site_misc_utime_failed_bug3519 => { 
     93    order => ++$order, 
     94    test_class => [qw(bug forking)], 
     95  }, 
     96 
     97  site_misc_mkdir_failed_limit => { 
     98    order => ++$order, 
     99    test_class => [qw(forking)], 
     100  }, 
     101 
     102  site_misc_rmdir_failed_limit => { 
     103    order => ++$order, 
     104    test_class => [qw(forking)], 
     105  }, 
     106 
     107  site_misc_symlink_failed_limit => { 
     108    order => ++$order, 
     109    test_class => [qw(forking)], 
     110  }, 
     111 
     112  site_misc_utime_failed_limit => { 
     113    order => ++$order, 
     114    test_class => [qw(forking)], 
     115  }, 
     116 
    57117}; 
    58118 
     
    63123sub list_tests { 
    64124  return testsuite_get_runnable_tests($TESTS); 
    65 } 
    66  
    67 sub set_up { 
    68   my $self = shift; 
    69   $self->{tmpdir} = testsuite_get_tmp_dir(); 
    70  
    71   # Create temporary scratch dir 
    72   eval { mkpath($self->{tmpdir}) }; 
    73   if ($@) { 
    74     my $abs_path = File::Spec->rel2abs($self->{tmpdir}); 
    75     die("Can't create dir $abs_path: $@"); 
    76   } 
    77 } 
    78  
    79 sub tear_down { 
    80   my $self = shift; 
    81  
    82   # Remove temporary scratch dir 
    83   if ($self->{tmpdir}) { 
    84     eval { rmtree($self->{tmpdir}) }; 
    85   } 
    86  
    87   undef $self; 
    88125} 
    89126 
     
    112149  # permissions/privs set for the account we create 
    113150  if ($< == 0) { 
    114     unless (chmod(0755, $home_dir)) { 
     151    unless (chmod(0755, $home_dir, $test_dir)) { 
    115152      die("Can't set perms on $home_dir to 0755: $!"); 
    116153    } 
    117154 
    118     unless (chown($uid, $gid, $home_dir)) { 
     155    unless (chown($uid, $gid, $home_dir, $test_dir)) { 
    119156      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
    120157    } 
     
    129166    ScoreboardFile => $scoreboard_file, 
    130167    SystemLog => $log_file, 
     168    TraceLog => $log_file, 
     169    Trace => 'fsio:10', 
    131170 
    132171    AuthUserFile => $auth_user_file, 
     
    9971036} 
    9981037 
     1038sub site_misc_mkdir_failed_bug3518 { 
     1039  my $self = shift; 
     1040  my $tmpdir = $self->{tmpdir}; 
     1041 
     1042  my $config_file = "$tmpdir/site.conf"; 
     1043  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1044  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1045 
     1046  my $log_file = File::Spec->rel2abs('tests.log'); 
     1047 
     1048  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1049  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1050 
     1051  my $user = 'proftpd'; 
     1052  my $passwd = 'test'; 
     1053  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1054  my $uid = 500; 
     1055  my $gid = 500; 
     1056 
     1057  my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     1058 
     1059  # Make sure that, if we're running as root, that the home directory has 
     1060  # permissions/privs set for the account we create 
     1061  if ($< == 0) { 
     1062    unless (chmod(0755, $home_dir)) { 
     1063      die("Can't set perms on $home_dir to 0755: $!"); 
     1064    } 
     1065 
     1066    unless (chown($uid, $gid, $home_dir)) { 
     1067      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1068    } 
     1069  } 
     1070 
     1071  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1072    '/bin/bash'); 
     1073  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1074 
     1075  my $config = { 
     1076    PidFile => $pid_file, 
     1077    ScoreboardFile => $scoreboard_file, 
     1078    SystemLog => $log_file, 
     1079 
     1080    AuthUserFile => $auth_user_file, 
     1081    AuthGroupFile => $auth_group_file, 
     1082 
     1083    IfModules => { 
     1084      'mod_delay.c' => { 
     1085        DelayEngine => 'off', 
     1086      }, 
     1087 
     1088      'mod_site_misc.c' => { 
     1089        SiteMiscEngine => 'off', 
     1090      }, 
     1091    }, 
     1092  }; 
     1093 
     1094  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1095 
     1096  # Open pipes, for use between the parent and child processes.  Specifically, 
     1097  # the child will indicate when it's done with its test by writing a message 
     1098  # to the parent. 
     1099  my ($rfh, $wfh); 
     1100  unless (pipe($rfh, $wfh)) { 
     1101    die("Can't open pipe: $!"); 
     1102  } 
     1103 
     1104  my $ex; 
     1105 
     1106  # Fork child 
     1107  $self->handle_sigchld(); 
     1108  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1109  if ($pid) { 
     1110    eval { 
     1111      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1112      $client->login($user, $passwd); 
     1113 
     1114      eval { $client->site('MKDIR', 'foo/bar/baz') }; 
     1115      unless ($@) { 
     1116        die("SITE MKDIR succeeded unexpectedly"); 
     1117      } 
     1118 
     1119      my $resp_code = $client->response_code(); 
     1120      my $resp_msg = $client->response_msg(); 
     1121 
     1122      my $expected; 
     1123 
     1124      $expected = 500; 
     1125      $self->assert($expected == $resp_code, 
     1126        test_msg("Expected $expected, got $resp_code")); 
     1127 
     1128      $expected = "'SITE MKDIR' not understood"; 
     1129      $self->assert($expected eq $resp_msg, 
     1130        test_msg("Expected '$expected', got '$resp_msg'")); 
     1131 
     1132      # Make sure that the test dir is NOT present 
     1133      if (-d $test_dir) { 
     1134        die("Directory $test_dir exists unexpectedly"); 
     1135      } 
     1136    }; 
     1137 
     1138    if ($@) { 
     1139      $ex = $@; 
     1140    } 
     1141 
     1142    $wfh->print("done\n"); 
     1143    $wfh->flush(); 
     1144 
     1145  } else { 
     1146    eval { server_wait($config_file, $rfh) }; 
     1147    if ($@) { 
     1148      warn($@); 
     1149      exit 1; 
     1150    } 
     1151 
     1152    exit 0; 
     1153  } 
     1154 
     1155  # Stop server 
     1156  server_stop($pid_file); 
     1157 
     1158  $self->assert_child_ok($pid); 
     1159 
     1160  if ($ex) { 
     1161    die($ex); 
     1162  } 
     1163 
     1164  unlink($log_file); 
     1165} 
     1166 
     1167sub site_misc_rmdir_failed_bug3518 { 
     1168  my $self = shift; 
     1169  my $tmpdir = $self->{tmpdir}; 
     1170 
     1171  my $config_file = "$tmpdir/site.conf"; 
     1172  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1173  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1174 
     1175  my $log_file = File::Spec->rel2abs('tests.log'); 
     1176 
     1177  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1178  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1179 
     1180  my $user = 'proftpd'; 
     1181  my $passwd = 'test'; 
     1182  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1183  my $uid = 500; 
     1184  my $gid = 500; 
     1185 
     1186  my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     1187  mkpath($sub_dir); 
     1188 
     1189  my $test_dirs = [ 
     1190    File::Spec->rel2abs("$tmpdir/foo"), 
     1191    File::Spec->rel2abs("$tmpdir/foo/bar"), 
     1192    $sub_dir, 
     1193  ]; 
     1194 
     1195  my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt"); 
     1196  if (open(my $fh, "> $test_file")) { 
     1197    print $fh "Quzz\n"; 
     1198 
     1199    unless (close($fh)) { 
     1200      die("Can't write $test_file: $!"); 
     1201    } 
     1202 
     1203  } else { 
     1204    die("Can't open $test_file: $!"); 
     1205  } 
     1206 
     1207  # Make sure that, if we're running as root, that the home directory has 
     1208  # permissions/privs set for the account we create 
     1209  if ($< == 0) { 
     1210    unless (chmod(0755, $home_dir)) { 
     1211      die("Can't set perms on $home_dir to 0755: $!"); 
     1212    } 
     1213 
     1214    unless (chown($uid, $gid, $home_dir)) { 
     1215      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1216    } 
     1217  } 
     1218 
     1219  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1220    '/bin/bash'); 
     1221  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1222 
     1223  my $config = { 
     1224    PidFile => $pid_file, 
     1225    ScoreboardFile => $scoreboard_file, 
     1226    SystemLog => $log_file, 
     1227 
     1228    AuthUserFile => $auth_user_file, 
     1229    AuthGroupFile => $auth_group_file, 
     1230 
     1231    IfModules => { 
     1232      'mod_delay.c' => { 
     1233        DelayEngine => 'off', 
     1234      }, 
     1235 
     1236      'mod_site_misc.c' => { 
     1237        SiteMiscEngine => 'off', 
     1238      }, 
     1239 
     1240    }, 
     1241  }; 
     1242 
     1243  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1244 
     1245  # Open pipes, for use between the parent and child processes.  Specifically, 
     1246  # the child will indicate when it's done with its test by writing a message 
     1247  # to the parent. 
     1248  my ($rfh, $wfh); 
     1249  unless (pipe($rfh, $wfh)) { 
     1250    die("Can't open pipe: $!"); 
     1251  } 
     1252 
     1253  my $ex; 
     1254 
     1255  # Fork child 
     1256  $self->handle_sigchld(); 
     1257  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1258  if ($pid) { 
     1259    eval { 
     1260      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1261      $client->login($user, $passwd); 
     1262 
     1263      eval { $client->site('RMDIR', 'foo') }; 
     1264      unless ($@) { 
     1265        die("SITE RMDIR succeeded unexpectedly"); 
     1266      } 
     1267 
     1268      my $resp_code = $client->response_code(); 
     1269      my $resp_msg = $client->response_msg(); 
     1270 
     1271      my $expected; 
     1272 
     1273      $expected = 500; 
     1274      $self->assert($expected == $resp_code, 
     1275        test_msg("Expected $expected, got $resp_code")); 
     1276 
     1277      $expected = "'SITE RMDIR' not understood"; 
     1278      $self->assert($expected eq $resp_msg, 
     1279        test_msg("Expected '$expected', got '$resp_msg'")); 
     1280 
     1281      # Make sure that the test file is NOT gone, along with all of the 
     1282      # test dirs. 
     1283      unless (-f $test_file) { 
     1284        die("File $test_file does not exist as expected"); 
     1285      } 
     1286 
     1287      foreach my $test_dir (@$test_dirs) { 
     1288        unless (-d $test_dir) { 
     1289          die("Directory $test_dir does not exist as expected"); 
     1290        } 
     1291      } 
     1292    }; 
     1293 
     1294    if ($@) { 
     1295      $ex = $@; 
     1296    } 
     1297 
     1298    $wfh->print("done\n"); 
     1299    $wfh->flush(); 
     1300 
     1301  } else { 
     1302    eval { server_wait($config_file, $rfh) }; 
     1303    if ($@) { 
     1304      warn($@); 
     1305      exit 1; 
     1306    } 
     1307 
     1308    exit 0; 
     1309  } 
     1310 
     1311  # Stop server 
     1312  server_stop($pid_file); 
     1313 
     1314  $self->assert_child_ok($pid); 
     1315 
     1316  if ($ex) { 
     1317    die($ex); 
     1318  } 
     1319 
     1320  unlink($log_file); 
     1321} 
     1322 
     1323sub site_misc_symlink_failed_bug3518 { 
     1324  my $self = shift; 
     1325  my $tmpdir = $self->{tmpdir}; 
     1326 
     1327  my $config_file = "$tmpdir/site.conf"; 
     1328  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1329  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1330 
     1331  my $log_file = File::Spec->rel2abs('tests.log'); 
     1332 
     1333  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1334  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1335 
     1336  my $user = 'proftpd'; 
     1337  my $passwd = 'test'; 
     1338  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1339  my $uid = 500; 
     1340  my $gid = 500; 
     1341 
     1342  my $test_symlink = File::Spec->rel2abs("$tmpdir/foo"); 
     1343 
     1344  # Make sure that, if we're running as root, that the home directory has 
     1345  # permissions/privs set for the account we create 
     1346  if ($< == 0) { 
     1347    unless (chmod(0755, $home_dir)) { 
     1348      die("Can't set perms on $home_dir to 0755: $!"); 
     1349    } 
     1350 
     1351    unless (chown($uid, $gid, $home_dir)) { 
     1352      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1353    } 
     1354  } 
     1355 
     1356  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1357    '/bin/bash'); 
     1358  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1359 
     1360  my $config = { 
     1361    PidFile => $pid_file, 
     1362    ScoreboardFile => $scoreboard_file, 
     1363    SystemLog => $log_file, 
     1364 
     1365    AuthUserFile => $auth_user_file, 
     1366    AuthGroupFile => $auth_group_file, 
     1367 
     1368    IfModules => { 
     1369      'mod_delay.c' => { 
     1370        DelayEngine => 'off', 
     1371      }, 
     1372 
     1373      'mod_site_misc.c' => { 
     1374        SiteMiscEngine => 'off', 
     1375      }, 
     1376 
     1377    }, 
     1378  }; 
     1379 
     1380  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1381 
     1382  # Open pipes, for use between the parent and child processes.  Specifically, 
     1383  # the child will indicate when it's done with its test by writing a message 
     1384  # to the parent. 
     1385  my ($rfh, $wfh); 
     1386  unless (pipe($rfh, $wfh)) { 
     1387    die("Can't open pipe: $!"); 
     1388  } 
     1389 
     1390  my $ex; 
     1391 
     1392  # Fork child 
     1393  $self->handle_sigchld(); 
     1394  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1395  if ($pid) { 
     1396    eval { 
     1397      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1398      $client->login($user, $passwd); 
     1399 
     1400      eval { $client->site('SYMLINK', 'site.conf', 'foo') }; 
     1401      unless ($@) { 
     1402        die("SITE SYMLINK succeeded unexpectedly"); 
     1403      } 
     1404 
     1405      my $resp_code = $client->response_code(); 
     1406      my $resp_msg = $client->response_msg(); 
     1407 
     1408      my $expected; 
     1409 
     1410      $expected = 500; 
     1411      $self->assert($expected == $resp_code, 
     1412        test_msg("Expected $expected, got $resp_code")); 
     1413 
     1414      $expected = "'SITE SYMLINK' not understood"; 
     1415      $self->assert($expected eq $resp_msg, 
     1416        test_msg("Expected '$expected', got '$resp_msg'")); 
     1417 
     1418      if (-l $test_symlink) { 
     1419        die("Symlink $test_symlink exists unexpectedly"); 
     1420      } 
     1421    }; 
     1422 
     1423    if ($@) { 
     1424      $ex = $@; 
     1425    } 
     1426 
     1427    $wfh->print("done\n"); 
     1428    $wfh->flush(); 
     1429 
     1430  } else { 
     1431    eval { server_wait($config_file, $rfh) }; 
     1432    if ($@) { 
     1433      warn($@); 
     1434      exit 1; 
     1435    } 
     1436 
     1437    exit 0; 
     1438  } 
     1439 
     1440  # Stop server 
     1441  server_stop($pid_file); 
     1442 
     1443  $self->assert_child_ok($pid); 
     1444 
     1445  if ($ex) { 
     1446    die($ex); 
     1447  } 
     1448 
     1449  unlink($log_file); 
     1450} 
     1451 
     1452sub site_misc_utime_failed_bug3518 { 
     1453  my $self = shift; 
     1454  my $tmpdir = $self->{tmpdir}; 
     1455 
     1456  my $config_file = "$tmpdir/site.conf"; 
     1457  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1458  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1459 
     1460  my $log_file = File::Spec->rel2abs('tests.log'); 
     1461 
     1462  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1463  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1464 
     1465  my $user = 'proftpd'; 
     1466  my $passwd = 'test'; 
     1467  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1468  my $uid = 500; 
     1469  my $gid = 500; 
     1470 
     1471  # Make sure that, if we're running as root, that the home directory has 
     1472  # permissions/privs set for the account we create 
     1473  if ($< == 0) { 
     1474    unless (chmod(0755, $home_dir)) { 
     1475      die("Can't set perms on $home_dir to 0755: $!"); 
     1476    } 
     1477 
     1478    unless (chown($uid, $gid, $home_dir)) { 
     1479      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1480    } 
     1481  } 
     1482 
     1483  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1484    '/bin/bash'); 
     1485  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1486 
     1487  my $config = { 
     1488    PidFile => $pid_file, 
     1489    ScoreboardFile => $scoreboard_file, 
     1490    SystemLog => $log_file, 
     1491 
     1492    AuthUserFile => $auth_user_file, 
     1493    AuthGroupFile => $auth_group_file, 
     1494 
     1495    IfModules => { 
     1496      'mod_delay.c' => { 
     1497        DelayEngine => 'off', 
     1498      }, 
     1499 
     1500      'mod_site_misc.c' => { 
     1501        SiteMiscEngine => 'off', 
     1502      }, 
     1503 
     1504    }, 
     1505  }; 
     1506 
     1507  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1508 
     1509  # Open pipes, for use between the parent and child processes.  Specifically, 
     1510  # the child will indicate when it's done with its test by writing a message 
     1511  # to the parent. 
     1512  my ($rfh, $wfh); 
     1513  unless (pipe($rfh, $wfh)) { 
     1514    die("Can't open pipe: $!"); 
     1515  } 
     1516 
     1517  my $ex; 
     1518 
     1519  # Fork child 
     1520  $self->handle_sigchld(); 
     1521  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1522  if ($pid) { 
     1523    eval { 
     1524      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1525      $client->login($user, $passwd); 
     1526 
     1527      eval { $client->site('UTIME', '200002240826', 'site.conf') }; 
     1528      unless ($@) { 
     1529        die("SITE UTIME succeeded unexpectedly"); 
     1530      } 
     1531 
     1532      my $resp_code = $client->response_code(); 
     1533      my $resp_msg = $client->response_msg(); 
     1534 
     1535      my $expected; 
     1536 
     1537      $expected = 500; 
     1538      $self->assert($expected == $resp_code, 
     1539        test_msg("Expected $expected, got $resp_code")); 
     1540 
     1541      $expected = "'SITE UTIME' not understood"; 
     1542      $self->assert($expected eq $resp_msg, 
     1543        test_msg("Expected '$expected', got '$resp_msg'")); 
     1544    }; 
     1545 
     1546    if ($@) { 
     1547      $ex = $@; 
     1548    } 
     1549 
     1550    $wfh->print("done\n"); 
     1551    $wfh->flush(); 
     1552 
     1553  } else { 
     1554    eval { server_wait($config_file, $rfh) }; 
     1555    if ($@) { 
     1556      warn($@); 
     1557      exit 1; 
     1558    } 
     1559 
     1560    exit 0; 
     1561  } 
     1562 
     1563  # Stop server 
     1564  server_stop($pid_file); 
     1565 
     1566  $self->assert_child_ok($pid); 
     1567 
     1568  if ($ex) { 
     1569    die($ex); 
     1570  } 
     1571 
     1572  unlink($log_file); 
     1573} 
     1574 
     1575sub site_misc_mkdir_failed_bug3519 { 
     1576  my $self = shift; 
     1577  my $tmpdir = $self->{tmpdir}; 
     1578 
     1579  my $config_file = "$tmpdir/site.conf"; 
     1580  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1581  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1582 
     1583  my $log_file = File::Spec->rel2abs('tests.log'); 
     1584 
     1585  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1586  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1587 
     1588  my $user = 'proftpd'; 
     1589  my $passwd = 'test'; 
     1590  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1591  my $uid = 500; 
     1592  my $gid = 500; 
     1593 
     1594  my $start_dir = File::Spec->rel2abs("$tmpdir/bar"); 
     1595  mkpath($start_dir); 
     1596 
     1597  my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     1598 
     1599  # Make sure that, if we're running as root, that the home directory has 
     1600  # permissions/privs set for the account we create 
     1601  if ($< == 0) { 
     1602    unless (chmod(0755, $home_dir)) { 
     1603      die("Can't set perms on $home_dir to 0755: $!"); 
     1604    } 
     1605 
     1606    unless (chown($uid, $gid, $home_dir)) { 
     1607      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1608    } 
     1609  } 
     1610 
     1611  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1612    '/bin/bash'); 
     1613  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1614 
     1615  my $config = { 
     1616    PidFile => $pid_file, 
     1617    ScoreboardFile => $scoreboard_file, 
     1618    SystemLog => $log_file, 
     1619 
     1620    AuthUserFile => $auth_user_file, 
     1621    AuthGroupFile => $auth_group_file, 
     1622 
     1623    IfModules => { 
     1624      'mod_delay.c' => { 
     1625        DelayEngine => 'off', 
     1626      }, 
     1627    }, 
     1628  }; 
     1629 
     1630  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1631 
     1632  if (open(my $fh, ">> $config_file")) { 
     1633    print $fh <<EOT; 
     1634<Directory $tmpdir/foo> 
     1635  <Limit WRITE> 
     1636    DenyAll 
     1637  </Limit> 
     1638</Directory> 
     1639EOT 
     1640 
     1641    unless (close($fh)) { 
     1642      die("Can't write $config_file: $!"); 
     1643    } 
     1644 
     1645  } else { 
     1646    die("Can't open $config_file: $!"); 
     1647  } 
     1648 
     1649  # Open pipes, for use between the parent and child processes.  Specifically, 
     1650  # the child will indicate when it's done with its test by writing a message 
     1651  # to the parent. 
     1652  my ($rfh, $wfh); 
     1653  unless (pipe($rfh, $wfh)) { 
     1654    die("Can't open pipe: $!"); 
     1655  } 
     1656 
     1657  my $ex; 
     1658 
     1659  # Fork child 
     1660  $self->handle_sigchld(); 
     1661  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1662  if ($pid) { 
     1663    eval { 
     1664      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1665      $client->login($user, $passwd); 
     1666 
     1667      my $path = 'bar/../foo/bar/baz'; 
     1668 
     1669      eval { $client->site('MKDIR', $path) }; 
     1670      unless ($@) { 
     1671        die("SITE MKDIR succeeded unexpectedly"); 
     1672      } 
     1673 
     1674      my $resp_code = $client->response_code(); 
     1675      my $resp_msg = $client->response_msg(); 
     1676 
     1677      my $expected; 
     1678 
     1679      $expected = 550; 
     1680      $self->assert($expected == $resp_code, 
     1681        test_msg("Expected $expected, got $resp_code")); 
     1682 
     1683      $expected = "MKDIR $path: Operation not permitted"; 
     1684      $self->assert($expected eq $resp_msg, 
     1685        test_msg("Expected '$expected', got '$resp_msg'")); 
     1686 
     1687      $client->quit(); 
     1688 
     1689      # Make sure the directory doesn't exist 
     1690      if (-d $test_dir) { 
     1691        die("Directory $test_dir exists unexpectedly"); 
     1692      } 
     1693    }; 
     1694 
     1695    if ($@) { 
     1696      $ex = $@; 
     1697    } 
     1698 
     1699    $wfh->print("done\n"); 
     1700    $wfh->flush(); 
     1701 
     1702  } else { 
     1703    eval { server_wait($config_file, $rfh) }; 
     1704    if ($@) { 
     1705      warn($@); 
     1706      exit 1; 
     1707    } 
     1708 
     1709    exit 0; 
     1710  } 
     1711 
     1712  # Stop server 
     1713  server_stop($pid_file); 
     1714 
     1715  $self->assert_child_ok($pid); 
     1716 
     1717  if ($ex) { 
     1718    die($ex); 
     1719  } 
     1720 
     1721  unlink($log_file); 
     1722} 
     1723 
     1724sub site_misc_rmdir_failed_bug3519 { 
     1725  my $self = shift; 
     1726  my $tmpdir = $self->{tmpdir}; 
     1727 
     1728  my $config_file = "$tmpdir/site.conf"; 
     1729  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1730  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1731 
     1732  my $log_file = File::Spec->rel2abs('tests.log'); 
     1733 
     1734  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1735  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1736 
     1737  my $user = 'proftpd'; 
     1738  my $passwd = 'test'; 
     1739  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1740  my $uid = 500; 
     1741  my $gid = 500; 
     1742 
     1743  my $start_dir = File::Spec->rel2abs("$tmpdir/bar"); 
     1744  mkpath($start_dir); 
     1745 
     1746  my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     1747  mkpath($sub_dir); 
     1748 
     1749  my $test_dirs = [ 
     1750    File::Spec->rel2abs("$tmpdir/foo"), 
     1751    File::Spec->rel2abs("$tmpdir/foo/bar"), 
     1752    $sub_dir, 
     1753  ]; 
     1754 
     1755  my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt"); 
     1756  if (open(my $fh, "> $test_file")) { 
     1757    print $fh "Quzz\n"; 
     1758 
     1759    unless (close($fh)) { 
     1760      die("Can't write $test_file: $!"); 
     1761    } 
     1762 
     1763  } else { 
     1764    die("Can't open $test_file: $!"); 
     1765  } 
     1766 
     1767  # Make sure that, if we're running as root, that the home directory has 
     1768  # permissions/privs set for the account we create 
     1769  if ($< == 0) { 
     1770    unless (chmod(0755, $home_dir)) { 
     1771      die("Can't set perms on $home_dir to 0755: $!"); 
     1772    } 
     1773 
     1774    unless (chown($uid, $gid, $home_dir)) { 
     1775      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1776    } 
     1777  } 
     1778 
     1779  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1780    '/bin/bash'); 
     1781  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1782 
     1783  my $config = { 
     1784    PidFile => $pid_file, 
     1785    ScoreboardFile => $scoreboard_file, 
     1786    SystemLog => $log_file, 
     1787 
     1788    AuthUserFile => $auth_user_file, 
     1789    AuthGroupFile => $auth_group_file, 
     1790 
     1791    IfModules => { 
     1792      'mod_delay.c' => { 
     1793        DelayEngine => 'off', 
     1794      }, 
     1795    }, 
     1796  }; 
     1797 
     1798  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1799 
     1800  if (open(my $fh, ">> $config_file")) { 
     1801    print $fh <<EOT; 
     1802<Directory $tmpdir/foo> 
     1803  <Limit WRITE> 
     1804    DenyAll 
     1805  </Limit> 
     1806</Directory> 
     1807EOT 
     1808 
     1809    unless (close($fh)) { 
     1810      die("Can't write $config_file: $!"); 
     1811    } 
     1812 
     1813  } else { 
     1814    die("Can't open $config_file: $!"); 
     1815  } 
     1816 
     1817  # Open pipes, for use between the parent and child processes.  Specifically, 
     1818  # the child will indicate when it's done with its test by writing a message 
     1819  # to the parent. 
     1820  my ($rfh, $wfh); 
     1821  unless (pipe($rfh, $wfh)) { 
     1822    die("Can't open pipe: $!"); 
     1823  } 
     1824 
     1825  my $ex; 
     1826 
     1827  # Fork child 
     1828  $self->handle_sigchld(); 
     1829  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1830  if ($pid) { 
     1831    eval { 
     1832      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1833      $client->login($user, $passwd); 
     1834 
     1835      my $path = 'bar/../foo'; 
     1836 
     1837      eval { $client->site('RMDIR', $path) }; 
     1838      unless ($@) { 
     1839        die("SITE RMDIR succeeded unexpectedly"); 
     1840      } 
     1841 
     1842      my $resp_code = $client->response_code(); 
     1843      my $resp_msg = $client->response_msg(); 
     1844 
     1845      my $expected; 
     1846 
     1847      $expected = 550; 
     1848      $self->assert($expected == $resp_code, 
     1849        test_msg("Expected $expected, got $resp_code")); 
     1850 
     1851      $expected = "RMDIR $path: Operation not permitted"; 
     1852      $self->assert($expected eq $resp_msg, 
     1853        test_msg("Expected '$expected', got '$resp_msg'")); 
     1854 
     1855      # Make sure that the test file is NOT gone, along with all of the 
     1856      # test dirs. 
     1857      unless (-f $test_file) { 
     1858        die("File $test_file does not exist as expected"); 
     1859      } 
     1860 
     1861      foreach my $test_dir (@$test_dirs) { 
     1862        unless (-d $test_dir) { 
     1863          die("Directory $test_dir does not exist as expected"); 
     1864        } 
     1865      } 
     1866    }; 
     1867 
     1868    if ($@) { 
     1869      $ex = $@; 
     1870    } 
     1871 
     1872    $wfh->print("done\n"); 
     1873    $wfh->flush(); 
     1874 
     1875  } else { 
     1876    eval { server_wait($config_file, $rfh) }; 
     1877    if ($@) { 
     1878      warn($@); 
     1879      exit 1; 
     1880    } 
     1881 
     1882    exit 0; 
     1883  } 
     1884 
     1885  # Stop server 
     1886  server_stop($pid_file); 
     1887 
     1888  $self->assert_child_ok($pid); 
     1889 
     1890  if ($ex) { 
     1891    die($ex); 
     1892  } 
     1893 
     1894  unlink($log_file); 
     1895} 
     1896 
     1897sub site_misc_symlink_failed_bug3519 { 
     1898  my $self = shift; 
     1899  my $tmpdir = $self->{tmpdir}; 
     1900 
     1901  my $config_file = "$tmpdir/site.conf"; 
     1902  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     1903  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     1904 
     1905  my $log_file = File::Spec->rel2abs('tests.log'); 
     1906 
     1907  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     1908  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     1909 
     1910  my $user = 'proftpd'; 
     1911  my $passwd = 'test'; 
     1912  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1913  my $uid = 500; 
     1914  my $gid = 500; 
     1915 
     1916  my $start_dir = File::Spec->rel2abs("$tmpdir/bar"); 
     1917  mkpath($start_dir); 
     1918 
     1919  my $test_symlink = File::Spec->rel2abs("$tmpdir/foo"); 
     1920 
     1921  # Make sure that, if we're running as root, that the home directory has 
     1922  # permissions/privs set for the account we create 
     1923  if ($< == 0) { 
     1924    unless (chmod(0755, $home_dir)) { 
     1925      die("Can't set perms on $home_dir to 0755: $!"); 
     1926    } 
     1927 
     1928    unless (chown($uid, $gid, $home_dir)) { 
     1929      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1930    } 
     1931  } 
     1932 
     1933  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1934    '/bin/bash'); 
     1935  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     1936 
     1937  my $config = { 
     1938    PidFile => $pid_file, 
     1939    ScoreboardFile => $scoreboard_file, 
     1940    SystemLog => $log_file, 
     1941 
     1942    AuthUserFile => $auth_user_file, 
     1943    AuthGroupFile => $auth_group_file, 
     1944 
     1945    IfModules => { 
     1946      'mod_delay.c' => { 
     1947        DelayEngine => 'off', 
     1948      }, 
     1949 
     1950    }, 
     1951  }; 
     1952 
     1953  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1954 
     1955  if (open(my $fh, ">> $config_file")) { 
     1956    print $fh <<EOT; 
     1957<Directory $tmpdir/foo> 
     1958  <Limit WRITE> 
     1959    DenyAll 
     1960  </Limit> 
     1961</Directory> 
     1962EOT 
     1963 
     1964    unless (close($fh)) { 
     1965      die("Can't write $config_file: $!"); 
     1966    } 
     1967 
     1968  } else { 
     1969    die("Can't open $config_file: $!"); 
     1970  } 
     1971 
     1972  # Open pipes, for use between the parent and child processes.  Specifically, 
     1973  # the child will indicate when it's done with its test by writing a message 
     1974  # to the parent. 
     1975  my ($rfh, $wfh); 
     1976  unless (pipe($rfh, $wfh)) { 
     1977    die("Can't open pipe: $!"); 
     1978  } 
     1979 
     1980  my $ex; 
     1981 
     1982  # Fork child 
     1983  $self->handle_sigchld(); 
     1984  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1985  if ($pid) { 
     1986    eval { 
     1987      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1988      $client->login($user, $passwd); 
     1989 
     1990      my $path = "bar/../foo"; 
     1991 
     1992      eval { $client->site('SYMLINK', 'site.conf', 'foo') }; 
     1993      unless ($@) { 
     1994        die("SITE SYMLINK succeeded unexpectedly"); 
     1995      } 
     1996 
     1997      my $resp_code = $client->response_code(); 
     1998      my $resp_msg = $client->response_msg(); 
     1999 
     2000      my $expected; 
     2001 
     2002      $expected = 550; 
     2003      $self->assert($expected == $resp_code, 
     2004        test_msg("Expected $expected, got $resp_code")); 
     2005 
     2006      $expected = "foo: Operation not permitted"; 
     2007      $self->assert($expected eq $resp_msg, 
     2008        test_msg("Expected '$expected', got '$resp_msg'")); 
     2009 
     2010      if (-l $test_symlink) { 
     2011        die("Symlink $test_symlink exists unexpectedly"); 
     2012      } 
     2013    }; 
     2014 
     2015    if ($@) { 
     2016      $ex = $@; 
     2017    } 
     2018 
     2019    $wfh->print("done\n"); 
     2020    $wfh->flush(); 
     2021 
     2022  } else { 
     2023    eval { server_wait($config_file, $rfh) }; 
     2024    if ($@) { 
     2025      warn($@); 
     2026      exit 1; 
     2027    } 
     2028 
     2029    exit 0; 
     2030  } 
     2031 
     2032  # Stop server 
     2033  server_stop($pid_file); 
     2034 
     2035  $self->assert_child_ok($pid); 
     2036 
     2037  if ($ex) { 
     2038    die($ex); 
     2039  } 
     2040 
     2041  unlink($log_file); 
     2042} 
     2043 
     2044sub site_misc_utime_failed_bug3519 { 
     2045  my $self = shift; 
     2046  my $tmpdir = $self->{tmpdir}; 
     2047 
     2048  my $config_file = "$tmpdir/site.conf"; 
     2049  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     2050  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     2051 
     2052  my $log_file = File::Spec->rel2abs('tests.log'); 
     2053 
     2054  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     2055  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     2056 
     2057  my $user = 'proftpd'; 
     2058  my $passwd = 'test'; 
     2059  my $home_dir = File::Spec->rel2abs($tmpdir); 
     2060  my $uid = 500; 
     2061  my $gid = 500; 
     2062 
     2063  my $start_dir = File::Spec->rel2abs("$tmpdir/bar"); 
     2064  mkpath($start_dir); 
     2065 
     2066  my $sub_dir = File::Spec->rel2abs("$tmpdir/foo"); 
     2067  mkpath($sub_dir); 
     2068 
     2069  my $test_file = File::Spec->rel2abs("$sub_dir/test.txt"); 
     2070  if (open(my $fh, "> $test_file")) { 
     2071    print $fh "Hello, World!\n"; 
     2072    unless (close($fh)) { 
     2073      die("Can't write $test_file: $!"); 
     2074    } 
     2075 
     2076  } else { 
     2077    die("Can't open $test_file: $!"); 
     2078  } 
     2079 
     2080  # Make sure that, if we're running as root, that the home directory has 
     2081  # permissions/privs set for the account we create 
     2082  if ($< == 0) { 
     2083    unless (chmod(0755, $home_dir, $start_dir, $sub_dir)) { 
     2084      die("Can't set perms on $home_dir to 0755: $!"); 
     2085    } 
     2086 
     2087    unless (chown($uid, $gid, $home_dir, $start_dir, $sub_dir)) { 
     2088      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     2089    } 
     2090  } 
     2091 
     2092  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     2093    '/bin/bash'); 
     2094  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     2095 
     2096  my $config = { 
     2097    PidFile => $pid_file, 
     2098    ScoreboardFile => $scoreboard_file, 
     2099    SystemLog => $log_file, 
     2100 
     2101    AuthUserFile => $auth_user_file, 
     2102    AuthGroupFile => $auth_group_file, 
     2103 
     2104    IfModules => { 
     2105      'mod_delay.c' => { 
     2106        DelayEngine => 'off', 
     2107      }, 
     2108 
     2109    }, 
     2110  }; 
     2111 
     2112  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     2113 
     2114  if (open(my $fh, ">> $config_file")) { 
     2115    print $fh <<EOT; 
     2116<Directory $tmpdir/foo> 
     2117  <Limit WRITE> 
     2118    DenyAll 
     2119  </Limit> 
     2120</Directory> 
     2121EOT 
     2122 
     2123    unless (close($fh)) { 
     2124      die("Can't write $config_file: $!"); 
     2125    } 
     2126 
     2127  } else { 
     2128    die("Can't open $config_file: $!"); 
     2129  } 
     2130 
     2131  # Open pipes, for use between the parent and child processes.  Specifically, 
     2132  # the child will indicate when it's done with its test by writing a message 
     2133  # to the parent. 
     2134  my ($rfh, $wfh); 
     2135  unless (pipe($rfh, $wfh)) { 
     2136    die("Can't open pipe: $!"); 
     2137  } 
     2138 
     2139  my $ex; 
     2140 
     2141  # Fork child 
     2142  $self->handle_sigchld(); 
     2143  defined(my $pid = fork()) or die("Can't fork: $!"); 
     2144  if ($pid) { 
     2145    eval { 
     2146      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     2147      $client->login($user, $passwd); 
     2148 
     2149      my $path = 'bar/../foo/test.txt'; 
     2150      my $timestamp = '200002240826'; 
     2151 
     2152      eval { $client->site('UTIME', $timestamp, $path) }; 
     2153      unless ($@) { 
     2154        die("SITE UTIME succeeded unexpectedly"); 
     2155      } 
     2156 
     2157      my $resp_code = $client->response_code(); 
     2158      my $resp_msg = $client->response_msg(); 
     2159 
     2160      my $expected; 
     2161 
     2162      $expected = 550; 
     2163      $self->assert($expected == $resp_code, 
     2164        test_msg("Expected $expected, got $resp_code")); 
     2165 
     2166      $expected = "UTIME $timestamp $path: Operation not permitted"; 
     2167      $self->assert($expected eq $resp_msg, 
     2168        test_msg("Expected '$expected', got '$resp_msg'")); 
     2169    }; 
     2170 
     2171    if ($@) { 
     2172      $ex = $@; 
     2173    } 
     2174 
     2175    $wfh->print("done\n"); 
     2176    $wfh->flush(); 
     2177 
     2178  } else { 
     2179    eval { server_wait($config_file, $rfh) }; 
     2180    if ($@) { 
     2181      warn($@); 
     2182      exit 1; 
     2183    } 
     2184 
     2185    exit 0; 
     2186  } 
     2187 
     2188  # Stop server 
     2189  server_stop($pid_file); 
     2190 
     2191  $self->assert_child_ok($pid); 
     2192 
     2193  if ($ex) { 
     2194    die($ex); 
     2195  } 
     2196 
     2197  unlink($log_file); 
     2198} 
     2199 
     2200sub site_misc_mkdir_failed_limit { 
     2201  my $self = shift; 
     2202  my $tmpdir = $self->{tmpdir}; 
     2203 
     2204  my $config_file = "$tmpdir/site.conf"; 
     2205  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     2206  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     2207 
     2208  my $log_file = File::Spec->rel2abs('tests.log'); 
     2209 
     2210  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     2211  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     2212 
     2213  my $user = 'proftpd'; 
     2214  my $passwd = 'test'; 
     2215  my $home_dir = File::Spec->rel2abs($tmpdir); 
     2216  my $uid = 500; 
     2217  my $gid = 500; 
     2218 
     2219  my $test_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     2220 
     2221  # Make sure that, if we're running as root, that the home directory has 
     2222  # permissions/privs set for the account we create 
     2223  if ($< == 0) { 
     2224    unless (chmod(0755, $home_dir)) { 
     2225      die("Can't set perms on $home_dir to 0755: $!"); 
     2226    } 
     2227 
     2228    unless (chown($uid, $gid, $home_dir)) { 
     2229      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     2230    } 
     2231  } 
     2232 
     2233  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     2234    '/bin/bash'); 
     2235  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     2236 
     2237  my $config = { 
     2238    PidFile => $pid_file, 
     2239    ScoreboardFile => $scoreboard_file, 
     2240    SystemLog => $log_file, 
     2241 
     2242    AuthUserFile => $auth_user_file, 
     2243    AuthGroupFile => $auth_group_file, 
     2244 
     2245    IfModules => { 
     2246      'mod_delay.c' => { 
     2247        DelayEngine => 'off', 
     2248      }, 
     2249    }, 
     2250 
     2251    Limit => { 
     2252      SITE_MKDIR => { 
     2253        DenyAll => '', 
     2254      }, 
     2255    }, 
     2256 
     2257  }; 
     2258 
     2259  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     2260 
     2261  # Open pipes, for use between the parent and child processes.  Specifically, 
     2262  # the child will indicate when it's done with its test by writing a message 
     2263  # to the parent. 
     2264  my ($rfh, $wfh); 
     2265  unless (pipe($rfh, $wfh)) { 
     2266    die("Can't open pipe: $!"); 
     2267  } 
     2268 
     2269  my $ex; 
     2270 
     2271  # Fork child 
     2272  $self->handle_sigchld(); 
     2273  defined(my $pid = fork()) or die("Can't fork: $!"); 
     2274  if ($pid) { 
     2275    eval { 
     2276      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     2277      $client->login($user, $passwd); 
     2278 
     2279      my $path = 'foo/bar/baz'; 
     2280 
     2281      eval { $client->site('MKDIR', $path) }; 
     2282      unless ($@) { 
     2283        die("SITE MKDIR succeeded unexpectedly"); 
     2284      } 
     2285 
     2286      my $resp_code = $client->response_code(); 
     2287      my $resp_msg = $client->response_msg(); 
     2288 
     2289      my $expected; 
     2290 
     2291      $expected = 550; 
     2292      $self->assert($expected == $resp_code, 
     2293        test_msg("Expected $expected, got $resp_code")); 
     2294 
     2295      $expected = "MKDIR $path: Operation not permitted"; 
     2296      $self->assert($expected eq $resp_msg, 
     2297        test_msg("Expected '$expected', got '$resp_msg'")); 
     2298 
     2299      # Make sure that the test dir is NOT present 
     2300      if (-d $test_dir) { 
     2301        die("Directory $test_dir exists unexpectedly"); 
     2302      } 
     2303    }; 
     2304 
     2305    if ($@) { 
     2306      $ex = $@; 
     2307    } 
     2308 
     2309    $wfh->print("done\n"); 
     2310    $wfh->flush(); 
     2311 
     2312  } else { 
     2313    eval { server_wait($config_file, $rfh) }; 
     2314    if ($@) { 
     2315      warn($@); 
     2316      exit 1; 
     2317    } 
     2318 
     2319    exit 0; 
     2320  } 
     2321 
     2322  # Stop server 
     2323  server_stop($pid_file); 
     2324 
     2325  $self->assert_child_ok($pid); 
     2326 
     2327  if ($ex) { 
     2328    die($ex); 
     2329  } 
     2330 
     2331  unlink($log_file); 
     2332} 
     2333 
     2334sub site_misc_rmdir_failed_limit { 
     2335  my $self = shift; 
     2336  my $tmpdir = $self->{tmpdir}; 
     2337 
     2338  my $config_file = "$tmpdir/site.conf"; 
     2339  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     2340  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     2341 
     2342  my $log_file = File::Spec->rel2abs('tests.log'); 
     2343 
     2344  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     2345  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     2346 
     2347  my $user = 'proftpd'; 
     2348  my $passwd = 'test'; 
     2349  my $home_dir = File::Spec->rel2abs($tmpdir); 
     2350  my $uid = 500; 
     2351  my $gid = 500; 
     2352 
     2353  my $sub_dir = File::Spec->rel2abs("$tmpdir/foo/bar/baz"); 
     2354  mkpath($sub_dir); 
     2355 
     2356  my $test_dirs = [ 
     2357    File::Spec->rel2abs("$tmpdir/foo"), 
     2358    File::Spec->rel2abs("$tmpdir/foo/bar"), 
     2359    $sub_dir, 
     2360  ]; 
     2361 
     2362  my $test_file = File::Spec->rel2abs("$tmpdir/foo/bar/quxx.txt"); 
     2363  if (open(my $fh, "> $test_file")) { 
     2364    print $fh "Quzz\n"; 
     2365 
     2366    unless (close($fh)) { 
     2367      die("Can't write $test_file: $!"); 
     2368    } 
     2369 
     2370  } else { 
     2371    die("Can't open $test_file: $!"); 
     2372  } 
     2373 
     2374  # Make sure that, if we're running as root, that the home directory has 
     2375  # permissions/privs set for the account we create 
     2376  if ($< == 0) { 
     2377    unless (chmod(0755, $home_dir)) { 
     2378      die("Can't set perms on $home_dir to 0755: $!"); 
     2379    } 
     2380 
     2381    unless (chown($uid, $gid, $home_dir)) { 
     2382      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     2383    } 
     2384  } 
     2385 
     2386  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     2387    '/bin/bash'); 
     2388  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     2389 
     2390  my $config = { 
     2391    PidFile => $pid_file, 
     2392    ScoreboardFile => $scoreboard_file, 
     2393    SystemLog => $log_file, 
     2394 
     2395    AuthUserFile => $auth_user_file, 
     2396    AuthGroupFile => $auth_group_file, 
     2397 
     2398    IfModules => { 
     2399      'mod_delay.c' => { 
     2400        DelayEngine => 'off', 
     2401      }, 
     2402    }, 
     2403 
     2404    Limit => { 
     2405      SITE_RMDIR => { 
     2406        DenyAll => '', 
     2407      }, 
     2408    }, 
     2409  }; 
     2410 
     2411  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     2412 
     2413  # Open pipes, for use between the parent and child processes.  Specifically, 
     2414  # the child will indicate when it's done with its test by writing a message 
     2415  # to the parent. 
     2416  my ($rfh, $wfh); 
     2417  unless (pipe($rfh, $wfh)) { 
     2418    die("Can't open pipe: $!"); 
     2419  } 
     2420 
     2421  my $ex; 
     2422 
     2423  # Fork child 
     2424  $self->handle_sigchld(); 
     2425  defined(my $pid = fork()) or die("Can't fork: $!"); 
     2426  if ($pid) { 
     2427    eval { 
     2428      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     2429      $client->login($user, $passwd); 
     2430 
     2431      my $path = 'foo'; 
     2432 
     2433      eval { $client->site('RMDIR', $path) }; 
     2434      unless ($@) { 
     2435        die("SITE RMDIR succeeded unexpectedly"); 
     2436      } 
     2437 
     2438      my $resp_code = $client->response_code(); 
     2439      my $resp_msg = $client->response_msg(); 
     2440 
     2441      my $expected; 
     2442 
     2443      $expected = 550; 
     2444      $self->assert($expected == $resp_code, 
     2445        test_msg("Expected $expected, got $resp_code")); 
     2446 
     2447      $expected = "RMDIR $path: Operation not permitted"; 
     2448      $self->assert($expected eq $resp_msg, 
     2449        test_msg("Expected '$expected', got '$resp_msg'")); 
     2450 
     2451      # Make sure that the test file is NOT gone, along with all of the 
     2452      # test dirs. 
     2453      unless (-f $test_file) { 
     2454        die("File $test_file does not exist as expected"); 
     2455      } 
     2456 
     2457      foreach my $test_dir (@$test_dirs) { 
     2458        unless (-d $test_dir) { 
     2459          die("Directory $test_dir does not exist as expected"); 
     2460        } 
     2461      } 
     2462    }; 
     2463 
     2464    if ($@) { 
     2465      $ex = $@; 
     2466    } 
     2467 
     2468    $wfh->print("done\n"); 
     2469    $wfh->flush(); 
     2470 
     2471  } else { 
     2472    eval { server_wait($config_file, $rfh) }; 
     2473    if ($@) { 
     2474      warn($@); 
     2475      exit 1; 
     2476    } 
     2477 
     2478    exit 0; 
     2479  } 
     2480 
     2481  # Stop server 
     2482  server_stop($pid_file); 
     2483 
     2484  $self->assert_child_ok($pid); 
     2485 
     2486  if ($ex) { 
     2487    die($ex); 
     2488  } 
     2489 
     2490  unlink($log_file); 
     2491} 
     2492 
     2493sub site_misc_symlink_failed_limit { 
     2494  my $self = shift; 
     2495  my $tmpdir = $self->{tmpdir}; 
     2496 
     2497  my $config_file = "$tmpdir/site.conf"; 
     2498  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     2499  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     2500 
     2501  my $log_file = File::Spec->rel2abs('tests.log'); 
     2502 
     2503  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     2504  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     2505 
     2506  my $user = 'proftpd'; 
     2507  my $passwd = 'test'; 
     2508  my $home_dir = File::Spec->rel2abs($tmpdir); 
     2509  my $uid = 500; 
     2510  my $gid = 500; 
     2511 
     2512  my $test_symlink = File::Spec->rel2abs("$tmpdir/foo"); 
     2513 
     2514  # Make sure that, if we're running as root, that the home directory has 
     2515  # permissions/privs set for the account we create 
     2516  if ($< == 0) { 
     2517    unless (chmod(0755, $home_dir)) { 
     2518      die("Can't set perms on $home_dir to 0755: $!"); 
     2519    } 
     2520 
     2521    unless (chown($uid, $gid, $home_dir)) { 
     2522      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     2523    } 
     2524  } 
     2525 
     2526  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     2527    '/bin/bash'); 
     2528  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     2529 
     2530  my $config = { 
     2531    PidFile => $pid_file, 
     2532    ScoreboardFile => $scoreboard_file, 
     2533    SystemLog => $log_file, 
     2534 
     2535    AuthUserFile => $auth_user_file, 
     2536    AuthGroupFile => $auth_group_file, 
     2537 
     2538    IfModules => { 
     2539      'mod_delay.c' => { 
     2540        DelayEngine => 'off', 
     2541      }, 
     2542    }, 
     2543 
     2544    Limit => { 
     2545      SITE_SYMLINK => { 
     2546        DenyAll => '', 
     2547      }, 
     2548    }, 
     2549  }; 
     2550 
     2551  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     2552 
     2553  # Open pipes, for use between the parent and child processes.  Specifically, 
     2554  # the child will indicate when it's done with its test by writing a message 
     2555  # to the parent. 
     2556  my ($rfh, $wfh); 
     2557  unless (pipe($rfh, $wfh)) { 
     2558    die("Can't open pipe: $!"); 
     2559  } 
     2560 
     2561  my $ex; 
     2562 
     2563  # Fork child 
     2564  $self->handle_sigchld(); 
     2565  defined(my $pid = fork()) or die("Can't fork: $!"); 
     2566  if ($pid) { 
     2567    eval { 
     2568      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     2569      $client->login($user, $passwd); 
     2570 
     2571      my $src = 'site.conf'; 
     2572      my $dst = 'foo'; 
     2573 
     2574      eval { $client->site('SYMLINK', $src, $dst) }; 
     2575      unless ($@) { 
     2576        die("SITE SYMLINK succeeded unexpectedly"); 
     2577      } 
     2578 
     2579      my $resp_code = $client->response_code(); 
     2580      my $resp_msg = $client->response_msg(); 
     2581 
     2582      my $expected; 
     2583 
     2584      $expected = 550; 
     2585      $self->assert($expected == $resp_code, 
     2586        test_msg("Expected $expected, got $resp_code")); 
     2587 
     2588      $expected = "$src: Operation not permitted"; 
     2589      $self->assert($expected eq $resp_msg, 
     2590        test_msg("Expected '$expected', got '$resp_msg'")); 
     2591 
     2592      if (-l $test_symlink) { 
     2593        die("Symlink $test_symlink exists unexpectedly"); 
     2594      } 
     2595    }; 
     2596 
     2597    if ($@) { 
     2598      $ex = $@; 
     2599    } 
     2600 
     2601    $wfh->print("done\n"); 
     2602    $wfh->flush(); 
     2603 
     2604  } else { 
     2605    eval { server_wait($config_file, $rfh) }; 
     2606    if ($@) { 
     2607      warn($@); 
     2608      exit 1; 
     2609    } 
     2610 
     2611    exit 0; 
     2612  } 
     2613 
     2614  # Stop server 
     2615  server_stop($pid_file); 
     2616 
     2617  $self->assert_child_ok($pid); 
     2618 
     2619  if ($ex) { 
     2620    die($ex); 
     2621  } 
     2622 
     2623  unlink($log_file); 
     2624} 
     2625 
     2626sub site_misc_utime_failed_limit { 
     2627  my $self = shift; 
     2628  my $tmpdir = $self->{tmpdir}; 
     2629 
     2630  my $config_file = "$tmpdir/site.conf"; 
     2631  my $pid_file = File::Spec->rel2abs("$tmpdir/site.pid"); 
     2632  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/site.scoreboard"); 
     2633 
     2634  my $log_file = File::Spec->rel2abs('tests.log'); 
     2635 
     2636  my $auth_user_file = File::Spec->rel2abs("$tmpdir/site.passwd"); 
     2637  my $auth_group_file = File::Spec->rel2abs("$tmpdir/site.group"); 
     2638 
     2639  my $user = 'proftpd'; 
     2640  my $passwd = 'test'; 
     2641  my $home_dir = File::Spec->rel2abs($tmpdir); 
     2642  my $uid = 500; 
     2643  my $gid = 500; 
     2644 
     2645  # Make sure that, if we're running as root, that the home directory has 
     2646  # permissions/privs set for the account we create 
     2647  if ($< == 0) { 
     2648    unless (chmod(0755, $home_dir)) { 
     2649      die("Can't set perms on $home_dir to 0755: $!"); 
     2650    } 
     2651 
     2652    unless (chown($uid, $gid, $home_dir)) { 
     2653      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     2654    } 
     2655  } 
     2656 
     2657  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     2658    '/bin/bash'); 
     2659  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     2660 
     2661  my $config = { 
     2662    PidFile => $pid_file, 
     2663    ScoreboardFile => $scoreboard_file, 
     2664    SystemLog => $log_file, 
     2665 
     2666    AuthUserFile => $auth_user_file, 
     2667    AuthGroupFile => $auth_group_file, 
     2668 
     2669    IfModules => { 
     2670      'mod_delay.c' => { 
     2671        DelayEngine => 'off', 
     2672      }, 
     2673    }, 
     2674 
     2675    Limit => { 
     2676      SITE_UTIME => { 
     2677        DenyAll => '', 
     2678      }, 
     2679    }, 
     2680  }; 
     2681 
     2682  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     2683 
     2684  # Open pipes, for use between the parent and child processes.  Specifically, 
     2685  # the child will indicate when it's done with its test by writing a message 
     2686  # to the parent. 
     2687  my ($rfh, $wfh); 
     2688  unless (pipe($rfh, $wfh)) { 
     2689    die("Can't open pipe: $!"); 
     2690  } 
     2691 
     2692  my $ex; 
     2693 
     2694  # Fork child 
     2695  $self->handle_sigchld(); 
     2696  defined(my $pid = fork()) or die("Can't fork: $!"); 
     2697  if ($pid) { 
     2698    eval { 
     2699      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     2700      $client->login($user, $passwd); 
     2701 
     2702      my $timestamp = '200002240826'; 
     2703      my $path = 'site.conf'; 
     2704 
     2705      eval { $client->site('UTIME', $timestamp, $path) }; 
     2706      unless ($@) { 
     2707        die("SITE UTIME succeeded unexpectedly"); 
     2708      } 
     2709 
     2710      my $resp_code = $client->response_code(); 
     2711      my $resp_msg = $client->response_msg(); 
     2712 
     2713      my $expected; 
     2714 
     2715      $expected = 550; 
     2716      $self->assert($expected == $resp_code, 
     2717        test_msg("Expected $expected, got $resp_code")); 
     2718 
     2719      $expected = "UTIME $timestamp $path: Operation not permitted"; 
     2720      $self->assert($expected eq $resp_msg, 
     2721        test_msg("Expected '$expected', got '$resp_msg'")); 
     2722    }; 
     2723 
     2724    if ($@) { 
     2725      $ex = $@; 
     2726    } 
     2727 
     2728    $wfh->print("done\n"); 
     2729    $wfh->flush(); 
     2730 
     2731  } else { 
     2732    eval { server_wait($config_file, $rfh) }; 
     2733    if ($@) { 
     2734      warn($@); 
     2735      exit 1; 
     2736    } 
     2737 
     2738    exit 0; 
     2739  } 
     2740 
     2741  # Stop server 
     2742  server_stop($pid_file); 
     2743 
     2744  $self->assert_child_ok($pid); 
     2745 
     2746  if ($ex) { 
     2747    die($ex); 
     2748  } 
     2749 
     2750  unlink($log_file); 
     2751} 
     2752 
    99927531; 
Note: See TracChangeset for help on using the changeset viewer.