Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/networking/ftpgetput.c

    r821 r1770  
    1414 */
    1515
    16 #include <sys/ioctl.h>
    17 
    18 #include <ctype.h>
    19 #include <errno.h>
    20 #include <fcntl.h>
    2116#include <getopt.h>
    22 #include <signal.h>
    23 #include <string.h>
    24 #include <unistd.h>
    25 
    26 #include <sys/socket.h>
    27 
    28 #include "busybox.h"
     17#include "libbb.h"
    2918
    3019typedef struct ftp_host_info_s {
    31     char *user;
    32     char *password;
    33     struct sockaddr_in *s_in;
     20    const char *user;
     21    const char *password;
     22    struct len_and_sockaddr *lsa;
    3423} ftp_host_info_t;
    3524
    36 static char verbose_flag = 0;
    37 static char do_continue = 0;
     25static smallint verbose_flag;
     26static smallint do_continue;
     27
     28static void ftp_die(const char *msg, const char *remote) ATTRIBUTE_NORETURN;
     29static void ftp_die(const char *msg, const char *remote)
     30{
     31    /* Guard against garbage from remote server */
     32    const char *cp = remote;
     33    while (*cp >= ' ' && *cp < '\x7f') cp++;
     34    bb_error_msg_and_die("unexpected server response%s%s: %.*s",
     35            msg ? " to " : "", msg ? msg : "",
     36            (int)(cp - remote), remote);
     37}
     38
    3839
    3940static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf)
    4041{
     42    unsigned n;
    4143    if (verbose_flag) {
    42         bb_error_msg("cmd %s%s", s1, s2);
     44        bb_error_msg("cmd %s %s", s1, s2);
    4345    }
    4446
    4547    if (s1) {
    4648        if (s2) {
    47             fprintf(stream, "%s%s\r\n", s1, s2);
     49            fprintf(stream, "%s %s\r\n", s1, s2);
    4850        } else {
    4951            fprintf(stream, "%s\r\n", s1);
     
    5456
    5557        if (fgets(buf, 510, stream) == NULL) {
    56             bb_perror_msg_and_die("fgets()");
     58            bb_perror_msg_and_die("fgets");
    5759        }
    5860        buf_ptr = strstr(buf, "\r\n");
     
    6062            *buf_ptr = '\0';
    6163        }
    62     } while (! isdigit(buf[0]) || buf[3] != ' ');
    63 
    64     return atoi(buf);
    65 }
    66 
    67 static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf)
     64    } while (!isdigit(buf[0]) || buf[3] != ' ');
     65
     66    buf[3] = '\0';
     67    n = xatou(buf);
     68    buf[3] = ' ';
     69    return n;
     70}
     71
     72static int xconnect_ftpdata(ftp_host_info_t *server, char *buf)
    6873{
    6974    char *buf_ptr;
    7075    unsigned short port_num;
    7176
     77    /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]
     78     * Server's IP is N1.N2.N3.N4 (we ignore it)
     79     * Server's port for data connection is P1*256+P2 */
     80    buf_ptr = strrchr(buf, ')');
     81    if (buf_ptr) *buf_ptr = '\0';
     82
    7283    buf_ptr = strrchr(buf, ',');
    7384    *buf_ptr = '\0';
    74     port_num = atoi(buf_ptr + 1);
     85    port_num = xatoul_range(buf_ptr + 1, 0, 255);
    7586
    7687    buf_ptr = strrchr(buf, ',');
    7788    *buf_ptr = '\0';
    78     port_num += atoi(buf_ptr + 1) * 256;
    79 
    80     server->s_in->sin_port=htons(port_num);
    81     return(xconnect(server->s_in));
     89    port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256;
     90
     91    set_nport(server->lsa, htons(port_num));
     92    return xconnect_stream(server->lsa);
    8293}
    8394
     
    8899
    89100    /* Connect to the command socket */
    90     control_stream = fdopen(xconnect(server->s_in), "r+");
     101    control_stream = fdopen(xconnect_stream(server->lsa), "r+");
    91102    if (control_stream == NULL) {
    92         bb_perror_msg_and_die("Couldnt open control stream");
     103        /* fdopen failed - extremely unlikely */
     104        bb_perror_nomsg_and_die();
    93105    }
    94106
    95107    if (ftpcmd(NULL, NULL, control_stream, buf) != 220) {
    96         bb_error_msg_and_die("%s", buf + 4);
     108        ftp_die(NULL, buf);
    97109    }
    98110
    99111    /*  Login to the server */
    100     switch (ftpcmd("USER ", server->user, control_stream, buf)) {
     112    switch (ftpcmd("USER", server->user, control_stream, buf)) {
    101113    case 230:
    102114        break;
    103115    case 331:
    104         if (ftpcmd("PASS ", server->password, control_stream, buf) != 230) {
    105             bb_error_msg_and_die("PASS error: %s", buf + 4);
     116        if (ftpcmd("PASS", server->password, control_stream, buf) != 230) {
     117            ftp_die("PASS", buf);
    106118        }
    107119        break;
    108120    default:
    109         bb_error_msg_and_die("USER error: %s", buf + 4);
     121        ftp_die("USER", buf);
    110122    }
    111123
    112124    ftpcmd("TYPE I", NULL, control_stream, buf);
    113125
    114     return(control_stream);
     126    return control_stream;
    115127}
    116128
    117129#if !ENABLE_FTPGET
    118 #define ftp_receive 0
     130int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
     131        const char *local_path, char *server_path);
    119132#else
    120 static int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
     133static
     134int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
    121135        const char *local_path, char *server_path)
    122136{
    123137    char buf[512];
    124     off_t filesize = 0;
     138/* I think 'filesize' usage here is bogus. Let's see... */
     139    //off_t filesize = -1;
     140#define filesize ((off_t)-1)
    125141    int fd_data;
    126142    int fd_local = -1;
     
    129145    /* Connect to the data socket */
    130146    if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
    131         bb_error_msg_and_die("PASV error: %s", buf + 4);
     147        ftp_die("PASV", buf);
    132148    }
    133149    fd_data = xconnect_ftpdata(server, buf);
    134150
    135     if (ftpcmd("SIZE ", server_path, control_stream, buf) == 213) {
    136         unsigned long value=filesize;
    137         if (safe_strtoul(buf + 4, &value))
    138             bb_error_msg_and_die("SIZE error: %s", buf + 4);
    139         filesize = value;
     151    if (ftpcmd("SIZE", server_path, control_stream, buf) == 213) {
     152        //filesize = BB_STRTOOFF(buf + 4, NULL, 10);
     153        //if (errno || filesize < 0)
     154        //  ftp_die("SIZE", buf);
    140155    } else {
    141         filesize = -1;
    142156        do_continue = 0;
    143157    }
    144158
    145     if ((local_path[0] == '-') && (local_path[1] == '\0')) {
     159    if (LONE_DASH(local_path)) {
    146160        fd_local = STDOUT_FILENO;
    147161        do_continue = 0;
     
    151165        struct stat sbuf;
    152166        if (lstat(local_path, &sbuf) < 0) {
    153             bb_perror_msg_and_die("fstat()");
     167            bb_perror_msg_and_die("lstat");
    154168        }
    155169        if (sbuf.st_size > 0) {
     
    161175
    162176    if (do_continue) {
    163         sprintf(buf, "REST %ld", (long)beg_range);
     177        sprintf(buf, "REST %"OFF_FMT"d", beg_range);
    164178        if (ftpcmd(buf, NULL, control_stream, buf) != 350) {
    165179            do_continue = 0;
    166180        } else {
    167             filesize -= beg_range;
    168         }
    169     }
    170 
    171     if (ftpcmd("RETR ", server_path, control_stream, buf) > 150) {
    172         bb_error_msg_and_die("RETR error: %s", buf + 4);
     181            //if (filesize != -1)
     182            //  filesize -= beg_range;
     183        }
     184    }
     185
     186    if (ftpcmd("RETR", server_path, control_stream, buf) > 150) {
     187        ftp_die("RETR", buf);
    173188    }
    174189
     
    176191    if (fd_local == -1) {
    177192        if (do_continue) {
    178             fd_local = bb_xopen(local_path, O_APPEND | O_WRONLY);
     193            fd_local = xopen(local_path, O_APPEND | O_WRONLY);
    179194        } else {
    180             fd_local = bb_xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
     195            fd_local = xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
    181196        }
    182197    }
     
    184199    /* Copy the file */
    185200    if (filesize != -1) {
    186         if (-1 == bb_copyfd_size(fd_data, fd_local, filesize))
    187             exit(EXIT_FAILURE);
     201        if (bb_copyfd_size(fd_data, fd_local, filesize) == -1)
     202            return EXIT_FAILURE;
    188203    } else {
    189         if (-1 == bb_copyfd_eof(fd_data, fd_local))
    190             exit(EXIT_FAILURE);
     204        if (bb_copyfd_eof(fd_data, fd_local) == -1)
     205            return EXIT_FAILURE;
    191206    }
    192207
     
    194209    close(fd_data);
    195210    if (ftpcmd(NULL, NULL, control_stream, buf) != 226) {
    196         bb_error_msg_and_die("ftp error: %s", buf + 4);
     211        ftp_die(NULL, buf);
    197212    }
    198213    ftpcmd("QUIT", NULL, control_stream, buf);
    199214
    200     return(EXIT_SUCCESS);
     215    return EXIT_SUCCESS;
    201216}
    202217#endif
    203218
    204219#if !ENABLE_FTPPUT
    205 #define ftp_send 0
     220int ftp_send(ftp_host_info_t *server, FILE *control_stream,
     221        const char *server_path, char *local_path);
    206222#else
    207 static int ftp_send(ftp_host_info_t *server, FILE *control_stream,
     223static
     224int ftp_send(ftp_host_info_t *server, FILE *control_stream,
    208225        const char *server_path, char *local_path)
    209226{
     
    216233    /*  Connect to the data socket */
    217234    if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
    218         bb_error_msg_and_die("PASV error: %s", buf + 4);
     235        ftp_die("PASV", buf);
    219236    }
    220237    fd_data = xconnect_ftpdata(server, buf);
    221238
    222239    /* get the local file */
    223     if ((local_path[0] == '-') && (local_path[1] == '\0')) {
    224         fd_local = STDIN_FILENO;
    225     } else {
    226         fd_local = bb_xopen(local_path, O_RDONLY);
     240    fd_local = STDIN_FILENO;
     241    if (NOT_LONE_DASH(local_path)) {
     242        fd_local = xopen(local_path, O_RDONLY);
    227243        fstat(fd_local, &sbuf);
    228244
    229         sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size);
     245        sprintf(buf, "ALLO %"OFF_FMT"u", sbuf.st_size);
    230246        response = ftpcmd(buf, NULL, control_stream, buf);
    231247        switch (response) {
     
    235251        default:
    236252            close(fd_local);
    237             bb_error_msg_and_die("ALLO error: %s", buf + 4);
     253            ftp_die("ALLO", buf);
    238254            break;
    239255        }
    240256    }
    241     response = ftpcmd("STOR ", server_path, control_stream, buf);
     257    response = ftpcmd("STOR", server_path, control_stream, buf);
    242258    switch (response) {
    243259    case 125:
     
    246262    default:
    247263        close(fd_local);
    248         bb_error_msg_and_die("STOR error: %s", buf + 4);
     264        ftp_die("STOR", buf);
    249265    }
    250266
     
    257273    close(fd_data);
    258274    if (ftpcmd(NULL, NULL, control_stream, buf) != 226) {
    259         bb_error_msg_and_die("error: %s", buf + 4);
     275        ftp_die("close", buf);
    260276    }
    261277    ftpcmd("QUIT", NULL, control_stream, buf);
    262278
    263     return(EXIT_SUCCESS);
     279    return EXIT_SUCCESS;
    264280}
    265281#endif
     
    272288
    273289#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
    274 static const struct option ftpgetput_long_options[] = {
    275     {"continue", 1, NULL, 'c'},
    276     {"verbose", 0, NULL, 'v'},
    277     {"username", 1, NULL, 'u'},
    278     {"password", 1, NULL, 'p'},
    279     {"port", 1, NULL, 'P'},
    280     {0, 0, 0, 0}
    281 };
    282 #else
    283 #define ftpgetput_long_options 0
    284 #endif
    285 
     290static const char ftpgetput_longopts[] ALIGN1 =
     291    "continue\0" Required_argument "c"
     292    "verbose\0"  No_argument       "v"
     293    "username\0" Required_argument "u"
     294    "password\0" Required_argument "p"
     295    "port\0"     Required_argument "P"
     296    ;
     297#endif
     298
     299int ftpgetput_main(int argc, char **argv);
    286300int ftpgetput_main(int argc, char **argv)
    287301{
    288302    /* content-length of the file */
    289     unsigned long opt;
    290     char *port = "ftp";
    291 
     303    unsigned opt;
     304    const char *port = "ftp";
    292305    /* socket to ftp server */
    293306    FILE *control_stream;
    294     struct sockaddr_in s_in;
    295 
    296     /* continue a prev transfer (-c) */
     307    /* continue previous transfer (-c) */
    297308    ftp_host_info_t *server;
    298309
    299     int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL;
    300 
     310#if ENABLE_FTPPUT && !ENABLE_FTPGET
     311# define ftp_action ftp_send
     312#elif ENABLE_FTPGET && !ENABLE_FTPPUT
     313# define ftp_action ftp_receive
     314#else
     315    int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = ftp_send;
    301316    /* Check to see if the command is ftpget or ftput */
    302     if (ENABLE_FTPPUT && (!ENABLE_FTPGET || bb_applet_name[3] == 'p')) {
    303         ftp_action = ftp_send;
    304     }
    305     if (ENABLE_FTPGET && (!ENABLE_FTPPUT || bb_applet_name[3] == 'g')) {
     317    if (applet_name[3] == 'g') {
    306318        ftp_action = ftp_receive;
    307319    }
     320#endif
    308321
    309322    /* Set default values */
    310     server = xmalloc(sizeof(ftp_host_info_t));
     323    server = xmalloc(sizeof(*server));
    311324    server->user = "anonymous";
    312325    server->password = "busybox@";
    313     verbose_flag = 0;
    314326
    315327    /*
    316328     * Decipher the command line
    317329     */
    318     if (ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS)
    319         bb_applet_long_options = ftpgetput_long_options;
    320 
    321     opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
     330#if ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS
     331    applet_long_options = ftpgetput_longopts;
     332#endif
     333    opt_complementary = "=3"; /* must have 3 params */
     334    opt = getopt32(argv, "cvu:p:P:", &server->user, &server->password, &port);
     335    argv += optind;
    322336
    323337    /* Process the non-option command line arguments */
    324     if (argc - optind != 3) {
    325         bb_show_usage();
    326     }
    327 
    328338    if (opt & FTPGETPUT_OPT_CONTINUE) {
    329339        do_continue = 1;
     
    336346     * sites (i.e. ftp.us.debian.org) use round-robin DNS
    337347     * and we want to connect to only one IP... */
    338     server->s_in = &s_in;
    339     bb_lookup_host(&s_in, argv[optind]);
    340     s_in.sin_port = bb_lookup_port(port, "tcp", 21);
     348    server->lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
    341349    if (verbose_flag) {
    342         printf("Connecting to %s[%s]:%d\n",
    343                 argv[optind], inet_ntoa(s_in.sin_addr), ntohs(s_in.sin_port));
     350        printf("Connecting to %s (%s)\n", argv[0],
     351            xmalloc_sockaddr2dotted(&server->lsa->sa));
    344352    }
    345353
     
    347355    control_stream = ftp_login(server);
    348356
    349     return(ftp_action(server, control_stream, argv[optind + 1], argv[optind + 2]));
    350 }
     357    return ftp_action(server, control_stream, argv[1], argv[2]);
     358}
Note: See TracChangeset for help on using the changeset viewer.