2
* Copyright (c) 1998, 1999 peter memishian (meem), meem@gnu.org
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* $Id: rlprm.c,v 1.7 1999/05/04 01:45:24 meem Exp $
17
#include <sys/types.h>
28
#include "component.h"
36
static struct component *components[] =
45
const char *program_name;
46
const char *bsd_program_name = "lprm";
48
static struct rlpr_rlprm *rlpr_rlprm;
50
static const char *make_removej_request(const char *, char * const *);
53
main(int argc, char *argv[])
56
struct component *comp;
60
program_name = argv[0];
63
setlocale(LC_ALL, "");
64
bindtextdomain(PACKAGE, LOCALEDIR);
67
if ((comp = component_init(components, argc, argv)) != 0)
68
msg(R_FATAL, 0, "component `%s': init() failed!", comp->name);
70
if (argv[optind] && strcmp("-", argv[optind]) == 0) {
71
argv[optind] = rlpr_rlprm->user;
73
msg(R_WARNING, 0, "`-' option as root only removes root's"
77
/* just to tidy the code later */
78
timeout = rlpr_rlprm->timeout;
81
* make the remove job request message (which we need to make as
82
* one message because some lpd's are broken and require that they
83
* reap the message in one read(2)). then connect to the lpd,
84
* send the request and read the reply.
87
req = make_removej_request(client_get_printer(), &argv[optind]);
89
sock_fd = client_open(rlpr_rlprm->timeout);
91
msg(R_FATAL, 0, "client_open(): cannot connect to lpd");
93
if (client_command_noack(sock_fd, req, timeout, "remove job req") == 0)
94
msg(R_FATAL, 0, "unable to send `remove job' request to lpd");
97
if (copy_file(sock_fd, STDOUT_FILENO, timeout, 0, "stdout") == 0)
98
msg(R_FATAL, 0, "unable to get job removal output from lpd");
102
if ((comp = component_fini(components)) != 0)
103
msg(R_FATAL, 0, "component `%s': fini() failed!", comp->name);
109
make_removej_request(const char *printer, char * const *argv)
112
unsigned int request_size = 3; /* REMJ"\n" */
115
request_size += strlen(rlpr_rlprm->user) + 1;
116
request_size += strlen(printer);
117
for (i = 0; argv[i] != 0; i++)
118
request_size += strlen(argv[i]) + 1;
120
request = xmalloc(request_size);
121
sprintf(request, "%c%s %s", REMJ, printer, rlpr_rlprm->user);
123
for (i = 0; argv[i] != 0; i++) {
124
strcat(request, " ");
125
strcat(request, argv[i]);
128
strcat(request, "\n");
137
rlpr_rlprm = xmalloc(sizeof (struct rlpr_rlprm));
138
pwd = getpwuid(getuid());
140
if (pwd == 0 || pwd->pw_name == 0) {
141
msg(R_ERROR, errno, "unable to resolve your username");
145
rlpr_rlprm->timeout = R_TIMEOUT_DEFAULT;
146
rlpr_rlprm->user = xstrdup(pwd->pw_name);
151
rlprm_parse_args(int opt)
156
msg(R_STDOUT, 0, "usage: %s [-Hprinthost] [-Pprinter] [-Xproxy]"
157
" [OPTIONS] [job/user ...]\nplease see the manpage for"
158
" detailed help", program_name);
163
rlpr_rlprm->timeout = strtol(optarg, 0, 0);
167
msg(R_STDOUT, 0, "version "VERSION" from "__DATE__" "__TIME__
179
static struct option rlprm_opts[] = {
180
{ "help", 0, 0, -600 },
181
{ "timeout", 1, 0, -601 },
182
{ "version", 0, 0, 'V' },
186
static const char rlprm_opt_list[] = "V";
188
struct component comp_rlprm = {
189
"rlprm", rlprm_init, 0,
190
{ { rlprm_opts, rlprm_opt_list, rlprm_parse_args } }