Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Mon, 13 Jan 2003 09:36:24 -0500 From: Jason Tishler Subject: Cygwin vsFTPd porting issues To: Cygwin Mail-followup-to: Cygwin Message-id: <20030113143624.GF1012@tishler.net> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_JZOxV2FL9z5wnAM+h1v1gQ)" User-Agent: Mutt/1.4i --Boundary_(ID_JZOxV2FL9z5wnAM+h1v1gQ) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline In my (seemingly) never ending search for a firewall friendly, Cygwin ftpd server, I finally stumbled across vsFTPd. By "firewall friendly," I mean being able to specifying the range of passive ports used during data transfers. Although, vsFTPd does not use autoconf, the code is well factored -- especially the system dependent routines. Hence, it ported to Cygwin without many problems. See the attached patch for the details. The following are the most notable changes: 1. Temporarily workaround a mmap()/fork() problem by effectively replacing vsf_secbuf_alloc() and vsf_secbuf_free() with malloc() and free(), respectively. 2. Add Corinna's standard NT authentication patch. 3. Workaround lack of Cygwin nanosleep(). 4. Workaround lack of Cygwin setregid() and setreuid(). The mmap()/fork() problem workaround is the only "show stopper." When I strace vsftpd, I get the following error: 311 37332969 [main] vsftpd 2232 fixup_mmaps_after_fork: recreate_mmaps_after_fork, mmapped_areas 0xA042100 90 37333059 [main] vsftpd 2232 fixup_mmaps_after_fork: fd -1, h 1F4, access 1, offset 0, size 65536, address 0xB40000 160 37333219 [main] vsftpd 2232 fixup_mmaps_after_fork: ReadProcessMemory failed for MAP_PRIVATE address 0xB40000, Win32 error 299 I will try to dig deeper to determine why ReadProcessMemory() is failing with ERROR_PARTIAL_COPY (i.e., 299), but any help or pointers will be greatly appreciated. Thanks, Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 --Boundary_(ID_JZOxV2FL9z5wnAM+h1v1gQ) Content-type: text/plain; charset=us-ascii; NAME=vsftpd.patch Content-transfer-encoding: 7BIT Content-disposition: attachment; filename=vsftpd.patch diff -rup vsftpd-1.1.3.orig/Makefile vsftpd-1.1.3/Makefile --- vsftpd-1.1.3.orig/Makefile 2002-10-21 19:15:16.000000000 -0400 +++ vsftpd-1.1.3/Makefile 2003-01-13 07:56:22.000000000 -0500 @@ -22,6 +22,8 @@ OBJS = main.o utility.o prelogin.o ftpcm vsftpd: $(OBJS) $(CC) -o vsftpd $(OBJS) $(LINK) $(LIBS) +.PHONY: install + install: if [ -x /usr/local/sbin ]; then \ $(INSTALL) -m 755 vsftpd /usr/local/sbin/vsftpd; \ diff -rup vsftpd-1.1.3.orig/port/porting_junk.h vsftpd-1.1.3/port/porting_junk.h --- vsftpd-1.1.3.orig/port/porting_junk.h 2002-09-25 14:16:24.000000000 -0400 +++ vsftpd-1.1.3/port/porting_junk.h 2003-01-13 08:12:35.000000000 -0500 @@ -21,6 +21,10 @@ #include "tru64_bogons.h" #endif +#ifdef __CYGWIN__ +#include "cygwin_bogons.h" +#endif + /* So many older systems lack these, that it's too much hassle to list all * the errant systems */ diff -rup vsftpd-1.1.3.orig/secbuf.c vsftpd-1.1.3/secbuf.c --- vsftpd-1.1.3.orig/secbuf.c 2001-04-22 18:15:37.000000000 -0400 +++ vsftpd-1.1.3/secbuf.c 2003-01-10 14:51:41.000000000 -0500 @@ -14,6 +14,21 @@ #include "sysutil.h" #include "sysdeputil.h" +#ifdef __CYGWIN__ +#include + +void +vsf_secbuf_alloc(char** p_ptr, unsigned int size) +{ + *p_ptr = (char*) malloc(size); +} + +void +vsf_secbuf_free(char** p_ptr) +{ + free(*p_ptr); +} +#else void vsf_secbuf_alloc(char** p_ptr, unsigned int size) { @@ -86,4 +101,4 @@ vsf_secbuf_free(char** p_ptr) /* Lose the mapping */ vsf_sysutil_memunmap(p_mmap, map_size); } - +#endif diff -rup vsftpd-1.1.3.orig/sysdeputil.c vsftpd-1.1.3/sysdeputil.c --- vsftpd-1.1.3.orig/sysdeputil.c 2002-10-29 20:06:41.000000000 -0500 +++ vsftpd-1.1.3/sysdeputil.c 2003-01-13 08:25:39.000000000 -0500 @@ -99,6 +99,14 @@ #ifdef __sun #define VSF_SYSDEP_HAVE_SOLARIS_SENDFILE #endif + +#ifdef __CYGWIN__ + #define VSF_SYSDEP_NEED_OLD_FD_PASSING + #undef VSF_SYSDEP_HAVE_PAM + #undef VSF_SYSDEP_HAVE_SHADOW + #undef VSF_SYSDEP_HAVE_USERSHELL + #include +#endif /* END config */ /* PAM support - we include our own dummy version if the system lacks this */ @@ -220,6 +228,14 @@ vsf_sysdep_check_auth(const struct mystr } } #endif /* VSF_SYSDEP_HAVE_SHADOW */ +#ifdef __CYGWIN__ + if (is_winnt) + { + HANDLE token = cygwin_logon_user (p_pwd, str_getbuf(p_pass_str)); + cygwin_set_impersonation_token (token); + return token != INVALID_HANDLE_VALUE; + } +#endif p_crypted = crypt(str_getbuf(p_pass_str), p_pwd->pw_passwd); if (!vsf_sysutil_strcmp(p_crypted, p_pwd->pw_passwd)) { diff -rup vsftpd-1.1.3.orig/sysutil.c vsftpd-1.1.3/sysutil.c --- vsftpd-1.1.3.orig/sysutil.c 2002-10-25 13:32:52.000000000 -0400 +++ vsftpd-1.1.3/sysutil.c 2003-01-13 08:18:34.000000000 -0500 @@ -15,6 +15,7 @@ #include "sysutil.h" #include "utility.h" #include "tunables.h" +#include "defs.h" /* Activate 64-bit file support on Linux/32bit */ #define _FILE_OFFSET_BITS 64 @@ -1806,7 +1807,7 @@ vsf_sysutil_get_random_byte(void) int vsf_sysutil_running_as_root(void) { - return (getuid() == 0); + return (getuid() == VSFTP_ROOT_UID); } void @@ -2021,10 +2022,13 @@ vsf_sysutil_qsort(void* p_base, unsigned { qsort(p_base, num_elem, elem_size, p_compar); } - void vsf_sysutil_sleep(double seconds) { +#ifdef __CYGWIN__ + sleep(seconds); + vsf_sysutil_check_pending_actions(kVSFSysUtilUnknown, 0, 0); +#else int retval; double fractional; time_t secs; @@ -2038,6 +2042,7 @@ vsf_sysutil_sleep(double seconds) retval = nanosleep(&ts, &ts); vsf_sysutil_check_pending_actions(kVSFSysUtilUnknown, 0, 0); } while (retval == -1 && errno == EINTR); +#endif } char* diff -rup vsftpd-1.1.3.orig/twoprocess.c vsftpd-1.1.3/twoprocess.c --- vsftpd-1.1.3.orig/twoprocess.c 2002-10-25 13:28:25.000000000 -0400 +++ vsftpd-1.1.3/twoprocess.c 2003-01-13 08:15:02.000000000 -0500 @@ -24,6 +24,9 @@ #include "defs.h" #include "parseconf.h" +/* For Linux, this adds nothing :-) */ +#include "port/porting_junk.h" + static void drop_all_privs(void); static void handle_sigchld(int duff); static void process_login_req(struct vsf_session* p_sess); diff -rup vsftpd-1.1.3.orig/vsf_findlibs.sh vsftpd-1.1.3/vsf_findlibs.sh --- vsftpd-1.1.3.orig/vsf_findlibs.sh 2002-10-27 19:12:53.000000000 -0500 +++ vsftpd-1.1.3/vsf_findlibs.sh 2003-01-13 07:55:44.000000000 -0500 @@ -35,6 +35,8 @@ elif [ -r /etc/redhat-release ]; then echo "-lcap"; fi exit +elif [ -x /usr/bin/cygwin1.dll ]; then + echo "-lcrypt" fi # Look for PAM (done weirdly due to distribution bugs (e.g. Debian) diff -rupN vsftpd-1.1.3.orig/port/cygwin_bogons.h vsftpd-1.1.3/port/cygwin_bogons.h --- vsftpd-1.1.3.orig/port/cygwin_bogons.h 1969-12-31 19:00:00.000000000 -0500 +++ vsftpd-1.1.3/port/cygwin_bogons.h 2003-01-13 08:26:25.000000000 -0500 @@ -0,0 +1,16 @@ +#ifndef VSF_CYGWIN_BOGONS_H +#define VSF_CYGWIN_BOGONS_H + +#include +#include +#include + +#undef VSFTP_ROOT_UID +#define VSFTP_ROOT_UID 18 + +#define setreuid(dummy, uid) seteuid(uid) +#define setregid(dummy, gid) setegid(gid) + +#define is_winnt (GetVersion() < 0x80000000) + +#endif /* VSF_CYGWIN_BOGONS_H */ --Boundary_(ID_JZOxV2FL9z5wnAM+h1v1gQ) Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --Boundary_(ID_JZOxV2FL9z5wnAM+h1v1gQ)--