/* -------------------------------------------------
* g2fd.c Gopher to FTP gateway daemon.
* Version 0.3 Hacked up: April 1992. Farhad Anklesaria.
* Based on a Perl story by John Ladwig.
* Based on a Perl story by Farhad Anklesaria.
*
* To be run by inetd.
* For installation, read the companion README.... or
* if you don't feel like doing that, the brief instructions
* are below:
*
* First edit the local parameters in defines below.
* Then do a "make g2fd"
* Then place the binary (g2fd) in some reasonable place,
* eg in /usr/local/bin
* Finally, edit /etc/services and /etc/servers or
* /etc/inetd.conf as the case may be. Kill
* and restart inetd.
*
* This file looks best with tabstops set to 4 rather than 8.
---------------------------------------------------- */
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
/*==============Local parameters to be edited in===============*/
#define LOCALHOST "hell.micro.umn.edu" /* This host's domain name */
#define LOCALPORT 70 /* This daemon's port */
#define MAXLOAD 8.0 /* For load limit if > 1 */
#define FTP "/usr/ucb/ftp" /* To invoke ftp */
#define UPTIME "/usr/ucb/uptime" /* To check loadavg. Ick. */
#define LIST "/tmp/gftpL+" /* Temp list file prefix */
#define DATA "/tmp/gftpD+" /* Temp data file prefix */
/*=============================================================*/
if ((childpid = fork()) == -1) {
Abort("Can't fork.");
} else if (childpid != 0) { /* We are the parent and we wait*/
WaitForChild();
}
/* If we get here we are the child and we can do some work */
signal(SIGPIPE, Cleanup); /* This and the extra fork is paranoia */
if (LoadTooHigh())
Abort("Too many connections. Try again later.");
gets(query); /* Courtesy of inetd */
last = strlen(buf) - 1; buf[last--] = '\0'; /* Munge the LF */
strcpy(tmpName, buf);
if (buf[last] == '/') {
tmpName[last] = '\0';
sprintf(theName, "%d%s", GDIR, tmpName);
return;
}
if ((buf[last] == '*') || (buf[last] == '@')) { /* Hack out * and @ */
buf[last] = '\0';
tmpName[last] = '\0';
}
/* At this point we're looking at a file */
if (strcasecmp(buf + strlen(buf) - strlen(ext4), ext4) == 0) { /* BinHex? */
sprintf(theName, "%d%s", GBINHEX, tmpName);
return;
}
for (extType = 0; extType < 15; extType++) { /* PC garbage? */
i = strcasecmp(buf + strlen(buf) - strlen(ext5[extType]),
ext5[extType]);
if (i == 0) {
sprintf(theName, "%d%s", GDOSB, tmpName);
return;
}
}
for (extType = 0; extType < 2; extType++) { /* unix binary? */
i = strcasecmp(buf + strlen(buf) - strlen(ext9[extType]),
ext9[extType]);
if (i == 0) {
sprintf(theName, "%d%s", GUNIXB, tmpName);
return;
}
}
sprintf(theName, "%d%s", GFILE, tmpName);
return; /* Some other and hopefully text file */
}