Changeset 90873cc in rtems-libbsd for rtemsbsd/ftpd


Ignore:
Timestamp:
06/28/16 03:32:01 (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
Children:
4a2b844
Parents:
c2ec5f1
Message:

Add ftpd as a service. Add rtems-bsd-config.h for app libbsd set up.

Location:
rtemsbsd/ftpd
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/ftpd/ftpd.c

    rc2ec5f1 r90873cc  
    1414 *                Arnout Vandecappelle <arnout@mind.be> (AV)
    1515 *                Sebastien Bourdeauducq <sebastien@milkymist.org> (MM)
    16  *               
     16 *
    1717 *
    1818 *  Changes:
     
    2121 *
    2222 *      * Support spaces in filenames
    23  * 
     23 *
    2424 *    2010-04-29        Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
    25  * 
     25 *
    2626 *      * Added USER/PASS authentication.
    27  * 
     27 *
    2828 *    2001-01-31        Sergei Organov <osv@javad.ru>
    2929 *
     
    245245
    246246/* Configuration table */
    247 extern struct rtems_ftpd_configuration rtems_ftpd_configuration;
     247static struct rtems_ftpd_configuration* ftpd_config;
    248248
    249249/* this is not prototyped in strict ansi mode */
     
    954954  }
    955955
    956   if (!null && rtems_ftpd_configuration.hooks != NULL)
     956  if (!null && ftpd_config->hooks != NULL)
    957957  {
    958958
     
    962962
    963963    i = 0;
    964     hook = &rtems_ftpd_configuration.hooks[i++];
     964    hook = &ftpd_config->hooks[i++];
    965965    while (hook->filename != NULL)
    966966    {
     
    970970        break;
    971971      }
    972       hook = &rtems_ftpd_configuration.hooks[i++];
     972      hook = &ftpd_config->hooks[i++];
    973973    }
    974974  }
     
    983983     */
    984984
    985     char                *bigBufr;
    986     size_t filesize = rtems_ftpd_configuration.max_hook_filesize + 1;
     985    char   *bigBufr;
     986    size_t  filesize = ftpd_config->max_hook_filesize + 1;
    987987
    988988    /*
     
    17671767    info->pass = NULL;
    17681768    info->user = strdup(fname);
    1769     if (rtems_ftpd_configuration.login &&
    1770       !rtems_ftpd_configuration.login(info->user, NULL)) {
     1769    if (ftpd_config->login &&
     1770      !ftpd_config->login(info->user, NULL)) {
    17711771      info->auth = false;
    17721772      send_reply(info, 331, "User name okay, need password.");
     
    17851785      send_reply(info, 332, "Need account to log in");
    17861786    } else {
    1787       if (rtems_ftpd_configuration.login &&
    1788         !rtems_ftpd_configuration.login(info->user, info->pass)) {
     1787      if (ftpd_config->login &&
     1788        !ftpd_config->login(info->user, info->pass)) {
    17891789        info->auth = false;
    17901790        send_reply(info, 530, "Not logged in.");
     
    18271827        char *c;
    18281828        c = strchr(args, ' ');
    1829         if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254) 
     1829        if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254)
    18301830          && (chmod(fname, (mode_t)mask) == 0))
    18311831          send_reply(info, 257, "CHMOD successful.");
     
    20102010
    20112011  addr.sin_family      = AF_INET;
    2012   addr.sin_port        = htons(rtems_ftpd_configuration.port);
     2012  addr.sin_port        = htons(ftpd_config->port);
    20132013  addr.sin_addr.s_addr = htonl(INADDR_ANY);
    20142014  memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
     
    20652065            info->user = NULL;
    20662066            info->pass = NULL;
    2067             if (rtems_ftpd_configuration.login)
     2067            if (ftpd_config->login)
    20682068              info->auth = false;
    20692069            else
     
    20892089 *
    20902090 * Input parameters:
    2091  *
     2091 *    config: constant initial setup.
    20922092 * Output parameters:
    20932093 *    returns RTEMS_SUCCESSFUL on successful start of the daemon.
    20942094 */
    20952095int
    2096 rtems_initialize_ftpd(void)
     2096rtems_ftpd_start(const struct rtems_ftpd_configuration* config)
    20972097{
    20982098  rtems_status_code   sc;
     
    21012101  int count;
    21022102
    2103   if (rtems_ftpd_configuration.port == 0)
    2104   {
    2105     rtems_ftpd_configuration.port = FTPD_CONTROL_PORT;
    2106   }
    2107 
    2108   if (rtems_ftpd_configuration.priority == 0)
    2109   {
    2110     rtems_ftpd_configuration.priority = 40;
    2111   }
    2112   priority = rtems_ftpd_configuration.priority;
    2113 
    2114   ftpd_timeout = rtems_ftpd_configuration.idle;
     2103  if (ftpd_config != NULL)
     2104    return RTEMS_RESOURCE_IN_USE;
     2105
     2106  ftpd_config = malloc(sizeof(*ftpd_config));
     2107  if (ftpd_config == NULL)
     2108    return RTEMS_NO_MEMORY;
     2109
     2110  *ftpd_config = *config;
     2111
     2112  if (ftpd_config->port == 0)
     2113  {
     2114    ftpd_config->port = FTPD_CONTROL_PORT;
     2115  }
     2116
     2117  if (ftpd_config->priority == 0)
     2118  {
     2119    ftpd_config->priority = 40;
     2120  }
     2121  priority = ftpd_config->priority;
     2122
     2123  ftpd_timeout = ftpd_config->idle;
    21152124  if (ftpd_timeout < 0)
    21162125    ftpd_timeout = 0;
    2117   rtems_ftpd_configuration.idle = ftpd_timeout;
    2118 
    2119   ftpd_access = rtems_ftpd_configuration.access;
     2126  ftpd_config->idle = ftpd_timeout;
     2127
     2128  ftpd_access = ftpd_config->access;
    21202129
    21212130  ftpd_root = "/";
    2122   if ( rtems_ftpd_configuration.root &&
    2123        rtems_ftpd_configuration.root[0] == '/' )
    2124     ftpd_root = rtems_ftpd_configuration.root;
    2125 
    2126   rtems_ftpd_configuration.root = ftpd_root;
    2127 
    2128   if (rtems_ftpd_configuration.tasks_count <= 0)
    2129     rtems_ftpd_configuration.tasks_count = 1;
    2130   count = rtems_ftpd_configuration.tasks_count;
     2131  if (ftpd_config->root && ftpd_config->root[0] == '/' )
     2132    ftpd_root = ftpd_config->root;
     2133
     2134  ftpd_config->root = ftpd_root;
     2135
     2136  if (ftpd_config->tasks_count <= 0)
     2137    ftpd_config->tasks_count = 1;
     2138  count = ftpd_config->tasks_count;
    21312139
    21322140  if (!task_pool_init(count, priority))
     
    21582166  }
    21592167
    2160   syslog(LOG_INFO, "ftpd: FTP daemon started (%d session%s max)",
    2161     count, ((count > 1) ? "s" : ""));
     2168  if (ftpd_config->verbose)
     2169    syslog(LOG_INFO, "ftpd: FTP daemon started (%d session%s max)",
     2170           count, ((count > 1) ? "s" : ""));
    21622171
    21632172  return RTEMS_SUCCESSFUL;
Note: See TracChangeset for help on using the changeset viewer.