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