[scponly] Initial Directory

Daniel Lorch ml-daniel at lorch.cc
Tue Nov 23 12:34:45 EST 2004


Hi

basically I'm looking for a drop-in replacement for proftpd, so this 
behaviour is required for all the interactive protocols which are "like 
FTP" from the user's perspective (sftp-server and WinSCP), but not for 
command-line tools like rsync and scp. So if a user logs in via his 
GUI-tool he should be sent to a subdirectory (like public_html), but if 
he uses scp or rsync (e.g. in a shell script) the initial directory 
should not be modified. Sounds complicated? :)

I wrote a patch against scponly-3.11 which implements this behaviour 
(the patch also includes changes against generated files like configure 
and config.h. I found them in CVS so I assumed they should be patched, 
too). I hope everything is done right, otherwise please let me know.

Usage:

   tar zxf scponly-3.11.tgz
   cd scponly-3.11
   patch -p1 < ../scponly-3.11-default-chdir.patch
   ./configure --with-default-chdir=public_html
   make
   make install

Comments?

This patch has not yet been thorougly tested, so use with care ;)

Daniel
-------------- next part --------------
diff -ur scponly-3.11-dist/config.h.in scponly-3.11-daniel/config.h.in
--- scponly-3.11-dist/config.h.in	Tue Nov 23 00:32:41 2004
+++ scponly-3.11-daniel/config.h.in	Mon Nov 22 23:41:47 2004
@@ -11,6 +11,7 @@
 #undef UNISON_COMPAT 
 #undef ENABLE_SCP2
 #undef ENABLE_SFTP
+#undef ENABLE_DEFAULT_CHDIR
 #undef ENABLE_WILDCARDS
 #undef RESTRICTIVE_FILENAMES
 #undef CHROOTED_NAME
@@ -55,4 +56,7 @@
 #undef PROG_UNISON
 #endif
 
-
+/* Initial directory after logging in */
+#ifdef ENABLE_DEFAULT_CHDIR
+#undef DEFAULT_CHDIR
+#endif
diff -ur scponly-3.11-dist/configure scponly-3.11-daniel/configure
--- scponly-3.11-dist/configure	Tue Nov 23 00:29:31 2004
+++ scponly-3.11-daniel/configure	Tue Nov 23 00:19:31 2004
@@ -842,6 +842,10 @@
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-sftp-server      path to sftp-server binary
                           defaults, to, on+guessed
+  --with-default-chdir    cd to this directory after logging in (mimicking
+                          proftpd's DefaultChdir directive). applies only to
+                          "ftp-like" interactive protocols like WinSCP and
+                          sftp, not to scp or rsync
 
 Some influential environment variables:
   CC          C compiler command
@@ -2724,6 +2728,26 @@
               scponly_sftp_compat=1
 
 fi;
+
+
+# Check whether --with-default-chdir or --without-default-chdir was given.
+if test "${with_default_chdir+set}" = set; then
+  withval="$with_default_chdir"
+
+	      cat >>confdefs.h <<\_ACEOF
+#define ENABLE_DEFAULT_CHDIR 1
+_ACEOF
+
+   	      cat >>confdefs.h <<_ACEOF
+#define DEFAULT_CHDIR "$withval"
+_ACEOF
+
+
+else
+
+              echo -n
+fi;
+
 
 # Check whether --enable-winscp-compat or --disable-winscp-compat was given.
 if test "${enable_winscp_compat+set}" = set; then
diff -ur scponly-3.11-dist/configure.in scponly-3.11-daniel/configure.in
--- scponly-3.11-dist/configure.in	Tue Nov 23 00:27:17 2004
+++ scponly-3.11-daniel/configure.in	Tue Nov 23 00:19:14 2004
@@ -108,6 +108,16 @@
               scponly_sftp_compat=1
       ])
 
+AC_ARG_WITH([default-chdir],
+      AC_HELP_STRING([--with-default-chdir], [cd to this directory after logging in (mimicking proftpd's DefaultChdir directive). applies only to "ftp-like" interactive protocols like WinSCP and sftp, not to scp or rsync]),
+      [
+	      AC_DEFINE([ENABLE_DEFAULT_CHDIR])
+   	      AC_DEFINE_UNQUOTED([DEFAULT_CHDIR], ["$withval"]) 
+      ],[
+              echo -n      dnl  Defaults to off, must be turned on explicitly
+      ])
+
+
 AC_ARG_ENABLE([winscp-compat],
       AC_HELP_STRING([--disable-winscp-compat], [disable WinSCP compatibility mode]),
       [
diff -ur scponly-3.11-dist/scponly.c scponly-3.11-daniel/scponly.c
--- scponly-3.11-dist/scponly.c	Tue Nov 23 00:27:08 2004
+++ scponly-3.11-daniel/scponly.c	Tue Nov 23 00:26:43 2004
@@ -292,6 +292,11 @@
 
 	fflush(stdout);
 
+#ifdef ENABLE_DEFAULT_CHDIR
+        syslog(LOG_INFO, "changing initial directory to %s", DEFAULT_CHDIR);
+        chdir(DEFAULT_CHDIR);
+#endif
+	
 	/*
 	 *	now process commands interactively
  	 */
@@ -430,6 +435,14 @@
 	if (exact_match(av[0],PROG_SCP))
 		av = expand_wildcards(av);
 #endif
+#endif
+
+#ifdef ENABLE_DEFAULT_CHDIR
+	if (exact_match(av[0],PROG_SFTP_SERVER))
+	{
+		syslog(LOG_INFO, "changing initial directory to %s", DEFAULT_CHDIR);
+		chdir(DEFAULT_CHDIR);
+	}
 #endif
 
 	flat_request = flatten_vector(av);


More information about the scponly mailing list