Annotation of 40BSD/cmd/xsend/xget.c, revision 1.1

1.1     ! root        1: #include "xmail.h"
        !             2: #include "sys/types.h"
        !             3: #include "sys/dir.h"
        !             4: #include "ctype.h"
        !             5: #include "pwd.h"
        !             6: #include "sys/stat.h"
        !             7: char *myname;
        !             8: int uid;
        !             9: struct direct dbuf;
        !            10: char *maildir = "/usr/spool/secretmail/";
        !            11: FILE *kf, *mf, *df;
        !            12: MINT *x, *b, *one, *t45, *z, *q, *r;
        !            13: MINT *two, *t15, *mbuf;
        !            14: char buf[256], line[128];
        !            15: #define MXF 100
        !            16: int fnum[MXF], fcnt;
        !            17: struct stat stbuf;
        !            18: main()
        !            19: {      int i;
        !            20:        char *p;
        !            21:        uid = getuid();
        !            22:        myname = getlogin();
        !            23:        if(myname == NULL)
        !            24:                myname = getpwuid(uid)->pw_name;
        !            25:        comminit();
        !            26:        mbuf = itom(0);
        !            27:        files();
        !            28:        setup(getpass("Key: "));
        !            29:        mkb();
        !            30:        mkx();
        !            31: #ifndef debug
        !            32:        invert(x, b, x);
        !            33: #else
        !            34:        invert(x, b, z);
        !            35:        mult(x, z, z);
        !            36:        mdiv(z, b, q, z);
        !            37:        omout(z);
        !            38:        invert(x, b, x);
        !            39: #endif
        !            40:        for(i=0; i<fcnt; i++)
        !            41:        {       sprintf(line, "%s%s.%d", maildir, myname, fnum[i]);
        !            42:                if(stat(line, &stbuf)<0)
        !            43:                {       perror(line);
        !            44:                        continue;
        !            45:                }
        !            46:                if(stbuf.st_size == 0)
        !            47:                {       printf("zero length mail file\n");
        !            48:                        unlink(line);
        !            49:                        continue;
        !            50:                }
        !            51:                if((mf = fopen(line, "r"))==NULL)
        !            52:                {       perror(line);
        !            53:                        continue;
        !            54:                }
        !            55:                decipher(mf, stdout);
        !            56:        cmnd:
        !            57:                printf("? ");
        !            58:                fgets(buf, sizeof(buf), stdin);
        !            59:                if(feof(stdin)) exit(0);
        !            60:                switch(buf[0])
        !            61:                {
        !            62:                case 'q':
        !            63:                        exit(0);
        !            64:                case 'n':
        !            65:                case 'd':
        !            66:                case '\n':
        !            67:                        unlink(line);
        !            68:                        fclose(mf);
        !            69:                        break;
        !            70:                case '!':
        !            71:                        system(buf+1);
        !            72:                        printf("!\n");
        !            73:                        goto cmnd;
        !            74:                case 's':
        !            75:                case 'w':
        !            76:                        rewind(mf);
        !            77:                        if(buf[1] == '\n' || buf[1] == '\0')
        !            78:                                strcpy(buf, "s mbox\n");
        !            79:                        for(p=buf; !isspace(*p); p++);
        !            80:                        for(; isspace(*p); p++);
        !            81:                        p[strlen(p)-1] = 0;
        !            82:                        kf = fopen(p, "a");
        !            83:                        if(kf == NULL)
        !            84:                        {       perror(p);
        !            85:                                break;
        !            86:                        }
        !            87:                        decipher(mf, kf);
        !            88:                        fclose(mf);
        !            89:                        fclose(kf);
        !            90:                        unlink(line);
        !            91:                        break;
        !            92:                }
        !            93:        }
        !            94:        exit(0);
        !            95: }
        !            96: icmp(a, b) int *a, *b;
        !            97: {
        !            98:        return(*a - *b);
        !            99: }
        !           100: files()
        !           101: {      int i;
        !           102:        if((df = fopen(maildir, "r")) == NULL)
        !           103:        {       perror(maildir);
        !           104:                exit(1);
        !           105:        }
        !           106:        strcpy(line, myname);
        !           107:        strcat(line, ".%d");
        !           108:        for(; !feof(df);)
        !           109:        {       fread(&dbuf, sizeof(dbuf), 1, df);
        !           110:                if(feof(df)) break;
        !           111:                if(dbuf.d_ino == 0) continue;
        !           112:                if(sscanf(dbuf.d_name, line, &i) != 1)
        !           113:                        continue;
        !           114:                if(fcnt >= MXF)
        !           115:                        break;
        !           116:                fnum[fcnt++] = i;
        !           117:        }
        !           118:        if(fcnt == 0)
        !           119:        {       printf("no secret mail\n");
        !           120:                exit(0);
        !           121:        }
        !           122:        qsort(fnum, fcnt, sizeof(int), icmp);
        !           123: }
        !           124: decipher(u, w) FILE *u, *w;
        !           125: {      int i;
        !           126:        short a;
        !           127:        for(;;)
        !           128:        {       nin(mbuf, u);
        !           129:                if(feof(u)) break;
        !           130:                mult(mbuf, x, mbuf);
        !           131:                mdiv(mbuf, b, q, mbuf);
        !           132:                for(i=1; i<=3; i++)
        !           133:                {       a = mbuf->val[i];
        !           134:                        putc(a&0177, w);
        !           135:                        a >>= 8;
        !           136:                        putc(a&0177, w);
        !           137:                }
        !           138:        }
        !           139: }

unix.superglobalmegacorp.com

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