diff options
author | joerg <joerg@FreeBSD.org> | 1996-05-05 14:04:33 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1996-05-05 14:04:33 +0000 |
commit | 0291e848bc787305335af649ac14bc8fe5a19a49 (patch) | |
tree | f679484620675241701b875cbab6124b83dc1136 /usr.sbin/lpr/lpc | |
parent | 825cd02612729df0559ca26d13d946c625215900 (diff) | |
download | FreeBSD-src-0291e848bc787305335af649ac14bc8fe5a19a49.zip FreeBSD-src-0291e848bc787305335af649ac14bc8fe5a19a49.tar.gz |
Vendor-branch import of the 4.4BSD-Lite2 code for lpr. There are
several bugfixes in it that are worth considering.
Don't be alarmed about the import conflicts...
Obtained from: 4.4BSD-Lite2
Diffstat (limited to 'usr.sbin/lpr/lpc')
-rw-r--r-- | usr.sbin/lpr/lpc/cmds.c | 3 | ||||
-rw-r--r-- | usr.sbin/lpr/lpc/lpc.8 | 7 | ||||
-rw-r--r-- | usr.sbin/lpr/lpc/lpc.c | 45 |
3 files changed, 47 insertions, 8 deletions
diff --git a/usr.sbin/lpr/lpc/cmds.c b/usr.sbin/lpr/lpc/cmds.c index 7c2b6fe..937fc08 100644 --- a/usr.sbin/lpr/lpc/cmds.c +++ b/usr.sbin/lpr/lpc/cmds.c @@ -39,7 +39,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/28/95"; #endif /* not lint */ /* @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; #include <sys/param.h> #include <sys/time.h> #include <sys/stat.h> +#include <sys/file.h> #include <signal.h> #include <fcntl.h> diff --git a/usr.sbin/lpr/lpc/lpc.8 b/usr.sbin/lpr/lpc/lpc.8 index a786adc..280a8b2 100644 --- a/usr.sbin/lpr/lpc/lpc.8 +++ b/usr.sbin/lpr/lpc/lpc.8 @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)lpc.8 8.3 (Berkeley) 4/19/94 +.\" @(#)lpc.8 8.5 (Berkeley) 4/28/95 .\" -.Dd April 19, 1994 +.Dd April 28, 1995 .Dt LPC 8 .Os BSD 4.2 .Sh NAME @@ -117,6 +117,7 @@ to put new jobs in the spool queue. .It Ic exit .It Ic quit Exit from lpc. +.ne 1i .Pp .It Ic restart No {\ all\ |\ printer\ } Attempt to start a new printer daemon. @@ -165,7 +166,7 @@ abbreviation matches more than one command .It Sy "?Invalid command" no match was found .It Sy "?Privileged command" -command can be executed by root only +you must be a member of group "operator" or root to execute this command .El .Sh HISTORY The diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c index 01cfc12..64432b2 100644 --- a/usr.sbin/lpr/lpc/lpc.c +++ b/usr.sbin/lpr/lpc/lpc.c @@ -39,7 +39,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)lpc.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> @@ -53,10 +53,16 @@ static char sccsid[] = "@(#)lpc.c 8.1 (Berkeley) 6/6/93"; #include <stdio.h> #include <ctype.h> #include <string.h> +#include <grp.h> +#include <sys/param.h> #include "lp.h" #include "lpc.h" #include "extern.h" +#ifndef LPR_OPER +#define LPR_OPER "operator" /* group name of lpr operators */ +#endif + /* * lpc -- line printer control program */ @@ -74,6 +80,7 @@ static void cmdscanner __P((int)); static struct cmd *getcmd __P((char *)); static void intr __P((int)); static void makeargv __P((void)); +static int ingroup __P((char *)); int main(argc, argv) @@ -95,7 +102,7 @@ main(argc, argv) printf("?Invalid command\n"); exit(1); } - if (c->c_priv && getuid()) { + if (c->c_priv && getuid() && ingroup(LPR_OPER) == 0) { printf("?Privileged command\n"); exit(1); } @@ -151,7 +158,7 @@ cmdscanner(top) printf("?Invalid command\n"); continue; } - if (c->c_priv && getuid()) { + if (c->c_priv && getuid() && ingroup(LPR_OPER) == 0) { printf("?Privileged command\n"); continue; } @@ -160,7 +167,7 @@ cmdscanner(top) longjmp(toplevel, 0); } -struct cmd * +static struct cmd * getcmd(name) register char *name; { @@ -275,3 +282,33 @@ help(argc, argv) c->c_name, c->c_help); } } + +/* + * return non-zero if the user is a member of the given group + */ +static int +ingroup(grname) + char *grname; +{ + static struct group *gptr=NULL; + static gid_t groups[NGROUPS]; + register gid_t gid; + register int i; + + if (gptr == NULL) { + if ((gptr = getgrnam(grname)) == NULL) { + fprintf(stderr, "Warning: unknown group '%s'\n", + grname); + return(0); + } + if (getgroups(NGROUPS, groups) < 0) { + perror("getgroups"); + exit(1); + } + } + gid = gptr->gr_gid; + for (i = 0; i < NGROUPS; i++) + if (gid == groups[i]) + return(1); + return(0); +} |