Changeset 86933ce0 in rtems


Ignore:
Timestamp:
Jun 24, 2011, 10:00:36 AM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
5f66df53
Parents:
a43aee32
Message:

2011-06-24 Arnout Vandecappelle <arnout@…>

Sebastien Bourdeauducq <sebastien@…>

PR 1724/cpukit

  • ftpd/ftpd.h, ftpd/ftpd.c: Added USER/PASS authentication.
Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    ra43aee32 r86933ce0  
     12011-06-24      Arnout Vandecappelle <arnout@mind.be>
     2                Sebastien Bourdeauducq <sebastien@milkymist.org>
     3
     4        PR 1724/cpukit
     5        * ftpd/ftpd.h, ftpd/ftpd.c: Added USER/PASS authentication.
     6
    172011-06-17      Joel Sherrill <joel.sherrill@oarcorp.com>
    28
  • cpukit/ftpd/ftpd.c

    ra43aee32 r86933ce0  
    11/* FIXME: 1. Parse command is a hack.  We can do better.
    2  *        2. Some sort of access control?
    3  *        3. OSV: hooks support seems to be bad, as it requires storing of
     2 *        2. OSV: hooks support seems to be bad, as it requires storing of
    43 *           entire input file in memory.  Seem to be better to change it to
    54 *           something more reasonable, like having
    65 *           'hook_write(void const *buf, int count)' routine that will be
    76 *           called multiple times while file is being received.
    8  *        4. OSV: Remove hack with "/dev/null"?
     7 *        3. OSV: Remove hack with "/dev/null"?
    98 *
    109 *  FTP Server Daemon
     
    1312 *
    1413 *  Changed by:   Sergei Organov <osv@javad.ru> (OSV)
     14 *                Arnout Vandecappelle <arnout@mind.be> (AV)
     15 *                Sebastien Bourdeauducq <sebastien@milkymist.org> (MM)
     16 *               
    1517 *
    1618 *  Changes:
     
    1921 *
    2022 *      * Support spaces in filenames
     23 *
     24 *    2010-04-29        Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
     25 *
     26 *      * Added USER/PASS authentication.
    2127 *
    2228 *    2001-01-31        Sergei Organov <osv@javad.ru>
     
    154160 *  12/01/97   - Creation (JWJ)
    155161 *  2001-01-08 - Changes by OSV
     162 *  2010-04-29 - Authentication added by AV
    156163 *************************************************************************/
    157164
     
    268275  int                 xfer_mode;   /* Transfer mode (ASCII/binary) */
    269276  rtems_id            tid;         /* Task id */
     277  char                *user;       /* user name (0 if not supplied) */
     278  char                *pass;       /* password (0 if not supplied) */
     279  bool                auth;        /* true if user/pass was valid, false if not or not supplied */
    270280} FTPD_SessionInfo_t;
    271281
     
    799809  int                 res = 0;
    800810
    801   if(!can_read())
     811  if(!can_read() || !info->auth)
    802812  {
    803813    send_reply(info, 550, "Access denied.");
     
    945955  WriteProc              wrt = &write;
    946956
    947   if(!can_write())
     957  if(!can_write() || !info->auth)
    948958  {
    949959    send_reply(info, 550, "Access denied.");
     
    12711281  int sc = 1;
    12721282
     1283  if(!info->auth)
     1284  {
     1285    send_reply(info, 550, "Access denied.");
     1286    return;
     1287  }
     1288
    12731289  send_reply(info, 150, "Opening ASCII mode data connection for LIST.");
    12741290
     
    13391355command_cwd(FTPD_SessionInfo_t  *info, char *dir)
    13401356{
     1357  if(!info->auth)
     1358  {
     1359    send_reply(info, 550, "Access denied.");
     1360    return;
     1361  }
     1362
    13411363  if(chdir(dir) == 0)
    13421364    send_reply(info, 250, "CWD command successful.");
     
    13651387  errno = 0;
    13661388  buf[0] = '"';
     1389
     1390  if(!info->auth)
     1391  {
     1392    send_reply(info, 550, "Access denied.");
     1393    return;
     1394  }
     1395
    13671396  cwd = getcwd(buf + 1, FTPD_BUFSIZE - 4);
    13681397  if(cwd)
     
    14011430  struct stat stbuf;
    14021431  char buf[FTPD_BUFSIZE];
     1432
     1433  if(!info->auth)
     1434  {
     1435    send_reply(info, 550, "Access denied.");
     1436    return;
     1437  }
    14031438
    14041439  if (0 > stat(fname, &stbuf))
     
    17261761    }
    17271762  }
    1728   else if (!strcmp("USER", cmd) || !strcmp("PASS", cmd))
    1729   {
    1730     send_reply(info, 230, "User logged in.");
     1763  else if (!strcmp("USER", cmd))
     1764  {
     1765    sscanf(args, "%254s", fname);
     1766    if (info->user)
     1767      free(info->user);
     1768    if (info->pass)
     1769      free(info->pass);
     1770    info->pass = NULL;
     1771    info->user = strdup(fname);
     1772    if (rtems_ftpd_configuration.login &&
     1773      !rtems_ftpd_configuration.login(info->user, NULL)) {
     1774      info->auth = false;
     1775      send_reply(info, 331, "User name okay, need password.");
     1776    } else {
     1777      info->auth = true;
     1778      send_reply(info, 230, "User logged in.");
     1779    }
     1780  }
     1781  else if (!strcmp("PASS", cmd))
     1782  {
     1783    sscanf(args, "%254s", fname);
     1784    if (info->pass)
     1785      free(info->pass);
     1786    info->pass = strdup(fname);
     1787    if (!info->user) {
     1788      send_reply(info, 332, "Need account to log in");
     1789    } else {
     1790      if (rtems_ftpd_configuration.login &&
     1791        !rtems_ftpd_configuration.login(info->user, info->pass)) {
     1792        info->auth = false;
     1793        send_reply(info, 530, "Not logged in.");
     1794      } else {
     1795        info->auth = true;
     1796        send_reply(info, 230, "User logged in.");
     1797      }
     1798    }
    17311799  }
    17321800  else if (!strcmp("DELE", cmd))
    17331801  {
    1734     if(!can_write())
     1802    if(!can_write() || !info->auth)
    17351803    {
    17361804      send_reply(info, 550, "Access denied.");
     
    17551823      int mask;
    17561824
    1757       if(!can_write())
     1825      if(!can_write() || !info->auth)
    17581826      {
    17591827        send_reply(info, 550, "Access denied.");
     
    17741842  else if (!strcmp("RMD", cmd))
    17751843  {
    1776     if(!can_write())
     1844    if(!can_write() || !info->auth)
    17771845    {
    17781846      send_reply(info, 550, "Access denied.");
     
    17911859  else if (!strcmp("MKD", cmd))
    17921860  {
    1793     if(!can_write())
     1861    if(!can_write() || !info->auth)
    17941862    {
    17951863      send_reply(info, 550, "Access denied.");
     
    18951963    close_data_socket(info);
    18961964    close_stream(info);
     1965    free(info->user);
     1966    free(info->pass);
    18971967    task_pool_release(info);
    18981968  }
     
    19812051              htons(ntohs(info->ctrl_addr.sin_port) - 1);
    19822052            info->idle = ftpd_timeout;
     2053            info->user = NULL;
     2054            info->pass = NULL;
     2055            if (rtems_ftpd_configuration.login)
     2056              info->auth = false;
     2057            else
     2058              info->auth = true;
    19832059            /* Wakeup the session task.  The task will call task_pool_release
    19842060               after it closes connection. */
  • cpukit/ftpd/ftpd.h

    ra43aee32 r86933ce0  
    2626typedef int (*rtems_ftpd_hookfunction)(char *, size_t);
    2727
     28#include <rtems/shell.h>
     29
    2830struct rtems_ftpd_hook
    2931{
     
    4648                                                  2 - write-only,
    4749                                                  3 - browse-only */
     50   rtems_shell_login_check_t login;            /* Login check or 0 to ignore
     51                                                  user/passwd. */
    4852};
    4953
Note: See TracChangeset for help on using the changeset viewer.