Annotation of 3BSD/cmd/net/netlpr.c, revision 1.1.1.1

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: main(argc,argv)
                     26:   char **argv; {
                     27:        /* parms are flags to the lpr command on the rem mach */
                     28:        int rcode,uid,pid;
                     29:        char parms[BUFSIZ], fnoacct, *sn, suid[20], sLprCommand[20];
                     30:        static char tomachstr[BUFSIZ], realcmd[BUFSIZ], tempbuf[BUFSIZ], sCmdAct[BUFSIZ];
                     31:        argv[argc] = 0;
                     32:        parms[0] = 0;
                     33:        debugflg = DBV;
                     34: 
                     35:        strcpy(sLprCommand,"lpr");
                     36: 
                     37:        argv++; argc--;
                     38:        while(argc > 0 && argv[0][0] == '-'){
                     39:                switch(argv[0][1]){
                     40:                case 'b': status.nonotify++; break;
                     41:                case 'c': harg(sLprCommand,&argc,&argv); break;
                     42:                case 'f': status.force++; break;
                     43:                case 'l': harg(status.login,&argc,&argv); break;
                     44:                case 'm': harg(tempbuf,&argc,&argv); 
                     45:                          remote = lookup(tempbuf);
                     46:                          break;
                     47:                case 'n': status.nowrite++; break;
                     48:                case 'p': harg(status.mpasswd,&argc,&argv); break;
                     49:                case 'q': status.quiet++; break;
                     50:                default:  strcat(parms,argv[0]); strcat(parms," "); break;
                     51:                }
                     52:                argc--, argv++;
                     53:                }
                     54:        /* read the .netrc file, to get a value for "remote" */
                     55:        commandfile();
                     56:        if(remote == 0)remote = getremote(local);
                     57:        /* fnoacct is true if no password is needed to netlpr */
                     58:        fnoacct = machtype[remote-'a']==M_CC&&machtype[local-'a']==M_CC;
                     59: 
                     60:        if(fnoacct){ /* no acct needed. */
                     61:                /* look in passwd file for jobno */
                     62:                uid = getuid();
                     63:                passwdent();
                     64:                sprintf(suid,"%d",uid);
                     65:        } else {
                     66:                /* get status.localname */
                     67:                sn = SnCurrent();
                     68:                if(sn == NULL){
                     69:                        fprintf(stderr,"Unknown userid\n");
                     70:                        exit(1);
                     71:                }
                     72:                strcpy(status.localname,sn);
                     73:                /* prompt for login and passwd */
                     74:                promptlogin(remote);
                     75:        }
                     76: 
                     77:        /* check to see that the lpr command is one of the approved set */
                     78:        if(strcmp(sLprCommand,"lpr") != 0
                     79:        && strcmp(sLprCommand,"epr") != 0
                     80:        && strcmp(sLprCommand,"bpr") != 0){
                     81:                fprintf(stderr,
                     82:                        "May not execute the '%s' command from netlpr.\n",
                     83:                        sLprCommand);
                     84:                exit(1);
                     85:        }
                     86: 
                     87:        do {
                     88:                if(fnoacct)
                     89:                        sprintf(sCmdAct,"%s -c%04d,%s %s",
                     90:                        sLprCommand,status.jobno,status.localname,parms);
                     91:                else    sprintf(sCmdAct,"%s %s",sLprCommand,parms);
                     92: 
                     93:                sprintf(tomachstr,"-m%c",remote);
                     94:                sprintf(realcmd,"netlpr %s%s",parms,(argc > 0 ? argv[0] : ""));
                     95: 
                     96:                while((pid = fork()) == -1)sleep(2);
                     97:                if(pid == 0){
                     98:                        if(argc > 0){
                     99:                                if(access(argv[0],04) == -1){
                    100:                                        perror(argv[0]);
                    101:                                        exit(1);
                    102:                                        }
                    103: # ifdef CC
                    104:                                if(fnoacct){
                    105:                                        setuid(0);
                    106:                                        mexecl(netcmd,"net",tomachstr,"-y",
                    107:                                        "-l",status.localname,"-u",suid,
                    108:                                        "-s",argv[0],"-c",realcmd,sCmdAct,0);
                    109:                                        }
                    110:                                else
                    111: # endif
                    112:                                {
                    113:                                        kexecl(netcmd,"net",tomachstr,
                    114:                                        "-s",argv[0],"-c",realcmd,sCmdAct,0);
                    115:                                        }
                    116:                                }
                    117:                        else {
                    118: # ifdef CC
                    119:                                if(fnoacct){
                    120:                                        setuid(0);
                    121:                                        mexecl(netcmd,"net",tomachstr,"-y","-",
                    122:                                        "-l",status.localname,"-u",suid,
                    123:                                        "-c",realcmd,sCmdAct,0);
                    124:                                        }
                    125:                                else
                    126: # endif
                    127:                                {
                    128:                                        kexecl(netcmd,"net",tomachstr, "-",
                    129:                                        "-c",realcmd,sCmdAct,0);
                    130:                                        }
                    131:                                }
                    132:                        fprintf(stderr,"Network is down\n");
                    133:                        exit(1);
                    134:                        }
                    135:                wait(&rcode);
                    136:                argc--, argv++;
                    137:                } while(argc > 0);
                    138:        exit(rcode >> 8);
                    139:        }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.