13
14
* 2. Redistributions in binary form must reproduce the above copyright
14
15
* notice, this list of conditions and the following disclaimer in the
15
16
* documentation and/or other materials provided with the distribution.
16
* 3. All advertising materials mentioning features or use of this software
17
* must display the following acknowledgement:
18
* This product includes software developed by the University of
19
* California, Berkeley and its contributors.
20
* 4. Neither the name of the University nor the names of its contributors
17
* 3. Neither the name of the University nor the names of its contributors
21
18
* may be used to endorse or promote products derived from this software
22
19
* without specific prior written permission.
38
static char copyright[] =
35
static const char copyright[] =
39
36
"@(#) Copyright (c) 1983, 1993\n\
40
37
The Regents of the University of California. All rights reserved.\n";
41
38
#endif /* not lint */
45
static char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
42
static const char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
47
static char rcsid[] = "$OpenBSD: lprm.c,v 1.5 1997/01/17 16:12:47 millert Exp $";
44
static const char rcsid[] = "$OpenBSD: lprm.c,v 1.16 2003/06/02 23:36:53 millert Exp $";
49
46
#endif /* not lint */
80
81
int requests; /* # of spool requests */
81
82
char *user[MAXUSERS]; /* users to process */
82
83
int users; /* # of users in user array */
83
uid_t uid, euid; /* real and effective user id's */
85
static char luser[16]; /* buffer for person */
87
void usage __P((void));
84
volatile sig_atomic_t gotintr; /* set when we receive SIGINT */
85
static char luser[LOGIN_NAME_MAX /*MAXLOGNAME*/]; /* buffer for person */
87
static void usage(void);
90
main(int argc, char **argv)
99
seteuid(uid); /* be safe */
98
* Simulate setuid daemon w/ PRIV_END called.
99
* We don't want lpr to actually be setuid daemon since that
100
* requires that the lpr binary be owned by user daemon, which
101
* is potentially unsafe.
103
if ((pw = getpwnam(DEFUID)) == NULL)
104
errx(1, "'lp' uid not in password file");
105
effective_uid = pw->pw_uid;
107
effective_gid = pw->pw_gid;
109
setresgid(real_gid, real_gid, effective_gid);
110
setresuid(real_uid, real_uid, effective_uid);
101
112
gethostname(host, sizeof(host));
102
openlog("lpd", 0, LOG_LPR);
103
if ((p = getpwuid(getuid())) == NULL)
113
openlog("lprm", 0, LOG_LPR);
114
if ((pw = getpwuid(real_uid)) == NULL)
104
115
fatal("Who are you?");
105
if (strlen(p->pw_name) >= sizeof(luser))
116
if (strlen(pw->pw_name) >= sizeof(luser))
106
117
fatal("Your name is too long");
107
strcpy(luser, p->pw_name);
118
strlcpy(luser, pw->pw_name, sizeof(luser));
110
if ((arg = *++argv)[0] == '-')
131
if (isdigit(arg[0])) {
132
if (requests >= MAXREQUESTS)
133
fatal("Too many requests");
134
requ[requests++] = atoi(arg);
136
if (users >= MAXUSERS)
137
fatal("Too many users");
120
while ((ch = getopt(argc, argv, "P:w:-")) != -1) {
129
l = strtol(optarg, &cp, 10);
130
if (*cp != '\0' || l < 0 || l >= INT_MAX)
131
errx(1, "wait time must be postive integer: %s",
133
wait_time = (u_int)l;
135
warnx("warning: wait time less than 30 seconds");
142
if (printer == NULL) {
144
if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
146
if ((p = getenv("PRINTER")) != NULL)
146
if (users < 0 && argc != 0)
149
if (isdigit(*argv[0])) {
150
if (requests >= MAXREQUESTS)
151
fatal("Too many requests");
152
requ[requests++] = atoi(argv[0]);
154
if (users >= MAXUSERS)
155
fatal("Too many users");
156
user[users++] = argv[0];
157
fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
169
extern char *__progname;
171
fprintf(stderr, "usage: %s [-] [-Pprinter] [[job #] [user] ...]\n",