Annotation of sbbs/sbbs2/smm/smb2smm.c, revision 1.1.1.2

1.1       root        1: /* SMB2SMM */
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: /* Scans SMB message base for messages to "SMM" and adds them to the SMM    */
                      6: /* database. */
                      7: 
                      8: #define  uint unsigned int
                      9: 
                     10: #define LOOP_NOPEN 500
                     11: 
                     12: #include <dos.h>
                     13: #include "smblib.h"
                     14: #include "smmdefs.h"
                     15: #include "nodedefs.h"
                     16: #include "crc32.h"
                     17: 
                     18: #define VERSION "2.01"
                     19: 
                     20: extern int daylight=0;
                     21: extern long timezone=0L;
                     22: 
                     23: unsigned _stklen=16000;                  /* Set stack size in code, not header */
                     24: 
                     25: char data_dir[128];
                     26: 
                     27: smb_t smb;
                     28: FILE *trashfile=NULL;
                     29: 
                     30: uchar cryptchar(uchar ch, ulong seed)
                     31: {
                     32: if(ch==0xfe)
                     33:        return(1);
                     34: if(ch<0x20 || ch&0x80) /* Ctrl chars and ex-ASCII are not xlated */
                     35:        return(ch);
                     36: return(ch^(seed&0x1f));
                     37: }
                     38: 
                     39: void decrypt(char *str, ulong seed)
                     40: {
                     41:        char out[1024];
                     42:        int i,j;
                     43: 
                     44: j=strlen(str);
                     45: for(i=0;i<j;i++)
                     46:        out[i]=cryptchar(str[i],seed^(i&7));
                     47: out[i]=0;
                     48: strcpy(str,out);
                     49: }
                     50: 
                     51: /****************************************************************************/
                     52: /* Returns 32-crc of string (not counting terminating NULL)                            */
                     53: /****************************************************************************/
                     54: ulong crc32(char *str)
                     55: {
                     56:        int i=0;
                     57:        ulong crc=0xffffffffUL;
                     58: 
                     59:        while(str[i])
                     60:                crc=ucrc32(str[i++],crc);
                     61:        crc=~crc;
                     62:        return(crc);
                     63: }
                     64: 
                     65: /***************************************************************************/
                     66: /* Truncates white-space chars off end of 'str' and terminates at first CR  */
                     67: /****************************************************************************/
                     68: void truncsp(char *str)
                     69: {
                     70:        char c;
                     71: 
                     72: str[strcspn(str,"\r")]=0;
                     73: c=strlen(str);
                     74: while(c && (uchar)str[c-1]<=SP) c--;
                     75: str[c]=0;
                     76: }
                     77: 
                     78: /****************************************************************************/
                     79: /* Converts an ASCII Hex string into an ulong                       */
                     80: /****************************************************************************/
                     81: ulong ahtoul(char *str)
                     82: {
                     83:        ulong l,val=0;
                     84: 
                     85: while(*str>' ' && (l=(*str++)|0x20)!=0x20)
                     86:        val=(l&0xf)+(l>>6&1)*9+val*16;
                     87: return(val);
                     88: }
                     89: 
                     90: 
                     91: /****************************************************************************/
                     92: /* Checks the disk drive for the existence of a file. Returns 1 if it       */
                     93: /* exists, 0 if it doesn't.                                                 */
                     94: /****************************************************************************/
                     95: char fexist(char *filespec)
                     96: {
                     97:     struct ffblk f;
                     98: 
                     99: if(findfirst(filespec,&f,0)==0)
                    100:     return(1);
                    101: return(0);
                    102: }
                    103: 
                    104: /****************************************************************************/
                    105: /* Returns the length of the file in 'filespec'                             */
                    106: /****************************************************************************/
                    107: long flength(char *filespec)
                    108: {
                    109:     struct ffblk f;
                    110: 
                    111: if(findfirst(filespec,&f,0)==0)
                    112:     return(f.ff_fsize);
                    113: return(-1L);
                    114: }
                    115: 
                    116: 
                    117: /****************************************************************************/
                    118: /* Converts a date string in format MM/DD/YY into unix time format                     */
                    119: /****************************************************************************/
                    120: time_t dstrtounix(char *str)
                    121: {
                    122:        struct date date;
                    123:        struct time curtime;
                    124: 
                    125: if(!strncmp(str,"00/00/00",8))
                    126:        return(0);
                    127: curtime.ti_hour=curtime.ti_min=curtime.ti_sec=0;
1.1.1.2 ! root      128: if(str[6]<'7')
1.1       root      129:        date.da_year=2000+((str[6]&0xf)*10)+(str[7]&0xf);
                    130: else
                    131:        date.da_year=1900+((str[6]&0xf)*10)+(str[7]&0xf);
                    132: date.da_mon=((str[0]&0xf)*10)+(str[1]&0xf);
                    133: date.da_day=((str[3]&0xf)*10)+(str[4]&0xf);
                    134: return(dostounix(&date,&curtime));
                    135: }
                    136: 
                    137: /****************************************************************************/
                    138: /* Updates 16-bit "rcrc" with character 'ch'                                */
                    139: /****************************************************************************/
                    140: void ucrc16(uchar ch, ushort *rcrc) {
                    141:        ushort i, cy;
                    142:     uchar nch=ch;
                    143:  
                    144: for (i=0; i<8; i++) {
                    145:     cy=*rcrc & 0x8000;
                    146:     *rcrc<<=1;
                    147:     if (nch & 0x80) *rcrc |= 1;
                    148:     nch<<=1;
                    149:     if (cy) *rcrc ^= 0x1021; }
                    150: }
                    151: 
                    152: /****************************************************************************/
                    153: /* Returns the age derived from the string 'birth' in the format MM/DD/YY      */
                    154: /****************************************************************************/
                    155: char getage(char *birth)
                    156: {
                    157:        char age;
                    158:        struct date date;
                    159: 
                    160: if(birth[0]<=SP)
                    161:        return(0);
                    162: getdate(&date);
                    163: age=(date.da_year-1900)-(((birth[6]&0xf)*10)+(birth[7]&0xf));
1.1.1.2 ! root      164: if(age>90)
        !           165:        age-=90;
1.1       root      166: if(atoi(birth)>12 || atoi(birth+3)>31)
                    167:        return(0);
                    168: if(((birth[0]&0xf)*10)+(birth[1]&0xf)>date.da_mon ||
                    169:        (((birth[0]&0xf)*10)+(birth[1]&0xf)==date.da_mon &&
                    170:        ((birth[3]&0xf)*10)+(birth[4]&0xf)>date.da_day))
                    171:        age--;
                    172: if(age<0)
                    173:        return(0);
                    174: return(age);
                    175: }
                    176: 
                    177: /****************************************************************************/
                    178: /* Returns 16-crc of string (not counting terminating NULL)                            */
                    179: /****************************************************************************/
                    180: ushort crc16(char *str)
                    181: {
                    182:        int     i=0;
                    183:        ushort  crc=0;
                    184: 
                    185: ucrc16(0,&crc);
                    186: while(str[i])
                    187:        ucrc16(str[i++],&crc);
                    188: ucrc16(0,&crc);
                    189: ucrc16(0,&crc);
                    190: return(crc);
                    191: }
                    192: 
                    193: 
                    194: char *base41(unsigned int i, char *str)
                    195: {
                    196:        char c;
                    197:        unsigned int j=41*41,k;
                    198: 
                    199: for(c=0;c<3;c++) {
                    200:        k=i/j;
                    201:        str[c]='0'+k;
                    202:        i-=(k*j);
                    203:        j/=41;
                    204:        if(str[c]>=':')
                    205:                str[c]='A'+(str[c]-':');
                    206:        if(str[c]>='[')
                    207:                str[c]='#'+(str[c]-'['); }
                    208: str[c]=0;
                    209: return(str);
                    210: }
                    211: 
                    212: 
                    213: /****************************************************************************/
                    214: /* Network open function. Opens all files DENYALL and retries LOOP_NOPEN    */
                    215: /* number of times if the attempted file is already open or denying access  */
                    216: /* for some other reason.      All files are opened in BINARY mode.                    */
                    217: /****************************************************************************/
                    218: int nopen(char *str, int access)
                    219: {
                    220:        char logstr[256];
                    221:        int file,share,count=0;
                    222: 
                    223: if(access&O_DENYNONE) share=O_DENYNONE;
                    224: else if(access==O_RDONLY) share=O_DENYWRITE;
                    225: else share=O_DENYALL;
                    226: while(((file=open(str,O_BINARY|share|access,S_IWRITE))==-1)
                    227:        && errno==EACCES && count++<LOOP_NOPEN)
                    228:        if(count>10)
                    229:           delay(55);
                    230: if(file==-1 && errno==EACCES)
                    231:        puts("\7\nNOPEN: ACCESS DENIED\n\7");
                    232: return(file);
                    233: }
                    234: 
                    235: 
                    236: /****************************************************************************/
                    237: /* Creates a short message for 'usernumber' than contains 'strin'                      */
                    238: /****************************************************************************/
                    239: void putsmsg(int usernumber, char *strin)
                    240: {
                    241:        char str[256];
                    242:        int file,i;
                    243:        struct ffblk ff;
                    244:     node_t node;
                    245: 
                    246: sprintf(str,"%sMSGS\\%4.4u.MSG",data_dir,usernumber);
                    247: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
                    248:        printf("\7Error opening/creating %s for creat/append access\n",str);
                    249:        return; }
                    250: i=strlen(strin);
                    251: if(write(file,strin,i)!=i) {
                    252:        close(file);
                    253:        printf("\7Error writing %u bytes to %s\n",i,str);
                    254:        return; }
                    255: close(file);
                    256: }
                    257: 
                    258: void puttgram(int usernumber, char *strin)
                    259: {
                    260:        char str[256];
                    261:        int file,i;
                    262:        struct ffblk ff;
                    263:     node_t node;
                    264: 
                    265: sprintf(str,"%4.4u.MSG",usernumber);
                    266: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
                    267:        printf("\7Error opening/creating %s for creat/append access\n",str);
                    268:        return; }
                    269: i=strlen(strin);
                    270: if(write(file,strin,i)!=i) {
                    271:        close(file);
                    272:        printf("\7Error writing %u bytes to %s\n",i,str);
                    273:        return; }
                    274: close(file);
                    275: }
                    276: 
                    277: int trash(char *instr)
                    278: {
                    279:        char str[1024],word[128];
                    280: 
                    281: if(!trashfile)
                    282:        return(0);
                    283: strcpy(str,instr);
                    284: strupr(str);
                    285: rewind(trashfile);
                    286: while(!ferror(trashfile)) {
                    287:        if(!fgets(word,125,trashfile))
                    288:                break;
                    289:        truncsp(word);
                    290:        if(!word[0])
                    291:                continue;
                    292:        strupr(word);
                    293:        if(strstr(str,word))
                    294:                return(1); }
                    295: return(0);
                    296: }
                    297: 
                    298: time_t checktime()
                    299: {
                    300:        struct tm tm;
                    301: 
                    302: memset(&tm,0,sizeof(tm));
                    303: tm.tm_year=94;
                    304: tm.tm_mday=1;
                    305: return(mktime(&tm)^0x2D24BD00L);
                    306: }
                    307: 
                    308: int main(int argc, char **argv)
                    309: {
                    310:        uchar   str[256],system[128],telegram[1024],HUGE16 *buf,HUGE16 *hp, *p
                    311:                        ,min_age,fname[64],path[128],tmp[128],ch;
                    312:        int     i,j,file,out,wallfile,msgfile,tgramonly=0,wallonly=0,esc;
                    313:        ulong   l,m,last,high,system_crc,crc,length;
                    314:        ushort  smm,smm_photo,touser;
                    315:        user_t  user;
                    316:        wall_t  wall;
                    317:        smbmsg_t msg;
                    318:        FILE    *stream,*index,*tmpfile;
                    319:        ixb_t   ixb;
                    320: 
                    321: fprintf(stderr,"\nSMB2SMM v%s - Updates SMM via SMB - Developed 1995-1997 "
                    322:        "Rob Swindell\n\n",VERSION);
                    323: 
                    324: if(checktime()) {
                    325:     printf("Time problem!\n");
                    326:     return(-1); }
                    327: 
                    328: if(argc<3) {
                    329:        fprintf(stderr,"usage: smb2smm <smb_file> <smm.dab>\n\n");
                    330:        fprintf(stderr,"example: smb2smm c:\\sbbs\\data\\subs\\syncdata "
                    331:                "c:\\sbbs\\xtrn\\smm\\smm.dab\n");
                    332:        return(1); }
                    333: 
                    334: p=getenv("SBBSNODE");
                    335: if(p==NULL) {
                    336:        printf("\7\nSBBSNODE environment variable not set.\n");
                    337:        exit(1); }
                    338: strcpy(str,p);
                    339: if(str[strlen(str)-1]!='\\')
                    340:        strcat(str,"\\");
                    341: strcat(str,"XTRN.DAT");
                    342: if((file=nopen(str,O_RDONLY))==-1 || (stream=fdopen(file,"rb"))==NULL) {
                    343:        printf("\7\nCan't open %s\n",str);
                    344:        exit(1); }
                    345: fgets(str,81,stream);          /* user name */
                    346: fgets(system,81,stream);       /* system name */
                    347: truncsp(system);
                    348: fgets(str,81,stream);          /* sysop name */
                    349: fgets(str,81,stream);          /* guru name */
                    350: fgets(str,81,stream);          /* ctrl dir */
                    351: fgets(str,81,stream);          /* data dir */
                    352: truncsp(str);
                    353: if(str[0]=='.') {
                    354:        strcpy(data_dir,p);     /* node dir */
                    355:        if(data_dir[strlen(data_dir)-1]!='\\')
                    356:                strcat(data_dir,"\\");
                    357:        strcat(data_dir,str); }
                    358: else
                    359:        strcpy(data_dir,str);
                    360: fclose(stream);
                    361: 
                    362: if(argc>3 && !stricmp(argv[3],"/t"))
                    363:        tgramonly=1;
                    364: 
                    365: if(argc>3 && !stricmp(argv[3],"/w"))
                    366:        wallonly=1;
                    367: 
                    368: strcpy(smb.file,argv[1]);
                    369: strupr(smb.file);
                    370: 
                    371: strcpy(str,argv[2]);
                    372: strupr(str);
                    373: if((file=open(str,O_RDWR|O_BINARY|O_DENYNONE|O_CREAT,S_IWRITE|S_IREAD))==-1) {
                    374:        printf("error opening %s\n",str);
                    375:        return(1); }
                    376: if((stream=fdopen(file,"r+b"))==NULL) {
                    377:        printf("error fdopening %s\n",str);
                    378:        return(1); }
                    379: setvbuf(stream,NULL,_IOFBF,4096);
                    380: 
                    381: p=strrchr(str,'.');
                    382: if(!p) p=str;
                    383: else p++;
                    384: strcpy(p,"IXB");
                    385: if((file=open(str,O_RDWR|O_BINARY|O_DENYNONE|O_CREAT,S_IWRITE|S_IREAD))==-1) {
                    386:        printf("error opening %s\n",str);
                    387:        return(1); }
                    388: if((index=fdopen(file,"r+b"))==NULL) {
                    389:        printf("error fdopening %s\n",str);
                    390:        return(1); }
                    391: setvbuf(index,NULL,_IOFBF,1024);
                    392: 
                    393: p=strrchr(str,'.');
                    394: if(!p) p=str;
                    395: else p++;
                    396: strcpy(p,"CAN");
                    397: trashfile=NULL;
                    398: if((file=open(str,O_RDONLY|O_DENYNONE))!=-1) {
                    399:        trashfile=fdopen(file,"rb");
                    400:        setvbuf(trashfile,NULL,_IOFBF,4096); }
                    401: 
                    402: p=strrchr(str,'.');
                    403: if(!p) p=str;
                    404: else p++;
                    405: strcpy(p,"CFG");
                    406: if((file=nopen(str,O_RDONLY))==-1) {
                    407:        printf("error opening %s\n",str);
                    408:     return(1); }
                    409: if((tmpfile=fdopen(file,"rb"))==NULL) {
                    410:        printf("error fdopening %s\n",str);
                    411:     return(1); }
                    412: fgets(str,128,tmpfile); /* Min purity age */
                    413: fgets(str,128,tmpfile); /* Min profile age */
                    414: truncsp(str);
                    415: min_age=atoi(str);
                    416: fclose(tmpfile);
                    417: 
                    418: sprintf(str,"%s.SMM",smb.file);
                    419: if((file=open(str,O_RDWR|O_BINARY|O_CREAT,S_IWRITE|S_IREAD))==-1) {
                    420:        printf("error opening %s\n",str);
                    421:        return(1); }
                    422: if(read(file,&last,4)!=4)
                    423:        last=0;
                    424: high=last;
                    425: 
                    426: sprintf(str,"%s.SHD",smb.file);
                    427: if(!fexist(str)) {
                    428:        printf("%s doesn't exist\n",smb.file);
                    429:        return(0); }
                    430: sprintf(str,"%s.SID",smb.file);
                    431: if(!flength(str)) {
                    432:        printf("%s is empty\n",smb.file);
                    433:     return(0); }
                    434: fprintf(stderr,"Opening %s\n",smb.file);
                    435: smb.retry_time=30;
                    436: if((i=smb_open(&smb))!=0) {
                    437:        printf("smb_open returned %d\n",i);
                    438:        return(1); }
                    439: 
                    440: smm=crc16("smm");
                    441: smm_photo=crc16("smm photo");
                    442: 
                    443: if((i=smb_locksmbhdr(&smb))!=0) {                              /* Be sure noone deletes or */
                    444:        printf("Error locking %d\n",i);             /* adds while we're reading */
                    445:        return(1); }
                    446: 
                    447: rewind(smb.sid_fp);
                    448: while(!feof(smb.sid_fp) && !ferror(smb.sid_fp)) {
                    449:        if(!fread(&msg.idx,sizeof(idxrec_t),1,smb.sid_fp))
                    450:         break;
                    451:        fprintf(stderr,"\r#%-5lu  ",msg.idx.number);
                    452:        if(msg.idx.to!=smm && msg.idx.to!=smm_photo)
                    453:                continue;
                    454:        if(msg.idx.number<=last || msg.idx.attr&MSG_DELETE)
                    455:                continue;
                    456:        high=msg.idx.number;
                    457:        if((i=smb_lockmsghdr(&smb,&msg))!=0) {
                    458:                printf("\7Error %d locking msg #%lu\n",i,msg.idx.number);
                    459:                continue; }
                    460:        if((i=smb_getmsghdr(&smb,&msg))!=0) {
                    461:                smb_unlockmsghdr(&smb,&msg);
                    462:                printf("\7Error %d reading msg #%lu\n",i,msg.idx.number);
                    463:                continue; }
                    464: 
                    465:        smb_unlockmsghdr(&smb,&msg);
                    466:        if(!msg.from_net.type || !strnicmp(msg.from,system,25)) { // ignore local msg
                    467:                smb_freemsgmem(&msg);
                    468:                continue; }
                    469: 
                    470:        printf("From: %-25.25s  To: %-25.25s  Subj: %s\n"
                    471:                ,msg.from,msg.to,msg.subj);
                    472: 
                    473:        if(msg.idx.to==smm_photo) {
                    474:                buf=smb_getmsgtxt(&smb,&msg,0);
                    475:                if(!buf) {
                    476:                        smb_freemsgmem(&msg);
                    477:                        continue; }
                    478:                sprintf(str,"%.4s",msg.subj);
                    479:                l=ahtoul(str);
                    480:                l^=0x0191;
                    481:                sprintf(str,"%.8s",msg.subj+4);
                    482:                system_crc=ahtoul(str);
                    483:                system_crc^=0x90120e71;
                    484:                fprintf(stderr,"Searching...");
                    485: 
                    486:                rewind(index);
                    487:                memset(&user,0,sizeof(user_t));
                    488:                while(1) {
                    489:                        if(!fread(&ixb,sizeof(ixb_t),1,index)) {
                    490:                                memset(&user,0,sizeof(user_t));
                    491:                                break; }
                    492:                        if(ixb.number==l && ixb.system==system_crc) {
                    493:                                fseek(index,ftell(index)-sizeof(ixb_t),SEEK_SET);
                    494:                                fseek(stream,(ftell(index)/sizeof(ixb_t))*sizeof(user_t)
                    495:                                        ,SEEK_SET);
                    496:                                fread(&user,sizeof(user_t),1,stream);
                    497:                                break; } }
                    498:                fprintf(stderr,"\n");
                    499: 
                    500:                if(!user.number) {
                    501:                        printf("Profile Not found\n");
                    502:                        smb_freemsgmem(&msg);
                    503:                        continue; }
                    504: 
                    505:                for(i=0;user.system[i];i++)
                    506:                        if(isalnum(user.system[i]))
                    507:                                break;
                    508:                if(!user.system[i])
                    509:                        fname[0]='~';
                    510:                else
                    511:                        fname[0]=user.system[i];
                    512:                for(i=strlen(user.system)-1;i>0;i--)
                    513:                        if(isalnum(user.system[i]))
                    514:                                break;
                    515:                if(i<=0)
                    516:                        fname[1]='~';
                    517:                else
                    518:                        fname[1]=user.system[i];
                    519:                fname[2]=0;
                    520:                strcpy(str,user.system);
                    521:         strupr(str);
                    522:                strcat(fname,base41(crc16(str),tmp));
                    523:                strcat(fname,base41(user.number,tmp));
                    524:                sprintf(str,".%.3s",msg.subj+20);
                    525:                strcat(fname,str);
                    526:                strupr(fname);
                    527: 
                    528:                if((out=nopen(fname,O_CREAT|O_WRONLY|O_TRUNC))==-1) {
                    529:                        printf("Error opening %s\n",fname);
                    530:                        smb_freemsgmem(&msg);
                    531:                        continue; }
                    532:                
                    533:                crc=0xffffffffUL;
                    534:                esc=0;
                    535:                for(l=0;buf[l]!=CR;l++)
                    536:                        ;
                    537:                buf[l]=0;
                    538:                length=ahtoul((char *)buf)^4096;
                    539:                l+=2;   /* Skip CRLF */
                    540:                for(m=0;buf[l] && m<length;l++) {
                    541:                        ch=buf[l];
                    542:                        if(ch<SP)
                    543:                                continue;
                    544:                        if(ch=='`') {
                    545:                                if(esc) {
                    546:                                        write(out,&ch,1);
                    547:                                        m++;
                    548:                                        crc=ucrc32(ch,crc);
                    549:                                        esc=0; }
                    550:                                else
                    551:                                        esc=1;
                    552:                                continue; }
                    553:                        if(esc) {
                    554:                                if(isalpha(ch)) {
                    555:                                        if(isupper(ch))
                    556:                                                ch-='@';
                    557:                                        else if(ch=='g')
                    558:                                                ch=0xe3;
                    559:                                        else if(ch=='h')
                    560:                                                ch=0x8d;
                    561:                                        else if(ch=='i')
                    562:                                                ch=0xee;
                    563:                                        else
                    564:                                                ch=0xfa+(ch-'a'); }
                    565:                                else
                    566:                                        ch=0xf0+(ch-'0');
                    567:                                write(out,&ch,1);
                    568:                                m++;
                    569:                                crc=ucrc32(ch,crc);
                    570:                                esc=0;
                    571:                                continue; }
                    572:                        if(ch>=0xf0)
                    573:                                ch&=0xf;
                    574:                        if(ch==0xee)
                    575:                                ch=0xff;
                    576:                        write(out,&ch,1);
                    577:                        m++;
                    578:                        crc=ucrc32(ch,crc); }
                    579:                close(out);
                    580:                crc=~crc;
                    581:                crc^=0x05296328L;
                    582:                sprintf(str,"%.8s",msg.subj+12);
                    583:                smb_freemsgmem(&msg);
                    584:                if(crc!=ahtoul(str)) {
                    585:                        printf("CRC error!\n");
                    586:                        remove(fname);
                    587:                        continue; }
                    588:                sprintf(path,"PHOTO\\%s",fname);
                    589:         mkdir("PHOTO");
                    590:                if(rename(fname,path)) {
                    591:                        printf("Error renaming %s to %s!\n",fname,path);
                    592:                        remove(fname);
                    593:                        continue; }
                    594:                user.misc|=USER_PHOTO;
                    595:                fseek(stream,(ftell(index)/sizeof(ixb_t))*sizeof(user_t),SEEK_SET);
                    596:                fwrite(&user,sizeof(user_t),1,stream);
                    597:                if(!strnicmp(user.system,system,25))
                    598:                        putsmsg(user.number
                    599:                                ,"\1n\1h\1mYour photo has been imported into "
                    600:                                        "\1wMatch Maker\1n\7\r\n");
                    601:                continue; }
                    602: 
                    603:        if(!stricmp(msg.subj,"->WALL<-")) {
                    604:                buf=smb_getmsgtxt(&smb,&msg,0);
                    605:                smb_freemsgmem(&msg);
                    606:                if(!buf)
                    607:                        continue;
                    608:                memset(&wall,0,sizeof(wall_t));
                    609:                hp=buf;
                    610:                while(*hp && *hp<SP) hp++;
                    611:                for(i=0;*hp>=SP && i<25;i++,hp++)
                    612:                        wall.name[i]=*hp;
                    613:                wall.name[i]=0;
                    614:                hp+=2;   /* Skip CRLF */
                    615:                for(i=0;*hp>=SP && i<40;i++,hp++)
                    616:                        wall.system[i]=*hp;
                    617:                wall.system[i]=0;
                    618:                hp+=2;   /* Skip CRLF */
                    619:                for(i=0;i<5;i++) {
                    620:                        for(j=0;*hp>=SP && j<70;j++,hp++)
                    621:                                wall.text[i][j]=*hp;
                    622:                        wall.text[i][j]=0;
                    623:                        hp+=2; }
                    624: 
                    625:                wall.written=ahtoul((char *)hp);
                    626:                wall.imported=time(NULL);
                    627:                FREE((char *)buf);
                    628:                decrypt(wall.name,wall.written);
                    629:                decrypt(wall.system,wall.written);
                    630:                for(i=0;i<5;i++) {
                    631:                        decrypt(wall.text[i],wall.written);
                    632:                        if(trash(wall.text[i])) {
                    633:                                printf("Rejected: Wall writing found in trash!\n");
                    634:                                break; } }
                    635:                if(i<5)
                    636:                        continue;
                    637:                if((wallfile=sopen("WALL.DAB",O_WRONLY|O_BINARY|O_CREAT,SH_DENYNO
                    638:                        ,S_IWRITE|S_IREAD))==-1) {
                    639:                        printf("Couldn't open WALL.DAB!\n");
                    640:                        continue; }
                    641:                lseek(wallfile,0L,SEEK_END);
                    642:                write(wallfile,&wall,sizeof(wall_t));
                    643:                close(wallfile);
                    644:                continue; }
                    645: 
                    646:        if(wallonly) {
                    647:                smb_freemsgmem(&msg);
                    648:                continue; }
                    649: 
                    650:        if(!stricmp(msg.subj,"->ALL<-")
                    651:                || !stricmp(msg.subj,"->SYS<-")
                    652:                || !stricmp(msg.subj,"->ONE<-")) {
                    653:                sprintf(str,"%.3s%05lu.MSG",msg.subj+2,msg.idx.number);
                    654:                buf=smb_getmsgtxt(&smb,&msg,0);
                    655:                smb_freemsgmem(&msg);
                    656:                if(!buf)
                    657:             continue;
                    658:                l=ahtoul((char *)buf);
                    659:                if(!l)
                    660:             continue;
                    661:                for(i=0;buf[i];i++)
                    662:             if(buf[i]==LF)
                    663:                 break;
                    664:         if(buf[i]!=LF)
                    665:             continue;
                    666:                if((msgfile=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
                    667:                        printf("error opening %s\n",str);
                    668:                        continue; }
                    669:                if((tmpfile=fdopen(msgfile,"wb"))==NULL) {
                    670:                        close(msgfile);
                    671:                        printf("error fdopening %s\n",str);
                    672:                        continue; }
                    673:                fprintf(tmpfile,"%08lx\r\n",l);
                    674:                l^=0x305F6C81UL;
                    675:                for(i++;buf[i];i++)
                    676:                        fputc(cryptchar(buf[i],l^(i&7)),tmpfile);
                    677:                fclose(tmpfile);
                    678:                putsmsg(1,"\1n\1h\1mNew announcement in \1wMatch Maker\1n\7\r\n");
                    679:                continue; }
                    680: 
                    681: 
                    682:        j=strlen(msg.subj);
                    683:        for(i=0;i<j;i++)
                    684:                if(!isdigit(msg.subj[i]))
                    685:                        break;
                    686:        if(i<j) {                               /* at least one non-digit, must be telegram */
                    687:                if(strnicmp(msg.subj,system,25)) {
                    688:                        smb_freemsgmem(&msg);
                    689:                        continue; }
                    690:                buf=smb_getmsgtxt(&smb,&msg,0);
                    691:                smb_freemsgmem(&msg);
                    692:                if(!buf)
                    693:                        continue;
                    694:                l=0;
                    695:                while(buf[l] && buf[l]!='}')         /* Find first text on line */
                    696:                        l++;
                    697:                if(!buf[l] || !buf[++l]) {
                    698:                        FREE(buf);
                    699:                        continue; }
                    700:                touser=ahtoul((char *)buf+l);
                    701:                while(buf[l] && buf[l]>=SP)     /* Go to end of line */
                    702:                        l++;
                    703:                while(buf[l] && buf[l]<=SP)     /* next line */
                    704:                        l++;
                    705:                i=0;
                    706:                while(buf[l]) {
                    707:                        if(buf[l]==LF && buf[l+1]==CR) { /* blank line */
                    708:                                telegram[i++]=LF;
                    709:                                break; }
                    710:                        telegram[i++]=buf[l++]; }
                    711:                telegram[i]=0;
                    712:                decrypt(telegram,touser);
                    713:                printf("Telegram to %u\n",touser);
                    714:                if(trash(telegram))
                    715:                        printf("Rejected: Contents in trash!\n");
                    716:                else {
                    717:                        putsmsg(touser,TGRAM_NOTICE);
                    718:                        puttgram(touser,telegram); }
                    719:                FREE(buf);
                    720:                continue;
                    721:                }
                    722: 
                    723:        if(tgramonly) {
                    724:                smb_freemsgmem(&msg);
                    725:                continue; }
                    726: 
                    727:        if(!msg.from[0]) {
                    728:                smb_freemsgmem(&msg);
                    729:                printf("Blank 'from' field.\n");
                    730:         continue; }
                    731: 
                    732:        l=atol(msg.subj);
                    733:        if(!l || l>65535L) {
                    734:                smb_freemsgmem(&msg);
                    735:                printf("Invalid profile.\n");
                    736:                continue; }
                    737:        fprintf(stderr,"Searching for %lu @ %s",l,msg.from);
                    738:        sprintf(str,"%.25s",msg.from);
                    739:        strupr(str);
                    740:        system_crc=crc32(str);
                    741: 
                    742:        rewind(index);
                    743:        memset(&user,0,sizeof(user_t));
                    744:        while(1) {
                    745:                if(!fread(&ixb,sizeof(ixb_t),1,index)) {
                    746:                        memset(&user,0,sizeof(user_t));
                    747:                        break; }
                    748:                if(ixb.number==l && ixb.system==system_crc) {
                    749:                        fseek(index,ftell(index)-sizeof(ixb_t),SEEK_SET);
                    750:                        fseek(stream,(ftell(index)/sizeof(ixb_t))*sizeof(user_t),SEEK_SET);
                    751:                        fread(&user,sizeof(user_t),1,stream);
                    752:                        if(!(user.misc&USER_FROMSMB)) {
                    753:                                memset(&user,0,sizeof(user_t));
                    754:                                fread(&ixb,sizeof(ixb_t),1,index);
                    755:                                continue; }
                    756:                        break; } }
                    757:        fprintf(stderr,"\n");
                    758: 
                    759:        if(!user.number) {
                    760:                fprintf(stderr,"Searching for unused record...");
                    761:                rewind(index);
                    762:                while(1) {                                      /* Find deleted record */
                    763:                        if(!fread(&ixb,sizeof(ixb_t),1,index))
                    764:                                break;
                    765:                        if(ixb.number==0) {
                    766:                                fseek(index,ftell(index)-sizeof(ixb_t),SEEK_SET);
                    767:                                break; } }
                    768:                user.created=time(NULL);
                    769:                user.number=l;
                    770:                sprintf(user.system,"%-.40s",msg.from);
                    771:                fprintf(stderr,"\n"); }
                    772: 
                    773:        fseek(stream,(ftell(index)/sizeof(ixb_t))*sizeof(user_t),SEEK_SET);
                    774:        user.updated=time(NULL);
                    775:        user.misc|=USER_FROMSMB;
                    776:        buf=smb_getmsgtxt(&smb,&msg,0);
                    777:        l=0;
                    778:        while(buf[l]) {
                    779:                while(buf[l] && buf[l]<=SP)             /* Find first text on line */
                    780:                        l++;
                    781:                if(!strnicmp((char *)buf+l,"0:",2)) {
                    782:                        l+=2;
                    783:                        sprintf(user.name,"%-.25s",(char *)buf+l);
                    784:                        truncsp(user.name);
                    785:                        decrypt(user.name,user.number); }
                    786:                if(!strnicmp((char *)buf+l,"1:",2)) {
                    787:                        l+=2;
                    788:                        sprintf(user.realname,"%-.25s",(char *)buf+l);
                    789:                        truncsp(user.realname);
                    790:                        decrypt(user.realname,user.number); }
                    791:                if(!strnicmp((char *)buf+l,"2:",2)) {
                    792:                        l+=2;
                    793:                        sprintf(user.birth,"%-.8s",(char *)buf+l);
                    794:                        decrypt(user.birth,user.number); }
                    795:                if(!strnicmp((char *)buf+l,"3:",2)) {
                    796:                        l+=2;
                    797:                        sprintf(user.location,"%-.30s",(char *)buf+l);
                    798:                        truncsp(user.location);
                    799:                        decrypt(user.location,user.number); }
                    800:                if(!strnicmp((char *)buf+l,"4:",2)) {
                    801:             l+=2;
                    802:                        sprintf(user.zipcode,"%-.10s",(char *)buf+l);
                    803:             truncsp(user.zipcode);
                    804:                        decrypt(user.zipcode,user.number); }
                    805:                if(!strnicmp((char *)buf+l,"5:",2)) {
                    806:                        l+=2;
                    807:                        sprintf(user.min_zipcode,"%-.10s",(char *)buf+l);
                    808:                        truncsp(user.min_zipcode);
                    809:                        decrypt(user.min_zipcode,user.number); }
                    810:                if(!strnicmp((char *)buf+l,"6:",2)) {
                    811:                        l+=2;
                    812:                        sprintf(user.max_zipcode,"%-.10s",(char *)buf+l);
                    813:                        truncsp(user.max_zipcode);
                    814:                        decrypt(user.max_zipcode,user.number); }
                    815:                if(!strnicmp((char *)buf+l,"7:",2)) {
                    816:                        l+=2;
                    817:                        sprintf(user.mbtype,"%-.4s",(char *)buf+l);
                    818:                        truncsp(user.mbtype);
                    819:                        decrypt(user.mbtype,user.number); }
                    820: 
                    821:                if(!strnicmp((char *)buf+l,"A:",2)) {
                    822:                        l+=2;
                    823:                        sprintf(user.note[0],"%-.50s",(char *)buf+l);
                    824:                        truncsp(user.note[0]);
                    825:                        decrypt(user.note[0],user.number); }
                    826:                if(!strnicmp((char *)buf+l,"B:",2)) {
                    827:                        l+=2;
                    828:                        sprintf(user.note[1],"%-.50s",(char *)buf+l);
                    829:                        truncsp(user.note[1]);
                    830:                        decrypt(user.note[1],user.number); }
                    831:                if(!strnicmp((char *)buf+l,"C:",2)) {
                    832:                        l+=2;
                    833:                        sprintf(user.note[2],"%-.50s",(char *)buf+l);
                    834:                        truncsp(user.note[2]);
                    835:                        decrypt(user.note[2],user.number); }
                    836:                if(!strnicmp((char *)buf+l,"D:",2)) {
                    837:                        l+=2;
                    838:                        sprintf(user.note[3],"%-.50s",(char *)buf+l);
                    839:                        truncsp(user.note[3]);
                    840:                        decrypt(user.note[3],user.number); }
                    841:                if(!strnicmp((char *)buf+l,"E:",2)) {
                    842:                        l+=2;
                    843:                        sprintf(user.note[4],"%-.50s",(char *)buf+l);
                    844:                        truncsp(user.note[4]);
                    845:                        decrypt(user.note[4],user.number); }
                    846: 
                    847:                if(!strnicmp((char *)buf+l,"F:",2)) {
                    848:                        l+=2;
                    849:                        user.sex=buf[l];
                    850:                        user.pref_sex=buf[l+1]; }
                    851: 
                    852:                if(!strnicmp((char *)buf+l,"G:",2)) {
                    853:                        l+=2;
                    854:                        user.marital=ahtoul((char *)buf+l); }
                    855:                if(!strnicmp((char *)buf+l,"H:",2)) {
                    856:                        l+=2;
                    857:                        user.pref_marital=ahtoul((char *)buf+l); }
                    858: 
                    859:                if(!strnicmp((char *)buf+l,"I:",2)) {
                    860:                        l+=2;
                    861:                        user.race=ahtoul((char *)buf+l); }
                    862:                if(!strnicmp((char *)buf+l,"J:",2)) {
                    863:                        l+=2;
                    864:                        user.pref_race=ahtoul((char *)buf+l); }
                    865: 
                    866:                if(!strnicmp((char *)buf+l,"K:",2)) {
                    867:                        l+=2;
                    868:                        user.hair=ahtoul((char *)buf+l); }
                    869:                if(!strnicmp((char *)buf+l,"L:",2)) {
                    870:                        l+=2;
                    871:                        user.pref_hair=ahtoul((char *)buf+l); }
                    872: 
                    873:                if(!strnicmp((char *)buf+l,"M:",2)) {
                    874:                        l+=2;
                    875:                        user.eyes=ahtoul((char *)buf+l); }
                    876:                if(!strnicmp((char *)buf+l,"N:",2)) {
                    877:                        l+=2;
                    878:                        user.pref_eyes=ahtoul((char *)buf+l); }
                    879: 
                    880:                if(!strnicmp((char *)buf+l,"O:",2)) {
                    881:                        l+=2;
                    882:                        user.weight=ahtoul((char *)buf+l); }
                    883:                if(!strnicmp((char *)buf+l,"P:",2)) {
                    884:                        l+=2;
                    885:                        user.min_weight=ahtoul((char *)buf+l); }
                    886:                if(!strnicmp((char *)buf+l,"Q:",2)) {
                    887:                        l+=2;
                    888:                        user.max_weight=ahtoul((char *)buf+l); }
                    889: 
                    890:                if(!strnicmp((char *)buf+l,"R:",2)) {
                    891:                        l+=2;
                    892:                        user.height=ahtoul((char *)buf+l); }
                    893:                if(!strnicmp((char *)buf+l,"S:",2)) {
                    894:                        l+=2;
                    895:                        user.min_height=ahtoul((char *)buf+l); }
                    896:                if(!strnicmp((char *)buf+l,"T:",2)) {
                    897:                        l+=2;
                    898:                        user.max_height=ahtoul((char *)buf+l); }
                    899: 
                    900:                if(!strnicmp((char *)buf+l,"U:",2)) {
                    901:                        l+=2;
                    902:                        user.min_age=ahtoul((char *)buf+l); }
                    903:                if(!strnicmp((char *)buf+l,"V:",2)) {
                    904:                        l+=2;
                    905:                        user.max_age=ahtoul((char *)buf+l); }
                    906: 
                    907:                if(!strnicmp((char *)buf+l,"W:",2)) {
                    908:                        l+=2;
                    909:                        user.purity=ahtoul((char *)buf+l); }
                    910: 
                    911:                if(!strnicmp((char *)buf+l,"X:",2)) {
                    912:                        l+=2;
                    913:                        user.income=ahtoul((char *)buf+l); }
                    914:                if(!strnicmp((char *)buf+l,"Y:",2)) {
                    915:                        l+=2;
                    916:                        user.min_income=ahtoul((char *)buf+l); }
                    917:                if(!strnicmp((char *)buf+l,"Z:",2)) {
                    918:                        l+=2;
                    919:                        user.max_income=ahtoul((char *)buf+l); }
                    920: 
                    921:                if(toupper(buf[l])=='*' && isdigit(buf[l+1])) {  /* Questionnaires */
                    922:                        i=buf[l+1]-'0';
                    923:                        l+=2;
                    924:                        sprintf(user.queans[i].name,"%-.8s",(char *)buf+l);
                    925:                        truncsp(user.queans[i].name);
                    926:                        decrypt(user.queans[i].name,user.number);
                    927:                        while(buf[l] && buf[l]>=SP) l++;        /* Go to end of line */
                    928:                        for(j=0;j<20;j++) {
                    929:                                while(buf[l] && buf[l]<=SP) l++;
                    930:                                user.queans[i].self[j]=ahtoul((char *)buf+l);
                    931:                                l+=5;
                    932:                                user.queans[i].pref[j]=ahtoul((char *)buf+l);
                    933:                                l+=5; } }
                    934: 
                    935:                while(buf[l] && buf[l]>=SP)     /* Go to end of line */
                    936:                        l++; }
                    937: 
                    938:        if(getage(user.birth)<min_age)          /* Too young */
                    939:                printf("Rejected: User's age (%u) less than minimum age (%u)\n"
                    940:                        ,getage(user.birth),min_age);
                    941:        else if(user.name[0]<SP || user.realname[0]<SP || user.system[0]<SP
                    942:                || user.location[0]<SP || user.zipcode[0]<SP || user.birth[0]<SP)
                    943:                printf("Rejected: Invalid user string\n");
                    944:        else if(trash(user.name))
                    945:                printf("Rejected: User's name (%s) in trash!\n",user.name);
                    946:        else if(trash(user.location))
                    947:                printf("Rejected: User's location (%s) in trash!\n",user.location);
                    948:        else if(trash(user.note[0]) || trash(user.note[1]) || trash(user.note[2])
                    949:                || trash(user.note[3]) || trash(user.note[4]))
                    950:                printf("Rejected: User's personal text in trash!\n");
                    951:        else {
                    952:                fwrite(&user,sizeof(user_t),1,stream);
                    953:                strupr(user.name);
                    954:                ixb.name=crc32(user.name);
                    955:                strupr(user.system);
                    956:                user.system[25]=0;
                    957:                ixb.system=crc32(user.system);
                    958:                ixb.number=user.number;
                    959:                ixb.updated=user.updated;
                    960:                fwrite(&ixb,sizeof(ixb_t),1,index); }
                    961:        FREE((char *)buf);
                    962:        smb_freemsgmem(&msg);
                    963:        }
                    964: 
                    965: lseek(file,0L,SEEK_SET);
                    966: write(file,&high,4);
                    967: close(file);
                    968: return(0);
                    969: }
                    970: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.