|
|
1.1 root 1: /*
2:
3: netlpr [-m mach] [-l login] [-p password] [-f] [-n] [-q] [-c ?pr] [file1 ... filen]
4:
5: send a set of files to the lineprinter on the mach machine.
6: if between CC machines, no account is needed, so no login
7: or passwd is prompted.
8: Other flags are simply passed thru.
9: Flags:
10: -m mach remote machine
11: -l login remote login name, ignored on CC
12: -p passwd remote password, " " "
13: -f force prompting of user name
14: -n don't send anything back
15: -q quiet option
16: -c printer use the "printer" command instead of "lpr"
17: */
18: /* also, netlpr should check the remote lpr's other user execute
19: bit to see if it is down
20: */
21: /* must run setuid root on CC machines only */
22:
23: # include "defs.h"
24:
25: /* global variables */
26: struct userinfo status;
27:
28: main(argc,argv)
29: char **argv; {
30: /* parms are flags to the lpr command on the rem mach */
31: int rcode,uid,pid;
32: char parms[BUFSIZ], fnoacct, *sn, suid[20], sLprCommand[20];
33: static char tomachstr[BUFSIZ], realcmd[BUFSIZ], tempbuf[BUFSIZ],
34: sCmdAct[BUFSIZ];
35: argv[argc] = 0;
36: parms[0] = 0;
37: debugflg = DBV;
38:
39: strcpy(sLprCommand,"lpr");
40:
41: argv++; argc--;
42: while(argc > 0 && argv[0][0] == '-'){
43: switch(argv[0][1]){
44: case 'b': status.nonotify++; break;
45: case 'c': harg(sLprCommand,&argc,&argv); break;
46: case 'f': status.force++; break;
47: case 'l': harg(status.login,&argc,&argv); break;
48: case 'm': harg(tempbuf,&argc,&argv);
49: remote = lookup(tempbuf);
50: if(remote == 0){
51: fprintf(stderr,"Unknown machine %s\n",tempbuf);
52: exit(EX_NOHOST);
53: }
54: break;
55: case 'n': status.nowrite++; break;
56: case 'p': harg(status.mpasswd,&argc,&argv); break;
57: case 'q': status.quiet++; break;
58: default: strcat(parms,argv[0]); strcat(parms," "); break;
59: }
60: argc--, argv++;
61: }
62: /* read the .netrc file, to get a value for "remote" */
63: commandfile();
64: if(remote == 0)remote = getremote(local);
65: /* fnoacct is true if no password is needed to netlpr */
66: fnoacct = machtype[remote-'a']==M_CC&&machtype[local-'a']==M_CC;
67:
68: if(fnoacct){ /* no acct needed. */
69: /* look in passwd file for jobno */
70: uid = getuid();
71: passwdent();
72: sprintf(suid,"%d",uid);
73: } else {
74: /* get status.localname */
75: sn = SnFromUid(getuid());
76: if(sn == NULL){
77: fprintf(stderr,"Unknown userid\n");
78: exit(EX_OSFILE);
79: }
80: strcpy(status.localname,sn);
81: /* prompt for login and passwd */
82: envloginpasswd(remote,status.login,status.mpasswd);
83: promptlogin(remote);
84: }
85:
86: /* check to see that the lpr command is one of the approved set */
87: if(strcmp(sLprCommand,"lpr") != 0
88: && strcmp(sLprCommand,"vpr") != 0
89: && strcmp(sLprCommand,"epr") != 0
90: && strcmp(sLprCommand,"bpr") != 0){
91: fprintf(stderr,
92: "May not execute the '%s' command from netlpr.\n",
93: sLprCommand);
94: exit(EX_USAGE);
95: }
96:
97: do {
98: if(fnoacct)
99: sprintf(sCmdAct,"%s -c%04d,%s %s",
100: sLprCommand,status.jobno,status.localname,parms);
101: else sprintf(sCmdAct,"%s %s",sLprCommand,parms);
102:
103: sprintf(tomachstr,"-m%c",remote);
104: sprintf(realcmd,"netlpr %s%s",parms,(argc > 0 ? argv[0] : ""));
105:
106: while((pid = fork()) == -1)sleep(2);
107: if(pid == 0){
108: if(argc > 0){
109: if(access(argv[0],04) == -1){
110: perror(argv[0]);
111: exit(EX_USAGE);
112: }
113: # ifdef NOREMACCT
114: if(fnoacct){
115: setuid(0);
116: mexecl(netcmd,"net",tomachstr,"-y",
117: "-l",status.localname,"-u",suid,
118: "-s",argv[0],"-c",realcmd,sCmdAct,0);
119: perror(netcmd);
120: }
121: else
122: # endif
123: {
124: kexecl(netcmd,"net",tomachstr,
125: "-s",argv[0],"-c",realcmd,sCmdAct,0);
126: perror(netcmd);
127: }
128: }
129: else {
130: # ifdef NOREMACCT
131: if(fnoacct){
132: setuid(0);
133: mexecl(netcmd,"net",tomachstr,"-y","-",
134: "-l",status.localname,"-u",suid,
135: "-c",realcmd,sCmdAct,0);
136: perror(netcmd);
137: }
138: else
139: # endif
140: {
141: kexecl(netcmd,"net",tomachstr, "-",
142: "-c",realcmd,sCmdAct,0);
143: perror(netcmd);
144: }
145: }
146: fprintf(stderr,"Network is down\n");
147: exit(EX_UNAVAILABLE);
148: }
149: wait(&rcode);
150: argc--, argv++;
151: } while(argc > 0);
152: exit(rcode >> 8);
153: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.