Annotation of 43BSDReno/usr.bin/xsend/xget/xget.c, revision 1.1

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

unix.superglobalmegacorp.com

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