1*8205Smckusick static char sccsid[] = "@(#)sendberkmail.c 4.1 (Berkeley) 09/12/82";
2*8205Smckusick
3*8205Smckusick # include "defs.h"
4*8205Smckusick
5*8205Smckusick /*
6*8205Smckusick Usage:
7*8205Smckusick sendberkmail [-m mach ] [-f addrfrom] [-h hopcnt] -t addrto
8*8205Smckusick
9*8205Smckusick Archaic Usage:
10*8205Smckusick sendberkmail mach:user
11*8205Smckusick
12*8205Smckusick Send remote mail to user on mach.
13*8205Smckusick Only one addrto allowed.
14*8205Smckusick
15*8205Smckusick Sendberkmail uses the network to send an mmail command
16*8205Smckusick to the remote machine. It specifies the source, destination,
17*8205Smckusick and a hop count only.
18*8205Smckusick
19*8205Smckusick Sendberkmail uses the -q option of net, so only error msgs
20*8205Smckusick and non-zero return codes will be sent back.
21*8205Smckusick
22*8205Smckusick It is best to think of sendberkmail as a transport mechanism:
23*8205Smckusick It takes mail from one machine to another machine (specified
24*8205Smckusick using the -m option) and executes the local mail program
25*8205Smckusick there with a to-address of "addrto", and a from-address
26*8205Smckusick of "addrfrom". If the -m option is not given, it parses the
27*8205Smckusick "addrto" field to get a berkeley network address.
28*8205Smckusick This extreme generality is necessary when destinations are on
29*8205Smckusick different networks, consider a command from the Ing70:
30*8205Smckusick
31*8205Smckusick sendberkmail -m csvax -f schmidt@parc -t research!chuck
32*8205Smckusick
33*8205Smckusick This is clearly a forwarding function- send mail from the Arpanet
34*8205Smckusick to the Bell Net, which calls our CSVAX.
35*8205Smckusick Alternatively, executed on the CSVAX,
36*8205Smckusick sendberkmail -m ing70 -f research!chuck -t schmidt@parc
37*8205Smckusick sends mail the other way.
38*8205Smckusick
39*8205Smckusick There is duplication in the arguments because of
40*8205Smckusick a need to convert to labelled parameters.
41*8205Smckusick See the note in mmail.c to that effect.
42*8205Smckusick
43*8205Smckusick
44*8205Smckusick Options:
45*8205Smckusick -t addrto mail command on remote machine will be
46*8205Smckusick fed "addrto" as address
47*8205Smckusick -f addrfrom mail will be "From" addrfrom
48*8205Smckusick -m mach send this mail to the "mach" machine
49*8205Smckusick -h hopcnt if this hopcnt hits a threshold, there
50*8205Smckusick is presumed to be an infinite loop.
51*8205Smckusick
52*8205Smckusick */
main(argc,argv)53*8205Smckusick main(argc,argv)
54*8205Smckusick char **argv; {
55*8205Smckusick char addrto[BUFSIZ], addrfrom[BUFSIZ], *sn;
56*8205Smckusick char mchto = 0, snto[BUFSIZ], snfrom[BUFSIZ], smchto[20], mchfrom;
57*8205Smckusick int cmdstr[BUFSIZ], hopcntstr[20];
58*8205Smckusick char rcmd[BUFSIZ];
59*8205Smckusick int hopcnt = 0;
60*8205Smckusick
61*8205Smckusick argc[argv] = 0;
62*8205Smckusick debugflg = DBV;
63*8205Smckusick addrfrom[0] = 0;
64*8205Smckusick addrto[0] = 0;
65*8205Smckusick
66*8205Smckusick while(argc > 1 && argv[1][0] == '-'){
67*8205Smckusick argc--; argv++;
68*8205Smckusick switch(argv[0][1]){
69*8205Smckusick case 'f':
70*8205Smckusick harg(addrfrom);
71*8205Smckusick break;
72*8205Smckusick case 'h':
73*8205Smckusick harg(hopcntstr);
74*8205Smckusick hopcnt = atoi(hopcntstr);
75*8205Smckusick break;
76*8205Smckusick case 'm':
77*8205Smckusick harg(smchto);
78*8205Smckusick mchto = lookup(smchto);
79*8205Smckusick break;
80*8205Smckusick case 't':
81*8205Smckusick harg(addrto);
82*8205Smckusick break;
83*8205Smckusick /* it is important to ignore unknown flags
84*8205Smckusick for compatibility reasons */
85*8205Smckusick }
86*8205Smckusick }
87*8205Smckusick
88*8205Smckusick /* handle to address */
89*8205Smckusick if(argc > 1)strcpy(addrto,argv[1]);
90*8205Smckusick if(addrto[0] == 0){
91*8205Smckusick fprintf(stderr,"Usage: sendberkmail mach:user\n");
92*8205Smckusick exit(EX_USAGE);
93*8205Smckusick }
94*8205Smckusick if(mchto == 0)
95*8205Smckusick mchto = MchSFromAddr(snto,addrto);
96*8205Smckusick else
97*8205Smckusick strcpy(snto,addrto);
98*8205Smckusick if(mchto == 0){
99*8205Smckusick fprintf(stderr,"Unknown host %s\n",addrto);
100*8205Smckusick exit(EX_NOHOST);
101*8205Smckusick };
102*8205Smckusick if(mchto == local){
103*8205Smckusick fprintf(stderr,
104*8205Smckusick "Use mail to send to %s on this machine. Mail not delivered.\n",
105*8205Smckusick addrto);
106*8205Smckusick exit(EX_NOUSER);
107*8205Smckusick }
108*8205Smckusick sprintf(rcmd,"mail %s",addrto);
109*8205Smckusick
110*8205Smckusick /* handle from address */
111*8205Smckusick if(addrfrom[0] == 0){
112*8205Smckusick char name[100];
113*8205Smckusick SnCurrent(name);
114*8205Smckusick sprintf(addrfrom,"%s:%s",longname(local),name);
115*8205Smckusick }
116*8205Smckusick mchfrom = MchSFromAddr(snfrom,addrfrom);
117*8205Smckusick
118*8205Smckusick /* uses new options of mmail */
119*8205Smckusick /* X's are for compatibility with mmail */
120*8205Smckusick sprintf(cmdstr,"%s XXX XXX XXX -f '%s' -t '%s' -h %d", MMAILCMD,
121*8205Smckusick addrfrom,addrto,hopcnt);
122*8205Smckusick /* old code:
123*8205Smckusick sprintf(cmdstr,"%s '%s' %s '%s'", MMAILCMD,snfrom,
124*8205Smckusick longname(mchfrom),snto);
125*8205Smckusick */
126*8205Smckusick
127*8205Smckusick
128*8205Smckusick mexecl(netcmd,"net","-m",longname(mchto),"-q","-l","network",
129*8205Smckusick "-","-c",rcmd,cmdstr,0);
130*8205Smckusick perror(netcmd);
131*8205Smckusick fprintf(stderr,"Network is down\n");
132*8205Smckusick exit(EX_UNAVAILABLE);
133*8205Smckusick }
134*8205Smckusick
SnCurrent(name)135*8205Smckusick SnCurrent(name)
136*8205Smckusick char *name;
137*8205Smckusick {
138*8205Smckusick char *sn;
139*8205Smckusick sn = getlogin();
140*8205Smckusick if(sn == NULL || *sn == 0 || *sn == ' '){
141*8205Smckusick struct passwd *pwd;
142*8205Smckusick pwd = getpwuid(getuid()); /* will read passwd file */
143*8205Smckusick if(pwd != NULL) sn = pwd->pw_name;
144*8205Smckusick if(sn == NULL){
145*8205Smckusick fprintf(stderr,"Who are you?\n");
146*8205Smckusick exit(EX_OSERR);
147*8205Smckusick }
148*8205Smckusick }
149*8205Smckusick strcpy(name, sn);
150*8205Smckusick }
151