Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.kei.com!news.mathworks.com!tank.news.pipex.net!pipex!howland.reston.ans.net!vixen.cso.uiuc.edu!uwm.edu!homer.alpha.net!usenet From: Dean Roth <Dean_Roth@mgic.com> Newsgroups: comp.unix.bsd.bsdi.misc Subject: Re: Multi homed FTP Date: 2 Oct 1995 21:19:36 GMT Organization: MGIC Lines: 158 Message-ID: <44pl18$f15@homer.alpha.net> References: <44odl2$g34@server05.icaen.uiowa.edu> <44on48$4dv@homer.alpha.net> <44p3ec$51h@news.cais.com> NNTP-Posting-Host: mgic7.mgic.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="-------------------------------16883324488340" X-Mailer: Mozilla 1.2N (Windows; I; 16bit) To: jsloan@livnet.com This is a multi-part message in MIME format. ---------------------------------16883324488340 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii jsloan@livnet.com (Jim Sloan) wrote: >In article <44on48$4dv@homer.alpha.net>, Dean Roth <Dean_Roth@mgic.com> wrote: >>dmorschh@ecn.uiowa.edu () wrote: >Dean, > could you please give the rest of us the patch that you did to wuftpd to >allow it to support virtual domains? This would be most helpful. Or even >just the lines that you changed in the source. See below. I hope you like C programming :-) Dean ---------------------------------16883324488340 Content-Transfer-Encoding: 7bit Content-Type: text/plain You need wu-ftpd source code. 1. If you have source code from BSDI you are in luck. Skip to step 3. 2. Bad news. You don't already have source code. I hope you are a good C programmer. Get a copy of ftpd from wuarchive.wustl.edu . You MUST change the code to use quad words in a few places rather than longs. This is a messy operation. If you cannot do C programming, and/or do not understand the difference between int, long and quad, forget it. offset_t in BSDI is a quad, and parts of the code (s/f/printf) need to be changed or ftpd will core dump. Why don't I just give you some diffs? Because I've made other mods to ftpd to integrate it with a customer database that you wouldn't want, and couldn't use even if you had them. 3. Below is vhost.c. Add it to ftpd's makefile. It expects to find file etc/vhosts in ftpd's directory. NOTE: not /etc/vhosts, but ftpd's etc directory. vhosts has the format: IP directory An example is shown below. 1.2.3.4 pub/foobar This example is for ftp.foobar.com . When a connection is made to that virtual host the code attached below looks up 1.2.3.4, the IP associated with ftp.foobar.com, and changes to directory pub/foobar . Users can use "cd" to move backward in the directory hierarchy. The space between the IP number and directory name can be spaces and/or tabs. ---vhost.c--- #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/syslog.h> static int get_local_addr(int sd, struct in_addr *out) { struct sockaddr addr; int len; len = sizeof(struct sockaddr); if(getsockname(sd,&addr,&len) < 0) { return(-1); } /*return ((struct sockaddr_in *)&addr)->sin_addr; /**/ *out = ((struct sockaddr_in *)&addr)->sin_addr; return(0); } check_virtual_host(int sock) { int status; struct in_addr in; FILE *fptr; char ip[256]; char buff[4096]; status = get_local_addr(0, &in); if (status == 0) { strcpy(ip, inet_ntoa(in)); syslog(LOG_INFO, "Host IP = [%s]", ip); } else syslog(LOG_INFO, "Host IP unknown"); fptr = fopen("etc/vhosts", "r"); if (!fptr) return(-1); while (fgets(buff, sizeof(buff), fptr)) { char *dir_name; strtok(buff, " \t"); /* IP number */ dir_name = strtok((char *)NULL, " \t\n"); if (strcmp(ip, buff) == 0) { chdir(dir_name); break; } } fclose(fptr); } ---ftpd.c--- 4. Modify ftpd.c. Find an area of the code that looks like the example shown below. expand_id(); if (anonymous || guest) { /* We MUST do a chdir() after the chroot. Otherwise the old current * directory will be accessible as "." outside the new root! */ if (anonymous) { if (chroot(pw->pw_dir) < 0 || chdir("/") < 0) { reply(550, "Can't set guest privileges."); goto bad; } /* *********************************************** */ /* GET (VIRTUAL) HOST IP AND CHANGE TO THAT SUBDIR */ /* *********************************************** */ check_virtual_host(); } Add the "check_virtual_host()" function as indicated, AFTER the chroot().