|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)xsend.c 4.3 6/30/83";
3: #endif
4:
5: #include "xmail.h"
6: #include <sys/types.h>
7: #include <pwd.h>
8: #include <sys/stat.h>
9: #include <sys/dir.h>
10: extern int errno;
11: struct stat stbuf;
12: int uid, destuid;
13: char *myname, *dest, *keyfile[128], line[128];
14: struct direct *dbuf;
15: char *maildir = "/usr/spool/secretmail/";
16: FILE *kf, *mf;
17: DIR *df;
18: MINT *a[42], *cd[6][128];
19: MINT *msg;
20: char buf[256], eof;
21: int dbg;
22: extern char *malloc(), *getlogin();
23:
24: main(argc, argv) char **argv;
25: { int i, nmax, len;
26: char *p;
27: long now;
28: if(argc != 2)
29: xfatal("mail to exactly one person");
30: uid = getuid();
31: p =getlogin();
32: if(p == NULL)
33: p = getpwuid(uid)->pw_name;
34: myname = malloc(strlen(p)+1);
35: strcpy(myname, p);
36: dest = argv[1];
37: strcpy(keyfile, maildir);
38: strcat(keyfile, dest);
39: strcat(keyfile, ".key");
40: if(stat(keyfile, &stbuf) <0)
41: xfatal("addressee not enrolled");
42: destuid = getpwnam(dest)->pw_uid;
43: if(destuid != stbuf.st_uid)
44: fprintf(stderr, "warning: addressee's key file may be subverted\n");
45: errno = 0;
46: kf = fopen(keyfile, "r");
47: if(kf == NULL)
48: xfatal("addressee's key weird");
49: df = opendir(maildir);
50: if(df == NULL)
51: { perror(maildir);
52: exit(1);
53: }
54: strcpy(line, dest);
55: strcat(line, ".%d");
56: nmax = -1;
57: while ((dbuf=readdir(df))!=NULL)
58: { if(sscanf(dbuf->d_name, line, &i) != 1)
59: continue;
60: if(i>nmax) nmax = i;
61: }
62: nmax ++;
63: for(i=0; i<10; i++)
64: { sprintf(line, "%s%s.%d", maildir, dest, nmax+i);
65: if(creat(line, 0666) >= 0) break;
66: }
67: if(i==10) xfatal("cannot create mail file");
68: mf = fopen(line, "w");
69: init();
70: time(&now);
71: sprintf(buf, "From %s %s", myname, ctime(&now) );
72: #ifdef DBG
73: dbg = 1;
74: #endif
75: run();
76: sprintf(buf, "mail %s <%snotice", dest, maildir);
77: system(buf);
78: exit(0);
79: }
80: mkcd()
81: { int i, j, k, n;
82: for(i=0; i<42; i++)
83: nin(a[i], kf);
84: fclose(kf);
85: for(i=0; i<6; i++)
86: for(j=0; j<128; j++)
87: for(k=j, n=0; k>0 && n<7; n++, k>>=1)
88: if(k&01) madd(cd[i][j], a[7*i+n], cd[i][j]);
89: }
90: encipher(s) char s[6];
91: { int i;
92: msub(msg, msg, msg);
93: for(i=0; i<6; i++)
94: madd(msg, cd[i][s[i]&0177], msg);
95: }
96: init()
97: { int i, j;
98: msg = itom(0);
99: for(i=0; i<42; i++)
100: a[i] = itom(0);
101: for(i=0; i<6; i++)
102: for(j=0; j<128; j++)
103: cd[i][j] = itom(0);
104: mkcd();
105: }
106: run()
107: { char *p;
108: int i, len, eof = 0;
109: for(;;)
110: { len = strlen(buf);
111: for(i=0; i<len/6; i++)
112: {
113: encipher(buf+6*i);
114: nout(msg, mf);
115: }
116: p = buf;
117: for(i *= 6; i<len; i++)
118: *p++ = buf[i];
119: if(eof) return;
120: fgets(p, sizeof(buf)-6, stdin);
121: if(strcmp(p, ".\n") == 0 || feof(stdin))
122: { for(i=0; i<6; i++) *p++ = ' ';
123: *p = 0;
124: eof = 1;
125: }
126: }
127: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.