FreeBSD Bugzilla – Attachment 12366 Details for
Bug 23944
Patch for ftpd to add a cd after the chroot.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 3.30 KB, created by
fschapachnik
on 2000-12-29 16:20:01 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
fschapachnik
Created:
2000-12-29 16:20:01 UTC
Size:
3.30 KB
patch
obsolete
>--- ftpd.c.orig Mon Oct 23 17:57:54 2000 >+++ ftpd.c Fri Dec 29 12:49:09 2000 >@@ -185,6 +185,9 @@ > > char *pid_file = NULL; > >+/* WARNING: FTP_CHROOT_SEPARATOR *MUST* end in / */ >+#define FTP_CHROOT_SEPARATOR "/./" >+ > /* > * Timeout intervals for retrying connections > * to hosts that don't accept PORT cmds. This >@@ -248,6 +251,7 @@ > static char *sgetsave __P((char *)); > static void reapchild __P((int)); > static void logxfer __P((char *, long, long)); >+static void get_chroot_and_cd_dirs __P((char *, char **, char **)); > > static char * > curdir() >@@ -1168,6 +1172,7 @@ > { > int rval; > FILE *fd; >+ char *cd_dir, *chroot_dir; > #ifdef LOGIN_CAP > login_cap_t *lc = NULL; > #endif >@@ -1291,10 +1296,15 @@ > goto bad; > } > } else if (dochroot) { >- if (chroot(pw->pw_dir) < 0 || chdir("/") < 0) { >+ get_chroot_and_cd_dirs(pw->pw_dir, &chroot_dir, &cd_dir); >+ if (chroot(chroot_dir) < 0 || chdir(cd_dir) < 0) { >+ free(chroot_dir); >+ free(cd_dir); > reply(550, "Can't change root."); > goto bad; > } >+ free(chroot_dir); >+ free(cd_dir); > } else if (chdir(pw->pw_dir) < 0) { > if (chdir("/") < 0) { > reply(530, "User %s: can't change directory to %s.", >@@ -2789,5 +2799,47 @@ > ctime(&now)+4, ident, remotehost, > path, name, size, now - start + (now == start)); > write(statfd, buf, strlen(buf)); >+ } >+} >+ >+/* >+ * Make a pointer to the chroot dir and another to the cd dir. >+ * The first is all the path up to the first FTP_CHROOT_SEPARATOR. >+ * The later is the remaining chars, not including the FTP_CHROOT_SEPARATOR, >+ * but prepending a '/'. >+ */ >+static void >+get_chroot_and_cd_dirs(user_home_dir, chroot_dir, cd_dir) >+ char *user_home_dir; >+ char **chroot_dir; >+ char **cd_dir; >+{ >+ char *p; >+ >+ /* Make a pointer to first character of string FTP_CHROOT_SEPARATOR >+ inside user_home_dir. */ >+ p = (char *) strstr(user_home_dir, FTP_CHROOT_SEPARATOR); >+ if (p == NULL) { >+ /* >+ * There is not FTP_CHROOT_SEPARATOR string inside >+ * user_home_dir. Return user_home_dir as chroot_dir, >+ * and "/" as cd_dir. >+ */ >+ *chroot_dir = (char *) strdup(user_home_dir); >+ *cd_dir = (char *) strdup("/"); >+ } else { >+ /* >+ * Use strlen(user_home_dir) as maximun length for >+ * both cd_dir and chroot_dir, as both are substrings of >+ * user_home_dir. >+ */ >+ if ((*chroot_dir = malloc(strlen(user_home_dir))) == NULL) >+ fatal("Ran out of memory."); >+ if ((*cd_dir = malloc(strlen(user_home_dir))) == NULL) >+ fatal("Ran out of memory."); >+ (void) strncpy(*chroot_dir, user_home_dir, p-user_home_dir); >+ /* Skip FTP_CHROOT_SEPARATOR (except the last /). */ >+ p += strlen(FTP_CHROOT_SEPARATOR)-1; >+ (void) strncpy(*cd_dir, p, strlen(p)); > } > } >--- ftpd.8.orig Fri Dec 29 12:53:21 2000 >+++ ftpd.8 Fri Dec 29 12:55:51 2000 >@@ -298,13 +298,14 @@ > or the user is a member of a group with a group entry in this file, > i.e. one prefixed with > .Ql \&@ , >-the session's root will be changed to the user's login directory by >+the session's root will be changed to the user's login directory (up to the first /./) by > .Xr chroot 2 > as for an > .Dq anonymous > or > .Dq ftp > account (see next item). >+The user is placed into the directory that remainds after stripping the former from the user's login directory. > This facility may also be triggered by enabling the boolean "ftp-chroot" > capability in > .Xr login.conf 5 .
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 23944
: 12366 |
12367
|
12368