[PATCH] Add option for specifying username to use for anonymous logins

Denys Vlasenko vda.linux at googlemail.com
Tue Jan 24 22:05:34 UTC 2017


Applied, thanks.

On Fri, Jan 6, 2017 at 11:01 PM, Andrey Mozzhuhin <amozzhuhin at yandex.ru> wrote:
> Anonymous ftpd logins is usefull even when ftpd authentication feature
> is enabled. Anonymous logins provide simple password-less connection
> for FTP clients.
>
> To allow password-less connection user command line option '-a USER' is
> added. This option allow specifying the system user to use when
> 'anonymous' username is provided in USER command.
>
> Signed-off-by: Andrey Mozzhuhin <amozzhuhin at yandex.ru>
> ---
>  networking/ftpd.c | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/networking/ftpd.c b/networking/ftpd.c
> index bcd60a2..7dd2242 100644
> --- a/networking/ftpd.c
> +++ b/networking/ftpd.c
> @@ -47,7 +47,9 @@
>  //kbuild:lib-$(CONFIG_FTPD) += ftpd.o
>
>  //usage:#define ftpd_trivial_usage
> -//usage:       "[-wvS] [-t N] [-T N] [DIR]"
> +//usage:       "[-wvS]"
> +//usage:       IF_FEATURE_FTPD_AUTHENTICATION(" [-a USER]")
> +//usage:       " [-t N] [-T N] [DIR]"
>  //usage:#define ftpd_full_usage "\n\n"
>  //usage:       "Anonymous FTP server\n"
>  //usage:       "\n"
> @@ -59,6 +61,8 @@
>  //usage:     "\n       -w      Allow upload"
>  //usage:     "\n       -v      Log errors to stderr. -vv: verbose log"
>  //usage:     "\n       -S      Log errors to syslog. -SS: verbose log"
> +//usage:       IF_FEATURE_FTPD_AUTHENTICATION(
> +//usage:     "\n       -a USER User for anonymous logins")
>  //usage:     "\n       -t,-T   Idle and absolute timeouts"
>  //usage:     "\n       DIR     Change root to this directory"
>
> @@ -1154,6 +1158,8 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
>  {
>  #if ENABLE_FEATURE_FTPD_AUTHENTICATION
>         struct passwd *pw = NULL;
> +       char *anonymous_user = NULL;
> +       int is_anonymous = 0;
>  #endif
>         unsigned abs_timeout;
>         unsigned verbose_S;
> @@ -1165,10 +1171,13 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
>         verbose_S = 0;
>         G.timeout = 2 * 60;
>         opt_complementary = "vv:SS";
> -#if BB_MMU
> -       opts = getopt32(argv,    "vS" IF_FEATURE_FTPD_WRITE("w") "t:+T:+",
> &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
> -#else
> -       opts = getopt32(argv, "l1AvS" IF_FEATURE_FTPD_WRITE("w") "t:+T:+",
> &G.timeout, &abs_timeout, &G.verbose, &verbose_S);
> +       opts = getopt32(argv, USE_FOR_NOMMU("l1A") "vS"
> IF_FEATURE_FTPD_WRITE("w")
> +                       "t:+T:+"
> +                       IF_FEATURE_FTPD_AUTHENTICATION("a:"),
> +                       &G.timeout, &abs_timeout,
> +                       IF_FEATURE_FTPD_AUTHENTICATION(&anonymous_user,)
> +                       &G.verbose, &verbose_S);
> +#if !BB_MMU
>         if (opts & (OPT_l|OPT_1)) {
>                 /* Our secret backdoor to ls */
>  /* TODO: pass --group-directories-first? would be nice, but ls doesn't do
> that yet */
> @@ -1234,11 +1243,12 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
>  #if ENABLE_FEATURE_FTPD_AUTHENTICATION
>         while (1) {
>                 uint32_t cmdval = cmdio_get_cmd_and_arg();
> -                       if (cmdval == const_USER) {
> -                       pw = getpwnam(G.ftp_arg);
> +               if (cmdval == const_USER) {
> +                       is_anonymous = anonymous_user && !strcmp(G.ftp_arg,
> "anonymous");
> +                       pw = is_anonymous ? getpwnam(anonymous_user) :
> getpwnam(G.ftp_arg);
>                         cmdio_write_raw(STR(FTP_GIVEPWORD)" Please specify
> password\r\n");
>                 } else if (cmdval == const_PASS) {
> -                       if (check_password(pw, G.ftp_arg) > 0) {
> +                       if (is_anonymous || check_password(pw, G.ftp_arg) >
> 0) {
>                                 break;  /* login success */
>                         }
>                         cmdio_write_raw(STR(FTP_LOGINERR)" Login
> failed\r\n");
> --
> 2.7.4
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list