~ubuntu-branches/ubuntu/jaunty/lpr/jaunty

« back to all changes in this revision

Viewing changes to lprm/lprm.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Majer
  • Date: 2004-07-27 16:45:19 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040727164519-fjgr6gmzlkuh53zz
Tags: 1:2003.09.23-7
Remove bash specific syntax in postinst. To make sure permissions are fixed
for the new lpr, rerun permission fixups on /var/spool/lpd/*, again.
(closes: #261590)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $OpenBSD: lprm.c,v 1.5 1997/01/17 16:12:47 millert Exp $        */
 
1
/*      $OpenBSD: lprm.c,v 1.16 2003/06/02 23:36:53 millert Exp $       */
 
2
/*      $$NetBSD: lprm.c,v 1.9 1999/08/16 03:12:32 simonb Exp $ */
2
3
 
3
4
/*
4
5
 * Copyright (c) 1983, 1993
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.
23
20
 *
35
32
 */
36
33
 
37
34
#ifndef lint
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 */
42
39
 
43
40
#ifndef lint
44
41
#if 0
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";
46
43
#else
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 $";
48
45
#endif
49
46
#endif /* not lint */
50
47
 
55
52
 *
56
53
 * Using information in the lock file, lprm will kill the
57
54
 * currently active daemon (if necessary), remove the associated files,
58
 
 * and startup a new daemon.  Priviledged users may remove anyone's spool
 
55
 * and startup a new daemon.  Privileged users may remove anyone's spool
59
56
 * entries, otherwise one can only remove their own.
60
57
 */
61
58
 
62
59
#include <sys/param.h>
63
60
 
64
 
#include <syslog.h>
 
61
#include <ctype.h>
65
62
#include <dirent.h>
 
63
#include <err.h>
 
64
#include <errno.h>
66
65
#include <pwd.h>
67
 
#include <unistd.h>
68
66
#include <stdlib.h>
69
67
#include <stdio.h>
70
68
#include <string.h>
71
 
#include <ctype.h>
 
69
#include <syslog.h>
 
70
#include <unistd.h>
 
71
#include <signal.h>
 
72
 
72
73
#include "lp.h"
73
74
#include "lp.local.h"
74
75
 
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 */
84
 
 
85
 
static char     luser[16];      /* buffer for person */
86
 
 
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 */
 
86
 
 
87
static void usage(void);
88
88
 
89
89
int
90
 
main(argc, argv)
91
 
        int argc;
92
 
        char *argv[];
 
90
main(int argc, char **argv)
93
91
{
94
 
        register char *arg;
95
 
        struct passwd *p;
96
 
 
97
 
        uid = getuid();
98
 
        euid = geteuid();
99
 
        seteuid(uid);   /* be safe */
100
 
        name = argv[0];
 
92
        struct passwd *pw;
 
93
        char *cp;
 
94
        long l;
 
95
        int ch;
 
96
 
 
97
        /*
 
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.
 
102
         */
 
103
        if ((pw = getpwnam(DEFUID)) == NULL)
 
104
                errx(1, "'lp' uid not in password file");
 
105
        effective_uid = pw->pw_uid;
 
106
        real_uid = getuid();
 
107
        effective_gid = pw->pw_gid;
 
108
        real_gid = getgid();
 
109
        setresgid(real_gid, real_gid, effective_gid);
 
110
        setresuid(real_uid, real_uid, effective_uid);
 
111
 
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));
108
119
        person = luser;
109
 
        while (--argc) {
110
 
                if ((arg = *++argv)[0] == '-')
111
 
                        switch (arg[1]) {
112
 
                        case 'P':
113
 
                                if (arg[2])
114
 
                                        printer = &arg[2];
115
 
                                else if (argc > 1) {
116
 
                                        argc--;
117
 
                                        printer = *++argv;
118
 
                                }
119
 
                                break;
120
 
                        case '\0':
121
 
                                if (!users) {
122
 
                                        users = -1;
123
 
                                        break;
124
 
                                }
125
 
                        default:
126
 
                                usage();
127
 
                        }
128
 
                else {
129
 
                        if (users < 0)
130
 
                                usage();
131
 
                        if (isdigit(arg[0])) {
132
 
                                if (requests >= MAXREQUESTS)
133
 
                                        fatal("Too many requests");
134
 
                                requ[requests++] = atoi(arg);
135
 
                        } else {
136
 
                                if (users >= MAXUSERS)
137
 
                                        fatal("Too many users");
138
 
                                user[users++] = arg;
139
 
                        }
 
120
        while ((ch = getopt(argc, argv, "P:w:-")) != -1) {
 
121
                switch (ch) {
 
122
                case '-':
 
123
                        users = -1;
 
124
                        break;
 
125
                case 'P':
 
126
                        printer = optarg;
 
127
                        break;
 
128
                case 'w':
 
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",
 
132
                                    optarg);
 
133
                        wait_time = (u_int)l;
 
134
                        if (wait_time < 30)
 
135
                                warnx("warning: wait time less than 30 seconds");
 
136
                        break;
 
137
                default:
 
138
                        usage();
140
139
                }
141
140
        }
142
 
        if (printer == NULL) {
143
 
                char *p;
 
141
        argc -= optind;
 
142
        argv += optind;
144
143
 
 
144
        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
145
145
                printer = DEFLP;
146
 
                if ((p = getenv("PRINTER")) != NULL)
147
 
                        printer = p;
 
146
        if (users < 0 && argc != 0)
 
147
                usage();
 
148
        while (argc > 0) {
 
149
                if (isdigit(*argv[0])) {
 
150
                        if (requests >= MAXREQUESTS)
 
151
                                fatal("Too many requests");
 
152
                        requ[requests++] = atoi(argv[0]);
 
153
                } else {
 
154
                        if (users >= MAXUSERS)
 
155
                                fatal("Too many users");
 
156
                        user[users++] = argv[0];
 
157
                }
 
158
                argc--;
 
159
                argv++;
148
160
        }
149
161
 
150
162
        rmjob();
151
163
        exit(0);
152
164
}
153
165
 
154
 
void
155
 
usage()
 
166
static void
 
167
usage(void)
156
168
{
157
 
        fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
 
169
        extern char *__progname;
 
170
 
 
171
        fprintf(stderr, "usage: %s [-] [-Pprinter] [[job #] [user] ...]\n",
 
172
            __progname);
158
173
        exit(2);
159
174
}