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