home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
mail
/
smail
/
src
/
rcs
/
bsmtp.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
15KB
|
844 lines
head 1.11;
access;
symbols
C_1:1.11;
locks; strict;
comment @ * @;
1.11
date 93.11.14.21.01.46; author Aussem; state Exp;
branches;
next 1.10;
1.10
date 93.11.13.22.13.56; author Aussem; state Exp;
branches;
next 1.9;
1.9
date 93.11.12.23.09.33; author Aussem; state Exp;
branches;
next 1.8;
1.8
date 93.11.09.17.00.22; author Aussem; state Exp;
branches;
next 1.7;
1.7
date 93.11.01.23.21.53; author Aussem; state Exp;
branches;
next 1.6;
1.6
date 93.10.28.23.31.15; author Aussem; state Exp;
branches;
next 1.5;
1.5
date 93.10.28.21.21.08; author Aussem; state Exp;
branches;
next 1.4;
1.4
date 93.10.23.22.46.59; author Aussem; state Exp;
branches;
next 1.3;
1.3
date 93.10.19.00.36.33; author Aussem; state Exp;
branches;
next 1.2;
1.2
date 93.10.17.23.23.47; author Aussem; state Exp;
branches;
next 1.1;
1.1
date 93.10.17.21.13.56; author Aussem; state Exp;
branches;
next ;
desc
@SMTP transport routines
@
1.11
log
@commtents insert
@
text
@/*
* bsmtp for smail/rmail
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Log: bsmtp.c,v $
* Revision 1.10 1993/11/13 22:13:56 Aussem
* check_site() generates only debug lines if the paramter debug is != No
* if there is no From line in the BSMTP mail convert_smtp will
* generate one
*
* Revision 1.9 1993/11/12 23:09:33 Aussem
* check_site does not care about case of the site
* in BSMTP file
* cosmetic changes in debug/advise output
*
* Revision 1.8 1993/11/09 17:00:22 Aussem
* cosmetic changes
*
* Revision 1.7 1993/11/01 23:21:53 Aussem
* fmode() call removed
*
* Revision 1.6 1993/10/28 23:31:15 Aussem
* converting \n to \r\n by using fmode() when receiving BSMTP mails
*
* Revision 1.5 1993/10/28 21:21:08 Aussem
* check_bsmtp() security check insert
*
* Revision 1.4 1993/10/23 22:46:59 Aussem
* the file for bsmtp sites is taken from uulib:config
*
* Revision 1.3 1993/10/19 00:36:33 Aussem
* check whether a site is a bsmtp site included
* hide_dot() implemented
*
* Revision 1.2 1993/10/17 23:23:47 Aussem
* removed the HELO line from write_bsmtp_prolog
*
* Revision 1.1 1993/10/17 21:13:56 Aussem
* Initial revision
*
*
*
*/
static char *rcsid="$Id: bsmtp.c,v 1.10 1993/11/13 22:13:56 Aussem Exp Aussem $";
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "defs.h"
#include <ctype.h>
extern char hostname[]; /* our host's name */
extern int debug;
extern char bsmtp_sites[];
extern char nows[];
extern char rmailname[];
/* Macros for Checking the compress type */
#define CHECK_FREEZE(buf) ((buf[0]=='0x1f' && buf[1]=='0x9f')?1:0)
#define CHECK_COMPRESS(buf) ((buf[0]=='0x1f' && buf[1]=='0x9d')?1:0)
#define CHECK_GZIP(buf) ((buf[0]=='0x1f' && buf[1]=='0x8b')?1:0)
/*
* setup_fromline(): generate a RFC conform from line
*
* params: address of the sender and the system
*
*/
static
void
setup_fromline(char *from,char *systemname)
{
char user[SMLBUF]; /* for rewriting user@@host */
char domain[SMLBUF]; /* " " " */
char addr[SMLBUF]; /* " " " */
enum eform form; /* " " " */
char buf[BIGBUF];
strcpy(addr, from);
(void) parse(addr, domain, user);
if(*domain == '\0') {
form = LOCAL;
} else {
form = UUCP;
}
build(domain, user, form, addr);
(void) strcpy(from, addr);
setdates();
sprintf(buf,RFROM(from,nows,systemname));
strcpy(from,buf);
}
/*
* write_bsmtp_prologue - write the initial SMTP commands for BSMTP transports
*
* write out the MAIL FROM line
*
*/
write_bsmtp_prologue(f,from)
FILE *f; /* file to write commands to */
char *from;
{
assert(f);
fprintf(f, "MAIL FROM:<%s!%s>\n",hostname, from);
}
/*
* write_bsmtp_epilogue - write tailing commands for BSMTP transports
*
* finish off the data command and write out the QUIT command.
*
*/
write_bsmtp_epilogue(f)
FILE *f;
{
assert(f);
fprintf(f, ".\n");
fprintf(f, ".\nQUIT\n");
}
/*
* uncompress_stream()
*
* uncompress a stream with cmd <tmp_from_stream >tmp
* and returns a FILE ptr to the uncompressed file
*
*/
FILE *uncompress_stream(FILE *fp,char cmd[])
{
char *text;
char tmpfile[SMLBUF],outfile[SMLBUF],line[SMLBUF];
FILE *out;
int rc;
size_t len;
if(!fp)
{
ADVISE("uncompress_stream: stream is null '%x'\n",fp);
return(NULL);
}
fseek(fp,0,SEEK_END);
len=ftell(fp);
if(len==0)
{
return(fp);
}
fseek(fp,0,SEEK_SET);
text=malloc(len*sizeof(char));
if(!text)
{
ADVISE("uncompress_stream: no memory for text '%x'\n",text);
return(NULL);
}
fread(text,len,1,fp);
if(strncmp(text,"HELO ",5)==0)
{
DEBUG("mail not compress, continue\n");
fseek(fp,0,SEEK_SET);
return(fp);
}
ADVISE("uncompressing...");
strcpy(tmpfile,tmpnam(NULL));
out=fopen(tmpfile,"wb");
if(!out)
{
DEBUG("\nunable to open tmpfile %s\n",tmpfile);
return(NULL);
}
fwrite(text,len,1,out);
fclose(out);
if(text)
free(text);
strcpy(outfile,tmpnam(NULL));
sprintf(line,"%s -d <%s >%s",cmd,tmpfile,outfile);
DEBUG("\ncmd: %s",line);
rc=system(line);
if(rc)
{
DEBUG("\nuncompressing failed ('%s')\n",line);
remove(tmpfile);
remove(outfile);
return(0);
}
remove(tmpfile);
ADVISE("\n");
return(fopen(outfile,"rb"));
}
/*
* uncompress_file()
*
* uncompress a file with cmd <name >tmp
* and replace name with the uncompressed
* file
*/
int uncompress_file(char *name,char cmd[])
{
char outfile[SMLBUF],line[SMLBUF];
int rc;
ADVISE("uncompressing...");
strcpy(outfile,tmpnam(NULL));
sprintf(line,"%s -d <%s >%s",cmd,name,outfile);
DEBUG("\ncmd: %s",line);
rc=system(line);
if(rc)
{
DEBUG("\nuncompressing failed ('%s')\n",line);
remove(outfile);
return(0);
}
sprintf(line,"copy %s %s",outfile,name);
rc=system(line);
remove(outfile);
ADVISE("\n");
return(1);
}
/*
* convert_smtp()
*
* converts a SMTP mail into UUCP mails and call rmail to
* deliver them via rmail
*
*/
convert_smtp(FILE *fp)
{
char line[BIGBUF],tmpname[SMLBUF],cmd[BIGBUF],puf[BIGBUF],
fromline[SMLBUF];
char *begin,*end,*result,*systemname;
FILE *out=NULL;
size_t msg,pos;
if(!fp)
return;
ADVISE("converting BSMTP file...");
strcpy(tmpname,tmpnam(NULL));
/* get the first line and check for HELO */
result=fgets(line,sizeof(line),fp);
if(!result)
goto error;
if(strncmp(line,"HELO ",5)!=0)
{
DEBUG("\nfile not in SMTP format aborting !\n");
return;
}
/* Save the systemname */
end=index(&line[5],'\n');
if(end)
*end='\0';
systemname=strdup(&line[5]);
ADVISE("\nReceiving mails from '%s'\n",systemname);
/* init dates */
setdates();
/* Read the first line */
result=fgets(line,sizeof(line),fp);
if(!result)
goto error;
do
{
/* search the MAIL FROM: line */
if(strncmp(line,"MAIL FROM:",10)!=0)
goto error;
msg=ftell(fp);
/* Extracting the sender */
begin=index(line,'<');
end=rindex(line,'>');
if(begin && end)
{
*end='\0';
strcpy(puf,begin+1);
*end='>';
}
if(debug==VERBOSE)
printf("\nFrom: %s\n",puf);
/* open the tmpfile */
out=fopen(tmpname,"w");
if(!out)
{
ADVISE("\nunable to open '%s'\n",tmpname);
goto error;
}
/* remove \n from nows */
strcpy(line,nows);
end=index(line,'\n');
if(end)
*end='\0';
/* setup the fromline */
setup_fromline(puf,systemname);
strcpy(fromline,puf);
while((result=fgets(line,sizeof(line),fp))!=NULL)
if(strncmp(line,"DATA\n",5)==0)break;
if(!result)
goto error;
/* Check whether we have a From user date remote system line */
result=fgets(line,sizeof(line),fp);
/* WE have no From line */
if(strncmp(line,"From ",5)!=NULL)
{
fputs(fromline,out);
if(debug==YES)
fputs(fromline,stdout);
}
do {
if(strncmp(line,".\n",5)==0)break;
/* remove the hidden dots */
if(strncmp(line,"..\n",5)==0)
{
fputs(".\n",out);
if(debug==YES)
fputs(".\n",stdout);
continue;
}
fputs(line,out);
if(debug==YES)
fputs(line,stdout);
}while((result=fgets(line,sizeof(line),fp))!=NULL);
if(!result)
goto error;
pos=ftell(fp);
fclose(out);
fseek(fp,msg,SEEK_SET);
while((result=fgets(line,sizeof(line),fp))!=NULL)
{
if(strncmp(line,"DATA\n",5)==0)break;
begin=index(line,'<');
if(begin)
{
end=rindex(++begin,'>');
if(end)
*end='\0';
sprintf(cmd,"%s <%s %s %s",rmailname,tmpname,VFLAG,begin);
DEBUG("\ncmd: '%s'\n",cmd);
if(debug != YES)
system(cmd);
}
}
if(!result)
goto error;
fseek(fp,pos,SEEK_SET);
result=fgets(line,sizeof(line),fp);
if(!result)
goto error;
}
while(strcmp(line,"QUIT\n")!=0);
ADVISE("\n");
remove(tmpname);
return;
error:
if(out)fclose(out);
DEBUG("Corrupt SMTP Format, aborting\n");
remove(tmpname);
}
/*
* check_site()
*
* check whether site is in uulib:mail/bsmtp_sites
*
*/
int check_site(char site[],enum edebug debug)
{
static char *text=NULL;
char puf[SMLBUF]="\n",*found;
if(!site ||
site[0]=='\0')
return(0);
ADVISE("BSMTP_check: seaching site '%s' in '%s' ",site,bsmtp_sites);
if(!text)
{
FILE *fp=NULL;
size_t pos;
fp=fopen(bsmtp_sites,"r");
if(!fp)
{
ADVISE("check_site: BSMTP file open('%s') failed\n", bsmtp_sites);
return(0);
}
fseek(fp,0,SEEK_END);
pos=ftell(fp);
if(pos<1)
{
ADVISE("check_site: BSMTP file is ('%s') empty\n", bsmtp_sites);
return(0);
}
fseek(fp,0,SEEK_SET);
text=malloc(pos*sizeof(char));
if(!text)
{
ADVISE("check_site: unable to alloc %d bytes\n", pos);
return(0);
}
fread(text,pos,1,fp);
fclose(fp);
/* case insenstiv please */
strlwr(text);
}
strcat(puf,site);
strcat(puf,"\n");
/* case insenstiv please */
strlwr(puf);
if(strstr(text,puf))
{
ADVISE("found\n");
return(1);
}
/* if the file starts with this site there is no \n at the begin */
strcpy(puf,site);
strcat(puf,"\n");
found=strstr(text,puf);
if(found==text)
{
ADVISE("found\n");
return(1);
}
ADVISE("not found\n");
return(0);
}
/*
* hide_dot()
*
* hide a dot behind a double dot
*
*/
void hide_dot(char *line,size_t max_len)
{
size_t act_len;
if(!line || line[0]!='.')
return;
act_len=strlen(line);
if(act_len+1<max_len)
{
strins(line+1,".");
}
else
DEBUG("hide_dot: unable to hide .dot in line '%s'\n",line);
}
/*
* re_hide_dot()
*
* remove the hidden dot
*
*/
void re_hide_dot(char *line)
{
if(!line || line[0]!='.' || line[1]!='.')
return;
strcpy(&line[0],&line[1]);
}
@
1.10
log
@check_site() generates only debug lines if the paramter debug is != No
if there is no From line in the BSMTP mail convert_smtp will
generate one
@
text
@d20 5
d59 1
a59 1
static char *rcsid="$Id: bsmtp.c,v 1.9 1993/11/12 23:09:33 Aussem Exp Aussem $";
d76 1
d84 2
d116 2
a117 1
* write out the HELO, MAIL FROM, RCPT TO and DATA commands.
a118 1
d131 1
d251 1
a251 1
* deliver them
a508 1
@
1.9
log
@check_site does not care about case of the site
in BSMTP file
cosmetic changes in debug/advise output
@
text
@d20 5
d54 1
a54 1
static char *rcsid="$Id: bsmtp.c,v 1.8 1993/11/09 17:00:22 Aussem Exp Aussem $";
d67 3
d76 30
d247 3
a249 2
char line[BIGBUF],tmpname[SMLBUF],cmd[BIGBUF];
char *begin,*end,*result;
d270 11
a280 1
ADVISE("\nfrom %s",&line[5]);
d290 1
d292 9
a300 1
msg=ftell(fp);
d302 2
a303 4
while((result=fgets(line,sizeof(line),fp))!=NULL)
if(strncmp(line,"DATA\n",5)==0)break;
if(!result)
goto error;
d305 1
d310 1
a310 1
return;
d313 10
d324 8
d333 6
d344 2
d349 4
a352 1
}
d369 1
a369 1
sprintf(cmd,"rmail <%s %s %s",tmpname,VFLAG,begin);
d384 1
d401 1
a401 1
int check_site(char site[])
d500 1
@
1.8
log
@cosmetic changes
@
text
@d20 3
d49 1
a49 1
static char *rcsid="$Id: bsmtp.c,v 1.7 1993/11/01 23:21:53 Aussem Exp Aussem $";
d111 1
a111 1
ADVISE("stream is null '%x'\n",fp);
d126 1
a126 1
ADVISE("no memory for text '%x'\n",text);
d284 1
a284 1
DEBUG("\nexecute '%s'\n",cmd);
d332 1
a332 1
ADVISE("BSMTP file open('%s') failed\n", bsmtp_sites);
d339 1
a339 1
ADVISE("BSMTP file is ('%s') empty\n", bsmtp_sites);
d346 1
a346 1
ADVISE("unable to alloc %d bytes\n", pos);
d351 2
d356 2
d397 1
a397 1
DEBUG("unable to hide .dot in line '%s'\n",line);
@
1.7
log
@fmode() call removed
@
text
@d20 3
d46 1
a46 1
static char *rcsid="$Id: bsmtp.c,v 1.6 1993/10/28 23:31:15 Aussem Exp Aussem $";
d108 1
a108 1
ADVISE("stream is zero %x\n",fp);
d123 1
a123 1
ADVISE("no memory for text %x\n",text);
d353 1
a353 1
ADVISE("found\n",site);
d362 1
a362 1
ADVISE("found\n",site);
d366 1
a366 1
ADVISE("not found\n",site);
@
1.6
log
@converting \n to \r\n by using fmode() when receiving BSMTP mails
@
text
@d20 3
d43 1
a43 1
static char *rcsid="$Id: bsmtp.c,v 1.5 1993/10/28 21:21:08 Aussem Exp Aussem $";
a210 1
fmode(fp,0);
d278 1
a278 1
DEBUG("\nexecute '%s'",cmd);
d283 1
a283 1
if(!result)
@
1.5
log
@check_bsmtp() security check insert
@
text
@d20 3
d40 1
a40 1
static char *rcsid="$Id: bsmtp.c,v 1.4 1993/10/23 22:46:59 Aussem Exp Aussem $";
d208 1
@
1.4
log
@the file for bsmtp sites is taken from uulib:config
@
text
@d20 3
d37 1
a37 1
static char *rcsid="$Id: bsmtp.c,v 1.3 1993/10/19 00:36:33 Aussem Exp Aussem $";
d306 4
@
1.3
log
@check whether a site is a bsmtp site included
hide_dot() implemented
@
text
@d20 4
d34 1
a34 1
static char *rcsid="$Id: bsmtp.c,v 1.2 1993/10/17 23:23:47 Aussem Exp Aussem $";
d46 1
d296 1
a296 1
* check whether site is in BSMTPSITES
d304 1
a304 1
DEBUG("seaching '%s'",site);
d310 1
a310 1
fp=fopen(BSMTPSITES,"r");
d313 1
a313 1
DEBUG("\nBSMTP file open('%s') failed\n", BSMTPSITES);
d320 1
a320 1
DEBUG("\nBSMTP file is ('%s') empty\n", BSMTPSITES);
d327 1
a327 1
DEBUG("\nunable to alloc %d bytes\n", pos);
d337 1
a337 1
DEBUG("found\n",site);
d346 1
a346 1
DEBUG("found\n",site);
d350 1
a350 1
DEBUG("not found\n",site);
@
1.2
log
@removed the HELO line from write_bsmtp_prolog
@
text
@d20 3
d30 1
a30 1
static char *rcsid="$Id: bsmtp.c,v 1.1 1993/10/17 21:13:56 Aussem Exp Aussem $";
d286 98
@
1.1
log
@Initial revision
@
text
@d19 3
a21 1
* $Log:$
d24 1
d27 1
a27 1
static char *rcsid="$Id$";
a36 1
extern char hostdomain[]; /* our host's domain */
a54 1
fprintf(f, "HELO %s\n",hostdomain);
@