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