home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
MYWIVE.ZIP
/
XFERTMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-06
|
4KB
|
161 lines
#include "vars.h"
#pragma hdrstop
#include <dir.h>
#define SETREC(i) lseek(dlf,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
/* the archive type to use */
#define ARC_NUMBER 0
/* .ZIP structures and defines */
#define ZIP_LOCAL_SIG 0x04034b50
#define ZIP_CENT_START_SIG 0x02014b50
#define ZIP_CENT_END_SIG 0x06054b50
typedef struct {
unsigned long signature; /* 0x04034b50 */
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_length;
} zip_local_header;
typedef struct {
unsigned long signature; /* 0x02014b50 */
unsigned short made_ver;
unsigned short extract_ver;
unsigned short flags;
unsigned short comp_meth;
unsigned short mod_time;
unsigned short mod_date;
unsigned long crc_32;
unsigned long comp_size;
unsigned long uncomp_size;
unsigned short filename_len;
unsigned short extra_len;
unsigned short comment_len;
unsigned short disk_start;
unsigned short int_attr;
unsigned long ext_attr;
unsigned long rel_ofs_header;
} zip_central_dir;
typedef struct {
unsigned long signature; /* 0x06054b50 */
unsigned short disk_num;
unsigned short cent_dir_disk_num;
unsigned short total_entries_this_disk;
unsigned short total_entries_total;
unsigned long central_dir_size;
unsigned long ofs_cent_dir;
unsigned short comment_len;
} zip_end_dir;
/* strings not to allow in a .zip file to extract from */
char *bad_words[] = {
"COMMAND",
"..",
NULL,
};
long bad_filename(char *fn)
{
int i;
strupr(fn);
for (i=0; bad_words[i]; i++) {
if (strstr(fn,bad_words[i])) {
npr("Can't extract from that because it has '%s'.\r\n",fn);
return(1);
}
}
if (!okfn(fn)) {
npr("Can't extract from that because it has '%s'.\r\n",fn);
return(1);
}
return(0);
}
long check_for_files_zip(char *fn)
{
int f;
long l,sig,len;
zip_local_header zl;
zip_central_dir zc;
zip_end_dir ze;
char s[161];
#define READ_FN(ln) {read(f,s,ln); s[ln]=0;}
f=open(fn,O_RDWR | O_BINARY);
if (f>0) {
l=0;
len=filelength(f);
while (l<len) {
lseek(f,l,SEEK_SET);
read(f,&sig, 4);
lseek(f,l,SEEK_SET);
switch(sig) {
case ZIP_LOCAL_SIG:
read(f,&zl, sizeof(zl));
READ_FN(zl.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zl);
l += zl.comp_size + zl.filename_len + zl.extra_length;
break;
case ZIP_CENT_START_SIG:
read(f,&zc, sizeof(zc));
READ_FN(zc.filename_len);
if (bad_filename(s)) {
close(f);
return(1);
}
l += sizeof(zc);
l += zc.filename_len + zc.extra_len;
break;
case ZIP_CENT_END_SIG:
read(f,&ze, sizeof(ze));
close(f);
return(0);
default:
close(f);
npr("Error examining that; can't extract from it.\r\n");
return(1);
}
}
close(f);
return(0);
}
npr("file not found: %s\r\n",fn);
return(1);
}
int check_for_files(char *fn)
{
char *ss;
ss=strrchr(fn,'.');
if (ss) {
if (stricmp(ss+1,"ZIP")==NULL) {
return(check_for_files_zip(fn));
} else if (stricmp(ss+1,"ARC")==NULL) {
/* no processing for .ARC files yet */
} else {
/* unknown archive type; let it through. */
}
} else {
/* no extension? */
npr("No extension.\r\n");
return(1);
}
return(0);
}