Changeset 1ef8e3d4 in rtems


Ignore:
Timestamp:
Sep 27, 2001, 1:31:56 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
5b87515
Parents:
d9e4f08
Message:

2001-09-27 Eric Norum <eric.norum@…>

  • lib/tftpDriver.c: Add limited chdir() support to the TFTP filesystem.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/libnetworking/ChangeLog

    rd9e4f08 r1ef8e3d4  
     12001-09-27      Eric Norum <eric.norum@usask.ca>
     2
     3        * lib/tftpDriver.c: Add limited chdir() support to the TFTP
     4        filesystem.
     5
    162001-09-23      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    27
  • c/src/exec/libnetworking/lib/tftpDriver.c

    rd9e4f08 r1ef8e3d4  
    2525#include <rtems.h>
    2626#include <rtems/libio.h>
     27#include <rtems/libio_.h>
    2728#include <rtems/rtems_bsdnet.h>
    2829#include <sys/types.h>
     
    434435)
    435436{
    436 
    437     /*
    438      * Read-only or write-only for now
     437    pathloc->handlers    = &rtems_tftp_handlers;
     438
     439    /*
     440     * Hack to provide the illusion of directories inside the TFTP file system.
     441     * Paths ending in a / are assumed to be directories.
     442     */
     443    if (pathname[strlen(pathname)-1] == '/') {
     444        char *cp;
     445       
     446        /*
     447         * Reject attempts to open() directories
     448         */
     449        if (flags)
     450            set_errno_and_return_minus_one( EISDIR );
     451        cp = strdup (pathname);
     452        if (cp == NULL)
     453            set_errno_and_return_minus_one( ENOMEM );
     454        pathloc->node_access = cp;
     455        return 0;
     456    }
     457
     458    /*
     459     * Reject it if it's not read-only or write-only.
    439460     */
    440461    flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE;
    441462    if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) )
    442463        set_errno_and_return_minus_one( EINVAL );
    443 
    444     /*
    445      * The File system is mounted at TFTP_PATHNAME_PREFIX
    446      * the caller of this routine has striped off this part of the
    447      * name. Save the remainder of the name for use by the open routine.
    448      */
    449     pathloc->node_access = (void * ) pathname;
    450     pathloc->handlers    = &rtems_tftp_handlers;
     464    pathloc->node_access = NULL;
    451465    return 0;
    452466}
    453467
    454 static int rtems_tftp_open(
     468/*
     469 * The routine which does most of the work for the IMFS open handler
     470 */
     471static int rtems_tftp_open_worker(
    455472    rtems_libio_t *iop,
    456     const char    *new_name,
     473    char          *full_path_name,
    457474    unsigned32     flags,
    458475    unsigned32     mode
     
    472489
    473490    /*
    474      * This came from the evaluate path.
    475      * Extract host name component
    476      */
    477     cp1 = cp2 = iop->file_info;   
     491     * Extract the host name component
     492     */
     493    cp2 = full_path_name;
     494    while (*cp2 == '/')
     495        cp2++;
     496    hostname = cp2;
    478497    while (*cp2 != '/') {
    479498        if (*cp2 == '\0')
     
    481500        cp2++;
    482501    }
    483     len = cp2 - cp1;
    484     hostname = malloc (len + 1);
    485     if (hostname == NULL)
    486         return ENOMEM;
    487     strncpy (hostname, cp1, len);
    488     hostname[len] = '\0';
     502    *cp2++ = '\0';
    489503
    490504    /*
     
    495509    else
    496510        farAddress.s_addr = inet_addr (hostname);
    497     free (hostname);
    498511    if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0))
    499512        return ENOENT;
     
    667680
    668681/*
     682 * The IMFS open handler
     683 */
     684static int rtems_tftp_open(
     685    rtems_libio_t *iop,
     686    const char    *new_name,
     687    unsigned32     flags,
     688    unsigned32     mode
     689)
     690{
     691    char *full_path_name;
     692    char *s1;
     693    int err;
     694
     695    /*
     696     * Tack the `current directory' on to relative paths.
     697     * We know that the current directory ends in a / character.
     698     */
     699    if (*new_name == '/') {
     700        /*
     701         * Skip the TFTP filesystem prefix.
     702         */
     703        int len = strlen (TFTP_PATHNAME_PREFIX);
     704        if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len))
     705            return ENOENT;
     706        new_name += len;
     707        s1 = "";
     708    }
     709    else {
     710        /*
     711         * Skip any leading ./ or ../ components.
     712         */
     713        for (;;) {
     714            while (*new_name == '/')
     715                new_name++;
     716            if ((new_name[0] == '.') && (new_name[1] == '/')) {
     717                new_name += 2;
     718                continue;
     719            }
     720            if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) {
     721                new_name += 3;
     722                continue;
     723            }
     724            break;
     725        }
     726        s1 = rtems_filesystem_current.node_access;
     727    }
     728    full_path_name = malloc (strlen (s1) + strlen (new_name) + 1);
     729    if (full_path_name == NULL)
     730        return ENOMEM;
     731    strcpy (full_path_name, s1);
     732    strcat (full_path_name, new_name);
     733    err = rtems_tftp_open_worker (iop, full_path_name, flags, mode);
     734    free (full_path_name);
     735    return err;
     736}
     737
     738/*
    669739 * Read from a TFTP stream
    670740 */
     
    863933}
    864934
    865 rtems_filesystem_node_types_t rtems_tftp_node_type(
     935static rtems_filesystem_node_types_t rtems_tftp_node_type(
    866936     rtems_filesystem_location_info_t        *pathloc                 /* IN */
    867937)
    868938{
    869     return RTEMS_FILESYSTEM_MEMORY_FILE;
     939    if (pathloc->node_access == NULL)
     940        return RTEMS_FILESYSTEM_MEMORY_FILE;
     941    return RTEMS_FILESYSTEM_DIRECTORY;
     942}
     943
     944static int rtems_tftp_free_node_info(
     945     rtems_filesystem_location_info_t        *pathloc                 /* IN */
     946)
     947{
     948    if (pathloc->node_access) {
     949        free (pathloc->node_access);
     950        pathloc->node_access = NULL;
     951    }
     952    return 0;
    870953}
    871954
     
    879962    NULL,                            /* mknod */
    880963    NULL,                            /* chown */
    881     NULL,                            /* freenodinfo */
     964    rtems_tftp_free_node_info,       /* freenodinfo */
    882965    NULL,                            /* mount */
    883966    rtems_tftp_mount_me,             /* initialize */
  • c/src/libnetworking/ChangeLog

    rd9e4f08 r1ef8e3d4  
     12001-09-27      Eric Norum <eric.norum@usask.ca>
     2
     3        * lib/tftpDriver.c: Add limited chdir() support to the TFTP
     4        filesystem.
     5
    162001-09-23      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    27
  • c/src/libnetworking/lib/tftpDriver.c

    rd9e4f08 r1ef8e3d4  
    2525#include <rtems.h>
    2626#include <rtems/libio.h>
     27#include <rtems/libio_.h>
    2728#include <rtems/rtems_bsdnet.h>
    2829#include <sys/types.h>
     
    434435)
    435436{
    436 
    437     /*
    438      * Read-only or write-only for now
     437    pathloc->handlers    = &rtems_tftp_handlers;
     438
     439    /*
     440     * Hack to provide the illusion of directories inside the TFTP file system.
     441     * Paths ending in a / are assumed to be directories.
     442     */
     443    if (pathname[strlen(pathname)-1] == '/') {
     444        char *cp;
     445       
     446        /*
     447         * Reject attempts to open() directories
     448         */
     449        if (flags)
     450            set_errno_and_return_minus_one( EISDIR );
     451        cp = strdup (pathname);
     452        if (cp == NULL)
     453            set_errno_and_return_minus_one( ENOMEM );
     454        pathloc->node_access = cp;
     455        return 0;
     456    }
     457
     458    /*
     459     * Reject it if it's not read-only or write-only.
    439460     */
    440461    flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE;
    441462    if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) )
    442463        set_errno_and_return_minus_one( EINVAL );
    443 
    444     /*
    445      * The File system is mounted at TFTP_PATHNAME_PREFIX
    446      * the caller of this routine has striped off this part of the
    447      * name. Save the remainder of the name for use by the open routine.
    448      */
    449     pathloc->node_access = (void * ) pathname;
    450     pathloc->handlers    = &rtems_tftp_handlers;
     464    pathloc->node_access = NULL;
    451465    return 0;
    452466}
    453467
    454 static int rtems_tftp_open(
     468/*
     469 * The routine which does most of the work for the IMFS open handler
     470 */
     471static int rtems_tftp_open_worker(
    455472    rtems_libio_t *iop,
    456     const char    *new_name,
     473    char          *full_path_name,
    457474    unsigned32     flags,
    458475    unsigned32     mode
     
    472489
    473490    /*
    474      * This came from the evaluate path.
    475      * Extract host name component
    476      */
    477     cp1 = cp2 = iop->file_info;   
     491     * Extract the host name component
     492     */
     493    cp2 = full_path_name;
     494    while (*cp2 == '/')
     495        cp2++;
     496    hostname = cp2;
    478497    while (*cp2 != '/') {
    479498        if (*cp2 == '\0')
     
    481500        cp2++;
    482501    }
    483     len = cp2 - cp1;
    484     hostname = malloc (len + 1);
    485     if (hostname == NULL)
    486         return ENOMEM;
    487     strncpy (hostname, cp1, len);
    488     hostname[len] = '\0';
     502    *cp2++ = '\0';
    489503
    490504    /*
     
    495509    else
    496510        farAddress.s_addr = inet_addr (hostname);
    497     free (hostname);
    498511    if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0))
    499512        return ENOENT;
     
    667680
    668681/*
     682 * The IMFS open handler
     683 */
     684static int rtems_tftp_open(
     685    rtems_libio_t *iop,
     686    const char    *new_name,
     687    unsigned32     flags,
     688    unsigned32     mode
     689)
     690{
     691    char *full_path_name;
     692    char *s1;
     693    int err;
     694
     695    /*
     696     * Tack the `current directory' on to relative paths.
     697     * We know that the current directory ends in a / character.
     698     */
     699    if (*new_name == '/') {
     700        /*
     701         * Skip the TFTP filesystem prefix.
     702         */
     703        int len = strlen (TFTP_PATHNAME_PREFIX);
     704        if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len))
     705            return ENOENT;
     706        new_name += len;
     707        s1 = "";
     708    }
     709    else {
     710        /*
     711         * Skip any leading ./ or ../ components.
     712         */
     713        for (;;) {
     714            while (*new_name == '/')
     715                new_name++;
     716            if ((new_name[0] == '.') && (new_name[1] == '/')) {
     717                new_name += 2;
     718                continue;
     719            }
     720            if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) {
     721                new_name += 3;
     722                continue;
     723            }
     724            break;
     725        }
     726        s1 = rtems_filesystem_current.node_access;
     727    }
     728    full_path_name = malloc (strlen (s1) + strlen (new_name) + 1);
     729    if (full_path_name == NULL)
     730        return ENOMEM;
     731    strcpy (full_path_name, s1);
     732    strcat (full_path_name, new_name);
     733    err = rtems_tftp_open_worker (iop, full_path_name, flags, mode);
     734    free (full_path_name);
     735    return err;
     736}
     737
     738/*
    669739 * Read from a TFTP stream
    670740 */
     
    863933}
    864934
    865 rtems_filesystem_node_types_t rtems_tftp_node_type(
     935static rtems_filesystem_node_types_t rtems_tftp_node_type(
    866936     rtems_filesystem_location_info_t        *pathloc                 /* IN */
    867937)
    868938{
    869     return RTEMS_FILESYSTEM_MEMORY_FILE;
     939    if (pathloc->node_access == NULL)
     940        return RTEMS_FILESYSTEM_MEMORY_FILE;
     941    return RTEMS_FILESYSTEM_DIRECTORY;
     942}
     943
     944static int rtems_tftp_free_node_info(
     945     rtems_filesystem_location_info_t        *pathloc                 /* IN */
     946)
     947{
     948    if (pathloc->node_access) {
     949        free (pathloc->node_access);
     950        pathloc->node_access = NULL;
     951    }
     952    return 0;
    870953}
    871954
     
    879962    NULL,                            /* mknod */
    880963    NULL,                            /* chown */
    881     NULL,                            /* freenodinfo */
     964    rtems_tftp_free_node_info,       /* freenodinfo */
    882965    NULL,                            /* mount */
    883966    rtems_tftp_mount_me,             /* initialize */
  • cpukit/libnetworking/ChangeLog

    rd9e4f08 r1ef8e3d4  
     12001-09-27      Eric Norum <eric.norum@usask.ca>
     2
     3        * lib/tftpDriver.c: Add limited chdir() support to the TFTP
     4        filesystem.
     5
    162001-09-23      Ralf Corsepius <corsepiu@faw.uni-ulm.de>
    27
  • cpukit/libnetworking/lib/tftpDriver.c

    rd9e4f08 r1ef8e3d4  
    2525#include <rtems.h>
    2626#include <rtems/libio.h>
     27#include <rtems/libio_.h>
    2728#include <rtems/rtems_bsdnet.h>
    2829#include <sys/types.h>
     
    434435)
    435436{
    436 
    437     /*
    438      * Read-only or write-only for now
     437    pathloc->handlers    = &rtems_tftp_handlers;
     438
     439    /*
     440     * Hack to provide the illusion of directories inside the TFTP file system.
     441     * Paths ending in a / are assumed to be directories.
     442     */
     443    if (pathname[strlen(pathname)-1] == '/') {
     444        char *cp;
     445       
     446        /*
     447         * Reject attempts to open() directories
     448         */
     449        if (flags)
     450            set_errno_and_return_minus_one( EISDIR );
     451        cp = strdup (pathname);
     452        if (cp == NULL)
     453            set_errno_and_return_minus_one( ENOMEM );
     454        pathloc->node_access = cp;
     455        return 0;
     456    }
     457
     458    /*
     459     * Reject it if it's not read-only or write-only.
    439460     */
    440461    flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE;
    441462    if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) )
    442463        set_errno_and_return_minus_one( EINVAL );
    443 
    444     /*
    445      * The File system is mounted at TFTP_PATHNAME_PREFIX
    446      * the caller of this routine has striped off this part of the
    447      * name. Save the remainder of the name for use by the open routine.
    448      */
    449     pathloc->node_access = (void * ) pathname;
    450     pathloc->handlers    = &rtems_tftp_handlers;
     464    pathloc->node_access = NULL;
    451465    return 0;
    452466}
    453467
    454 static int rtems_tftp_open(
     468/*
     469 * The routine which does most of the work for the IMFS open handler
     470 */
     471static int rtems_tftp_open_worker(
    455472    rtems_libio_t *iop,
    456     const char    *new_name,
     473    char          *full_path_name,
    457474    unsigned32     flags,
    458475    unsigned32     mode
     
    472489
    473490    /*
    474      * This came from the evaluate path.
    475      * Extract host name component
    476      */
    477     cp1 = cp2 = iop->file_info;   
     491     * Extract the host name component
     492     */
     493    cp2 = full_path_name;
     494    while (*cp2 == '/')
     495        cp2++;
     496    hostname = cp2;
    478497    while (*cp2 != '/') {
    479498        if (*cp2 == '\0')
     
    481500        cp2++;
    482501    }
    483     len = cp2 - cp1;
    484     hostname = malloc (len + 1);
    485     if (hostname == NULL)
    486         return ENOMEM;
    487     strncpy (hostname, cp1, len);
    488     hostname[len] = '\0';
     502    *cp2++ = '\0';
    489503
    490504    /*
     
    495509    else
    496510        farAddress.s_addr = inet_addr (hostname);
    497     free (hostname);
    498511    if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0))
    499512        return ENOENT;
     
    667680
    668681/*
     682 * The IMFS open handler
     683 */
     684static int rtems_tftp_open(
     685    rtems_libio_t *iop,
     686    const char    *new_name,
     687    unsigned32     flags,
     688    unsigned32     mode
     689)
     690{
     691    char *full_path_name;
     692    char *s1;
     693    int err;
     694
     695    /*
     696     * Tack the `current directory' on to relative paths.
     697     * We know that the current directory ends in a / character.
     698     */
     699    if (*new_name == '/') {
     700        /*
     701         * Skip the TFTP filesystem prefix.
     702         */
     703        int len = strlen (TFTP_PATHNAME_PREFIX);
     704        if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len))
     705            return ENOENT;
     706        new_name += len;
     707        s1 = "";
     708    }
     709    else {
     710        /*
     711         * Skip any leading ./ or ../ components.
     712         */
     713        for (;;) {
     714            while (*new_name == '/')
     715                new_name++;
     716            if ((new_name[0] == '.') && (new_name[1] == '/')) {
     717                new_name += 2;
     718                continue;
     719            }
     720            if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) {
     721                new_name += 3;
     722                continue;
     723            }
     724            break;
     725        }
     726        s1 = rtems_filesystem_current.node_access;
     727    }
     728    full_path_name = malloc (strlen (s1) + strlen (new_name) + 1);
     729    if (full_path_name == NULL)
     730        return ENOMEM;
     731    strcpy (full_path_name, s1);
     732    strcat (full_path_name, new_name);
     733    err = rtems_tftp_open_worker (iop, full_path_name, flags, mode);
     734    free (full_path_name);
     735    return err;
     736}
     737
     738/*
    669739 * Read from a TFTP stream
    670740 */
     
    863933}
    864934
    865 rtems_filesystem_node_types_t rtems_tftp_node_type(
     935static rtems_filesystem_node_types_t rtems_tftp_node_type(
    866936     rtems_filesystem_location_info_t        *pathloc                 /* IN */
    867937)
    868938{
    869     return RTEMS_FILESYSTEM_MEMORY_FILE;
     939    if (pathloc->node_access == NULL)
     940        return RTEMS_FILESYSTEM_MEMORY_FILE;
     941    return RTEMS_FILESYSTEM_DIRECTORY;
     942}
     943
     944static int rtems_tftp_free_node_info(
     945     rtems_filesystem_location_info_t        *pathloc                 /* IN */
     946)
     947{
     948    if (pathloc->node_access) {
     949        free (pathloc->node_access);
     950        pathloc->node_access = NULL;
     951    }
     952    return 0;
    870953}
    871954
     
    879962    NULL,                            /* mknod */
    880963    NULL,                            /* chown */
    881     NULL,                            /* freenodinfo */
     964    rtems_tftp_free_node_info,       /* freenodinfo */
    882965    NULL,                            /* mount */
    883966    rtems_tftp_mount_me,             /* initialize */
Note: See TracChangeset for help on using the changeset viewer.