file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.sbin / lpr / lpr / lpr.c
index 79621f3..1e409d0 100644 (file)
 
 char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
 
 
 char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
 
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)lpr.c      4.26 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983, 1989 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
 
 
+#ifndef lint
+static char sccsid[] = "@(#)lpr.c      5.6 (Berkeley) %G%";
+#endif /* not lint */
 /*
  *      lpr -- off line print
  *
 /*
  *      lpr -- off line print
  *
@@ -71,9 +93,12 @@ static char sccsid[] = "@(#)lpr.c    4.26 (Berkeley) %G%";
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <pwd.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <pwd.h>
+#include <grp.h>
 #include <signal.h>
 #include <ctype.h>
 #include <signal.h>
 #include <ctype.h>
+#include <syslog.h>
 #include "lp.local.h"
 #include "lp.local.h"
+#include "pathnames.h"
 
 char    *tfname;               /* tmp copy of cf before linking */
 char    *cfname;               /* daemon control files, linked from tf's */
 
 char    *tfname;               /* tmp copy of cf before linking */
 char    *cfname;               /* daemon control files, linked from tf's */
@@ -101,13 +126,14 @@ char      *class = host;          /* class title on header page */
 char    *jobname;              /* job name on header page */
 char   *name;                  /* program name */
 char   *printer;               /* printer name */
 char    *jobname;              /* job name on header page */
 char   *name;                  /* program name */
 char   *printer;               /* printer name */
-char   buf[BUFSIZ];
+struct stat statb;
 
 int    MX;                     /* maximum number of blocks to copy */
 int    MC;                     /* maximum number of copies allowed */
 int    DU;                     /* daemon user-id */
 char   *SD;                    /* spool directory */
 char   *LO;                    /* lock file name */
 
 int    MX;                     /* maximum number of blocks to copy */
 int    MC;                     /* maximum number of copies allowed */
 int    DU;                     /* daemon user-id */
 char   *SD;                    /* spool directory */
 char   *LO;                    /* lock file name */
+char   *RG;                    /* restrict group */
 short  SC;                     /* suppress multiple copies */
 
 char   *getenv();
 short  SC;                     /* suppress multiple copies */
 
 char   *getenv();
