static char sccsid
[] = "@(#)netlpr.c 4.1 (Berkeley) %G%";
static char *netlpr_sid
= "@(#)netlpr.c 1.4";
netlpr [-m mach] [-l login] [-p password] [-f] [-n] [-q] [-c ?pr] [file1 ... filen]
send a set of files to the lineprinter on the mach machine.
if between CC machines, no account is needed, so no login
Other flags are simply passed thru.
-l login remote login name, ignored on CC
-p passwd remote password, " " "
-f force prompting of user name
-n don't send anything back
-c printer use the "printer" command instead of "lpr"
/* also, netlpr should check the remote lpr's other user execute
/* must run setuid root on CC machines only */
/* parms are flags to the lpr command on the rem mach */
int rcode
,uid
,pid
, Iflag
;
char parms
[BUFSIZ
], fnoacct
, *sn
, suid
[20], sLprCommand
[20];
static char tomachstr
[BUFSIZ
], realcmd
[BUFSIZ
], tempbuf
[BUFSIZ
],
strcpy(sLprCommand
,"lpr");
while(argc
> 0 && argv
[0][0] == '-'){
strcat( parms
, argv
[0] );
case 'c': harg(sLprCommand
); break;
case 'f': status
.force
++; break;
case 'l': harg(status
.login
); break;
remote
= lookup(tempbuf
);
fprintf(stderr
,"Unknown machine %s\n",tempbuf
);
case 'n': status
.nowrite
++; break;
case 'p': harg(status
.mpasswd
); break;
case 'q': status
.quiet
++; break;
case 'I': Iflag
++; break;
default: strcat(parms
,argv
[0]); strcat(parms
," "); break;
/* read the .netrc file, to get a value for "remote" */
if(remote
== 0)remote
= getremote(local
);
/* fnoacct is true if no password is needed to netlpr */
fnoacct
= machtype
[chtoinx(remote
)]==M_CC
&& machtype
[chtoinx(local
)]==M_CC
;
if(fnoacct
){ /* no acct needed. */
/* look in passwd file for jobno */
/* get status.localname */
sn
= SnFromUid(getuid());
fprintf(stderr
,"Unknown userid\n");
strcpy(status
.localname
,sn
);
/* prompt for login and passwd */
envloginpasswd(remote
,status
.login
,status
.mpasswd
);
/* check to see that the lpr command is one of the approved set */
if(strcmp(sLprCommand
,"lpr") != 0
&& strcmp(sLprCommand
,"vpr") != 0
&& strcmp(sLprCommand
,"epr") != 0
&& strcmp(sLprCommand
,"bpr") != 0){
"May not execute the '%s' command from netlpr.\n",
sprintf(sCmdAct
,"%s -c%s,%s %s",
sLprCommand
,status
.jobno
,status
.localname
,parms
);
else sprintf(sCmdAct
,"%s %s",sLprCommand
,parms
);
sprintf(tomachstr
,"-m%c",remote
);
sprintf(realcmd
,"netlpr %s%s",parms
,(argc
> 0 ? argv
[0] : ""));
while((pid
= fork()) == -1)sleep(2);
if(access(argv
[0],04) == -1){
mexecl(netcmd
,"net",tomachstr
,"-y",
"-l",status
.localname
,"-u",suid
,
"-s",argv
[0],"-c",realcmd
,sCmdAct
,0);
kexecl(netcmd
,"net",tomachstr
,
"-s",argv
[0],"-c",realcmd
,sCmdAct
,0);
mexecl(netcmd
,"net",tomachstr
,"-y","-b","-",
kexecl(netcmd
,"net",tomachstr
, "-",
fprintf(stderr
,"Network is down\n");