I use a similar patch, I added option -h to enable the functionality.
On Sun, May 1, 2022 at 2:17 PM Aleksander Mazur <[email protected]> wrote:
>
> Hi,
>
> AFAIU ftpd just shares current working directory (unless given a path), no
> matter who logs in.
> I find it useful to let ftpd chroot or cd to the home directory of a
> (non-root) user who logs in.
> Please consider attached patch. I hope it won't ruin anybody's setup.
>
> --
> Aleksander Mazur
> _______________________________________________
> busybox mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/busybox
diff -Nru busybox-1.33.1.orig/networking/ftpd.c busybox-1.33.1/networking/ftpd.c
--- busybox-1.33.1.orig/networking/ftpd.c 2021-01-01 02:52:27.000000000 -0800
+++ busybox-1.33.1/networking/ftpd.c 2021-08-23 22:12:23.582753732 -0700
@@ -1164,9 +1164,10 @@
#endif
BIT_A = (!BB_MMU) * 2,
OPT_A = (1 << (BIT_A + 0)),
- OPT_v = (1 << (BIT_A + 1)),
- OPT_S = (1 << (BIT_A + 2)),
- OPT_w = (1 << (BIT_A + 3)) * ENABLE_FEATURE_FTPD_WRITE,
+ OPT_h = (1 << (BIT_A + 1)),
+ OPT_v = (1 << (BIT_A + 2)),
+ OPT_S = (1 << (BIT_A + 3)),
+ OPT_w = (1 << (BIT_A + 4)) * ENABLE_FEATURE_FTPD_WRITE,
};
int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -1186,7 +1187,7 @@
verbose_S = 0;
G.timeout = 2 * 60;
#if BB_MMU
- opts = getopt32(argv, "^" "AvS" IF_FEATURE_FTPD_WRITE("w")
+ opts = getopt32(argv, "^" "AhvS" IF_FEATURE_FTPD_WRITE("w")
"t:+T:+" IF_FEATURE_FTPD_AUTHENTICATION("a:")
"\0" "vv:SS",
&G.timeout, &abs_timeout, IF_FEATURE_FTPD_AUTHENTICATION(&anon_opt,)
@@ -1295,7 +1296,7 @@
G.root_fd = -1;
#endif
argv += optind;
- if (argv[0]) {
+ if (argv[0] && (pw == NULL || !(opts & OPT_h))) {
const char *basedir = argv[0];
#if !BB_MMU
G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY);
@@ -1319,8 +1320,14 @@
}
#if ENABLE_FEATURE_FTPD_AUTHENTICATION
- if (pw)
+ if (pw) {
+ const char *basedir = pw->pw_dir;
+ if ((opts & OPT_h) && chroot(pw->pw_dir) == 0)
+ basedir = "/";
change_identity(pw);
+ if (opts & OPT_h)
+ xchdir(basedir);
+ }
/* else: -A is in effect */
#endif
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox