1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595
|
/*
* ProFTPD - FTP server daemon
* Copyright (c) 1997, 1998 Public Flood Software
* Copyright (c) 1999, 2000 MacGyver aka Habeeb J. Dihu <macgyver@tos.net>
* Copyright (c) 2001-2005 The ProFTPD Project team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu
* and other respective copyright holders give permission to link this program
* with OpenSSL, and distribute the resulting executable, without including
* the source code for OpenSSL in the source distribution.
*/
/* Data transfer module for ProFTPD
*
* $Id: mod_xfer.c,v 1.194 2006/03/15 03:56:23 castaglia Exp $
*/
#include "conf.h"
#include "privs.h"
#include <signal.h>
#ifdef HAVE_SYS_SENDFILE_H
#include <sys/sendfile.h>
#endif
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
extern module auth_module;
extern pid_t mpid;
/* Variables for this module */
static pr_fh_t *retr_fh = NULL;
static pr_fh_t *stor_fh = NULL;
static unsigned char have_prot = FALSE;
static unsigned char use_sendfile = TRUE;
/* Transfer rate variables */
static long double xfer_rate_kbps = 0.0, xfer_rate_bps = 0.0;
static off_t xfer_rate_freebytes = 0.0;
static unsigned char have_xfer_rate = FALSE;
static unsigned int xfer_rate_scoreboard_updates = 0;
/* Transfer rate functions */
static void xfer_rate_lookup(cmd_rec *);
static unsigned char xfer_rate_parse_cmdlist(config_rec *, char *);
static void xfer_rate_sigmask(unsigned char);
static void xfer_rate_throttle(off_t, unsigned int);
module xfer_module;
static int xfer_errno;
static unsigned long find_max_nbytes(char *directive) {
config_rec *c = NULL;
unsigned int ctxt_precedence = 0;
unsigned char have_user_limit, have_group_limit, have_class_limit,
have_all_limit;
unsigned long max_nbytes = 0UL;
have_user_limit = have_group_limit = have_class_limit =
have_all_limit = FALSE;
c = find_config(CURRENT_CONF, CONF_PARAM, directive, FALSE);
while (c) {
/* This check is for more than three arguments: one argument is the
* classifier (i.e. "user", "group", or "class"), one argument is
* the precedence, one is the number of bytes; the remaining arguments
* are the individual items in the configured expression.
*/
if (c->argc > 3) {
if (strcmp(c->argv[2], "user") == 0) {
if (pr_expr_eval_user_or((char **) &c->argv[3])) {
if (*((unsigned int *) c->argv[1]) > ctxt_precedence) {
/* Set the context precedence */
ctxt_precedence = *((unsigned int *) c->argv[1]);
max_nbytes = *((unsigned long *) c->argv[0]);
have_group_limit = have_class_limit = have_all_limit = FALSE;
have_user_limit = TRUE;
}
}
} else if (strcmp(c->argv[2], "group") == 0) {
if (pr_expr_eval_group_or((char **) &c->argv[3])) {
if (*((unsigned int *) c->argv[1]) > ctxt_precedence) {
/* Set the context precedence */
ctxt_precedence = *((unsigned int *) c->argv[1]);
max_nbytes = *((unsigned long *) c->argv[0]);
have_user_limit = have_class_limit = have_all_limit = FALSE;
have_group_limit = TRUE;
}
}
} else if (strcmp(c->argv[2], "class") == 0) {
if (pr_expr_eval_class_or((char **) &c->argv[3])) {
if (*((unsigned int *) c->argv[1]) > ctxt_precedence) {
/* Set the context precedence */
ctxt_precedence = *((unsigned int *) c->argv[1]);
max_nbytes = *((unsigned long *) c->argv[0]);
have_user_limit = have_group_limit = have_all_limit = FALSE;
have_class_limit = TRUE;
}
}
}
} else {
if (*((unsigned int *) c->argv[1]) > ctxt_precedence) {
/* Set the context precedence. */
ctxt_precedence = *((unsigned int *) c->argv[1]);
max_nbytes = *((unsigned long *) c->argv[0]);
have_user_limit = have_group_limit = have_class_limit = FALSE;
have_all_limit = TRUE;
}
}
c = find_config_next(c, c->next, CONF_PARAM, directive, FALSE);
}
/* Print out some nice debugging information. */
if (max_nbytes > 0UL &&
(have_user_limit || have_group_limit ||
have_class_limit || have_all_limit)) {
pr_log_debug(DEBUG5, "%s (%lu bytes) in effect for %s",
directive, max_nbytes,
have_user_limit ? "user " : have_group_limit ? "group " :
have_class_limit ? "class " : "all");
}
return max_nbytes;
}
static unsigned long parse_max_nbytes(char *nbytes_str, char *units_str) {
long res;
unsigned long nbytes;
char *endp = NULL;
float units_factor = 0.0;
/* clear any previous local errors */
xfer_errno = 0;
/* first, check the given units to determine the correct mulitplier
*/
if (!strcasecmp("Gb", units_str)) {
units_factor = 1024.0 * 1024.0 * 1024.0;
} else if (!strcasecmp("Mb", units_str)) {
units_factor = 1024.0 * 1024.0;
} else if (!strcasecmp("Kb", units_str)) {
units_factor = 1024.0;
} else if (!strcasecmp("b", units_str)) {
units_factor = 1.0;
} else {
xfer_errno = EINVAL;
return 0;
}
/* make sure a number was given */
if (!isdigit((int) *nbytes_str)) {
xfer_errno = EINVAL;
return 0;
}
/* knowing the factor, now convert the given number string to a real
* number
*/
res = strtol(nbytes_str, &endp, 10);
if (errno == ERANGE) {
xfer_errno = ERANGE;
return 0;
}
if (endp && *endp) {
xfer_errno = EINVAL;
return 0;
}
/* don't bother to apply the factor if that will cause the number to
* overflow
*/
if (res > (ULONG_MAX / units_factor)) {
xfer_errno = ERANGE;
return 0;
}
nbytes = (unsigned long) res * units_factor;
return nbytes;
}
static void _log_transfer(char direction, char abort_flag) {
struct timeval end_time;
char *fullpath = NULL;
memset(&end_time, '\0', sizeof(end_time));
if (session.xfer.start_time.tv_sec != 0) {
gettimeofday(&end_time, NULL);
end_time.tv_sec -= session.xfer.start_time.tv_sec;
if (end_time.tv_usec >= session.xfer.start_time.tv_usec)
end_time.tv_usec -= session.xfer.start_time.tv_usec;
else {
end_time.tv_usec = 1000000L - (session.xfer.start_time.tv_usec -
end_time.tv_usec);
end_time.tv_sec--;
}
}
fullpath = dir_abs_path(session.xfer.p, session.xfer.path, TRUE);
if ((session.sf_flags & SF_ANON) != 0) {
xferlog_write(end_time.tv_sec, pr_netaddr_get_sess_remote_name(),
session.xfer.total_bytes, fullpath,
(session.sf_flags & SF_ASCII ? 'a' : 'b'), direction,
'a', session.anon_user, abort_flag);
} else {
xferlog_write(end_time.tv_sec, pr_netaddr_get_sess_remote_name(),
session.xfer.total_bytes, fullpath,
(session.sf_flags & SF_ASCII ? 'a' : 'b'), direction,
'r', session.user, abort_flag);
}
pr_log_debug(DEBUG1, "Transfer %s %" PR_LU " bytes in %ld.%02lu seconds",
abort_flag == 'c' ? "completed:" : "aborted after",
(pr_off_t) session.xfer.total_bytes, (long) end_time.tv_sec,
(unsigned long)(end_time.tv_usec / 10000));
}
/* Code borrowed from src/dirtree.c's get_word() -- modified to separate
* words on commas as well as spaces.
*/
static char *get_cmd_from_list(char **list) {
char *res = NULL, *dst = NULL;
unsigned char quote_mode = FALSE;
while (**list && isspace((int) **list))
(*list)++;
if (!**list)
return NULL;
res = dst = *list;
if (**list == '\"') {
quote_mode = TRUE;
(*list)++;
}
while (**list && **list != ',' &&
(quote_mode ? (**list != '\"') : (!isspace((int) **list)))) {
if (**list == '\\' && quote_mode) {
/* escaped char */
if (*((*list) + 1))
*dst = *(++(*list));
}
*dst++ = **list;
++(*list);
}
if (**list)
(*list)++;
*dst = '\0';
return res;
}
static void xfer_rate_lookup(cmd_rec *cmd) {
config_rec *c = NULL;
char *xfer_cmd = NULL;
unsigned char have_user_rate = FALSE, have_group_rate = FALSE,
have_class_rate = FALSE, have_all_rate = FALSE;
unsigned int precedence = 0;
/* Make sure the variables are (re)initialized */
xfer_rate_kbps = xfer_rate_bps = 0.0;
xfer_rate_freebytes = 0;
xfer_rate_scoreboard_updates = 0;
have_xfer_rate = FALSE;
c = find_config(CURRENT_CONF, CONF_PARAM, "TransferRate", FALSE);
/* Note: need to cycle through all the matching config_recs, and using
* the information from the current config_rec only if it matches
* the target *and* has a higher precedence than any of the previously
* found config_recs.
*/
while (c) {
char **cmdlist = (char **) c->argv[0];
unsigned char matched_cmd = FALSE;
/* Does this TransferRate apply to the current command? Note: this
* could be made more efficient by using bitmasks rather than string
* comparisons.
*/
for (xfer_cmd = *cmdlist; xfer_cmd; xfer_cmd = *(cmdlist++)) {
if (!strcasecmp(xfer_cmd, cmd->argv[0])) {
matched_cmd = TRUE;
break;
}
}
/* No -- continue on to the next TransferRate. */
if (!matched_cmd) {
c = find_config_next(c, c->next, CONF_PARAM, "TransferRate", FALSE);
continue;
}
if (c->argc > 4) {
if (strcmp(c->argv[4], "user") == 0) {
if (pr_expr_eval_user_or((char **) &c->argv[5]) &&
*((unsigned int *) c->argv[3]) > precedence) {
/* Set the precedence. */
precedence = *((unsigned int *) c->argv[3]);
xfer_rate_kbps = *((long double *) c->argv[1]);
xfer_rate_freebytes = *((off_t *) c->argv[2]);
have_xfer_rate = TRUE;
have_user_rate = TRUE;
have_group_rate = have_class_rate = have_all_rate = FALSE;
}
} else if (strcmp(c->argv[4], "group") == 0) {
if (pr_expr_eval_group_and((char **) &c->argv[5]) &&
*((unsigned int *) c->argv[3]) > precedence) {
/* Set the precedence. */
precedence = *((unsigned int *) c->argv[3]);
xfer_rate_kbps = *((long double *) c->argv[1]);
xfer_rate_freebytes = *((off_t *) c->argv[2]);
have_xfer_rate = TRUE;
have_group_rate = TRUE;
have_user_rate = have_class_rate = have_all_rate = FALSE;
}
} else if (strcmp(c->argv[4], "class") == 0) {
if (pr_expr_eval_class_or((char **) &c->argv[5]) &&
*((unsigned int *) c->argv[3]) > precedence) {
/* Set the precedence. */
precedence = *((unsigned int *) c->argv[3]);
xfer_rate_kbps = *((long double *) c->argv[1]);
xfer_rate_freebytes = *((off_t *) c->argv[2]);
have_xfer_rate = TRUE;
have_class_rate = TRUE;
have_user_rate = have_group_rate = have_all_rate = FALSE;
}
}
} else {
if (*((unsigned int *) c->argv[3]) > precedence) {
/* Set the precedence. */
precedence = *((unsigned int *) c->argv[3]);
xfer_rate_kbps = *((long double *) c->argv[1]);
xfer_rate_freebytes = *((off_t *) c->argv[2]);
have_xfer_rate = TRUE;
have_all_rate = TRUE;
have_user_rate = have_group_rate = have_class_rate = FALSE;
}
}
c = find_config_next(c, c->next, CONF_PARAM, "TransferRate", FALSE);
}
/* Print out a helpful debugging message. */
if (have_xfer_rate) {
pr_log_debug(DEBUG3, "TransferRate (%.3Lf KB/s, %" PR_LU
" bytes free) in effect%s", xfer_rate_kbps,
(pr_off_t) xfer_rate_freebytes,
have_user_rate ? " for current user" :
have_group_rate ? " for current group" :
have_class_rate ? " for current class" : "");
/* Convert the configured Kbps to bytes per usec, for use later.
* The 1024.0 factor converts for Kbytes to bytes, and the
* 1000000.0 factor converts from secs to usecs.
*/
xfer_rate_bps = xfer_rate_kbps * 1024.0;
}
}
static unsigned char xfer_rate_parse_cmdlist(config_rec *c, char *cmdlist) {
char *cmd = NULL;
array_header *cmds = NULL;
/* Allocate an array_header. */
cmds = make_array(c->pool, 0, sizeof(char *));
/* Add each command to the array, checking for invalid commands or
* duplicates.
*/
while ((cmd = get_cmd_from_list(&cmdlist)) != NULL) {
/* Is the given command a valid one for this directive? */
if (strcasecmp(cmd, C_APPE) && strcasecmp(cmd, C_RETR) &&
strcasecmp(cmd, C_STOR) && strcasecmp(cmd, C_STOU)) {
pr_log_debug(DEBUG0, "invalid TransferRate command: %s", cmd);
return FALSE;
}
*((char **) push_array(cmds)) = pstrdup(c->pool, cmd);
}
/* Terminate the array with a NULL. */
*((char **) push_array(cmds)) = NULL;
/* Store the array of commands in the config_rec. */
c->argv[0] = (void *) cmds->elts;
return TRUE;
}
/* Very similar to the {block,unblock}_signals() function, this masks most
* of the same signals -- except for TERM. This allows a throttling process
* to be killed by the admin.
*/
static void xfer_rate_sigmask(unsigned char block) {
static sigset_t sig_set;
if (block) {
sigemptyset(&sig_set);
sigaddset(&sig_set, SIGCHLD);
sigaddset(&sig_set, SIGUSR1);
sigaddset(&sig_set, SIGINT);
sigaddset(&sig_set, SIGQUIT);
sigaddset(&sig_set, SIGURG);
#ifdef SIGIO
sigaddset(&sig_set, SIGIO);
#endif /* SIGIO */
#ifdef SIGBUS
sigaddset(&sig_set, SIGBUS);
#endif /* SIGBUS */
sigaddset(&sig_set, SIGHUP);
while (sigprocmask(SIG_BLOCK, &sig_set, NULL) < 0) {
if (errno == EINTR) {
pr_signals_handle();
continue;
}
break;
}
} else {
while (sigprocmask(SIG_UNBLOCK, &sig_set, NULL) < 0) {
if (errno == EINTR) {
pr_signals_handle();
continue;
}
break;
}
}
}
/* Returns the difference, in milliseconds, between the given timeval and
* now.
*/
static long xfer_rate_since(struct timeval *then) {
struct timeval now;
gettimeofday(&now, NULL);
return (((now.tv_sec - then->tv_sec) * 1000L) +
((now.tv_usec - then->tv_usec) / 1000L));
}
static void xfer_rate_throttle(off_t xferlen, unsigned int xfer_ending) {
long ideal = 0, elapsed = 0;
off_t orig_xferlen = xferlen;
/* Calculate the time interval since the transfer of data started. */
elapsed = xfer_rate_since(&session.xfer.start_time);
/* Perform no throttling if no throttling has been configured. */
if (!have_xfer_rate) {
xfer_rate_scoreboard_updates++;
if (xfer_ending ||
xfer_rate_scoreboard_updates % PR_TUNABLE_XFER_SCOREBOARD_UPDATES == 0) {
/* Update the scoreboard. */
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_LEN, orig_xferlen,
PR_SCORE_XFER_ELAPSED, (unsigned long) elapsed,
NULL);
xfer_rate_scoreboard_updates = 0;
}
return;
}
/* Give credit for any configured freebytes. */
if (xferlen && xfer_rate_freebytes) {
if (xferlen > xfer_rate_freebytes)
/* Decrement the number of bytes transferred by the freebytes, so that
* any throttling does not take into account the freebytes.
*/
xferlen -= xfer_rate_freebytes;
else {
xfer_rate_scoreboard_updates++;
/* The number of bytes transferred is less than the freebytes. Just
* update the scoreboard -- no throttling needed.
*/
if (xfer_ending ||
xfer_rate_scoreboard_updates % PR_TUNABLE_XFER_SCOREBOARD_UPDATES == 0) {
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_LEN, orig_xferlen,
PR_SCORE_XFER_ELAPSED, (unsigned long) elapsed,
NULL);
xfer_rate_scoreboard_updates = 0;
}
return;
}
}
ideal = xferlen * 1000L / xfer_rate_bps;
if (ideal > elapsed) {
struct timeval tv;
/* Setup for the select. We use select() instead of usleep() because it
* seems to be far more portable across platforms.
*
* ideal and elapsed are in milleconds, but tv_usec will be microseconds,
* so be sure to convert properly.
*/
tv.tv_usec = (ideal - elapsed) * 1000;
tv.tv_sec = tv.tv_usec / 1000000L;
tv.tv_usec = tv.tv_usec % 1000000L;
pr_log_debug(DEBUG7, "transferring too fast, delaying %ld sec%s, %ld usecs",
(long int) tv.tv_sec, tv.tv_sec == 1 ? "" : "s", (long int) tv.tv_usec);
/* No interruptions, please... */
xfer_rate_sigmask(TRUE);
if (select(0, NULL, NULL, NULL, &tv) < 0)
pr_log_pri(PR_LOG_WARNING, "warning: unable to throttle bandwidth: %s",
strerror(errno));
xfer_rate_sigmask(FALSE);
pr_signals_handle();
/* Update the scoreboard. */
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_LEN, orig_xferlen,
PR_SCORE_XFER_ELAPSED, (unsigned long) ideal,
NULL);
} else {
/* Update the scoreboard. */
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_LEN, orig_xferlen,
PR_SCORE_XFER_ELAPSED, (unsigned long) elapsed,
NULL);
}
return;
}
static int transmit_normal(char *buf, long bufsz) {
long sz = pr_fsio_read(retr_fh, buf, bufsz);
if (sz <= 0)
return 0;
return pr_data_xfer(buf, sz);
}
#ifdef HAVE_SENDFILE
static int transmit_sendfile(off_t count, off_t *offset,
pr_sendfile_t *retval) {
/* We don't use sendfile() if:
* - We're using bandwidth throttling.
* - We're transmitting an ASCII file.
* - We're using RFC2228 data channel protection
* - There's no data left to transmit.
* - UseSendfile is set to off.
*/
if (have_xfer_rate ||
!(session.xfer.file_size - count) ||
(session.sf_flags & (SF_ASCII|SF_ASCII_OVERRIDE)) ||
have_prot ||
!use_sendfile)
return 0;
retry:
*retval = pr_data_sendfile(PR_FH_FD(retr_fh), offset,
session.xfer.file_size - count);
if (*retval == -1) {
switch (errno) {
case EAGAIN:
case EINTR:
/* Interrupted call, or the other side wasn't ready yet. */
pr_signals_handle();
goto retry;
case EPIPE:
case ECONNRESET:
case ETIMEDOUT:
case EHOSTUNREACH:
/* Other side broke the connection. */
break;
#ifdef ENOSYS
case ENOSYS:
#endif /* ENOSYS */
case EINVAL:
/* No sendfile support, apparently. Try it the normal way. */
return 0;
break;
default:
pr_log_pri(PR_LOG_ERR, "transmit_sendfile() error, "
"reverting to normal data transmission: [%d] %s", errno,
strerror(errno));
return 0;
}
}
return 1;
}
#endif /* HAVE_SENDFILE */
/* Note: the count and offset arguments are only for the benefit of
* transmit_sendfile(), if sendfile support is enabled. The transmit_normal()
* function only needs/uses buf and bufsz.
*/
static long transmit_data(off_t count, off_t *offset, char *buf, long bufsz) {
long res;
#ifdef TCP_CORK
int on = 1;
socklen_t len = sizeof(int);
# ifdef SOL_TCP
int tcp_level = SOL_TCP;
# else
int tcp_level = IPPROTO_TCP;
# endif /* SOL_TCP */
#endif /* TCP_CORK */
#ifdef HAVE_SENDFILE
pr_sendfile_t retval;
#endif /* HAVE_SENDFILE */
#ifdef TCP_CORK
/* Note: TCP_CORK is a Linuxism, introduced with the 2.4 kernel. It
* has effects similar to BSD's TCP_NOPUSH option.
*/
if (setsockopt(PR_NETIO_FD(session.d->outstrm), tcp_level, TCP_CORK, &on,
len) < 0)
pr_log_pri(PR_LOG_NOTICE, "error setting TCP_CORK: %s", strerror(errno));
#endif /* TCP_CORK */
#ifdef HAVE_SENDFILE
if (transmit_sendfile(count, offset, &retval) == 0)
res = transmit_normal(buf, bufsz);
else
res = (long) retval;
#else
res = transmit_normal(buf, bufsz);
#endif /* HAVE_SENDFILE */
#ifdef TCP_CORK
on = 0;
if (setsockopt(PR_NETIO_FD(session.d->outstrm), tcp_level, TCP_CORK, &on,
len) < 0)
pr_log_pri(PR_LOG_NOTICE, "error setting TCP_CORK: %s", strerror(errno));
#endif /* TCP_CORK */
return res;
}
static void stor_chown(void) {
struct stat st;
char *xfer_path = NULL;
if (session.xfer.xfer_type == STOR_HIDDEN)
xfer_path = session.xfer.path_hidden;
else
xfer_path = session.xfer.path;
/* session.fsgid defaults to -1, so chown(2) won't chgrp unless specifically
* requested via GroupOwner.
*/
if ((session.fsuid != (uid_t) -1) && xfer_path) {
int err = 0, iserr = 0;
PRIVS_ROOT
if (pr_fsio_chown(xfer_path, session.fsuid, session.fsgid) == -1) {
iserr++;
err = errno;
}
PRIVS_RELINQUISH
if (iserr)
pr_log_pri(PR_LOG_WARNING, "chown(%s) as root failed: %s", xfer_path,
strerror(err));
else {
if (session.fsgid != (gid_t) -1)
pr_log_debug(DEBUG2, "root chown(%s) to uid %lu, gid %lu successful",
xfer_path, (unsigned long) session.fsuid,
(unsigned long) session.fsgid);
else
pr_log_debug(DEBUG2, "root chown(%s) to uid %lu successful", xfer_path,
(unsigned long) session.fsuid);
pr_fs_clear_cache();
pr_fsio_stat(xfer_path, &st);
/* The chmod happens after the chown because chown will remove
* the S{U,G}ID bits on some files (namely, directories); the subsequent
* chmod is used to restore those dropped bits. This makes it
* necessary to use root privs when doing the chmod as well (at least
* in the case of chown'ing the file via root privs) in order to insure
* that the mode can be set (a file might be being "given away", and if
* root privs aren't used, the chmod() will fail because the old owner/
* session user doesn't have the necessary privileges to do so).
*/
iserr = 0;
PRIVS_ROOT
if (pr_fsio_chmod(xfer_path, st.st_mode) < 0)
iserr++;
PRIVS_RELINQUISH
if (iserr)
pr_log_debug(DEBUG0, "root chmod(%s) to %04o failed: %s", xfer_path,
(unsigned int) st.st_mode, strerror(errno));
else
pr_log_debug(DEBUG2, "root chmod(%s) to %04o successful", xfer_path,
(unsigned int) st.st_mode);
}
} else if ((session.fsgid != (gid_t) -1) && xfer_path) {
if (pr_fsio_chown(xfer_path, (uid_t) -1, session.fsgid) == -1)
pr_log_pri(PR_LOG_WARNING, "chown(%s) failed: %s", xfer_path,
strerror(errno));
else {
pr_log_debug(DEBUG2, "chown(%s) to gid %lu successful", xfer_path,
(unsigned long) session.fsgid);
pr_fs_clear_cache();
pr_fsio_stat(xfer_path, &st);
if (pr_fsio_chmod(xfer_path, st.st_mode) < 0)
pr_log_debug(DEBUG0, "chmod(%s) to %04o failed: %s", xfer_path,
(unsigned int) st.st_mode, strerror(errno));
}
}
}
static void retr_abort(void) {
/* Isn't necessary to send anything here, just cleanup */
if (retr_fh) {
pr_fsio_close(retr_fh);
retr_fh = NULL;
}
_log_transfer('o', 'i');
}
static void retr_complete(void) {
pr_fsio_close(retr_fh);
retr_fh = NULL;
}
static void stor_abort(void) {
unsigned char *delete_stores = NULL;
if (stor_fh) {
if (pr_fsio_close(stor_fh) != 0)
pr_log_pri(PR_LOG_NOTICE, "notice: error closing '%s': %s",
stor_fh->fh_path, strerror(errno));
stor_fh = NULL;
}
if (session.xfer.xfer_type == STOR_HIDDEN) {
/* If hidden stor aborted, remove only hidden file, not real one */
if (session.xfer.path_hidden)
pr_fsio_unlink(session.xfer.path_hidden);
} else if (session.xfer.path) {
if ((delete_stores = get_param_ptr(CURRENT_CONF, "DeleteAbortedStores",
FALSE)) != NULL && *delete_stores == TRUE)
pr_fsio_unlink(session.xfer.path);
}
_log_transfer('i', 'i');
}
static int stor_complete(void) {
int res = 0;
if (pr_fsio_close(stor_fh) != 0) {
pr_log_pri(PR_LOG_NOTICE, "notice: error closing '%s': %s",
stor_fh->fh_path, strerror(errno));
res = -1;
}
stor_fh = NULL;
return res;
}
static int get_hidden_store_path(cmd_rec *cmd, char *path) {
char *c = NULL, *hidden_path;
int dotcount = 0, foundslash = 0, basenamestart = 0, maxlen;
/* We have to also figure out the temporary hidden file name for receiving
* this transfer. Length is +5 due to .in. prepended and "." at end.
*/
/* Figure out where the basename starts */
for (c = path; *c; ++c) {
if (*c == '/') {
foundslash = 1;
basenamestart = dotcount = 0;
} else if (*c == '.') {
++dotcount;
/* Keep track of leading dots, ... is normal, . and .. are special.
* So if we exceed ".." it becomes a normal file. Retroactively consider
* this the possible start of the basename.
*/
if ((dotcount > 2) &&
!basenamestart)
basenamestart = ((unsigned long) c - (unsigned long) path) - dotcount;
} else {
/* We found a nonslash, nondot character; if this is the first time
* we found one since the last slash, remember this as the possible
* start of the basename.
*/
if (!basenamestart)
basenamestart = ((unsigned long) c - (unsigned long) path) - dotcount;
}
}
if (!basenamestart) {
/* This probably shouldn't happen */
pr_response_add_err(R_451, "%s: Bad file name", path);
return -1;
}
/* Add five for the ".in." and "." characters, plus one for a terminating
* NUL.
*/
maxlen = strlen(path) + 6;
if (maxlen > PR_TUNABLE_PATH_MAX) {
/* This probably shouldn't happen */
pr_response_add_err(R_451, "%s: File name too long", path);
return -1;
}
if (pr_table_add(cmd->notes, "mod_xfer.store-hidden-path", NULL, 0) < 0)
pr_log_pri(PR_LOG_NOTICE,
"notice: error adding 'mod_xfer.store-hidden-path': %s",
strerror(errno));
if (!foundslash) {
/* Simple local file name */
hidden_path = pstrcat(cmd->tmp_pool, ".in.", path, ".", NULL);
pr_log_pri(PR_LOG_DEBUG, "HiddenStore: local path, will rename %s to %s",
hidden_path, path);
} else {
/* Complex relative path or absolute path */
hidden_path = pstrndup(cmd->pool, path, maxlen);
hidden_path[basenamestart] = '\0';
hidden_path = pstrcat(cmd->pool, hidden_path, ".in.",
path + basenamestart, ".", NULL);
pr_log_pri(PR_LOG_DEBUG, "HiddenStore: complex path, will rename %s to %s",
hidden_path, path);
}
if (file_mode(hidden_path)) {
pr_log_debug(DEBUG3, "HiddenStore path '%s' already exists",
hidden_path);
pr_response_add_err(R_550, "%s: Temporary hidden file %s already exists",
cmd->arg, hidden_path);
return -1;
}
if (pr_table_set(cmd->notes, "mod_xfer.store-hidden-path",
hidden_path, 0) < 0)
pr_log_pri(PR_LOG_NOTICE,
"notice: error setting 'mod_xfer.store-hidden-path': %s",
strerror(errno));
session.xfer.xfer_type = STOR_HIDDEN;
return 0;
}
MODRET xfer_post_prot(cmd_rec *cmd) {
CHECK_CMD_ARGS(cmd, 2);
if (strcmp(cmd->argv[1], "C") != 0)
have_prot = TRUE;
else
have_prot = FALSE;
return DECLINED(cmd);
}
/* This is a PRE_CMD handler that checks security, etc, and places the full
* filename to receive in cmd->notes, under the key 'mod_xfer.store-path'.
* Note that we CANNOT use cmd->tmp_pool for this, as tmp_pool only lasts for
* the duration of this function.
*/
MODRET xfer_pre_stor(cmd_rec *cmd) {
char *dir;
mode_t fmode;
unsigned char *hidden_stores = NULL, *allow_overwrite = NULL,
*allow_restart = NULL;
if (cmd->argc < 2) {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
dir = dir_best_path(cmd->tmp_pool, cmd->arg);
if (!dir || !dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, dir, NULL)) {
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
fmode = file_mode(dir);
allow_overwrite = get_param_ptr(CURRENT_CONF, "AllowOverwrite", FALSE);
if (fmode && (session.xfer.xfer_type != STOR_APPEND) &&
(!allow_overwrite || *allow_overwrite == FALSE)) {
pr_log_debug(DEBUG6, "AllowOverwrite denied permission for %s", cmd->arg);
pr_response_add_err(R_550, "%s: Overwrite permission denied", cmd->arg);
return ERROR(cmd);
}
if (fmode && !S_ISREG(fmode) && !S_ISFIFO(fmode)) {
pr_response_add_err(R_550, "%s: Not a regular file", cmd->arg);
return ERROR(cmd);
}
/* If restarting, check permissions on this directory, if
* AllowStoreRestart is set, permit it
*/
allow_restart = get_param_ptr(CURRENT_CONF, "AllowStoreRestart", FALSE);
if (fmode &&
(session.restart_pos || (session.xfer.xfer_type == STOR_APPEND)) &&
(!allow_restart || *allow_restart == FALSE)) {
pr_response_add_err(R_451, "%s: Append/Restart not permitted, try again",
cmd->arg);
session.restart_pos = 0L;
session.xfer.xfer_type = STOR_DEFAULT;
return ERROR(cmd);
}
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.store-path",
pstrdup(cmd->pool, dir), 0) < 0)
pr_log_pri(PR_LOG_NOTICE, "notice: error adding 'mod_xfer.store-path': %s",
strerror(errno));
if ((hidden_stores = get_param_ptr(CURRENT_CONF, "HiddenStores",
FALSE)) != NULL && *hidden_stores == TRUE) {
if (get_hidden_store_path(cmd, dir) < 0)
return ERROR(cmd);
}
return HANDLED(cmd);
}
/* xfer_pre_stou() is a PRE_CMD handler that changes the uploaded filename
* to a unique one, after making the requisite security and authorization
* checks.
*/
MODRET xfer_pre_stou(cmd_rec *cmd) {
config_rec *c = NULL;
char *prefix = "ftp", *filename = NULL;
int tmpfd;
mode_t mode;
unsigned char *allow_overwrite = NULL;
/* Some FTP clients are "broken" in that they will send a filename
* along with STOU. Technically this violates RFC959, but for now, just
* ignore that filename. Stupid client implementors.
*/
if (cmd->argc > 2) {
pr_response_add_err(R_500, "'%s' not understood.", get_full_cmd(cmd));
return ERROR(cmd);
}
/* Watch for STOU preceded by REST, which makes no sense.
*
* REST: session.restart_pos > 0
*/
if (session.restart_pos) {
pr_response_add_err(R_550, "STOU incompatible with REST");
return ERROR(cmd);
}
/* Generate the filename to be stored, depending on the configured
* unique filename prefix.
*/
if ((c = find_config(CURRENT_CONF, CONF_PARAM, "StoreUniquePrefix",
FALSE)) != NULL)
prefix = c->argv[0];
/* Now, construct the unique filename using the cmd_rec's pool, the
* prefix, and mkstemp().
*/
filename = pstrcat(cmd->pool, prefix, "XXXXXX", NULL);
tmpfd = mkstemp(filename);
if (tmpfd < 0) {
pr_log_pri(PR_LOG_ERR, "error: unable to use mkstemp(): %s",
strerror(errno));
/* If we can't guarantee a unique filename, refuse the command. */
pr_response_add_err(R_450, "%s: unable to generate unique filename",
cmd->argv[0]);
return ERROR(cmd);
} else {
cmd->arg = filename;
/* Close the unique file. This introduces a small race condition
* between the time this function returns, and the STOU CMD handler
* opens the unique file, but this may have to do, as closing that
* race would involve some major restructuring.
*/
close(tmpfd);
}
/* It's OK to reuse the char * pointer for filename. */
filename = dir_best_path(cmd->tmp_pool, cmd->arg);
if (!filename || !dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group,
filename, NULL)) {
/* Do not forget to delete the file created by mkstemp(3) if there is
* an error.
*/
(void) pr_fsio_unlink(cmd->arg);
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
mode = file_mode(filename);
/* Note: this case should never happen: how one can be appending to
* a supposedly unique filename? Should probably be removed...
*/
allow_overwrite = get_param_ptr(CURRENT_CONF, "AllowOverwrite", FALSE);
if (mode && session.xfer.xfer_type != STOR_APPEND &&
(!allow_overwrite || *allow_overwrite == FALSE)) {
pr_log_debug(DEBUG6, "AllowOverwrite denied permission for %s", cmd->arg);
pr_response_add_err(R_550, "%s: Overwrite permission denied", cmd->arg);
return ERROR(cmd);
}
/* Not likely to _not_ be a regular file, but just to be certain... */
if (mode && !S_ISREG(mode)) {
(void) pr_fsio_unlink(cmd->arg);
pr_response_add_err(R_550, "%s: Not a regular file", cmd->arg);
return ERROR(cmd);
}
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.store-path",
pstrdup(cmd->pool, filename), 0) < 0)
pr_log_pri(PR_LOG_NOTICE, "notice: error adding 'mod_xfer.store-path': %s",
strerror(errno));
session.xfer.xfer_type = STOR_UNIQUE;
return HANDLED(cmd);
}
/* xfer_post_stou() is a POST_CMD handler that changes the mode of the
* STOU file from 0600, which is what mkstemp() makes it, to 0666,
* the default for files uploaded via STOR. This is to prevent users
* from being surprised.
*/
MODRET xfer_post_stou(cmd_rec *cmd) {
/* This is the same mode as used in src/fs.c. Should probably be
* available as a macro.
*/
mode_t mode = 0666;
if (pr_fsio_chmod(cmd->arg, mode) < 0) {
/* Not much to do but log the error. */
pr_log_pri(PR_LOG_ERR, "error: unable to chmod '%s': %s", cmd->arg,
strerror(errno));
}
return HANDLED(cmd);
}
/* xfer_pre_appe() is the PRE_CMD handler for the APPE command, which
* simply sets xfer_type to STOR_APPEND and calls xfer_pre_stor().
*/
MODRET xfer_pre_appe(cmd_rec *cmd) {
session.xfer.xfer_type = STOR_APPEND;
session.restart_pos = 0L;
return xfer_pre_stor(cmd);
}
MODRET xfer_stor(cmd_rec *cmd) {
char *dir;
char *lbuf;
int bufsz,len;
off_t nbytes_stored, nbytes_max_store = 0;
unsigned char have_limit = FALSE;
struct stat st;
off_t curr_pos = 0;
#if defined(HAVE_REGEX_H) && defined(HAVE_REGCOMP)
regex_t *preg;
int ret;
#endif /* REGEX */
/* This function sets static module variables for later throttling */
xfer_rate_lookup(cmd);
session.xfer.path = pr_table_get(cmd->notes, "mod_xfer.store-path", NULL);
session.xfer.path_hidden = pr_table_get(cmd->notes,
"mod_xfer.store-hidden-path", NULL);
dir = session.xfer.path;
#if defined(HAVE_REGEX_H) && defined(HAVE_REGCOMP)
preg = (regex_t *) get_param_ptr(CURRENT_CONF, "PathAllowFilter", FALSE);
if (preg) {
ret = regexec(preg, cmd->arg, 0, NULL, 0);
if (ret != 0) {
pr_log_debug(DEBUG2, "'%s' denied by PathAllowFilter", cmd->arg);
pr_response_add_err(R_550, "%s: Forbidden filename", cmd->arg);
return ERROR(cmd);
} else {
char errmsg[200];
regerror(ret, preg, errmsg, sizeof(errmsg));
pr_log_debug(DEBUG8, "'%s' allowed by PathAllowFilter (%s)", cmd->arg,
errmsg);
}
}
preg = (regex_t *) get_param_ptr(CURRENT_CONF, "PathDenyFilter", FALSE);
if (preg) {
ret = regexec(preg, cmd->arg, 0, NULL, 0);
if (ret == 0) {
pr_log_debug(DEBUG2, "'%s' denied by PathDenyFilter", cmd->arg);
pr_response_add_err(R_550, "%s: Forbidden filename", cmd->arg);
return ERROR(cmd);
} else {
char errmsg[200];
regerror(ret, preg, errmsg, sizeof(errmsg));
pr_log_debug(DEBUG8, "'%s' allowed by PathDenyFilter (%s)", cmd->arg,
errmsg);
}
}
#endif /* REGEX */
/* Make sure the proper current working directory is set in the FSIO
* layer, so that the proper FS can be used for the open().
*/
pr_fs_setcwd(pr_fs_getcwd());
if (session.xfer.xfer_type == STOR_HIDDEN)
stor_fh = pr_fsio_open(session.xfer.path_hidden,
O_WRONLY|(session.restart_pos ? 0 : O_CREAT|O_EXCL));
else if (session.xfer.xfer_type == STOR_APPEND) {
stor_fh = pr_fsio_open(session.xfer.path, O_CREAT|O_WRONLY);
if (stor_fh)
if (pr_fsio_lseek(stor_fh, 0, SEEK_END) == (off_t) -1) {
(void) pr_fsio_close(stor_fh);
stor_fh = NULL;
}
}
else /* Normal session */
stor_fh = pr_fsio_open(dir,
O_WRONLY|(session.restart_pos ? 0 : O_TRUNC|O_CREAT));
if (stor_fh && session.restart_pos) {
int xerrno = 0;
if (pr_fsio_lseek(stor_fh, session.restart_pos, SEEK_SET) == -1)
xerrno = errno;
else if (pr_fsio_stat(dir, &st) == -1)
xerrno = errno;
if (xerrno) {
(void) pr_fsio_close(stor_fh);
errno = xerrno;
stor_fh = NULL;
}
/* Make sure that the requested offset is valid (within the size of the
* file being resumed.
*/
if (stor_fh && session.restart_pos > st.st_size) {
pr_response_add_err(R_554, "%s: invalid REST argument", cmd->arg);
(void) pr_fsio_close(stor_fh);
stor_fh = NULL;
return ERROR(cmd);
}
curr_pos = session.restart_pos;
session.restart_pos = 0L;
}
if (!stor_fh) {
pr_log_debug(DEBUG4, "unable to open '%s' for writing: %s", cmd->arg,
strerror(errno));
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
/* Perform the actual transfer now */
pr_data_init(cmd->arg, PR_NETIO_IO_RD);
session.xfer.file_size = curr_pos;
/* First, make sure the uploaded file has the requested ownership. */
stor_chown();
if (pr_data_open(cmd->arg, NULL, PR_NETIO_IO_RD, 0) < 0) {
stor_abort();
pr_data_abort(0, TRUE);
return ERROR(cmd);
}
/* Initialize the number of bytes stored */
nbytes_stored = 0;
/* Retrieve the number of bytes to store, maximum, if present.
* This check is needed during the pr_data_xfer() loop, below, because
* the size of the file being uploaded isn't known in advance
*/
if ((nbytes_max_store = find_max_nbytes("MaxStoreFileSize")) == 0UL)
have_limit = FALSE;
else
have_limit = TRUE;
/* Check the MaxStoreFileSize, and abort now if zero. */
if (have_limit &&
nbytes_max_store == 0) {
pr_log_pri(PR_LOG_INFO, "MaxStoreFileSize (%" PR_LU " byte%s) reached: "
"aborting transfer of '%s'", (pr_off_t) nbytes_max_store,
nbytes_max_store != 1 ? "s" : "", dir);
/* Abort the transfer. */
stor_abort();
/* Set errno to EDQOUT (or the most appropriate alternative). */
#if defined(EDQUOT)
pr_data_abort(EDQUOT, FALSE);
#elif defined(EFBIG)
pr_data_abort(EFBIG, FALSE);
#else
pr_data_abort(EPERM, FALSE);
#endif
return ERROR(cmd);
}
bufsz = (main_server->tcp_rcvbuf_len > 0 ? main_server->tcp_rcvbuf_len :
PR_TUNABLE_XFER_BUFFER_SIZE);
lbuf = (char *) palloc(cmd->tmp_pool, bufsz);
while ((len = pr_data_xfer(lbuf, bufsz)) > 0) {
int res;
pr_signals_handle();
if (XFER_ABORTED)
break;
nbytes_stored += len;
/* Double-check the current number of bytes stored against the
* MaxStoreFileSize, if configured.
*/
if (have_limit &&
nbytes_stored > nbytes_max_store) {
pr_log_pri(PR_LOG_INFO, "MaxStoreFileSize (%" PR_LU " bytes) reached: "
"aborting transfer of '%s'", (pr_off_t) nbytes_max_store, dir);
/* Unlink the file being written. */
pr_fsio_unlink(dir);
/* Abort the transfer. */
stor_abort();
/* Set errno to EDQOUT (or the most appropriate alternative). */
#if defined(EDQUOT)
pr_data_abort(EDQUOT, FALSE);
#elif defined(EFBIG)
pr_data_abort(EFBIG, FALSE);
#else
pr_data_abort(EPERM, FALSE);
#endif
return ERROR(cmd);
}
res = pr_fsio_write(stor_fh, lbuf, len);
if (res != len) {
int xerrno = EIO;
if (res < 0)
xerrno = errno;
stor_abort();
pr_data_abort(xerrno, FALSE);
return ERROR(cmd);
}
/* If no throttling is configured, this does nothing. */
xfer_rate_throttle(nbytes_stored, FALSE);
}
if (XFER_ABORTED) {
stor_abort();
pr_data_abort(0, 0);
return ERROR(cmd);
} else if (len < 0) {
stor_abort();
pr_data_abort(PR_NETIO_ERRNO(session.d->instrm), FALSE);
return ERROR(cmd);
} else {
/* If no throttling is configured, this does nothing. */
xfer_rate_throttle(nbytes_stored, TRUE);
if (stor_complete() < 0) {
/* Check errno for EDQOUT (or the most appropriate alternative).
* (I hate the fact that FTP has a special response code just for
* this, and that clients actually expect it. Special cases are
* stupid.)
*/
#if defined(EDQUOT)
if (errno == EDQUOT) {
pr_response_add_err(R_552, "%s: %s", session.xfer.path,
strerror(errno));
return ERROR(cmd);
}
#elif defined(EFBIG)
if (errno == EFBIG) {
pr_response_add_err(R_552, "%s: %s", session.xfer.path,
strerror(errno));
return ERROR(cmd);
}
#endif
pr_response_add_err(R_550, "%s: %s", session.xfer.path,
strerror(errno));
return ERROR(cmd);
}
if (session.xfer.path &&
session.xfer.path_hidden) {
if (pr_fsio_rename(session.xfer.path_hidden, session.xfer.path) != 0) {
/* This should only fail on a race condition with a chmod/chown
* or if STOR_APPEND is on and the permissions are squirrely.
* The poor user will have to re-upload, but we've got more important
* problems to worry about and this failure should be fairly rare.
*/
pr_log_pri(PR_LOG_WARNING, "Rename of %s to %s failed: %s.",
session.xfer.path_hidden, session.xfer.path, strerror(errno));
pr_response_add_err(R_550, "%s: Rename of hidden file %s failed: %s",
session.xfer.path, session.xfer.path_hidden, strerror(errno));
pr_fsio_unlink(session.xfer.path_hidden);
return ERROR(cmd);
}
}
pr_data_close(FALSE);
}
return HANDLED(cmd);
}
MODRET xfer_rest(cmd_rec *cmd) {
off_t pos;
char *endp = NULL;
unsigned char *hidden_stores = NULL;
if (cmd->argc != 2) {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
/* If we're using HiddenStores, then REST won't work. */
hidden_stores = get_param_ptr(CURRENT_CONF, "HiddenStores", FALSE);
if (hidden_stores != NULL &&
*hidden_stores == TRUE) {
pr_response_add_err(R_501, "REST not compatible with server configuration");
return ERROR(cmd);
}
/* Don't allow negative numbers. strtoul()/strtoull() will silently
* handle them.
*/
if (*cmd->argv[1] == '-') {
pr_response_add_err(R_501,
"REST requires a value greater than or equal to 0");
return ERROR(cmd);
}
#ifdef HAVE_STRTOULL
pos = strtoull(cmd->argv[1], &endp, 10);
#else
pos = strtoul(cmd->argv[1], &endp, 10);
#endif /* HAVE_STRTOULL */
if (endp &&
*endp) {
pr_response_add_err(R_501,
"REST requires a value greater than or equal to 0");
return ERROR(cmd);
}
session.restart_pos = pos;
/* Refuse the command if we're in ASCII mode, and the restart position
* is anything other than zero.
*
* Ideally, we would refuse the REST command when in ASCII mode regardless
* of position. However, some (IMHO, stupid) clients "test" the FTP
* server by sending "REST 0" to see if the server supports REST, without
* regard to the transfer type. This, then, is a hack to handle such
* clients.
*/
if ((session.sf_flags & SF_ASCII) &&
pos != 0) {
pr_log_debug(DEBUG5, "%s not allowed in ASCII mode", cmd->argv[0]);
pr_response_add_err(R_501,
"%s: Resuming transfers not allowed in ASCII mode", cmd->argv[0]);
return ERROR(cmd);
}
pr_response_add(R_350, "Restarting at %" PR_LU ". Send STORE or RETRIEVE to "
"initiate transfer", (pr_off_t) pos);
return HANDLED(cmd);
}
/* This is a PRE_CMD handler that checks security, etc, and places the full
* filename to send in cmd->notes (note that we CANNOT use cmd->tmp_pool
* for this, as tmp_pool only lasts for the duration of this function).
*/
MODRET xfer_pre_retr(cmd_rec *cmd) {
char *dir = NULL;
mode_t fmode;
unsigned char *allow_restart = NULL;
if (cmd->argc < 2) {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
dir = dir_realpath(cmd->tmp_pool, cmd->arg);
if (!dir ||
!dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, dir, NULL)) {
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
fmode = file_mode(dir);
if (!S_ISREG(fmode)) {
if (!fmode)
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
else
pr_response_add_err(R_550, "%s: Not a regular file", cmd->arg);
return ERROR(cmd);
}
/* If restart is on, check to see if AllowRestartRetrieve is off, in
* which case we disallow the transfer and clear restart_pos.
*/
allow_restart = get_param_ptr(CURRENT_CONF, "AllowRetrieveRestart", FALSE);
if (session.restart_pos &&
(allow_restart && *allow_restart == FALSE)) {
pr_response_add_err(R_451, "%s: Restart not permitted, try again",
cmd->arg);
session.restart_pos = 0L;
return ERROR(cmd);
}
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.retr-path",
pstrdup(cmd->pool, dir), 0) < 0)
pr_log_pri(PR_LOG_NOTICE, "notice: error adding 'mod_xfer.retr-path': %s",
strerror(errno));
return HANDLED(cmd);
}
MODRET xfer_retr(cmd_rec *cmd) {
char *dir = NULL, *lbuf;
struct stat st;
off_t nbytes_max_retrieve = 0;
unsigned char have_limit = FALSE;
long bufsz, len = 0;
off_t curr_pos = 0, nbytes_sent = 0, cnt_steps = 0, cnt_next = 0;
/* This function sets static module variables for later potential
* throttling of the transfer.
*/
xfer_rate_lookup(cmd);
dir = pr_table_get(cmd->notes, "mod_xfer.retr-path", NULL);
retr_fh = pr_fsio_open(dir, O_RDONLY);
if (retr_fh == NULL) {
/* Error opening the file. */
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
if (pr_fsio_stat(dir, &st) < 0) {
/* Error stat'ing the file. */
int xerrno = errno;
pr_fsio_close(retr_fh);
errno = xerrno;
retr_fh = NULL;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));
return ERROR(cmd);
}
if (session.restart_pos) {
/* Make sure that the requested offset is valid (within the size of the
* file being resumed.
*/
if (session.restart_pos > st.st_size) {
pr_response_add_err(R_554, "%s: invalid REST argument", cmd->arg);
pr_fsio_close(retr_fh);
retr_fh = NULL;
return ERROR(cmd);
}
if (pr_fsio_lseek(retr_fh, session.restart_pos,
SEEK_SET) == (off_t) -1) {
int xerrno = errno;
pr_fsio_close(retr_fh);
errno = xerrno;
retr_fh = NULL;
pr_log_debug(DEBUG0, "error seeking to offset %" PR_LU
"for file %s: %s", session.restart_pos, dir, strerror(errno));
pr_response_add_err(R_554, "%s: invalid REST argument", cmd->arg);
return ERROR(cmd);
}
curr_pos = session.restart_pos;
session.restart_pos = 0L;
}
/* Send the data */
pr_data_init(cmd->arg, PR_NETIO_IO_WR);
session.xfer.path = dir;
session.xfer.file_size = st.st_size;
cnt_steps = session.xfer.file_size / 100;
if (cnt_steps == 0)
cnt_steps = 1;
if (pr_data_open(cmd->arg, NULL, PR_NETIO_IO_WR, st.st_size - curr_pos) < 0) {
retr_abort();
pr_data_abort(0, TRUE);
return ERROR(cmd);
}
/* Retrieve the number of bytes to retrieve, maximum, if present */
if ((nbytes_max_retrieve = find_max_nbytes("MaxRetrieveFileSize")) == 0UL)
have_limit = FALSE;
else
have_limit = TRUE;
/* Check the MaxRetrieveFileSize. If it is zero, or if the size
* of the file being retrieved is greater than the MaxRetrieveFileSize,
* then signal an error and abort the transfer now.
*/
if (have_limit &&
((nbytes_max_retrieve == 0) || (st.st_size > nbytes_max_retrieve))) {
pr_log_pri(PR_LOG_INFO, "MaxRetrieveFileSize (%" PR_LU " byte%s) reached: "
"aborting transfer of '%s'", (pr_off_t) nbytes_max_retrieve,
nbytes_max_retrieve != 1 ? "s" : "", dir);
/* Abort the transfer. */
retr_abort();
/* Set errno to EPERM ("Operation not permitted") */
pr_data_abort(EPERM, FALSE);
return ERROR(cmd);
}
bufsz = (main_server->tcp_sndbuf_len > 0 ? main_server->tcp_sndbuf_len :
PR_TUNABLE_XFER_BUFFER_SIZE);
lbuf = (char *) palloc(cmd->tmp_pool, bufsz);
nbytes_sent = curr_pos;
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_SIZE, session.xfer.file_size,
PR_SCORE_XFER_DONE, 0,
NULL);
while (nbytes_sent != session.xfer.file_size) {
pr_signals_handle();
if (XFER_ABORTED)
break;
len = transmit_data(nbytes_sent, &curr_pos, lbuf, bufsz);
if (len == 0)
break;
if (len < 0) {
retr_abort();
pr_data_abort(PR_NETIO_ERRNO(session.d->outstrm), FALSE);
return ERROR(cmd);
}
nbytes_sent += len;
if ((nbytes_sent / cnt_steps) != cnt_next) {
cnt_next = nbytes_sent / cnt_steps;
pr_scoreboard_update_entry(getpid(),
PR_SCORE_XFER_DONE, nbytes_sent,
NULL);
}
/* If no throttling is configured, this simply updates the scoreboard.
* In this case, we want to use session.xfer.total_bytes, rather than
* nbytes_sent, as the latter incorporates a REST position and the
* former does not. (When handling STOR, this is not an issue: different
* end-of-loop conditions).
*/
xfer_rate_throttle(session.xfer.total_bytes, FALSE);
}
if (XFER_ABORTED) {
retr_abort();
pr_data_abort(0, 0);
return ERROR(cmd);
} else if (len < 0) {
retr_abort();
pr_data_abort(errno, FALSE);
return ERROR(cmd);
} else {
/* If no throttling is configured, this simply updates the scoreboard.
* In this case, we want to use session.xfer.total_bytes, rather than
* nbytes_sent, as the latter incorporates a REST position and the
* former does not. (When handling STOR, this is not an issue: different
* end-of-loop conditions).
*/
xfer_rate_throttle(session.xfer.total_bytes, TRUE);
retr_complete();
pr_data_close(FALSE);
}
return HANDLED(cmd);
}
MODRET xfer_abor(cmd_rec *cmd) {
if (cmd->argc != 1) {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
pr_data_abort(0, FALSE);
pr_data_reset();
pr_data_cleanup();
pr_response_add(R_226, "Abort successful");
return HANDLED(cmd);
}
MODRET xfer_type(cmd_rec *cmd) {
if (cmd->argc < 2 || cmd->argc > 3) {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
cmd->argv[1][0] = toupper(cmd->argv[1][0]);
if (!strcmp(cmd->argv[1], "A") ||
(cmd->argc == 3 && !strcmp(cmd->argv[1], "L") &&
!strcmp(cmd->argv[2], "7"))) {
/* TYPE A(SCII) or TYPE L 7. */
session.sf_flags |= SF_ASCII;
} else if (!strcmp(cmd->argv[1], "I") ||
(cmd->argc == 3 && !strcmp(cmd->argv[1], "L") &&
!strcmp(cmd->argv[2], "8"))) {
/* TYPE I(MAGE) or TYPE L 8. */
session.sf_flags &= (SF_ALL^SF_ASCII);
} else {
pr_response_add_err(R_500, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
pr_response_add(R_200, "Type set to %s", cmd->argv[1]);
return HANDLED(cmd);
}
MODRET xfer_stru(cmd_rec *cmd) {
if (cmd->argc != 2) {
pr_response_add_err(R_501, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
cmd->argv[1][0] = toupper(cmd->argv[1][0]);
switch ((int) cmd->argv[1][0]) {
case 'F':
/* Should 202 be returned instead??? */
pr_response_add(R_200, "Structure set to F.");
return HANDLED(cmd);
break;
case 'R':
/* Accept R but with no operational difference from F???
* R is required in minimum implementations by RFC-959, 5.1.
* RFC-1123, 4.1.2.13, amends this to only apply to servers whose file
* systems support record structures, but also suggests that such a
* server "may still accept files with STRU R, recording the byte stream
* literally." Another configurable choice, perhaps?
*
* NOTE: wu-ftpd does not so accept STRU R.
*/
/* FALLTHROUGH */
case 'P':
/* RFC-1123 recommends against implementing P. */
pr_response_add_err(R_504, "'%s' unsupported structure type.",
get_full_cmd(cmd));
return ERROR(cmd);
break;
default:
pr_response_add_err(R_501, "'%s' unrecognized structure type.",
get_full_cmd(cmd));
return ERROR(cmd);
break;
}
}
MODRET xfer_mode(cmd_rec *cmd) {
if (cmd->argc != 2) {
pr_response_add_err(R_501, "'%s' not understood", get_full_cmd(cmd));
return ERROR(cmd);
}
cmd->argv[1][0] = toupper(cmd->argv[1][0]);
switch ((int) cmd->argv[1][0]) {
case 'S':
/* Should 202 be returned instead??? */
pr_response_add(R_200, "Mode set to S.");
return HANDLED(cmd);
break;
case 'B':
/* FALLTHROUGH */
case 'C':
pr_response_add_err(R_504, "'%s' unsupported transfer mode.",
get_full_cmd(cmd));
return ERROR(cmd);
break;
default:
pr_response_add_err(R_501, "'%s' unrecognized transfer mode.",
get_full_cmd(cmd));
return ERROR(cmd);
break;
}
}
MODRET xfer_allo(cmd_rec *cmd) {
pr_response_add(R_202, "No storage allocation necessary.");
return HANDLED(cmd);
}
MODRET xfer_smnt(cmd_rec *cmd) {
pr_response_add(R_502, "SMNT command not implemented.");
return HANDLED(cmd);
}
MODRET xfer_err_cleanup(cmd_rec *cmd) {
if (session.xfer.p)
destroy_pool(session.xfer.p);
memset(&session.xfer, '\0', sizeof(session.xfer));
/* Don't forget to clear any possible REST parameter as well. */
session.restart_pos = 0;
return DECLINED(cmd);
}
MODRET xfer_log_stor(cmd_rec *cmd) {
_log_transfer('i', 'c');
/* Increment the byte counter. */
session.total_bytes_in += session.xfer.total_bytes;
/* Increment the file counters. */
session.total_files_in++;
session.total_files_xfer++;
pr_data_cleanup();
/* Don't forget to clear any possible REST parameter as well. */
session.restart_pos = 0;
return DECLINED(cmd);
}
MODRET xfer_log_retr(cmd_rec *cmd) {
_log_transfer('o', 'c');
/* Increment the byte counter. */
session.total_bytes_out += session.xfer.total_bytes;
/* Increment the file counters. */
session.total_files_out++;
session.total_files_xfer++;
pr_data_cleanup();
/* Don't forget to clear any possible REST parameter as well. */
session.restart_pos = 0;
return DECLINED(cmd);
}
static int noxfer_timeout_cb(CALLBACK_FRAME) {
if (session.sf_flags & SF_XFER)
/* Transfer in progress, ignore this timeout */
return 1;
pr_event_generate("core.timeout-no-transfer", NULL);
pr_response_send_async(R_421, "No Transfer Timeout (%d seconds): closing "
"control connection.", TimeoutNoXfer);
pr_timer_remove(TIMER_IDLE, ANY_MODULE);
pr_timer_remove(TIMER_LOGIN, ANY_MODULE);
/* If this timeout is encountered and we are expecting a passive transfer,
* add some logging that suggests things to check and possibly fix
* (e.g. network/firewall rules).
*/
if (session.sf_flags & SF_PASSIVE) {
pr_log_pri(PR_LOG_INFO,
"Passive data transfer failed, possibly due to network issues");
pr_log_pri(PR_LOG_INFO,
"Check your PassivePorts and MasqueradeAddress settings,");
pr_log_pri(PR_LOG_INFO,
"and any router, NAT, and firewall rules in the network path.");
}
session_exit(PR_LOG_NOTICE, "FTP no transfer timeout, disconnected", 0, NULL);
return 0;
}
/* Configuration handlers
*/
MODRET set_allowoverwrite(cmd_rec *cmd) {
int bool = -1;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|
CONF_DIR|CONF_DYNDIR);
if ((bool = get_boolean(cmd, 1)) == -1)
CONF_ERROR(cmd, "expected boolean parameter");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = (unsigned char) bool;
c->flags |= CF_MERGEDOWN;
return HANDLED(cmd);
}
MODRET set_allowrestart(cmd_rec *cmd) {
int bool = -1;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|
CONF_DIR|CONF_DYNDIR);
if ((bool = get_boolean(cmd, 1)) == -1)
CONF_ERROR(cmd, "expected boolean parameter");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = bool;
c->flags |= CF_MERGEDOWN;
return HANDLED(cmd);
}
MODRET set_deleteabortedstores(cmd_rec *cmd) {
int bool = -1;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|
CONF_DIR|CONF_DYNDIR);
if ((bool = get_boolean(cmd, 1)) == -1)
CONF_ERROR(cmd, "expected Boolean parameter");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = bool;
c->flags |= CF_MERGEDOWN;
return HANDLED(cmd);
}
MODRET set_hiddenstores(cmd_rec *cmd) {
int bool = -1;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|CONF_DIR);
if ((bool = get_boolean(cmd, 1)) == -1)
CONF_ERROR(cmd, "expected Boolean parameter");
c = add_config_param("HiddenStores", 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = bool;
c->flags |= CF_MERGEDOWN;
return HANDLED(cmd);
}
MODRET set_maxfilesize(cmd_rec *cmd) {
config_rec *c = NULL;
unsigned long nbytes;
unsigned int precedence = 0;
int ctxt = (cmd->config && cmd->config->config_type != CONF_PARAM ?
cmd->config->config_type : cmd->server->config_type ?
cmd->server->config_type : CONF_ROOT);
if (cmd->argc-1 == 1) {
if (strcmp(cmd->argv[1], "*") != 0)
CONF_ERROR(cmd, "incorrect number of parameters");
} else if (cmd->argc-1 != 2 && cmd->argc-1 != 4)
CONF_ERROR(cmd, "incorrect number of parameters");
CHECK_CONF(cmd, CONF_ROOT|CONF_ANON|CONF_VIRTUAL|CONF_GLOBAL|CONF_DIR|
CONF_DYNDIR);
/* Set the precedence for this config_rec based on its configuration
* context.
*/
if (ctxt & CONF_GLOBAL)
precedence = 1;
/* These will never appear simultaneously */
else if (ctxt & CONF_ROOT || ctxt & CONF_VIRTUAL)
precedence = 2;
else if (ctxt & CONF_ANON)
precedence = 3;
else if (ctxt & CONF_DIR)
precedence = 4;
else if (ctxt & CONF_DYNDIR)
precedence = 5;
/* If the directive was used with four arguments, it means the optional
* classifiers and expression were used. Make sure the classifier is a valid
* one.
*/
if (cmd->argc-1 == 4) {
if (!strcmp(cmd->argv[3], "user") ||
!strcmp(cmd->argv[3], "group") ||
!strcmp(cmd->argv[3], "class")) {
/* no-op */
} else
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unknown classifier used: '",
cmd->argv[3], "'", NULL));
}
if (cmd->argc-1 == 1) {
/* Do nothing here -- the "*" (the only parameter allowed if there is
* only a single parameter given) signifies an unlimited size, which is
* what the server provides by default.
*/
nbytes = 0UL;
} else {
/* Pass the cmd_rec off to see what number of bytes was
* requested/configured.
*/
if ((nbytes = parse_max_nbytes(cmd->argv[1], cmd->argv[2])) == 0) {
char ulong_max[80] = {'\0'};
sprintf(ulong_max, "%lu", (unsigned long) ULONG_MAX);
if (xfer_errno == EINVAL)
CONF_ERROR(cmd, "invalid parameters");
if (xfer_errno == ERANGE)
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
"number of bytes must be between 0 and ", ulong_max, NULL));
}
}
if (cmd->argc-1 == 1 || cmd->argc-1 == 2) {
c = add_config_param(cmd->argv[0], 2, NULL, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned long));
*((unsigned long *) c->argv[0]) = nbytes;
c->argv[1] = pcalloc(c->pool, sizeof(unsigned int));
*((unsigned int *) c->argv[1]) = precedence;
} else {
array_header *acl = NULL;
int argc = cmd->argc - 4;
char **argv = cmd->argv + 3;
acl = pr_expr_create(cmd->tmp_pool, &argc, argv);
c = add_config_param(cmd->argv[0], 0);
c->argc = argc + 3;
c->argv = pcalloc(c->pool, ((argc + 4) * sizeof(char *)));
argv = (char **) c->argv;
/* Copy in the configured bytes */
*argv = pcalloc(c->pool, sizeof(unsigned long));
*((unsigned long *) *argv++) = nbytes;
/* Copy in the precedence */
*argv = pcalloc(c->pool, sizeof(unsigned int));
*((unsigned int *) *argv++) = precedence;
/* Copy in the classifier. */
*argv++ = pstrdup(c->pool, cmd->argv[3]);
if (argc && acl) {
while (argc--) {
*argv++ = pstrdup(c->pool, *((char **) acl->elts));
acl->elts = ((char **) acl->elts) + 1;
}
}
/* Don't forget the terminating NULL */
*argv = NULL;
}
c->flags |= CF_MERGEDOWN_MULTI;
return HANDLED(cmd);
}
MODRET set_storeuniqueprefix(cmd_rec *cmd) {
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|
CONF_DIR|CONF_DYNDIR);
/* make sure there are no slashes in the prefix */
if (strchr(cmd->argv[1], '/') != NULL)
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "no slashes allowed in prefix: '",
cmd->argv[1], "'", NULL));
c = add_config_param_str(cmd->argv[0], 1, (void *) cmd->argv[1]);
c->flags |= CF_MERGEDOWN;
return HANDLED(cmd);
}
MODRET set_timeoutnoxfer(cmd_rec *cmd) {
int timeout = -1;
char *endp = NULL;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
timeout = (int) strtol(cmd->argv[1], &endp, 10);
if ((endp && *endp) || timeout < 0 || timeout > 65535)
CONF_ERROR(cmd, "timeout values must be between 0 and 65535");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = timeout;
return HANDLED(cmd);
}
MODRET set_timeoutstalled(cmd_rec *cmd) {
int timeout = -1;
char *endp = NULL;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
timeout = (int) strtol(cmd->argv[1], &endp, 10);
if ((endp && *endp) || timeout < 0 || timeout > 65535)
CONF_ERROR(cmd, "timeout values must be between 0 and 65535");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = timeout;
return HANDLED(cmd);
}
/* usage: TransferRate cmds kbps[:free-bytes] ["user"|"group"|"class"
* expression]
*/
MODRET set_transferrate(cmd_rec *cmd) {
config_rec *c = NULL;
char *tmp = NULL, *endp = NULL;
long double rate = 0.0;
off_t freebytes = 0;
unsigned int precedence = 0;
int ctxt = (cmd->config && cmd->config->config_type != CONF_PARAM ?
cmd->config->config_type : cmd->server->config_type ?
cmd->server->config_type : CONF_ROOT);
/* Must have two or four parameters */
if (cmd->argc-1 != 2 && cmd->argc-1 != 4)
CONF_ERROR(cmd, "wrong number of parameters");
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON|
CONF_DIR|CONF_DYNDIR);
/* Set the precedence for this config_rec based on its configuration
* context.
*/
if (ctxt & CONF_GLOBAL)
precedence = 1;
/* These will never appear simultaneously */
else if (ctxt & CONF_ROOT || ctxt & CONF_VIRTUAL)
precedence = 2;
else if (ctxt & CONF_ANON)
precedence = 3;
else if (ctxt & CONF_DIR)
precedence = 4;
/* Note: by tweaking this value to be lower than the precedence for
* <Directory> appearances of this directive, I can effectively cause
* any .ftpaccess appearances not to override...
*/
else if (ctxt & CONF_DYNDIR)
precedence = 5;
/* Check for a valid classifier. */
if (cmd->argc-1 > 2) {
if (!strcmp(cmd->argv[3], "user") ||
!strcmp(cmd->argv[3], "group") ||
!strcmp(cmd->argv[3], "class"))
/* do nothing */
;
else
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unknown classifier requested: '",
cmd->argv[3], "'", NULL));
}
if ((tmp = strchr(cmd->argv[2], ':')) != NULL)
*tmp = '\0';
/* Parse the 'kbps' part. Ideally, we'd be using strtold(3) rather than
* strtod(3) here, but FreeBSD doesn't have strtold(3). Yay. Portability.
*/
rate = (long double) strtod(cmd->argv[2], &endp);
if (rate < 0.0)
CONF_ERROR(cmd, "rate must be greater than zero");
if (endp && *endp)
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "invalid number: '",
cmd->argv[2], "'", NULL));
/* Parse any 'free-bytes' part */
if (tmp) {
cmd->argv[2] = ++tmp;
if ((freebytes = strtoul(cmd->argv[2], &endp, 10)) < 0)
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
"negative values not allowed: '", cmd->argv[2], "'", NULL));
if (endp && *endp)
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "invalid number: '",
cmd->argv[2], "'", NULL));
}
/* Construct the config_rec */
if (cmd->argc-1 == 2) {
c = add_config_param(cmd->argv[0], 4, NULL, NULL, NULL, NULL);
/* Parse the command list. */
if (!xfer_rate_parse_cmdlist(c, cmd->argv[1]))
CONF_ERROR(cmd, "error with command list");
c->argv[1] = pcalloc(c->pool, sizeof(long double));
*((long double *) c->argv[1]) = rate;
c->argv[2] = pcalloc(c->pool, sizeof(off_t));
*((off_t *) c->argv[2]) = freebytes;
c->argv[3] = pcalloc(c->pool, sizeof(unsigned int));
*((unsigned int *) c->argv[3]) = precedence;
} else {
array_header *acl = NULL;
int argc = cmd->argc - 4;
char **argv = cmd->argv + 3;
acl = pr_expr_create(cmd->tmp_pool, &argc, argv);
c = add_config_param(cmd->argv[0], 0);
/* Parse the command list. */
/* The five additional slots are for: cmd-list, bps, free-bytes,
* precedence, user/group/class.
*/
c->argc = argc + 5;
c->argv = pcalloc(c->pool, ((c->argc + 1) * sizeof(char *)));
argv = (char **) c->argv;
if (!xfer_rate_parse_cmdlist(c, cmd->argv[1]))
CONF_ERROR(cmd, "error with command list");
/* Note: the command list is at index 0, hence this increment. */
argv++;
*argv = pcalloc(c->pool, sizeof(long double));
*((long double *) *argv++) = rate;
*argv = pcalloc(c->pool, sizeof(off_t));
*((unsigned long *) *argv++) = freebytes;
*argv = pcalloc(c->pool, sizeof(unsigned int));
*((unsigned int *) *argv++) = precedence;
*argv++ = pstrdup(c->pool, cmd->argv[3]);
if (argc && acl) {
while (argc--) {
*argv++ = pstrdup(c->pool, *((char **) acl->elts));
acl->elts = ((char **) acl->elts) + 1;
}
}
/* don't forget the terminating NULL */
*argv = NULL;
}
c->flags |= CF_MERGEDOWN_MULTI;
return HANDLED(cmd);
}
/* usage: UseSendfile on|off */
MODRET set_usesendfile(cmd_rec *cmd) {
int bool = -1;
config_rec *c;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
bool = get_boolean(cmd, 1);
if (bool == -1)
CONF_ERROR(cmd, "expected Boolean parameter");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = bool;
return HANDLED(cmd);
}
/* Event handlers
*/
static void xfer_sigusr2_ev(const void *event_data, void *user_data) {
/* Only do this if we're currently involved in a data transfer.
* This is a hack put in to support mod_shaper's antics.
*/
if (strcmp(session.curr_cmd, C_APPE) == 0 ||
strcmp(session.curr_cmd, C_RETR) == 0 ||
strcmp(session.curr_cmd, C_STOR) == 0 ||
strcmp(session.curr_cmd, C_STOU) == 0) {
pool *p = make_sub_pool(session.pool);
cmd_rec *cmd = pr_cmd_alloc(p, 1, session.curr_cmd);
/* Rescan the config tree for TransferRates, picking up any possible
* changes.
*/
pr_log_debug(DEBUG2, "rechecking TransferRates");
xfer_rate_lookup(cmd);
destroy_pool(p);
}
return;
}
/* Events handlers
*/
static void xfer_exit_ev(const void *event_data, void *user_data) {
if (session.sf_flags & SF_XFER) {
if (session.xfer.direction == PR_NETIO_IO_RD)
/* An upload is occurring... */
stor_abort();
else
/* A download is occurring... */
retr_abort();
}
return;
}
/* Initialization routines
*/
static int xfer_init(void) {
/* Add the commands handled by this module to the HELP list. */
pr_help_add(C_TYPE, "<sp> type-code (A, I, L 7, L 8)", TRUE);
pr_help_add(C_STRU, "is not implemented (always F)", TRUE);
pr_help_add(C_MODE, "is not implemented (always S)", TRUE);
pr_help_add(C_RETR, "<sp> pathname", TRUE);
pr_help_add(C_STOR, "<sp> pathname", TRUE);
pr_help_add(C_STOU, "(store unique filename)", TRUE);
pr_help_add(C_APPE, "<sp> pathname", TRUE);
pr_help_add(C_REST, "<sp> byte-count", TRUE);
pr_help_add(C_ABOR, "(abort current operation)", TRUE);
return 0;
}
static int xfer_sess_init(void) {
config_rec *c = NULL;
/* Check for a server-specific TimeoutNoTransfer */
if ((c = find_config(main_server->conf, CONF_PARAM, "TimeoutNoTransfer",
FALSE)) != NULL)
TimeoutNoXfer = *((int *) c->argv[0]);
/* Setup TimeoutNoXfer timer */
if (TimeoutNoXfer)
pr_timer_add(TimeoutNoXfer, TIMER_NOXFER, &xfer_module, noxfer_timeout_cb);
/* Check for a server-specific TimeoutStalled */
if ((c = find_config(main_server->conf, CONF_PARAM, "TimeoutStalled",
FALSE)) != NULL)
TimeoutStalled = *((int *) c->argv[0]);
/* Note: timers for handling TimeoutStalled timeouts are handled in the
* data transfer routines, not here.
*/
/* Check for UseSendfile. */
c = find_config(main_server->conf, CONF_PARAM, "UseSendfile", FALSE);
if (c)
use_sendfile = *((unsigned char *) c->argv[0]);
/* Exit handler for HiddenStores cleanup */
pr_event_register(&xfer_module, "core.exit", xfer_exit_ev, NULL);
pr_event_register(&xfer_module, "core.signal.USR2", xfer_sigusr2_ev,
NULL);
return 0;
}
/* Module API tables
*/
static conftable xfer_conftab[] = {
{ "AllowOverwrite", set_allowoverwrite, NULL },
{ "AllowRetrieveRestart", set_allowrestart, NULL },
{ "AllowStoreRestart", set_allowrestart, NULL },
{ "DeleteAbortedStores", set_deleteabortedstores, NULL },
{ "HiddenStor", set_hiddenstores, NULL },
{ "HiddenStores", set_hiddenstores, NULL },
{ "MaxRetrieveFileSize", set_maxfilesize, NULL },
{ "MaxStoreFileSize", set_maxfilesize, NULL },
{ "StoreUniquePrefix", set_storeuniqueprefix, NULL },
{ "TimeoutNoTransfer", set_timeoutnoxfer, NULL },
{ "TimeoutStalled", set_timeoutstalled, NULL },
{ "TransferRate", set_transferrate, NULL },
{ "UseSendfile", set_usesendfile, NULL },
{ NULL }
};
static cmdtable xfer_cmdtab[] = {
{ CMD, C_TYPE, G_NONE, xfer_type, TRUE, FALSE, CL_MISC },
{ CMD, C_STRU, G_NONE, xfer_stru, TRUE, FALSE, CL_MISC },
{ CMD, C_MODE, G_NONE, xfer_mode, TRUE, FALSE, CL_MISC },
{ CMD, C_ALLO, G_NONE, xfer_allo, TRUE, FALSE, CL_MISC },
{ CMD, C_SMNT, G_NONE, xfer_smnt, TRUE, FALSE, CL_MISC },
{ PRE_CMD, C_RETR, G_READ, xfer_pre_retr, TRUE, FALSE },
{ CMD, C_RETR, G_READ, xfer_retr, TRUE, FALSE, CL_READ },
{ LOG_CMD, C_RETR, G_NONE, xfer_log_retr, FALSE, FALSE },
{ LOG_CMD_ERR, C_RETR,G_NONE, xfer_err_cleanup, FALSE, FALSE },
{ PRE_CMD, C_STOR, G_WRITE, xfer_pre_stor, TRUE, FALSE },
{ CMD, C_STOR, G_WRITE, xfer_stor, TRUE, FALSE, CL_WRITE },
{ LOG_CMD, C_STOR, G_NONE, xfer_log_stor, FALSE, FALSE },
{ LOG_CMD_ERR, C_STOR,G_NONE, xfer_err_cleanup, FALSE, FALSE },
{ PRE_CMD, C_STOU, G_WRITE, xfer_pre_stou, TRUE, FALSE },
{ CMD, C_STOU, G_WRITE, xfer_stor, TRUE, FALSE, CL_WRITE },
{ POST_CMD,C_STOU, G_WRITE, xfer_post_stou,FALSE, FALSE },
{ LOG_CMD, C_STOU, G_NONE, xfer_log_stor, FALSE, FALSE },
{ LOG_CMD_ERR, C_STOU,G_NONE, xfer_err_cleanup, FALSE, FALSE },
{ PRE_CMD, C_APPE, G_WRITE, xfer_pre_appe, TRUE, FALSE },
{ CMD, C_APPE, G_WRITE, xfer_stor, TRUE, FALSE, CL_WRITE },
{ LOG_CMD, C_APPE, G_NONE, xfer_log_stor, FALSE, FALSE },
{ LOG_CMD_ERR, C_APPE,G_NONE, xfer_err_cleanup, FALSE, FALSE },
{ CMD, C_ABOR, G_NONE, xfer_abor, TRUE, TRUE, CL_MISC },
{ CMD, C_REST, G_NONE, xfer_rest, TRUE, FALSE, CL_MISC },
{ POST_CMD,C_PROT, G_NONE, xfer_post_prot,FALSE, FALSE },
{ 0,NULL }
};
module xfer_module = {
NULL, NULL,
/* Module API version */
0x20,
/* Module name */
"xfer",
/* Module configuration directive table */
xfer_conftab,
/* Module command handler table */
xfer_cmdtab,
/* Module authentication handler table */
NULL,
/* Module initialization function */
xfer_init,
/* Session initialization function */
xfer_sess_init
};
|