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

Defined functions

decipher defined in line 126; used 2 times
files defined in line 102; used 1 times
  • in line 28
icmp defined in line 98; used 1 times
main defined in line 18; never used

Defined variables

buf defined in line 14; used 16 times
dbuf defined in line 9; used 4 times
fcnt defined in line 16; used 5 times
fnum defined in line 16; used 3 times
line defined in line 14; used 11 times
maildir defined in line 10; used 3 times
myname defined in line 7; used 3 times
stbuf defined in line 17; used 2 times
uid defined in line 8; used 2 times

Defined macros

MXF defined in line 15; used 2 times
Last modified: 1983-06-29
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1060
Valid CSS Valid XHTML 1.0 Strict