Annotation of 43BSDReno/old/berknet/netmail.c, revision 1.1.1.1

1.1       root        1: static char sccsid[] = "@(#)netmail.c  4.1     (Berkeley)      9/12/82";
                      2: 
                      3: /* sccs id variable */
                      4: static char *netmail_sid = "@(#)netmail.c      1.2";
                      5: /*
                      6: 
                      7: 
                      8:  netmail [-c] [-l ...] [-p ...] [-f] [-n] [-q] ([mach] | [mach:username])
                      9: 
                     10:    Read mail on remote machine "mach"
                     11:    Sends a command to the remote machine to "mail" the mail
                     12:    to this machine.
                     13: 
                     14:    If the -c option is specified, this command is a mail check command,
                     15:    and in this mode it logs into the remote machine as "network"
                     16:    and determines if mach:username has mail.
                     17:    It writes/mails a message to that effect.
                     18:    This variant is intended to be used in .login files, silently
                     19:    checking if you have mail on another machine.
                     20: 
                     21:    Must duplicate effort that will be redone by the net command-
                     22:    the calls to commandfile and promptlogin are necessary
                     23:    to get a value for the login name to send to the prmail
                     24:    command on the other machine.
                     25:    May read the passwd file:
                     26:        1. Commandfile calls getenv(HOME) to get the home directory.
                     27:           If not easily reached,....
                     28:        2. SnCurrent() calls getlogin(). If no entry in utmp file,
                     29:           will read passwd file.
                     30:  */
                     31: # include "defs.h"
                     32: 
                     33: /* global variables */
                     34: struct userinfo status;
                     35: 
                     36: main(argc,argv)
                     37:   char **argv; {
                     38:        char *s;
                     39:        char machparm[BUFSIZ], fromaddress[BUFSIZ], fMailCheck = 0;
                     40:        char rcmd[BUFSIZ], fquiet = 0;
                     41:        debugflg = DBV;
                     42:        strcpy(rcmd,"netmail");
                     43:        argc--; argv++;
                     44:        while(argc > 0 && argv[0][0] == '-'){
                     45:                switch(argv[0][1]){
                     46:                case 'b':       status.nonotify++; appss(rcmd,argv[0]); break;
                     47:                case 'c':       fMailCheck++;      appss(rcmd,argv[0]); break;
                     48:                case 'f':       status.force++;    appss(rcmd,argv[0]); break;
                     49:                case 'l':       harg(status.login); break;
                     50:                case 'n':       status.nowrite++;  appss(rcmd,argv[0]); break;
                     51:                case 'p':       harg(status.mpasswd); break;
                     52:                case 'q':       fquiet = 1;        appss(rcmd,argv[0]); break;
                     53:                default:
                     54:                        fprintf(stderr,
                     55:        "Usage: netmail [-l login] [-p password] [-c] [-f] [-n] [-q] [mach]\n");
                     56:                        exit(EX_USAGE);
                     57:                }
                     58:                argc--, argv++;
                     59:                }
                     60:        if(argc > 0){
                     61:                if(FMemberSCh(argv[0],':'))
                     62:                        remote = MchSFromAddr(status.login,argv[0]);
                     63:                else
                     64:                        remote = lookup(argv[0]);
                     65:                if(remote == 0){
                     66:                        fprintf(stderr,"Unknown machine %s\n",argv[0]);
                     67:                        exit(EX_NOHOST);
                     68:                }
                     69:                appss(rcmd,argv[0]);
                     70:        }
                     71: 
                     72:        /* read the .netrc file to get a value for remote */
                     73:        /* will get status.login, passwd, and force for fetch variant */
                     74:        commandfile();
                     75:        if(remote == 0)remote = getremote(local);
                     76:        sprintf(machparm,"-m%c",remote);
                     77:                
                     78: 
                     79:        if(remote == local){
                     80:                fprintf(stderr,
                     81:                "Use the mail command to read your mail on this machine.\n");
                     82:                exit(EX_USAGE);
                     83:        }
                     84: 
                     85: /* read pw file, get local addr to send to prmail, store in status.localname */
                     86:        s = SnFromUid(getuid());
                     87:        if(s == NULL){
                     88:                fprintf(stderr,"Unknown local user\n");
                     89:                exit(EX_OSFILE);
                     90:        }
                     91:        strcpy(status.localname,s);
                     92:        sprintf(fromaddress,"%s:%s",longname(local),s);
                     93: 
                     94:        /* mail check variant */
                     95:        if(fMailCheck){
                     96:                if(status.login[0] == 0){
                     97:                        fprintf(stderr,
                     98:                        "Must supply a remote user name for mail check.\n");
                     99:                        exit(EX_USAGE);
                    100:                }
                    101:                /* send mail check over, no passwd needed */
                    102:                if(fquiet)
                    103:                        mexecl(netcmd,"net","-q",machparm,"-l","network",
                    104:                        "-c",rcmd,
                    105:                        PRMAIL,"-c","-l",status.login,"-f",fromaddress,0);
                    106:                else
                    107:                        mexecl(netcmd,"net","-q",machparm,"-l","network",
                    108:                        "-c",rcmd,
                    109:                        PRMAIL,"-c","-l",status.login,"-f",fromaddress,"-k",0);
                    110:                perror(netcmd);
                    111:                fprintf(stderr,"Network is down\n");
                    112:                exit(EX_UNAVAILABLE);
                    113:        }
                    114: 
                    115:        /* mail forward variant */
                    116: 
                    117:        /* 
                    118:           get name to send as parameter to prmail.
                    119:           required for multiple login names with the same uid's
                    120:           stored in status.login
                    121:        */
                    122:        envloginpasswd(remote,status.login,status.mpasswd); /* look in env */
                    123:        promptlogin(remote);    /* prompt for name, passwd explicitely */
                    124: 
                    125:        if(fquiet)
                    126:                kexecl(netcmd,"net","-q",machparm,"-c",rcmd,PRMAIL,"-l",
                    127:                        status.login,"-f",fromaddress,"-r",0);
                    128:        else
                    129:                kexecl(netcmd,"net","-q",machparm,"-c",rcmd,PRMAIL,"-l",
                    130:                        status.login,"-f",fromaddress,"-r","-k",0);
                    131:        perror(netcmd);
                    132:        fprintf(stderr,"Network is down\n");
                    133:        exit(EX_UNAVAILABLE);
                    134:        }
                    135: /*
                    136:        append string sfrom to end of string sto, preceded by blank */
                    137: appss(sto,sfrom)
                    138:        register char *sto, *sfrom;
                    139: {
                    140:        strcat(sto," ");
                    141:        strcat(sto,sfrom);
                    142: }

unix.superglobalmegacorp.com

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