Annotation of 43BSD/old/berknet/sendberkmail.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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