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

Defined functions

appss defined in line 132; used 6 times
main defined in line 31; never used

Defined variables

status defined in line 29; used 14 times
Last modified: 1980-07-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 775
Valid CSS Valid XHTML 1.0 Strict