@@ -122,8 +148,10 @@ main(argc, argv)
 {
        extern struct passwd *getpwuid();
        struct passwd *pw;
 {
        extern struct passwd *getpwuid();
        struct passwd *pw;
+       struct group *gptr;
        extern char *itoa();
        register char *arg, *cp;
        extern char *itoa();
        register char *arg, *cp;
+       char buf[BUFSIZ];
        int i, f;
        struct stat stb;
 
        int i, f;
        struct stat stb;
 
@@ -138,6 +166,7 @@ main(argc, argv)
 
        name = argv[0];
        gethostname(host, sizeof (host));
 
        name = argv[0];
        gethostname(host, sizeof (host));
+       openlog("lpd", 0, LOG_LPR);
 
        while (argc > 1 && argv[1][0] == '-') {
                argc--;
 
        while (argc > 1 && argv[1][0] == '-') {
                argc--;
@@ -163,6 +192,16 @@ main(argc, argv)
                        }
                        break;
 
                        }
                        break;
 
+               case 'U':               /* user name */
+                       hdr++;
+                       if (arg[2])
+                               person = &arg[2];
+                       else if (argc > 1) {
+                               argc--;
+                               person = *++argv;
+                       }
+                       break;
+
                case 'J':               /* job name */
                        hdr++;
                        if (arg[2])
                case 'J':               /* job name */
                        hdr++;
                        if (arg[2])
@@ -256,9 +295,27 @@ main(argc, argv)
         * algorithm as lprm. 
         */
        userid = getuid();
         * algorithm as lprm. 
         */
        userid = getuid();
-       if ((pw = getpwuid(userid)) == NULL)
-               fatal("Who are you?");
-       person = pw->pw_name;
+       if (userid != DU || person == 0) {
+               if ((pw = getpwuid(userid)) == NULL)
+                       fatal("Who are you?");
+               person = pw->pw_name;
+       }
+       /*
+        * Check for restricted group access.
+        */
+       if (RG != NULL && userid != DU) {
+               if ((gptr = getgrnam(RG)) == NULL)
+                       fatal("Restricted group specified incorrectly");
+               if (gptr->gr_gid != getgid()) {
+                       while (*gptr->gr_mem != NULL) {
+                               if ((strcmp(person, *gptr->gr_mem)) == 0)
+                                       break;
+                               gptr->gr_mem++;
+                       }
+                       if (*gptr->gr_mem == NULL)
+                               fatal("Not a member of the restricted group");
+               }
+       }
        /*
         * Check to make sure queuing is enabled if userid is not root.
         */
        /*
         * Check to make sure queuing is enabled if userid is not root.
         */
@@ -305,6 +362,8 @@ main(argc, argv)
                        continue;       /* file unreasonable */
 
                if (sflag && (cp = linked(arg)) != NULL) {
                        continue;       /* file unreasonable */
 
                if (sflag && (cp = linked(arg)) != NULL) {
+                       (void) sprintf(buf, "%d %d", statb.st_dev, statb.st_ino);
+                       card('S', buf);
                        if (format == 'p')
                                card('T', title ? title : arg);
                        for (i = 0; i < ncopies; i++)
                        if (format == 'p')
                                card('T', title ? title : arg);
                        for (i = 0; i < ncopies; i++)
@@ -370,6 +429,7 @@ copy(f, n)
        char n[];
 {
        register int fd, i, nr, nc;
        char n[];
 {
        register int fd, i, nr, nc;
+       char buf[BUFSIZ];
 
        if (format == 'p')
                card('T', title ? title : n);
 
        if (format == 'p')
                card('T', title ? title : n);
@@ -443,6 +503,7 @@ linked(file)
 card(c, p2)
        register char c, *p2;
 {
 card(c, p2)
        register char c, *p2;
 {
+       char buf[BUFSIZ];
        register char *p1 = buf;
        register int len = 2;
 
        register char *p1 = buf;
        register int len = 2;
 
@@ -524,7 +585,6 @@ test(file)
        char *file;
 {
        struct exec execb;
        char *file;
 {
        struct exec execb;
-       struct stat statb;
        register int fd;
        register char *cp;
 
        register int fd;
        register char *cp;
 
@@ -609,6 +669,7 @@ chkprinter(s)
        char *s;
 {
        int status;
        char *s;
 {
        int status;
+       char buf[BUFSIZ];
        static char pbuf[BUFSIZ/2];
        char *bp = pbuf;
        extern char *pgetstr();
        static char pbuf[BUFSIZ/2];
        char *bp = pbuf;
        extern char *pgetstr();
@@ -618,9 +679,10 @@ chkprinter(s)
        else if (status == 0)
                fatal("%s: unknown printer", s);
        if ((SD = pgetstr("sd", &bp)) == NULL)
        else if (status == 0)
                fatal("%s: unknown printer", s);
        if ((SD = pgetstr("sd", &bp)) == NULL)
-               SD = DEFSPOOL;
+               SD = _PATH_DEFSPOOL;
        if ((LO = pgetstr("lo", &bp)) == NULL)
                LO = DEFLOCK;
        if ((LO = pgetstr("lo", &bp)) == NULL)
                LO = DEFLOCK;
+       RG = pgetstr("rg", &bp);
        if ((MX = pgetnum("mx")) < 0)
                MX = DEFMX;
        if ((MC = pgetnum("mc")) < 0)
        if ((MX = pgetnum("mx")) < 0)
                MX = DEFMX;
        if ((MC = pgetnum("mc")) < 0)
@@ -637,6 +699,7 @@ mktemps()
 {
        register int c, len, fd, n;
        register char *cp;
 {
        register int c, len, fd, n;
        register char *cp;
+       char buf[BUFSIZ];
        char *mktemp();
 
        (void) sprintf(buf, "%s/.seq", SD);
        char *mktemp();
 
        (void) sprintf(buf, "%s/.seq", SD);