]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
2e4ff8af | 2 | * "$Id: ipp.c 7014 2007-10-10 21:57:43Z mike $" |
ef416fc2 | 3 | * |
4 | * IPP routines for the Common UNIX Printing System (CUPS) scheduler. | |
5 | * | |
91c84a35 | 6 | * Copyright 2007-2008 by Apple Inc. |
f7deaa1a | 7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
8 | * | |
9 | * This file contains Kerberos support code, copyright 2006 by | |
10 | * Jelmer Vernooij. | |
ef416fc2 | 11 | * |
12 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 13 | * property of Apple Inc. and are protected by Federal copyright |
14 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
15 | * which should have been included with this file. If this file is | |
16 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 17 | * |
18 | * Contents: | |
19 | * | |
a603edef MS |
20 | * cupsdProcessIPPRequest() - Process an incoming IPP request. |
21 | * cupsdTimeoutJob() - Timeout a job waiting on job files. | |
22 | * accept_jobs() - Accept print jobs to a printer. | |
23 | * add_class() - Add a class to the system. | |
24 | * add_file() - Add a file to a job. | |
25 | * add_job() - Add a job to a print queue. | |
26 | * add_job_state_reasons() - Add the "job-state-reasons" attribute based | |
27 | * upon the job and printer state... | |
28 | * add_job_subscriptions() - Add any subcriptions for a job. | |
29 | * add_job_uuid() - Add job-uuid attribute to a job. | |
30 | * add_printer() - Add a printer to the system. | |
31 | * add_printer_state_reasons() - Add the "printer-state-reasons" attribute | |
32 | * based upon the printer state... | |
33 | * add_queued_job_count() - Add the "queued-job-count" attribute for the | |
34 | * specified printer or class. | |
35 | * apple_init_profile() - Initialize a color profile. | |
36 | * apple_register_profiles() - Register color profiles for a printer. | |
37 | * apple_unregister_profiles() - Remove color profiles for the specified | |
38 | * printer. | |
39 | * apply_printer_defaults() - Apply printer default options to a job. | |
40 | * authenticate_job() - Set job authentication info. | |
41 | * cancel_all_jobs() - Cancel all print jobs. | |
42 | * cancel_job() - Cancel a print job. | |
43 | * cancel_subscription() - Cancel a subscription. | |
44 | * check_quotas() - Check quotas for a printer and user. | |
3dfe78b3 MS |
45 | * check_rss_recipient() - Check that we do not have a duplicate RSS |
46 | * feed URI. | |
a603edef MS |
47 | * copy_attribute() - Copy a single attribute. |
48 | * copy_attrs() - Copy attributes from one request to another. | |
49 | * copy_banner() - Copy a banner file to the requests directory | |
50 | * for the specified job. | |
51 | * copy_file() - Copy a PPD file or interface script... | |
52 | * copy_model() - Copy a PPD model file, substituting default | |
53 | * values as needed... | |
54 | * copy_job_attrs() - Copy job attributes. | |
55 | * copy_printer_attrs() - Copy printer attributes. | |
56 | * copy_subscription_attrs() - Copy subscription attributes. | |
57 | * create_job() - Print a file to a printer or class. | |
58 | * create_requested_array() - Create an array for the requested-attributes. | |
59 | * create_subscription() - Create a notification subscription. | |
60 | * delete_printer() - Remove a printer or class from the system. | |
61 | * get_default() - Get the default destination. | |
62 | * get_devices() - Get the list of available devices on the | |
63 | * local system. | |
64 | * get_document() - Get a copy of a job file. | |
65 | * get_job_attrs() - Get job attributes. | |
66 | * get_jobs() - Get a list of jobs for the specified printer. | |
67 | * get_notifications() - Get events for a subscription. | |
68 | * get_ppd() - Get a named PPD from the local system. | |
69 | * get_ppds() - Get the list of PPD files on the local | |
70 | * system. | |
71 | * get_printer_attrs() - Get printer attributes. | |
72 | * get_printers() - Get a list of printers or classes. | |
73 | * get_subscription_attrs() - Get subscription attributes. | |
74 | * get_subscriptions() - Get subscriptions. | |
75 | * get_username() - Get the username associated with a request. | |
76 | * hold_job() - Hold a print job. | |
77 | * move_job() - Move a job to a new destination. | |
78 | * ppd_parse_line() - Parse a PPD default line. | |
79 | * print_job() - Print a file to a printer or class. | |
80 | * read_ps_job_ticket() - Reads a job ticket embedded in a PS file. | |
81 | * reject_jobs() - Reject print jobs to a printer. | |
82 | * release_job() - Release a held print job. | |
83 | * renew_subscription() - Renew an existing subscription... | |
84 | * restart_job() - Restart an old print job. | |
85 | * save_auth_info() - Save authentication information for a job. | |
86 | * save_krb5_creds() - Save Kerberos credentials for the job. | |
87 | * send_document() - Send a file to a printer or class. | |
88 | * send_http_error() - Send a HTTP error back to the IPP client. | |
89 | * send_ipp_status() - Send a status back to the IPP client. | |
90 | * set_default() - Set the default destination... | |
91 | * set_job_attrs() - Set job attributes. | |
92 | * set_printer_defaults() - Set printer default options from a request. | |
93 | * start_printer() - Start a printer. | |
94 | * stop_printer() - Stop a printer. | |
95 | * url_encode_attr() - URL-encode a string attribute. | |
96 | * url_encode_string() - URL-encode a string. | |
97 | * user_allowed() - See if a user is allowed to print to a queue. | |
98 | * validate_job() - Validate printer options and destination. | |
99 | * validate_name() - Make sure the printer name only contains | |
100 | * valid chars. | |
101 | * validate_user() - Validate the user for the request. | |
ef416fc2 | 102 | */ |
103 | ||
104 | /* | |
105 | * Include necessary headers... | |
106 | */ | |
107 | ||
108 | #include "cupsd.h" | |
a603edef | 109 | #include <cups/ppd-private.h> |
ef416fc2 | 110 | |
111 | #ifdef HAVE_LIBPAPER | |
112 | # include <paper.h> | |
113 | #endif /* HAVE_LIBPAPER */ | |
114 | ||
f899b121 | 115 | #ifdef __APPLE__ |
568fa3fa MS |
116 | # include <ApplicationServices/ApplicationServices.h> |
117 | # include <CoreFoundation/CoreFoundation.h> | |
f899b121 | 118 | # ifdef HAVE_MEMBERSHIP_H |
119 | # include <membership.h> | |
120 | # endif /* HAVE_MEMBERSHIP_H */ | |
121 | # ifdef HAVE_MEMBERSHIPPRIV_H | |
122 | # include <membershipPriv.h> | |
123 | # else | |
7594b224 | 124 | extern int mbr_user_name_to_uuid(const char* name, uuid_t uu); |
125 | extern int mbr_group_name_to_uuid(const char* name, uuid_t uu); | |
126 | extern int mbr_check_membership_by_id(uuid_t user, gid_t group, int* ismember); | |
f899b121 | 127 | # endif /* HAVE_MEMBERSHIPPRIV_H */ |
128 | #endif /* __APPLE__ */ | |
7594b224 | 129 | |
ef416fc2 | 130 | |
ef416fc2 | 131 | /* |
132 | * Local functions... | |
133 | */ | |
134 | ||
135 | static void accept_jobs(cupsd_client_t *con, ipp_attribute_t *uri); | |
136 | static void add_class(cupsd_client_t *con, ipp_attribute_t *uri); | |
b423cd4c | 137 | static int add_file(cupsd_client_t *con, cupsd_job_t *job, |
138 | mime_type_t *filetype, int compression); | |
f7deaa1a | 139 | static cupsd_job_t *add_job(cupsd_client_t *con, cupsd_printer_t *printer, |
80ca4592 | 140 | mime_type_t *filetype); |
ef416fc2 | 141 | static void add_job_state_reasons(cupsd_client_t *con, cupsd_job_t *job); |
142 | static void add_job_subscriptions(cupsd_client_t *con, cupsd_job_t *job); | |
bd7854cb | 143 | static void add_job_uuid(cupsd_client_t *con, cupsd_job_t *job); |
ef416fc2 | 144 | static void add_printer(cupsd_client_t *con, ipp_attribute_t *uri); |
b423cd4c | 145 | static void add_printer_state_reasons(cupsd_client_t *con, |
146 | cupsd_printer_t *p); | |
ef416fc2 | 147 | static void add_queued_job_count(cupsd_client_t *con, cupsd_printer_t *p); |
568fa3fa | 148 | #ifdef __APPLE__ |
a603edef MS |
149 | static void apple_init_profile(ppd_file_t *ppd, cups_array_t *languages, |
150 | CMDeviceProfileInfo *profile, unsigned id, | |
151 | const char *name, const char *text, | |
152 | const char *iccfile); | |
568fa3fa MS |
153 | static void apple_register_profiles(cupsd_printer_t *p); |
154 | static void apple_unregister_profiles(cupsd_printer_t *p); | |
155 | #endif /* __APPLE__ */ | |
b423cd4c | 156 | static void apply_printer_defaults(cupsd_printer_t *printer, |
157 | cupsd_job_t *job); | |
ef416fc2 | 158 | static void authenticate_job(cupsd_client_t *con, ipp_attribute_t *uri); |
159 | static void cancel_all_jobs(cupsd_client_t *con, ipp_attribute_t *uri); | |
160 | static void cancel_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
161 | static void cancel_subscription(cupsd_client_t *con, int id); | |
3dfe78b3 | 162 | static int check_rss_recipient(const char *recipient); |
ef416fc2 | 163 | static int check_quotas(cupsd_client_t *con, cupsd_printer_t *p); |
164 | static ipp_attribute_t *copy_attribute(ipp_t *to, ipp_attribute_t *attr, | |
165 | int quickcopy); | |
fa73b229 | 166 | static void copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra, |
ef416fc2 | 167 | ipp_tag_t group, int quickcopy); |
b423cd4c | 168 | static int copy_banner(cupsd_client_t *con, cupsd_job_t *job, |
169 | const char *name); | |
ef416fc2 | 170 | static int copy_file(const char *from, const char *to); |
b423cd4c | 171 | static int copy_model(cupsd_client_t *con, const char *from, |
172 | const char *to); | |
fa73b229 | 173 | static void copy_job_attrs(cupsd_client_t *con, |
174 | cupsd_job_t *job, | |
175 | cups_array_t *ra); | |
176 | static void copy_printer_attrs(cupsd_client_t *con, | |
177 | cupsd_printer_t *printer, | |
178 | cups_array_t *ra); | |
ef416fc2 | 179 | static void copy_subscription_attrs(cupsd_client_t *con, |
180 | cupsd_subscription_t *sub, | |
181 | cups_array_t *ra); | |
182 | static void create_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
183 | static cups_array_t *create_requested_array(ipp_t *request); | |
184 | static void create_subscription(cupsd_client_t *con, ipp_attribute_t *uri); | |
185 | static void delete_printer(cupsd_client_t *con, ipp_attribute_t *uri); | |
186 | static void get_default(cupsd_client_t *con); | |
187 | static void get_devices(cupsd_client_t *con); | |
2e4ff8af | 188 | static void get_document(cupsd_client_t *con, ipp_attribute_t *uri); |
ef416fc2 | 189 | static void get_jobs(cupsd_client_t *con, ipp_attribute_t *uri); |
190 | static void get_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri); | |
bd7854cb | 191 | static void get_notifications(cupsd_client_t *con); |
b94498cf | 192 | static void get_ppd(cupsd_client_t *con, ipp_attribute_t *uri); |
ef416fc2 | 193 | static void get_ppds(cupsd_client_t *con); |
194 | static void get_printers(cupsd_client_t *con, int type); | |
195 | static void get_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri); | |
196 | static void get_subscription_attrs(cupsd_client_t *con, int sub_id); | |
197 | static void get_subscriptions(cupsd_client_t *con, ipp_attribute_t *uri); | |
e00b005a | 198 | static const char *get_username(cupsd_client_t *con); |
ef416fc2 | 199 | static void hold_job(cupsd_client_t *con, ipp_attribute_t *uri); |
200 | static void move_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
ef416fc2 | 201 | static int ppd_parse_line(const char *line, char *option, int olen, |
202 | char *choice, int clen); | |
203 | static void print_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
204 | static void read_ps_job_ticket(cupsd_client_t *con); | |
205 | static void reject_jobs(cupsd_client_t *con, ipp_attribute_t *uri); | |
206 | static void release_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
207 | static void renew_subscription(cupsd_client_t *con, int sub_id); | |
208 | static void restart_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
f7deaa1a | 209 | static void save_auth_info(cupsd_client_t *con, cupsd_job_t *job, |
210 | ipp_attribute_t *auth_info); | |
211 | #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H) | |
212 | static void save_krb5_creds(cupsd_client_t *con, cupsd_job_t *job); | |
213 | #endif /* HAVE_GSSAPI && HAVE_KRB5_H */ | |
ef416fc2 | 214 | static void send_document(cupsd_client_t *con, ipp_attribute_t *uri); |
f899b121 | 215 | static void send_http_error(cupsd_client_t *con, http_status_t status, |
216 | cupsd_printer_t *printer); | |
ef416fc2 | 217 | static void send_ipp_status(cupsd_client_t *con, ipp_status_t status, |
218 | const char *message, ...) | |
219 | # ifdef __GNUC__ | |
220 | __attribute__ ((__format__ (__printf__, 3, 4))) | |
221 | # endif /* __GNUC__ */ | |
222 | ; | |
223 | static void set_default(cupsd_client_t *con, ipp_attribute_t *uri); | |
224 | static void set_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri); | |
b423cd4c | 225 | static void set_printer_defaults(cupsd_client_t *con, |
226 | cupsd_printer_t *printer); | |
ef416fc2 | 227 | static void start_printer(cupsd_client_t *con, ipp_attribute_t *uri); |
228 | static void stop_printer(cupsd_client_t *con, ipp_attribute_t *uri); | |
89d46774 | 229 | static void url_encode_attr(ipp_attribute_t *attr, char *buffer, |
230 | int bufsize); | |
b94498cf | 231 | static char *url_encode_string(const char *s, char *buffer, int bufsize); |
ef416fc2 | 232 | static int user_allowed(cupsd_printer_t *p, const char *username); |
233 | static void validate_job(cupsd_client_t *con, ipp_attribute_t *uri); | |
234 | static int validate_name(const char *name); | |
235 | static int validate_user(cupsd_job_t *job, cupsd_client_t *con, | |
236 | const char *owner, char *username, | |
237 | int userlen); | |
238 | ||
239 | ||
240 | /* | |
09a101d6 | 241 | * 'cupsdProcessIPPRequest()' - Process an incoming IPP request. |
ef416fc2 | 242 | */ |
243 | ||
244 | int /* O - 1 on success, 0 on failure */ | |
245 | cupsdProcessIPPRequest( | |
246 | cupsd_client_t *con) /* I - Client connection */ | |
247 | { | |
248 | ipp_tag_t group; /* Current group tag */ | |
249 | ipp_attribute_t *attr; /* Current attribute */ | |
250 | ipp_attribute_t *charset; /* Character set attribute */ | |
251 | ipp_attribute_t *language; /* Language attribute */ | |
252 | ipp_attribute_t *uri; /* Printer URI attribute */ | |
253 | ipp_attribute_t *username; /* requesting-user-name attr */ | |
254 | int sub_id; /* Subscription ID */ | |
255 | ||
256 | ||
257 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
258 | "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x", | |
259 | con, con->http.fd, con->request->request.op.operation_id); | |
260 | ||
261 | /* | |
262 | * First build an empty response message for this request... | |
263 | */ | |
264 | ||
265 | con->response = ippNew(); | |
266 | ||
bc44d920 | 267 | con->response->request.status.version[0] = |
268 | con->request->request.op.version[0]; | |
269 | con->response->request.status.version[1] = | |
270 | con->request->request.op.version[1]; | |
271 | con->response->request.status.request_id = | |
272 | con->request->request.op.request_id; | |
ef416fc2 | 273 | |
274 | /* | |
275 | * Then validate the request header and required attributes... | |
276 | */ | |
f7deaa1a | 277 | |
ef416fc2 | 278 | if (con->request->request.any.version[0] != 1) |
279 | { | |
280 | /* | |
281 | * Return an error, since we only support IPP 1.x. | |
282 | */ | |
283 | ||
284 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
285 | "%04X %s Bad request version number %d.%d", | |
286 | IPP_VERSION_NOT_SUPPORTED, con->http.hostname, | |
287 | con->request->request.any.version[0], | |
288 | con->request->request.any.version[1]); | |
289 | ||
290 | send_ipp_status(con, IPP_VERSION_NOT_SUPPORTED, | |
291 | _("Bad request version number %d.%d!"), | |
292 | con->request->request.any.version[0], | |
293 | con->request->request.any.version[1]); | |
f7deaa1a | 294 | } |
fa73b229 | 295 | else if (!con->request->attrs) |
ef416fc2 | 296 | { |
297 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
298 | "%04X %s No attributes in request", | |
299 | IPP_BAD_REQUEST, con->http.hostname); | |
300 | ||
301 | send_ipp_status(con, IPP_BAD_REQUEST, _("No attributes in request!")); | |
302 | } | |
303 | else | |
304 | { | |
305 | /* | |
306 | * Make sure that the attributes are provided in the correct order and | |
307 | * don't repeat groups... | |
308 | */ | |
309 | ||
310 | for (attr = con->request->attrs, group = attr->group_tag; | |
fa73b229 | 311 | attr; |
ef416fc2 | 312 | attr = attr->next) |
313 | if (attr->group_tag < group && attr->group_tag != IPP_TAG_ZERO) | |
314 | { | |
315 | /* | |
316 | * Out of order; return an error... | |
317 | */ | |
318 | ||
319 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
320 | "%04X %s Attribute groups are out of order", | |
321 | IPP_BAD_REQUEST, con->http.hostname); | |
322 | ||
323 | send_ipp_status(con, IPP_BAD_REQUEST, | |
324 | _("Attribute groups are out of order (%x < %x)!"), | |
325 | attr->group_tag, group); | |
326 | break; | |
327 | } | |
328 | else | |
329 | group = attr->group_tag; | |
330 | ||
fa73b229 | 331 | if (!attr) |
ef416fc2 | 332 | { |
333 | /* | |
334 | * Then make sure that the first three attributes are: | |
335 | * | |
336 | * attributes-charset | |
337 | * attributes-natural-language | |
338 | * printer-uri/job-uri | |
339 | */ | |
340 | ||
341 | attr = con->request->attrs; | |
342 | if (attr && !strcmp(attr->name, "attributes-charset") && | |
fa73b229 | 343 | (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET) |
ef416fc2 | 344 | charset = attr; |
345 | else | |
346 | charset = NULL; | |
347 | ||
348 | if (attr) | |
349 | attr = attr->next; | |
350 | ||
351 | if (attr && !strcmp(attr->name, "attributes-natural-language") && | |
fa73b229 | 352 | (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE) |
ef416fc2 | 353 | language = attr; |
354 | else | |
355 | language = NULL; | |
356 | ||
fa73b229 | 357 | if ((attr = ippFindAttribute(con->request, "printer-uri", |
358 | IPP_TAG_URI)) != NULL) | |
ef416fc2 | 359 | uri = attr; |
fa73b229 | 360 | else if ((attr = ippFindAttribute(con->request, "job-uri", |
361 | IPP_TAG_URI)) != NULL) | |
ef416fc2 | 362 | uri = attr; |
b94498cf | 363 | else if (con->request->request.op.operation_id == CUPS_GET_PPD) |
364 | uri = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME); | |
ef416fc2 | 365 | else |
366 | uri = NULL; | |
367 | ||
368 | if (charset) | |
369 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET, | |
bc44d920 | 370 | "attributes-charset", NULL, |
371 | charset->values[0].string.text); | |
ef416fc2 | 372 | else |
373 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET, | |
374 | "attributes-charset", NULL, DefaultCharset); | |
375 | ||
376 | if (language) | |
377 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
378 | "attributes-natural-language", NULL, | |
379 | language->values[0].string.text); | |
380 | else | |
381 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
382 | "attributes-natural-language", NULL, DefaultLanguage); | |
383 | ||
2e4ff8af MS |
384 | if (charset && |
385 | strcasecmp(charset->values[0].string.text, "us-ascii") && | |
386 | strcasecmp(charset->values[0].string.text, "utf-8")) | |
387 | { | |
388 | /* | |
389 | * Bad character set... | |
390 | */ | |
391 | ||
392 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unsupported character set \"%s\"!", | |
393 | charset->values[0].string.text); | |
394 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
395 | "%04X %s Unsupported attributes-charset value \"%s\"", | |
396 | IPP_CHARSET, con->http.hostname, | |
397 | charset->values[0].string.text); | |
398 | send_ipp_status(con, IPP_BAD_REQUEST, | |
399 | _("Unsupported character set \"%s\"!"), | |
400 | charset->values[0].string.text); | |
401 | } | |
402 | else if (!charset || !language || | |
403 | (!uri && | |
404 | con->request->request.op.operation_id != CUPS_GET_DEFAULT && | |
405 | con->request->request.op.operation_id != CUPS_GET_PRINTERS && | |
406 | con->request->request.op.operation_id != CUPS_GET_CLASSES && | |
407 | con->request->request.op.operation_id != CUPS_GET_DEVICES && | |
408 | con->request->request.op.operation_id != CUPS_GET_PPDS)) | |
ef416fc2 | 409 | { |
410 | /* | |
411 | * Return an error, since attributes-charset, | |
412 | * attributes-natural-language, and printer-uri/job-uri are required | |
413 | * for all operations. | |
414 | */ | |
415 | ||
416 | if (!charset) | |
417 | { | |
418 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
419 | "Missing attributes-charset attribute!"); | |
420 | ||
421 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
422 | "%04X %s Missing attributes-charset attribute", | |
423 | IPP_BAD_REQUEST, con->http.hostname); | |
424 | } | |
425 | ||
426 | if (!language) | |
427 | { | |
428 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
429 | "Missing attributes-natural-language attribute!"); | |
430 | ||
431 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
432 | "%04X %s Missing attributes-natural-language attribute", | |
433 | IPP_BAD_REQUEST, con->http.hostname); | |
434 | } | |
435 | ||
436 | if (!uri) | |
437 | { | |
438 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
b94498cf | 439 | "Missing printer-uri, job-uri, or ppd-name " |
440 | "attribute!"); | |
ef416fc2 | 441 | |
442 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
b94498cf | 443 | "%04X %s Missing printer-uri, job-uri, or ppd-name " |
444 | "attribute", IPP_BAD_REQUEST, con->http.hostname); | |
ef416fc2 | 445 | } |
446 | ||
447 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Request attributes follow..."); | |
448 | ||
fa73b229 | 449 | for (attr = con->request->attrs; attr; attr = attr->next) |
f7deaa1a | 450 | cupsdLogMessage(CUPSD_LOG_DEBUG, |
ef416fc2 | 451 | "attr \"%s\": group_tag = %x, value_tag = %x", |
452 | attr->name ? attr->name : "(null)", attr->group_tag, | |
453 | attr->value_tag); | |
454 | ||
455 | cupsdLogMessage(CUPSD_LOG_DEBUG, "End of attributes..."); | |
456 | ||
457 | send_ipp_status(con, IPP_BAD_REQUEST, | |
458 | _("Missing required attributes!")); | |
459 | } | |
460 | else | |
461 | { | |
462 | /* | |
463 | * OK, all the checks pass so far; make sure requesting-user-name is | |
464 | * not "root" from a remote host... | |
465 | */ | |
466 | ||
467 | if ((username = ippFindAttribute(con->request, "requesting-user-name", | |
468 | IPP_TAG_NAME)) != NULL) | |
469 | { | |
470 | /* | |
471 | * Check for root user... | |
472 | */ | |
473 | ||
474 | if (!strcmp(username->values[0].string.text, "root") && | |
475 | strcasecmp(con->http.hostname, "localhost") && | |
476 | strcmp(con->username, "root")) | |
477 | { | |
478 | /* | |
479 | * Remote unauthenticated user masquerading as local root... | |
480 | */ | |
481 | ||
757d2cad | 482 | _cupsStrFree(username->values[0].string.text); |
483 | username->values[0].string.text = _cupsStrAlloc(RemoteRoot); | |
ef416fc2 | 484 | } |
485 | } | |
486 | ||
487 | if ((attr = ippFindAttribute(con->request, "notify-subscription-id", | |
488 | IPP_TAG_INTEGER)) != NULL) | |
489 | sub_id = attr->values[0].integer; | |
490 | else | |
491 | sub_id = 0; | |
492 | ||
493 | /* | |
494 | * Then try processing the operation... | |
495 | */ | |
496 | ||
497 | if (uri) | |
bd7854cb | 498 | cupsdLogMessage(CUPSD_LOG_DEBUG, "%s %s", |
499 | ippOpString(con->request->request.op.operation_id), | |
500 | uri->values[0].string.text); | |
501 | else | |
502 | cupsdLogMessage(CUPSD_LOG_DEBUG, "%s", | |
503 | ippOpString(con->request->request.op.operation_id)); | |
ef416fc2 | 504 | |
505 | switch (con->request->request.op.operation_id) | |
506 | { | |
507 | case IPP_PRINT_JOB : | |
508 | print_job(con, uri); | |
509 | break; | |
510 | ||
511 | case IPP_VALIDATE_JOB : | |
512 | validate_job(con, uri); | |
513 | break; | |
514 | ||
515 | case IPP_CREATE_JOB : | |
516 | create_job(con, uri); | |
517 | break; | |
518 | ||
519 | case IPP_SEND_DOCUMENT : | |
520 | send_document(con, uri); | |
521 | break; | |
522 | ||
523 | case IPP_CANCEL_JOB : | |
524 | cancel_job(con, uri); | |
525 | break; | |
526 | ||
527 | case IPP_GET_JOB_ATTRIBUTES : | |
528 | get_job_attrs(con, uri); | |
529 | break; | |
530 | ||
531 | case IPP_GET_JOBS : | |
532 | get_jobs(con, uri); | |
533 | break; | |
534 | ||
535 | case IPP_GET_PRINTER_ATTRIBUTES : | |
536 | get_printer_attrs(con, uri); | |
537 | break; | |
538 | ||
539 | case IPP_HOLD_JOB : | |
540 | hold_job(con, uri); | |
541 | break; | |
542 | ||
543 | case IPP_RELEASE_JOB : | |
544 | release_job(con, uri); | |
545 | break; | |
546 | ||
547 | case IPP_RESTART_JOB : | |
548 | restart_job(con, uri); | |
549 | break; | |
550 | ||
551 | case IPP_PAUSE_PRINTER : | |
552 | stop_printer(con, uri); | |
553 | break; | |
554 | ||
555 | case IPP_RESUME_PRINTER : | |
556 | start_printer(con, uri); | |
557 | break; | |
558 | ||
559 | case IPP_PURGE_JOBS : | |
560 | cancel_all_jobs(con, uri); | |
561 | break; | |
562 | ||
563 | case IPP_SET_JOB_ATTRIBUTES : | |
564 | set_job_attrs(con, uri); | |
565 | break; | |
566 | ||
567 | case CUPS_GET_DEFAULT : | |
568 | get_default(con); | |
569 | break; | |
570 | ||
571 | case CUPS_GET_PRINTERS : | |
572 | get_printers(con, 0); | |
573 | break; | |
574 | ||
575 | case CUPS_GET_CLASSES : | |
576 | get_printers(con, CUPS_PRINTER_CLASS); | |
577 | break; | |
578 | ||
579 | case CUPS_ADD_PRINTER : | |
580 | add_printer(con, uri); | |
581 | break; | |
582 | ||
583 | case CUPS_DELETE_PRINTER : | |
584 | delete_printer(con, uri); | |
585 | break; | |
586 | ||
587 | case CUPS_ADD_CLASS : | |
588 | add_class(con, uri); | |
589 | break; | |
590 | ||
591 | case CUPS_DELETE_CLASS : | |
592 | delete_printer(con, uri); | |
593 | break; | |
594 | ||
595 | case CUPS_ACCEPT_JOBS : | |
596 | case IPP_ENABLE_PRINTER : | |
597 | accept_jobs(con, uri); | |
598 | break; | |
599 | ||
600 | case CUPS_REJECT_JOBS : | |
601 | case IPP_DISABLE_PRINTER : | |
602 | reject_jobs(con, uri); | |
603 | break; | |
604 | ||
605 | case CUPS_SET_DEFAULT : | |
606 | set_default(con, uri); | |
607 | break; | |
608 | ||
609 | case CUPS_GET_DEVICES : | |
610 | get_devices(con); | |
611 | break; | |
612 | ||
2e4ff8af MS |
613 | case CUPS_GET_DOCUMENT : |
614 | get_document(con, uri); | |
615 | break; | |
616 | ||
b94498cf | 617 | case CUPS_GET_PPD : |
618 | get_ppd(con, uri); | |
619 | break; | |
620 | ||
ef416fc2 | 621 | case CUPS_GET_PPDS : |
622 | get_ppds(con); | |
623 | break; | |
624 | ||
625 | case CUPS_MOVE_JOB : | |
626 | move_job(con, uri); | |
627 | break; | |
628 | ||
629 | case CUPS_AUTHENTICATE_JOB : | |
630 | authenticate_job(con, uri); | |
631 | break; | |
632 | ||
633 | case IPP_CREATE_PRINTER_SUBSCRIPTION : | |
634 | case IPP_CREATE_JOB_SUBSCRIPTION : | |
635 | create_subscription(con, uri); | |
636 | break; | |
637 | ||
638 | case IPP_GET_SUBSCRIPTION_ATTRIBUTES : | |
639 | get_subscription_attrs(con, sub_id); | |
640 | break; | |
641 | ||
642 | case IPP_GET_SUBSCRIPTIONS : | |
643 | get_subscriptions(con, uri); | |
644 | break; | |
645 | ||
646 | case IPP_RENEW_SUBSCRIPTION : | |
647 | renew_subscription(con, sub_id); | |
648 | break; | |
649 | ||
650 | case IPP_CANCEL_SUBSCRIPTION : | |
651 | cancel_subscription(con, sub_id); | |
652 | break; | |
653 | ||
654 | case IPP_GET_NOTIFICATIONS : | |
bd7854cb | 655 | get_notifications(con); |
ef416fc2 | 656 | break; |
657 | ||
658 | default : | |
659 | cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, | |
660 | "%04X %s Operation %04X (%s) not supported", | |
661 | IPP_OPERATION_NOT_SUPPORTED, con->http.hostname, | |
662 | con->request->request.op.operation_id, | |
663 | ippOpString(con->request->request.op.operation_id)); | |
664 | ||
665 | send_ipp_status(con, IPP_OPERATION_NOT_SUPPORTED, | |
666 | _("%s not supported!"), | |
bc44d920 | 667 | ippOpString( |
668 | con->request->request.op.operation_id)); | |
ef416fc2 | 669 | break; |
670 | } | |
671 | } | |
672 | } | |
673 | } | |
674 | ||
675 | if (con->response) | |
676 | { | |
677 | /* | |
678 | * Sending data from the scheduler... | |
679 | */ | |
680 | ||
681 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
682 | "cupsdProcessIPPRequest: %d status_code=%x (%s)", | |
683 | con->http.fd, con->response->request.status.status_code, | |
684 | ippErrorString(con->response->request.status.status_code)); | |
685 | ||
5bd77a73 | 686 | if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE)) |
ef416fc2 | 687 | { |
f301802f | 688 | #ifdef CUPSD_USE_CHUNKING |
689 | /* | |
690 | * Because older versions of CUPS (1.1.17 and older) and some IPP | |
d09495fa | 691 | * clients do not implement chunking properly, we cannot use |
f301802f | 692 | * chunking by default. This may become the default in future |
693 | * CUPS releases, or we might add a configuration directive for | |
694 | * it. | |
695 | */ | |
696 | ||
ef416fc2 | 697 | if (con->http.version == HTTP_1_1) |
698 | { | |
07725fee | 699 | if (httpPrintf(HTTP(con), "Transfer-Encoding: chunked\r\n\r\n") < 0) |
700 | return (0); | |
701 | ||
702 | if (cupsdFlushHeader(con) < 0) | |
703 | return (0); | |
d09495fa | 704 | |
705 | con->http.data_encoding = HTTP_ENCODE_CHUNKED; | |
ef416fc2 | 706 | } |
707 | else | |
f301802f | 708 | #endif /* CUPSD_USE_CHUNKING */ |
ef416fc2 | 709 | { |
d09495fa | 710 | size_t length; /* Length of response */ |
ef416fc2 | 711 | |
d09495fa | 712 | |
713 | length = ippLength(con->response); | |
ef416fc2 | 714 | |
b94498cf | 715 | if (con->file >= 0 && !con->pipe_pid) |
716 | { | |
717 | struct stat fileinfo; /* File information */ | |
718 | ||
719 | ||
720 | if (!fstat(con->file, &fileinfo)) | |
721 | length += fileinfo.st_size; | |
722 | } | |
723 | ||
07725fee | 724 | if (httpPrintf(HTTP(con), "Content-Length: " CUPS_LLFMT "\r\n\r\n", |
725 | CUPS_LLCAST length) < 0) | |
726 | return (0); | |
727 | ||
728 | if (cupsdFlushHeader(con) < 0) | |
729 | return (0); | |
d09495fa | 730 | |
731 | con->http.data_encoding = HTTP_ENCODE_LENGTH; | |
732 | con->http.data_remaining = length; | |
b94498cf | 733 | |
734 | if (con->http.data_remaining <= INT_MAX) | |
735 | con->http._data_remaining = con->http.data_remaining; | |
736 | else | |
737 | con->http._data_remaining = INT_MAX; | |
ef416fc2 | 738 | } |
739 | ||
f7deaa1a | 740 | cupsdAddSelect(con->http.fd, (cupsd_selfunc_t)cupsdReadClient, |
741 | (cupsd_selfunc_t)cupsdWriteClient, con); | |
ef416fc2 | 742 | |
743 | /* | |
744 | * Tell the caller the response header was sent successfully... | |
745 | */ | |
746 | ||
747 | return (1); | |
748 | } | |
749 | else | |
750 | { | |
751 | /* | |
752 | * Tell the caller the response header could not be sent... | |
753 | */ | |
754 | ||
755 | return (0); | |
756 | } | |
757 | } | |
758 | else | |
759 | { | |
760 | /* | |
761 | * Sending data from a subprocess like cups-deviced; tell the caller | |
762 | * everything is A-OK so far... | |
763 | */ | |
764 | ||
765 | return (1); | |
766 | } | |
767 | } | |
768 | ||
769 | ||
09a101d6 | 770 | /* |
771 | * 'cupsdTimeoutJob()' - Timeout a job waiting on job files. | |
772 | */ | |
773 | ||
91c84a35 | 774 | int /* O - 0 on success, -1 on error */ |
09a101d6 | 775 | cupsdTimeoutJob(cupsd_job_t *job) /* I - Job to timeout */ |
776 | { | |
777 | cupsd_printer_t *printer; /* Destination printer or class */ | |
778 | ipp_attribute_t *attr; /* job-sheets attribute */ | |
779 | int kbytes; /* Kilobytes in banner */ | |
780 | ||
781 | ||
782 | job->pending_timeout = 0; | |
783 | ||
784 | /* | |
785 | * See if we need to add the ending sheet... | |
786 | */ | |
787 | ||
788 | printer = cupsdFindDest(job->dest); | |
789 | attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME); | |
790 | ||
791 | if (printer && | |
792 | !(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) && | |
793 | attr && attr->num_values > 1) | |
794 | { | |
795 | /* | |
796 | * Yes... | |
797 | */ | |
798 | ||
799 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Adding end banner page \"%s\".", | |
800 | job->id, attr->values[1].string.text); | |
801 | ||
91c84a35 MS |
802 | if ((kbytes = copy_banner(NULL, job, attr->values[1].string.text)) < 0) |
803 | return (-1); | |
09a101d6 | 804 | |
805 | cupsdUpdateQuota(printer, job->username, 0, kbytes); | |
806 | } | |
91c84a35 MS |
807 | |
808 | return (0); | |
09a101d6 | 809 | } |
810 | ||
811 | ||
ef416fc2 | 812 | /* |
813 | * 'accept_jobs()' - Accept print jobs to a printer. | |
814 | */ | |
815 | ||
816 | static void | |
817 | accept_jobs(cupsd_client_t *con, /* I - Client connection */ | |
818 | ipp_attribute_t *uri) /* I - Printer or class URI */ | |
819 | { | |
820 | http_status_t status; /* Policy status */ | |
bc44d920 | 821 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 822 | cupsd_printer_t *printer; /* Printer data */ |
823 | ||
824 | ||
825 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "accept_jobs(%p[%d], %s)", con, | |
826 | con->http.fd, uri->values[0].string.text); | |
827 | ||
828 | /* | |
829 | * Is the destination valid? | |
830 | */ | |
831 | ||
f7deaa1a | 832 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 833 | { |
834 | /* | |
835 | * Bad URI... | |
836 | */ | |
837 | ||
838 | send_ipp_status(con, IPP_NOT_FOUND, | |
839 | _("The printer or class was not found.")); | |
840 | return; | |
841 | } | |
842 | ||
843 | /* | |
844 | * Check policy... | |
845 | */ | |
846 | ||
847 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) | |
848 | { | |
f899b121 | 849 | send_http_error(con, status, printer); |
ef416fc2 | 850 | return; |
851 | } | |
852 | ||
853 | /* | |
854 | * Accept jobs sent to the printer... | |
855 | */ | |
856 | ||
857 | printer->accepting = 1; | |
858 | printer->state_message[0] = '\0'; | |
859 | ||
860 | cupsdAddPrinterHistory(printer); | |
861 | ||
862 | if (dtype & CUPS_PRINTER_CLASS) | |
f7deaa1a | 863 | { |
3dfe78b3 | 864 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
f7deaa1a | 865 | |
866 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" now accepting jobs (\"%s\").", | |
867 | printer->name, get_username(con)); | |
868 | } | |
ef416fc2 | 869 | else |
f7deaa1a | 870 | { |
3dfe78b3 | 871 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
ef416fc2 | 872 | |
bc44d920 | 873 | cupsdLogMessage(CUPSD_LOG_INFO, |
874 | "Printer \"%s\" now accepting jobs (\"%s\").", | |
f7deaa1a | 875 | printer->name, get_username(con)); |
876 | } | |
ef416fc2 | 877 | |
878 | /* | |
879 | * Everything was ok, so return OK status... | |
880 | */ | |
881 | ||
882 | con->response->request.status.status_code = IPP_OK; | |
883 | } | |
884 | ||
885 | ||
886 | /* | |
887 | * 'add_class()' - Add a class to the system. | |
888 | */ | |
889 | ||
890 | static void | |
891 | add_class(cupsd_client_t *con, /* I - Client connection */ | |
892 | ipp_attribute_t *uri) /* I - URI of class */ | |
893 | { | |
894 | http_status_t status; /* Policy status */ | |
895 | int i; /* Looping var */ | |
896 | char method[HTTP_MAX_URI], /* Method portion of URI */ | |
897 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
898 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
899 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
900 | int port; /* Port portion of URI */ | |
901 | cupsd_printer_t *pclass, /* Class */ | |
902 | *member; /* Member printer/class */ | |
903 | cups_ptype_t dtype; /* Destination type */ | |
ef416fc2 | 904 | ipp_attribute_t *attr; /* Printer attribute */ |
905 | int modify; /* Non-zero if we just modified */ | |
b423cd4c | 906 | char newname[IPP_MAX_NAME]; /* New class name */ |
e00b005a | 907 | int need_restart_job; /* Need to restart job? */ |
ef416fc2 | 908 | |
909 | ||
910 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_class(%p[%d], %s)", con, | |
911 | con->http.fd, uri->values[0].string.text); | |
912 | ||
913 | /* | |
914 | * Do we have a valid URI? | |
915 | */ | |
916 | ||
a4d04587 | 917 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
918 | sizeof(method), username, sizeof(username), host, | |
919 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 920 | |
921 | ||
fa73b229 | 922 | if (strncmp(resource, "/classes/", 9) || strlen(resource) == 9) |
ef416fc2 | 923 | { |
924 | /* | |
925 | * No, return an error... | |
926 | */ | |
927 | ||
928 | send_ipp_status(con, IPP_BAD_REQUEST, | |
929 | _("The printer-uri must be of the form " | |
930 | "\"ipp://HOSTNAME/classes/CLASSNAME\".")); | |
931 | return; | |
932 | } | |
933 | ||
934 | /* | |
935 | * Do we have a valid printer name? | |
936 | */ | |
937 | ||
938 | if (!validate_name(resource + 9)) | |
939 | { | |
940 | /* | |
941 | * No, return an error... | |
942 | */ | |
943 | ||
944 | send_ipp_status(con, IPP_BAD_REQUEST, | |
945 | _("The printer-uri \"%s\" contains invalid characters."), | |
946 | uri->values[0].string.text); | |
947 | return; | |
948 | } | |
949 | ||
ef416fc2 | 950 | /* |
951 | * See if the class already exists; if not, create a new class... | |
952 | */ | |
953 | ||
954 | if ((pclass = cupsdFindClass(resource + 9)) == NULL) | |
955 | { | |
956 | /* | |
957 | * Class doesn't exist; see if we have a printer of the same name... | |
958 | */ | |
959 | ||
960 | if ((pclass = cupsdFindPrinter(resource + 9)) != NULL && | |
bc44d920 | 961 | !(pclass->type & CUPS_PRINTER_DISCOVERED)) |
ef416fc2 | 962 | { |
963 | /* | |
964 | * Yes, return an error... | |
965 | */ | |
966 | ||
967 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
968 | _("A printer named \"%s\" already exists!"), | |
969 | resource + 9); | |
970 | return; | |
971 | } | |
972 | ||
973 | /* | |
2e4ff8af | 974 | * No, check the default policy and then add the class... |
ef416fc2 | 975 | */ |
976 | ||
2e4ff8af MS |
977 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
978 | { | |
979 | send_http_error(con, status, NULL); | |
980 | return; | |
981 | } | |
982 | ||
ef416fc2 | 983 | pclass = cupsdAddClass(resource + 9); |
984 | modify = 0; | |
985 | } | |
986 | else if (pclass->type & CUPS_PRINTER_IMPLICIT) | |
987 | { | |
988 | /* | |
2fb76298 | 989 | * Check the default policy, then rename the implicit class to "AnyClass" |
2e4ff8af | 990 | * or remove it... |
ef416fc2 | 991 | */ |
992 | ||
2e4ff8af MS |
993 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
994 | { | |
995 | send_http_error(con, status, NULL); | |
996 | return; | |
997 | } | |
998 | ||
ef416fc2 | 999 | if (ImplicitAnyClasses) |
1000 | { | |
b423cd4c | 1001 | snprintf(newname, sizeof(newname), "Any%s", resource + 9); |
1002 | cupsdRenamePrinter(pclass, newname); | |
ef416fc2 | 1003 | } |
1004 | else | |
1005 | cupsdDeletePrinter(pclass, 1); | |
1006 | ||
1007 | /* | |
1008 | * Add the class as a new local class... | |
1009 | */ | |
1010 | ||
1011 | pclass = cupsdAddClass(resource + 9); | |
1012 | modify = 0; | |
1013 | } | |
bc44d920 | 1014 | else if (pclass->type & CUPS_PRINTER_DISCOVERED) |
ef416fc2 | 1015 | { |
1016 | /* | |
2e4ff8af | 1017 | * Check the default policy, then rename the remote class to "Class"... |
ef416fc2 | 1018 | */ |
1019 | ||
2e4ff8af MS |
1020 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
1021 | { | |
1022 | send_http_error(con, status, NULL); | |
1023 | return; | |
1024 | } | |
1025 | ||
b423cd4c | 1026 | snprintf(newname, sizeof(newname), "%s@%s", resource + 9, pclass->hostname); |
1027 | cupsdRenamePrinter(pclass, newname); | |
ef416fc2 | 1028 | |
1029 | /* | |
1030 | * Add the class as a new local class... | |
1031 | */ | |
1032 | ||
1033 | pclass = cupsdAddClass(resource + 9); | |
1034 | modify = 0; | |
1035 | } | |
2e4ff8af MS |
1036 | else if ((status = cupsdCheckPolicy(pclass->op_policy_ptr, con, |
1037 | NULL)) != HTTP_OK) | |
1038 | { | |
2fb76298 | 1039 | send_http_error(con, status, pclass); |
2e4ff8af MS |
1040 | return; |
1041 | } | |
ef416fc2 | 1042 | else |
1043 | modify = 1; | |
1044 | ||
1045 | /* | |
1046 | * Look for attributes and copy them over as needed... | |
1047 | */ | |
1048 | ||
e00b005a | 1049 | need_restart_job = 0; |
1050 | ||
fa73b229 | 1051 | if ((attr = ippFindAttribute(con->request, "printer-location", |
1052 | IPP_TAG_TEXT)) != NULL) | |
ef416fc2 | 1053 | cupsdSetString(&pclass->location, attr->values[0].string.text); |
1054 | ||
fa73b229 | 1055 | if ((attr = ippFindAttribute(con->request, "printer-info", |
1056 | IPP_TAG_TEXT)) != NULL) | |
ef416fc2 | 1057 | cupsdSetString(&pclass->info, attr->values[0].string.text); |
1058 | ||
fa73b229 | 1059 | if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", |
1060 | IPP_TAG_BOOLEAN)) != NULL) | |
ef416fc2 | 1061 | { |
bc44d920 | 1062 | cupsdLogMessage(CUPSD_LOG_INFO, |
1063 | "Setting %s printer-is-accepting-jobs to %d (was %d.)", | |
1064 | pclass->name, attr->values[0].boolean, pclass->accepting); | |
ef416fc2 | 1065 | |
1066 | pclass->accepting = attr->values[0].boolean; | |
1067 | cupsdAddPrinterHistory(pclass); | |
1068 | } | |
1069 | ||
fa73b229 | 1070 | if ((attr = ippFindAttribute(con->request, "printer-is-shared", |
1071 | IPP_TAG_BOOLEAN)) != NULL) | |
ef416fc2 | 1072 | { |
1073 | if (pclass->shared && !attr->values[0].boolean) | |
f7deaa1a | 1074 | cupsdDeregisterPrinter(pclass, 1); |
ef416fc2 | 1075 | |
1076 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1077 | "Setting %s printer-is-shared to %d (was %d.)", | |
1078 | pclass->name, attr->values[0].boolean, pclass->shared); | |
1079 | ||
1080 | pclass->shared = attr->values[0].boolean; | |
1081 | } | |
1082 | ||
fa73b229 | 1083 | if ((attr = ippFindAttribute(con->request, "printer-state", |
1084 | IPP_TAG_ENUM)) != NULL) | |
ef416fc2 | 1085 | { |
1086 | if (attr->values[0].integer != IPP_PRINTER_IDLE && | |
1087 | attr->values[0].integer != IPP_PRINTER_STOPPED) | |
1088 | { | |
1089 | send_ipp_status(con, IPP_BAD_REQUEST, | |
1090 | _("Attempt to set %s printer-state to bad value %d!"), | |
1091 | pclass->name, attr->values[0].integer); | |
1092 | return; | |
1093 | } | |
1094 | ||
bc44d920 | 1095 | cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", |
1096 | pclass->name, attr->values[0].integer, pclass->state); | |
ef416fc2 | 1097 | |
1098 | if (attr->values[0].integer == IPP_PRINTER_STOPPED) | |
1099 | cupsdStopPrinter(pclass, 0); | |
1100 | else | |
e00b005a | 1101 | { |
ef416fc2 | 1102 | cupsdSetPrinterState(pclass, (ipp_pstate_t)(attr->values[0].integer), 0); |
e00b005a | 1103 | need_restart_job = 1; |
1104 | } | |
ef416fc2 | 1105 | } |
fa73b229 | 1106 | if ((attr = ippFindAttribute(con->request, "printer-state-message", |
1107 | IPP_TAG_TEXT)) != NULL) | |
ef416fc2 | 1108 | { |
1109 | strlcpy(pclass->state_message, attr->values[0].string.text, | |
1110 | sizeof(pclass->state_message)); | |
1111 | cupsdAddPrinterHistory(pclass); | |
1112 | } | |
fa73b229 | 1113 | if ((attr = ippFindAttribute(con->request, "member-uris", |
1114 | IPP_TAG_URI)) != NULL) | |
ef416fc2 | 1115 | { |
1116 | /* | |
1117 | * Clear the printer array as needed... | |
1118 | */ | |
1119 | ||
e00b005a | 1120 | need_restart_job = 1; |
1121 | ||
ef416fc2 | 1122 | if (pclass->num_printers > 0) |
1123 | { | |
1124 | free(pclass->printers); | |
1125 | pclass->num_printers = 0; | |
1126 | } | |
1127 | ||
1128 | /* | |
1129 | * Add each printer or class that is listed... | |
1130 | */ | |
1131 | ||
1132 | for (i = 0; i < attr->num_values; i ++) | |
1133 | { | |
1134 | /* | |
1135 | * Search for the printer or class URI... | |
1136 | */ | |
1137 | ||
f7deaa1a | 1138 | if (!cupsdValidateDest(attr->values[i].string.text, &dtype, &member)) |
ef416fc2 | 1139 | { |
1140 | /* | |
1141 | * Bad URI... | |
1142 | */ | |
1143 | ||
1144 | send_ipp_status(con, IPP_NOT_FOUND, | |
1145 | _("The printer or class was not found.")); | |
1146 | return; | |
1147 | } | |
1148 | ||
1149 | /* | |
1150 | * Add it to the class... | |
1151 | */ | |
1152 | ||
1153 | cupsdAddPrinterToClass(pclass, member); | |
1154 | } | |
1155 | } | |
1156 | ||
b423cd4c | 1157 | set_printer_defaults(con, pclass); |
1158 | ||
09a101d6 | 1159 | if ((attr = ippFindAttribute(con->request, "auth-info-required", |
1160 | IPP_TAG_KEYWORD)) != NULL) | |
1161 | cupsdSetAuthInfoRequired(pclass, NULL, attr); | |
1162 | ||
ef416fc2 | 1163 | /* |
1164 | * Update the printer class attributes and return... | |
1165 | */ | |
1166 | ||
1167 | cupsdSetPrinterAttrs(pclass); | |
3dfe78b3 | 1168 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
e00b005a | 1169 | |
1170 | if (need_restart_job && pclass->job) | |
1171 | { | |
1172 | cupsd_job_t *job; | |
1173 | ||
1174 | /* | |
1175 | * Stop the current job and then restart it below... | |
1176 | */ | |
1177 | ||
1178 | job = (cupsd_job_t *)pclass->job; | |
1179 | ||
1180 | cupsdStopJob(job, 1); | |
bd7854cb | 1181 | |
e00b005a | 1182 | job->state->values[0].integer = IPP_JOB_PENDING; |
bd7854cb | 1183 | job->state_value = IPP_JOB_PENDING; |
e00b005a | 1184 | } |
1185 | ||
1186 | if (need_restart_job) | |
1187 | cupsdCheckJobs(); | |
ef416fc2 | 1188 | |
3dfe78b3 | 1189 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
ef416fc2 | 1190 | |
1191 | if (modify) | |
1192 | { | |
1193 | cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, pclass, NULL, | |
1194 | "Class \"%s\" modified by \"%s\".", pclass->name, | |
e00b005a | 1195 | get_username(con)); |
ef416fc2 | 1196 | |
1197 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" modified by \"%s\".", | |
e00b005a | 1198 | pclass->name, get_username(con)); |
ef416fc2 | 1199 | } |
1200 | else | |
1201 | { | |
1202 | cupsdAddPrinterHistory(pclass); | |
1203 | ||
1204 | cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, pclass, NULL, | |
1205 | "New class \"%s\" added by \"%s\".", pclass->name, | |
e00b005a | 1206 | get_username(con)); |
ef416fc2 | 1207 | |
1208 | cupsdLogMessage(CUPSD_LOG_INFO, "New class \"%s\" added by \"%s\".", | |
e00b005a | 1209 | pclass->name, get_username(con)); |
ef416fc2 | 1210 | } |
1211 | ||
1212 | con->response->request.status.status_code = IPP_OK; | |
1213 | } | |
1214 | ||
1215 | ||
1216 | /* | |
1217 | * 'add_file()' - Add a file to a job. | |
1218 | */ | |
1219 | ||
1220 | static int /* O - 0 on success, -1 on error */ | |
1221 | add_file(cupsd_client_t *con, /* I - Connection to client */ | |
1222 | cupsd_job_t *job, /* I - Job to add to */ | |
1223 | mime_type_t *filetype, /* I - Type of file */ | |
1224 | int compression) /* I - Compression */ | |
1225 | { | |
1226 | mime_type_t **filetypes; /* New filetypes array... */ | |
1227 | int *compressions; /* New compressions array... */ | |
1228 | ||
1229 | ||
1230 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
bc44d920 | 1231 | "add_file(con=%p[%d], job=%d, filetype=%s/%s, " |
1232 | "compression=%d)", con, con ? con->http.fd : -1, job->id, | |
1233 | filetype->super, filetype->type, compression); | |
ef416fc2 | 1234 | |
1235 | /* | |
1236 | * Add the file to the job... | |
1237 | */ | |
1238 | ||
1239 | if (job->num_files == 0) | |
1240 | { | |
1241 | compressions = (int *)malloc(sizeof(int)); | |
1242 | filetypes = (mime_type_t **)malloc(sizeof(mime_type_t *)); | |
1243 | } | |
1244 | else | |
1245 | { | |
1246 | compressions = (int *)realloc(job->compressions, | |
1247 | (job->num_files + 1) * sizeof(int)); | |
1248 | filetypes = (mime_type_t **)realloc(job->filetypes, | |
1249 | (job->num_files + 1) * | |
1250 | sizeof(mime_type_t *)); | |
1251 | } | |
1252 | ||
fa73b229 | 1253 | if (!compressions || !filetypes) |
ef416fc2 | 1254 | { |
07725fee | 1255 | cupsdCancelJob(job, 1, IPP_JOB_ABORTED); |
ef416fc2 | 1256 | |
09a101d6 | 1257 | if (con) |
1258 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
1259 | _("Unable to allocate memory for file types!")); | |
1260 | ||
ef416fc2 | 1261 | return (-1); |
1262 | } | |
1263 | ||
1264 | job->compressions = compressions; | |
1265 | job->compressions[job->num_files] = compression; | |
1266 | job->filetypes = filetypes; | |
1267 | job->filetypes[job->num_files] = filetype; | |
1268 | ||
1269 | job->num_files ++; | |
1270 | ||
3dfe78b3 MS |
1271 | job->dirty = 1; |
1272 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); | |
1273 | ||
ef416fc2 | 1274 | return (0); |
1275 | } | |
1276 | ||
1277 | ||
1278 | /* | |
b423cd4c | 1279 | * 'add_job()' - Add a job to a print queue. |
ef416fc2 | 1280 | */ |
1281 | ||
b423cd4c | 1282 | static cupsd_job_t * /* O - Job object */ |
1283 | add_job(cupsd_client_t *con, /* I - Client connection */ | |
f7deaa1a | 1284 | cupsd_printer_t *printer, /* I - Destination printer */ |
80ca4592 | 1285 | mime_type_t *filetype) /* I - First print file type, if any */ |
ef416fc2 | 1286 | { |
b423cd4c | 1287 | http_status_t status; /* Policy status */ |
f7deaa1a | 1288 | ipp_attribute_t *attr, /* Current attribute */ |
1289 | *auth_info; /* auth-info attribute */ | |
b423cd4c | 1290 | const char *val; /* Default option value */ |
1291 | int priority; /* Job priority */ | |
1292 | char *title; /* Job name/title */ | |
1293 | cupsd_job_t *job; /* Current job */ | |
f7deaa1a | 1294 | char job_uri[HTTP_MAX_URI]; /* Job URI */ |
b423cd4c | 1295 | int kbytes; /* Size of print file */ |
1296 | int i; /* Looping var */ | |
1297 | int lowerpagerange; /* Page range bound */ | |
ef416fc2 | 1298 | |
1299 | ||
f7deaa1a | 1300 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))", |
1301 | con, con->http.fd, printer, printer->name, | |
0a682745 MS |
1302 | filetype, filetype ? filetype->super : "none", |
1303 | filetype ? filetype->type : "none"); | |
ef416fc2 | 1304 | |
b423cd4c | 1305 | /* |
1306 | * Check remote printing to non-shared printer... | |
1307 | */ | |
ef416fc2 | 1308 | |
b423cd4c | 1309 | if (!printer->shared && |
1310 | strcasecmp(con->http.hostname, "localhost") && | |
1311 | strcasecmp(con->http.hostname, ServerName)) | |
1312 | { | |
1313 | send_ipp_status(con, IPP_NOT_AUTHORIZED, | |
1314 | _("The printer or class is not shared!")); | |
1315 | return (NULL); | |
1316 | } | |
ef416fc2 | 1317 | |
b423cd4c | 1318 | /* |
1319 | * Check policy... | |
1320 | */ | |
ef416fc2 | 1321 | |
f899b121 | 1322 | auth_info = ippFindAttribute(con->request, "auth-info", IPP_TAG_TEXT); |
7594b224 | 1323 | |
b423cd4c | 1324 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) |
1325 | { | |
f899b121 | 1326 | send_http_error(con, status, printer); |
b423cd4c | 1327 | return (NULL); |
1328 | } | |
3dfe78b3 MS |
1329 | else if (printer->num_auth_info_required > 0 && |
1330 | strcmp(printer->auth_info_required[0], "none") && | |
7594b224 | 1331 | !con->username[0] && !auth_info) |
b423cd4c | 1332 | { |
f899b121 | 1333 | send_http_error(con, HTTP_UNAUTHORIZED, printer); |
b423cd4c | 1334 | return (NULL); |
1335 | } | |
7594b224 | 1336 | #ifdef HAVE_SSL |
1337 | else if (auth_info && !con->http.tls && | |
1338 | !httpAddrLocalhost(con->http.hostaddr)) | |
1339 | { | |
1340 | /* | |
1341 | * Require encryption of auth-info over non-local connections... | |
1342 | */ | |
1343 | ||
f899b121 | 1344 | send_http_error(con, HTTP_UPGRADE_REQUIRED, printer); |
7594b224 | 1345 | return (NULL); |
1346 | } | |
1347 | #endif /* HAVE_SSL */ | |
ef416fc2 | 1348 | |
b423cd4c | 1349 | /* |
1350 | * See if the printer is accepting jobs... | |
1351 | */ | |
1352 | ||
1353 | if (!printer->accepting) | |
1354 | { | |
1355 | send_ipp_status(con, IPP_NOT_ACCEPTING, | |
1356 | _("Destination \"%s\" is not accepting jobs."), | |
f7deaa1a | 1357 | printer->name); |
b423cd4c | 1358 | return (NULL); |
ef416fc2 | 1359 | } |
ef416fc2 | 1360 | |
b423cd4c | 1361 | /* |
80ca4592 | 1362 | * Validate job template attributes; for now just document-format, |
f7deaa1a | 1363 | * copies, number-up, and page-ranges... |
b423cd4c | 1364 | */ |
ef416fc2 | 1365 | |
80ca4592 | 1366 | if (filetype && printer->filetypes && |
1367 | !cupsArrayFind(printer->filetypes, filetype)) | |
1368 | { | |
1369 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; | |
1370 | /* MIME media type string */ | |
1371 | ||
1372 | ||
1373 | snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, | |
1374 | filetype->type); | |
1375 | ||
1376 | send_ipp_status(con, IPP_DOCUMENT_FORMAT, | |
1377 | _("Unsupported format \'%s\'!"), mimetype); | |
1378 | ||
1379 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE, | |
1380 | "document-format", NULL, mimetype); | |
1381 | ||
1382 | return (NULL); | |
1383 | } | |
1384 | ||
b423cd4c | 1385 | if ((attr = ippFindAttribute(con->request, "copies", |
1386 | IPP_TAG_INTEGER)) != NULL) | |
1387 | { | |
1388 | if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies) | |
1389 | { | |
1390 | send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."), | |
1391 | attr->values[0].integer); | |
1392 | ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER, | |
1393 | "copies", attr->values[0].integer); | |
1394 | return (NULL); | |
1395 | } | |
1396 | } | |
ef416fc2 | 1397 | |
3dfe78b3 MS |
1398 | if ((attr = ippFindAttribute(con->request, "job-sheets", |
1399 | IPP_TAG_ZERO)) != NULL) | |
1400 | { | |
1401 | if (attr->value_tag != IPP_TAG_KEYWORD && | |
1402 | attr->value_tag != IPP_TAG_NAME) | |
1403 | { | |
1404 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value type!")); | |
1405 | return (NULL); | |
1406 | } | |
1407 | ||
1408 | if (attr->num_values > 2) | |
1409 | { | |
1410 | send_ipp_status(con, IPP_BAD_REQUEST, | |
1411 | _("Too many job-sheets values (%d > 2)!"), | |
1412 | attr->num_values); | |
1413 | return (NULL); | |
1414 | } | |
1415 | ||
1416 | for (i = 0; i < attr->num_values; i ++) | |
1417 | if (strcmp(attr->values[i].string.text, "none") && | |
1418 | !cupsdFindBanner(attr->values[i].string.text)) | |
1419 | { | |
1420 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-sheets value \"%s\"!"), | |
1421 | attr->values[i].string.text); | |
1422 | return (NULL); | |
1423 | } | |
1424 | } | |
1425 | ||
f7deaa1a | 1426 | if ((attr = ippFindAttribute(con->request, "number-up", |
1427 | IPP_TAG_INTEGER)) != NULL) | |
1428 | { | |
1429 | if (attr->values[0].integer != 1 && | |
1430 | attr->values[0].integer != 2 && | |
1431 | attr->values[0].integer != 4 && | |
1432 | attr->values[0].integer != 6 && | |
1433 | attr->values[0].integer != 9 && | |
1434 | attr->values[0].integer != 16) | |
1435 | { | |
1436 | send_ipp_status(con, IPP_ATTRIBUTES, _("Bad number-up value %d."), | |
1437 | attr->values[0].integer); | |
1438 | ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER, | |
1439 | "number-up", attr->values[0].integer); | |
1440 | return (NULL); | |
1441 | } | |
1442 | } | |
1443 | ||
b423cd4c | 1444 | if ((attr = ippFindAttribute(con->request, "page-ranges", |
1445 | IPP_TAG_RANGE)) != NULL) | |
1446 | { | |
1447 | for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++) | |
1448 | { | |
f7deaa1a | 1449 | if (attr->values[i].range.lower < lowerpagerange || |
b423cd4c | 1450 | attr->values[i].range.lower > attr->values[i].range.upper) |
1451 | { | |
1452 | send_ipp_status(con, IPP_BAD_REQUEST, | |
1453 | _("Bad page-ranges values %d-%d."), | |
1454 | attr->values[i].range.lower, | |
1455 | attr->values[i].range.upper); | |
1456 | return (NULL); | |
1457 | } | |
ef416fc2 | 1458 | |
b423cd4c | 1459 | lowerpagerange = attr->values[i].range.upper + 1; |
1460 | } | |
1461 | } | |
ef416fc2 | 1462 | |
1463 | /* | |
b423cd4c | 1464 | * Make sure we aren't over our limit... |
ef416fc2 | 1465 | */ |
1466 | ||
b423cd4c | 1467 | if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs) |
1468 | cupsdCleanJobs(); | |
ef416fc2 | 1469 | |
f7deaa1a | 1470 | if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs) |
b423cd4c | 1471 | { |
1472 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
1473 | _("Too many active jobs.")); | |
1474 | return (NULL); | |
1475 | } | |
1476 | ||
bc44d920 | 1477 | if ((i = check_quotas(con, printer)) < 0) |
b423cd4c | 1478 | { |
1479 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached.")); | |
1480 | return (NULL); | |
1481 | } | |
bc44d920 | 1482 | else if (i == 0) |
1483 | { | |
1484 | send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Not allowed to print.")); | |
1485 | return (NULL); | |
1486 | } | |
ef416fc2 | 1487 | |
1488 | /* | |
b423cd4c | 1489 | * Create the job and set things up... |
ef416fc2 | 1490 | */ |
1491 | ||
b423cd4c | 1492 | if ((attr = ippFindAttribute(con->request, "job-priority", |
1493 | IPP_TAG_INTEGER)) != NULL) | |
1494 | priority = attr->values[0].integer; | |
1495 | else | |
ef416fc2 | 1496 | { |
b423cd4c | 1497 | if ((val = cupsGetOption("job-priority", printer->num_options, |
1498 | printer->options)) != NULL) | |
1499 | priority = atoi(val); | |
1500 | else | |
1501 | priority = 50; | |
ef416fc2 | 1502 | |
b423cd4c | 1503 | ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority", |
1504 | priority); | |
1505 | } | |
ef416fc2 | 1506 | |
b423cd4c | 1507 | if ((attr = ippFindAttribute(con->request, "job-name", |
1508 | IPP_TAG_NAME)) != NULL) | |
1509 | title = attr->values[0].string.text; | |
1510 | else | |
1511 | ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, | |
1512 | title = "Untitled"); | |
ef416fc2 | 1513 | |
b423cd4c | 1514 | if ((job = cupsdAddJob(priority, printer->name)) == NULL) |
1515 | { | |
1516 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
f7deaa1a | 1517 | _("Unable to add job for destination \"%s\"!"), |
1518 | printer->name); | |
b423cd4c | 1519 | return (NULL); |
1520 | } | |
ef416fc2 | 1521 | |
f7deaa1a | 1522 | job->dtype = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT | |
1523 | CUPS_PRINTER_REMOTE); | |
b423cd4c | 1524 | job->attrs = con->request; |
3dfe78b3 | 1525 | job->dirty = 1; |
2abf387c | 1526 | con->request = ippNewRequest(job->attrs->request.op.operation_id); |
ef416fc2 | 1527 | |
3dfe78b3 MS |
1528 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); |
1529 | ||
b423cd4c | 1530 | add_job_uuid(con, job); |
1531 | apply_printer_defaults(printer, job); | |
ef416fc2 | 1532 | |
b423cd4c | 1533 | attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME); |
ef416fc2 | 1534 | |
b423cd4c | 1535 | if (con->username[0]) |
1536 | { | |
1537 | cupsdSetString(&job->username, con->username); | |
ef416fc2 | 1538 | |
1539 | if (attr) | |
b423cd4c | 1540 | cupsdSetString(&attr->values[0].string.text, con->username); |
ef416fc2 | 1541 | } |
b423cd4c | 1542 | else if (attr) |
1543 | { | |
1544 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
1545 | "add_job: requesting-user-name=\"%s\"", | |
1546 | attr->values[0].string.text); | |
ef416fc2 | 1547 | |
b423cd4c | 1548 | cupsdSetString(&job->username, attr->values[0].string.text); |
1549 | } | |
1550 | else | |
1551 | cupsdSetString(&job->username, "anonymous"); | |
ef416fc2 | 1552 | |
b423cd4c | 1553 | if (!attr) |
1554 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, | |
1555 | "job-originating-user-name", NULL, job->username); | |
1556 | else | |
1557 | { | |
1558 | attr->group_tag = IPP_TAG_JOB; | |
757d2cad | 1559 | _cupsStrFree(attr->name); |
1560 | attr->name = _cupsStrAlloc("job-originating-user-name"); | |
b423cd4c | 1561 | } |
ef416fc2 | 1562 | |
f7deaa1a | 1563 | if (con->username[0] || auth_info) |
1564 | { | |
1565 | save_auth_info(con, job, auth_info); | |
1566 | ||
1567 | /* | |
1568 | * Remove the auth-info attribute from the attribute data... | |
1569 | */ | |
1570 | ||
1571 | if (auth_info) | |
a4924f6c | 1572 | ippDeleteAttribute(job->attrs, auth_info); |
f7deaa1a | 1573 | } |
1574 | ||
b423cd4c | 1575 | if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name", |
1576 | IPP_TAG_ZERO)) != NULL) | |
ef416fc2 | 1577 | { |
b423cd4c | 1578 | /* |
1579 | * Request contains a job-originating-host-name attribute; validate it... | |
1580 | */ | |
ef416fc2 | 1581 | |
b423cd4c | 1582 | if (attr->value_tag != IPP_TAG_NAME || |
1583 | attr->num_values != 1 || | |
1584 | strcmp(con->http.hostname, "localhost")) | |
ef416fc2 | 1585 | { |
1586 | /* | |
b423cd4c | 1587 | * Can't override the value if we aren't connected via localhost. |
1588 | * Also, we can only have 1 value and it must be a name value. | |
ef416fc2 | 1589 | */ |
1590 | ||
b423cd4c | 1591 | switch (attr->value_tag) |
1592 | { | |
1593 | case IPP_TAG_STRING : | |
1594 | case IPP_TAG_TEXTLANG : | |
1595 | case IPP_TAG_NAMELANG : | |
1596 | case IPP_TAG_TEXT : | |
1597 | case IPP_TAG_NAME : | |
1598 | case IPP_TAG_KEYWORD : | |
1599 | case IPP_TAG_URI : | |
1600 | case IPP_TAG_URISCHEME : | |
1601 | case IPP_TAG_CHARSET : | |
1602 | case IPP_TAG_LANGUAGE : | |
1603 | case IPP_TAG_MIMETYPE : | |
1604 | /* | |
1605 | * Free old strings... | |
1606 | */ | |
ef416fc2 | 1607 | |
b423cd4c | 1608 | for (i = 0; i < attr->num_values; i ++) |
1609 | { | |
757d2cad | 1610 | _cupsStrFree(attr->values[i].string.text); |
b423cd4c | 1611 | attr->values[i].string.text = NULL; |
1612 | if (attr->values[i].string.charset) | |
1613 | { | |
757d2cad | 1614 | _cupsStrFree(attr->values[i].string.charset); |
b423cd4c | 1615 | attr->values[i].string.charset = NULL; |
1616 | } | |
1617 | } | |
ef416fc2 | 1618 | |
b423cd4c | 1619 | default : |
1620 | break; | |
1621 | } | |
ef416fc2 | 1622 | |
b423cd4c | 1623 | /* |
1624 | * Use the default connection hostname instead... | |
1625 | */ | |
bd7854cb | 1626 | |
b423cd4c | 1627 | attr->value_tag = IPP_TAG_NAME; |
1628 | attr->num_values = 1; | |
757d2cad | 1629 | attr->values[0].string.text = _cupsStrAlloc(con->http.hostname); |
b423cd4c | 1630 | } |
bd7854cb | 1631 | |
b423cd4c | 1632 | attr->group_tag = IPP_TAG_JOB; |
1633 | } | |
1634 | else | |
1635 | { | |
1636 | /* | |
1637 | * No job-originating-host-name attribute, so use the hostname from | |
1638 | * the connection... | |
1639 | */ | |
bd7854cb | 1640 | |
f7deaa1a | 1641 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, |
b423cd4c | 1642 | "job-originating-host-name", NULL, con->http.hostname); |
1643 | } | |
bd7854cb | 1644 | |
b423cd4c | 1645 | ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation", |
1646 | time(NULL)); | |
1647 | attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, | |
1648 | "time-at-processing", 0); | |
1649 | attr->value_tag = IPP_TAG_NOVALUE; | |
1650 | attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, | |
1651 | "time-at-completed", 0); | |
1652 | attr->value_tag = IPP_TAG_NOVALUE; | |
bd7854cb | 1653 | |
1654 | /* | |
b423cd4c | 1655 | * Add remaining job attributes... |
bd7854cb | 1656 | */ |
1657 | ||
b423cd4c | 1658 | ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id); |
1659 | job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM, | |
1660 | "job-state", IPP_JOB_STOPPED); | |
d09495fa | 1661 | job->state_value = (ipp_jstate_t)job->state->values[0].integer; |
b423cd4c | 1662 | job->sheets = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, |
1663 | "job-media-sheets-completed", 0); | |
1664 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL, | |
1665 | printer->uri); | |
1666 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, | |
1667 | title); | |
bd7854cb | 1668 | |
b423cd4c | 1669 | if ((attr = ippFindAttribute(job->attrs, "job-k-octets", |
1670 | IPP_TAG_INTEGER)) != NULL) | |
1671 | attr->values[0].integer = 0; | |
1672 | else | |
1673 | attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, | |
1674 | "job-k-octets", 0); | |
bd7854cb | 1675 | |
b423cd4c | 1676 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", |
1677 | IPP_TAG_KEYWORD)) == NULL) | |
1678 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); | |
1679 | if (!attr) | |
ef416fc2 | 1680 | { |
b423cd4c | 1681 | if ((val = cupsGetOption("job-hold-until", printer->num_options, |
1682 | printer->options)) == NULL) | |
1683 | val = "no-hold"; | |
ef416fc2 | 1684 | |
b423cd4c | 1685 | attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD, |
1686 | "job-hold-until", NULL, val); | |
ef416fc2 | 1687 | } |
b423cd4c | 1688 | if (attr && strcmp(attr->values[0].string.text, "no-hold") && |
1689 | !(printer->type & CUPS_PRINTER_REMOTE)) | |
ef416fc2 | 1690 | { |
1691 | /* | |
b423cd4c | 1692 | * Hold job until specified time... |
ef416fc2 | 1693 | */ |
1694 | ||
b423cd4c | 1695 | cupsdSetJobHoldUntil(job, attr->values[0].string.text); |
e53920b9 | 1696 | |
1697 | job->state->values[0].integer = IPP_JOB_HELD; | |
1698 | job->state_value = IPP_JOB_HELD; | |
ef416fc2 | 1699 | } |
b423cd4c | 1700 | else if (job->attrs->request.op.operation_id == IPP_CREATE_JOB) |
ef416fc2 | 1701 | { |
e53920b9 | 1702 | job->hold_until = time(NULL) + 60; |
b423cd4c | 1703 | job->state->values[0].integer = IPP_JOB_HELD; |
1704 | job->state_value = IPP_JOB_HELD; | |
1705 | } | |
1706 | else | |
1707 | { | |
1708 | job->state->values[0].integer = IPP_JOB_PENDING; | |
1709 | job->state_value = IPP_JOB_PENDING; | |
ef416fc2 | 1710 | } |
1711 | ||
b423cd4c | 1712 | if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) || |
1713 | Classification) | |
ef416fc2 | 1714 | { |
1715 | /* | |
b423cd4c | 1716 | * Add job sheets options... |
ef416fc2 | 1717 | */ |
1718 | ||
b423cd4c | 1719 | if ((attr = ippFindAttribute(job->attrs, "job-sheets", |
1720 | IPP_TAG_ZERO)) == NULL) | |
ef416fc2 | 1721 | { |
b423cd4c | 1722 | cupsdLogMessage(CUPSD_LOG_DEBUG, |
1723 | "Adding default job-sheets values \"%s,%s\"...", | |
1724 | printer->job_sheets[0], printer->job_sheets[1]); | |
ef416fc2 | 1725 | |
b423cd4c | 1726 | attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets", |
1727 | 2, NULL, NULL); | |
757d2cad | 1728 | attr->values[0].string.text = _cupsStrAlloc(printer->job_sheets[0]); |
1729 | attr->values[1].string.text = _cupsStrAlloc(printer->job_sheets[1]); | |
ef416fc2 | 1730 | } |
1731 | ||
b423cd4c | 1732 | job->job_sheets = attr; |
ef416fc2 | 1733 | |
ef416fc2 | 1734 | /* |
b423cd4c | 1735 | * Enforce classification level if set... |
ef416fc2 | 1736 | */ |
1737 | ||
b423cd4c | 1738 | if (Classification) |
ef416fc2 | 1739 | { |
b423cd4c | 1740 | cupsdLogMessage(CUPSD_LOG_INFO, |
1741 | "Classification=\"%s\", ClassifyOverride=%d", | |
1742 | Classification ? Classification : "(null)", | |
1743 | ClassifyOverride); | |
ef416fc2 | 1744 | |
b423cd4c | 1745 | if (ClassifyOverride) |
1746 | { | |
1747 | if (!strcmp(attr->values[0].string.text, "none") && | |
1748 | (attr->num_values == 1 || | |
1749 | !strcmp(attr->values[1].string.text, "none"))) | |
1750 | { | |
1751 | /* | |
1752 | * Force the leading banner to have the classification on it... | |
1753 | */ | |
ef416fc2 | 1754 | |
b423cd4c | 1755 | cupsdSetString(&attr->values[0].string.text, Classification); |
e00b005a | 1756 | |
b423cd4c | 1757 | cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED " |
1758 | "job-sheets=\"%s,none\", " | |
1759 | "job-originating-user-name=\"%s\"", | |
1760 | job->id, Classification, job->username); | |
1761 | } | |
1762 | else if (attr->num_values == 2 && | |
1763 | strcmp(attr->values[0].string.text, | |
1764 | attr->values[1].string.text) && | |
1765 | strcmp(attr->values[0].string.text, "none") && | |
1766 | strcmp(attr->values[1].string.text, "none")) | |
1767 | { | |
1768 | /* | |
1769 | * Can't put two different security markings on the same document! | |
1770 | */ | |
ef416fc2 | 1771 | |
b423cd4c | 1772 | cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text); |
ef416fc2 | 1773 | |
b423cd4c | 1774 | cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED " |
1775 | "job-sheets=\"%s,%s\", " | |
1776 | "job-originating-user-name=\"%s\"", | |
1777 | job->id, attr->values[0].string.text, | |
1778 | attr->values[1].string.text, job->username); | |
1779 | } | |
1780 | else if (strcmp(attr->values[0].string.text, Classification) && | |
1781 | strcmp(attr->values[0].string.text, "none") && | |
1782 | (attr->num_values == 1 || | |
1783 | (strcmp(attr->values[1].string.text, Classification) && | |
1784 | strcmp(attr->values[1].string.text, "none")))) | |
1785 | { | |
1786 | if (attr->num_values == 1) | |
1787 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
1788 | "[Job %d] CLASSIFICATION OVERRIDDEN " | |
1789 | "job-sheets=\"%s\", " | |
1790 | "job-originating-user-name=\"%s\"", | |
1791 | job->id, attr->values[0].string.text, job->username); | |
1792 | else | |
1793 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
1794 | "[Job %d] CLASSIFICATION OVERRIDDEN " | |
1795 | "job-sheets=\"%s,%s\",fffff " | |
1796 | "job-originating-user-name=\"%s\"", | |
1797 | job->id, attr->values[0].string.text, | |
1798 | attr->values[1].string.text, job->username); | |
1799 | } | |
1800 | } | |
1801 | else if (strcmp(attr->values[0].string.text, Classification) && | |
1802 | (attr->num_values == 1 || | |
1803 | strcmp(attr->values[1].string.text, Classification))) | |
ef416fc2 | 1804 | { |
1805 | /* | |
b423cd4c | 1806 | * Force the banner to have the classification on it... |
ef416fc2 | 1807 | */ |
1808 | ||
b423cd4c | 1809 | if (attr->num_values > 1 && |
1810 | !strcmp(attr->values[0].string.text, attr->values[1].string.text)) | |
1811 | { | |
1812 | cupsdSetString(&(attr->values[0].string.text), Classification); | |
1813 | cupsdSetString(&(attr->values[1].string.text), Classification); | |
1814 | } | |
1815 | else | |
1816 | { | |
1817 | if (attr->num_values == 1 || | |
1818 | strcmp(attr->values[0].string.text, "none")) | |
1819 | cupsdSetString(&(attr->values[0].string.text), Classification); | |
ef416fc2 | 1820 | |
b423cd4c | 1821 | if (attr->num_values > 1 && |
1822 | strcmp(attr->values[1].string.text, "none")) | |
1823 | cupsdSetString(&(attr->values[1].string.text), Classification); | |
1824 | } | |
ef416fc2 | 1825 | |
b423cd4c | 1826 | if (attr->num_values > 1) |
1827 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
1828 | "[Job %d] CLASSIFICATION FORCED " | |
1829 | "job-sheets=\"%s,%s\", " | |
1830 | "job-originating-user-name=\"%s\"", | |
1831 | job->id, attr->values[0].string.text, | |
1832 | attr->values[1].string.text, job->username); | |
1833 | else | |
1834 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
1835 | "[Job %d] CLASSIFICATION FORCED " | |
1836 | "job-sheets=\"%s\", " | |
1837 | "job-originating-user-name=\"%s\"", | |
1838 | job->id, Classification, job->username); | |
ef416fc2 | 1839 | } |
1840 | } | |
1841 | ||
b423cd4c | 1842 | /* |
1843 | * See if we need to add the starting sheet... | |
1844 | */ | |
ef416fc2 | 1845 | |
b423cd4c | 1846 | if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))) |
ef416fc2 | 1847 | { |
b423cd4c | 1848 | cupsdLogMessage(CUPSD_LOG_INFO, |
09a101d6 | 1849 | "[Job %d] Adding start banner page \"%s\".", |
1850 | job->id, attr->values[0].string.text); | |
ef416fc2 | 1851 | |
91c84a35 | 1852 | if ((kbytes = copy_banner(con, job, attr->values[0].string.text)) < 0) |
3dfe78b3 MS |
1853 | { |
1854 | cupsdDeleteJob(job); | |
91c84a35 | 1855 | return (NULL); |
3dfe78b3 | 1856 | } |
ef416fc2 | 1857 | |
b423cd4c | 1858 | cupsdUpdateQuota(printer, job->username, 0, kbytes); |
1859 | } | |
ef416fc2 | 1860 | } |
b423cd4c | 1861 | else if ((attr = ippFindAttribute(job->attrs, "job-sheets", |
1862 | IPP_TAG_ZERO)) != NULL) | |
1863 | job->sheets = attr; | |
ef416fc2 | 1864 | |
b423cd4c | 1865 | /* |
1866 | * Fill in the response info... | |
1867 | */ | |
ef416fc2 | 1868 | |
b423cd4c | 1869 | snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName, |
1870 | LocalPort, job->id); | |
ef416fc2 | 1871 | |
b423cd4c | 1872 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, |
1873 | job_uri); | |
ef416fc2 | 1874 | |
b423cd4c | 1875 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id); |
ef416fc2 | 1876 | |
b423cd4c | 1877 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", |
1878 | job->state_value); | |
1879 | add_job_state_reasons(con, job); | |
ef416fc2 | 1880 | |
b423cd4c | 1881 | con->response->request.status.status_code = IPP_OK; |
ef416fc2 | 1882 | |
b423cd4c | 1883 | /* |
1884 | * Add any job subscriptions... | |
1885 | */ | |
ef416fc2 | 1886 | |
b423cd4c | 1887 | add_job_subscriptions(con, job); |
ef416fc2 | 1888 | |
b423cd4c | 1889 | /* |
1890 | * Set all but the first two attributes to the job attributes group... | |
1891 | */ | |
ef416fc2 | 1892 | |
b423cd4c | 1893 | for (attr = job->attrs->attrs->next->next; attr; attr = attr->next) |
1894 | attr->group_tag = IPP_TAG_JOB; | |
ef416fc2 | 1895 | |
1896 | /* | |
b423cd4c | 1897 | * Fire the "job created" event... |
ef416fc2 | 1898 | */ |
1899 | ||
b423cd4c | 1900 | cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created."); |
ef416fc2 | 1901 | |
1902 | /* | |
b423cd4c | 1903 | * Return the new job... |
ef416fc2 | 1904 | */ |
1905 | ||
b423cd4c | 1906 | return (job); |
1907 | } | |
ef416fc2 | 1908 | |
ef416fc2 | 1909 | |
b423cd4c | 1910 | /* |
1911 | * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based | |
1912 | * upon the job and printer state... | |
1913 | */ | |
ef416fc2 | 1914 | |
b423cd4c | 1915 | static void |
1916 | add_job_state_reasons( | |
1917 | cupsd_client_t *con, /* I - Client connection */ | |
1918 | cupsd_job_t *job) /* I - Job info */ | |
1919 | { | |
1920 | cupsd_printer_t *dest; /* Destination printer */ | |
ef416fc2 | 1921 | |
ef416fc2 | 1922 | |
b423cd4c | 1923 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)", |
1924 | con, con->http.fd, job ? job->id : 0); | |
ef416fc2 | 1925 | |
d09495fa | 1926 | switch (job ? job->state_value : IPP_JOB_CANCELED) |
ef416fc2 | 1927 | { |
b423cd4c | 1928 | case IPP_JOB_PENDING : |
80ca4592 | 1929 | dest = cupsdFindDest(job->dest); |
bd7854cb | 1930 | |
b423cd4c | 1931 | if (dest && dest->state == IPP_PRINTER_STOPPED) |
1932 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1933 | "job-state-reasons", NULL, "printer-stopped"); | |
1934 | else | |
1935 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1936 | "job-state-reasons", NULL, "none"); | |
1937 | break; | |
ef416fc2 | 1938 | |
b423cd4c | 1939 | case IPP_JOB_HELD : |
1940 | if (ippFindAttribute(job->attrs, "job-hold-until", | |
1941 | IPP_TAG_KEYWORD) != NULL || | |
1942 | ippFindAttribute(job->attrs, "job-hold-until", | |
1943 | IPP_TAG_NAME) != NULL) | |
1944 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1945 | "job-state-reasons", NULL, "job-hold-until-specified"); | |
1946 | else | |
1947 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1948 | "job-state-reasons", NULL, "job-incoming"); | |
1949 | break; | |
ef416fc2 | 1950 | |
b423cd4c | 1951 | case IPP_JOB_PROCESSING : |
1952 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1953 | "job-state-reasons", NULL, "job-printing"); | |
1954 | break; | |
ef416fc2 | 1955 | |
b423cd4c | 1956 | case IPP_JOB_STOPPED : |
1957 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1958 | "job-state-reasons", NULL, "job-stopped"); | |
1959 | break; | |
ef416fc2 | 1960 | |
d09495fa | 1961 | case IPP_JOB_CANCELED : |
b423cd4c | 1962 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, |
1963 | "job-state-reasons", NULL, "job-canceled-by-user"); | |
1964 | break; | |
ef416fc2 | 1965 | |
b423cd4c | 1966 | case IPP_JOB_ABORTED : |
1967 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1968 | "job-state-reasons", NULL, "aborted-by-system"); | |
1969 | break; | |
ef416fc2 | 1970 | |
b423cd4c | 1971 | case IPP_JOB_COMPLETED : |
1972 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, | |
1973 | "job-state-reasons", NULL, "job-completed-successfully"); | |
1974 | break; | |
ef416fc2 | 1975 | } |
ef416fc2 | 1976 | } |
1977 | ||
1978 | ||
1979 | /* | |
b423cd4c | 1980 | * 'add_job_subscriptions()' - Add any subcriptions for a job. |
ef416fc2 | 1981 | */ |
1982 | ||
1983 | static void | |
b423cd4c | 1984 | add_job_subscriptions( |
1985 | cupsd_client_t *con, /* I - Client connection */ | |
1986 | cupsd_job_t *job) /* I - Newly created job */ | |
ef416fc2 | 1987 | { |
b423cd4c | 1988 | int i; /* Looping var */ |
1989 | ipp_attribute_t *prev, /* Previous attribute */ | |
1990 | *next, /* Next attribute */ | |
1991 | *attr; /* Current attribute */ | |
1992 | cupsd_subscription_t *sub; /* Subscription object */ | |
1993 | const char *recipient, /* notify-recipient-uri */ | |
1994 | *pullmethod; /* notify-pull-method */ | |
1995 | ipp_attribute_t *user_data; /* notify-user-data */ | |
1996 | int interval; /* notify-time-interval */ | |
1997 | unsigned mask; /* notify-events */ | |
ef416fc2 | 1998 | |
ef416fc2 | 1999 | |
b423cd4c | 2000 | /* |
2001 | * Find the first subscription group attribute; return if we have | |
2002 | * none... | |
2003 | */ | |
ef416fc2 | 2004 | |
b423cd4c | 2005 | for (attr = job->attrs->attrs, prev = NULL; |
2006 | attr; | |
2007 | prev = attr, attr = attr->next) | |
2008 | if (attr->group_tag == IPP_TAG_SUBSCRIPTION) | |
2009 | break; | |
ef416fc2 | 2010 | |
b423cd4c | 2011 | if (!attr) |
2012 | return; | |
ef416fc2 | 2013 | |
b423cd4c | 2014 | /* |
2015 | * Process the subscription attributes in the request... | |
2016 | */ | |
ef416fc2 | 2017 | |
b423cd4c | 2018 | while (attr) |
2019 | { | |
2020 | recipient = NULL; | |
2021 | pullmethod = NULL; | |
2022 | user_data = NULL; | |
2023 | interval = 0; | |
2024 | mask = CUPSD_EVENT_NONE; | |
ef416fc2 | 2025 | |
b423cd4c | 2026 | while (attr && attr->group_tag != IPP_TAG_ZERO) |
2027 | { | |
f899b121 | 2028 | if (!strcmp(attr->name, "notify-recipient-uri") && |
b423cd4c | 2029 | attr->value_tag == IPP_TAG_URI) |
3dfe78b3 MS |
2030 | { |
2031 | /* | |
2032 | * Validate the recipient scheme against the ServerBin/notifier | |
2033 | * directory... | |
2034 | */ | |
2035 | ||
2036 | char notifier[1024], /* Notifier filename */ | |
2037 | scheme[HTTP_MAX_URI], /* Scheme portion of URI */ | |
2038 | userpass[HTTP_MAX_URI], /* Username portion of URI */ | |
2039 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
2040 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
2041 | int port; /* Port portion of URI */ | |
2042 | ||
2043 | ||
b423cd4c | 2044 | recipient = attr->values[0].string.text; |
3dfe78b3 MS |
2045 | |
2046 | if (httpSeparateURI(HTTP_URI_CODING_ALL, recipient, | |
2047 | scheme, sizeof(scheme), userpass, sizeof(userpass), | |
2048 | host, sizeof(host), &port, | |
2049 | resource, sizeof(resource)) < HTTP_URI_OK) | |
2050 | { | |
2051 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
2052 | _("Bad notify-recipient-uri URI \"%s\"!"), recipient); | |
2053 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
2054 | "notify-status-code", IPP_URI_SCHEME); | |
2055 | return; | |
2056 | } | |
2057 | ||
2058 | snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin, | |
2059 | scheme); | |
2060 | if (access(notifier, X_OK)) | |
2061 | { | |
2062 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
2063 | _("notify-recipient-uri URI \"%s\" uses unknown " | |
2064 | "scheme!"), recipient); | |
2065 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
2066 | "notify-status-code", IPP_URI_SCHEME); | |
2067 | return; | |
2068 | } | |
2069 | ||
2070 | if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient)) | |
2071 | { | |
2072 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
2073 | _("notify-recipient-uri URI \"%s\" is already used!"), | |
2074 | recipient); | |
2075 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
2076 | "notify-status-code", IPP_ATTRIBUTES); | |
2077 | return; | |
2078 | } | |
2079 | } | |
b423cd4c | 2080 | else if (!strcmp(attr->name, "notify-pull-method") && |
2081 | attr->value_tag == IPP_TAG_KEYWORD) | |
3dfe78b3 | 2082 | { |
b423cd4c | 2083 | pullmethod = attr->values[0].string.text; |
3dfe78b3 MS |
2084 | |
2085 | if (strcmp(pullmethod, "ippget")) | |
2086 | { | |
2087 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
2088 | _("Bad notify-pull-method \"%s\"!"), pullmethod); | |
2089 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
2090 | "notify-status-code", IPP_ATTRIBUTES); | |
2091 | return; | |
2092 | } | |
2093 | } | |
b423cd4c | 2094 | else if (!strcmp(attr->name, "notify-charset") && |
2095 | attr->value_tag == IPP_TAG_CHARSET && | |
2096 | strcmp(attr->values[0].string.text, "us-ascii") && | |
2097 | strcmp(attr->values[0].string.text, "utf-8")) | |
2098 | { | |
2099 | send_ipp_status(con, IPP_CHARSET, | |
2100 | _("Character set \"%s\" not supported!"), | |
2101 | attr->values[0].string.text); | |
2102 | return; | |
2103 | } | |
2104 | else if (!strcmp(attr->name, "notify-natural-language") && | |
2105 | (attr->value_tag != IPP_TAG_LANGUAGE || | |
2106 | strcmp(attr->values[0].string.text, DefaultLanguage))) | |
2107 | { | |
2108 | send_ipp_status(con, IPP_CHARSET, | |
2109 | _("Language \"%s\" not supported!"), | |
2110 | attr->values[0].string.text); | |
2111 | return; | |
2112 | } | |
2113 | else if (!strcmp(attr->name, "notify-user-data") && | |
2114 | attr->value_tag == IPP_TAG_STRING) | |
2115 | { | |
2116 | if (attr->num_values > 1 || attr->values[0].unknown.length > 63) | |
2117 | { | |
2118 | send_ipp_status(con, IPP_REQUEST_VALUE, | |
2119 | _("The notify-user-data value is too large " | |
2120 | "(%d > 63 octets)!"), | |
2121 | attr->values[0].unknown.length); | |
2122 | return; | |
2123 | } | |
ef416fc2 | 2124 | |
b423cd4c | 2125 | user_data = attr; |
2126 | } | |
2127 | else if (!strcmp(attr->name, "notify-events") && | |
2128 | attr->value_tag == IPP_TAG_KEYWORD) | |
2129 | { | |
2130 | for (i = 0; i < attr->num_values; i ++) | |
2131 | mask |= cupsdEventValue(attr->values[i].string.text); | |
2132 | } | |
2133 | else if (!strcmp(attr->name, "notify-lease-duration")) | |
2134 | { | |
2135 | send_ipp_status(con, IPP_BAD_REQUEST, | |
2136 | _("The notify-lease-duration attribute cannot be " | |
2137 | "used with job subscriptions.")); | |
2138 | return; | |
2139 | } | |
2140 | else if (!strcmp(attr->name, "notify-time-interval") && | |
2141 | attr->value_tag == IPP_TAG_INTEGER) | |
2142 | interval = attr->values[0].integer; | |
ef416fc2 | 2143 | |
b423cd4c | 2144 | attr = attr->next; |
2145 | } | |
ef416fc2 | 2146 | |
b423cd4c | 2147 | if (!recipient && !pullmethod) |
2148 | break; | |
ef416fc2 | 2149 | |
b423cd4c | 2150 | if (mask == CUPSD_EVENT_NONE) |
2151 | mask = CUPSD_EVENT_JOB_COMPLETED; | |
ef416fc2 | 2152 | |
b423cd4c | 2153 | sub = cupsdAddSubscription(mask, cupsdFindDest(job->dest), job, recipient, |
2154 | 0); | |
ef416fc2 | 2155 | |
b423cd4c | 2156 | sub->interval = interval; |
ef416fc2 | 2157 | |
b423cd4c | 2158 | cupsdSetString(&sub->owner, job->username); |
ef416fc2 | 2159 | |
b423cd4c | 2160 | if (user_data) |
ef416fc2 | 2161 | { |
b423cd4c | 2162 | sub->user_data_len = user_data->values[0].unknown.length; |
2163 | memcpy(sub->user_data, user_data->values[0].unknown.data, | |
2164 | sub->user_data_len); | |
ef416fc2 | 2165 | } |
2166 | ||
b423cd4c | 2167 | ippAddSeparator(con->response); |
2168 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
2169 | "notify-subscription-id", sub->id); | |
ef416fc2 | 2170 | |
b423cd4c | 2171 | if (attr) |
2172 | attr = attr->next; | |
ef416fc2 | 2173 | } |
2174 | ||
3dfe78b3 | 2175 | cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS); |
b423cd4c | 2176 | |
ef416fc2 | 2177 | /* |
b423cd4c | 2178 | * Remove all of the subscription attributes from the job request... |
ef416fc2 | 2179 | */ |
2180 | ||
b423cd4c | 2181 | for (attr = job->attrs->attrs, prev = NULL; attr; attr = next) |
ef416fc2 | 2182 | { |
b423cd4c | 2183 | next = attr->next; |
ef416fc2 | 2184 | |
b423cd4c | 2185 | if (attr->group_tag == IPP_TAG_SUBSCRIPTION || |
2186 | attr->group_tag == IPP_TAG_ZERO) | |
2187 | { | |
2188 | /* | |
2189 | * Free and remove this attribute... | |
2190 | */ | |
ef416fc2 | 2191 | |
757d2cad | 2192 | _ippFreeAttr(attr); |
ef416fc2 | 2193 | |
b423cd4c | 2194 | if (prev) |
2195 | prev->next = next; | |
2196 | else | |
2197 | job->attrs->attrs = next; | |
2198 | } | |
2199 | else | |
2200 | prev = attr; | |
ef416fc2 | 2201 | } |
2202 | ||
b423cd4c | 2203 | job->attrs->last = prev; |
2204 | job->attrs->current = prev; | |
2205 | } | |
ef416fc2 | 2206 | |
ef416fc2 | 2207 | |
b423cd4c | 2208 | /* |
2209 | * 'add_job_uuid()' - Add job-uuid attribute to a job. | |
2210 | * | |
2211 | * See RFC 4122 for the definition of UUIDs and the format. | |
2212 | */ | |
2213 | ||
2214 | static void | |
2215 | add_job_uuid(cupsd_client_t *con, /* I - Client connection */ | |
2216 | cupsd_job_t *job) /* I - Job */ | |
2217 | { | |
2218 | char uuid[1024]; /* job-uuid string */ | |
b423cd4c | 2219 | _cups_md5_state_t md5state; /* MD5 state */ |
2220 | unsigned char md5sum[16]; /* MD5 digest/sum */ | |
ef416fc2 | 2221 | |
ef416fc2 | 2222 | |
2223 | /* | |
b423cd4c | 2224 | * First see if the job already has a job-uuid attribute; if so, return... |
ef416fc2 | 2225 | */ |
2226 | ||
d09495fa | 2227 | if (ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI)) |
b423cd4c | 2228 | return; |
ef416fc2 | 2229 | |
2230 | /* | |
b423cd4c | 2231 | * No job-uuid attribute, so build a version 3 UUID with the local job |
2232 | * ID at the end; see RFC 4122 for details. Start with the MD5 sum of | |
2233 | * the ServerName, server name and port that the client connected to, | |
2234 | * and local job ID... | |
ef416fc2 | 2235 | */ |
2236 | ||
b423cd4c | 2237 | snprintf(uuid, sizeof(uuid), "%s:%s:%d:%d", ServerName, con->servername, |
2238 | con->serverport, job->id); | |
ef416fc2 | 2239 | |
757d2cad | 2240 | _cupsMD5Init(&md5state); |
2241 | _cupsMD5Append(&md5state, (unsigned char *)uuid, strlen(uuid)); | |
2242 | _cupsMD5Finish(&md5state, md5sum); | |
ef416fc2 | 2243 | |
2244 | /* | |
b423cd4c | 2245 | * Format the UUID URI using the MD5 sum and job ID. |
ef416fc2 | 2246 | */ |
2247 | ||
b423cd4c | 2248 | snprintf(uuid, sizeof(uuid), |
2249 | "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" | |
2250 | "%02x%02x%02x%02x%02x%02x", | |
2251 | md5sum[0], md5sum[1], md5sum[2], md5sum[3], md5sum[4], md5sum[5], | |
2252 | (md5sum[6] & 15) | 0x30, md5sum[7], (md5sum[8] & 0x3f) | 0x40, | |
2253 | md5sum[9], md5sum[10], md5sum[11], md5sum[12], md5sum[13], | |
2254 | md5sum[14], md5sum[15]); | |
ef416fc2 | 2255 | |
b423cd4c | 2256 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL, uuid); |
ef416fc2 | 2257 | } |
2258 | ||
2259 | ||
2260 | /* | |
b423cd4c | 2261 | * 'add_printer()' - Add a printer to the system. |
ef416fc2 | 2262 | */ |
2263 | ||
2264 | static void | |
b423cd4c | 2265 | add_printer(cupsd_client_t *con, /* I - Client connection */ |
2266 | ipp_attribute_t *uri) /* I - URI of printer */ | |
ef416fc2 | 2267 | { |
2268 | http_status_t status; /* Policy status */ | |
b423cd4c | 2269 | int i; /* Looping var */ |
09a101d6 | 2270 | char scheme[HTTP_MAX_URI], /* Method portion of URI */ |
b423cd4c | 2271 | username[HTTP_MAX_URI], /* Username portion of URI */ |
ef416fc2 | 2272 | host[HTTP_MAX_URI], /* Host portion of URI */ |
2273 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
2274 | int port; /* Port portion of URI */ | |
b423cd4c | 2275 | cupsd_printer_t *printer; /* Printer/class */ |
2276 | ipp_attribute_t *attr; /* Printer attribute */ | |
2277 | cups_file_t *fp; /* Script/PPD file */ | |
2278 | char line[1024]; /* Line from file... */ | |
2279 | char srcfile[1024], /* Source Script/PPD file */ | |
2280 | dstfile[1024]; /* Destination Script/PPD file */ | |
2281 | int modify; /* Non-zero if we are modifying */ | |
2282 | char newname[IPP_MAX_NAME]; /* New printer name */ | |
2283 | int need_restart_job; /* Need to restart job? */ | |
09a101d6 | 2284 | int set_device_uri, /* Did we set the device URI? */ |
2285 | set_port_monitor; /* Did we set the port monitor? */ | |
ef416fc2 | 2286 | |
2287 | ||
b423cd4c | 2288 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con, |
ef416fc2 | 2289 | con->http.fd, uri->values[0].string.text); |
2290 | ||
2291 | /* | |
b423cd4c | 2292 | * Do we have a valid URI? |
ef416fc2 | 2293 | */ |
2294 | ||
09a101d6 | 2295 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
2296 | sizeof(scheme), username, sizeof(username), host, | |
b423cd4c | 2297 | sizeof(host), &port, resource, sizeof(resource)); |
2298 | ||
2299 | if (strncmp(resource, "/printers/", 10) || strlen(resource) == 10) | |
ef416fc2 | 2300 | { |
b423cd4c | 2301 | /* |
2302 | * No, return an error... | |
2303 | */ | |
2304 | ||
ef416fc2 | 2305 | send_ipp_status(con, IPP_BAD_REQUEST, |
b423cd4c | 2306 | _("The printer-uri must be of the form " |
2307 | "\"ipp://HOSTNAME/printers/PRINTERNAME\".")); | |
ef416fc2 | 2308 | return; |
2309 | } | |
2310 | ||
2311 | /* | |
b423cd4c | 2312 | * Do we have a valid printer name? |
ef416fc2 | 2313 | */ |
2314 | ||
b423cd4c | 2315 | if (!validate_name(resource + 10)) |
ef416fc2 | 2316 | { |
b423cd4c | 2317 | /* |
2318 | * No, return an error... | |
2319 | */ | |
2320 | ||
2321 | send_ipp_status(con, IPP_BAD_REQUEST, | |
2322 | _("The printer-uri \"%s\" contains invalid characters."), | |
2323 | uri->values[0].string.text); | |
2324 | return; | |
ef416fc2 | 2325 | } |
ef416fc2 | 2326 | |
ef416fc2 | 2327 | /* |
b423cd4c | 2328 | * See if the printer already exists; if not, create a new printer... |
2329 | */ | |
ef416fc2 | 2330 | |
b423cd4c | 2331 | if ((printer = cupsdFindPrinter(resource + 10)) == NULL) |
ef416fc2 | 2332 | { |
2333 | /* | |
b423cd4c | 2334 | * Printer doesn't exist; see if we have a class of the same name... |
ef416fc2 | 2335 | */ |
2336 | ||
b423cd4c | 2337 | if ((printer = cupsdFindClass(resource + 10)) != NULL && |
bc44d920 | 2338 | !(printer->type & CUPS_PRINTER_DISCOVERED)) |
ef416fc2 | 2339 | { |
b423cd4c | 2340 | /* |
2341 | * Yes, return an error... | |
2342 | */ | |
ef416fc2 | 2343 | |
b423cd4c | 2344 | send_ipp_status(con, IPP_NOT_POSSIBLE, |
2345 | _("A class named \"%s\" already exists!"), | |
2346 | resource + 10); | |
ef416fc2 | 2347 | return; |
2348 | } | |
2349 | ||
2350 | /* | |
2e4ff8af | 2351 | * No, check the default policy then add the printer... |
ef416fc2 | 2352 | */ |
2353 | ||
2e4ff8af MS |
2354 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
2355 | { | |
2356 | send_http_error(con, status, NULL); | |
2357 | return; | |
2358 | } | |
2359 | ||
b423cd4c | 2360 | printer = cupsdAddPrinter(resource + 10); |
2361 | modify = 0; | |
ef416fc2 | 2362 | } |
b423cd4c | 2363 | else if (printer->type & CUPS_PRINTER_IMPLICIT) |
ef416fc2 | 2364 | { |
2365 | /* | |
2e4ff8af MS |
2366 | * Check the default policy, then rename the implicit printer to |
2367 | * "AnyPrinter" or delete it... | |
ef416fc2 | 2368 | */ |
2369 | ||
2e4ff8af MS |
2370 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
2371 | { | |
2372 | send_http_error(con, status, NULL); | |
2373 | return; | |
2374 | } | |
2375 | ||
b423cd4c | 2376 | if (ImplicitAnyClasses) |
ef416fc2 | 2377 | { |
b423cd4c | 2378 | snprintf(newname, sizeof(newname), "Any%s", resource + 10); |
2379 | cupsdRenamePrinter(printer, newname); | |
ef416fc2 | 2380 | } |
b423cd4c | 2381 | else |
2382 | cupsdDeletePrinter(printer, 1); | |
ef416fc2 | 2383 | |
2384 | /* | |
b423cd4c | 2385 | * Add the printer as a new local printer... |
ef416fc2 | 2386 | */ |
2387 | ||
b423cd4c | 2388 | printer = cupsdAddPrinter(resource + 10); |
2389 | modify = 0; | |
ef416fc2 | 2390 | } |
bc44d920 | 2391 | else if (printer->type & CUPS_PRINTER_DISCOVERED) |
b423cd4c | 2392 | { |
2393 | /* | |
2e4ff8af MS |
2394 | * Check the default policy, then rename the remote printer to |
2395 | * "Printer@server"... | |
b423cd4c | 2396 | */ |
ef416fc2 | 2397 | |
2e4ff8af MS |
2398 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
2399 | { | |
2400 | send_http_error(con, status, NULL); | |
2401 | return; | |
2402 | } | |
2403 | ||
b423cd4c | 2404 | snprintf(newname, sizeof(newname), "%s@%s", resource + 10, |
2405 | printer->hostname); | |
2406 | cupsdRenamePrinter(printer, newname); | |
ef416fc2 | 2407 | |
b423cd4c | 2408 | /* |
2409 | * Add the printer as a new local printer... | |
2410 | */ | |
ef416fc2 | 2411 | |
b423cd4c | 2412 | printer = cupsdAddPrinter(resource + 10); |
2413 | modify = 0; | |
2414 | } | |
2e4ff8af MS |
2415 | else if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, |
2416 | NULL)) != HTTP_OK) | |
2417 | { | |
2fb76298 | 2418 | send_http_error(con, status, printer); |
2e4ff8af MS |
2419 | return; |
2420 | } | |
b423cd4c | 2421 | else |
2422 | modify = 1; | |
ef416fc2 | 2423 | |
b423cd4c | 2424 | /* |
2425 | * Look for attributes and copy them over as needed... | |
2426 | */ | |
ef416fc2 | 2427 | |
b423cd4c | 2428 | need_restart_job = 0; |
ef416fc2 | 2429 | |
b423cd4c | 2430 | if ((attr = ippFindAttribute(con->request, "printer-location", |
2431 | IPP_TAG_TEXT)) != NULL) | |
2432 | cupsdSetString(&printer->location, attr->values[0].string.text); | |
ef416fc2 | 2433 | |
b423cd4c | 2434 | if ((attr = ippFindAttribute(con->request, "printer-info", |
2435 | IPP_TAG_TEXT)) != NULL) | |
2436 | cupsdSetString(&printer->info, attr->values[0].string.text); | |
ef416fc2 | 2437 | |
09a101d6 | 2438 | set_device_uri = 0; |
2439 | ||
b423cd4c | 2440 | if ((attr = ippFindAttribute(con->request, "device-uri", |
2441 | IPP_TAG_URI)) != NULL) | |
ef416fc2 | 2442 | { |
2443 | /* | |
b423cd4c | 2444 | * Do we have a valid device URI? |
ef416fc2 | 2445 | */ |
2446 | ||
2fb76298 MS |
2447 | http_uri_status_t uri_status; /* URI separation status */ |
2448 | ||
2449 | ||
b423cd4c | 2450 | need_restart_job = 1; |
ef416fc2 | 2451 | |
2fb76298 MS |
2452 | uri_status = httpSeparateURI(HTTP_URI_CODING_ALL, |
2453 | attr->values[0].string.text, | |
2454 | scheme, sizeof(scheme), | |
2455 | username, sizeof(username), | |
2456 | host, sizeof(host), &port, | |
2457 | resource, sizeof(resource)); | |
2458 | ||
2459 | if (uri_status < HTTP_URI_OK) | |
2460 | { | |
2461 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"), | |
2462 | attr->values[0].string.text); | |
2463 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
2464 | "add_printer: httpSeparateURI returned %d", uri_status); | |
2465 | return; | |
2466 | } | |
b423cd4c | 2467 | |
09a101d6 | 2468 | if (!strcmp(scheme, "file")) |
ef416fc2 | 2469 | { |
2470 | /* | |
b423cd4c | 2471 | * See if the administrator has enabled file devices... |
ef416fc2 | 2472 | */ |
2473 | ||
b423cd4c | 2474 | if (!FileDevice && strcmp(resource, "/dev/null")) |
ef416fc2 | 2475 | { |
2476 | /* | |
b423cd4c | 2477 | * File devices are disabled and the URL is not file:/dev/null... |
ef416fc2 | 2478 | */ |
2479 | ||
b423cd4c | 2480 | send_ipp_status(con, IPP_NOT_POSSIBLE, |
2481 | _("File device URIs have been disabled! " | |
2482 | "To enable, see the FileDevice directive in " | |
2483 | "\"%s/cupsd.conf\"."), | |
2484 | ServerRoot); | |
ef416fc2 | 2485 | return; |
2486 | } | |
b423cd4c | 2487 | } |
2488 | else | |
2489 | { | |
ef416fc2 | 2490 | /* |
b423cd4c | 2491 | * See if the backend exists and is executable... |
ef416fc2 | 2492 | */ |
2493 | ||
09a101d6 | 2494 | snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, scheme); |
b423cd4c | 2495 | if (access(srcfile, X_OK)) |
ef416fc2 | 2496 | { |
2497 | /* | |
b423cd4c | 2498 | * Could not find device in list! |
ef416fc2 | 2499 | */ |
ef416fc2 | 2500 | |
b423cd4c | 2501 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"), |
2502 | attr->values[0].string.text); | |
2503 | return; | |
ef416fc2 | 2504 | } |
2505 | } | |
ef416fc2 | 2506 | |
b423cd4c | 2507 | cupsdLogMessage(CUPSD_LOG_INFO, |
2508 | "Setting %s device-uri to \"%s\" (was \"%s\".)", | |
2509 | printer->name, | |
2510 | cupsdSanitizeURI(attr->values[0].string.text, line, | |
2511 | sizeof(line)), | |
2512 | cupsdSanitizeURI(printer->device_uri, resource, | |
2513 | sizeof(resource))); | |
ef416fc2 | 2514 | |
b423cd4c | 2515 | cupsdSetString(&printer->device_uri, attr->values[0].string.text); |
09a101d6 | 2516 | set_device_uri = 1; |
ef416fc2 | 2517 | } |
2518 | ||
09a101d6 | 2519 | set_port_monitor = 0; |
2520 | ||
b423cd4c | 2521 | if ((attr = ippFindAttribute(con->request, "port-monitor", |
09a101d6 | 2522 | IPP_TAG_NAME)) != NULL) |
ef416fc2 | 2523 | { |
b423cd4c | 2524 | ipp_attribute_t *supported; /* port-monitor-supported attribute */ |
ef416fc2 | 2525 | |
ef416fc2 | 2526 | |
b423cd4c | 2527 | need_restart_job = 1; |
ef416fc2 | 2528 | |
b423cd4c | 2529 | supported = ippFindAttribute(printer->attrs, "port-monitor-supported", |
a41f09e2 | 2530 | IPP_TAG_NAME); |
080811b1 MS |
2531 | if (supported) |
2532 | { | |
2533 | for (i = 0; i < supported->num_values; i ++) | |
2534 | if (!strcmp(supported->values[i].string.text, | |
2535 | attr->values[0].string.text)) | |
2536 | break; | |
2537 | } | |
ef416fc2 | 2538 | |
080811b1 | 2539 | if (!supported || i >= supported->num_values) |
b423cd4c | 2540 | { |
2541 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"), | |
2542 | attr->values[0].string.text); | |
2543 | return; | |
2544 | } | |
ef416fc2 | 2545 | |
b423cd4c | 2546 | cupsdLogMessage(CUPSD_LOG_INFO, |
2547 | "Setting %s port-monitor to \"%s\" (was \"%s\".)", | |
2548 | printer->name, attr->values[0].string.text, | |
09a101d6 | 2549 | printer->port_monitor ? printer->port_monitor : "none"); |
ef416fc2 | 2550 | |
b423cd4c | 2551 | if (strcmp(attr->values[0].string.text, "none")) |
2552 | cupsdSetString(&printer->port_monitor, attr->values[0].string.text); | |
2553 | else | |
2554 | cupsdClearString(&printer->port_monitor); | |
09a101d6 | 2555 | |
2556 | set_port_monitor = 1; | |
b423cd4c | 2557 | } |
ef416fc2 | 2558 | |
b423cd4c | 2559 | if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", |
2560 | IPP_TAG_BOOLEAN)) != NULL) | |
2561 | { | |
2562 | cupsdLogMessage(CUPSD_LOG_INFO, | |
2563 | "Setting %s printer-is-accepting-jobs to %d (was %d.)", | |
2564 | printer->name, attr->values[0].boolean, printer->accepting); | |
ef416fc2 | 2565 | |
b423cd4c | 2566 | printer->accepting = attr->values[0].boolean; |
2567 | cupsdAddPrinterHistory(printer); | |
2568 | } | |
bd7854cb | 2569 | |
b423cd4c | 2570 | if ((attr = ippFindAttribute(con->request, "printer-is-shared", |
2571 | IPP_TAG_BOOLEAN)) != NULL) | |
2572 | { | |
2573 | if (printer->shared && !attr->values[0].boolean) | |
f7deaa1a | 2574 | cupsdDeregisterPrinter(printer, 1); |
bd7854cb | 2575 | |
b423cd4c | 2576 | cupsdLogMessage(CUPSD_LOG_INFO, |
2577 | "Setting %s printer-is-shared to %d (was %d.)", | |
2578 | printer->name, attr->values[0].boolean, printer->shared); | |
bd7854cb | 2579 | |
b423cd4c | 2580 | printer->shared = attr->values[0].boolean; |
2581 | } | |
bd7854cb | 2582 | |
b423cd4c | 2583 | if ((attr = ippFindAttribute(con->request, "printer-state", |
2584 | IPP_TAG_ENUM)) != NULL) | |
bd7854cb | 2585 | { |
b423cd4c | 2586 | if (attr->values[0].integer != IPP_PRINTER_IDLE && |
2587 | attr->values[0].integer != IPP_PRINTER_STOPPED) | |
2588 | { | |
2589 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d!"), | |
2590 | attr->values[0].integer); | |
2591 | return; | |
2592 | } | |
bd7854cb | 2593 | |
bc44d920 | 2594 | cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-state to %d (was %d.)", |
2595 | printer->name, attr->values[0].integer, printer->state); | |
b423cd4c | 2596 | |
2597 | if (attr->values[0].integer == IPP_PRINTER_STOPPED) | |
2598 | cupsdStopPrinter(printer, 0); | |
2599 | else | |
2600 | { | |
2601 | need_restart_job = 1; | |
2602 | cupsdSetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0); | |
2603 | } | |
2604 | } | |
2605 | if ((attr = ippFindAttribute(con->request, "printer-state-message", | |
2606 | IPP_TAG_TEXT)) != NULL) | |
2607 | { | |
2608 | strlcpy(printer->state_message, attr->values[0].string.text, | |
2609 | sizeof(printer->state_message)); | |
2610 | cupsdAddPrinterHistory(printer); | |
bd7854cb | 2611 | } |
2612 | ||
b423cd4c | 2613 | set_printer_defaults(con, printer); |
2614 | ||
09a101d6 | 2615 | if ((attr = ippFindAttribute(con->request, "auth-info-required", |
2616 | IPP_TAG_KEYWORD)) != NULL) | |
2617 | cupsdSetAuthInfoRequired(printer, NULL, attr); | |
2618 | ||
bd7854cb | 2619 | /* |
b423cd4c | 2620 | * See if we have all required attributes... |
bd7854cb | 2621 | */ |
2622 | ||
b423cd4c | 2623 | if (!printer->device_uri) |
2624 | cupsdSetString(&printer->device_uri, "file:///dev/null"); | |
bd7854cb | 2625 | |
2626 | /* | |
b423cd4c | 2627 | * See if we have an interface script or PPD file attached to the request... |
bd7854cb | 2628 | */ |
2629 | ||
b423cd4c | 2630 | if (con->filename) |
2631 | { | |
2632 | need_restart_job = 1; | |
bd7854cb | 2633 | |
b423cd4c | 2634 | strlcpy(srcfile, con->filename, sizeof(srcfile)); |
ef416fc2 | 2635 | |
b423cd4c | 2636 | if ((fp = cupsFileOpen(srcfile, "rb"))) |
2637 | { | |
2638 | /* | |
2639 | * Yes; get the first line from it... | |
2640 | */ | |
ef416fc2 | 2641 | |
b423cd4c | 2642 | line[0] = '\0'; |
2643 | cupsFileGets(fp, line, sizeof(line)); | |
2644 | cupsFileClose(fp); | |
ef416fc2 | 2645 | |
b423cd4c | 2646 | /* |
2647 | * Then see what kind of file it is... | |
2648 | */ | |
ef416fc2 | 2649 | |
b423cd4c | 2650 | snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot, |
2651 | printer->name); | |
ef416fc2 | 2652 | |
b423cd4c | 2653 | if (!strncmp(line, "*PPD-Adobe", 10)) |
2654 | { | |
2655 | /* | |
2656 | * The new file is a PPD file, so remove any old interface script | |
2657 | * that might be lying around... | |
2658 | */ | |
ef416fc2 | 2659 | |
b423cd4c | 2660 | unlink(dstfile); |
2661 | } | |
2662 | else | |
2663 | { | |
2664 | /* | |
2665 | * This must be an interface script, so move the file over to the | |
2666 | * interfaces directory and make it executable... | |
2667 | */ | |
ef416fc2 | 2668 | |
b423cd4c | 2669 | if (copy_file(srcfile, dstfile)) |
2670 | { | |
2671 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
2672 | _("Unable to copy interface script - %s!"), | |
2673 | strerror(errno)); | |
2674 | return; | |
2675 | } | |
568fa3fa MS |
2676 | |
2677 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
2678 | "Copied interface script successfully!"); | |
2679 | chmod(dstfile, 0755); | |
b423cd4c | 2680 | } |
ef416fc2 | 2681 | |
b423cd4c | 2682 | snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, |
2683 | printer->name); | |
ef416fc2 | 2684 | |
b423cd4c | 2685 | if (!strncmp(line, "*PPD-Adobe", 10)) |
2686 | { | |
2687 | /* | |
2688 | * The new file is a PPD file, so move the file over to the | |
2689 | * ppd directory and make it readable by all... | |
2690 | */ | |
ef416fc2 | 2691 | |
b423cd4c | 2692 | if (copy_file(srcfile, dstfile)) |
2693 | { | |
2694 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
2695 | _("Unable to copy PPD file - %s!"), | |
2696 | strerror(errno)); | |
2697 | return; | |
2698 | } | |
568fa3fa MS |
2699 | |
2700 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
2701 | "Copied PPD file successfully!"); | |
2702 | chmod(dstfile, 0644); | |
2703 | ||
2704 | #ifdef __APPLE__ | |
2705 | /* | |
2706 | * (Re)register color profiles... | |
2707 | */ | |
2708 | ||
2709 | apple_unregister_profiles(printer); | |
2710 | apple_register_profiles(printer); | |
2711 | #endif /* __APPLE__ */ | |
b423cd4c | 2712 | } |
2713 | else | |
2714 | { | |
2715 | /* | |
2716 | * This must be an interface script, so remove any old PPD file that | |
2717 | * may be lying around... | |
2718 | */ | |
ef416fc2 | 2719 | |
b423cd4c | 2720 | unlink(dstfile); |
2721 | } | |
2722 | } | |
2723 | } | |
2724 | else if ((attr = ippFindAttribute(con->request, "ppd-name", | |
2725 | IPP_TAG_NAME)) != NULL) | |
ef416fc2 | 2726 | { |
b423cd4c | 2727 | need_restart_job = 1; |
ef416fc2 | 2728 | |
b423cd4c | 2729 | if (!strcmp(attr->values[0].string.text, "raw")) |
ef416fc2 | 2730 | { |
b423cd4c | 2731 | /* |
2732 | * Raw driver, remove any existing PPD or interface script files. | |
2733 | */ | |
ef416fc2 | 2734 | |
b423cd4c | 2735 | snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot, |
2736 | printer->name); | |
2737 | unlink(dstfile); | |
ef416fc2 | 2738 | |
b423cd4c | 2739 | snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, |
2740 | printer->name); | |
2741 | unlink(dstfile); | |
2742 | } | |
2743 | else | |
ef416fc2 | 2744 | { |
b423cd4c | 2745 | /* |
2746 | * PPD model file... | |
2747 | */ | |
2748 | ||
2749 | snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot, | |
2750 | printer->name); | |
2751 | unlink(dstfile); | |
2752 | ||
2753 | snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, | |
2754 | printer->name); | |
2755 | ||
2756 | if (copy_model(con, attr->values[0].string.text, dstfile)) | |
2757 | { | |
2758 | send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file!")); | |
2759 | return; | |
2760 | } | |
568fa3fa MS |
2761 | |
2762 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
2763 | "Copied PPD file successfully!"); | |
2764 | chmod(dstfile, 0644); | |
2765 | ||
2766 | #ifdef __APPLE__ | |
2767 | /* | |
2768 | * (Re)register color profiles... | |
2769 | */ | |
2770 | ||
2771 | apple_unregister_profiles(printer); | |
2772 | apple_register_profiles(printer); | |
2773 | #endif /* __APPLE__ */ | |
ef416fc2 | 2774 | } |
2775 | } | |
2776 | ||
09a101d6 | 2777 | /* |
2778 | * If we set the device URI but not the port monitor, check which port | |
2779 | * monitor to use by default... | |
2780 | */ | |
2781 | ||
2782 | if (set_device_uri && !set_port_monitor) | |
2783 | { | |
2784 | ppd_file_t *ppd; /* PPD file */ | |
2785 | ppd_attr_t *ppdattr; /* cupsPortMonitor attribute */ | |
2786 | ||
2787 | ||
2788 | httpSeparateURI(HTTP_URI_CODING_ALL, printer->device_uri, scheme, | |
2789 | sizeof(scheme), username, sizeof(username), host, | |
2790 | sizeof(host), &port, resource, sizeof(resource)); | |
2791 | ||
2792 | snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, | |
2793 | printer->name); | |
2794 | if ((ppd = ppdOpenFile(srcfile)) != NULL) | |
2795 | { | |
2796 | for (ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
2797 | ppdattr; | |
2798 | ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) | |
2799 | if (!strcmp(scheme, ppdattr->spec)) | |
2800 | { | |
2801 | cupsdLogMessage(CUPSD_LOG_INFO, | |
2802 | "Setting %s port-monitor to \"%s\" (was \"%s\".)", | |
2803 | printer->name, ppdattr->value, | |
bc44d920 | 2804 | printer->port_monitor ? printer->port_monitor |
2805 | : "none"); | |
09a101d6 | 2806 | |
2807 | if (strcmp(ppdattr->value, "none")) | |
2808 | cupsdSetString(&printer->port_monitor, ppdattr->value); | |
2809 | else | |
2810 | cupsdClearString(&printer->port_monitor); | |
2811 | ||
2812 | break; | |
2813 | } | |
2814 | ||
2815 | ppdClose(ppd); | |
2816 | } | |
2817 | } | |
2818 | ||
ef416fc2 | 2819 | /* |
b423cd4c | 2820 | * Update the printer attributes and return... |
ef416fc2 | 2821 | */ |
2822 | ||
b423cd4c | 2823 | cupsdSetPrinterAttrs(printer); |
3dfe78b3 | 2824 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
ef416fc2 | 2825 | |
b423cd4c | 2826 | if (need_restart_job && printer->job) |
ef416fc2 | 2827 | { |
b423cd4c | 2828 | cupsd_job_t *job; |
ef416fc2 | 2829 | |
b423cd4c | 2830 | /* |
2831 | * Stop the current job and then restart it below... | |
2832 | */ | |
ef416fc2 | 2833 | |
b423cd4c | 2834 | job = (cupsd_job_t *)printer->job; |
ef416fc2 | 2835 | |
b423cd4c | 2836 | cupsdStopJob(job, 1); |
2837 | ||
2838 | job->state->values[0].integer = IPP_JOB_PENDING; | |
2839 | job->state_value = IPP_JOB_PENDING; | |
ef416fc2 | 2840 | } |
2841 | ||
b423cd4c | 2842 | if (need_restart_job) |
2843 | cupsdCheckJobs(); | |
ef416fc2 | 2844 | |
3dfe78b3 | 2845 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
b423cd4c | 2846 | |
2847 | if (modify) | |
ef416fc2 | 2848 | { |
b423cd4c | 2849 | cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL, |
2850 | "Printer \"%s\" modified by \"%s\".", printer->name, | |
2851 | get_username(con)); | |
ef416fc2 | 2852 | |
b423cd4c | 2853 | cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".", |
2854 | printer->name, get_username(con)); | |
ef416fc2 | 2855 | } |
b423cd4c | 2856 | else |
2857 | { | |
2858 | cupsdAddPrinterHistory(printer); | |
ef416fc2 | 2859 | |
b423cd4c | 2860 | cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, printer, NULL, |
2861 | "New printer \"%s\" added by \"%s\".", printer->name, | |
2862 | get_username(con)); | |
ef416fc2 | 2863 | |
b423cd4c | 2864 | cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".", |
2865 | printer->name, get_username(con)); | |
2866 | } | |
2867 | ||
2868 | con->response->request.status.status_code = IPP_OK; | |
ef416fc2 | 2869 | } |
2870 | ||
2871 | ||
2872 | /* | |
b423cd4c | 2873 | * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute |
2874 | * based upon the printer state... | |
ef416fc2 | 2875 | */ |
2876 | ||
b423cd4c | 2877 | static void |
2878 | add_printer_state_reasons( | |
2879 | cupsd_client_t *con, /* I - Client connection */ | |
2880 | cupsd_printer_t *p) /* I - Printer info */ | |
ef416fc2 | 2881 | { |
b423cd4c | 2882 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
2883 | "add_printer_state_reasons(%p[%d], %p[%s])", | |
2884 | con, con->http.fd, p, p->name); | |
ef416fc2 | 2885 | |
b423cd4c | 2886 | if (p->num_reasons == 0) |
2887 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2888 | "printer-state-reasons", NULL, | |
2889 | p->state == IPP_PRINTER_STOPPED ? "paused" : "none"); | |
2890 | else | |
2891 | ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2892 | "printer-state-reasons", p->num_reasons, NULL, | |
2893 | (const char * const *)p->reasons); | |
2894 | } | |
ef416fc2 | 2895 | |
ef416fc2 | 2896 | |
b423cd4c | 2897 | /* |
2898 | * 'add_queued_job_count()' - Add the "queued-job-count" attribute for | |
2899 | * the specified printer or class. | |
2900 | */ | |
ef416fc2 | 2901 | |
b423cd4c | 2902 | static void |
2903 | add_queued_job_count( | |
2904 | cupsd_client_t *con, /* I - Client connection */ | |
2905 | cupsd_printer_t *p) /* I - Printer or class */ | |
2906 | { | |
2907 | int count; /* Number of jobs on destination */ | |
ef416fc2 | 2908 | |
ef416fc2 | 2909 | |
b423cd4c | 2910 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])", |
2911 | con, con->http.fd, p, p->name); | |
ef416fc2 | 2912 | |
b423cd4c | 2913 | count = cupsdGetPrinterJobCount(p->name); |
ef416fc2 | 2914 | |
b423cd4c | 2915 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, |
2916 | "queued-job-count", count); | |
2917 | } | |
ef416fc2 | 2918 | |
ef416fc2 | 2919 | |
568fa3fa | 2920 | #ifdef __APPLE__ |
568fa3fa MS |
2921 | /* |
2922 | * 'apple_init_profile()' - Initialize a color profile. | |
2923 | */ | |
2924 | ||
2925 | static void | |
2926 | apple_init_profile( | |
a603edef MS |
2927 | ppd_file_t *ppd, /* I - PPD file */ |
2928 | cups_array_t *languages, /* I - Languages in the PPD file */ | |
568fa3fa MS |
2929 | CMDeviceProfileInfo *profile, /* I - Profile record */ |
2930 | unsigned id, /* I - Profile ID */ | |
2931 | const char *name, /* I - Profile name */ | |
a603edef | 2932 | const char *text, /* I - Profile UI text */ |
568fa3fa MS |
2933 | const char *iccfile) /* I - ICC filename */ |
2934 | { | |
2935 | char url[1024]; /* URL for profile filename */ | |
2936 | CFMutableDictionaryRef dict; /* Dictionary for name */ | |
a603edef MS |
2937 | char *language; /* Current language */ |
2938 | ppd_attr_t *attr; /* Profile attribute */ | |
db0bd74a MS |
2939 | CFStringRef cflang, /* Language string */ |
2940 | cftext; /* Localized text */ | |
568fa3fa MS |
2941 | |
2942 | ||
a603edef MS |
2943 | /* |
2944 | * Build the profile name dictionary... | |
2945 | */ | |
568fa3fa MS |
2946 | |
2947 | dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
2948 | &kCFTypeDictionaryKeyCallBacks, | |
2949 | &kCFTypeDictionaryValueCallBacks); | |
2950 | ||
db0bd74a MS |
2951 | cftext = CFStringCreateWithCString(kCFAllocatorDefault, text, |
2952 | kCFStringEncodingUTF8); | |
a603edef | 2953 | |
db0bd74a MS |
2954 | if (cftext) |
2955 | { | |
2956 | CFDictionarySetValue(dict, CFSTR("en"), cftext); | |
2957 | CFRelease(cftext); | |
2958 | } | |
2959 | ||
2960 | if (languages) | |
a603edef MS |
2961 | { |
2962 | /* | |
2963 | * Find localized names for the color profiles... | |
2964 | */ | |
2965 | ||
2966 | cupsArraySave(ppd->sorted_attrs); | |
2967 | ||
2968 | for (language = (char *)cupsArrayFirst(languages); | |
2969 | language; | |
2970 | language = (char *)cupsArrayNext(languages)) | |
2971 | { | |
db0bd74a | 2972 | if (iccfile) |
c9fc04c6 MS |
2973 | { |
2974 | if ((attr = _ppdLocalizedAttr(ppd, "cupsICCProfile", name, | |
2975 | language)) == NULL) | |
2976 | attr = _ppdLocalizedAttr(ppd, "APTiogaProfile", name, language); | |
2977 | } | |
db0bd74a MS |
2978 | else |
2979 | attr = _ppdLocalizedAttr(ppd, "ColorModel", name, language); | |
2980 | ||
2981 | if (attr && attr->text[0]) | |
2982 | { | |
2983 | cflang = CFStringCreateWithCString(kCFAllocatorDefault, language, | |
2984 | kCFStringEncodingUTF8); | |
2985 | cftext = CFStringCreateWithCString(kCFAllocatorDefault, attr->text, | |
2986 | kCFStringEncodingUTF8); | |
2987 | ||
2988 | if (cflang && cftext) | |
2989 | CFDictionarySetValue(dict, cflang, cftext); | |
2990 | ||
2991 | if (cflang) | |
2992 | CFRelease(cflang); | |
2993 | ||
2994 | if (cftext) | |
2995 | CFRelease(cftext); | |
2996 | } | |
a603edef MS |
2997 | } |
2998 | ||
2999 | cupsArrayRestore(ppd->sorted_attrs); | |
3000 | } | |
3001 | ||
3002 | /* | |
3003 | * Fill in the profile data... | |
3004 | */ | |
3005 | ||
3006 | if (iccfile) | |
3007 | httpAssembleURI(HTTP_URI_CODING_ALL, url, sizeof(url), "file", NULL, "", 0, | |
3008 | iccfile); | |
3009 | ||
568fa3fa MS |
3010 | profile->dataVersion = cmDeviceProfileInfoVersion1; |
3011 | profile->profileID = id; | |
3012 | profile->profileLoc.locType = iccfile ? cmPathBasedProfile : cmNoProfileBase; | |
3013 | profile->profileName = dict; | |
3014 | ||
3015 | if (iccfile) | |
3016 | strlcpy(profile->profileLoc.u.pathLoc.path, iccfile, | |
3017 | sizeof(profile->profileLoc.u.pathLoc.path)); | |
568fa3fa MS |
3018 | } |
3019 | ||
3020 | ||
3021 | /* | |
3022 | * 'apple_register_profiles()' - Register color profiles for a printer. | |
3023 | */ | |
3024 | ||
3025 | static void | |
3026 | apple_register_profiles( | |
3027 | cupsd_printer_t *p) /* I - Printer */ | |
3028 | { | |
3029 | int i; /* Looping var */ | |
3030 | char ppdfile[1024], /* PPD filename */ | |
db0bd74a MS |
3031 | iccfile[1024], /* ICC filename */ |
3032 | selector[PPD_MAX_NAME]; | |
3033 | /* Profile selection string */ | |
568fa3fa | 3034 | ppd_file_t *ppd; /* PPD file */ |
db0bd74a MS |
3035 | ppd_attr_t *attr, /* cupsICCProfile attributes */ |
3036 | *profileid_attr;/* cupsProfileID attribute */ | |
c9fc04c6 | 3037 | const char *profile_key; /* Profile keyword */ |
568fa3fa | 3038 | ppd_option_t *cm_option; /* Color model option */ |
db0bd74a MS |
3039 | ppd_choice_t *cm_choice, /* Color model choice */ |
3040 | *q1_choice, /* ColorModel (or other) qualifier */ | |
3041 | *q2_choice, /* MediaType (or other) qualifier */ | |
3042 | *q3_choice; /* Resolution (or other) qualifier */ | |
568fa3fa MS |
3043 | int num_profiles; /* Number of profiles */ |
3044 | CMError error; /* Last error */ | |
db0bd74a MS |
3045 | unsigned device_id, /* Printer device ID */ |
3046 | profile_id, /* Profile ID */ | |
3047 | default_profile_id = 0; | |
3048 | /* Default profile ID */ | |
3049 | CFMutableDictionaryRef device_name; /* Printer device name dictionary */ | |
3050 | CFStringRef printer_name; /* Printer name string */ | |
568fa3fa MS |
3051 | CMDeviceScope scope = /* Scope of the registration */ |
3052 | { | |
3053 | kCFPreferencesAnyUser, | |
3054 | kCFPreferencesCurrentHost | |
3055 | }; | |
3056 | CMDeviceProfileArrayPtr profiles; /* Profiles */ | |
3057 | CMDeviceProfileInfo *profile; /* Current profile */ | |
a603edef | 3058 | cups_array_t *languages; /* Languages array */ |
568fa3fa MS |
3059 | |
3060 | ||
64a69576 MS |
3061 | /* |
3062 | * Make sure ColorSync is available... | |
3063 | */ | |
3064 | ||
3065 | if (CMRegisterColorDevice == NULL) | |
3066 | return; | |
3067 | ||
568fa3fa MS |
3068 | /* |
3069 | * Try opening the PPD file for this printer... | |
3070 | */ | |
3071 | ||
3072 | snprintf(ppdfile, sizeof(ppdfile), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
3073 | if ((ppd = ppdOpenFile(ppdfile)) == NULL) | |
3074 | return; | |
3075 | ||
db0bd74a MS |
3076 | ppdMarkDefaults(ppd); |
3077 | ||
568fa3fa MS |
3078 | /* |
3079 | * See if we have any profiles... | |
3080 | */ | |
3081 | ||
c9fc04c6 MS |
3082 | if ((attr = ppdFindAttr(ppd, "APTiogaProfile", NULL)) != NULL) |
3083 | profile_key = "APTiogaProfile"; | |
3084 | else | |
3085 | { | |
3086 | attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); | |
3087 | profile_key = "cupsICCProfile"; | |
3088 | } | |
3089 | ||
3090 | for (num_profiles = 0; attr; attr = ppdFindNextAttr(ppd, profile_key, NULL)) | |
568fa3fa MS |
3091 | if (attr->spec[0] && attr->value && attr->value[0]) |
3092 | { | |
3093 | if (attr->value[0] != '/') | |
3094 | snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir, | |
3095 | attr->value); | |
3096 | else | |
3097 | strlcpy(iccfile, attr->value, sizeof(iccfile)); | |
3098 | ||
3099 | if (access(iccfile, 0)) | |
3100 | continue; | |
3101 | ||
3102 | num_profiles ++; | |
3103 | } | |
3104 | ||
c9fc04c6 | 3105 | |
568fa3fa MS |
3106 | /* |
3107 | * If we have profiles, add them... | |
3108 | */ | |
3109 | ||
3110 | if (num_profiles > 0) | |
3111 | { | |
db0bd74a MS |
3112 | /* |
3113 | * Figure out the default profile selectors... | |
3114 | */ | |
3115 | ||
3116 | if ((attr = ppdFindAttr(ppd, "cupsICCQualifier1", NULL)) != NULL && | |
3117 | attr->value && attr->value[0]) | |
3118 | q1_choice = ppdFindMarkedChoice(ppd, attr->value); | |
3119 | else | |
3120 | q1_choice = ppdFindMarkedChoice(ppd, "ColorModel"); | |
3121 | ||
3122 | if ((attr = ppdFindAttr(ppd, "cupsICCQualifier2", NULL)) != NULL && | |
3123 | attr->value && attr->value[0]) | |
3124 | q2_choice = ppdFindMarkedChoice(ppd, attr->value); | |
3125 | else | |
3126 | q2_choice = ppdFindMarkedChoice(ppd, "MediaType"); | |
3127 | ||
3128 | if ((attr = ppdFindAttr(ppd, "cupsICCQualifier3", NULL)) != NULL && | |
3129 | attr->value && attr->value[0]) | |
3130 | q3_choice = ppdFindMarkedChoice(ppd, attr->value); | |
3131 | else | |
3132 | q3_choice = ppdFindMarkedChoice(ppd, "Resolution"); | |
3133 | ||
568fa3fa MS |
3134 | /* |
3135 | * Build the array of profiles... | |
3136 | * | |
3137 | * Note: This calloc actually requests slightly more memory than needed. | |
3138 | */ | |
3139 | ||
3140 | if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL) | |
3141 | { | |
3142 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3143 | "Unable to allocate memory for %d profiles!", | |
3144 | num_profiles); | |
3145 | ppdClose(ppd); | |
3146 | return; | |
3147 | } | |
3148 | ||
3149 | profiles->profileCount = num_profiles; | |
a603edef | 3150 | languages = _ppdGetLanguages(ppd); |
568fa3fa MS |
3151 | |
3152 | for (profile = profiles->profiles, | |
c9fc04c6 | 3153 | attr = ppdFindAttr(ppd, profile_key, NULL); |
568fa3fa | 3154 | attr; |
c9fc04c6 | 3155 | attr = ppdFindNextAttr(ppd, profile_key, NULL)) |
568fa3fa MS |
3156 | if (attr->spec[0] && attr->value && attr->value[0]) |
3157 | { | |
3158 | /* | |
3159 | * Add this profile... | |
3160 | */ | |
3161 | ||
3162 | if (attr->value[0] != '/') | |
3163 | snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir, | |
3164 | attr->value); | |
3165 | else | |
3166 | strlcpy(iccfile, attr->value, sizeof(iccfile)); | |
3167 | ||
3168 | if (access(iccfile, 0)) | |
3169 | continue; | |
3170 | ||
c9fc04c6 MS |
3171 | if (profile_key[0] == 'c') |
3172 | { | |
3173 | cupsArraySave(ppd->sorted_attrs); | |
db0bd74a | 3174 | |
c9fc04c6 MS |
3175 | if ((profileid_attr = ppdFindAttr(ppd, "cupsProfileID", |
3176 | attr->spec)) != NULL && | |
3177 | profileid_attr->value && isdigit(profileid_attr->value[0] & 255)) | |
3178 | profile_id = (unsigned)strtoul(profileid_attr->value, NULL, 10); | |
3179 | else | |
3180 | profile_id = _ppdHashName(attr->spec); | |
db0bd74a | 3181 | |
c9fc04c6 MS |
3182 | cupsArrayRestore(ppd->sorted_attrs); |
3183 | } | |
3184 | else | |
3185 | profile_id = atoi(attr->spec); | |
db0bd74a MS |
3186 | |
3187 | apple_init_profile(ppd, languages, profile, profile_id, attr->spec, | |
3188 | attr->text[0] ? attr->text : attr->spec, iccfile); | |
568fa3fa MS |
3189 | |
3190 | profile ++; | |
db0bd74a MS |
3191 | |
3192 | /* | |
3193 | * See if this is the default profile... | |
3194 | */ | |
3195 | ||
3196 | if (!default_profile_id && q1_choice) | |
3197 | { | |
3198 | if (q2_choice) | |
3199 | { | |
3200 | if (q3_choice) | |
3201 | { | |
3202 | snprintf(selector, sizeof(selector), "%s.%s.%s", | |
3203 | q1_choice->choice, q2_choice->choice, q3_choice->choice); | |
3204 | if (!strcmp(selector, attr->spec)) | |
3205 | default_profile_id = profile_id; | |
3206 | } | |
3207 | ||
3208 | if (!default_profile_id) | |
3209 | { | |
3210 | snprintf(selector, sizeof(selector), "%s.%s.", q1_choice->choice, | |
3211 | q2_choice->choice); | |
3212 | if (!strcmp(selector, attr->spec)) | |
3213 | default_profile_id = profile_id; | |
3214 | } | |
3215 | } | |
3216 | ||
3217 | if (!default_profile_id && q3_choice) | |
3218 | { | |
3219 | snprintf(selector, sizeof(selector), "%s..%s", q1_choice->choice, | |
3220 | q3_choice->choice); | |
3221 | if (!strcmp(selector, attr->spec)) | |
3222 | default_profile_id = profile_id; | |
3223 | } | |
3224 | ||
3225 | if (!default_profile_id) | |
3226 | { | |
3227 | snprintf(selector, sizeof(selector), "%s..", q1_choice->choice); | |
3228 | if (!strcmp(selector, attr->spec)) | |
3229 | default_profile_id = profile_id; | |
3230 | } | |
3231 | } | |
568fa3fa | 3232 | } |
a603edef MS |
3233 | |
3234 | _ppdFreeLanguages(languages); | |
568fa3fa MS |
3235 | } |
3236 | else if ((cm_option = ppdFindOption(ppd, "ColorModel")) != NULL) | |
3237 | { | |
3238 | /* | |
db0bd74a | 3239 | * Extract profiles from ColorModel option... |
568fa3fa MS |
3240 | */ |
3241 | ||
db0bd74a | 3242 | const char *profile_name; /* Name of generic profile */ |
568fa3fa | 3243 | |
db0bd74a MS |
3244 | |
3245 | num_profiles = cm_option->num_choices; | |
568fa3fa MS |
3246 | |
3247 | if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL) | |
3248 | { | |
3249 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3250 | "Unable to allocate memory for %d profiles!", | |
3251 | num_profiles); | |
3252 | ppdClose(ppd); | |
3253 | return; | |
3254 | } | |
3255 | ||
3256 | profiles->profileCount = num_profiles; | |
3257 | ||
3258 | for (profile = profiles->profiles, i = cm_option->num_choices, | |
3259 | cm_choice = cm_option->choices; | |
3260 | i > 0; | |
db0bd74a MS |
3261 | i --, cm_choice ++, profile ++) |
3262 | { | |
3263 | if (!strcmp(cm_choice->choice, "Gray") || | |
3264 | !strcmp(cm_choice->choice, "Black")) | |
3265 | profile_name = "Gray"; | |
3266 | else if (!strcmp(cm_choice->choice, "RGB") || | |
3267 | !strcmp(cm_choice->choice, "CMY")) | |
3268 | profile_name = "RGB"; | |
3269 | else if (!strcmp(cm_choice->choice, "CMYK") || | |
3270 | !strcmp(cm_choice->choice, "KCMY")) | |
3271 | profile_name = "CMYK"; | |
3272 | else | |
3273 | profile_name = "DeviceN"; | |
3274 | ||
3275 | snprintf(selector, sizeof(selector), "%s..", profile_name); | |
3276 | profile_id = _ppdHashName(selector); | |
3277 | ||
3278 | apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice, | |
3279 | cm_choice->text, NULL); | |
3280 | ||
3281 | if (cm_choice->marked) | |
3282 | default_profile_id = profile_id; | |
3283 | } | |
568fa3fa MS |
3284 | } |
3285 | else | |
3286 | { | |
3287 | /* | |
3288 | * Use the default colorspace... | |
3289 | */ | |
3290 | ||
db0bd74a | 3291 | num_profiles = 1 + ppd->colorspace != PPD_CS_GRAY; |
568fa3fa | 3292 | |
db0bd74a | 3293 | if ((profiles = calloc(num_profiles, sizeof(CMDeviceProfileArray))) == NULL) |
568fa3fa MS |
3294 | { |
3295 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3296 | "Unable to allocate memory for %d profiles!", | |
3297 | num_profiles); | |
3298 | ppdClose(ppd); | |
3299 | return; | |
3300 | } | |
3301 | ||
db0bd74a MS |
3302 | profiles->profileCount = num_profiles; |
3303 | ||
3304 | apple_init_profile(ppd, NULL, profiles->profiles, _ppdHashName("Gray.."), | |
3305 | "Gray", "Gray", NULL); | |
568fa3fa MS |
3306 | |
3307 | switch (ppd->colorspace) | |
3308 | { | |
568fa3fa | 3309 | case PPD_CS_RGB : |
db0bd74a MS |
3310 | case PPD_CS_CMY : |
3311 | apple_init_profile(ppd, NULL, profiles->profiles + 1, | |
a603edef | 3312 | _ppdHashName("RGB.."), "RGB", "RGB", NULL); |
568fa3fa | 3313 | break; |
db0bd74a | 3314 | case PPD_CS_RGBK : |
568fa3fa | 3315 | case PPD_CS_CMYK : |
db0bd74a | 3316 | apple_init_profile(ppd, NULL, profiles->profiles + 1, |
a603edef | 3317 | _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL); |
568fa3fa MS |
3318 | break; |
3319 | ||
db0bd74a MS |
3320 | case PPD_CS_N : |
3321 | apple_init_profile(ppd, NULL, profiles->profiles + 1, | |
3322 | _ppdHashName("DeviceN.."), "DeviceN", "DeviceN", | |
3323 | NULL); | |
3324 | break; | |
3325 | ||
568fa3fa | 3326 | default : |
568fa3fa MS |
3327 | break; |
3328 | } | |
3329 | } | |
3330 | ||
3331 | if (num_profiles > 0) | |
3332 | { | |
db0bd74a MS |
3333 | /* |
3334 | * Make sure we have a default profile ID... | |
3335 | */ | |
3336 | ||
3337 | if (!default_profile_id) | |
3338 | default_profile_id = profiles->profiles[num_profiles - 1].profileID; | |
3339 | ||
568fa3fa MS |
3340 | /* |
3341 | * Get the device ID hash and pathelogical name dictionary. | |
3342 | */ | |
3343 | ||
3344 | cupsdLogMessage(CUPSD_LOG_INFO, "Registering ICC color profiles for \"%s\"", | |
3345 | p->name); | |
3346 | ||
db0bd74a MS |
3347 | device_id = _ppdHashName(p->name); |
3348 | device_name = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
3349 | &kCFTypeDictionaryKeyCallBacks, | |
3350 | &kCFTypeDictionaryValueCallBacks); | |
3351 | printer_name = CFStringCreateWithCString(kCFAllocatorDefault, p->name, | |
3352 | kCFStringEncodingUTF8); | |
568fa3fa | 3353 | |
db0bd74a MS |
3354 | if (device_name && printer_name) |
3355 | { | |
3356 | CFDictionarySetValue(device_name, CFSTR("en"), printer_name); | |
568fa3fa | 3357 | |
db0bd74a MS |
3358 | /* |
3359 | * Register the device with ColorSync... | |
3360 | */ | |
568fa3fa | 3361 | |
db0bd74a MS |
3362 | error = CMRegisterColorDevice(cmPrinterDeviceClass, device_id, |
3363 | device_name, &scope); | |
568fa3fa | 3364 | |
db0bd74a MS |
3365 | /* |
3366 | * Register the profiles... | |
3367 | */ | |
568fa3fa | 3368 | |
db0bd74a MS |
3369 | if (error == noErr) |
3370 | error = CMSetDeviceFactoryProfiles(cmPrinterDeviceClass, device_id, | |
3371 | default_profile_id, profiles); | |
3372 | } | |
3373 | else | |
3374 | error = 1000; | |
568fa3fa MS |
3375 | |
3376 | /* | |
3377 | * Clean up... | |
3378 | */ | |
3379 | ||
3380 | if (error != noErr) | |
3381 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3382 | "Unable to register ICC color profiles for \"%s\" - %d", | |
3383 | p->name, (int)error); | |
3384 | ||
3385 | for (profile = profiles->profiles; | |
3386 | num_profiles > 0; | |
3387 | profile ++, num_profiles --) | |
3388 | CFRelease(profile->profileName); | |
3389 | ||
3390 | free(profiles); | |
db0bd74a MS |
3391 | |
3392 | if (printer_name) | |
3393 | CFRelease(printer_name); | |
3394 | ||
3395 | if (device_name) | |
3396 | CFRelease(device_name); | |
568fa3fa MS |
3397 | } |
3398 | ||
3399 | ppdClose(ppd); | |
3400 | } | |
3401 | ||
3402 | ||
3403 | /* | |
3404 | * 'apple_unregister_profiles()' - Remove color profiles for the specified | |
3405 | * printer. | |
3406 | */ | |
3407 | ||
3408 | static void | |
3409 | apple_unregister_profiles( | |
3410 | cupsd_printer_t *p) /* I - Printer */ | |
3411 | { | |
64a69576 MS |
3412 | /* |
3413 | * Make sure ColorSync is available... | |
3414 | */ | |
3415 | ||
3416 | if (CMUnregisterColorDevice != NULL) | |
3417 | CMUnregisterColorDevice(cmPrinterDeviceClass, _ppdHashName(p->name)); | |
568fa3fa MS |
3418 | } |
3419 | #endif /* __APPLE__ */ | |
3420 | ||
b423cd4c | 3421 | /* |
3422 | * 'apply_printer_defaults()' - Apply printer default options to a job. | |
3423 | */ | |
ef416fc2 | 3424 | |
b423cd4c | 3425 | static void |
3426 | apply_printer_defaults( | |
3427 | cupsd_printer_t *printer, /* I - Printer */ | |
3428 | cupsd_job_t *job) /* I - Job */ | |
3429 | { | |
3430 | int i, /* Looping var */ | |
3431 | num_options; /* Number of default options */ | |
3432 | cups_option_t *options, /* Default options */ | |
f7deaa1a | 3433 | *option; /* Current option */ |
ef416fc2 | 3434 | |
ef416fc2 | 3435 | |
b423cd4c | 3436 | /* |
3437 | * Collect all of the default options and add the missing ones to the | |
3438 | * job object... | |
3439 | */ | |
ef416fc2 | 3440 | |
b423cd4c | 3441 | for (i = printer->num_options, num_options = 0, option = printer->options; |
3442 | i > 0; | |
3443 | i --, option ++) | |
3444 | if (!ippFindAttribute(job->attrs, option->name, IPP_TAG_ZERO)) | |
3445 | { | |
3446 | num_options = cupsAddOption(option->name, option->value, num_options, | |
3447 | &options); | |
3448 | } | |
ef416fc2 | 3449 | |
b423cd4c | 3450 | /* |
3451 | * Encode these options as attributes in the job object... | |
3452 | */ | |
ef416fc2 | 3453 | |
b423cd4c | 3454 | cupsEncodeOptions2(job->attrs, num_options, options, IPP_TAG_JOB); |
3455 | cupsFreeOptions(num_options, options); | |
3456 | } | |
3457 | ||
3458 | ||
3459 | /* | |
3460 | * 'authenticate_job()' - Set job authentication info. | |
3461 | */ | |
3462 | ||
3463 | static void | |
3464 | authenticate_job(cupsd_client_t *con, /* I - Client connection */ | |
3465 | ipp_attribute_t *uri) /* I - Job URI */ | |
3466 | { | |
f7deaa1a | 3467 | ipp_attribute_t *attr, /* job-id attribute */ |
3468 | *auth_info; /* auth-info attribute */ | |
b423cd4c | 3469 | int jobid; /* Job ID */ |
3470 | cupsd_job_t *job; /* Current job */ | |
3471 | char method[HTTP_MAX_URI], | |
3472 | /* Method portion of URI */ | |
3473 | username[HTTP_MAX_URI], | |
3474 | /* Username portion of URI */ | |
3475 | host[HTTP_MAX_URI], | |
3476 | /* Host portion of URI */ | |
3477 | resource[HTTP_MAX_URI]; | |
3478 | /* Resource portion of URI */ | |
3479 | int port; /* Port portion of URI */ | |
ef416fc2 | 3480 | |
ef416fc2 | 3481 | |
b423cd4c | 3482 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "authenticate_job(%p[%d], %s)", |
3483 | con, con->http.fd, uri->values[0].string.text); | |
ef416fc2 | 3484 | |
b423cd4c | 3485 | /* |
3486 | * Start with "everything is OK" status... | |
3487 | */ | |
ef416fc2 | 3488 | |
b423cd4c | 3489 | con->response->request.status.status_code = IPP_OK; |
ef416fc2 | 3490 | |
b423cd4c | 3491 | /* |
3492 | * See if we have a job URI or a printer URI... | |
3493 | */ | |
ef416fc2 | 3494 | |
b423cd4c | 3495 | if (!strcmp(uri->name, "printer-uri")) |
3496 | { | |
3497 | /* | |
3498 | * Got a printer URI; see if we also have a job-id attribute... | |
3499 | */ | |
ef416fc2 | 3500 | |
b423cd4c | 3501 | if ((attr = ippFindAttribute(con->request, "job-id", |
3502 | IPP_TAG_INTEGER)) == NULL) | |
3503 | { | |
3504 | send_ipp_status(con, IPP_BAD_REQUEST, | |
3505 | _("Got a printer-uri attribute but no job-id!")); | |
3506 | return; | |
3507 | } | |
3508 | ||
3509 | jobid = attr->values[0].integer; | |
3510 | } | |
3511 | else | |
3512 | { | |
3513 | /* | |
3514 | * Got a job URI; parse it to get the job ID... | |
3515 | */ | |
ef416fc2 | 3516 | |
b423cd4c | 3517 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
3518 | sizeof(method), username, sizeof(username), host, | |
3519 | sizeof(host), &port, resource, sizeof(resource)); | |
f7deaa1a | 3520 | |
b423cd4c | 3521 | if (strncmp(resource, "/jobs/", 6)) |
3522 | { | |
3523 | /* | |
3524 | * Not a valid URI! | |
3525 | */ | |
ef416fc2 | 3526 | |
b423cd4c | 3527 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad job-uri attribute \"%s\"!"), |
3528 | uri->values[0].string.text); | |
3529 | return; | |
3530 | } | |
ef416fc2 | 3531 | |
b423cd4c | 3532 | jobid = atoi(resource + 6); |
3533 | } | |
ef416fc2 | 3534 | |
b423cd4c | 3535 | /* |
3536 | * See if the job exists... | |
3537 | */ | |
ef416fc2 | 3538 | |
b423cd4c | 3539 | if ((job = cupsdFindJob(jobid)) == NULL) |
3540 | { | |
3541 | /* | |
3542 | * Nope - return a "not found" error... | |
3543 | */ | |
ef416fc2 | 3544 | |
b423cd4c | 3545 | send_ipp_status(con, IPP_NOT_FOUND, |
3546 | _("Job #%d does not exist!"), jobid); | |
ef416fc2 | 3547 | return; |
b423cd4c | 3548 | } |
ef416fc2 | 3549 | |
b423cd4c | 3550 | /* |
3551 | * See if the job has been completed... | |
3552 | */ | |
3553 | ||
3554 | if (job->state_value != IPP_JOB_HELD) | |
ef416fc2 | 3555 | { |
3556 | /* | |
b423cd4c | 3557 | * Return a "not-possible" error... |
ef416fc2 | 3558 | */ |
3559 | ||
b423cd4c | 3560 | send_ipp_status(con, IPP_NOT_POSSIBLE, |
3561 | _("Job #%d is not held for authentication!"), | |
3562 | jobid); | |
3563 | return; | |
3564 | } | |
ef416fc2 | 3565 | |
b423cd4c | 3566 | /* |
3567 | * See if we have already authenticated... | |
3568 | */ | |
3569 | ||
f7deaa1a | 3570 | auth_info = ippFindAttribute(con->request, "auth-info", IPP_TAG_TEXT); |
3571 | ||
3572 | if (!con->username[0] && !auth_info) | |
b423cd4c | 3573 | { |
db1f069b MS |
3574 | cupsd_printer_t *printer; /* Job destination */ |
3575 | ||
3576 | ||
3577 | /* | |
3578 | * No auth data. If we need to authenticate via Kerberos, send a | |
3579 | * HTTP auth challenge, otherwise just return an IPP error... | |
3580 | */ | |
3581 | ||
3582 | printer = cupsdFindDest(job->dest); | |
3583 | ||
3584 | if (printer && printer->num_auth_info_required > 0 && | |
3585 | !strcmp(printer->auth_info_required[0], "negotiate")) | |
3586 | send_http_error(con, HTTP_UNAUTHORIZED, printer); | |
3587 | else | |
3588 | send_ipp_status(con, IPP_NOT_AUTHORIZED, | |
3589 | _("No authentication information provided!")); | |
b423cd4c | 3590 | return; |
3591 | } | |
3592 | ||
3593 | /* | |
3594 | * See if the job is owned by the requesting user... | |
3595 | */ | |
3596 | ||
3597 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
3598 | { | |
2fb76298 | 3599 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
b423cd4c | 3600 | return; |
3601 | } | |
3602 | ||
3603 | /* | |
3604 | * Save the authentication information for this job... | |
3605 | */ | |
3606 | ||
f7deaa1a | 3607 | save_auth_info(con, job, auth_info); |
b423cd4c | 3608 | |
3609 | /* | |
3610 | * Reset the job-hold-until value to "no-hold"... | |
3611 | */ | |
3612 | ||
3613 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", | |
3614 | IPP_TAG_KEYWORD)) == NULL) | |
3615 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); | |
3616 | ||
3617 | if (attr) | |
3618 | { | |
3619 | attr->value_tag = IPP_TAG_KEYWORD; | |
3620 | cupsdSetString(&(attr->values[0].string.text), "no-hold"); | |
ef416fc2 | 3621 | } |
b423cd4c | 3622 | |
3623 | /* | |
3624 | * Release the job and return... | |
3625 | */ | |
3626 | ||
3627 | cupsdReleaseJob(job); | |
3628 | ||
09a101d6 | 3629 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Authenticated by \"%s\".", jobid, |
b423cd4c | 3630 | con->username); |
ef416fc2 | 3631 | } |
3632 | ||
3633 | ||
3634 | /* | |
b423cd4c | 3635 | * 'cancel_all_jobs()' - Cancel all print jobs. |
ef416fc2 | 3636 | */ |
3637 | ||
b423cd4c | 3638 | static void |
3639 | cancel_all_jobs(cupsd_client_t *con, /* I - Client connection */ | |
3640 | ipp_attribute_t *uri) /* I - Job or Printer URI */ | |
ef416fc2 | 3641 | { |
b423cd4c | 3642 | http_status_t status; /* Policy status */ |
b423cd4c | 3643 | cups_ptype_t dtype; /* Destination type */ |
f7deaa1a | 3644 | char scheme[HTTP_MAX_URI], /* Scheme portion of URI */ |
b423cd4c | 3645 | userpass[HTTP_MAX_URI], /* Username portion of URI */ |
f7deaa1a | 3646 | hostname[HTTP_MAX_URI], /* Host portion of URI */ |
b423cd4c | 3647 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ |
3648 | int port; /* Port portion of URI */ | |
3649 | ipp_attribute_t *attr; /* Attribute in request */ | |
3650 | const char *username; /* Username */ | |
3651 | int purge; /* Purge? */ | |
3652 | cupsd_printer_t *printer; /* Printer */ | |
ef416fc2 | 3653 | |
3654 | ||
b423cd4c | 3655 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_all_jobs(%p[%d], %s)", con, |
3656 | con->http.fd, uri->values[0].string.text); | |
ef416fc2 | 3657 | |
3658 | /* | |
b423cd4c | 3659 | * See if we have a printer URI... |
ef416fc2 | 3660 | */ |
3661 | ||
b423cd4c | 3662 | if (strcmp(uri->name, "printer-uri")) |
3663 | { | |
3664 | send_ipp_status(con, IPP_BAD_REQUEST, | |
3665 | _("The printer-uri attribute is required!")); | |
3666 | return; | |
3667 | } | |
ef416fc2 | 3668 | |
3669 | /* | |
b423cd4c | 3670 | * Get the username (if any) for the jobs we want to cancel (only if |
3671 | * "my-jobs" is specified... | |
ef416fc2 | 3672 | */ |
3673 | ||
b423cd4c | 3674 | if ((attr = ippFindAttribute(con->request, "my-jobs", |
3675 | IPP_TAG_BOOLEAN)) != NULL && | |
3676 | attr->values[0].boolean) | |
ef416fc2 | 3677 | { |
b423cd4c | 3678 | if ((attr = ippFindAttribute(con->request, "requesting-user-name", |
3679 | IPP_TAG_NAME)) != NULL) | |
3680 | username = attr->values[0].string.text; | |
3681 | else | |
3682 | { | |
3683 | send_ipp_status(con, IPP_BAD_REQUEST, | |
3684 | _("Missing requesting-user-name attribute!")); | |
3685 | return; | |
3686 | } | |
ef416fc2 | 3687 | } |
b423cd4c | 3688 | else |
3689 | username = NULL; | |
ef416fc2 | 3690 | |
b423cd4c | 3691 | /* |
3692 | * Look for the "purge-jobs" attribute... | |
3693 | */ | |
3694 | ||
3695 | if ((attr = ippFindAttribute(con->request, "purge-jobs", | |
3696 | IPP_TAG_BOOLEAN)) != NULL) | |
3697 | purge = attr->values[0].boolean; | |
3698 | else | |
3699 | purge = 1; | |
ef416fc2 | 3700 | |
3701 | /* | |
b423cd4c | 3702 | * And if the destination is valid... |
ef416fc2 | 3703 | */ |
3704 | ||
f7deaa1a | 3705 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 3706 | { |
3707 | /* | |
b423cd4c | 3708 | * Bad URI? |
ef416fc2 | 3709 | */ |
3710 | ||
f7deaa1a | 3711 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, |
3712 | scheme, sizeof(scheme), userpass, sizeof(userpass), | |
3713 | hostname, sizeof(hostname), &port, | |
3714 | resource, sizeof(resource)); | |
3715 | ||
b423cd4c | 3716 | if ((!strncmp(resource, "/printers/", 10) && resource[10]) || |
3717 | (!strncmp(resource, "/classes/", 9) && resource[9])) | |
3718 | { | |
3719 | send_ipp_status(con, IPP_NOT_FOUND, | |
3720 | _("The printer or class was not found.")); | |
3721 | return; | |
3722 | } | |
ef416fc2 | 3723 | |
b423cd4c | 3724 | /* |
3725 | * Check policy... | |
3726 | */ | |
3727 | ||
3728 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
3729 | { | |
f899b121 | 3730 | send_http_error(con, status, NULL); |
b423cd4c | 3731 | return; |
3732 | } | |
ef416fc2 | 3733 | |
ef416fc2 | 3734 | /* |
b423cd4c | 3735 | * Cancel all jobs on all printers... |
ef416fc2 | 3736 | */ |
3737 | ||
b423cd4c | 3738 | cupsdCancelJobs(NULL, username, purge); |
ef416fc2 | 3739 | |
b423cd4c | 3740 | cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".", |
d09495fa | 3741 | purge ? "purged" : "canceled", get_username(con)); |
ef416fc2 | 3742 | } |
b423cd4c | 3743 | else |
ef416fc2 | 3744 | { |
3745 | /* | |
b423cd4c | 3746 | * Check policy... |
ef416fc2 | 3747 | */ |
3748 | ||
f7deaa1a | 3749 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, |
3750 | NULL)) != HTTP_OK) | |
b423cd4c | 3751 | { |
f899b121 | 3752 | send_http_error(con, status, printer); |
b423cd4c | 3753 | return; |
3754 | } | |
ef416fc2 | 3755 | |
b423cd4c | 3756 | /* |
3757 | * Cancel all of the jobs on the named printer... | |
3758 | */ | |
3759 | ||
f7deaa1a | 3760 | cupsdCancelJobs(printer->name, username, purge); |
b423cd4c | 3761 | |
3762 | cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".", | |
f7deaa1a | 3763 | printer->name, purge ? "purged" : "canceled", |
3764 | get_username(con)); | |
ef416fc2 | 3765 | } |
3766 | ||
b423cd4c | 3767 | con->response->request.status.status_code = IPP_OK; |
3768 | } | |
3769 | ||
3770 | ||
3771 | /* | |
3772 | * 'cancel_job()' - Cancel a print job. | |
3773 | */ | |
3774 | ||
3775 | static void | |
3776 | cancel_job(cupsd_client_t *con, /* I - Client connection */ | |
3777 | ipp_attribute_t *uri) /* I - Job or Printer URI */ | |
3778 | { | |
3779 | ipp_attribute_t *attr; /* Current attribute */ | |
3780 | int jobid; /* Job ID */ | |
f7deaa1a | 3781 | char scheme[HTTP_MAX_URI], /* Scheme portion of URI */ |
b423cd4c | 3782 | username[HTTP_MAX_URI], /* Username portion of URI */ |
3783 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
3784 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
3785 | int port; /* Port portion of URI */ | |
3786 | cupsd_job_t *job; /* Job information */ | |
bc44d920 | 3787 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
b423cd4c | 3788 | cupsd_printer_t *printer; /* Printer data */ |
0a682745 | 3789 | int purge; /* Purge the job? */ |
b423cd4c | 3790 | |
3791 | ||
3792 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con, | |
3793 | con->http.fd, uri->values[0].string.text); | |
3794 | ||
ef416fc2 | 3795 | /* |
b423cd4c | 3796 | * See if we have a job URI or a printer URI... |
ef416fc2 | 3797 | */ |
3798 | ||
b423cd4c | 3799 | if (!strcmp(uri->name, "printer-uri")) |
3800 | { | |
3801 | /* | |
3802 | * Got a printer URI; see if we also have a job-id attribute... | |
3803 | */ | |
3804 | ||
3805 | if ((attr = ippFindAttribute(con->request, "job-id", | |
3806 | IPP_TAG_INTEGER)) == NULL) | |
3807 | { | |
3808 | send_ipp_status(con, IPP_BAD_REQUEST, | |
3809 | _("Got a printer-uri attribute but no job-id!")); | |
3810 | return; | |
3811 | } | |
3812 | ||
3813 | if ((jobid = attr->values[0].integer) == 0) | |
ef416fc2 | 3814 | { |
3815 | /* | |
b423cd4c | 3816 | * Find the current job on the specified printer... |
ef416fc2 | 3817 | */ |
3818 | ||
f7deaa1a | 3819 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 3820 | { |
3821 | /* | |
b423cd4c | 3822 | * Bad URI... |
ef416fc2 | 3823 | */ |
3824 | ||
b423cd4c | 3825 | send_ipp_status(con, IPP_NOT_FOUND, |
3826 | _("The printer or class was not found.")); | |
3827 | return; | |
ef416fc2 | 3828 | } |
3829 | ||
3830 | /* | |
b423cd4c | 3831 | * See if the printer is currently printing a job... |
ef416fc2 | 3832 | */ |
3833 | ||
b423cd4c | 3834 | if (printer->job) |
3835 | jobid = ((cupsd_job_t *)printer->job)->id; | |
ef416fc2 | 3836 | else |
ef416fc2 | 3837 | { |
3838 | /* | |
b423cd4c | 3839 | * No, see if there are any pending jobs... |
ef416fc2 | 3840 | */ |
f7deaa1a | 3841 | |
b423cd4c | 3842 | for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs); |
3843 | job; | |
3844 | job = (cupsd_job_t *)cupsArrayNext(ActiveJobs)) | |
3845 | if (job->state_value <= IPP_JOB_PROCESSING && | |
f7deaa1a | 3846 | !strcasecmp(job->dest, printer->name)) |
b423cd4c | 3847 | break; |
ef416fc2 | 3848 | |
b423cd4c | 3849 | if (job) |
3850 | jobid = job->id; | |
3851 | else | |
ef416fc2 | 3852 | { |
355e94dc MS |
3853 | for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs); |
3854 | job; | |
3855 | job = (cupsd_job_t *)cupsArrayNext(ActiveJobs)) | |
3856 | if (job->state_value == IPP_JOB_STOPPED && | |
3857 | !strcasecmp(job->dest, printer->name)) | |
3858 | break; | |
3859 | ||
3860 | if (job) | |
3861 | jobid = job->id; | |
3862 | else | |
3863 | { | |
3864 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("No active jobs on %s!"), | |
3865 | printer->name); | |
3866 | return; | |
3867 | } | |
b423cd4c | 3868 | } |
3869 | } | |
3870 | } | |
3871 | } | |
3872 | else | |
3873 | { | |
3874 | /* | |
3875 | * Got a job URI; parse it to get the job ID... | |
3876 | */ | |
ef416fc2 | 3877 | |
f7deaa1a | 3878 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
3879 | sizeof(scheme), username, sizeof(username), host, | |
b423cd4c | 3880 | sizeof(host), &port, resource, sizeof(resource)); |
f7deaa1a | 3881 | |
b423cd4c | 3882 | if (strncmp(resource, "/jobs/", 6)) |
3883 | { | |
3884 | /* | |
3885 | * Not a valid URI! | |
3886 | */ | |
ef416fc2 | 3887 | |
b423cd4c | 3888 | send_ipp_status(con, IPP_BAD_REQUEST, |
3889 | _("Bad job-uri attribute \"%s\"!"), | |
3890 | uri->values[0].string.text); | |
3891 | return; | |
3892 | } | |
3893 | ||
3894 | jobid = atoi(resource + 6); | |
3895 | } | |
3896 | ||
0a682745 MS |
3897 | /* |
3898 | * Look for the "purge-job" attribute... | |
3899 | */ | |
3900 | ||
3901 | if ((attr = ippFindAttribute(con->request, "purge-job", | |
3902 | IPP_TAG_BOOLEAN)) != NULL) | |
3903 | purge = attr->values[0].boolean; | |
3904 | else | |
3905 | purge = 0; | |
3906 | ||
b423cd4c | 3907 | /* |
3908 | * See if the job exists... | |
3909 | */ | |
3910 | ||
3911 | if ((job = cupsdFindJob(jobid)) == NULL) | |
3912 | { | |
3913 | /* | |
3914 | * Nope - return a "not found" error... | |
3915 | */ | |
3916 | ||
3917 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
3918 | return; | |
3919 | } | |
3920 | ||
3921 | /* | |
3922 | * See if the job is owned by the requesting user... | |
3923 | */ | |
3924 | ||
3925 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
3926 | { | |
2fb76298 | 3927 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
b423cd4c | 3928 | return; |
3929 | } | |
3930 | ||
3931 | /* | |
d09495fa | 3932 | * See if the job is already completed, canceled, or aborted; if so, |
b423cd4c | 3933 | * we can't cancel... |
3934 | */ | |
3935 | ||
0a682745 | 3936 | if (job->state_value >= IPP_JOB_CANCELED && !purge) |
b423cd4c | 3937 | { |
e1d6a774 | 3938 | switch (job->state_value) |
3939 | { | |
d09495fa | 3940 | case IPP_JOB_CANCELED : |
e1d6a774 | 3941 | send_ipp_status(con, IPP_NOT_POSSIBLE, |
d09495fa | 3942 | _("Job #%d is already canceled - can\'t cancel."), |
e1d6a774 | 3943 | jobid); |
3944 | break; | |
3945 | ||
3946 | case IPP_JOB_ABORTED : | |
3947 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
3948 | _("Job #%d is already aborted - can\'t cancel."), | |
3949 | jobid); | |
3950 | break; | |
3951 | ||
3952 | default : | |
3953 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
3954 | _("Job #%d is already completed - can\'t cancel."), | |
3955 | jobid); | |
3956 | break; | |
3957 | } | |
3958 | ||
b423cd4c | 3959 | return; |
3960 | } | |
ef416fc2 | 3961 | |
b423cd4c | 3962 | /* |
3963 | * Cancel the job and return... | |
3964 | */ | |
ef416fc2 | 3965 | |
0a682745 | 3966 | cupsdCancelJob(job, purge, IPP_JOB_CANCELED); |
b423cd4c | 3967 | cupsdCheckJobs(); |
ef416fc2 | 3968 | |
0a682745 MS |
3969 | if (purge) |
3970 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Purged by \"%s\".", jobid, | |
3971 | username); | |
3972 | else | |
3973 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Canceled by \"%s\".", jobid, | |
3974 | username); | |
ef416fc2 | 3975 | |
b423cd4c | 3976 | con->response->request.status.status_code = IPP_OK; |
3977 | } | |
ef416fc2 | 3978 | |
ef416fc2 | 3979 | |
b423cd4c | 3980 | /* |
3981 | * 'cancel_subscription()' - Cancel a subscription. | |
3982 | */ | |
ef416fc2 | 3983 | |
b423cd4c | 3984 | static void |
3985 | cancel_subscription( | |
3986 | cupsd_client_t *con, /* I - Client connection */ | |
3987 | int sub_id) /* I - Subscription ID */ | |
3988 | { | |
3989 | http_status_t status; /* Policy status */ | |
3990 | cupsd_subscription_t *sub; /* Subscription */ | |
ef416fc2 | 3991 | |
ef416fc2 | 3992 | |
b423cd4c | 3993 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
3994 | "cancel_subscription(con=%p[%d], sub_id=%d)", | |
3995 | con, con->http.fd, sub_id); | |
ef416fc2 | 3996 | |
b423cd4c | 3997 | /* |
3998 | * Is the subscription ID valid? | |
3999 | */ | |
ef416fc2 | 4000 | |
b423cd4c | 4001 | if ((sub = cupsdFindSubscription(sub_id)) == NULL) |
4002 | { | |
4003 | /* | |
4004 | * Bad subscription ID... | |
4005 | */ | |
ef416fc2 | 4006 | |
b423cd4c | 4007 | send_ipp_status(con, IPP_NOT_FOUND, |
4008 | _("notify-subscription-id %d no good!"), sub_id); | |
4009 | return; | |
4010 | } | |
ef416fc2 | 4011 | |
b423cd4c | 4012 | /* |
4013 | * Check policy... | |
4014 | */ | |
ef416fc2 | 4015 | |
b423cd4c | 4016 | if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr : |
4017 | DefaultPolicyPtr, | |
4018 | con, sub->owner)) != HTTP_OK) | |
4019 | { | |
f899b121 | 4020 | send_http_error(con, status, sub->dest); |
b423cd4c | 4021 | return; |
4022 | } | |
ef416fc2 | 4023 | |
b423cd4c | 4024 | /* |
4025 | * Cancel the subscription... | |
4026 | */ | |
ef416fc2 | 4027 | |
b423cd4c | 4028 | cupsdDeleteSubscription(sub, 1); |
ef416fc2 | 4029 | |
b423cd4c | 4030 | con->response->request.status.status_code = IPP_OK; |
ef416fc2 | 4031 | } |
4032 | ||
4033 | ||
3dfe78b3 MS |
4034 | /* |
4035 | * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI. | |
4036 | */ | |
4037 | ||
4038 | static int /* O - 1 if OK, 0 if not */ | |
4039 | check_rss_recipient( | |
4040 | const char *recipient) /* I - Recipient URI */ | |
4041 | { | |
4042 | cupsd_subscription_t *sub; /* Current subscription */ | |
4043 | ||
4044 | ||
4045 | for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions); | |
4046 | sub; | |
4047 | sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions)) | |
4048 | if (sub->recipient) | |
4049 | { | |
4050 | /* | |
4051 | * Compare the URIs up to the first ?... | |
4052 | */ | |
4053 | ||
4054 | const char *r1, *r2; | |
4055 | ||
4056 | for (r1 = recipient, r2 = sub->recipient; | |
4057 | *r1 == *r2 && *r1 && *r1 != '?' && *r2 && *r2 != '?'; | |
4058 | r1 ++, r2 ++); | |
4059 | ||
4060 | if (*r1 == *r2) | |
4061 | return (0); | |
4062 | } | |
4063 | ||
4064 | return (1); | |
4065 | } | |
4066 | ||
4067 | ||
ef416fc2 | 4068 | /* |
b423cd4c | 4069 | * 'check_quotas()' - Check quotas for a printer and user. |
ef416fc2 | 4070 | */ |
4071 | ||
b423cd4c | 4072 | static int /* O - 1 if OK, 0 if not */ |
4073 | check_quotas(cupsd_client_t *con, /* I - Client connection */ | |
4074 | cupsd_printer_t *p) /* I - Printer or class */ | |
ef416fc2 | 4075 | { |
b423cd4c | 4076 | int i; /* Looping var */ |
4077 | char username[33]; /* Username */ | |
4078 | cupsd_quota_t *q; /* Quota data */ | |
7594b224 | 4079 | #ifdef HAVE_MBR_UID_TO_UUID |
4080 | /* | |
4081 | * Use Apple membership APIs which require that all names represent | |
4082 | * valid user account or group records accessible by the server. | |
4083 | */ | |
4084 | ||
4085 | uuid_t usr_uuid; /* UUID for job requesting user */ | |
4086 | uuid_t usr2_uuid; /* UUID for ACL user name entry */ | |
4087 | uuid_t grp_uuid; /* UUID for ACL group name entry */ | |
4088 | int mbr_err; /* Error from membership function */ | |
4089 | int is_member; /* Is this user a member? */ | |
4090 | #else | |
4091 | /* | |
4092 | * Use standard POSIX APIs for checking users and groups... | |
4093 | */ | |
4094 | ||
b423cd4c | 4095 | struct passwd *pw; /* User password data */ |
7594b224 | 4096 | #endif /* HAVE_MBR_UID_TO_UUID */ |
ef416fc2 | 4097 | |
4098 | ||
b423cd4c | 4099 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])", |
4100 | con, con->http.fd, p, p->name); | |
ef416fc2 | 4101 | |
b423cd4c | 4102 | /* |
4103 | * Figure out who is printing... | |
4104 | */ | |
4105 | ||
4106 | strlcpy(username, get_username(con), sizeof(username)); | |
4107 | ||
4108 | /* | |
4109 | * Check global active job limits for printers and users... | |
4110 | */ | |
4111 | ||
4112 | if (MaxJobsPerPrinter) | |
ef416fc2 | 4113 | { |
b423cd4c | 4114 | /* |
4115 | * Check if there are too many pending jobs on this printer... | |
4116 | */ | |
4117 | ||
4118 | if (cupsdGetPrinterJobCount(p->name) >= MaxJobsPerPrinter) | |
4119 | { | |
4120 | cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for printer \"%s\"...", | |
4121 | p->name); | |
4122 | return (0); | |
4123 | } | |
4124 | } | |
4125 | ||
4126 | if (MaxJobsPerUser) | |
4127 | { | |
4128 | /* | |
4129 | * Check if there are too many pending jobs for this user... | |
4130 | */ | |
4131 | ||
4132 | if (cupsdGetUserJobCount(username) >= MaxJobsPerUser) | |
4133 | { | |
4134 | cupsdLogMessage(CUPSD_LOG_INFO, "Too many jobs for user \"%s\"...", | |
4135 | username); | |
4136 | return (0); | |
4137 | } | |
ef416fc2 | 4138 | } |
4139 | ||
4140 | /* | |
b423cd4c | 4141 | * Check against users... |
ef416fc2 | 4142 | */ |
4143 | ||
b423cd4c | 4144 | if (p->num_users == 0 && p->k_limit == 0 && p->page_limit == 0) |
4145 | return (1); | |
4146 | ||
4147 | if (p->num_users) | |
4148 | { | |
7594b224 | 4149 | #ifdef HAVE_MBR_UID_TO_UUID |
4150 | /* | |
4151 | * Get UUID for job requesting user... | |
4152 | */ | |
4153 | ||
4154 | if (mbr_user_name_to_uuid((char *)username, usr_uuid)) | |
4155 | { | |
4156 | /* | |
4157 | * Unknown user... | |
4158 | */ | |
4159 | ||
4160 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
4161 | "check_quotas: UUID lookup failed for user \"%s\"", | |
4162 | username); | |
4163 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4164 | "Denying user \"%s\" access to printer \"%s\" " | |
4165 | "(unknown user)...", | |
4166 | username, p->name); | |
4167 | return (0); | |
4168 | } | |
4169 | #else | |
4170 | /* | |
4171 | * Get UID and GID of requesting user... | |
4172 | */ | |
4173 | ||
b423cd4c | 4174 | pw = getpwnam(username); |
4175 | endpwent(); | |
7594b224 | 4176 | #endif /* HAVE_MBR_UID_TO_UUID */ |
b423cd4c | 4177 | |
4178 | for (i = 0; i < p->num_users; i ++) | |
4179 | if (p->users[i][0] == '@') | |
4180 | { | |
4181 | /* | |
4182 | * Check group membership... | |
4183 | */ | |
4184 | ||
7594b224 | 4185 | #ifdef HAVE_MBR_UID_TO_UUID |
c9fc04c6 MS |
4186 | if (p->users[i][1] == '#') |
4187 | { | |
4188 | if (uuid_parse((char *)p->users[i] + 2, grp_uuid)) | |
4189 | uuid_clear(grp_uuid); | |
4190 | } | |
4191 | else if ((mbr_err = mbr_group_name_to_uuid((char *)p->users[i] + 1, | |
4192 | grp_uuid)) != 0) | |
7594b224 | 4193 | { |
4194 | /* | |
4195 | * Invalid ACL entries are ignored for matching; just record a | |
4196 | * warning in the log... | |
4197 | */ | |
4198 | ||
4199 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
4200 | "check_quotas: UUID lookup failed for ACL entry " | |
4201 | "\"%s\" (err=%d)", p->users[i], mbr_err); | |
4202 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4203 | "Access control entry \"%s\" not a valid group name; " | |
4204 | "entry ignored", p->users[i]); | |
4205 | } | |
7594b224 | 4206 | |
c9fc04c6 MS |
4207 | if ((mbr_err = mbr_check_membership(usr_uuid, grp_uuid, |
4208 | &is_member)) != 0) | |
4209 | { | |
4210 | /* | |
4211 | * At this point, there should be no errors, but check anyways... | |
7594b224 | 4212 | */ |
4213 | ||
c9fc04c6 MS |
4214 | cupsdLogMessage(CUPSD_LOG_DEBUG, |
4215 | "check_quotas: group \"%s\" membership check " | |
4216 | "failed (err=%d)", p->users[i] + 1, mbr_err); | |
4217 | is_member = 0; | |
7594b224 | 4218 | } |
c9fc04c6 MS |
4219 | |
4220 | /* | |
4221 | * Stop if we found a match... | |
4222 | */ | |
4223 | ||
4224 | if (is_member) | |
4225 | break; | |
4226 | ||
7594b224 | 4227 | #else |
b423cd4c | 4228 | if (cupsdCheckGroup(username, pw, p->users[i] + 1)) |
4229 | break; | |
7594b224 | 4230 | #endif /* HAVE_MBR_UID_TO_UUID */ |
4231 | } | |
4232 | #ifdef HAVE_MBR_UID_TO_UUID | |
4233 | else | |
4234 | { | |
c9fc04c6 MS |
4235 | if (p->users[i][0] == '#') |
4236 | { | |
4237 | if (uuid_parse((char *)p->users[i] + 1, usr2_uuid)) | |
4238 | uuid_clear(usr2_uuid); | |
4239 | } | |
4240 | else if ((mbr_err = mbr_user_name_to_uuid((char *)p->users[i], | |
4241 | usr2_uuid)) != 0) | |
7594b224 | 4242 | { |
4243 | /* | |
4244 | * Invalid ACL entries are ignored for matching; just record a | |
4245 | * warning in the log... | |
4246 | */ | |
4247 | ||
4248 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
4249 | "check_quotas: UUID lookup failed for ACL entry " | |
4250 | "\"%s\" (err=%d)", p->users[i], mbr_err); | |
4251 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4252 | "Access control entry \"%s\" not a valid user name; " | |
4253 | "entry ignored", p->users[i]); | |
4254 | } | |
7594b224 | 4255 | |
c9fc04c6 MS |
4256 | if ((mbr_err = mbr_check_membership(usr_uuid, usr2_uuid, |
4257 | &is_member)) != 0) | |
4258 | { | |
4259 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
4260 | "check_quotas: User \"%s\" identity check failed " | |
4261 | "(err=%d)", p->users[i], mbr_err); | |
4262 | is_member = 0; | |
7594b224 | 4263 | } |
c9fc04c6 MS |
4264 | |
4265 | if (is_member) | |
4266 | break; | |
b423cd4c | 4267 | } |
7594b224 | 4268 | #else |
b423cd4c | 4269 | else if (!strcasecmp(username, p->users[i])) |
4270 | break; | |
7594b224 | 4271 | #endif /* HAVE_MBR_UID_TO_UUID */ |
b423cd4c | 4272 | |
4273 | if ((i < p->num_users) == p->deny_users) | |
ef416fc2 | 4274 | { |
b423cd4c | 4275 | cupsdLogMessage(CUPSD_LOG_INFO, |
4276 | "Denying user \"%s\" access to printer \"%s\"...", | |
4277 | username, p->name); | |
4278 | return (0); | |
ef416fc2 | 4279 | } |
b423cd4c | 4280 | } |
ef416fc2 | 4281 | |
4282 | /* | |
b423cd4c | 4283 | * Check quotas... |
ef416fc2 | 4284 | */ |
4285 | ||
7594b224 | 4286 | #ifdef __APPLE__ |
3d8365b8 | 4287 | if (AppleQuotas && (q = cupsdFindQuota(p, username)) != NULL) |
7594b224 | 4288 | { |
4289 | /* | |
4290 | * TODO: Define these special page count values as constants! | |
4291 | */ | |
4292 | ||
4293 | if (q->page_count == -4) /* special case: unlimited user */ | |
4294 | { | |
4295 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4296 | "User \"%s\" request approved for printer %s (%s): " | |
4297 | "unlimited quota.", | |
4298 | username, p->name, p->info); | |
4299 | q->page_count = 0; /* allow user to print */ | |
4300 | return (1); | |
4301 | } | |
4302 | else if (q->page_count == -3) /* quota exceeded */ | |
4303 | { | |
4304 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4305 | "User \"%s\" request denied for printer %s (%s): " | |
4306 | "quota limit exceeded.", | |
4307 | username, p->name, p->info); | |
4308 | q->page_count = 2; /* force quota exceeded failure */ | |
bc44d920 | 4309 | return (-1); |
7594b224 | 4310 | } |
4311 | else if (q->page_count == -2) /* quota disabled for user */ | |
4312 | { | |
4313 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4314 | "User \"%s\" request denied for printer %s (%s): " | |
4315 | "printing disabled for user.", | |
4316 | username, p->name, p->info); | |
4317 | q->page_count = 2; /* force quota exceeded failure */ | |
bc44d920 | 4318 | return (-1); |
7594b224 | 4319 | } |
4320 | else if (q->page_count == -1) /* quota access error */ | |
4321 | { | |
4322 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4323 | "User \"%s\" request denied for printer %s (%s): " | |
4324 | "unable to determine quota limit.", | |
4325 | username, p->name, p->info); | |
4326 | q->page_count = 2; /* force quota exceeded failure */ | |
bc44d920 | 4327 | return (-1); |
7594b224 | 4328 | } |
4329 | else if (q->page_count < 0) /* user not found or other error */ | |
4330 | { | |
4331 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4332 | "User \"%s\" request denied for printer %s (%s): " | |
4333 | "user disabled / missing quota.", | |
4334 | username, p->name, p->info); | |
4335 | q->page_count = 2; /* force quota exceeded failure */ | |
bc44d920 | 4336 | return (-1); |
7594b224 | 4337 | } |
4338 | else /* page within user limits */ | |
4339 | { | |
4340 | q->page_count = 0; /* allow user to print */ | |
4341 | return (1); | |
4342 | } | |
4343 | } | |
4344 | else | |
4345 | #endif /* __APPLE__ */ | |
b423cd4c | 4346 | if (p->k_limit || p->page_limit) |
4347 | { | |
4348 | if ((q = cupsdUpdateQuota(p, username, 0, 0)) == NULL) | |
4349 | { | |
4350 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
4351 | "Unable to allocate quota data for user \"%s\"!", | |
4352 | username); | |
bc44d920 | 4353 | return (-1); |
b423cd4c | 4354 | } |
ef416fc2 | 4355 | |
b423cd4c | 4356 | if ((q->k_count >= p->k_limit && p->k_limit) || |
4357 | (q->page_count >= p->page_limit && p->page_limit)) | |
4358 | { | |
4359 | cupsdLogMessage(CUPSD_LOG_INFO, "User \"%s\" is over the quota limit...", | |
4360 | username); | |
bc44d920 | 4361 | return (-1); |
b423cd4c | 4362 | } |
4363 | } | |
4364 | ||
4365 | /* | |
4366 | * If we have gotten this far, we're done! | |
4367 | */ | |
4368 | ||
4369 | return (1); | |
ef416fc2 | 4370 | } |
4371 | ||
4372 | ||
4373 | /* | |
b423cd4c | 4374 | * 'copy_attribute()' - Copy a single attribute. |
ef416fc2 | 4375 | */ |
4376 | ||
b423cd4c | 4377 | static ipp_attribute_t * /* O - New attribute */ |
4378 | copy_attribute( | |
4379 | ipp_t *to, /* O - Destination request/response */ | |
4380 | ipp_attribute_t *attr, /* I - Attribute to copy */ | |
4381 | int quickcopy) /* I - Do a quick copy? */ | |
ef416fc2 | 4382 | { |
b423cd4c | 4383 | int i; /* Looping var */ |
4384 | ipp_attribute_t *toattr; /* Destination attribute */ | |
ef416fc2 | 4385 | |
4386 | ||
4387 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
b423cd4c | 4388 | "copy_attribute(%p, %p[%s,%x,%x])", to, attr, |
4389 | attr->name ? attr->name : "(null)", attr->group_tag, | |
4390 | attr->value_tag); | |
ef416fc2 | 4391 | |
b423cd4c | 4392 | switch (attr->value_tag & ~IPP_TAG_COPY) |
4393 | { | |
4394 | case IPP_TAG_ZERO : | |
4395 | toattr = ippAddSeparator(to); | |
4396 | break; | |
ef416fc2 | 4397 | |
b423cd4c | 4398 | case IPP_TAG_INTEGER : |
4399 | case IPP_TAG_ENUM : | |
4400 | toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag, | |
4401 | attr->name, attr->num_values, NULL); | |
ef416fc2 | 4402 | |
b423cd4c | 4403 | for (i = 0; i < attr->num_values; i ++) |
4404 | toattr->values[i].integer = attr->values[i].integer; | |
4405 | break; | |
ef416fc2 | 4406 | |
b423cd4c | 4407 | case IPP_TAG_BOOLEAN : |
4408 | toattr = ippAddBooleans(to, attr->group_tag, attr->name, | |
4409 | attr->num_values, NULL); | |
ef416fc2 | 4410 | |
b423cd4c | 4411 | for (i = 0; i < attr->num_values; i ++) |
4412 | toattr->values[i].boolean = attr->values[i].boolean; | |
4413 | break; | |
ef416fc2 | 4414 | |
b423cd4c | 4415 | case IPP_TAG_STRING : |
4416 | case IPP_TAG_TEXT : | |
4417 | case IPP_TAG_NAME : | |
4418 | case IPP_TAG_KEYWORD : | |
4419 | case IPP_TAG_URI : | |
4420 | case IPP_TAG_URISCHEME : | |
4421 | case IPP_TAG_CHARSET : | |
4422 | case IPP_TAG_LANGUAGE : | |
4423 | case IPP_TAG_MIMETYPE : | |
4424 | toattr = ippAddStrings(to, attr->group_tag, | |
4425 | (ipp_tag_t)(attr->value_tag | quickcopy), | |
4426 | attr->name, attr->num_values, NULL, NULL); | |
ef416fc2 | 4427 | |
b423cd4c | 4428 | if (quickcopy) |
4429 | { | |
4430 | for (i = 0; i < attr->num_values; i ++) | |
4431 | toattr->values[i].string.text = attr->values[i].string.text; | |
4432 | } | |
4433 | else | |
4434 | { | |
4435 | for (i = 0; i < attr->num_values; i ++) | |
bc44d920 | 4436 | toattr->values[i].string.text = |
4437 | _cupsStrAlloc(attr->values[i].string.text); | |
b423cd4c | 4438 | } |
4439 | break; | |
ef416fc2 | 4440 | |
b423cd4c | 4441 | case IPP_TAG_DATE : |
4442 | toattr = ippAddDate(to, attr->group_tag, attr->name, | |
4443 | attr->values[0].date); | |
4444 | break; | |
ef416fc2 | 4445 | |
b423cd4c | 4446 | case IPP_TAG_RESOLUTION : |
4447 | toattr = ippAddResolutions(to, attr->group_tag, attr->name, | |
4448 | attr->num_values, IPP_RES_PER_INCH, | |
4449 | NULL, NULL); | |
ef416fc2 | 4450 | |
b423cd4c | 4451 | for (i = 0; i < attr->num_values; i ++) |
4452 | { | |
4453 | toattr->values[i].resolution.xres = attr->values[i].resolution.xres; | |
4454 | toattr->values[i].resolution.yres = attr->values[i].resolution.yres; | |
4455 | toattr->values[i].resolution.units = attr->values[i].resolution.units; | |
4456 | } | |
4457 | break; | |
ef416fc2 | 4458 | |
b423cd4c | 4459 | case IPP_TAG_RANGE : |
4460 | toattr = ippAddRanges(to, attr->group_tag, attr->name, | |
4461 | attr->num_values, NULL, NULL); | |
ef416fc2 | 4462 | |
b423cd4c | 4463 | for (i = 0; i < attr->num_values; i ++) |
4464 | { | |
4465 | toattr->values[i].range.lower = attr->values[i].range.lower; | |
4466 | toattr->values[i].range.upper = attr->values[i].range.upper; | |
4467 | } | |
4468 | break; | |
ef416fc2 | 4469 | |
b423cd4c | 4470 | case IPP_TAG_TEXTLANG : |
4471 | case IPP_TAG_NAMELANG : | |
4472 | toattr = ippAddStrings(to, attr->group_tag, | |
4473 | (ipp_tag_t)(attr->value_tag | quickcopy), | |
4474 | attr->name, attr->num_values, NULL, NULL); | |
ef416fc2 | 4475 | |
b423cd4c | 4476 | if (quickcopy) |
4477 | { | |
4478 | for (i = 0; i < attr->num_values; i ++) | |
4479 | { | |
4480 | toattr->values[i].string.charset = attr->values[i].string.charset; | |
4481 | toattr->values[i].string.text = attr->values[i].string.text; | |
4482 | } | |
4483 | } | |
4484 | else | |
4485 | { | |
4486 | for (i = 0; i < attr->num_values; i ++) | |
4487 | { | |
4488 | if (!i) | |
4489 | toattr->values[i].string.charset = | |
757d2cad | 4490 | _cupsStrAlloc(attr->values[i].string.charset); |
b423cd4c | 4491 | else |
4492 | toattr->values[i].string.charset = | |
4493 | toattr->values[0].string.charset; | |
ef416fc2 | 4494 | |
bc44d920 | 4495 | toattr->values[i].string.text = |
4496 | _cupsStrAlloc(attr->values[i].string.text); | |
b423cd4c | 4497 | } |
4498 | } | |
4499 | break; | |
ef416fc2 | 4500 | |
b423cd4c | 4501 | case IPP_TAG_BEGIN_COLLECTION : |
4502 | toattr = ippAddCollections(to, attr->group_tag, attr->name, | |
4503 | attr->num_values, NULL); | |
ef416fc2 | 4504 | |
b423cd4c | 4505 | for (i = 0; i < attr->num_values; i ++) |
4506 | { | |
4507 | toattr->values[i].collection = ippNew(); | |
4508 | copy_attrs(toattr->values[i].collection, attr->values[i].collection, | |
4509 | NULL, IPP_TAG_ZERO, 0); | |
4510 | } | |
ef416fc2 | 4511 | break; |
ef416fc2 | 4512 | |
b423cd4c | 4513 | default : |
4514 | toattr = ippAddIntegers(to, attr->group_tag, attr->value_tag, | |
4515 | attr->name, attr->num_values, NULL); | |
ef416fc2 | 4516 | |
b423cd4c | 4517 | for (i = 0; i < attr->num_values; i ++) |
4518 | { | |
4519 | toattr->values[i].unknown.length = attr->values[i].unknown.length; | |
ef416fc2 | 4520 | |
b423cd4c | 4521 | if (toattr->values[i].unknown.length > 0) |
4522 | { | |
4523 | if ((toattr->values[i].unknown.data = | |
4524 | malloc(toattr->values[i].unknown.length)) == NULL) | |
4525 | toattr->values[i].unknown.length = 0; | |
4526 | else | |
4527 | memcpy(toattr->values[i].unknown.data, | |
4528 | attr->values[i].unknown.data, | |
4529 | toattr->values[i].unknown.length); | |
4530 | } | |
4531 | } | |
4532 | break; /* anti-compiler-warning-code */ | |
4533 | } | |
ef416fc2 | 4534 | |
b423cd4c | 4535 | return (toattr); |
4536 | } | |
4537 | ||
4538 | ||
4539 | /* | |
4540 | * 'copy_attrs()' - Copy attributes from one request to another. | |
4541 | */ | |
4542 | ||
4543 | static void | |
4544 | copy_attrs(ipp_t *to, /* I - Destination request */ | |
4545 | ipp_t *from, /* I - Source request */ | |
4546 | cups_array_t *ra, /* I - Requested attributes */ | |
4547 | ipp_tag_t group, /* I - Group to copy */ | |
4548 | int quickcopy) /* I - Do a quick copy? */ | |
4549 | { | |
4550 | ipp_attribute_t *fromattr; /* Source attribute */ | |
ef416fc2 | 4551 | |
ef416fc2 | 4552 | |
b423cd4c | 4553 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
4554 | "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)", | |
4555 | to, from, ra, group, quickcopy); | |
ef416fc2 | 4556 | |
b423cd4c | 4557 | if (!to || !from) |
4558 | return; | |
e00b005a | 4559 | |
b423cd4c | 4560 | for (fromattr = from->attrs; fromattr; fromattr = fromattr->next) |
ef416fc2 | 4561 | { |
4562 | /* | |
b423cd4c | 4563 | * Filter attributes as needed... |
ef416fc2 | 4564 | */ |
4565 | ||
2abf387c | 4566 | if ((group != IPP_TAG_ZERO && fromattr->group_tag != group && |
4567 | fromattr->group_tag != IPP_TAG_ZERO) || !fromattr->name) | |
b423cd4c | 4568 | continue; |
4569 | ||
4570 | if (!ra || cupsArrayFind(ra, fromattr->name)) | |
4571 | copy_attribute(to, fromattr, quickcopy); | |
ef416fc2 | 4572 | } |
b423cd4c | 4573 | } |
ef416fc2 | 4574 | |
ef416fc2 | 4575 | |
b423cd4c | 4576 | /* |
4577 | * 'copy_banner()' - Copy a banner file to the requests directory for the | |
4578 | * specified job. | |
4579 | */ | |
ef416fc2 | 4580 | |
b423cd4c | 4581 | static int /* O - Size of banner file in kbytes */ |
4582 | copy_banner(cupsd_client_t *con, /* I - Client connection */ | |
4583 | cupsd_job_t *job, /* I - Job information */ | |
4584 | const char *name) /* I - Name of banner */ | |
4585 | { | |
4586 | int i; /* Looping var */ | |
4587 | int kbytes; /* Size of banner file in kbytes */ | |
4588 | char filename[1024]; /* Job filename */ | |
4589 | cupsd_banner_t *banner; /* Pointer to banner */ | |
4590 | cups_file_t *in; /* Input file */ | |
4591 | cups_file_t *out; /* Output file */ | |
4592 | int ch; /* Character from file */ | |
4593 | char attrname[255], /* Name of attribute */ | |
4594 | *s; /* Pointer into name */ | |
4595 | ipp_attribute_t *attr; /* Attribute */ | |
ef416fc2 | 4596 | |
ef416fc2 | 4597 | |
3dfe78b3 MS |
4598 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
4599 | "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")", | |
09a101d6 | 4600 | con, con ? con->http.fd : -1, job, job->id, |
4601 | name ? name : "(null)"); | |
ef416fc2 | 4602 | |
b423cd4c | 4603 | /* |
4604 | * Find the banner; return if not found or "none"... | |
4605 | */ | |
ef416fc2 | 4606 | |
b423cd4c | 4607 | if (!name || !strcmp(name, "none") || |
4608 | (banner = cupsdFindBanner(name)) == NULL) | |
4609 | return (0); | |
ef416fc2 | 4610 | |
b423cd4c | 4611 | /* |
4612 | * Open the banner and job files... | |
4613 | */ | |
ef416fc2 | 4614 | |
b423cd4c | 4615 | if (add_file(con, job, banner->filetype, 0)) |
91c84a35 | 4616 | return (-1); |
ef416fc2 | 4617 | |
b423cd4c | 4618 | snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id, |
4619 | job->num_files); | |
4620 | if ((out = cupsFileOpen(filename, "w")) == NULL) | |
4621 | { | |
4622 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3dfe78b3 | 4623 | "Unable to create banner job file %s - %s", |
b423cd4c | 4624 | filename, strerror(errno)); |
4625 | job->num_files --; | |
4626 | return (0); | |
4627 | } | |
4628 | ||
4629 | fchmod(cupsFileNumber(out), 0640); | |
4630 | fchown(cupsFileNumber(out), RunUser, Group); | |
ef416fc2 | 4631 | |
4632 | /* | |
b423cd4c | 4633 | * Try the localized banner file under the subdirectory... |
ef416fc2 | 4634 | */ |
4635 | ||
80ca4592 | 4636 | strlcpy(attrname, job->attrs->attrs->next->values[0].string.text, |
b423cd4c | 4637 | sizeof(attrname)); |
4638 | if (strlen(attrname) > 2 && attrname[2] == '-') | |
ef416fc2 | 4639 | { |
4640 | /* | |
b423cd4c | 4641 | * Convert ll-cc to ll_CC... |
ef416fc2 | 4642 | */ |
4643 | ||
b423cd4c | 4644 | attrname[2] = '_'; |
4645 | attrname[3] = toupper(attrname[3] & 255); | |
4646 | attrname[4] = toupper(attrname[4] & 255); | |
4647 | } | |
ef416fc2 | 4648 | |
b423cd4c | 4649 | snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir, |
4650 | attrname, name); | |
ef416fc2 | 4651 | |
b423cd4c | 4652 | if (access(filename, 0) && strlen(attrname) > 2) |
ef416fc2 | 4653 | { |
4654 | /* | |
b423cd4c | 4655 | * Wasn't able to find "ll_CC" locale file; try the non-national |
4656 | * localization banner directory. | |
ef416fc2 | 4657 | */ |
4658 | ||
b423cd4c | 4659 | attrname[2] = '\0'; |
ef416fc2 | 4660 | |
b423cd4c | 4661 | snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir, |
4662 | attrname, name); | |
ef416fc2 | 4663 | } |
b423cd4c | 4664 | |
4665 | if (access(filename, 0)) | |
ef416fc2 | 4666 | { |
4667 | /* | |
b423cd4c | 4668 | * Use the non-localized banner file. |
ef416fc2 | 4669 | */ |
4670 | ||
b423cd4c | 4671 | snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name); |
4672 | } | |
ef416fc2 | 4673 | |
b423cd4c | 4674 | if ((in = cupsFileOpen(filename, "r")) == NULL) |
4675 | { | |
4676 | cupsFileClose(out); | |
4677 | unlink(filename); | |
4678 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3dfe78b3 | 4679 | "Unable to open banner template file %s - %s", |
b423cd4c | 4680 | filename, strerror(errno)); |
4681 | job->num_files --; | |
4682 | return (0); | |
ef416fc2 | 4683 | } |
4684 | ||
4685 | /* | |
b423cd4c | 4686 | * Parse the file to the end... |
ef416fc2 | 4687 | */ |
4688 | ||
b423cd4c | 4689 | while ((ch = cupsFileGetChar(in)) != EOF) |
4690 | if (ch == '{') | |
4691 | { | |
4692 | /* | |
4693 | * Get an attribute name... | |
4694 | */ | |
ef416fc2 | 4695 | |
b423cd4c | 4696 | for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;) |
4697 | if (!isalpha(ch & 255) && ch != '-' && ch != '?') | |
4698 | break; | |
4699 | else if (s < (attrname + sizeof(attrname) - 1)) | |
4700 | *s++ = ch; | |
4701 | else | |
4702 | break; | |
ef416fc2 | 4703 | |
b423cd4c | 4704 | *s = '\0'; |
4705 | ||
4706 | if (ch != '}') | |
4707 | { | |
4708 | /* | |
4709 | * Ignore { followed by stuff that is not an attribute name... | |
4710 | */ | |
4711 | ||
4712 | cupsFilePrintf(out, "{%s%c", attrname, ch); | |
4713 | continue; | |
4714 | } | |
ef416fc2 | 4715 | |
ef416fc2 | 4716 | /* |
b423cd4c | 4717 | * See if it is defined... |
ef416fc2 | 4718 | */ |
4719 | ||
b423cd4c | 4720 | if (attrname[0] == '?') |
4721 | s = attrname + 1; | |
4722 | else | |
4723 | s = attrname; | |
ef416fc2 | 4724 | |
b423cd4c | 4725 | if (!strcmp(s, "printer-name")) |
4726 | { | |
4727 | cupsFilePuts(out, job->dest); | |
4728 | continue; | |
ef416fc2 | 4729 | } |
b423cd4c | 4730 | else if ((attr = ippFindAttribute(job->attrs, s, IPP_TAG_ZERO)) == NULL) |
4731 | { | |
4732 | /* | |
4733 | * See if we have a leading question mark... | |
4734 | */ | |
ef416fc2 | 4735 | |
b423cd4c | 4736 | if (attrname[0] != '?') |
4737 | { | |
4738 | /* | |
4739 | * Nope, write to file as-is; probably a PostScript procedure... | |
4740 | */ | |
ef416fc2 | 4741 | |
b423cd4c | 4742 | cupsFilePrintf(out, "{%s}", attrname); |
4743 | } | |
ef416fc2 | 4744 | |
b423cd4c | 4745 | continue; |
4746 | } | |
ef416fc2 | 4747 | |
b423cd4c | 4748 | /* |
4749 | * Output value(s)... | |
4750 | */ | |
ef416fc2 | 4751 | |
b423cd4c | 4752 | for (i = 0; i < attr->num_values; i ++) |
4753 | { | |
4754 | if (i) | |
4755 | cupsFilePutChar(out, ','); | |
ef416fc2 | 4756 | |
b423cd4c | 4757 | switch (attr->value_tag) |
4758 | { | |
4759 | case IPP_TAG_INTEGER : | |
4760 | case IPP_TAG_ENUM : | |
4761 | if (!strncmp(s, "time-at-", 8)) | |
4762 | cupsFilePuts(out, cupsdGetDateTime(attr->values[i].integer)); | |
4763 | else | |
4764 | cupsFilePrintf(out, "%d", attr->values[i].integer); | |
4765 | break; | |
ef416fc2 | 4766 | |
b423cd4c | 4767 | case IPP_TAG_BOOLEAN : |
4768 | cupsFilePrintf(out, "%d", attr->values[i].boolean); | |
4769 | break; | |
ef416fc2 | 4770 | |
b423cd4c | 4771 | case IPP_TAG_NOVALUE : |
4772 | cupsFilePuts(out, "novalue"); | |
4773 | break; | |
ef416fc2 | 4774 | |
b423cd4c | 4775 | case IPP_TAG_RANGE : |
4776 | cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower, | |
4777 | attr->values[i].range.upper); | |
4778 | break; | |
fa73b229 | 4779 | |
b423cd4c | 4780 | case IPP_TAG_RESOLUTION : |
4781 | cupsFilePrintf(out, "%dx%d%s", attr->values[i].resolution.xres, | |
4782 | attr->values[i].resolution.yres, | |
4783 | attr->values[i].resolution.units == IPP_RES_PER_INCH ? | |
4784 | "dpi" : "dpc"); | |
4785 | break; | |
fa73b229 | 4786 | |
b423cd4c | 4787 | case IPP_TAG_URI : |
4788 | case IPP_TAG_STRING : | |
4789 | case IPP_TAG_TEXT : | |
4790 | case IPP_TAG_NAME : | |
4791 | case IPP_TAG_KEYWORD : | |
4792 | case IPP_TAG_CHARSET : | |
4793 | case IPP_TAG_LANGUAGE : | |
4794 | if (!strcasecmp(banner->filetype->type, "postscript")) | |
4795 | { | |
4796 | /* | |
4797 | * Need to quote strings for PS banners... | |
4798 | */ | |
fa73b229 | 4799 | |
b423cd4c | 4800 | const char *p; |
fa73b229 | 4801 | |
b423cd4c | 4802 | for (p = attr->values[i].string.text; *p; p ++) |
4803 | { | |
4804 | if (*p == '(' || *p == ')' || *p == '\\') | |
4805 | { | |
4806 | cupsFilePutChar(out, '\\'); | |
4807 | cupsFilePutChar(out, *p); | |
4808 | } | |
4809 | else if (*p < 32 || *p > 126) | |
4810 | cupsFilePrintf(out, "\\%03o", *p & 255); | |
4811 | else | |
4812 | cupsFilePutChar(out, *p); | |
4813 | } | |
4814 | } | |
4815 | else | |
4816 | cupsFilePuts(out, attr->values[i].string.text); | |
4817 | break; | |
fa73b229 | 4818 | |
b423cd4c | 4819 | default : |
4820 | break; /* anti-compiler-warning-code */ | |
4821 | } | |
4822 | } | |
4823 | } | |
4824 | else if (ch == '\\') /* Quoted char */ | |
4825 | { | |
4826 | ch = cupsFileGetChar(in); | |
fa73b229 | 4827 | |
b423cd4c | 4828 | if (ch != '{') /* Only do special handling for \{ */ |
4829 | cupsFilePutChar(out, '\\'); | |
fa73b229 | 4830 | |
b423cd4c | 4831 | cupsFilePutChar(out, ch); |
4832 | } | |
4833 | else | |
4834 | cupsFilePutChar(out, ch); | |
fa73b229 | 4835 | |
b423cd4c | 4836 | cupsFileClose(in); |
fa73b229 | 4837 | |
b423cd4c | 4838 | kbytes = (cupsFileTell(out) + 1023) / 1024; |
fa73b229 | 4839 | |
b423cd4c | 4840 | if ((attr = ippFindAttribute(job->attrs, "job-k-octets", |
4841 | IPP_TAG_INTEGER)) != NULL) | |
4842 | attr->values[0].integer += kbytes; | |
4843 | ||
4844 | cupsFileClose(out); | |
4845 | ||
4846 | return (kbytes); | |
fa73b229 | 4847 | } |
4848 | ||
4849 | ||
4850 | /* | |
b423cd4c | 4851 | * 'copy_file()' - Copy a PPD file or interface script... |
fa73b229 | 4852 | */ |
4853 | ||
b423cd4c | 4854 | static int /* O - 0 = success, -1 = error */ |
4855 | copy_file(const char *from, /* I - Source file */ | |
4856 | const char *to) /* I - Destination file */ | |
fa73b229 | 4857 | { |
b423cd4c | 4858 | cups_file_t *src, /* Source file */ |
4859 | *dst; /* Destination file */ | |
4860 | int bytes; /* Bytes to read/write */ | |
4861 | char buffer[2048]; /* Copy buffer */ | |
fa73b229 | 4862 | |
4863 | ||
b423cd4c | 4864 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_file(\"%s\", \"%s\")", from, to); |
4865 | ||
fa73b229 | 4866 | /* |
b423cd4c | 4867 | * Open the source and destination file for a copy... |
fa73b229 | 4868 | */ |
4869 | ||
b423cd4c | 4870 | if ((src = cupsFileOpen(from, "rb")) == NULL) |
4871 | return (-1); | |
fa73b229 | 4872 | |
b423cd4c | 4873 | if ((dst = cupsFileOpen(to, "wb")) == NULL) |
4874 | { | |
4875 | cupsFileClose(src); | |
4876 | return (-1); | |
4877 | } | |
fa73b229 | 4878 | |
b423cd4c | 4879 | /* |
4880 | * Copy the source file to the destination... | |
4881 | */ | |
fa73b229 | 4882 | |
b423cd4c | 4883 | while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0) |
4884 | if (cupsFileWrite(dst, buffer, bytes) < bytes) | |
4885 | { | |
4886 | cupsFileClose(src); | |
4887 | cupsFileClose(dst); | |
4888 | return (-1); | |
4889 | } | |
fa73b229 | 4890 | |
b423cd4c | 4891 | /* |
4892 | * Close both files and return... | |
4893 | */ | |
fa73b229 | 4894 | |
b423cd4c | 4895 | cupsFileClose(src); |
fa73b229 | 4896 | |
b423cd4c | 4897 | return (cupsFileClose(dst)); |
4898 | } | |
fa73b229 | 4899 | |
fa73b229 | 4900 | |
b423cd4c | 4901 | /* |
4902 | * 'copy_model()' - Copy a PPD model file, substituting default values | |
4903 | * as needed... | |
4904 | */ | |
e00b005a | 4905 | |
b423cd4c | 4906 | static int /* O - 0 = success, -1 = error */ |
4907 | copy_model(cupsd_client_t *con, /* I - Client connection */ | |
4908 | const char *from, /* I - Source file */ | |
4909 | const char *to) /* I - Destination file */ | |
4910 | { | |
f7deaa1a | 4911 | fd_set input; /* select() input set */ |
b423cd4c | 4912 | struct timeval timeout; /* select() timeout */ |
bc44d920 | 4913 | int maxfd; /* Max file descriptor for select() */ |
b423cd4c | 4914 | char tempfile[1024]; /* Temporary PPD file */ |
4915 | int tempfd; /* Temporary PPD file descriptor */ | |
4916 | int temppid; /* Process ID of cups-driverd */ | |
4917 | int temppipe[2]; /* Temporary pipes */ | |
4918 | char *argv[4], /* Command-line arguments */ | |
4919 | *envp[MAX_ENV]; /* Environment */ | |
4920 | cups_file_t *src, /* Source file */ | |
4921 | *dst; /* Destination file */ | |
2abf387c | 4922 | ppd_file_t *ppd; /* PPD file */ |
b423cd4c | 4923 | int bytes, /* Bytes from pipe */ |
4924 | total; /* Total bytes from pipe */ | |
2abf387c | 4925 | char buffer[2048]; /* Copy buffer */ |
b423cd4c | 4926 | int i; /* Looping var */ |
4927 | char option[PPD_MAX_NAME], /* Option name */ | |
4928 | choice[PPD_MAX_NAME]; /* Choice name */ | |
4929 | int num_defaults; /* Number of default options */ | |
2abf387c | 4930 | cups_option_t *defaults; /* Default options */ |
b423cd4c | 4931 | char cups_protocol[PPD_MAX_LINE]; |
4932 | /* cupsProtocol attribute */ | |
4933 | int have_letter, /* Have Letter size */ | |
4934 | have_a4; /* Have A4 size */ | |
4935 | #ifdef HAVE_LIBPAPER | |
4936 | char *paper_result; /* Paper size name from libpaper */ | |
4937 | char system_paper[64]; /* Paper size name buffer */ | |
4938 | #endif /* HAVE_LIBPAPER */ | |
e00b005a | 4939 | |
e00b005a | 4940 | |
b423cd4c | 4941 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
4942 | "copy_model(con=%p, from=\"%s\", to=\"%s\")", | |
4943 | con, from, to); | |
e00b005a | 4944 | |
b423cd4c | 4945 | /* |
4946 | * Run cups-driverd to get the PPD file... | |
4947 | */ | |
e00b005a | 4948 | |
b423cd4c | 4949 | argv[0] = "cups-driverd"; |
4950 | argv[1] = "cat"; | |
4951 | argv[2] = (char *)from; | |
4952 | argv[3] = NULL; | |
e00b005a | 4953 | |
b423cd4c | 4954 | cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0]))); |
e00b005a | 4955 | |
b423cd4c | 4956 | snprintf(buffer, sizeof(buffer), "%s/daemon/cups-driverd", ServerBin); |
4957 | snprintf(tempfile, sizeof(tempfile), "%s/%d.ppd", TempDir, con->http.fd); | |
4958 | tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600); | |
4959 | if (tempfd < 0) | |
4960 | return (-1); | |
4961 | ||
4962 | cupsdOpenPipe(temppipe); | |
4963 | ||
b423cd4c | 4964 | cupsdLogMessage(CUPSD_LOG_DEBUG, |
4965 | "copy_model: Running \"cups-driverd cat %s\"...", from); | |
fa73b229 | 4966 | |
b423cd4c | 4967 | if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1], |
a4924f6c | 4968 | -1, -1, 0, DefaultProfile, &temppid)) |
fa73b229 | 4969 | { |
b423cd4c | 4970 | close(tempfd); |
4971 | unlink(tempfile); | |
a4924f6c | 4972 | |
b423cd4c | 4973 | return (-1); |
fa73b229 | 4974 | } |
4975 | ||
b423cd4c | 4976 | close(temppipe[1]); |
fa73b229 | 4977 | |
b423cd4c | 4978 | /* |
4979 | * Wait up to 30 seconds for the PPD file to be copied... | |
4980 | */ | |
fa73b229 | 4981 | |
b423cd4c | 4982 | total = 0; |
fa73b229 | 4983 | |
b423cd4c | 4984 | if (temppipe[0] > CGIPipes[0]) |
4985 | maxfd = temppipe[0] + 1; | |
4986 | else | |
4987 | maxfd = CGIPipes[0] + 1; | |
ef416fc2 | 4988 | |
b423cd4c | 4989 | for (;;) |
4990 | { | |
4991 | /* | |
4992 | * See if we have data ready... | |
4993 | */ | |
ef416fc2 | 4994 | |
b423cd4c | 4995 | bytes = 0; |
ef416fc2 | 4996 | |
f7deaa1a | 4997 | FD_ZERO(&input); |
4998 | FD_SET(temppipe[0], &input); | |
4999 | FD_SET(CGIPipes[0], &input); | |
ef416fc2 | 5000 | |
b423cd4c | 5001 | timeout.tv_sec = 30; |
5002 | timeout.tv_usec = 0; | |
5003 | ||
f7deaa1a | 5004 | if ((i = select(maxfd, &input, NULL, NULL, &timeout)) < 0) |
b423cd4c | 5005 | { |
5006 | if (errno == EINTR) | |
5007 | continue; | |
5008 | else | |
5009 | break; | |
5010 | } | |
5011 | else if (i == 0) | |
ef416fc2 | 5012 | { |
5013 | /* | |
b423cd4c | 5014 | * We have timed out... |
ef416fc2 | 5015 | */ |
5016 | ||
b423cd4c | 5017 | break; |
ef416fc2 | 5018 | } |
b423cd4c | 5019 | |
f7deaa1a | 5020 | if (FD_ISSET(temppipe[0], &input)) |
ef416fc2 | 5021 | { |
5022 | /* | |
b423cd4c | 5023 | * Read the PPD file from the pipe, and write it to the PPD file. |
ef416fc2 | 5024 | */ |
5025 | ||
b423cd4c | 5026 | if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0) |
5027 | { | |
5028 | if (write(tempfd, buffer, bytes) < bytes) | |
5029 | break; | |
ef416fc2 | 5030 | |
b423cd4c | 5031 | total += bytes; |
5032 | } | |
5033 | else | |
5034 | break; | |
ef416fc2 | 5035 | } |
b423cd4c | 5036 | |
f7deaa1a | 5037 | if (FD_ISSET(CGIPipes[0], &input)) |
b423cd4c | 5038 | cupsdUpdateCGI(); |
ef416fc2 | 5039 | } |
5040 | ||
b423cd4c | 5041 | close(temppipe[0]); |
5042 | close(tempfd); | |
ef416fc2 | 5043 | |
b423cd4c | 5044 | if (!total) |
ef416fc2 | 5045 | { |
b423cd4c | 5046 | /* |
5047 | * No data from cups-deviced... | |
5048 | */ | |
5049 | ||
5050 | cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!"); | |
5051 | unlink(tempfile); | |
5052 | return (-1); | |
ef416fc2 | 5053 | } |
5054 | ||
b423cd4c | 5055 | /* |
5056 | * Read the source file and see what page sizes are supported... | |
5057 | */ | |
fa73b229 | 5058 | |
2abf387c | 5059 | if ((ppd = ppdOpenFile(tempfile)) == NULL) |
b423cd4c | 5060 | { |
5061 | unlink(tempfile); | |
5062 | return (-1); | |
5063 | } | |
fa73b229 | 5064 | |
2abf387c | 5065 | have_letter = ppdPageSize(ppd, "Letter") != NULL; |
5066 | have_a4 = ppdPageSize(ppd, "A4") != NULL; | |
ef416fc2 | 5067 | |
5068 | /* | |
b423cd4c | 5069 | * Open the destination (if possible) and set the default options... |
ef416fc2 | 5070 | */ |
5071 | ||
b423cd4c | 5072 | num_defaults = 0; |
5073 | defaults = NULL; | |
5074 | cups_protocol[0] = '\0'; | |
ef416fc2 | 5075 | |
b423cd4c | 5076 | if ((dst = cupsFileOpen(to, "rb")) != NULL) |
ef416fc2 | 5077 | { |
5078 | /* | |
b423cd4c | 5079 | * Read all of the default lines from the old PPD... |
ef416fc2 | 5080 | */ |
5081 | ||
b423cd4c | 5082 | while (cupsFileGets(dst, buffer, sizeof(buffer))) |
5083 | if (!strncmp(buffer, "*Default", 8)) | |
5084 | { | |
5085 | /* | |
5086 | * Add the default option... | |
5087 | */ | |
ef416fc2 | 5088 | |
b423cd4c | 5089 | if (!ppd_parse_line(buffer, option, sizeof(option), |
5090 | choice, sizeof(choice))) | |
2abf387c | 5091 | { |
5092 | ppd_option_t *ppdo; /* PPD option */ | |
5093 | ||
5094 | ||
5095 | /* | |
5096 | * Only add the default if the default hasn't already been | |
5097 | * set and the choice exists in the new PPD... | |
5098 | */ | |
5099 | ||
5100 | if (!cupsGetOption(option, num_defaults, defaults) && | |
5101 | (ppdo = ppdFindOption(ppd, option)) != NULL && | |
5102 | ppdFindChoice(ppdo, choice)) | |
5103 | num_defaults = cupsAddOption(option, choice, num_defaults, | |
b423cd4c | 5104 | &defaults); |
2abf387c | 5105 | } |
b423cd4c | 5106 | } |
5107 | else if (!strncmp(buffer, "*cupsProtocol:", 14)) | |
5108 | strlcpy(cups_protocol, buffer, sizeof(cups_protocol)); | |
ef416fc2 | 5109 | |
b423cd4c | 5110 | cupsFileClose(dst); |
ef416fc2 | 5111 | } |
b423cd4c | 5112 | #ifdef HAVE_LIBPAPER |
5113 | else if ((paper_result = systempapername()) != NULL) | |
5114 | { | |
5115 | /* | |
5116 | * Set the default media sizes from the systemwide default... | |
5117 | */ | |
ef416fc2 | 5118 | |
b423cd4c | 5119 | strlcpy(system_paper, paper_result, sizeof(system_paper)); |
5120 | system_paper[0] = toupper(system_paper[0] & 255); | |
ef416fc2 | 5121 | |
b423cd4c | 5122 | if ((!strcmp(system_paper, "Letter") && have_letter) || |
5123 | (!strcmp(system_paper, "A4") && have_a4)) | |
5124 | { | |
f7deaa1a | 5125 | num_defaults = cupsAddOption("PageSize", system_paper, |
26d47ec6 | 5126 | num_defaults, &defaults); |
f7deaa1a | 5127 | num_defaults = cupsAddOption("PageRegion", system_paper, |
26d47ec6 | 5128 | num_defaults, &defaults); |
f7deaa1a | 5129 | num_defaults = cupsAddOption("PaperDimension", system_paper, |
26d47ec6 | 5130 | num_defaults, &defaults); |
f7deaa1a | 5131 | num_defaults = cupsAddOption("ImageableArea", system_paper, |
26d47ec6 | 5132 | num_defaults, &defaults); |
b423cd4c | 5133 | } |
ef416fc2 | 5134 | } |
b423cd4c | 5135 | #endif /* HAVE_LIBPAPER */ |
5136 | else | |
ef416fc2 | 5137 | { |
b423cd4c | 5138 | /* |
5139 | * Add the default media sizes... | |
5140 | * | |
5141 | * Note: These values are generally not valid for large-format devices | |
5142 | * like plotters, however it is probably safe to say that those | |
5143 | * users will configure the media size after initially adding | |
5144 | * the device anyways... | |
5145 | */ | |
5146 | ||
5147 | if (!DefaultLanguage || | |
5148 | !strcasecmp(DefaultLanguage, "C") || | |
5149 | !strcasecmp(DefaultLanguage, "POSIX") || | |
5150 | !strcasecmp(DefaultLanguage, "en") || | |
2abf387c | 5151 | !strncasecmp(DefaultLanguage, "en.", 3) || |
b423cd4c | 5152 | !strncasecmp(DefaultLanguage, "en_US", 5) || |
5153 | !strncasecmp(DefaultLanguage, "en_CA", 5) || | |
5154 | !strncasecmp(DefaultLanguage, "fr_CA", 5)) | |
5155 | { | |
5156 | /* | |
5157 | * These are the only locales that will default to "letter" size... | |
5158 | */ | |
5159 | ||
5160 | if (have_letter) | |
5161 | { | |
2abf387c | 5162 | num_defaults = cupsAddOption("PageSize", "Letter", num_defaults, |
5163 | &defaults); | |
5164 | num_defaults = cupsAddOption("PageRegion", "Letter", num_defaults, | |
5165 | &defaults); | |
5166 | num_defaults = cupsAddOption("PaperDimension", "Letter", num_defaults, | |
5167 | &defaults); | |
5168 | num_defaults = cupsAddOption("ImageableArea", "Letter", num_defaults, | |
5169 | &defaults); | |
b423cd4c | 5170 | } |
5171 | } | |
5172 | else if (have_a4) | |
5173 | { | |
5174 | /* | |
5175 | * The rest default to "a4" size... | |
5176 | */ | |
5177 | ||
2abf387c | 5178 | num_defaults = cupsAddOption("PageSize", "A4", num_defaults, |
5179 | &defaults); | |
5180 | num_defaults = cupsAddOption("PageRegion", "A4", num_defaults, | |
5181 | &defaults); | |
5182 | num_defaults = cupsAddOption("PaperDimension", "A4", num_defaults, | |
5183 | &defaults); | |
5184 | num_defaults = cupsAddOption("ImageableArea", "A4", num_defaults, | |
5185 | &defaults); | |
b423cd4c | 5186 | } |
ef416fc2 | 5187 | } |
5188 | ||
2abf387c | 5189 | ppdClose(ppd); |
5190 | ||
5191 | /* | |
5192 | * Open the source file for a copy... | |
5193 | */ | |
5194 | ||
5195 | if ((src = cupsFileOpen(tempfile, "rb")) == NULL) | |
5196 | { | |
5197 | cupsFreeOptions(num_defaults, defaults); | |
5198 | unlink(tempfile); | |
5199 | return (-1); | |
5200 | } | |
5201 | ||
ef416fc2 | 5202 | /* |
b423cd4c | 5203 | * Open the destination file for a copy... |
ef416fc2 | 5204 | */ |
5205 | ||
b423cd4c | 5206 | if ((dst = cupsFileOpen(to, "wb")) == NULL) |
ef416fc2 | 5207 | { |
2abf387c | 5208 | cupsFreeOptions(num_defaults, defaults); |
b423cd4c | 5209 | cupsFileClose(src); |
5210 | unlink(tempfile); | |
5211 | return (-1); | |
ef416fc2 | 5212 | } |
5213 | ||
5214 | /* | |
b423cd4c | 5215 | * Copy the source file to the destination... |
ef416fc2 | 5216 | */ |
5217 | ||
b423cd4c | 5218 | while (cupsFileGets(src, buffer, sizeof(buffer))) |
ef416fc2 | 5219 | { |
b423cd4c | 5220 | if (!strncmp(buffer, "*Default", 8)) |
ef416fc2 | 5221 | { |
b423cd4c | 5222 | /* |
5223 | * Check for an previous default option choice... | |
5224 | */ | |
ef416fc2 | 5225 | |
b423cd4c | 5226 | if (!ppd_parse_line(buffer, option, sizeof(option), |
5227 | choice, sizeof(choice))) | |
ef416fc2 | 5228 | { |
2abf387c | 5229 | const char *val; /* Default option value */ |
ef416fc2 | 5230 | |
2abf387c | 5231 | |
5232 | if ((val = cupsGetOption(option, num_defaults, defaults)) != NULL) | |
5233 | { | |
5234 | /* | |
5235 | * Substitute the previous choice... | |
5236 | */ | |
5237 | ||
5238 | snprintf(buffer, sizeof(buffer), "*Default%s: %s", option, val); | |
5239 | } | |
b423cd4c | 5240 | } |
ef416fc2 | 5241 | } |
b423cd4c | 5242 | |
5243 | cupsFilePrintf(dst, "%s\n", buffer); | |
ef416fc2 | 5244 | } |
5245 | ||
b423cd4c | 5246 | if (cups_protocol[0]) |
5247 | cupsFilePrintf(dst, "%s\n", cups_protocol); | |
5248 | ||
2abf387c | 5249 | cupsFreeOptions(num_defaults, defaults); |
b423cd4c | 5250 | |
ef416fc2 | 5251 | /* |
b423cd4c | 5252 | * Close both files and return... |
ef416fc2 | 5253 | */ |
5254 | ||
b423cd4c | 5255 | cupsFileClose(src); |
5256 | ||
5257 | unlink(tempfile); | |
5258 | ||
5259 | return (cupsFileClose(dst)); | |
5260 | } | |
5261 | ||
5262 | ||
5263 | /* | |
5264 | * 'copy_job_attrs()' - Copy job attributes. | |
5265 | */ | |
ef416fc2 | 5266 | |
b423cd4c | 5267 | static void |
5268 | copy_job_attrs(cupsd_client_t *con, /* I - Client connection */ | |
5269 | cupsd_job_t *job, /* I - Job */ | |
5270 | cups_array_t *ra) /* I - Requested attributes array */ | |
5271 | { | |
5272 | char job_uri[HTTP_MAX_URI]; /* Job URI */ | |
ef416fc2 | 5273 | |
ef416fc2 | 5274 | |
5275 | /* | |
b423cd4c | 5276 | * Send the requested attributes for each job... |
ef416fc2 | 5277 | */ |
5278 | ||
b423cd4c | 5279 | httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL, |
5280 | con->servername, con->serverport, "/jobs/%d", | |
5281 | job->id); | |
ef416fc2 | 5282 | |
2e4ff8af MS |
5283 | if (!ra || cupsArrayFind(ra, "document-count")) |
5284 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, | |
5285 | "document-count", job->num_files); | |
5286 | ||
b423cd4c | 5287 | if (!ra || cupsArrayFind(ra, "job-more-info")) |
5288 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, | |
5289 | "job-more-info", NULL, job_uri); | |
ef416fc2 | 5290 | |
b423cd4c | 5291 | if (job->state_value > IPP_JOB_PROCESSING && |
5292 | (!ra || cupsArrayFind(ra, "job-preserved"))) | |
5293 | ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved", | |
5294 | job->num_files > 0); | |
ef416fc2 | 5295 | |
b423cd4c | 5296 | if (!ra || cupsArrayFind(ra, "job-printer-up-time")) |
5297 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, | |
5298 | "job-printer-up-time", time(NULL)); | |
ef416fc2 | 5299 | |
b423cd4c | 5300 | if (!ra || cupsArrayFind(ra, "job-state-reasons")) |
5301 | add_job_state_reasons(con, job); | |
bd7854cb | 5302 | |
b423cd4c | 5303 | if (!ra || cupsArrayFind(ra, "job-uri")) |
5304 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, | |
5305 | "job-uri", NULL, job_uri); | |
ef416fc2 | 5306 | |
b423cd4c | 5307 | copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0); |
5308 | } | |
ef416fc2 | 5309 | |
ef416fc2 | 5310 | |
b423cd4c | 5311 | /* |
5312 | * 'copy_printer_attrs()' - Copy printer attributes. | |
5313 | */ | |
ef416fc2 | 5314 | |
b423cd4c | 5315 | static void |
5316 | copy_printer_attrs( | |
5317 | cupsd_client_t *con, /* I - Client connection */ | |
5318 | cupsd_printer_t *printer, /* I - Printer */ | |
5319 | cups_array_t *ra) /* I - Requested attributes array */ | |
5320 | { | |
5321 | char printer_uri[HTTP_MAX_URI]; | |
5322 | /* Printer URI */ | |
5323 | time_t curtime; /* Current time */ | |
5324 | int i; /* Looping var */ | |
5325 | ipp_attribute_t *history; /* History collection */ | |
ef416fc2 | 5326 | |
ef416fc2 | 5327 | |
b423cd4c | 5328 | /* |
5329 | * Copy the printer attributes to the response using requested-attributes | |
5330 | * and document-format attributes that may be provided by the client. | |
5331 | */ | |
ef416fc2 | 5332 | |
b423cd4c | 5333 | curtime = time(NULL); |
ef416fc2 | 5334 | |
b423cd4c | 5335 | #ifdef __APPLE__ |
5336 | if ((!ra || cupsArrayFind(ra, "com.apple.print.recoverable-message")) && | |
5337 | printer->recoverable) | |
5338 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
5339 | "com.apple.print.recoverable-message", NULL, | |
5340 | printer->recoverable); | |
5341 | #endif /* __APPLE__ */ | |
ef416fc2 | 5342 | |
5a738aea MS |
5343 | if (!ra || cupsArrayFind(ra, "marker-change-time")) |
5344 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5345 | "marker-change-time", printer->marker_time); | |
5346 | ||
323c5de1 | 5347 | if (printer->alert && (!ra || cupsArrayFind(ra, "printer-alert"))) |
5348 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING, | |
5349 | "printer-alert", NULL, printer->alert); | |
5350 | ||
5351 | if (printer->alert_description && | |
5352 | (!ra || cupsArrayFind(ra, "printer-alert-description"))) | |
5353 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
5354 | "printer-alert-description", NULL, | |
5355 | printer->alert_description); | |
5356 | ||
b423cd4c | 5357 | if (!ra || cupsArrayFind(ra, "printer-current-time")) |
5358 | ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time", | |
5359 | ippTimeToDate(curtime)); | |
ef416fc2 | 5360 | |
d9bca400 MS |
5361 | #ifdef HAVE_DNSSD |
5362 | if (!ra || cupsArrayFind(ra, "printer-dns-sd-name")) | |
5363 | { | |
5364 | if (printer->reg_name) | |
5365 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
5366 | "printer-dns-sd-name", NULL, printer->reg_name); | |
5367 | else | |
5368 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, | |
5369 | "printer-dns-sd-name", 0); | |
5370 | } | |
5371 | #endif /* HAVE_DNSSD */ | |
5372 | ||
b423cd4c | 5373 | if (!ra || cupsArrayFind(ra, "printer-error-policy")) |
5374 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
5375 | "printer-error-policy", NULL, printer->error_policy); | |
ef416fc2 | 5376 | |
b423cd4c | 5377 | if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs")) |
5378 | ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs", | |
5379 | printer->accepting); | |
ef416fc2 | 5380 | |
b423cd4c | 5381 | if (!ra || cupsArrayFind(ra, "printer-is-shared")) |
5382 | ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared", | |
5383 | printer->shared); | |
ef416fc2 | 5384 | |
b423cd4c | 5385 | if (!ra || cupsArrayFind(ra, "printer-op-policy")) |
5386 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
5387 | "printer-op-policy", NULL, printer->op_policy); | |
5388 | ||
5389 | if (!ra || cupsArrayFind(ra, "printer-state")) | |
5390 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", | |
5391 | printer->state); | |
5392 | ||
5393 | if (!ra || cupsArrayFind(ra, "printer-state-change-time")) | |
5394 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5395 | "printer-state-change-time", printer->state_time); | |
f7deaa1a | 5396 | |
b423cd4c | 5397 | if (MaxPrinterHistory > 0 && printer->num_history > 0 && |
5398 | cupsArrayFind(ra, "printer-state-history")) | |
ef416fc2 | 5399 | { |
5400 | /* | |
b423cd4c | 5401 | * Printer history is only sent if specifically requested, so that |
5402 | * older CUPS/IPP clients won't barf on the collection attributes. | |
ef416fc2 | 5403 | */ |
5404 | ||
b423cd4c | 5405 | history = ippAddCollections(con->response, IPP_TAG_PRINTER, |
5406 | "printer-state-history", | |
5407 | printer->num_history, NULL); | |
5408 | ||
5409 | for (i = 0; i < printer->num_history; i ++) | |
5410 | copy_attrs(history->values[i].collection = ippNew(), printer->history[i], | |
5411 | NULL, IPP_TAG_ZERO, 0); | |
ef416fc2 | 5412 | } |
5413 | ||
b423cd4c | 5414 | if (!ra || cupsArrayFind(ra, "printer-state-message")) |
5415 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
5416 | "printer-state-message", NULL, printer->state_message); | |
ef416fc2 | 5417 | |
b423cd4c | 5418 | if (!ra || cupsArrayFind(ra, "printer-state-reasons")) |
5419 | add_printer_state_reasons(con, printer); | |
ef416fc2 | 5420 | |
b423cd4c | 5421 | if (!ra || cupsArrayFind(ra, "printer-type")) |
5422 | { | |
5423 | int type; /* printer-type value */ | |
ef416fc2 | 5424 | |
ef416fc2 | 5425 | |
ef416fc2 | 5426 | /* |
b423cd4c | 5427 | * Add the CUPS-specific printer-type attribute... |
ef416fc2 | 5428 | */ |
5429 | ||
09a101d6 | 5430 | type = printer->type; |
b423cd4c | 5431 | |
5432 | if (printer == DefaultPrinter) | |
5433 | type |= CUPS_PRINTER_DEFAULT; | |
5434 | ||
5435 | if (!printer->accepting) | |
5436 | type |= CUPS_PRINTER_REJECTING; | |
5437 | ||
5438 | if (!printer->shared) | |
5439 | type |= CUPS_PRINTER_NOT_SHARED; | |
5440 | ||
5441 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type", | |
5442 | type); | |
ef416fc2 | 5443 | } |
ef416fc2 | 5444 | |
b423cd4c | 5445 | if (!ra || cupsArrayFind(ra, "printer-up-time")) |
5446 | ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5447 | "printer-up-time", curtime); | |
ef416fc2 | 5448 | |
b423cd4c | 5449 | if ((!ra || cupsArrayFind(ra, "printer-uri-supported")) && |
5450 | !ippFindAttribute(printer->attrs, "printer-uri-supported", | |
5451 | IPP_TAG_URI)) | |
ef416fc2 | 5452 | { |
b423cd4c | 5453 | httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), |
5454 | "ipp", NULL, con->servername, con->serverport, | |
8ca02f3c | 5455 | (printer->type & CUPS_PRINTER_CLASS) ? |
5456 | "/classes/%s" : "/printers/%s", printer->name); | |
b423cd4c | 5457 | ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, |
5458 | "printer-uri-supported", NULL, printer_uri); | |
5459 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"", | |
5460 | printer_uri); | |
5461 | } | |
ef416fc2 | 5462 | |
b423cd4c | 5463 | if (!ra || cupsArrayFind(ra, "queued-job-count")) |
5464 | add_queued_job_count(con, printer); | |
ef416fc2 | 5465 | |
b423cd4c | 5466 | copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0); |
5467 | copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY); | |
5468 | } | |
ef416fc2 | 5469 | |
ef416fc2 | 5470 | |
b423cd4c | 5471 | /* |
5472 | * 'copy_subscription_attrs()' - Copy subscription attributes. | |
5473 | */ | |
ef416fc2 | 5474 | |
b423cd4c | 5475 | static void |
5476 | copy_subscription_attrs( | |
5477 | cupsd_client_t *con, /* I - Client connection */ | |
5478 | cupsd_subscription_t *sub, /* I - Subscription */ | |
5479 | cups_array_t *ra) /* I - Requested attributes array */ | |
5480 | { | |
5481 | ipp_attribute_t *attr; /* Current attribute */ | |
5482 | char printer_uri[HTTP_MAX_URI]; | |
5483 | /* Printer URI */ | |
5484 | int count; /* Number of events */ | |
5485 | unsigned mask; /* Current event mask */ | |
5486 | const char *name; /* Current event name */ | |
ef416fc2 | 5487 | |
ef416fc2 | 5488 | |
b423cd4c | 5489 | /* |
5490 | * Copy the subscription attributes to the response using the | |
5491 | * requested-attributes attribute that may be provided by the client. | |
5492 | */ | |
ef416fc2 | 5493 | |
b423cd4c | 5494 | if (!ra || cupsArrayFind(ra, "notify-events")) |
5495 | { | |
5496 | if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL) | |
5497 | { | |
5498 | /* | |
5499 | * Simple event list... | |
5500 | */ | |
ef416fc2 | 5501 | |
b423cd4c | 5502 | ippAddString(con->response, IPP_TAG_SUBSCRIPTION, |
d09495fa | 5503 | (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY), |
b423cd4c | 5504 | "notify-events", NULL, name); |
5505 | } | |
5506 | else | |
5507 | { | |
5508 | /* | |
5509 | * Complex event list... | |
5510 | */ | |
ef416fc2 | 5511 | |
b423cd4c | 5512 | for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1) |
5513 | if (sub->mask & mask) | |
5514 | count ++; | |
ef416fc2 | 5515 | |
b423cd4c | 5516 | attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION, |
d09495fa | 5517 | (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY), |
b423cd4c | 5518 | "notify-events", count, NULL, NULL); |
ef416fc2 | 5519 | |
b423cd4c | 5520 | for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1) |
5521 | if (sub->mask & mask) | |
5522 | { | |
5523 | attr->values[count].string.text = | |
5524 | (char *)cupsdEventName((cupsd_eventmask_t)mask); | |
ef416fc2 | 5525 | |
b423cd4c | 5526 | count ++; |
5527 | } | |
ef416fc2 | 5528 | } |
b423cd4c | 5529 | } |
ef416fc2 | 5530 | |
b423cd4c | 5531 | if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id"))) |
5532 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
5533 | "notify-job-id", sub->job->id); | |
ef416fc2 | 5534 | |
b423cd4c | 5535 | if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration"))) |
5536 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
5537 | "notify-lease-duration", sub->lease); | |
ef416fc2 | 5538 | |
b423cd4c | 5539 | if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri"))) |
5540 | { | |
5541 | httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), | |
5542 | "ipp", NULL, con->servername, con->serverport, | |
5543 | "/printers/%s", sub->dest->name); | |
5544 | ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, | |
5545 | "notify-printer-uri", NULL, printer_uri); | |
ef416fc2 | 5546 | } |
ef416fc2 | 5547 | |
b423cd4c | 5548 | if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri"))) |
5549 | ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, | |
5550 | "notify-recipient-uri", NULL, sub->recipient); | |
5551 | else if (!ra || cupsArrayFind(ra, "notify-pull-method")) | |
5552 | ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, | |
5553 | "notify-pull-method", NULL, "ippget"); | |
ef416fc2 | 5554 | |
b423cd4c | 5555 | if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name")) |
5556 | ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME, | |
5557 | "notify-subscriber-user-name", NULL, sub->owner); | |
ef416fc2 | 5558 | |
b423cd4c | 5559 | if (!ra || cupsArrayFind(ra, "notify-subscription-id")) |
5560 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
5561 | "notify-subscription-id", sub->id); | |
ef416fc2 | 5562 | |
b423cd4c | 5563 | if (!ra || cupsArrayFind(ra, "notify-time-interval")) |
5564 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
5565 | "notify-time-interval", sub->interval); | |
ef416fc2 | 5566 | |
b423cd4c | 5567 | if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data"))) |
5568 | ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data", | |
5569 | sub->user_data, sub->user_data_len); | |
5570 | } | |
ef416fc2 | 5571 | |
ef416fc2 | 5572 | |
b423cd4c | 5573 | /* |
5574 | * 'create_job()' - Print a file to a printer or class. | |
5575 | */ | |
5576 | ||
5577 | static void | |
5578 | create_job(cupsd_client_t *con, /* I - Client connection */ | |
5579 | ipp_attribute_t *uri) /* I - Printer URI */ | |
5580 | { | |
f7deaa1a | 5581 | cupsd_printer_t *printer; /* Printer */ |
5582 | cupsd_job_t *job; /* New job */ | |
b423cd4c | 5583 | |
ef416fc2 | 5584 | |
b423cd4c | 5585 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con, |
5586 | con->http.fd, uri->values[0].string.text); | |
ef416fc2 | 5587 | |
f7deaa1a | 5588 | /* |
5589 | * Is the destination valid? | |
5590 | */ | |
5591 | ||
5592 | if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer)) | |
5593 | { | |
5594 | /* | |
5595 | * Bad URI... | |
5596 | */ | |
5597 | ||
5598 | send_ipp_status(con, IPP_NOT_FOUND, | |
5599 | _("The printer or class was not found.")); | |
5600 | return; | |
5601 | } | |
5602 | ||
ef416fc2 | 5603 | /* |
b423cd4c | 5604 | * Create the job object... |
ef416fc2 | 5605 | */ |
5606 | ||
f7deaa1a | 5607 | if ((job = add_job(con, printer, NULL)) == NULL) |
b423cd4c | 5608 | return; |
ef416fc2 | 5609 | |
09a101d6 | 5610 | job->pending_timeout = 1; |
5611 | ||
ef416fc2 | 5612 | /* |
5613 | * Save and log the job... | |
5614 | */ | |
f7deaa1a | 5615 | |
09a101d6 | 5616 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Queued on \"%s\" by \"%s\".", |
ef416fc2 | 5617 | job->id, job->dest, job->username); |
ef416fc2 | 5618 | } |
5619 | ||
5620 | ||
5621 | /* | |
5622 | * 'create_requested_array()' - Create an array for the requested-attributes. | |
5623 | */ | |
5624 | ||
5625 | static cups_array_t * /* O - Array of attributes or NULL */ | |
5626 | create_requested_array(ipp_t *request) /* I - IPP request */ | |
5627 | { | |
5628 | int i; /* Looping var */ | |
5629 | ipp_attribute_t *requested; /* requested-attributes attribute */ | |
5630 | cups_array_t *ra; /* Requested attributes array */ | |
5631 | char *value; /* Current value */ | |
5632 | ||
5633 | ||
5634 | /* | |
5635 | * Get the requested-attributes attribute, and return NULL if we don't | |
5636 | * have one... | |
5637 | */ | |
5638 | ||
5639 | if ((requested = ippFindAttribute(request, "requested-attributes", | |
5640 | IPP_TAG_KEYWORD)) == NULL) | |
5641 | return (NULL); | |
5642 | ||
5643 | /* | |
5644 | * If the attribute contains a single "all" keyword, return NULL... | |
5645 | */ | |
5646 | ||
5647 | if (requested->num_values == 1 && | |
5648 | !strcmp(requested->values[0].string.text, "all")) | |
5649 | return (NULL); | |
5650 | ||
5651 | /* | |
5652 | * Create an array using "strcmp" as the comparison function... | |
5653 | */ | |
5654 | ||
5655 | ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
5656 | ||
5657 | for (i = 0; i < requested->num_values; i ++) | |
5658 | { | |
5659 | value = requested->values[i].string.text; | |
5660 | ||
5661 | if (!strcmp(value, "job-template")) | |
5662 | { | |
5663 | cupsArrayAdd(ra, "copies"); | |
5664 | cupsArrayAdd(ra, "copies-default"); | |
5665 | cupsArrayAdd(ra, "copies-supported"); | |
5666 | cupsArrayAdd(ra, "finishings"); | |
5667 | cupsArrayAdd(ra, "finishings-default"); | |
5668 | cupsArrayAdd(ra, "finishings-supported"); | |
5669 | cupsArrayAdd(ra, "job-hold-until"); | |
5670 | cupsArrayAdd(ra, "job-hold-until-default"); | |
5671 | cupsArrayAdd(ra, "job-hold-until-supported"); | |
5672 | cupsArrayAdd(ra, "job-priority"); | |
5673 | cupsArrayAdd(ra, "job-priority-default"); | |
5674 | cupsArrayAdd(ra, "job-priority-supported"); | |
5675 | cupsArrayAdd(ra, "job-sheets"); | |
5676 | cupsArrayAdd(ra, "job-sheets-default"); | |
5677 | cupsArrayAdd(ra, "job-sheets-supported"); | |
5678 | cupsArrayAdd(ra, "media"); | |
5679 | cupsArrayAdd(ra, "media-default"); | |
5680 | cupsArrayAdd(ra, "media-supported"); | |
5681 | cupsArrayAdd(ra, "multiple-document-handling"); | |
5682 | cupsArrayAdd(ra, "multiple-document-handling-default"); | |
5683 | cupsArrayAdd(ra, "multiple-document-handling-supported"); | |
5684 | cupsArrayAdd(ra, "number-up"); | |
5685 | cupsArrayAdd(ra, "number-up-default"); | |
5686 | cupsArrayAdd(ra, "number-up-supported"); | |
5687 | cupsArrayAdd(ra, "orientation-requested"); | |
5688 | cupsArrayAdd(ra, "orientation-requested-default"); | |
5689 | cupsArrayAdd(ra, "orientation-requested-supported"); | |
5690 | cupsArrayAdd(ra, "page-ranges"); | |
5691 | cupsArrayAdd(ra, "page-ranges-supported"); | |
5692 | cupsArrayAdd(ra, "printer-resolution"); | |
5693 | cupsArrayAdd(ra, "printer-resolution-default"); | |
5694 | cupsArrayAdd(ra, "printer-resolution-supported"); | |
5695 | cupsArrayAdd(ra, "print-quality"); | |
5696 | cupsArrayAdd(ra, "print-quality-default"); | |
5697 | cupsArrayAdd(ra, "print-quality-supported"); | |
5698 | cupsArrayAdd(ra, "sides"); | |
5699 | cupsArrayAdd(ra, "sides-default"); | |
5700 | cupsArrayAdd(ra, "sides-supported"); | |
5701 | } | |
5702 | else if (!strcmp(value, "job-description")) | |
5703 | { | |
5704 | cupsArrayAdd(ra, "date-time-at-completed"); | |
5705 | cupsArrayAdd(ra, "date-time-at-creation"); | |
5706 | cupsArrayAdd(ra, "date-time-at-processing"); | |
5707 | cupsArrayAdd(ra, "job-detailed-status-message"); | |
5708 | cupsArrayAdd(ra, "job-document-access-errors"); | |
5709 | cupsArrayAdd(ra, "job-id"); | |
5710 | cupsArrayAdd(ra, "job-impressions"); | |
5711 | cupsArrayAdd(ra, "job-impressions-completed"); | |
5712 | cupsArrayAdd(ra, "job-k-octets"); | |
5713 | cupsArrayAdd(ra, "job-k-octets-processed"); | |
5714 | cupsArrayAdd(ra, "job-media-sheets"); | |
5715 | cupsArrayAdd(ra, "job-media-sheets-completed"); | |
5716 | cupsArrayAdd(ra, "job-message-from-operator"); | |
5717 | cupsArrayAdd(ra, "job-more-info"); | |
5718 | cupsArrayAdd(ra, "job-name"); | |
5719 | cupsArrayAdd(ra, "job-originating-user-name"); | |
5720 | cupsArrayAdd(ra, "job-printer-up-time"); | |
5721 | cupsArrayAdd(ra, "job-printer-uri"); | |
5722 | cupsArrayAdd(ra, "job-state"); | |
5723 | cupsArrayAdd(ra, "job-state-message"); | |
5724 | cupsArrayAdd(ra, "job-state-reasons"); | |
5725 | cupsArrayAdd(ra, "job-uri"); | |
5726 | cupsArrayAdd(ra, "number-of-documents"); | |
5727 | cupsArrayAdd(ra, "number-of-intervening-jobs"); | |
5728 | cupsArrayAdd(ra, "output-device-assigned"); | |
5729 | cupsArrayAdd(ra, "time-at-completed"); | |
5730 | cupsArrayAdd(ra, "time-at-creation"); | |
5731 | cupsArrayAdd(ra, "time-at-processing"); | |
5732 | } | |
5733 | else if (!strcmp(value, "printer-description")) | |
5734 | { | |
5735 | cupsArrayAdd(ra, "charset-configured"); | |
5736 | cupsArrayAdd(ra, "charset-supported"); | |
5737 | cupsArrayAdd(ra, "color-supported"); | |
5738 | cupsArrayAdd(ra, "compression-supported"); | |
5739 | cupsArrayAdd(ra, "document-format-default"); | |
5740 | cupsArrayAdd(ra, "document-format-supported"); | |
5741 | cupsArrayAdd(ra, "generated-natural-language-supported"); | |
5742 | cupsArrayAdd(ra, "ipp-versions-supported"); | |
5743 | cupsArrayAdd(ra, "job-impressions-supported"); | |
5744 | cupsArrayAdd(ra, "job-k-octets-supported"); | |
5745 | cupsArrayAdd(ra, "job-media-sheets-supported"); | |
5746 | cupsArrayAdd(ra, "multiple-document-jobs-supported"); | |
5747 | cupsArrayAdd(ra, "multiple-operation-time-out"); | |
5748 | cupsArrayAdd(ra, "natural-language-configured"); | |
5749 | cupsArrayAdd(ra, "notify-attributes-supported"); | |
5750 | cupsArrayAdd(ra, "notify-lease-duration-default"); | |
5751 | cupsArrayAdd(ra, "notify-lease-duration-supported"); | |
5752 | cupsArrayAdd(ra, "notify-max-events-supported"); | |
f301802f | 5753 | cupsArrayAdd(ra, "notify-events-default"); |
5754 | cupsArrayAdd(ra, "notify-events-supported"); | |
ef416fc2 | 5755 | cupsArrayAdd(ra, "notify-pull-method-supported"); |
5756 | cupsArrayAdd(ra, "notify-schemes-supported"); | |
5757 | cupsArrayAdd(ra, "operations-supported"); | |
5758 | cupsArrayAdd(ra, "pages-per-minute"); | |
5759 | cupsArrayAdd(ra, "pages-per-minute-color"); | |
5760 | cupsArrayAdd(ra, "pdl-override-supported"); | |
323c5de1 | 5761 | cupsArrayAdd(ra, "printer-alert"); |
5762 | cupsArrayAdd(ra, "printer-alert-description"); | |
ef416fc2 | 5763 | cupsArrayAdd(ra, "printer-current-time"); |
5764 | cupsArrayAdd(ra, "printer-driver-installer"); | |
5765 | cupsArrayAdd(ra, "printer-info"); | |
5766 | cupsArrayAdd(ra, "printer-is-accepting-jobs"); | |
5767 | cupsArrayAdd(ra, "printer-location"); | |
5768 | cupsArrayAdd(ra, "printer-make-and-model"); | |
5769 | cupsArrayAdd(ra, "printer-message-from-operator"); | |
5770 | cupsArrayAdd(ra, "printer-more-info"); | |
5771 | cupsArrayAdd(ra, "printer-more-info-manufacturer"); | |
5772 | cupsArrayAdd(ra, "printer-name"); | |
5773 | cupsArrayAdd(ra, "printer-state"); | |
5774 | cupsArrayAdd(ra, "printer-state-message"); | |
5775 | cupsArrayAdd(ra, "printer-state-reasons"); | |
5776 | cupsArrayAdd(ra, "printer-up-time"); | |
5777 | cupsArrayAdd(ra, "printer-uri-supported"); | |
5778 | cupsArrayAdd(ra, "queued-job-count"); | |
5779 | cupsArrayAdd(ra, "reference-uri-schemes-supported"); | |
5780 | cupsArrayAdd(ra, "uri-authentication-supported"); | |
5781 | cupsArrayAdd(ra, "uri-security-supported"); | |
5782 | } | |
f7deaa1a | 5783 | else if (!strcmp(value, "printer-defaults")) |
5784 | { | |
5785 | char *name; /* Option name */ | |
5786 | ||
5787 | ||
5788 | for (name = (char *)cupsArrayFirst(CommonDefaults); | |
5789 | name; | |
5790 | name = (char *)cupsArrayNext(CommonDefaults)) | |
5791 | cupsArrayAdd(ra, name); | |
5792 | } | |
ef416fc2 | 5793 | else if (!strcmp(value, "subscription-template")) |
5794 | { | |
5795 | cupsArrayAdd(ra, "notify-attributes"); | |
5796 | cupsArrayAdd(ra, "notify-charset"); | |
5797 | cupsArrayAdd(ra, "notify-events"); | |
5798 | cupsArrayAdd(ra, "notify-lease-duration"); | |
5799 | cupsArrayAdd(ra, "notify-natural-language"); | |
5800 | cupsArrayAdd(ra, "notify-pull-method"); | |
5801 | cupsArrayAdd(ra, "notify-recipient-uri"); | |
5802 | cupsArrayAdd(ra, "notify-time-interval"); | |
5803 | cupsArrayAdd(ra, "notify-user-data"); | |
5804 | } | |
5805 | else | |
5806 | cupsArrayAdd(ra, value); | |
5807 | } | |
5808 | ||
5809 | return (ra); | |
5810 | } | |
5811 | ||
5812 | ||
5813 | /* | |
5814 | * 'create_subscription()' - Create a notification subscription. | |
5815 | */ | |
5816 | ||
5817 | static void | |
5818 | create_subscription( | |
5819 | cupsd_client_t *con, /* I - Client connection */ | |
5820 | ipp_attribute_t *uri) /* I - Printer URI */ | |
5821 | { | |
5822 | http_status_t status; /* Policy status */ | |
5823 | int i; /* Looping var */ | |
5824 | ipp_attribute_t *attr; /* Current attribute */ | |
bc44d920 | 5825 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ed486911 | 5826 | char scheme[HTTP_MAX_URI], |
5827 | /* Scheme portion of URI */ | |
ef416fc2 | 5828 | userpass[HTTP_MAX_URI], |
5829 | /* Username portion of URI */ | |
5830 | host[HTTP_MAX_URI], | |
5831 | /* Host portion of URI */ | |
5832 | resource[HTTP_MAX_URI]; | |
5833 | /* Resource portion of URI */ | |
5834 | int port; /* Port portion of URI */ | |
5835 | cupsd_printer_t *printer; /* Printer/class */ | |
5836 | cupsd_job_t *job; /* Job */ | |
5837 | int jobid; /* Job ID */ | |
5838 | cupsd_subscription_t *sub; /* Subscription object */ | |
bc44d920 | 5839 | const char *username, /* requesting-user-name or |
5840 | authenticated username */ | |
ef416fc2 | 5841 | *recipient, /* notify-recipient-uri */ |
5842 | *pullmethod; /* notify-pull-method */ | |
5843 | ipp_attribute_t *user_data; /* notify-user-data */ | |
5844 | int interval, /* notify-time-interval */ | |
5845 | lease; /* notify-lease-duration */ | |
5846 | unsigned mask; /* notify-events */ | |
f7deaa1a | 5847 | ipp_attribute_t *notify_events,/* notify-events(-default) */ |
5848 | *notify_lease; /* notify-lease-duration(-default) */ | |
ef416fc2 | 5849 | |
5850 | ||
bd7854cb | 5851 | #ifdef DEBUG |
5852 | for (attr = con->request->attrs; attr; attr = attr->next) | |
5853 | { | |
5854 | if (attr->group_tag != IPP_TAG_ZERO) | |
3dfe78b3 | 5855 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "g%04x v%04x %s", attr->group_tag, |
bd7854cb | 5856 | attr->value_tag, attr->name); |
5857 | else | |
3dfe78b3 | 5858 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "----SEP----"); |
bd7854cb | 5859 | } |
5860 | #endif /* DEBUG */ | |
5861 | ||
ef416fc2 | 5862 | /* |
5863 | * Is the destination valid? | |
5864 | */ | |
5865 | ||
fa73b229 | 5866 | cupsdLogMessage(CUPSD_LOG_DEBUG, |
5867 | "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")", | |
5868 | con, con->http.fd, uri->values[0].string.text); | |
5869 | ||
ed486911 | 5870 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
5871 | sizeof(scheme), userpass, sizeof(userpass), host, | |
a4d04587 | 5872 | sizeof(host), &port, resource, sizeof(resource)); |
ef416fc2 | 5873 | |
5874 | if (!strcmp(resource, "/")) | |
5875 | { | |
ef416fc2 | 5876 | dtype = (cups_ptype_t)0; |
5877 | printer = NULL; | |
5878 | } | |
5879 | else if (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10) | |
5880 | { | |
ef416fc2 | 5881 | dtype = (cups_ptype_t)0; |
5882 | printer = NULL; | |
5883 | } | |
5884 | else if (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9) | |
5885 | { | |
ef416fc2 | 5886 | dtype = CUPS_PRINTER_CLASS; |
5887 | printer = NULL; | |
5888 | } | |
f7deaa1a | 5889 | else if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 5890 | { |
5891 | /* | |
5892 | * Bad URI... | |
5893 | */ | |
5894 | ||
5895 | send_ipp_status(con, IPP_NOT_FOUND, | |
5896 | _("The printer or class was not found.")); | |
5897 | return; | |
5898 | } | |
5899 | ||
5900 | /* | |
5901 | * Check policy... | |
5902 | */ | |
5903 | ||
5904 | if (printer) | |
5905 | { | |
f7deaa1a | 5906 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, |
5907 | NULL)) != HTTP_OK) | |
ef416fc2 | 5908 | { |
f899b121 | 5909 | send_http_error(con, status, printer); |
ef416fc2 | 5910 | return; |
5911 | } | |
5912 | } | |
5913 | else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
5914 | { | |
f899b121 | 5915 | send_http_error(con, status, NULL); |
ef416fc2 | 5916 | return; |
5917 | } | |
5918 | ||
5919 | /* | |
5920 | * Get the user that is requesting the subscription... | |
5921 | */ | |
5922 | ||
e00b005a | 5923 | username = get_username(con); |
ef416fc2 | 5924 | |
5925 | /* | |
5926 | * Find the first subscription group attribute; return if we have | |
5927 | * none... | |
5928 | */ | |
5929 | ||
5930 | for (attr = con->request->attrs; attr; attr = attr->next) | |
5931 | if (attr->group_tag == IPP_TAG_SUBSCRIPTION) | |
5932 | break; | |
5933 | ||
5934 | if (!attr) | |
5935 | { | |
5936 | send_ipp_status(con, IPP_BAD_REQUEST, | |
5937 | _("No subscription attributes in request!")); | |
5938 | return; | |
5939 | } | |
5940 | ||
5941 | /* | |
5942 | * Process the subscription attributes in the request... | |
5943 | */ | |
5944 | ||
fa73b229 | 5945 | con->response->request.status.status_code = IPP_BAD_REQUEST; |
5946 | ||
ef416fc2 | 5947 | while (attr) |
5948 | { | |
5949 | recipient = NULL; | |
5950 | pullmethod = NULL; | |
5951 | user_data = NULL; | |
5952 | interval = 0; | |
5953 | lease = DefaultLeaseDuration; | |
5954 | jobid = 0; | |
5955 | mask = CUPSD_EVENT_NONE; | |
5956 | ||
f7deaa1a | 5957 | if (printer) |
5958 | { | |
5959 | notify_events = ippFindAttribute(printer->attrs, "notify-events-default", | |
5960 | IPP_TAG_KEYWORD); | |
5961 | notify_lease = ippFindAttribute(printer->attrs, | |
5962 | "notify-lease-duration-default", | |
5963 | IPP_TAG_INTEGER); | |
5964 | ||
5965 | if (notify_lease) | |
5966 | lease = notify_lease->values[0].integer; | |
5967 | } | |
5968 | else | |
5969 | { | |
5970 | notify_events = NULL; | |
5971 | notify_lease = NULL; | |
5972 | } | |
5973 | ||
ef416fc2 | 5974 | while (attr && attr->group_tag != IPP_TAG_ZERO) |
5975 | { | |
7594b224 | 5976 | if (!strcmp(attr->name, "notify-recipient-uri") && |
ef416fc2 | 5977 | attr->value_tag == IPP_TAG_URI) |
ed486911 | 5978 | { |
5979 | /* | |
5980 | * Validate the recipient scheme against the ServerBin/notifier | |
5981 | * directory... | |
5982 | */ | |
5983 | ||
5984 | char notifier[1024]; /* Notifier filename */ | |
5985 | ||
5986 | ||
ef416fc2 | 5987 | recipient = attr->values[0].string.text; |
ed486911 | 5988 | |
8ca02f3c | 5989 | if (httpSeparateURI(HTTP_URI_CODING_ALL, recipient, |
5990 | scheme, sizeof(scheme), userpass, sizeof(userpass), | |
5991 | host, sizeof(host), &port, | |
5992 | resource, sizeof(resource)) < HTTP_URI_OK) | |
ed486911 | 5993 | { |
5994 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
7594b224 | 5995 | _("Bad notify-recipient-uri URI \"%s\"!"), recipient); |
ed486911 | 5996 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, |
5997 | "notify-status-code", IPP_URI_SCHEME); | |
5998 | return; | |
5999 | } | |
6000 | ||
6001 | snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin, | |
6002 | scheme); | |
6003 | if (access(notifier, X_OK)) | |
6004 | { | |
6005 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
bc44d920 | 6006 | _("notify-recipient-uri URI \"%s\" uses unknown " |
6007 | "scheme!"), recipient); | |
ed486911 | 6008 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, |
6009 | "notify-status-code", IPP_URI_SCHEME); | |
6010 | return; | |
6011 | } | |
3dfe78b3 MS |
6012 | |
6013 | if (!strcmp(scheme, "rss") && !check_rss_recipient(recipient)) | |
6014 | { | |
6015 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
6016 | _("notify-recipient-uri URI \"%s\" is already used!"), | |
6017 | recipient); | |
6018 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
6019 | "notify-status-code", IPP_ATTRIBUTES); | |
6020 | return; | |
6021 | } | |
ed486911 | 6022 | } |
ef416fc2 | 6023 | else if (!strcmp(attr->name, "notify-pull-method") && |
6024 | attr->value_tag == IPP_TAG_KEYWORD) | |
ed486911 | 6025 | { |
ef416fc2 | 6026 | pullmethod = attr->values[0].string.text; |
ed486911 | 6027 | |
6028 | if (strcmp(pullmethod, "ippget")) | |
6029 | { | |
6030 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
6031 | _("Bad notify-pull-method \"%s\"!"), pullmethod); | |
6032 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, | |
6033 | "notify-status-code", IPP_ATTRIBUTES); | |
6034 | return; | |
6035 | } | |
6036 | } | |
ef416fc2 | 6037 | else if (!strcmp(attr->name, "notify-charset") && |
6038 | attr->value_tag == IPP_TAG_CHARSET && | |
6039 | strcmp(attr->values[0].string.text, "us-ascii") && | |
6040 | strcmp(attr->values[0].string.text, "utf-8")) | |
6041 | { | |
6042 | send_ipp_status(con, IPP_CHARSET, | |
6043 | _("Character set \"%s\" not supported!"), | |
6044 | attr->values[0].string.text); | |
6045 | return; | |
6046 | } | |
6047 | else if (!strcmp(attr->name, "notify-natural-language") && | |
6048 | (attr->value_tag != IPP_TAG_LANGUAGE || | |
6049 | strcmp(attr->values[0].string.text, DefaultLanguage))) | |
6050 | { | |
6051 | send_ipp_status(con, IPP_CHARSET, | |
6052 | _("Language \"%s\" not supported!"), | |
6053 | attr->values[0].string.text); | |
6054 | return; | |
6055 | } | |
6056 | else if (!strcmp(attr->name, "notify-user-data") && | |
6057 | attr->value_tag == IPP_TAG_STRING) | |
6058 | { | |
6059 | if (attr->num_values > 1 || attr->values[0].unknown.length > 63) | |
6060 | { | |
6061 | send_ipp_status(con, IPP_REQUEST_VALUE, | |
6062 | _("The notify-user-data value is too large " | |
6063 | "(%d > 63 octets)!"), | |
6064 | attr->values[0].unknown.length); | |
6065 | return; | |
6066 | } | |
6067 | ||
6068 | user_data = attr; | |
6069 | } | |
6070 | else if (!strcmp(attr->name, "notify-events") && | |
6071 | attr->value_tag == IPP_TAG_KEYWORD) | |
f7deaa1a | 6072 | notify_events = attr; |
ef416fc2 | 6073 | else if (!strcmp(attr->name, "notify-lease-duration") && |
6074 | attr->value_tag == IPP_TAG_INTEGER) | |
6075 | lease = attr->values[0].integer; | |
6076 | else if (!strcmp(attr->name, "notify-time-interval") && | |
6077 | attr->value_tag == IPP_TAG_INTEGER) | |
6078 | interval = attr->values[0].integer; | |
6079 | else if (!strcmp(attr->name, "notify-job-id") && | |
6080 | attr->value_tag == IPP_TAG_INTEGER) | |
6081 | jobid = attr->values[0].integer; | |
6082 | ||
6083 | attr = attr->next; | |
6084 | } | |
6085 | ||
f7deaa1a | 6086 | if (notify_events) |
6087 | { | |
6088 | for (i = 0; i < notify_events->num_values; i ++) | |
6089 | mask |= cupsdEventValue(notify_events->values[i].string.text); | |
6090 | } | |
6091 | ||
bd7854cb | 6092 | if (recipient) |
6093 | cupsdLogMessage(CUPSD_LOG_DEBUG, "recipient=\"%s\"", recipient); | |
6094 | if (pullmethod) | |
6095 | cupsdLogMessage(CUPSD_LOG_DEBUG, "pullmethod=\"%s\"", pullmethod); | |
6096 | cupsdLogMessage(CUPSD_LOG_DEBUG, "notify-lease-duration=%d", lease); | |
6097 | cupsdLogMessage(CUPSD_LOG_DEBUG, "notify-time-interval=%d", interval); | |
fa73b229 | 6098 | |
ef416fc2 | 6099 | if (!recipient && !pullmethod) |
6100 | break; | |
6101 | ||
6102 | if (mask == CUPSD_EVENT_NONE) | |
6103 | { | |
6104 | if (jobid) | |
6105 | mask = CUPSD_EVENT_JOB_COMPLETED; | |
6106 | else if (printer) | |
6107 | mask = CUPSD_EVENT_PRINTER_STATE_CHANGED; | |
6108 | else | |
6109 | { | |
6110 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6111 | _("notify-events not specified!")); | |
6112 | return; | |
6113 | } | |
6114 | } | |
6115 | ||
bd7854cb | 6116 | if (MaxLeaseDuration && (lease == 0 || lease > MaxLeaseDuration)) |
ef416fc2 | 6117 | { |
6118 | cupsdLogMessage(CUPSD_LOG_INFO, | |
6119 | "create_subscription: Limiting notify-lease-duration to " | |
6120 | "%d seconds.", | |
6121 | MaxLeaseDuration); | |
6122 | lease = MaxLeaseDuration; | |
6123 | } | |
6124 | ||
6125 | if (jobid) | |
6126 | { | |
6127 | if ((job = cupsdFindJob(jobid)) == NULL) | |
6128 | { | |
6129 | send_ipp_status(con, IPP_NOT_FOUND, _("Job %d not found!"), jobid); | |
6130 | return; | |
6131 | } | |
6132 | } | |
6133 | else | |
6134 | job = NULL; | |
6135 | ||
6136 | sub = cupsdAddSubscription(mask, printer, job, recipient, 0); | |
6137 | ||
fa73b229 | 6138 | if (job) |
6139 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added subscription %d for job %d", | |
6140 | sub->id, job->id); | |
6141 | else if (printer) | |
6142 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
6143 | "Added subscription %d for printer \"%s\"", | |
6144 | sub->id, printer->name); | |
6145 | else | |
6146 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added subscription %d for server", | |
6147 | sub->id); | |
6148 | ||
ef416fc2 | 6149 | sub->interval = interval; |
6150 | sub->lease = lease; | |
bd7854cb | 6151 | sub->expire = lease ? time(NULL) + lease : 0; |
ef416fc2 | 6152 | |
6153 | cupsdSetString(&sub->owner, username); | |
6154 | ||
6155 | if (user_data) | |
6156 | { | |
6157 | sub->user_data_len = user_data->values[0].unknown.length; | |
6158 | memcpy(sub->user_data, user_data->values[0].unknown.data, | |
6159 | sub->user_data_len); | |
6160 | } | |
6161 | ||
6162 | ippAddSeparator(con->response); | |
6163 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
6164 | "notify-subscription-id", sub->id); | |
6165 | ||
fa73b229 | 6166 | con->response->request.status.status_code = IPP_OK; |
6167 | ||
ef416fc2 | 6168 | if (attr) |
6169 | attr = attr->next; | |
6170 | } | |
6171 | ||
3dfe78b3 | 6172 | cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS); |
ef416fc2 | 6173 | } |
6174 | ||
6175 | ||
6176 | /* | |
6177 | * 'delete_printer()' - Remove a printer or class from the system. | |
6178 | */ | |
6179 | ||
6180 | static void | |
6181 | delete_printer(cupsd_client_t *con, /* I - Client connection */ | |
6182 | ipp_attribute_t *uri) /* I - URI of printer or class */ | |
6183 | { | |
6184 | http_status_t status; /* Policy status */ | |
bc44d920 | 6185 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 6186 | cupsd_printer_t *printer; /* Printer/class */ |
6187 | char filename[1024]; /* Script/PPD filename */ | |
6188 | ||
6189 | ||
6190 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "delete_printer(%p[%d], %s)", con, | |
6191 | con->http.fd, uri->values[0].string.text); | |
6192 | ||
6193 | /* | |
6194 | * Do we have a valid URI? | |
6195 | */ | |
6196 | ||
f7deaa1a | 6197 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 6198 | { |
6199 | /* | |
6200 | * Bad URI... | |
6201 | */ | |
6202 | ||
6203 | send_ipp_status(con, IPP_NOT_FOUND, | |
6204 | _("The printer or class was not found.")); | |
6205 | return; | |
6206 | } | |
6207 | ||
6208 | /* | |
6209 | * Check policy... | |
6210 | */ | |
6211 | ||
6212 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6213 | { | |
f899b121 | 6214 | send_http_error(con, status, NULL); |
ef416fc2 | 6215 | return; |
6216 | } | |
6217 | ||
6218 | /* | |
6219 | * Remove old jobs... | |
6220 | */ | |
6221 | ||
f7deaa1a | 6222 | cupsdCancelJobs(printer->name, NULL, 1); |
ef416fc2 | 6223 | |
6224 | /* | |
6225 | * Remove old subscriptions and send a "deleted printer" event... | |
6226 | */ | |
6227 | ||
6228 | cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, printer, NULL, | |
6229 | "%s \"%s\" deleted by \"%s\".", | |
6230 | (dtype & CUPS_PRINTER_CLASS) ? "Class" : "Printer", | |
f7deaa1a | 6231 | printer->name, get_username(con)); |
ef416fc2 | 6232 | |
6233 | cupsdExpireSubscriptions(printer, NULL); | |
f7deaa1a | 6234 | |
ef416fc2 | 6235 | /* |
6236 | * Remove any old PPD or script files... | |
6237 | */ | |
6238 | ||
f7deaa1a | 6239 | snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, |
6240 | printer->name); | |
ef416fc2 | 6241 | unlink(filename); |
6242 | ||
f7deaa1a | 6243 | snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, |
6244 | printer->name); | |
ef416fc2 | 6245 | unlink(filename); |
6246 | ||
568fa3fa MS |
6247 | #ifdef __APPLE__ |
6248 | /* | |
6249 | * Unregister color profiles... | |
6250 | */ | |
6251 | ||
6252 | apple_unregister_profiles(printer); | |
6253 | #endif /* __APPLE__ */ | |
6254 | ||
ef416fc2 | 6255 | if (dtype & CUPS_PRINTER_CLASS) |
6256 | { | |
f7deaa1a | 6257 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".", |
6258 | printer->name, get_username(con)); | |
ef416fc2 | 6259 | |
6260 | cupsdDeletePrinter(printer, 0); | |
3dfe78b3 | 6261 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
ef416fc2 | 6262 | } |
6263 | else | |
6264 | { | |
f7deaa1a | 6265 | cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".", |
6266 | printer->name, get_username(con)); | |
ef416fc2 | 6267 | |
6268 | cupsdDeletePrinter(printer, 0); | |
3dfe78b3 | 6269 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
ef416fc2 | 6270 | } |
6271 | ||
3dfe78b3 | 6272 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
ef416fc2 | 6273 | |
6274 | /* | |
6275 | * Return with no errors... | |
6276 | */ | |
6277 | ||
6278 | con->response->request.status.status_code = IPP_OK; | |
6279 | } | |
6280 | ||
6281 | ||
6282 | /* | |
6283 | * 'get_default()' - Get the default destination. | |
6284 | */ | |
6285 | ||
6286 | static void | |
6287 | get_default(cupsd_client_t *con) /* I - Client connection */ | |
6288 | { | |
fa73b229 | 6289 | http_status_t status; /* Policy status */ |
6290 | cups_array_t *ra; /* Requested attributes array */ | |
ef416fc2 | 6291 | |
6292 | ||
6293 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_default(%p[%d])", con, con->http.fd); | |
6294 | ||
6295 | /* | |
6296 | * Check policy... | |
6297 | */ | |
6298 | ||
6299 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6300 | { | |
f899b121 | 6301 | send_http_error(con, status, NULL); |
ef416fc2 | 6302 | return; |
6303 | } | |
6304 | ||
fa73b229 | 6305 | if (DefaultPrinter) |
ef416fc2 | 6306 | { |
fa73b229 | 6307 | ra = create_requested_array(con->request); |
ef416fc2 | 6308 | |
fa73b229 | 6309 | copy_printer_attrs(con, DefaultPrinter, ra); |
ef416fc2 | 6310 | |
fa73b229 | 6311 | cupsArrayDelete(ra); |
ef416fc2 | 6312 | |
fa73b229 | 6313 | con->response->request.status.status_code = IPP_OK; |
ef416fc2 | 6314 | } |
6315 | else | |
6316 | send_ipp_status(con, IPP_NOT_FOUND, _("No default printer")); | |
6317 | } | |
6318 | ||
6319 | ||
6320 | /* | |
6321 | * 'get_devices()' - Get the list of available devices on the local system. | |
6322 | */ | |
6323 | ||
6324 | static void | |
6325 | get_devices(cupsd_client_t *con) /* I - Client connection */ | |
6326 | { | |
6327 | http_status_t status; /* Policy status */ | |
ae71f5de MS |
6328 | ipp_attribute_t *limit, /* limit attribute */ |
6329 | *timeout, /* timeout attribute */ | |
6330 | *requested, /* requested-attributes attribute */ | |
6331 | *exclude; /* exclude-schemes attribute */ | |
ef416fc2 | 6332 | char command[1024], /* cups-deviced command */ |
6333 | options[1024], /* Options to pass to command */ | |
ae71f5de | 6334 | requested_str[256], |
89d46774 | 6335 | /* String for requested attributes */ |
ae71f5de MS |
6336 | exclude_str[512]; |
6337 | /* String for excluded attributes */ | |
ef416fc2 | 6338 | |
6339 | ||
6340 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_devices(%p[%d])", con, con->http.fd); | |
6341 | ||
6342 | /* | |
6343 | * Check policy... | |
6344 | */ | |
6345 | ||
6346 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6347 | { | |
f899b121 | 6348 | send_http_error(con, status, NULL); |
ef416fc2 | 6349 | return; |
6350 | } | |
6351 | ||
6352 | /* | |
6353 | * Run cups-deviced command with the given options... | |
6354 | */ | |
6355 | ||
ae71f5de MS |
6356 | limit = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER); |
6357 | timeout = ippFindAttribute(con->request, "timeout", IPP_TAG_INTEGER); | |
ef416fc2 | 6358 | requested = ippFindAttribute(con->request, "requested-attributes", |
6359 | IPP_TAG_KEYWORD); | |
ae71f5de | 6360 | exclude = ippFindAttribute(con->request, "exclude-schemes", IPP_TAG_NAME); |
ef416fc2 | 6361 | |
6362 | if (requested) | |
89d46774 | 6363 | url_encode_attr(requested, requested_str, sizeof(requested_str)); |
ef416fc2 | 6364 | else |
89d46774 | 6365 | strlcpy(requested_str, "requested-attributes=all", sizeof(requested_str)); |
ef416fc2 | 6366 | |
ae71f5de MS |
6367 | if (exclude) |
6368 | url_encode_attr(exclude, exclude_str, sizeof(exclude_str)); | |
6369 | else | |
6370 | exclude_str[0] = '\0'; | |
6371 | ||
ef416fc2 | 6372 | snprintf(command, sizeof(command), "%s/daemon/cups-deviced", ServerBin); |
6373 | snprintf(options, sizeof(options), | |
ae71f5de | 6374 | "%d+%d+%d+%d+%s%s%s", |
ef416fc2 | 6375 | con->request->request.op.request_id, |
ae71f5de MS |
6376 | limit ? limit->values[0].integer : 0, |
6377 | timeout ? timeout->values[0].integer : 10, | |
6378 | (int)User, | |
6379 | requested_str, | |
6380 | exclude_str[0] ? "%20" : "", exclude_str); | |
ef416fc2 | 6381 | |
6382 | if (cupsdSendCommand(con, command, options, 1)) | |
6383 | { | |
6384 | /* | |
6385 | * Command started successfully, don't send an IPP response here... | |
6386 | */ | |
6387 | ||
6388 | ippDelete(con->response); | |
6389 | con->response = NULL; | |
6390 | } | |
6391 | else | |
6392 | { | |
6393 | /* | |
6394 | * Command failed, return "internal error" so the user knows something | |
6395 | * went wrong... | |
6396 | */ | |
6397 | ||
6398 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
6399 | _("cups-deviced failed to execute.")); | |
6400 | } | |
6401 | } | |
6402 | ||
6403 | ||
2e4ff8af MS |
6404 | /* |
6405 | * 'get_document()' - Get a copy of a job file. | |
6406 | */ | |
6407 | ||
6408 | static void | |
6409 | get_document(cupsd_client_t *con, /* I - Client connection */ | |
6410 | ipp_attribute_t *uri) /* I - Job URI */ | |
6411 | { | |
6412 | http_status_t status; /* Policy status */ | |
6413 | ipp_attribute_t *attr; /* Current attribute */ | |
6414 | int jobid; /* Job ID */ | |
6415 | int docnum; /* Document number */ | |
6416 | cupsd_job_t *job; /* Current job */ | |
6417 | char method[HTTP_MAX_URI], /* Method portion of URI */ | |
6418 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
6419 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
6420 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
6421 | int port; /* Port portion of URI */ | |
6422 | char filename[1024], /* Filename for document */ | |
6423 | format[1024]; /* Format for document */ | |
6424 | ||
6425 | ||
6426 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_document(%p[%d], %s)", con, | |
6427 | con->http.fd, uri->values[0].string.text); | |
6428 | ||
6429 | /* | |
6430 | * See if we have a job URI or a printer URI... | |
6431 | */ | |
6432 | ||
6433 | if (!strcmp(uri->name, "printer-uri")) | |
6434 | { | |
6435 | /* | |
6436 | * Got a printer URI; see if we also have a job-id attribute... | |
6437 | */ | |
6438 | ||
6439 | if ((attr = ippFindAttribute(con->request, "job-id", | |
6440 | IPP_TAG_INTEGER)) == NULL) | |
6441 | { | |
6442 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6443 | _("Got a printer-uri attribute but no job-id!")); | |
6444 | return; | |
6445 | } | |
6446 | ||
6447 | jobid = attr->values[0].integer; | |
6448 | } | |
6449 | else | |
6450 | { | |
6451 | /* | |
6452 | * Got a job URI; parse it to get the job ID... | |
6453 | */ | |
6454 | ||
6455 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, | |
6456 | sizeof(method), username, sizeof(username), host, | |
6457 | sizeof(host), &port, resource, sizeof(resource)); | |
6458 | ||
6459 | if (strncmp(resource, "/jobs/", 6)) | |
6460 | { | |
6461 | /* | |
6462 | * Not a valid URI! | |
6463 | */ | |
6464 | ||
6465 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6466 | _("Bad job-uri attribute \"%s\"!"), | |
6467 | uri->values[0].string.text); | |
6468 | return; | |
6469 | } | |
6470 | ||
6471 | jobid = atoi(resource + 6); | |
6472 | } | |
6473 | ||
6474 | /* | |
6475 | * See if the job exists... | |
6476 | */ | |
6477 | ||
6478 | if ((job = cupsdFindJob(jobid)) == NULL) | |
6479 | { | |
6480 | /* | |
6481 | * Nope - return a "not found" error... | |
6482 | */ | |
6483 | ||
6484 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
6485 | return; | |
6486 | } | |
6487 | ||
6488 | /* | |
6489 | * Check policy... | |
6490 | */ | |
6491 | ||
6492 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6493 | { | |
6494 | send_http_error(con, status, NULL); | |
6495 | return; | |
6496 | } | |
6497 | ||
6498 | /* | |
6499 | * Get the document number... | |
6500 | */ | |
6501 | ||
6502 | if ((attr = ippFindAttribute(con->request, "document-number", | |
6503 | IPP_TAG_INTEGER)) == NULL) | |
6504 | { | |
6505 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6506 | _("Missing document-number attribute!")); | |
6507 | return; | |
6508 | } | |
6509 | ||
6510 | if ((docnum = attr->values[0].integer) < 1 || docnum > job->num_files || | |
6511 | attr->num_values > 1) | |
6512 | { | |
6513 | send_ipp_status(con, IPP_NOT_FOUND, _("Document %d not found in job %d."), | |
6514 | docnum, jobid); | |
6515 | return; | |
6516 | } | |
6517 | ||
6518 | snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, jobid, | |
6519 | docnum); | |
6520 | if ((con->file = open(filename, O_RDONLY)) == -1) | |
6521 | { | |
6522 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
6523 | "Unable to open document %d in job %d - %s", docnum, jobid, | |
6524 | strerror(errno)); | |
6525 | send_ipp_status(con, IPP_NOT_FOUND, | |
6526 | _("Unable to open document %d in job %d!"), docnum, jobid); | |
6527 | return; | |
6528 | } | |
6529 | ||
6530 | fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC); | |
6531 | ||
6532 | cupsdLoadJob(job); | |
6533 | ||
6534 | snprintf(format, sizeof(format), "%s/%s", job->filetypes[docnum - 1]->super, | |
6535 | job->filetypes[docnum - 1]->type); | |
6536 | ||
6537 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format", | |
6538 | NULL, format); | |
6539 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "document-number", | |
6540 | docnum); | |
6541 | if ((attr = ippFindAttribute(job->attrs, "document-name", | |
6542 | IPP_TAG_NAME)) != NULL) | |
6543 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "document-name", | |
6544 | NULL, attr->values[0].string.text); | |
6545 | } | |
6546 | ||
6547 | ||
ef416fc2 | 6548 | /* |
fa73b229 | 6549 | * 'get_job_attrs()' - Get job attributes. |
ef416fc2 | 6550 | */ |
6551 | ||
6552 | static void | |
fa73b229 | 6553 | get_job_attrs(cupsd_client_t *con, /* I - Client connection */ |
6554 | ipp_attribute_t *uri) /* I - Job URI */ | |
ef416fc2 | 6555 | { |
6556 | http_status_t status; /* Policy status */ | |
fa73b229 | 6557 | ipp_attribute_t *attr; /* Current attribute */ |
6558 | int jobid; /* Job ID */ | |
6559 | cupsd_job_t *job; /* Current job */ | |
ef416fc2 | 6560 | char method[HTTP_MAX_URI], /* Method portion of URI */ |
6561 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
6562 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
6563 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
6564 | int port; /* Port portion of URI */ | |
fa73b229 | 6565 | cups_array_t *ra; /* Requested attributes array */ |
ef416fc2 | 6566 | |
6567 | ||
fa73b229 | 6568 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_job_attrs(%p[%d], %s)", con, |
6569 | con->http.fd, uri->values[0].string.text); | |
ef416fc2 | 6570 | |
6571 | /* | |
fa73b229 | 6572 | * See if we have a job URI or a printer URI... |
6573 | */ | |
6574 | ||
6575 | if (!strcmp(uri->name, "printer-uri")) | |
6576 | { | |
6577 | /* | |
6578 | * Got a printer URI; see if we also have a job-id attribute... | |
6579 | */ | |
6580 | ||
6581 | if ((attr = ippFindAttribute(con->request, "job-id", | |
6582 | IPP_TAG_INTEGER)) == NULL) | |
6583 | { | |
6584 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6585 | _("Got a printer-uri attribute but no job-id!")); | |
6586 | return; | |
6587 | } | |
6588 | ||
6589 | jobid = attr->values[0].integer; | |
6590 | } | |
6591 | else | |
6592 | { | |
6593 | /* | |
6594 | * Got a job URI; parse it to get the job ID... | |
6595 | */ | |
6596 | ||
a4d04587 | 6597 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
6598 | sizeof(method), username, sizeof(username), host, | |
6599 | sizeof(host), &port, resource, sizeof(resource)); | |
fa73b229 | 6600 | |
6601 | if (strncmp(resource, "/jobs/", 6)) | |
6602 | { | |
6603 | /* | |
6604 | * Not a valid URI! | |
6605 | */ | |
6606 | ||
6607 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6608 | _("Bad job-uri attribute \"%s\"!"), | |
6609 | uri->values[0].string.text); | |
6610 | return; | |
6611 | } | |
6612 | ||
6613 | jobid = atoi(resource + 6); | |
6614 | } | |
6615 | ||
6616 | /* | |
6617 | * See if the job exists... | |
6618 | */ | |
6619 | ||
6620 | if ((job = cupsdFindJob(jobid)) == NULL) | |
6621 | { | |
6622 | /* | |
6623 | * Nope - return a "not found" error... | |
6624 | */ | |
6625 | ||
6626 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
6627 | return; | |
6628 | } | |
6629 | ||
6630 | /* | |
6631 | * Check policy... | |
6632 | */ | |
6633 | ||
6634 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6635 | { | |
f899b121 | 6636 | send_http_error(con, status, NULL); |
fa73b229 | 6637 | return; |
6638 | } | |
6639 | ||
6640 | /* | |
6641 | * Copy attributes... | |
6642 | */ | |
6643 | ||
bd7854cb | 6644 | cupsdLoadJob(job); |
6645 | ||
fa73b229 | 6646 | ra = create_requested_array(con->request); |
6647 | copy_job_attrs(con, job, ra); | |
6648 | cupsArrayDelete(ra); | |
6649 | ||
6650 | con->response->request.status.status_code = IPP_OK; | |
6651 | } | |
6652 | ||
6653 | ||
6654 | /* | |
6655 | * 'get_jobs()' - Get a list of jobs for the specified printer. | |
6656 | */ | |
6657 | ||
6658 | static void | |
6659 | get_jobs(cupsd_client_t *con, /* I - Client connection */ | |
6660 | ipp_attribute_t *uri) /* I - Printer URI */ | |
6661 | { | |
6662 | http_status_t status; /* Policy status */ | |
6663 | ipp_attribute_t *attr; /* Current attribute */ | |
6664 | const char *dest; /* Destination */ | |
bc44d920 | 6665 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
fa73b229 | 6666 | cups_ptype_t dmask; /* Destination type mask */ |
f7deaa1a | 6667 | char scheme[HTTP_MAX_URI], /* Scheme portion of URI */ |
fa73b229 | 6668 | username[HTTP_MAX_URI], /* Username portion of URI */ |
6669 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
6670 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
6671 | int port; /* Port portion of URI */ | |
6672 | int completed; /* Completed jobs? */ | |
6673 | int first_job_id; /* First job ID */ | |
6674 | int limit; /* Maximum number of jobs to return */ | |
6675 | int count; /* Number of jobs that match */ | |
6676 | cupsd_job_t *job; /* Current job pointer */ | |
6677 | cupsd_printer_t *printer; /* Printer */ | |
6678 | cups_array_t *list; /* Which job list... */ | |
6679 | cups_array_t *ra; /* Requested attributes array */ | |
6680 | ||
6681 | ||
6682 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs(%p[%d], %s)", con, con->http.fd, | |
6683 | uri->values[0].string.text); | |
6684 | ||
6685 | /* | |
6686 | * Is the destination valid? | |
ef416fc2 | 6687 | */ |
6688 | ||
f7deaa1a | 6689 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
6690 | sizeof(scheme), username, sizeof(username), host, | |
a4d04587 | 6691 | sizeof(host), &port, resource, sizeof(resource)); |
ef416fc2 | 6692 | |
fa73b229 | 6693 | if (!strcmp(resource, "/") || |
6694 | (!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6)) | |
ef416fc2 | 6695 | { |
6696 | dest = NULL; | |
6697 | dtype = (cups_ptype_t)0; | |
6698 | dmask = (cups_ptype_t)0; | |
6699 | printer = NULL; | |
6700 | } | |
fa73b229 | 6701 | else if (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10) |
ef416fc2 | 6702 | { |
6703 | dest = NULL; | |
6704 | dtype = (cups_ptype_t)0; | |
6705 | dmask = CUPS_PRINTER_CLASS; | |
6706 | printer = NULL; | |
6707 | } | |
fa73b229 | 6708 | else if (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9) |
ef416fc2 | 6709 | { |
6710 | dest = NULL; | |
6711 | dtype = CUPS_PRINTER_CLASS; | |
6712 | dmask = CUPS_PRINTER_CLASS; | |
6713 | printer = NULL; | |
6714 | } | |
f7deaa1a | 6715 | else if ((dest = cupsdValidateDest(uri->values[0].string.text, &dtype, |
6716 | &printer)) == NULL) | |
ef416fc2 | 6717 | { |
6718 | /* | |
6719 | * Bad URI... | |
6720 | */ | |
6721 | ||
6722 | send_ipp_status(con, IPP_NOT_FOUND, | |
6723 | _("The printer or class was not found.")); | |
6724 | return; | |
6725 | } | |
6726 | else | |
b86bc4cf | 6727 | { |
6728 | dtype &= CUPS_PRINTER_CLASS; | |
ef416fc2 | 6729 | dmask = CUPS_PRINTER_CLASS; |
b86bc4cf | 6730 | } |
ef416fc2 | 6731 | |
6732 | /* | |
6733 | * Check policy... | |
6734 | */ | |
6735 | ||
6736 | if (printer) | |
6737 | { | |
f7deaa1a | 6738 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, |
6739 | NULL)) != HTTP_OK) | |
ef416fc2 | 6740 | { |
f899b121 | 6741 | send_http_error(con, status, printer); |
ef416fc2 | 6742 | return; |
6743 | } | |
6744 | } | |
6745 | else if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
6746 | { | |
f899b121 | 6747 | send_http_error(con, status, NULL); |
ef416fc2 | 6748 | return; |
6749 | } | |
6750 | ||
6751 | /* | |
6752 | * See if the "which-jobs" attribute have been specified... | |
6753 | */ | |
6754 | ||
fa73b229 | 6755 | if ((attr = ippFindAttribute(con->request, "which-jobs", |
6756 | IPP_TAG_KEYWORD)) != NULL && | |
ef416fc2 | 6757 | !strcmp(attr->values[0].string.text, "completed")) |
6758 | { | |
6759 | completed = 1; | |
6760 | list = Jobs; | |
6761 | } | |
6762 | else if (attr && !strcmp(attr->values[0].string.text, "all")) | |
6763 | { | |
6764 | completed = 0; | |
6765 | list = Jobs; | |
6766 | } | |
3dfe78b3 MS |
6767 | else if (attr && !strcmp(attr->values[0].string.text, "printing")) |
6768 | { | |
6769 | completed = 0; | |
6770 | list = PrintingJobs; | |
6771 | } | |
ef416fc2 | 6772 | else |
6773 | { | |
6774 | completed = 0; | |
6775 | list = ActiveJobs; | |
6776 | } | |
6777 | ||
6778 | /* | |
6779 | * See if they want to limit the number of jobs reported... | |
6780 | */ | |
6781 | ||
fa73b229 | 6782 | if ((attr = ippFindAttribute(con->request, "limit", |
6783 | IPP_TAG_INTEGER)) != NULL) | |
ef416fc2 | 6784 | limit = attr->values[0].integer; |
6785 | else | |
3dfe78b3 | 6786 | limit = 0; |
ef416fc2 | 6787 | |
6788 | if ((attr = ippFindAttribute(con->request, "first-job-id", | |
6789 | IPP_TAG_INTEGER)) != NULL) | |
6790 | first_job_id = attr->values[0].integer; | |
6791 | else | |
6792 | first_job_id = 1; | |
6793 | ||
6794 | /* | |
6795 | * See if we only want to see jobs for a specific user... | |
6796 | */ | |
6797 | ||
fa73b229 | 6798 | if ((attr = ippFindAttribute(con->request, "my-jobs", |
6799 | IPP_TAG_BOOLEAN)) != NULL && | |
ef416fc2 | 6800 | attr->values[0].boolean) |
e00b005a | 6801 | strlcpy(username, get_username(con), sizeof(username)); |
ef416fc2 | 6802 | else |
6803 | username[0] = '\0'; | |
6804 | ||
fa73b229 | 6805 | ra = create_requested_array(con->request); |
ef416fc2 | 6806 | |
6807 | /* | |
6808 | * OK, build a list of jobs for this printer... | |
6809 | */ | |
6810 | ||
6811 | for (count = 0, job = (cupsd_job_t *)cupsArrayFirst(list); | |
3dfe78b3 | 6812 | (limit <= 0 || count < limit) && job; |
ef416fc2 | 6813 | job = (cupsd_job_t *)cupsArrayNext(list)) |
6814 | { | |
6815 | /* | |
6816 | * Filter out jobs that don't match... | |
6817 | */ | |
6818 | ||
6819 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: job->id = %d", job->id); | |
6820 | ||
0a682745 MS |
6821 | if (!job->dest || !job->username) |
6822 | cupsdLoadJob(job); | |
6823 | ||
6824 | if (!job->dest || !job->username) | |
6825 | continue; | |
6826 | ||
fa73b229 | 6827 | if ((dest && strcmp(job->dest, dest)) && |
6828 | (!job->printer || !dest || strcmp(job->printer->name, dest))) | |
ef416fc2 | 6829 | continue; |
6830 | if ((job->dtype & dmask) != dtype && | |
fa73b229 | 6831 | (!job->printer || (job->printer->type & dmask) != dtype)) |
ef416fc2 | 6832 | continue; |
bd7854cb | 6833 | if (completed && job->state_value <= IPP_JOB_STOPPED) |
ef416fc2 | 6834 | continue; |
6835 | ||
6836 | if (job->id < first_job_id) | |
6837 | continue; | |
6838 | ||
bd7854cb | 6839 | cupsdLoadJob(job); |
6840 | ||
6841 | if (!job->attrs) | |
6842 | continue; | |
6843 | ||
7594b224 | 6844 | if (username[0] && strcasecmp(username, job->username)) |
6845 | continue; | |
6846 | ||
fa73b229 | 6847 | if (count > 0) |
6848 | ippAddSeparator(con->response); | |
6849 | ||
ef416fc2 | 6850 | count ++; |
6851 | ||
6852 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count = %d", count); | |
6853 | ||
fa73b229 | 6854 | copy_job_attrs(con, job, ra); |
ef416fc2 | 6855 | } |
6856 | ||
fa73b229 | 6857 | cupsArrayDelete(ra); |
ef416fc2 | 6858 | |
fa73b229 | 6859 | con->response->request.status.status_code = IPP_OK; |
ef416fc2 | 6860 | } |
6861 | ||
6862 | ||
6863 | /* | |
6864 | * 'get_notifications()' - Get events for a subscription. | |
6865 | */ | |
6866 | ||
6867 | static void | |
bd7854cb | 6868 | get_notifications(cupsd_client_t *con) /* I - Client connection */ |
ef416fc2 | 6869 | { |
bd7854cb | 6870 | int i, j; /* Looping vars */ |
6871 | http_status_t status; /* Policy status */ | |
6872 | cupsd_subscription_t *sub; /* Subscription */ | |
6873 | ipp_attribute_t *ids, /* notify-subscription-ids */ | |
6874 | *sequences; /* notify-sequence-numbers */ | |
6875 | int min_seq; /* Minimum sequence number */ | |
6876 | int interval; /* Poll interval */ | |
6877 | ||
6878 | ||
f7deaa1a | 6879 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_notifications(con=%p[%d])", |
bd7854cb | 6880 | con, con->http.fd); |
6881 | ||
6882 | /* | |
6883 | * Get subscription attributes... | |
6884 | */ | |
6885 | ||
6886 | ids = ippFindAttribute(con->request, "notify-subscription-ids", | |
6887 | IPP_TAG_INTEGER); | |
6888 | sequences = ippFindAttribute(con->request, "notify-sequence-numbers", | |
6889 | IPP_TAG_INTEGER); | |
6890 | ||
6891 | if (!ids) | |
6892 | { | |
6893 | send_ipp_status(con, IPP_BAD_REQUEST, | |
6894 | _("Missing notify-subscription-ids attribute!")); | |
6895 | return; | |
6896 | } | |
6897 | ||
6898 | /* | |
6899 | * Are the subscription IDs valid? | |
6900 | */ | |
6901 | ||
6902 | for (i = 0, interval = 60; i < ids->num_values; i ++) | |
6903 | { | |
6904 | if ((sub = cupsdFindSubscription(ids->values[i].integer)) == NULL) | |
6905 | { | |
6906 | /* | |
6907 | * Bad subscription ID... | |
6908 | */ | |
6909 | ||
6910 | send_ipp_status(con, IPP_NOT_FOUND, | |
6911 | _("notify-subscription-id %d no good!"), | |
6912 | ids->values[i].integer); | |
6913 | return; | |
6914 | } | |
6915 | ||
6916 | /* | |
6917 | * Check policy... | |
6918 | */ | |
6919 | ||
6920 | if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr : | |
6921 | DefaultPolicyPtr, | |
6922 | con, sub->owner)) != HTTP_OK) | |
6923 | { | |
f899b121 | 6924 | send_http_error(con, status, sub->dest); |
bd7854cb | 6925 | return; |
6926 | } | |
6927 | ||
6928 | /* | |
6929 | * Check the subscription type and update the interval accordingly. | |
6930 | */ | |
6931 | ||
6932 | if (sub->job && sub->job->state_value == IPP_JOB_PROCESSING && | |
6933 | interval > 10) | |
6934 | interval = 10; | |
6935 | else if (sub->job && sub->job->state_value >= IPP_JOB_STOPPED) | |
6936 | interval = 0; | |
6937 | else if (sub->dest && sub->dest->state == IPP_PRINTER_PROCESSING && | |
6938 | interval > 30) | |
6939 | interval = 30; | |
6940 | } | |
6941 | ||
6942 | /* | |
6943 | * Tell the client to poll again in N seconds... | |
6944 | */ | |
6945 | ||
6946 | if (interval > 0) | |
6947 | ippAddInteger(con->response, IPP_TAG_OPERATION, IPP_TAG_INTEGER, | |
6948 | "notify-get-interval", interval); | |
6949 | ||
6950 | ippAddInteger(con->response, IPP_TAG_OPERATION, IPP_TAG_INTEGER, | |
6951 | "printer-up-time", time(NULL)); | |
6952 | ||
6953 | /* | |
6954 | * Copy the subscription event attributes to the response. | |
6955 | */ | |
6956 | ||
6957 | con->response->request.status.status_code = | |
6958 | interval ? IPP_OK : IPP_OK_EVENTS_COMPLETE; | |
6959 | ||
6960 | for (i = 0; i < ids->num_values; i ++) | |
6961 | { | |
6962 | /* | |
6963 | * Get the subscription and sequence number... | |
6964 | */ | |
6965 | ||
6966 | sub = cupsdFindSubscription(ids->values[i].integer); | |
6967 | ||
6968 | if (sequences && i < sequences->num_values) | |
6969 | min_seq = sequences->values[i].integer; | |
6970 | else | |
6971 | min_seq = 1; | |
6972 | ||
6973 | /* | |
6974 | * If we don't have any new events, nothing to do here... | |
6975 | */ | |
6976 | ||
6977 | if (min_seq > (sub->first_event_id + sub->num_events)) | |
6978 | continue; | |
6979 | ||
6980 | /* | |
6981 | * Otherwise copy all of the new events... | |
6982 | */ | |
6983 | ||
6984 | if (sub->first_event_id > min_seq) | |
6985 | j = 0; | |
6986 | else | |
6987 | j = min_seq - sub->first_event_id; | |
6988 | ||
b423cd4c | 6989 | for (; j < sub->num_events; j ++) |
6990 | { | |
6991 | ippAddSeparator(con->response); | |
ef416fc2 | 6992 | |
b423cd4c | 6993 | copy_attrs(con->response, sub->events[j]->attrs, NULL, |
6994 | IPP_TAG_EVENT_NOTIFICATION, 0); | |
6995 | } | |
6996 | } | |
6997 | } | |
ef416fc2 | 6998 | |
ef416fc2 | 6999 | |
b94498cf | 7000 | /* |
7001 | * 'get_ppd()' - Get a named PPD from the local system. | |
7002 | */ | |
7003 | ||
7004 | static void | |
7005 | get_ppd(cupsd_client_t *con, /* I - Client connection */ | |
7006 | ipp_attribute_t *uri) /* I - Printer URI or PPD name */ | |
7007 | { | |
7008 | http_status_t status; /* Policy status */ | |
7009 | cupsd_printer_t *dest; /* Destination */ | |
7010 | cups_ptype_t dtype; /* Destination type */ | |
7011 | ||
7012 | ||
7013 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppd(%p[%d], %p[%s=%s])", con, | |
7014 | con->http.fd, uri, uri->name, uri->values[0].string.text); | |
7015 | ||
7016 | if (!strcmp(uri->name, "ppd-name")) | |
7017 | { | |
7018 | /* | |
7019 | * Return a PPD file from cups-driverd... | |
7020 | */ | |
7021 | ||
7022 | char command[1024], /* cups-driverd command */ | |
7023 | options[1024], /* Options to pass to command */ | |
7024 | ppd_name[1024]; /* ppd-name */ | |
7025 | ||
7026 | ||
7027 | /* | |
7028 | * Check policy... | |
7029 | */ | |
7030 | ||
7031 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
7032 | { | |
7033 | send_http_error(con, status, NULL); | |
7034 | return; | |
7035 | } | |
7036 | ||
7037 | /* | |
7038 | * Run cups-driverd command with the given options... | |
7039 | */ | |
7040 | ||
7041 | snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin); | |
7042 | url_encode_string(uri->values[0].string.text, ppd_name, sizeof(ppd_name)); | |
7043 | snprintf(options, sizeof(options), "get+%d+%s", | |
7044 | con->request->request.op.request_id, ppd_name); | |
7045 | ||
7046 | if (cupsdSendCommand(con, command, options, 0)) | |
7047 | { | |
7048 | /* | |
7049 | * Command started successfully, don't send an IPP response here... | |
7050 | */ | |
7051 | ||
7052 | ippDelete(con->response); | |
7053 | con->response = NULL; | |
7054 | } | |
7055 | else | |
7056 | { | |
7057 | /* | |
7058 | * Command failed, return "internal error" so the user knows something | |
7059 | * went wrong... | |
7060 | */ | |
7061 | ||
7062 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
7063 | _("cups-driverd failed to execute.")); | |
7064 | } | |
7065 | } | |
7066 | else if (!strcmp(uri->name, "printer-uri") && | |
7067 | cupsdValidateDest(uri->values[0].string.text, &dtype, &dest)) | |
7068 | { | |
7069 | int i; /* Looping var */ | |
7070 | char filename[1024]; /* PPD filename */ | |
7071 | ||
7072 | ||
7073 | /* | |
7074 | * Check policy... | |
7075 | */ | |
7076 | ||
7077 | if ((status = cupsdCheckPolicy(dest->op_policy_ptr, con, NULL)) != HTTP_OK) | |
7078 | { | |
2fb76298 | 7079 | send_http_error(con, status, dest); |
b94498cf | 7080 | return; |
7081 | } | |
7082 | ||
7083 | /* | |
7084 | * See if we need the PPD for a class or remote printer... | |
7085 | */ | |
7086 | ||
bc44d920 | 7087 | snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, |
7088 | dest->name); | |
7089 | ||
7090 | if ((dtype & CUPS_PRINTER_REMOTE) && access(filename, 0)) | |
b94498cf | 7091 | { |
3d8365b8 | 7092 | con->response->request.status.status_code = CUPS_SEE_OTHER; |
b94498cf | 7093 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI, |
7094 | "printer-uri", NULL, dest->uri); | |
7095 | return; | |
7096 | } | |
7097 | else if (dtype & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)) | |
7098 | { | |
7099 | for (i = 0; i < dest->num_printers; i ++) | |
7100 | if (!(dest->printers[i]->type & | |
bc44d920 | 7101 | (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))) |
7102 | { | |
7103 | snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, | |
7104 | dest->printers[i]->name); | |
7105 | ||
7106 | if (!access(filename, 0)) | |
7107 | break; | |
7108 | } | |
b94498cf | 7109 | |
7110 | if (i < dest->num_printers) | |
7111 | dest = dest->printers[i]; | |
7112 | else | |
7113 | { | |
3d8365b8 | 7114 | con->response->request.status.status_code = CUPS_SEE_OTHER; |
b94498cf | 7115 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI, |
7116 | "printer-uri", NULL, dest->printers[0]->uri); | |
7117 | return; | |
7118 | } | |
7119 | } | |
7120 | ||
7121 | /* | |
7122 | * Found the printer with the PPD file, now see if there is one... | |
7123 | */ | |
7124 | ||
b94498cf | 7125 | if ((con->file = open(filename, O_RDONLY)) < 0) |
7126 | { | |
7127 | send_ipp_status(con, IPP_NOT_FOUND, | |
7128 | _("The PPD file \"%s\" could not be opened: %s"), | |
3d8365b8 | 7129 | uri->values[0].string.text, strerror(errno)); |
b94498cf | 7130 | return; |
7131 | } | |
7132 | ||
7133 | fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC); | |
7134 | ||
7135 | con->pipe_pid = 0; | |
7136 | ||
3d8365b8 | 7137 | con->response->request.status.status_code = IPP_OK; |
b94498cf | 7138 | } |
7139 | else | |
7140 | send_ipp_status(con, IPP_NOT_FOUND, | |
7141 | _("The PPD file \"%s\" could not be found."), | |
7142 | uri->values[0].string.text); | |
7143 | } | |
7144 | ||
7145 | ||
b423cd4c | 7146 | /* |
7147 | * 'get_ppds()' - Get the list of PPD files on the local system. | |
7148 | */ | |
ef416fc2 | 7149 | |
b423cd4c | 7150 | static void |
7151 | get_ppds(cupsd_client_t *con) /* I - Client connection */ | |
7152 | { | |
7153 | http_status_t status; /* Policy status */ | |
b423cd4c | 7154 | ipp_attribute_t *limit, /* Limit attribute */ |
b94498cf | 7155 | *device, /* ppd-device-id attribute */ |
7156 | *language, /* ppd-natural-language attribute */ | |
b423cd4c | 7157 | *make, /* ppd-make attribute */ |
b94498cf | 7158 | *model, /* ppd-make-and-model attribute */ |
3d8365b8 | 7159 | *model_number, /* ppd-model-number attribute */ |
b94498cf | 7160 | *product, /* ppd-product attribute */ |
7161 | *psversion, /* ppd-psverion attribute */ | |
3d8365b8 | 7162 | *type, /* ppd-type attribute */ |
b423cd4c | 7163 | *requested; /* requested-attributes attribute */ |
b94498cf | 7164 | char command[1024], /* cups-driverd command */ |
b423cd4c | 7165 | options[1024], /* Options to pass to command */ |
b94498cf | 7166 | device_str[256],/* Escaped ppd-device-id string */ |
7167 | language_str[256], | |
bc44d920 | 7168 | /* Escaped ppd-natural-language */ |
b94498cf | 7169 | make_str[256], /* Escaped ppd-make string */ |
7170 | model_str[256], /* Escaped ppd-make-and-model string */ | |
3d8365b8 | 7171 | model_number_str[256], |
7172 | /* ppd-model-number string */ | |
b94498cf | 7173 | product_str[256], |
7174 | /* Escaped ppd-product string */ | |
7175 | psversion_str[256], | |
7176 | /* Escaped ppd-psversion string */ | |
3d8365b8 | 7177 | type_str[256], /* Escaped ppd-type string */ |
b94498cf | 7178 | requested_str[256]; |
89d46774 | 7179 | /* String for requested attributes */ |
ef416fc2 | 7180 | |
ef416fc2 | 7181 | |
b423cd4c | 7182 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->http.fd); |
ef416fc2 | 7183 | |
7184 | /* | |
b423cd4c | 7185 | * Check policy... |
ef416fc2 | 7186 | */ |
7187 | ||
b423cd4c | 7188 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
ef416fc2 | 7189 | { |
f899b121 | 7190 | send_http_error(con, status, NULL); |
b423cd4c | 7191 | return; |
ef416fc2 | 7192 | } |
ef416fc2 | 7193 | |
b423cd4c | 7194 | /* |
7195 | * Run cups-driverd command with the given options... | |
7196 | */ | |
7197 | ||
3d8365b8 | 7198 | limit = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER); |
7199 | device = ippFindAttribute(con->request, "ppd-device-id", IPP_TAG_TEXT); | |
7200 | language = ippFindAttribute(con->request, "ppd-natural-language", | |
7201 | IPP_TAG_LANGUAGE); | |
7202 | make = ippFindAttribute(con->request, "ppd-make", IPP_TAG_TEXT); | |
7203 | model = ippFindAttribute(con->request, "ppd-make-and-model", | |
7204 | IPP_TAG_TEXT); | |
7205 | model_number = ippFindAttribute(con->request, "ppd-model-number", | |
7206 | IPP_TAG_INTEGER); | |
7207 | product = ippFindAttribute(con->request, "ppd-product", IPP_TAG_TEXT); | |
7208 | psversion = ippFindAttribute(con->request, "ppd-psversion", IPP_TAG_TEXT); | |
7209 | type = ippFindAttribute(con->request, "ppd-type", IPP_TAG_KEYWORD); | |
7210 | requested = ippFindAttribute(con->request, "requested-attributes", | |
7211 | IPP_TAG_KEYWORD); | |
b423cd4c | 7212 | |
7213 | if (requested) | |
89d46774 | 7214 | url_encode_attr(requested, requested_str, sizeof(requested_str)); |
7215 | else | |
7216 | strlcpy(requested_str, "requested-attributes=all", sizeof(requested_str)); | |
ef416fc2 | 7217 | |
b94498cf | 7218 | if (device) |
7219 | url_encode_attr(device, device_str, sizeof(device_str)); | |
7220 | else | |
7221 | device_str[0] = '\0'; | |
7222 | ||
7223 | if (language) | |
7224 | url_encode_attr(language, language_str, sizeof(language_str)); | |
7225 | else | |
7226 | language_str[0] = '\0'; | |
7227 | ||
89d46774 | 7228 | if (make) |
7229 | url_encode_attr(make, make_str, sizeof(make_str)); | |
b423cd4c | 7230 | else |
89d46774 | 7231 | make_str[0] = '\0'; |
fa73b229 | 7232 | |
b94498cf | 7233 | if (model) |
7234 | url_encode_attr(model, model_str, sizeof(model_str)); | |
7235 | else | |
7236 | model_str[0] = '\0'; | |
7237 | ||
3d8365b8 | 7238 | if (model_number) |
7239 | snprintf(model_number_str, sizeof(model_number_str), "ppd-model-number=%d", | |
7240 | model_number->values[0].integer); | |
7241 | else | |
7242 | model_number_str[0] = '\0'; | |
7243 | ||
b94498cf | 7244 | if (product) |
7245 | url_encode_attr(product, product_str, sizeof(product_str)); | |
7246 | else | |
7247 | product_str[0] = '\0'; | |
7248 | ||
7249 | if (psversion) | |
7250 | url_encode_attr(psversion, psversion_str, sizeof(psversion_str)); | |
7251 | else | |
7252 | psversion_str[0] = '\0'; | |
7253 | ||
3d8365b8 | 7254 | if (type) |
7255 | url_encode_attr(type, type_str, sizeof(type_str)); | |
7256 | else | |
7257 | type_str[0] = '\0'; | |
7258 | ||
b423cd4c | 7259 | snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin); |
3d8365b8 | 7260 | snprintf(options, sizeof(options), |
7261 | "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", | |
b423cd4c | 7262 | con->request->request.op.request_id, |
7263 | limit ? limit->values[0].integer : 0, | |
b94498cf | 7264 | requested_str, |
7265 | device ? "%20" : "", device_str, | |
7266 | language ? "%20" : "", language_str, | |
7267 | make ? "%20" : "", make_str, | |
7268 | model ? "%20" : "", model_str, | |
3d8365b8 | 7269 | model_number ? "%20" : "", model_number_str, |
b94498cf | 7270 | product ? "%20" : "", product_str, |
3d8365b8 | 7271 | psversion ? "%20" : "", psversion_str, |
7272 | type ? "%20" : "", type_str); | |
ef416fc2 | 7273 | |
b423cd4c | 7274 | if (cupsdSendCommand(con, command, options, 0)) |
7275 | { | |
7276 | /* | |
7277 | * Command started successfully, don't send an IPP response here... | |
7278 | */ | |
7279 | ||
7280 | ippDelete(con->response); | |
7281 | con->response = NULL; | |
7282 | } | |
7283 | else | |
7284 | { | |
7285 | /* | |
7286 | * Command failed, return "internal error" so the user knows something | |
7287 | * went wrong... | |
7288 | */ | |
7289 | ||
7290 | send_ipp_status(con, IPP_INTERNAL_ERROR, | |
7291 | _("cups-driverd failed to execute.")); | |
7292 | } | |
ef416fc2 | 7293 | } |
7294 | ||
7295 | ||
7296 | /* | |
b423cd4c | 7297 | * 'get_printer_attrs()' - Get printer attributes. |
ef416fc2 | 7298 | */ |
7299 | ||
7300 | static void | |
b423cd4c | 7301 | get_printer_attrs(cupsd_client_t *con, /* I - Client connection */ |
7302 | ipp_attribute_t *uri) /* I - Printer URI */ | |
ef416fc2 | 7303 | { |
7304 | http_status_t status; /* Policy status */ | |
bc44d920 | 7305 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
b423cd4c | 7306 | cupsd_printer_t *printer; /* Printer/class */ |
ef416fc2 | 7307 | cups_array_t *ra; /* Requested attributes array */ |
7308 | ||
7309 | ||
b423cd4c | 7310 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_attrs(%p[%d], %s)", con, |
7311 | con->http.fd, uri->values[0].string.text); | |
ef416fc2 | 7312 | |
7313 | /* | |
b423cd4c | 7314 | * Is the destination valid? |
ef416fc2 | 7315 | */ |
7316 | ||
f7deaa1a | 7317 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 7318 | { |
7319 | /* | |
b423cd4c | 7320 | * Bad URI... |
ef416fc2 | 7321 | */ |
7322 | ||
7323 | send_ipp_status(con, IPP_NOT_FOUND, | |
b423cd4c | 7324 | _("The printer or class was not found.")); |
ef416fc2 | 7325 | return; |
7326 | } | |
7327 | ||
7328 | /* | |
7329 | * Check policy... | |
7330 | */ | |
7331 | ||
b423cd4c | 7332 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) |
ef416fc2 | 7333 | { |
f899b121 | 7334 | send_http_error(con, status, printer); |
ef416fc2 | 7335 | return; |
7336 | } | |
7337 | ||
7338 | /* | |
b423cd4c | 7339 | * Send the attributes... |
ef416fc2 | 7340 | */ |
7341 | ||
7342 | ra = create_requested_array(con->request); | |
7343 | ||
b423cd4c | 7344 | copy_printer_attrs(con, printer, ra); |
ef416fc2 | 7345 | |
7346 | cupsArrayDelete(ra); | |
7347 | ||
7348 | con->response->request.status.status_code = IPP_OK; | |
7349 | } | |
7350 | ||
7351 | ||
7352 | /* | |
b423cd4c | 7353 | * 'get_printers()' - Get a list of printers or classes. |
ef416fc2 | 7354 | */ |
7355 | ||
7356 | static void | |
b423cd4c | 7357 | get_printers(cupsd_client_t *con, /* I - Client connection */ |
7358 | int type) /* I - 0 or CUPS_PRINTER_CLASS */ | |
ef416fc2 | 7359 | { |
b423cd4c | 7360 | http_status_t status; /* Policy status */ |
7361 | ipp_attribute_t *attr; /* Current attribute */ | |
bc44d920 | 7362 | int limit; /* Max number of printers to return */ |
b423cd4c | 7363 | int count; /* Number of printers that match */ |
7364 | cupsd_printer_t *printer; /* Current printer pointer */ | |
7365 | int printer_type, /* printer-type attribute */ | |
7366 | printer_mask; /* printer-type-mask attribute */ | |
7367 | char *location; /* Location string */ | |
7368 | const char *username; /* Current user */ | |
7369 | char *first_printer_name; /* first-printer-name attribute */ | |
7370 | cups_array_t *ra; /* Requested attributes array */ | |
ef416fc2 | 7371 | |
ef416fc2 | 7372 | |
b423cd4c | 7373 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con, |
7374 | con->http.fd, type); | |
ef416fc2 | 7375 | |
7376 | /* | |
7377 | * Check policy... | |
7378 | */ | |
7379 | ||
b423cd4c | 7380 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) |
ef416fc2 | 7381 | { |
f899b121 | 7382 | send_http_error(con, status, NULL); |
ef416fc2 | 7383 | return; |
7384 | } | |
7385 | ||
7386 | /* | |
b423cd4c | 7387 | * Check for printers... |
ef416fc2 | 7388 | */ |
7389 | ||
b423cd4c | 7390 | if (!Printers || !cupsArrayCount(Printers)) |
7391 | { | |
7392 | send_ipp_status(con, IPP_NOT_FOUND, _("No destinations added.")); | |
7393 | return; | |
7394 | } | |
7395 | ||
7396 | /* | |
7397 | * See if they want to limit the number of printers reported... | |
7398 | */ | |
ef416fc2 | 7399 | |
fa73b229 | 7400 | if ((attr = ippFindAttribute(con->request, "limit", |
7401 | IPP_TAG_INTEGER)) != NULL) | |
ef416fc2 | 7402 | limit = attr->values[0].integer; |
7403 | else | |
b423cd4c | 7404 | limit = 10000000; |
7405 | ||
7406 | if ((attr = ippFindAttribute(con->request, "first-printer-name", | |
7407 | IPP_TAG_NAME)) != NULL) | |
7408 | first_printer_name = attr->values[0].string.text; | |
7409 | else | |
7410 | first_printer_name = NULL; | |
ef416fc2 | 7411 | |
7412 | /* | |
b423cd4c | 7413 | * Support filtering... |
ef416fc2 | 7414 | */ |
7415 | ||
b423cd4c | 7416 | if ((attr = ippFindAttribute(con->request, "printer-type", |
7417 | IPP_TAG_ENUM)) != NULL) | |
7418 | printer_type = attr->values[0].integer; | |
ef416fc2 | 7419 | else |
b423cd4c | 7420 | printer_type = 0; |
ef416fc2 | 7421 | |
b423cd4c | 7422 | if ((attr = ippFindAttribute(con->request, "printer-type-mask", |
7423 | IPP_TAG_ENUM)) != NULL) | |
7424 | printer_mask = attr->values[0].integer; | |
ef416fc2 | 7425 | else |
b423cd4c | 7426 | printer_mask = 0; |
e00b005a | 7427 | |
b423cd4c | 7428 | if ((attr = ippFindAttribute(con->request, "printer-location", |
7429 | IPP_TAG_TEXT)) != NULL) | |
7430 | location = attr->values[0].string.text; | |
7431 | else | |
7432 | location = NULL; | |
e00b005a | 7433 | |
7434 | if (con->username[0]) | |
b423cd4c | 7435 | username = con->username; |
e00b005a | 7436 | else if ((attr = ippFindAttribute(con->request, "requesting-user-name", |
7437 | IPP_TAG_NAME)) != NULL) | |
b423cd4c | 7438 | username = attr->values[0].string.text; |
e00b005a | 7439 | else |
b423cd4c | 7440 | username = NULL; |
ef416fc2 | 7441 | |
b423cd4c | 7442 | ra = create_requested_array(con->request); |
ef416fc2 | 7443 | |
7444 | /* | |
b423cd4c | 7445 | * OK, build a list of printers for this printer... |
ef416fc2 | 7446 | */ |
7447 | ||
b423cd4c | 7448 | if (first_printer_name) |
ef416fc2 | 7449 | { |
b423cd4c | 7450 | if ((printer = cupsdFindDest(first_printer_name)) == NULL) |
7451 | printer = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
ef416fc2 | 7452 | } |
7453 | else | |
b423cd4c | 7454 | printer = (cupsd_printer_t *)cupsArrayFirst(Printers); |
ef416fc2 | 7455 | |
b423cd4c | 7456 | for (count = 0; |
7457 | count < limit && printer; | |
7458 | printer = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
7459 | { | |
7460 | if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) && | |
7461 | (printer->type & printer_mask) == printer_type && | |
7462 | (!location || !printer->location || | |
7463 | !strcasecmp(printer->location, location))) | |
ef416fc2 | 7464 | { |
7465 | /* | |
b423cd4c | 7466 | * If HideImplicitMembers is enabled, see if this printer or class |
7467 | * is a member of an implicit class... | |
ef416fc2 | 7468 | */ |
7469 | ||
b423cd4c | 7470 | if (ImplicitClasses && HideImplicitMembers && |
7471 | printer->in_implicit_class) | |
7472 | continue; | |
ef416fc2 | 7473 | |
b423cd4c | 7474 | /* |
7475 | * If a username is specified, see if it is allowed or denied | |
7476 | * access... | |
7477 | */ | |
ef416fc2 | 7478 | |
b423cd4c | 7479 | if (printer->num_users && username && !user_allowed(printer, username)) |
7480 | continue; | |
ef416fc2 | 7481 | |
b423cd4c | 7482 | /* |
7483 | * Add the group separator as needed... | |
7484 | */ | |
ef416fc2 | 7485 | |
b423cd4c | 7486 | if (count > 0) |
7487 | ippAddSeparator(con->response); | |
ef416fc2 | 7488 | |
b423cd4c | 7489 | count ++; |
ef416fc2 | 7490 | |
b423cd4c | 7491 | /* |
7492 | * Send the attributes... | |
7493 | */ | |
ef416fc2 | 7494 | |
b423cd4c | 7495 | copy_printer_attrs(con, printer, ra); |
7496 | } | |
ef416fc2 | 7497 | } |
7498 | ||
b423cd4c | 7499 | cupsArrayDelete(ra); |
ef416fc2 | 7500 | |
7501 | con->response->request.status.status_code = IPP_OK; | |
7502 | } | |
7503 | ||
7504 | ||
7505 | /* | |
b423cd4c | 7506 | * 'get_subscription_attrs()' - Get subscription attributes. |
ef416fc2 | 7507 | */ |
7508 | ||
7509 | static void | |
b423cd4c | 7510 | get_subscription_attrs( |
7511 | cupsd_client_t *con, /* I - Client connection */ | |
7512 | int sub_id) /* I - Subscription ID */ | |
ef416fc2 | 7513 | { |
b423cd4c | 7514 | http_status_t status; /* Policy status */ |
7515 | cupsd_subscription_t *sub; /* Subscription */ | |
7516 | cups_array_t *ra; /* Requested attributes array */ | |
ef416fc2 | 7517 | |
7518 | ||
b423cd4c | 7519 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
7520 | "get_subscription_attrs(con=%p[%d], sub_id=%d)", | |
7521 | con, con->http.fd, sub_id); | |
ef416fc2 | 7522 | |
fa73b229 | 7523 | /* |
b423cd4c | 7524 | * Is the subscription ID valid? |
fa73b229 | 7525 | */ |
7526 | ||
b423cd4c | 7527 | if ((sub = cupsdFindSubscription(sub_id)) == NULL) |
fa73b229 | 7528 | { |
7529 | /* | |
b423cd4c | 7530 | * Bad subscription ID... |
fa73b229 | 7531 | */ |
7532 | ||
7533 | send_ipp_status(con, IPP_NOT_FOUND, | |
b423cd4c | 7534 | _("notify-subscription-id %d no good!"), sub_id); |
fa73b229 | 7535 | return; |
7536 | } | |
7537 | ||
7538 | /* | |
7539 | * Check policy... | |
7540 | */ | |
7541 | ||
b423cd4c | 7542 | if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr : |
7543 | DefaultPolicyPtr, | |
7544 | con, sub->owner)) != HTTP_OK) | |
fa73b229 | 7545 | { |
f899b121 | 7546 | send_http_error(con, status, sub->dest); |
fa73b229 | 7547 | return; |
7548 | } | |
7549 | ||
ef416fc2 | 7550 | /* |
b423cd4c | 7551 | * Copy the subscription attributes to the response using the |
7552 | * requested-attributes attribute that may be provided by the client. | |
ef416fc2 | 7553 | */ |
7554 | ||
b423cd4c | 7555 | ra = create_requested_array(con->request); |
fa73b229 | 7556 | |
b423cd4c | 7557 | copy_subscription_attrs(con, sub, ra); |
ef416fc2 | 7558 | |
b423cd4c | 7559 | cupsArrayDelete(ra); |
fa73b229 | 7560 | |
b423cd4c | 7561 | con->response->request.status.status_code = IPP_OK; |
7562 | } | |
fa73b229 | 7563 | |
fa73b229 | 7564 | |
b423cd4c | 7565 | /* |
7566 | * 'get_subscriptions()' - Get subscriptions. | |
7567 | */ | |
ef416fc2 | 7568 | |
b423cd4c | 7569 | static void |
7570 | get_subscriptions(cupsd_client_t *con, /* I - Client connection */ | |
7571 | ipp_attribute_t *uri) /* I - Printer/job URI */ | |
7572 | { | |
7573 | http_status_t status; /* Policy status */ | |
7574 | int count; /* Number of subscriptions */ | |
7575 | int limit; /* Limit */ | |
7576 | cupsd_subscription_t *sub; /* Subscription */ | |
7577 | cups_array_t *ra; /* Requested attributes array */ | |
7578 | ipp_attribute_t *attr; /* Attribute */ | |
bc44d920 | 7579 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
f7deaa1a | 7580 | char scheme[HTTP_MAX_URI], |
7581 | /* Scheme portion of URI */ | |
b423cd4c | 7582 | username[HTTP_MAX_URI], |
7583 | /* Username portion of URI */ | |
7584 | host[HTTP_MAX_URI], | |
7585 | /* Host portion of URI */ | |
7586 | resource[HTTP_MAX_URI]; | |
7587 | /* Resource portion of URI */ | |
7588 | int port; /* Port portion of URI */ | |
7589 | cupsd_job_t *job; /* Job pointer */ | |
7590 | cupsd_printer_t *printer; /* Printer */ | |
fa73b229 | 7591 | |
fa73b229 | 7592 | |
b423cd4c | 7593 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
7594 | "get_subscriptions(con=%p[%d], uri=%s)", | |
7595 | con, con->http.fd, uri->values[0].string.text); | |
7596 | ||
7597 | /* | |
7598 | * Is the destination valid? | |
7599 | */ | |
7600 | ||
f7deaa1a | 7601 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
7602 | sizeof(scheme), username, sizeof(username), host, | |
b423cd4c | 7603 | sizeof(host), &port, resource, sizeof(resource)); |
7604 | ||
7605 | if (!strcmp(resource, "/") || | |
7606 | (!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6) || | |
7607 | (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10) || | |
7608 | (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9)) | |
7609 | { | |
7610 | printer = NULL; | |
7611 | job = NULL; | |
ef416fc2 | 7612 | } |
b423cd4c | 7613 | else if (!strncmp(resource, "/jobs/", 6) && resource[6]) |
ef416fc2 | 7614 | { |
b423cd4c | 7615 | printer = NULL; |
7616 | job = cupsdFindJob(atoi(resource + 6)); | |
ef416fc2 | 7617 | |
b423cd4c | 7618 | if (!job) |
ef416fc2 | 7619 | { |
b423cd4c | 7620 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%s does not exist!"), |
7621 | resource + 6); | |
ef416fc2 | 7622 | return; |
7623 | } | |
b423cd4c | 7624 | } |
f7deaa1a | 7625 | else if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
b423cd4c | 7626 | { |
fa73b229 | 7627 | /* |
b423cd4c | 7628 | * Bad URI... |
fa73b229 | 7629 | */ |
7630 | ||
b423cd4c | 7631 | send_ipp_status(con, IPP_NOT_FOUND, |
7632 | _("The printer or class was not found.")); | |
7633 | return; | |
7634 | } | |
7635 | else if ((attr = ippFindAttribute(con->request, "notify-job-id", | |
7636 | IPP_TAG_INTEGER)) != NULL) | |
7637 | { | |
7638 | job = cupsdFindJob(attr->values[0].integer); | |
ef416fc2 | 7639 | |
b423cd4c | 7640 | if (!job) |
fa73b229 | 7641 | { |
b423cd4c | 7642 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), |
7643 | attr->values[0].integer); | |
fa73b229 | 7644 | return; |
7645 | } | |
ef416fc2 | 7646 | } |
b423cd4c | 7647 | else |
7648 | job = NULL; | |
ef416fc2 | 7649 | |
7650 | /* | |
b423cd4c | 7651 | * Check policy... |
ef416fc2 | 7652 | */ |
7653 | ||
b423cd4c | 7654 | if ((status = cupsdCheckPolicy(printer ? printer->op_policy_ptr : |
7655 | DefaultPolicyPtr, | |
7656 | con, NULL)) != HTTP_OK) | |
ef416fc2 | 7657 | { |
f899b121 | 7658 | send_http_error(con, status, printer); |
b423cd4c | 7659 | return; |
7660 | } | |
ef416fc2 | 7661 | |
b423cd4c | 7662 | /* |
7663 | * Copy the subscription attributes to the response using the | |
7664 | * requested-attributes attribute that may be provided by the client. | |
7665 | */ | |
ef416fc2 | 7666 | |
b423cd4c | 7667 | ra = create_requested_array(con->request); |
ef416fc2 | 7668 | |
b423cd4c | 7669 | if ((attr = ippFindAttribute(con->request, "limit", |
7670 | IPP_TAG_INTEGER)) != NULL) | |
7671 | limit = attr->values[0].integer; | |
7672 | else | |
7673 | limit = 0; | |
ef416fc2 | 7674 | |
b423cd4c | 7675 | /* |
7676 | * See if we only want to see subscriptions for a specific user... | |
7677 | */ | |
ef416fc2 | 7678 | |
b423cd4c | 7679 | if ((attr = ippFindAttribute(con->request, "my-subscriptions", |
7680 | IPP_TAG_BOOLEAN)) != NULL && | |
7681 | attr->values[0].boolean) | |
7682 | strlcpy(username, get_username(con), sizeof(username)); | |
fa73b229 | 7683 | else |
b423cd4c | 7684 | username[0] = '\0'; |
ef416fc2 | 7685 | |
b423cd4c | 7686 | for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions), count = 0; |
7687 | sub; | |
7688 | sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions)) | |
7689 | if ((!printer || sub->dest == printer) && (!job || sub->job == job) && | |
7690 | (!username[0] || !strcasecmp(username, sub->owner))) | |
fa73b229 | 7691 | { |
b423cd4c | 7692 | ippAddSeparator(con->response); |
7693 | copy_subscription_attrs(con, sub, ra); | |
ef416fc2 | 7694 | |
b423cd4c | 7695 | count ++; |
7696 | if (limit && count >= limit) | |
7697 | break; | |
7698 | } | |
ef416fc2 | 7699 | |
b423cd4c | 7700 | cupsArrayDelete(ra); |
fa73b229 | 7701 | |
b423cd4c | 7702 | if (count) |
7703 | con->response->request.status.status_code = IPP_OK; | |
7704 | else | |
7705 | send_ipp_status(con, IPP_NOT_FOUND, _("No subscriptions found.")); | |
7706 | } | |
ef416fc2 | 7707 | |
ef416fc2 | 7708 | |
b423cd4c | 7709 | /* |
7710 | * 'get_username()' - Get the username associated with a request. | |
7711 | */ | |
ef416fc2 | 7712 | |
b423cd4c | 7713 | static const char * /* O - Username */ |
7714 | get_username(cupsd_client_t *con) /* I - Connection */ | |
7715 | { | |
7716 | ipp_attribute_t *attr; /* Attribute */ | |
ef416fc2 | 7717 | |
ef416fc2 | 7718 | |
b423cd4c | 7719 | if (con->username[0]) |
7720 | return (con->username); | |
7721 | else if ((attr = ippFindAttribute(con->request, "requesting-user-name", | |
7722 | IPP_TAG_NAME)) != NULL) | |
7723 | return (attr->values[0].string.text); | |
7724 | else | |
7725 | return ("anonymous"); | |
ef416fc2 | 7726 | } |
7727 | ||
7728 | ||
7729 | /* | |
b423cd4c | 7730 | * 'hold_job()' - Hold a print job. |
ef416fc2 | 7731 | */ |
7732 | ||
b423cd4c | 7733 | static void |
7734 | hold_job(cupsd_client_t *con, /* I - Client connection */ | |
7735 | ipp_attribute_t *uri) /* I - Job or Printer URI */ | |
ef416fc2 | 7736 | { |
b423cd4c | 7737 | ipp_attribute_t *attr, /* Current job-hold-until */ |
7738 | *newattr; /* New job-hold-until */ | |
7739 | int jobid; /* Job ID */ | |
7740 | char method[HTTP_MAX_URI], /* Method portion of URI */ | |
7741 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
7742 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
7743 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
7744 | int port; /* Port portion of URI */ | |
7745 | cupsd_job_t *job; /* Job information */ | |
7746 | ||
ef416fc2 | 7747 | |
b423cd4c | 7748 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_job(%p[%d], %s)", con, con->http.fd, |
7749 | uri->values[0].string.text); | |
ef416fc2 | 7750 | |
7751 | /* | |
b423cd4c | 7752 | * See if we have a job URI or a printer URI... |
ef416fc2 | 7753 | */ |
7754 | ||
b423cd4c | 7755 | if (!strcmp(uri->name, "printer-uri")) |
7756 | { | |
7757 | /* | |
7758 | * Got a printer URI; see if we also have a job-id attribute... | |
7759 | */ | |
ef416fc2 | 7760 | |
b423cd4c | 7761 | if ((attr = ippFindAttribute(con->request, "job-id", |
7762 | IPP_TAG_INTEGER)) == NULL) | |
7763 | { | |
7764 | send_ipp_status(con, IPP_BAD_REQUEST, | |
7765 | _("Got a printer-uri attribute but no job-id!")); | |
7766 | return; | |
7767 | } | |
ef416fc2 | 7768 | |
b423cd4c | 7769 | jobid = attr->values[0].integer; |
7770 | } | |
ef416fc2 | 7771 | else |
ef416fc2 | 7772 | { |
b423cd4c | 7773 | /* |
7774 | * Got a job URI; parse it to get the job ID... | |
7775 | */ | |
ef416fc2 | 7776 | |
b423cd4c | 7777 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
7778 | sizeof(method), username, sizeof(username), host, | |
7779 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 7780 | |
b423cd4c | 7781 | if (strncmp(resource, "/jobs/", 6)) |
7782 | { | |
7783 | /* | |
7784 | * Not a valid URI! | |
7785 | */ | |
ef416fc2 | 7786 | |
b423cd4c | 7787 | send_ipp_status(con, IPP_BAD_REQUEST, |
7788 | _("Bad job-uri attribute \"%s\"!"), | |
7789 | uri->values[0].string.text); | |
7790 | return; | |
7791 | } | |
ef416fc2 | 7792 | |
b423cd4c | 7793 | jobid = atoi(resource + 6); |
7794 | } | |
ef416fc2 | 7795 | |
ef416fc2 | 7796 | /* |
b423cd4c | 7797 | * See if the job exists... |
ef416fc2 | 7798 | */ |
7799 | ||
b423cd4c | 7800 | if ((job = cupsdFindJob(jobid)) == NULL) |
7801 | { | |
7802 | /* | |
7803 | * Nope - return a "not found" error... | |
7804 | */ | |
7805 | ||
7806 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
7807 | return; | |
7808 | } | |
ef416fc2 | 7809 | |
7810 | /* | |
b423cd4c | 7811 | * See if the job is owned by the requesting user... |
ef416fc2 | 7812 | */ |
7813 | ||
b423cd4c | 7814 | if (!validate_user(job, con, job->username, username, sizeof(username))) |
7815 | { | |
2fb76298 | 7816 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
b423cd4c | 7817 | return; |
7818 | } | |
ef416fc2 | 7819 | |
7820 | /* | |
b423cd4c | 7821 | * Hold the job and return... |
ef416fc2 | 7822 | */ |
7823 | ||
b423cd4c | 7824 | cupsdHoldJob(job); |
ef416fc2 | 7825 | |
d09495fa | 7826 | cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, |
7827 | "Job held by user."); | |
7828 | ||
b423cd4c | 7829 | if ((newattr = ippFindAttribute(con->request, "job-hold-until", |
7830 | IPP_TAG_KEYWORD)) == NULL) | |
7831 | newattr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME); | |
ef416fc2 | 7832 | |
b423cd4c | 7833 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", |
7834 | IPP_TAG_KEYWORD)) == NULL) | |
7835 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); | |
ef416fc2 | 7836 | |
b423cd4c | 7837 | if (attr) |
7838 | { | |
7839 | /* | |
7840 | * Free the old hold value and copy the new one over... | |
7841 | */ | |
ef416fc2 | 7842 | |
757d2cad | 7843 | _cupsStrFree(attr->values[0].string.text); |
ef416fc2 | 7844 | |
b423cd4c | 7845 | if (newattr) |
ef416fc2 | 7846 | { |
b423cd4c | 7847 | attr->value_tag = newattr->value_tag; |
7848 | attr->values[0].string.text = | |
757d2cad | 7849 | _cupsStrAlloc(newattr->values[0].string.text); |
b423cd4c | 7850 | } |
7851 | else | |
7852 | { | |
7853 | attr->value_tag = IPP_TAG_KEYWORD; | |
757d2cad | 7854 | attr->values[0].string.text = _cupsStrAlloc("indefinite"); |
ef416fc2 | 7855 | } |
7856 | ||
b423cd4c | 7857 | /* |
7858 | * Hold job until specified time... | |
7859 | */ | |
ef416fc2 | 7860 | |
b423cd4c | 7861 | cupsdSetJobHoldUntil(job, attr->values[0].string.text); |
d09495fa | 7862 | |
7863 | cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, job->printer, job, | |
7864 | "Job job-hold-until value changed by user."); | |
b423cd4c | 7865 | } |
ef416fc2 | 7866 | |
09a101d6 | 7867 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Held by \"%s\".", jobid, |
b423cd4c | 7868 | username); |
7869 | ||
7870 | con->response->request.status.status_code = IPP_OK; | |
ef416fc2 | 7871 | } |
7872 | ||
7873 | ||
7874 | /* | |
b423cd4c | 7875 | * 'move_job()' - Move a job to a new destination. |
ef416fc2 | 7876 | */ |
7877 | ||
7878 | static void | |
b423cd4c | 7879 | move_job(cupsd_client_t *con, /* I - Client connection */ |
7880 | ipp_attribute_t *uri) /* I - Job URI */ | |
ef416fc2 | 7881 | { |
7882 | http_status_t status; /* Policy status */ | |
7883 | ipp_attribute_t *attr; /* Current attribute */ | |
b423cd4c | 7884 | int jobid; /* Job ID */ |
ef416fc2 | 7885 | cupsd_job_t *job; /* Current job */ |
d09495fa | 7886 | const char *src; /* Source printer/class */ |
b423cd4c | 7887 | cups_ptype_t stype, /* Source type (printer or class) */ |
bc44d920 | 7888 | dtype; /* Destination type (printer/class) */ |
f7deaa1a | 7889 | char scheme[HTTP_MAX_URI], /* Scheme portion of URI */ |
ef416fc2 | 7890 | username[HTTP_MAX_URI], /* Username portion of URI */ |
7891 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
b423cd4c | 7892 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ |
ef416fc2 | 7893 | int port; /* Port portion of URI */ |
b423cd4c | 7894 | cupsd_printer_t *sprinter, /* Source printer */ |
7895 | *dprinter; /* Destination printer */ | |
ef416fc2 | 7896 | |
7897 | ||
b423cd4c | 7898 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->http.fd, |
ef416fc2 | 7899 | uri->values[0].string.text); |
7900 | ||
7901 | /* | |
b423cd4c | 7902 | * Get the new printer or class... |
ef416fc2 | 7903 | */ |
7904 | ||
b423cd4c | 7905 | if ((attr = ippFindAttribute(con->request, "job-printer-uri", |
7906 | IPP_TAG_URI)) == NULL) | |
ef416fc2 | 7907 | { |
b423cd4c | 7908 | /* |
7909 | * Need job-printer-uri... | |
7910 | */ | |
ef416fc2 | 7911 | |
b423cd4c | 7912 | send_ipp_status(con, IPP_BAD_REQUEST, |
7913 | _("job-printer-uri attribute missing!")); | |
7914 | return; | |
ef416fc2 | 7915 | } |
f7faf1f5 | 7916 | |
f7deaa1a | 7917 | if (!cupsdValidateDest(attr->values[0].string.text, &dtype, &dprinter)) |
ef416fc2 | 7918 | { |
b423cd4c | 7919 | /* |
7920 | * Bad URI... | |
7921 | */ | |
ef416fc2 | 7922 | |
b423cd4c | 7923 | send_ipp_status(con, IPP_NOT_FOUND, |
7924 | _("The printer or class was not found.")); | |
7925 | return; | |
ef416fc2 | 7926 | } |
7927 | ||
ef416fc2 | 7928 | /* |
b423cd4c | 7929 | * See if we have a job URI or a printer URI... |
ef416fc2 | 7930 | */ |
7931 | ||
f7deaa1a | 7932 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme, |
7933 | sizeof(scheme), username, sizeof(username), host, | |
b423cd4c | 7934 | sizeof(host), &port, resource, sizeof(resource)); |
7935 | ||
7936 | if (!strcmp(uri->name, "printer-uri")) | |
ef416fc2 | 7937 | { |
7938 | /* | |
b423cd4c | 7939 | * Got a printer URI; see if we also have a job-id attribute... |
ef416fc2 | 7940 | */ |
7941 | ||
b423cd4c | 7942 | if ((attr = ippFindAttribute(con->request, "job-id", |
7943 | IPP_TAG_INTEGER)) == NULL) | |
ef416fc2 | 7944 | { |
b423cd4c | 7945 | /* |
7946 | * Move all jobs... | |
7947 | */ | |
7948 | ||
f7deaa1a | 7949 | if ((src = cupsdValidateDest(uri->values[0].string.text, &stype, |
7950 | &sprinter)) == NULL) | |
b423cd4c | 7951 | { |
7952 | /* | |
7953 | * Bad URI... | |
7954 | */ | |
7955 | ||
7956 | send_ipp_status(con, IPP_NOT_FOUND, | |
7957 | _("The printer or class was not found.")); | |
7958 | return; | |
7959 | } | |
7960 | ||
7961 | job = NULL; | |
7962 | } | |
7963 | else | |
7964 | { | |
7965 | /* | |
7966 | * Otherwise, just move a single job... | |
7967 | */ | |
7968 | ||
7969 | if ((job = cupsdFindJob(attr->values[0].integer)) == NULL) | |
7970 | { | |
7971 | /* | |
7972 | * Nope - return a "not found" error... | |
7973 | */ | |
7974 | ||
7975 | send_ipp_status(con, IPP_NOT_FOUND, | |
7976 | _("Job #%d does not exist!"), attr->values[0].integer); | |
7977 | return; | |
7978 | } | |
7979 | else | |
7980 | { | |
7981 | /* | |
7982 | * Job found, initialize source pointers... | |
7983 | */ | |
7984 | ||
7985 | src = NULL; | |
7986 | sprinter = NULL; | |
7987 | } | |
ef416fc2 | 7988 | } |
7989 | } | |
7990 | else | |
7991 | { | |
7992 | /* | |
b423cd4c | 7993 | * Got a job URI; parse it to get the job ID... |
ef416fc2 | 7994 | */ |
7995 | ||
b423cd4c | 7996 | if (strncmp(resource, "/jobs/", 6)) |
7997 | { | |
7998 | /* | |
7999 | * Not a valid URI! | |
8000 | */ | |
8001 | ||
8002 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8003 | _("Bad job-uri attribute \"%s\"!"), | |
8004 | uri->values[0].string.text); | |
8005 | return; | |
8006 | } | |
ef416fc2 | 8007 | |
ef416fc2 | 8008 | /* |
b423cd4c | 8009 | * See if the job exists... |
ef416fc2 | 8010 | */ |
8011 | ||
b423cd4c | 8012 | jobid = atoi(resource + 6); |
ef416fc2 | 8013 | |
b423cd4c | 8014 | if ((job = cupsdFindJob(jobid)) == NULL) |
ef416fc2 | 8015 | { |
8016 | /* | |
b423cd4c | 8017 | * Nope - return a "not found" error... |
ef416fc2 | 8018 | */ |
8019 | ||
b423cd4c | 8020 | send_ipp_status(con, IPP_NOT_FOUND, |
8021 | _("Job #%d does not exist!"), jobid); | |
8022 | return; | |
ef416fc2 | 8023 | } |
8024 | else | |
b423cd4c | 8025 | { |
8026 | /* | |
8027 | * Job found, initialize source pointers... | |
8028 | */ | |
ef416fc2 | 8029 | |
b423cd4c | 8030 | src = NULL; |
8031 | sprinter = NULL; | |
8032 | } | |
ef416fc2 | 8033 | } |
8034 | ||
ac884b6a MS |
8035 | /* |
8036 | * Check the policy of the destination printer... | |
8037 | */ | |
8038 | ||
8039 | if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, | |
8040 | job ? job->username : NULL)) != HTTP_OK) | |
8041 | { | |
8042 | send_http_error(con, status, dprinter); | |
8043 | return; | |
8044 | } | |
8045 | ||
ef416fc2 | 8046 | /* |
b423cd4c | 8047 | * Now move the job or jobs... |
ef416fc2 | 8048 | */ |
8049 | ||
b423cd4c | 8050 | if (job) |
8051 | { | |
8052 | /* | |
8053 | * See if the job has been completed... | |
8054 | */ | |
8055 | ||
8056 | if (job->state_value > IPP_JOB_STOPPED) | |
8057 | { | |
8058 | /* | |
8059 | * Return a "not-possible" error... | |
8060 | */ | |
8061 | ||
8062 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
8063 | _("Job #%d is finished and cannot be altered!"), | |
8064 | job->id); | |
8065 | return; | |
8066 | } | |
ef416fc2 | 8067 | |
b423cd4c | 8068 | /* |
8069 | * See if the job is owned by the requesting user... | |
8070 | */ | |
ef416fc2 | 8071 | |
b423cd4c | 8072 | if (!validate_user(job, con, job->username, username, sizeof(username))) |
8073 | { | |
2fb76298 | 8074 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
b423cd4c | 8075 | return; |
8076 | } | |
ef416fc2 | 8077 | |
ef416fc2 | 8078 | /* |
b423cd4c | 8079 | * Move the job to a different printer or class... |
ef416fc2 | 8080 | */ |
8081 | ||
e53920b9 | 8082 | cupsdMoveJob(job, dprinter); |
ef416fc2 | 8083 | } |
b423cd4c | 8084 | else |
8085 | { | |
8086 | /* | |
8087 | * Got the source printer, now look through the jobs... | |
8088 | */ | |
ef416fc2 | 8089 | |
b423cd4c | 8090 | for (job = (cupsd_job_t *)cupsArrayFirst(Jobs); |
8091 | job; | |
8092 | job = (cupsd_job_t *)cupsArrayNext(Jobs)) | |
8093 | { | |
8094 | /* | |
8095 | * See if the job is pointing at the source printer or has not been | |
8096 | * completed... | |
8097 | */ | |
ef416fc2 | 8098 | |
b423cd4c | 8099 | if (strcasecmp(job->dest, src) || |
8100 | job->state_value > IPP_JOB_STOPPED) | |
8101 | continue; | |
ef416fc2 | 8102 | |
b423cd4c | 8103 | /* |
8104 | * See if the job can be moved by the requesting user... | |
8105 | */ | |
ef416fc2 | 8106 | |
b423cd4c | 8107 | if (!validate_user(job, con, job->username, username, sizeof(username))) |
8108 | continue; | |
ef416fc2 | 8109 | |
b423cd4c | 8110 | /* |
8111 | * Move the job to a different printer or class... | |
8112 | */ | |
ef416fc2 | 8113 | |
e53920b9 | 8114 | cupsdMoveJob(job, dprinter); |
b423cd4c | 8115 | } |
ef416fc2 | 8116 | } |
8117 | ||
8118 | /* | |
b423cd4c | 8119 | * Start jobs if possible... |
ef416fc2 | 8120 | */ |
8121 | ||
b423cd4c | 8122 | cupsdCheckJobs(); |
ef416fc2 | 8123 | |
8124 | /* | |
b423cd4c | 8125 | * Return with "everything is OK" status... |
ef416fc2 | 8126 | */ |
8127 | ||
b423cd4c | 8128 | con->response->request.status.status_code = IPP_OK; |
8129 | } | |
ef416fc2 | 8130 | |
ef416fc2 | 8131 | |
b423cd4c | 8132 | /* |
8133 | * 'ppd_parse_line()' - Parse a PPD default line. | |
8134 | */ | |
ef416fc2 | 8135 | |
b423cd4c | 8136 | static int /* O - 0 on success, -1 on failure */ |
8137 | ppd_parse_line(const char *line, /* I - Line */ | |
8138 | char *option, /* O - Option name */ | |
8139 | int olen, /* I - Size of option name */ | |
8140 | char *choice, /* O - Choice name */ | |
8141 | int clen) /* I - Size of choice name */ | |
8142 | { | |
8143 | /* | |
8144 | * Verify this is a default option line... | |
8145 | */ | |
ef416fc2 | 8146 | |
b423cd4c | 8147 | if (strncmp(line, "*Default", 8)) |
8148 | return (-1); | |
ef416fc2 | 8149 | |
b423cd4c | 8150 | /* |
8151 | * Read the option name... | |
8152 | */ | |
8153 | ||
8154 | for (line += 8, olen --; isalnum(*line & 255); line ++) | |
8155 | if (olen > 0) | |
8156 | { | |
8157 | *option++ = *line; | |
8158 | olen --; | |
ef416fc2 | 8159 | } |
8160 | ||
b423cd4c | 8161 | *option = '\0'; |
ef416fc2 | 8162 | |
b423cd4c | 8163 | /* |
8164 | * Skip everything else up to the colon (:)... | |
8165 | */ | |
ef416fc2 | 8166 | |
b423cd4c | 8167 | while (*line && *line != ':') |
8168 | line ++; | |
ef416fc2 | 8169 | |
b423cd4c | 8170 | if (!*line) |
8171 | return (-1); | |
ef416fc2 | 8172 | |
b423cd4c | 8173 | line ++; |
ef416fc2 | 8174 | |
b423cd4c | 8175 | /* |
8176 | * Now grab the option choice, skipping leading whitespace... | |
8177 | */ | |
ef416fc2 | 8178 | |
b423cd4c | 8179 | while (isspace(*line & 255)) |
8180 | line ++; | |
ef416fc2 | 8181 | |
b423cd4c | 8182 | for (clen --; isalnum(*line & 255); line ++) |
8183 | if (clen > 0) | |
8184 | { | |
8185 | *choice++ = *line; | |
8186 | clen --; | |
8187 | } | |
ef416fc2 | 8188 | |
b423cd4c | 8189 | *choice = '\0'; |
ef416fc2 | 8190 | |
b423cd4c | 8191 | /* |
8192 | * Return with no errors... | |
8193 | */ | |
ef416fc2 | 8194 | |
b423cd4c | 8195 | return (0); |
8196 | } | |
ef416fc2 | 8197 | |
ef416fc2 | 8198 | |
b423cd4c | 8199 | /* |
8200 | * 'print_job()' - Print a file to a printer or class. | |
8201 | */ | |
ef416fc2 | 8202 | |
b423cd4c | 8203 | static void |
8204 | print_job(cupsd_client_t *con, /* I - Client connection */ | |
8205 | ipp_attribute_t *uri) /* I - Printer URI */ | |
8206 | { | |
8207 | ipp_attribute_t *attr; /* Current attribute */ | |
8208 | ipp_attribute_t *format; /* Document-format attribute */ | |
f7deaa1a | 8209 | const char *default_format; /* document-format-default value */ |
b423cd4c | 8210 | cupsd_job_t *job; /* New job */ |
8211 | char filename[1024]; /* Job filename */ | |
8212 | mime_type_t *filetype; /* Type of file */ | |
8213 | char super[MIME_MAX_SUPER], /* Supertype of file */ | |
8214 | type[MIME_MAX_TYPE], /* Subtype of file */ | |
8215 | mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; | |
8216 | /* Textual name of mime type */ | |
8217 | cupsd_printer_t *printer; /* Printer data */ | |
8218 | struct stat fileinfo; /* File information */ | |
8219 | int kbytes; /* Size of file */ | |
8220 | int compression; /* Document compression */ | |
ef416fc2 | 8221 | |
ef416fc2 | 8222 | |
b423cd4c | 8223 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "print_job(%p[%d], %s)", con, con->http.fd, |
8224 | uri->values[0].string.text); | |
ef416fc2 | 8225 | |
b423cd4c | 8226 | /* |
8227 | * Validate print file attributes, for now just document-format and | |
8228 | * compression (CUPS only supports "none" and "gzip")... | |
8229 | */ | |
ef416fc2 | 8230 | |
b423cd4c | 8231 | compression = CUPS_FILE_NONE; |
ef416fc2 | 8232 | |
b423cd4c | 8233 | if ((attr = ippFindAttribute(con->request, "compression", |
8234 | IPP_TAG_KEYWORD)) != NULL) | |
8235 | { | |
8236 | if (strcmp(attr->values[0].string.text, "none") | |
8237 | #ifdef HAVE_LIBZ | |
8238 | && strcmp(attr->values[0].string.text, "gzip") | |
8239 | #endif /* HAVE_LIBZ */ | |
8240 | ) | |
8241 | { | |
8242 | send_ipp_status(con, IPP_ATTRIBUTES, | |
8243 | _("Unsupported compression \"%s\"!"), | |
8244 | attr->values[0].string.text); | |
8245 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD, | |
8246 | "compression", NULL, attr->values[0].string.text); | |
8247 | return; | |
8248 | } | |
ef416fc2 | 8249 | |
b423cd4c | 8250 | #ifdef HAVE_LIBZ |
8251 | if (!strcmp(attr->values[0].string.text, "gzip")) | |
8252 | compression = CUPS_FILE_GZIP; | |
8253 | #endif /* HAVE_LIBZ */ | |
8254 | } | |
ef416fc2 | 8255 | |
b423cd4c | 8256 | /* |
8257 | * Do we have a file to print? | |
8258 | */ | |
ef416fc2 | 8259 | |
b423cd4c | 8260 | if (!con->filename) |
8261 | { | |
8262 | send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!")); | |
8263 | return; | |
8264 | } | |
ef416fc2 | 8265 | |
f7deaa1a | 8266 | /* |
8267 | * Is the destination valid? | |
8268 | */ | |
8269 | ||
8270 | if (!cupsdValidateDest(uri->values[0].string.text, NULL, &printer)) | |
8271 | { | |
8272 | /* | |
8273 | * Bad URI... | |
8274 | */ | |
8275 | ||
8276 | send_ipp_status(con, IPP_NOT_FOUND, | |
8277 | _("The printer or class was not found.")); | |
8278 | return; | |
8279 | } | |
8280 | ||
b423cd4c | 8281 | /* |
8282 | * Is it a format we support? | |
8283 | */ | |
ef416fc2 | 8284 | |
b423cd4c | 8285 | if ((format = ippFindAttribute(con->request, "document-format", |
8286 | IPP_TAG_MIMETYPE)) != NULL) | |
8287 | { | |
8288 | /* | |
8289 | * Grab format from client... | |
8290 | */ | |
8291 | ||
f7deaa1a | 8292 | if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, |
8293 | type) != 2) | |
b423cd4c | 8294 | { |
8295 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8296 | _("Could not scan type \"%s\"!"), | |
8297 | format->values[0].string.text); | |
8298 | return; | |
ef416fc2 | 8299 | } |
b423cd4c | 8300 | } |
f7deaa1a | 8301 | else if ((default_format = cupsGetOption("document-format", |
8302 | printer->num_options, | |
8303 | printer->options)) != NULL) | |
8304 | { | |
8305 | /* | |
8306 | * Use default document format... | |
8307 | */ | |
8308 | ||
8309 | if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2) | |
8310 | { | |
8311 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8312 | _("Could not scan type \"%s\"!"), | |
8313 | default_format); | |
8314 | return; | |
8315 | } | |
8316 | } | |
b423cd4c | 8317 | else |
8318 | { | |
8319 | /* | |
f7deaa1a | 8320 | * Auto-type it! |
b423cd4c | 8321 | */ |
8322 | ||
8323 | strcpy(super, "application"); | |
8324 | strcpy(type, "octet-stream"); | |
8325 | } | |
ef416fc2 | 8326 | |
b423cd4c | 8327 | if (!strcmp(super, "application") && !strcmp(type, "octet-stream")) |
8328 | { | |
ef416fc2 | 8329 | /* |
b423cd4c | 8330 | * Auto-type the file... |
ef416fc2 | 8331 | */ |
8332 | ||
b423cd4c | 8333 | ipp_attribute_t *doc_name; /* document-name attribute */ |
8334 | ||
8335 | ||
a0f6818e | 8336 | cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job ???] Auto-typing file..."); |
b423cd4c | 8337 | |
8338 | doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME); | |
8339 | filetype = mimeFileType(MimeDatabase, con->filename, | |
8340 | doc_name ? doc_name->values[0].string.text : NULL, | |
8341 | &compression); | |
8342 | ||
f7deaa1a | 8343 | if (!filetype) |
8344 | filetype = mimeType(MimeDatabase, super, type); | |
a0f6818e MS |
8345 | |
8346 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job ???] Request file type is %s/%s.", | |
8347 | filetype->super, filetype->type); | |
f7deaa1a | 8348 | } |
8349 | else | |
8350 | filetype = mimeType(MimeDatabase, super, type); | |
ef416fc2 | 8351 | |
f7deaa1a | 8352 | if (filetype && |
8353 | (!format || | |
8354 | (!strcmp(super, "application") && !strcmp(type, "octet-stream")))) | |
8355 | { | |
8356 | /* | |
8357 | * Replace the document-format attribute value with the auto-typed or | |
8358 | * default one. | |
8359 | */ | |
b423cd4c | 8360 | |
f7deaa1a | 8361 | snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, |
8362 | filetype->type); | |
ed486911 | 8363 | |
f7deaa1a | 8364 | if (format) |
8365 | { | |
8366 | _cupsStrFree(format->values[0].string.text); | |
8367 | ||
8368 | format->values[0].string.text = _cupsStrAlloc(mimetype); | |
ef416fc2 | 8369 | } |
b423cd4c | 8370 | else |
f7deaa1a | 8371 | ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, |
8372 | "document-format", NULL, mimetype); | |
ef416fc2 | 8373 | } |
f7deaa1a | 8374 | else if (!filetype) |
b423cd4c | 8375 | { |
8376 | send_ipp_status(con, IPP_DOCUMENT_FORMAT, | |
8377 | _("Unsupported format \'%s/%s\'!"), super, type); | |
8378 | cupsdLogMessage(CUPSD_LOG_INFO, | |
8379 | "Hint: Do you have the raw file printing rules enabled?"); | |
8380 | ||
8381 | if (format) | |
8382 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE, | |
8383 | "document-format", NULL, format->values[0].string.text); | |
8384 | ||
8385 | return; | |
8386 | } | |
8387 | ||
b423cd4c | 8388 | /* |
8389 | * Read any embedded job ticket info from PS files... | |
8390 | */ | |
8391 | ||
8392 | if (!strcasecmp(filetype->super, "application") && | |
8393 | !strcasecmp(filetype->type, "postscript")) | |
8394 | read_ps_job_ticket(con); | |
8395 | ||
8396 | /* | |
8397 | * Create the job object... | |
8398 | */ | |
8399 | ||
f7deaa1a | 8400 | if ((job = add_job(con, printer, filetype)) == NULL) |
b423cd4c | 8401 | return; |
8402 | ||
8403 | /* | |
8404 | * Update quota data... | |
8405 | */ | |
8406 | ||
8407 | if (stat(con->filename, &fileinfo)) | |
8408 | kbytes = 0; | |
8409 | else | |
8410 | kbytes = (fileinfo.st_size + 1023) / 1024; | |
8411 | ||
8412 | cupsdUpdateQuota(printer, job->username, 0, kbytes); | |
8413 | ||
8414 | if ((attr = ippFindAttribute(job->attrs, "job-k-octets", | |
8415 | IPP_TAG_INTEGER)) != NULL) | |
8416 | attr->values[0].integer += kbytes; | |
8417 | ||
ef416fc2 | 8418 | /* |
8419 | * Add the job file... | |
8420 | */ | |
8421 | ||
8422 | if (add_file(con, job, filetype, compression)) | |
8423 | return; | |
8424 | ||
8425 | snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id, | |
8426 | job->num_files); | |
8427 | rename(con->filename, filename); | |
8428 | cupsdClearString(&con->filename); | |
8429 | ||
8430 | /* | |
8431 | * See if we need to add the ending sheet... | |
8432 | */ | |
8433 | ||
91c84a35 MS |
8434 | if (cupsdTimeoutJob(job)) |
8435 | return; | |
ef416fc2 | 8436 | |
ef416fc2 | 8437 | /* |
8438 | * Log and save the job... | |
8439 | */ | |
8440 | ||
a0f6818e MS |
8441 | cupsdLogMessage(CUPSD_LOG_INFO, |
8442 | "[Job %d] File of type %s/%s queued by \"%s\".", job->id, | |
8443 | filetype->super, filetype->type, job->username); | |
8444 | cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] hold_until=%d", job->id, | |
ef416fc2 | 8445 | (int)job->hold_until); |
8446 | ||
ef416fc2 | 8447 | /* |
8448 | * Start the job if possible... | |
8449 | */ | |
8450 | ||
8451 | cupsdCheckJobs(); | |
8452 | } | |
8453 | ||
8454 | ||
8455 | /* | |
8456 | * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file. | |
8457 | * | |
8458 | * This function only gets called when printing a single PostScript | |
8459 | * file using the Print-Job operation. It doesn't work for Create-Job + | |
8460 | * Send-File, since the job attributes need to be set at job creation | |
8461 | * time for banners to work. The embedded PS job ticket stuff is here | |
8462 | * only to allow the Windows printer driver for CUPS to pass in JCL | |
8463 | * options and IPP attributes which otherwise would be lost. | |
8464 | * | |
8465 | * The format of a PS job ticket is simple: | |
8466 | * | |
8467 | * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN | |
8468 | * | |
8469 | * %cupsJobTicket: attr1=value1 | |
8470 | * %cupsJobTicket: attr2=value2 | |
8471 | * ... | |
8472 | * %cupsJobTicket: attrN=valueN | |
8473 | * | |
8474 | * Job ticket lines must appear immediately after the first line that | |
8475 | * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop | |
8476 | * looking for job ticket info when it finds a line that does not begin | |
8477 | * with "%cupsJobTicket:". | |
8478 | * | |
8479 | * The maximum length of a job ticket line, including the prefix, is | |
8480 | * 255 characters to conform with the Adobe DSC. | |
8481 | * | |
8482 | * Read-only attributes are rejected with a notice to the error log in | |
8483 | * case a malicious user tries anything. Since the job ticket is read | |
8484 | * prior to attribute validation in print_job(), job ticket attributes | |
8485 | * will go through the same validation as IPP attributes... | |
8486 | */ | |
8487 | ||
8488 | static void | |
8489 | read_ps_job_ticket(cupsd_client_t *con) /* I - Client connection */ | |
8490 | { | |
8491 | cups_file_t *fp; /* File to read from */ | |
8492 | char line[256]; /* Line data */ | |
8493 | int num_options; /* Number of options */ | |
8494 | cups_option_t *options; /* Options */ | |
8495 | ipp_t *ticket; /* New attributes */ | |
8496 | ipp_attribute_t *attr, /* Current attribute */ | |
8497 | *attr2, /* Job attribute */ | |
8498 | *prev2; /* Previous job attribute */ | |
8499 | ||
8500 | ||
8501 | /* | |
8502 | * First open the print file... | |
8503 | */ | |
8504 | ||
8505 | if ((fp = cupsFileOpen(con->filename, "rb")) == NULL) | |
8506 | { | |
8507 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
8508 | "read_ps_job_ticket: Unable to open PostScript print file " | |
8509 | "- %s", | |
8510 | strerror(errno)); | |
8511 | return; | |
8512 | } | |
8513 | ||
8514 | /* | |
8515 | * Skip the first line... | |
8516 | */ | |
8517 | ||
8518 | if (cupsFileGets(fp, line, sizeof(line)) == NULL) | |
8519 | { | |
8520 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
8521 | "read_ps_job_ticket: Unable to read from PostScript print " | |
8522 | "file - %s", | |
8523 | strerror(errno)); | |
8524 | cupsFileClose(fp); | |
8525 | return; | |
8526 | } | |
8527 | ||
fa73b229 | 8528 | if (strncmp(line, "%!PS-Adobe-", 11)) |
ef416fc2 | 8529 | { |
8530 | /* | |
8531 | * Not a DSC-compliant file, so no job ticket info will be available... | |
8532 | */ | |
8533 | ||
8534 | cupsFileClose(fp); | |
8535 | return; | |
8536 | } | |
8537 | ||
8538 | /* | |
8539 | * Read job ticket info from the file... | |
8540 | */ | |
8541 | ||
8542 | num_options = 0; | |
8543 | options = NULL; | |
8544 | ||
fa73b229 | 8545 | while (cupsFileGets(fp, line, sizeof(line))) |
ef416fc2 | 8546 | { |
8547 | /* | |
8548 | * Stop at the first non-ticket line... | |
8549 | */ | |
8550 | ||
fa73b229 | 8551 | if (strncmp(line, "%cupsJobTicket:", 15)) |
ef416fc2 | 8552 | break; |
8553 | ||
8554 | /* | |
8555 | * Add the options to the option array... | |
8556 | */ | |
8557 | ||
8558 | num_options = cupsParseOptions(line + 15, num_options, &options); | |
8559 | } | |
8560 | ||
8561 | /* | |
8562 | * Done with the file; see if we have any options... | |
8563 | */ | |
8564 | ||
8565 | cupsFileClose(fp); | |
8566 | ||
8567 | if (num_options == 0) | |
8568 | return; | |
8569 | ||
8570 | /* | |
8571 | * OK, convert the options to an attribute list, and apply them to | |
8572 | * the request... | |
8573 | */ | |
8574 | ||
8575 | ticket = ippNew(); | |
8576 | cupsEncodeOptions(ticket, num_options, options); | |
8577 | ||
8578 | /* | |
8579 | * See what the user wants to change. | |
8580 | */ | |
8581 | ||
fa73b229 | 8582 | for (attr = ticket->attrs; attr; attr = attr->next) |
ef416fc2 | 8583 | { |
8584 | if (attr->group_tag != IPP_TAG_JOB || !attr->name) | |
8585 | continue; | |
8586 | ||
8587 | if (!strcmp(attr->name, "job-originating-host-name") || | |
8588 | !strcmp(attr->name, "job-originating-user-name") || | |
8589 | !strcmp(attr->name, "job-media-sheets-completed") || | |
8590 | !strcmp(attr->name, "job-k-octets") || | |
8591 | !strcmp(attr->name, "job-id") || | |
8592 | !strncmp(attr->name, "job-state", 9) || | |
8593 | !strncmp(attr->name, "time-at-", 8)) | |
8594 | continue; /* Read-only attrs */ | |
8595 | ||
fa73b229 | 8596 | if ((attr2 = ippFindAttribute(con->request, attr->name, |
8597 | IPP_TAG_ZERO)) != NULL) | |
ef416fc2 | 8598 | { |
8599 | /* | |
8600 | * Some other value; first free the old value... | |
8601 | */ | |
8602 | ||
8603 | if (con->request->attrs == attr2) | |
8604 | { | |
8605 | con->request->attrs = attr2->next; | |
8606 | prev2 = NULL; | |
8607 | } | |
8608 | else | |
8609 | { | |
fa73b229 | 8610 | for (prev2 = con->request->attrs; prev2; prev2 = prev2->next) |
ef416fc2 | 8611 | if (prev2->next == attr2) |
8612 | { | |
8613 | prev2->next = attr2->next; | |
8614 | break; | |
8615 | } | |
8616 | } | |
8617 | ||
8618 | if (con->request->last == attr2) | |
8619 | con->request->last = prev2; | |
8620 | ||
757d2cad | 8621 | _ippFreeAttr(attr2); |
ef416fc2 | 8622 | } |
8623 | ||
8624 | /* | |
8625 | * Add new option by copying it... | |
8626 | */ | |
8627 | ||
8628 | copy_attribute(con->request, attr, 0); | |
8629 | } | |
8630 | ||
8631 | /* | |
8632 | * Then free the attribute list and option array... | |
8633 | */ | |
8634 | ||
8635 | ippDelete(ticket); | |
8636 | cupsFreeOptions(num_options, options); | |
8637 | } | |
8638 | ||
8639 | ||
8640 | /* | |
8641 | * 'reject_jobs()' - Reject print jobs to a printer. | |
8642 | */ | |
8643 | ||
8644 | static void | |
8645 | reject_jobs(cupsd_client_t *con, /* I - Client connection */ | |
8646 | ipp_attribute_t *uri) /* I - Printer or class URI */ | |
8647 | { | |
8648 | http_status_t status; /* Policy status */ | |
bc44d920 | 8649 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 8650 | cupsd_printer_t *printer; /* Printer data */ |
8651 | ipp_attribute_t *attr; /* printer-state-message text */ | |
8652 | ||
8653 | ||
8654 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "reject_jobs(%p[%d], %s)", con, | |
8655 | con->http.fd, uri->values[0].string.text); | |
8656 | ||
8657 | /* | |
8658 | * Is the destination valid? | |
8659 | */ | |
8660 | ||
f7deaa1a | 8661 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 8662 | { |
8663 | /* | |
8664 | * Bad URI... | |
8665 | */ | |
8666 | ||
8667 | send_ipp_status(con, IPP_NOT_FOUND, | |
8668 | _("The printer or class was not found.")); | |
8669 | return; | |
8670 | } | |
8671 | ||
8672 | /* | |
8673 | * Check policy... | |
8674 | */ | |
8675 | ||
8676 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) | |
8677 | { | |
f899b121 | 8678 | send_http_error(con, status, printer); |
ef416fc2 | 8679 | return; |
8680 | } | |
8681 | ||
8682 | /* | |
8683 | * Reject jobs sent to the printer... | |
8684 | */ | |
8685 | ||
8686 | printer->accepting = 0; | |
8687 | ||
8688 | if ((attr = ippFindAttribute(con->request, "printer-state-message", | |
8689 | IPP_TAG_TEXT)) == NULL) | |
8690 | strcpy(printer->state_message, "Rejecting Jobs"); | |
8691 | else | |
8692 | strlcpy(printer->state_message, attr->values[0].string.text, | |
8693 | sizeof(printer->state_message)); | |
8694 | ||
8695 | cupsdAddPrinterHistory(printer); | |
8696 | ||
8697 | if (dtype & CUPS_PRINTER_CLASS) | |
8698 | { | |
3dfe78b3 | 8699 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
ef416fc2 | 8700 | |
8701 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" rejecting jobs (\"%s\").", | |
f7deaa1a | 8702 | printer->name, get_username(con)); |
ef416fc2 | 8703 | } |
8704 | else | |
8705 | { | |
3dfe78b3 | 8706 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
ef416fc2 | 8707 | |
8708 | cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" rejecting jobs (\"%s\").", | |
f7deaa1a | 8709 | printer->name, get_username(con)); |
ef416fc2 | 8710 | } |
8711 | ||
8712 | /* | |
8713 | * Everything was ok, so return OK status... | |
8714 | */ | |
8715 | ||
8716 | con->response->request.status.status_code = IPP_OK; | |
8717 | } | |
8718 | ||
8719 | ||
8720 | /* | |
8721 | * 'release_job()' - Release a held print job. | |
8722 | */ | |
8723 | ||
8724 | static void | |
8725 | release_job(cupsd_client_t *con, /* I - Client connection */ | |
8726 | ipp_attribute_t *uri) /* I - Job or Printer URI */ | |
8727 | { | |
8728 | ipp_attribute_t *attr; /* Current attribute */ | |
8729 | int jobid; /* Job ID */ | |
8730 | char method[HTTP_MAX_URI], /* Method portion of URI */ | |
8731 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
8732 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
8733 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
8734 | int port; /* Port portion of URI */ | |
8735 | cupsd_job_t *job; /* Job information */ | |
8736 | ||
8737 | ||
8738 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "release_job(%p[%d], %s)", con, | |
8739 | con->http.fd, uri->values[0].string.text); | |
8740 | ||
8741 | /* | |
8742 | * See if we have a job URI or a printer URI... | |
8743 | */ | |
8744 | ||
8745 | if (!strcmp(uri->name, "printer-uri")) | |
8746 | { | |
8747 | /* | |
8748 | * Got a printer URI; see if we also have a job-id attribute... | |
8749 | */ | |
8750 | ||
fa73b229 | 8751 | if ((attr = ippFindAttribute(con->request, "job-id", |
8752 | IPP_TAG_INTEGER)) == NULL) | |
ef416fc2 | 8753 | { |
8754 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8755 | _("Got a printer-uri attribute but no job-id!")); | |
8756 | return; | |
8757 | } | |
8758 | ||
8759 | jobid = attr->values[0].integer; | |
8760 | } | |
8761 | else | |
8762 | { | |
8763 | /* | |
8764 | * Got a job URI; parse it to get the job ID... | |
8765 | */ | |
8766 | ||
a4d04587 | 8767 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
8768 | sizeof(method), username, sizeof(username), host, | |
8769 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 8770 | |
8771 | if (strncmp(resource, "/jobs/", 6)) | |
8772 | { | |
8773 | /* | |
8774 | * Not a valid URI! | |
8775 | */ | |
8776 | ||
8777 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8778 | _("Bad job-uri attribute \"%s\"!"), | |
8779 | uri->values[0].string.text); | |
8780 | return; | |
8781 | } | |
8782 | ||
8783 | jobid = atoi(resource + 6); | |
8784 | } | |
8785 | ||
8786 | /* | |
8787 | * See if the job exists... | |
8788 | */ | |
8789 | ||
8790 | if ((job = cupsdFindJob(jobid)) == NULL) | |
8791 | { | |
8792 | /* | |
8793 | * Nope - return a "not found" error... | |
8794 | */ | |
8795 | ||
8796 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
8797 | return; | |
8798 | } | |
8799 | ||
8800 | /* | |
8801 | * See if job is "held"... | |
8802 | */ | |
8803 | ||
bd7854cb | 8804 | if (job->state_value != IPP_JOB_HELD) |
ef416fc2 | 8805 | { |
8806 | /* | |
8807 | * Nope - return a "not possible" error... | |
8808 | */ | |
8809 | ||
8810 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not held!"), jobid); | |
8811 | return; | |
8812 | } | |
8813 | ||
8814 | /* | |
8815 | * See if the job is owned by the requesting user... | |
8816 | */ | |
8817 | ||
8818 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
8819 | { | |
2fb76298 | 8820 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
ef416fc2 | 8821 | return; |
8822 | } | |
8823 | ||
8824 | /* | |
8825 | * Reset the job-hold-until value to "no-hold"... | |
8826 | */ | |
8827 | ||
fa73b229 | 8828 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", |
8829 | IPP_TAG_KEYWORD)) == NULL) | |
ef416fc2 | 8830 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); |
8831 | ||
fa73b229 | 8832 | if (attr) |
ef416fc2 | 8833 | { |
757d2cad | 8834 | _cupsStrFree(attr->values[0].string.text); |
4400e98d | 8835 | |
ef416fc2 | 8836 | attr->value_tag = IPP_TAG_KEYWORD; |
757d2cad | 8837 | attr->values[0].string.text = _cupsStrAlloc("no-hold"); |
d09495fa | 8838 | |
8839 | cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, job->printer, job, | |
8840 | "Job job-hold-until value changed by user."); | |
ef416fc2 | 8841 | } |
8842 | ||
8843 | /* | |
8844 | * Release the job and return... | |
8845 | */ | |
8846 | ||
8847 | cupsdReleaseJob(job); | |
8848 | ||
d09495fa | 8849 | cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, |
8850 | "Job released by user."); | |
8851 | ||
09a101d6 | 8852 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Released by \"%s\".", jobid, |
ef416fc2 | 8853 | username); |
8854 | ||
8855 | con->response->request.status.status_code = IPP_OK; | |
8856 | } | |
8857 | ||
8858 | ||
8859 | /* | |
8860 | * 'renew_subscription()' - Renew an existing subscription... | |
8861 | */ | |
8862 | ||
8863 | static void | |
8864 | renew_subscription( | |
8865 | cupsd_client_t *con, /* I - Client connection */ | |
8866 | int sub_id) /* I - Subscription ID */ | |
8867 | { | |
bd7854cb | 8868 | http_status_t status; /* Policy status */ |
8869 | cupsd_subscription_t *sub; /* Subscription */ | |
8870 | ipp_attribute_t *lease; /* notify-lease-duration */ | |
8871 | ||
8872 | ||
8873 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
8874 | "renew_subscription(con=%p[%d], sub_id=%d)", | |
8875 | con, con->http.fd, sub_id); | |
8876 | ||
8877 | /* | |
8878 | * Is the subscription ID valid? | |
8879 | */ | |
8880 | ||
8881 | if ((sub = cupsdFindSubscription(sub_id)) == NULL) | |
8882 | { | |
8883 | /* | |
8884 | * Bad subscription ID... | |
8885 | */ | |
8886 | ||
8887 | send_ipp_status(con, IPP_NOT_FOUND, | |
8888 | _("notify-subscription-id %d no good!"), sub_id); | |
8889 | return; | |
8890 | } | |
8891 | ||
8892 | if (sub->job) | |
8893 | { | |
8894 | /* | |
8895 | * Job subscriptions cannot be renewed... | |
8896 | */ | |
8897 | ||
8898 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
8899 | _("Job subscriptions cannot be renewed!")); | |
8900 | return; | |
8901 | } | |
8902 | ||
8903 | /* | |
8904 | * Check policy... | |
8905 | */ | |
8906 | ||
8907 | if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr : | |
8908 | DefaultPolicyPtr, | |
8909 | con, sub->owner)) != HTTP_OK) | |
8910 | { | |
f899b121 | 8911 | send_http_error(con, status, sub->dest); |
bd7854cb | 8912 | return; |
8913 | } | |
8914 | ||
8915 | /* | |
8916 | * Renew the subscription... | |
8917 | */ | |
8918 | ||
8919 | lease = ippFindAttribute(con->request, "notify-lease-duration", | |
8920 | IPP_TAG_INTEGER); | |
8921 | ||
8922 | sub->lease = lease ? lease->values[0].integer : DefaultLeaseDuration; | |
8923 | ||
8924 | if (MaxLeaseDuration && (sub->lease == 0 || sub->lease > MaxLeaseDuration)) | |
8925 | { | |
8926 | cupsdLogMessage(CUPSD_LOG_INFO, | |
8927 | "renew_subscription: Limiting notify-lease-duration to " | |
8928 | "%d seconds.", | |
8929 | MaxLeaseDuration); | |
8930 | sub->lease = MaxLeaseDuration; | |
8931 | } | |
8932 | ||
8933 | sub->expire = sub->lease ? time(NULL) + sub->lease : 0; | |
8934 | ||
3dfe78b3 | 8935 | cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS); |
bd7854cb | 8936 | |
8937 | con->response->request.status.status_code = IPP_OK; | |
b94498cf | 8938 | |
8939 | ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | |
8940 | "notify-lease-duration", sub->lease); | |
ef416fc2 | 8941 | } |
8942 | ||
8943 | ||
8944 | /* | |
8945 | * 'restart_job()' - Restart an old print job. | |
8946 | */ | |
8947 | ||
8948 | static void | |
8949 | restart_job(cupsd_client_t *con, /* I - Client connection */ | |
8950 | ipp_attribute_t *uri) /* I - Job or Printer URI */ | |
8951 | { | |
8952 | ipp_attribute_t *attr; /* Current attribute */ | |
8953 | int jobid; /* Job ID */ | |
8954 | char method[HTTP_MAX_URI], /* Method portion of URI */ | |
8955 | username[HTTP_MAX_URI], /* Username portion of URI */ | |
8956 | host[HTTP_MAX_URI], /* Host portion of URI */ | |
8957 | resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
8958 | int port; /* Port portion of URI */ | |
8959 | cupsd_job_t *job; /* Job information */ | |
8960 | ||
8961 | ||
8962 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "restart_job(%p[%d], %s)", con, | |
8963 | con->http.fd, uri->values[0].string.text); | |
8964 | ||
8965 | /* | |
8966 | * See if we have a job URI or a printer URI... | |
8967 | */ | |
8968 | ||
8969 | if (!strcmp(uri->name, "printer-uri")) | |
8970 | { | |
8971 | /* | |
8972 | * Got a printer URI; see if we also have a job-id attribute... | |
8973 | */ | |
8974 | ||
fa73b229 | 8975 | if ((attr = ippFindAttribute(con->request, "job-id", |
8976 | IPP_TAG_INTEGER)) == NULL) | |
ef416fc2 | 8977 | { |
8978 | send_ipp_status(con, IPP_BAD_REQUEST, | |
8979 | _("Got a printer-uri attribute but no job-id!")); | |
8980 | return; | |
8981 | } | |
8982 | ||
8983 | jobid = attr->values[0].integer; | |
8984 | } | |
8985 | else | |
8986 | { | |
8987 | /* | |
8988 | * Got a job URI; parse it to get the job ID... | |
8989 | */ | |
8990 | ||
a4d04587 | 8991 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
8992 | sizeof(method), username, sizeof(username), host, | |
8993 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 8994 | |
fa73b229 | 8995 | if (strncmp(resource, "/jobs/", 6)) |
ef416fc2 | 8996 | { |
8997 | /* | |
8998 | * Not a valid URI! | |
8999 | */ | |
9000 | ||
9001 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9002 | _("Bad job-uri attribute \"%s\"!"), | |
9003 | uri->values[0].string.text); | |
9004 | return; | |
9005 | } | |
9006 | ||
9007 | jobid = atoi(resource + 6); | |
9008 | } | |
9009 | ||
9010 | /* | |
9011 | * See if the job exists... | |
9012 | */ | |
9013 | ||
9014 | if ((job = cupsdFindJob(jobid)) == NULL) | |
9015 | { | |
9016 | /* | |
9017 | * Nope - return a "not found" error... | |
9018 | */ | |
9019 | ||
9020 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
9021 | return; | |
9022 | } | |
9023 | ||
9024 | /* | |
9025 | * See if job is in any of the "completed" states... | |
9026 | */ | |
9027 | ||
bd7854cb | 9028 | if (job->state_value <= IPP_JOB_PROCESSING) |
ef416fc2 | 9029 | { |
9030 | /* | |
9031 | * Nope - return a "not possible" error... | |
9032 | */ | |
9033 | ||
9034 | send_ipp_status(con, IPP_NOT_POSSIBLE, _("Job #%d is not complete!"), | |
9035 | jobid); | |
9036 | return; | |
9037 | } | |
9038 | ||
9039 | /* | |
9040 | * See if we have retained the job files... | |
9041 | */ | |
9042 | ||
bd7854cb | 9043 | cupsdLoadJob(job); |
9044 | ||
07725fee | 9045 | if (!job->attrs || job->num_files == 0) |
ef416fc2 | 9046 | { |
9047 | /* | |
9048 | * Nope - return a "not possible" error... | |
9049 | */ | |
9050 | ||
9051 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
9052 | _("Job #%d cannot be restarted - no files!"), jobid); | |
9053 | return; | |
9054 | } | |
9055 | ||
9056 | /* | |
9057 | * See if the job is owned by the requesting user... | |
9058 | */ | |
9059 | ||
9060 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
9061 | { | |
2fb76298 | 9062 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
ef416fc2 | 9063 | return; |
9064 | } | |
9065 | ||
9066 | /* | |
9067 | * Restart the job and return... | |
9068 | */ | |
9069 | ||
9070 | cupsdRestartJob(job); | |
9071 | ||
09a101d6 | 9072 | cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Restarted by \"%s\".", jobid, |
ef416fc2 | 9073 | username); |
9074 | ||
9075 | con->response->request.status.status_code = IPP_OK; | |
9076 | } | |
9077 | ||
9078 | ||
9079 | /* | |
9080 | * 'save_auth_info()' - Save authentication information for a job. | |
9081 | */ | |
9082 | ||
9083 | static void | |
f7deaa1a | 9084 | save_auth_info( |
9085 | cupsd_client_t *con, /* I - Client connection */ | |
9086 | cupsd_job_t *job, /* I - Job */ | |
9087 | ipp_attribute_t *auth_info) /* I - auth-info attribute, if any */ | |
ef416fc2 | 9088 | { |
09a101d6 | 9089 | int i; /* Looping var */ |
9090 | char filename[1024]; /* Job authentication filename */ | |
9091 | cups_file_t *fp; /* Job authentication file */ | |
9092 | char line[2048]; /* Line for file */ | |
9093 | cupsd_printer_t *dest; /* Destination printer/class */ | |
ef416fc2 | 9094 | |
9095 | ||
9096 | /* | |
9097 | * This function saves the in-memory authentication information for | |
9098 | * a job so that it can be used to authenticate with a remote host. | |
9099 | * The information is stored in a file that is readable only by the | |
f7deaa1a | 9100 | * root user. The fields are Base-64 encoded, each on a separate line, |
9101 | * followed by random number (up to 1024) of newlines to limit the | |
9102 | * amount of information that is exposed. | |
ef416fc2 | 9103 | * |
9104 | * Because of the potential for exposing of authentication information, | |
9105 | * this functionality is only enabled when running cupsd as root. | |
9106 | * | |
9107 | * This caching only works for the Basic and BasicDigest authentication | |
9108 | * types. Digest authentication cannot be cached this way, and in | |
9109 | * the future Kerberos authentication may make all of this obsolete. | |
9110 | * | |
9111 | * Authentication information is saved whenever an authenticated | |
9112 | * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is | |
9113 | * performed. | |
9114 | * | |
9115 | * This information is deleted after a job is completed or canceled, | |
9116 | * so reprints may require subsequent re-authentication. | |
9117 | */ | |
9118 | ||
9119 | if (RunUser) | |
9120 | return; | |
9121 | ||
09a101d6 | 9122 | if ((dest = cupsdFindDest(job->dest)) == NULL) |
9123 | return; | |
9124 | ||
ef416fc2 | 9125 | /* |
9126 | * Create the authentication file and change permissions... | |
9127 | */ | |
9128 | ||
9129 | snprintf(filename, sizeof(filename), "%s/a%05d", RequestRoot, job->id); | |
9130 | if ((fp = cupsFileOpen(filename, "w")) == NULL) | |
9131 | { | |
9132 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
9133 | "Unable to save authentication info to \"%s\" - %s", | |
9134 | filename, strerror(errno)); | |
9135 | return; | |
9136 | } | |
9137 | ||
9138 | fchown(cupsFileNumber(fp), 0, 0); | |
9139 | fchmod(cupsFileNumber(fp), 0400); | |
9140 | ||
09a101d6 | 9141 | if (auth_info && auth_info->num_values == dest->num_auth_info_required) |
f7deaa1a | 9142 | { |
9143 | /* | |
09a101d6 | 9144 | * Write 1 to 3 auth values... |
f7deaa1a | 9145 | */ |
ef416fc2 | 9146 | |
09a101d6 | 9147 | cupsdClearString(&job->auth_username); |
9148 | cupsdClearString(&job->auth_domain); | |
9149 | cupsdClearString(&job->auth_password); | |
9150 | ||
f7deaa1a | 9151 | for (i = 0; i < auth_info->num_values; i ++) |
9152 | { | |
9153 | httpEncode64_2(line, sizeof(line), auth_info->values[i].string.text, | |
9154 | strlen(auth_info->values[i].string.text)); | |
9155 | cupsFilePrintf(fp, "%s\n", line); | |
09a101d6 | 9156 | |
9157 | if (!strcmp(dest->auth_info_required[i], "username")) | |
839a51c8 | 9158 | cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s", |
09a101d6 | 9159 | auth_info->values[i].string.text); |
9160 | else if (!strcmp(dest->auth_info_required[i], "domain")) | |
839a51c8 | 9161 | cupsdSetStringf(&job->auth_domain, "AUTH_DOMAIN=%s", |
09a101d6 | 9162 | auth_info->values[i].string.text); |
9163 | else if (!strcmp(dest->auth_info_required[i], "password")) | |
839a51c8 | 9164 | cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s", |
09a101d6 | 9165 | auth_info->values[i].string.text); |
f7deaa1a | 9166 | } |
9167 | } | |
09a101d6 | 9168 | else if (con->username[0]) |
f7deaa1a | 9169 | { |
9170 | /* | |
9171 | * Write the authenticated username... | |
9172 | */ | |
ef416fc2 | 9173 | |
f7deaa1a | 9174 | httpEncode64_2(line, sizeof(line), con->username, strlen(con->username)); |
9175 | cupsFilePrintf(fp, "%s\n", line); | |
ef416fc2 | 9176 | |
839a51c8 | 9177 | cupsdSetStringf(&job->auth_username, "AUTH_USERNAME=%s", con->username); |
09a101d6 | 9178 | cupsdClearString(&job->auth_domain); |
9179 | ||
f7deaa1a | 9180 | /* |
9181 | * Write the authenticated password... | |
9182 | */ | |
9183 | ||
9184 | httpEncode64_2(line, sizeof(line), con->password, strlen(con->password)); | |
9185 | cupsFilePrintf(fp, "%s\n", line); | |
09a101d6 | 9186 | |
839a51c8 | 9187 | cupsdSetStringf(&job->auth_password, "AUTH_PASSWORD=%s", con->password); |
f7deaa1a | 9188 | } |
ef416fc2 | 9189 | |
9190 | /* | |
9191 | * Write a random number of newlines to the end of the file... | |
9192 | */ | |
9193 | ||
9194 | for (i = (rand() % 1024); i >= 0; i --) | |
9195 | cupsFilePutChar(fp, '\n'); | |
9196 | ||
9197 | /* | |
9198 | * Close the file and return... | |
9199 | */ | |
9200 | ||
9201 | cupsFileClose(fp); | |
f7deaa1a | 9202 | |
9203 | #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H) | |
09a101d6 | 9204 | if (con->gss_have_creds) |
9205 | save_krb5_creds(con, job); | |
9206 | else if (job->ccname) | |
9207 | cupsdClearString(&(job->ccname)); | |
f7deaa1a | 9208 | #endif /* HAVE_GSSAPI && HAVE_KRB5_H */ |
9209 | } | |
9210 | ||
9211 | ||
9212 | #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H) | |
9213 | /* | |
9214 | * 'save_krb5_creds()' - Save Kerberos credentials for the job. | |
9215 | */ | |
9216 | ||
9217 | static void | |
9218 | save_krb5_creds(cupsd_client_t *con, /* I - Client connection */ | |
9219 | cupsd_job_t *job) /* I - Job */ | |
9220 | { | |
7ff4fea9 MS |
9221 | # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL) |
9222 | cupsdLogMessage(CUPSD_LOG_INFO, | |
9223 | "Sorry, your version of Kerberos does not support delegated " | |
9224 | "credentials!"); | |
9225 | return; | |
9226 | ||
9227 | # else | |
db1f069b MS |
9228 | krb5_error_code error; /* Kerberos error code */ |
9229 | OM_uint32 major_status, /* Major status code */ | |
9230 | minor_status; /* Minor status code */ | |
db1f069b | 9231 | krb5_principal principal; /* Kerberos principal */ |
f7deaa1a | 9232 | |
9233 | ||
7ff4fea9 | 9234 | # ifdef __APPLE__ |
f7deaa1a | 9235 | /* |
c24d2134 MS |
9236 | * If the weak-linked GSSAPI/Kerberos library is not present, don't try |
9237 | * to use it... | |
f7deaa1a | 9238 | */ |
9239 | ||
c24d2134 | 9240 | if (krb5_init_context == NULL) |
f7deaa1a | 9241 | return; |
7ff4fea9 | 9242 | # endif /* __APPLE__ */ |
f7deaa1a | 9243 | |
cc0d019f MS |
9244 | /* |
9245 | * We MUST create a file-based cache because memory-based caches are | |
9246 | * only valid for the current process/address space. | |
7ff4fea9 MS |
9247 | * |
9248 | * Due to various bugs/features in different versions of Kerberos, we | |
9249 | * need either the krb5_cc_new_unique() function or Heimdal's version | |
9250 | * of krb5_cc_gen_new() to create a new FILE: credential cache that | |
9251 | * can be passed to the backend. These functions create a temporary | |
9252 | * file (typically in /tmp) containing the cached credentials, which | |
9253 | * are removed when we have successfully printed a job. | |
9254 | */ | |
9255 | ||
9256 | # ifdef HAVE_KRB5_CC_NEW_UNIQUE | |
9257 | if ((error = krb5_cc_new_unique(KerberosContext, "FILE", NULL, | |
9258 | &(job->ccache))) != 0) | |
9259 | # else /* HAVE_HEIMDAL */ | |
0a682745 | 9260 | if ((error = krb5_cc_gen_new(KerberosContext, &krb5_fcc_ops, |
7ff4fea9 MS |
9261 | &(job->ccache))) != 0) |
9262 | # endif /* HAVE_KRB5_CC_NEW_UNIQUE */ | |
9263 | { | |
db1f069b MS |
9264 | cupsdLogMessage(CUPSD_LOG_ERROR, |
9265 | "Unable to create new credentials cache (%d/%s)", | |
7ff4fea9 | 9266 | error, strerror(errno)); |
76cd9e37 | 9267 | job->ccache = NULL; |
f7deaa1a | 9268 | return; |
9269 | } | |
9270 | ||
db1f069b MS |
9271 | if ((error = krb5_parse_name(KerberosContext, con->username, &principal)) != 0) |
9272 | { | |
9273 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to parse kerberos username (%d/%s)", | |
9274 | error, strerror(errno)); | |
9275 | krb5_cc_destroy(KerberosContext, job->ccache); | |
9276 | job->ccache = NULL; | |
9277 | return; | |
9278 | } | |
9279 | ||
9280 | if ((error = krb5_cc_initialize(KerberosContext, job->ccache, principal))) | |
9281 | { | |
9282 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
9283 | "Unable to initialize credentials cache (%d/%s)", error, | |
9284 | strerror(errno)); | |
9285 | krb5_cc_destroy(KerberosContext, job->ccache); | |
9286 | krb5_free_principal(KerberosContext, principal); | |
9287 | job->ccache = NULL; | |
9288 | return; | |
9289 | } | |
9290 | ||
9291 | krb5_free_principal(KerberosContext, principal); | |
9292 | ||
7ff4fea9 MS |
9293 | /* |
9294 | * Copy the user's credentials to the new cache file... | |
9295 | */ | |
9296 | ||
f7deaa1a | 9297 | major_status = gss_krb5_copy_ccache(&minor_status, con->gss_delegated_cred, |
c24d2134 | 9298 | job->ccache); |
f7deaa1a | 9299 | |
9300 | if (GSS_ERROR(major_status)) | |
9301 | { | |
9302 | cupsdLogGSSMessage(CUPSD_LOG_ERROR, major_status, minor_status, | |
9303 | "Unable to import client credentials cache"); | |
c24d2134 | 9304 | krb5_cc_destroy(KerberosContext, job->ccache); |
76cd9e37 | 9305 | job->ccache = NULL; |
f7deaa1a | 9306 | return; |
9307 | } | |
9308 | ||
7ff4fea9 MS |
9309 | /* |
9310 | * Add the KRB5CCNAME environment variable to the job so that the | |
9311 | * backend can use the credentials when printing. | |
9312 | */ | |
9313 | ||
9314 | cupsdSetStringf(&(job->ccname), "KRB5CCNAME=FILE:%s", | |
c24d2134 | 9315 | krb5_cc_get_name(KerberosContext, job->ccache)); |
cc0d019f MS |
9316 | |
9317 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "[Job %d] save_krb5_creds: %s", job->id, | |
9318 | job->ccname); | |
7ff4fea9 | 9319 | # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */ |
ef416fc2 | 9320 | } |
f7deaa1a | 9321 | #endif /* HAVE_GSSAPI && HAVE_KRB5_H */ |
ef416fc2 | 9322 | |
9323 | ||
9324 | /* | |
9325 | * 'send_document()' - Send a file to a printer or class. | |
9326 | */ | |
9327 | ||
9328 | static void | |
9329 | send_document(cupsd_client_t *con, /* I - Client connection */ | |
9330 | ipp_attribute_t *uri) /* I - Printer URI */ | |
9331 | { | |
9332 | ipp_attribute_t *attr; /* Current attribute */ | |
a0f6818e MS |
9333 | ipp_attribute_t *format; /* Request's document-format attribute */ |
9334 | ipp_attribute_t *jformat; /* Job's document-format attribute */ | |
f7deaa1a | 9335 | const char *default_format;/* document-format-default value */ |
ef416fc2 | 9336 | int jobid; /* Job ID number */ |
9337 | cupsd_job_t *job; /* Current job */ | |
9338 | char job_uri[HTTP_MAX_URI], | |
9339 | /* Job URI */ | |
9340 | method[HTTP_MAX_URI], | |
9341 | /* Method portion of URI */ | |
9342 | username[HTTP_MAX_URI], | |
9343 | /* Username portion of URI */ | |
9344 | host[HTTP_MAX_URI], | |
9345 | /* Host portion of URI */ | |
9346 | resource[HTTP_MAX_URI]; | |
9347 | /* Resource portion of URI */ | |
9348 | int port; /* Port portion of URI */ | |
9349 | mime_type_t *filetype; /* Type of file */ | |
9350 | char super[MIME_MAX_SUPER], | |
9351 | /* Supertype of file */ | |
9352 | type[MIME_MAX_TYPE], | |
9353 | /* Subtype of file */ | |
9354 | mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; | |
9355 | /* Textual name of mime type */ | |
9356 | char filename[1024]; /* Job filename */ | |
9357 | cupsd_printer_t *printer; /* Current printer */ | |
9358 | struct stat fileinfo; /* File information */ | |
9359 | int kbytes; /* Size of file */ | |
9360 | int compression; /* Type of compression */ | |
9361 | ||
9362 | ||
9363 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_document(%p[%d], %s)", con, | |
9364 | con->http.fd, uri->values[0].string.text); | |
9365 | ||
9366 | /* | |
9367 | * See if we have a job URI or a printer URI... | |
9368 | */ | |
9369 | ||
9370 | if (!strcmp(uri->name, "printer-uri")) | |
9371 | { | |
9372 | /* | |
9373 | * Got a printer URI; see if we also have a job-id attribute... | |
9374 | */ | |
9375 | ||
fa73b229 | 9376 | if ((attr = ippFindAttribute(con->request, "job-id", |
9377 | IPP_TAG_INTEGER)) == NULL) | |
ef416fc2 | 9378 | { |
9379 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9380 | _("Got a printer-uri attribute but no job-id!")); | |
9381 | return; | |
9382 | } | |
9383 | ||
9384 | jobid = attr->values[0].integer; | |
9385 | } | |
9386 | else | |
9387 | { | |
9388 | /* | |
9389 | * Got a job URI; parse it to get the job ID... | |
9390 | */ | |
9391 | ||
a4d04587 | 9392 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
9393 | sizeof(method), username, sizeof(username), host, | |
9394 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 9395 | |
9396 | if (strncmp(resource, "/jobs/", 6)) | |
9397 | { | |
9398 | /* | |
9399 | * Not a valid URI! | |
9400 | */ | |
9401 | ||
9402 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9403 | _("Bad job-uri attribute \"%s\"!"), | |
9404 | uri->values[0].string.text); | |
9405 | return; | |
9406 | } | |
9407 | ||
9408 | jobid = atoi(resource + 6); | |
9409 | } | |
9410 | ||
9411 | /* | |
9412 | * See if the job exists... | |
9413 | */ | |
9414 | ||
9415 | if ((job = cupsdFindJob(jobid)) == NULL) | |
9416 | { | |
9417 | /* | |
9418 | * Nope - return a "not found" error... | |
9419 | */ | |
9420 | ||
9421 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
9422 | return; | |
9423 | } | |
9424 | ||
f301802f | 9425 | printer = cupsdFindDest(job->dest); |
9426 | ||
ef416fc2 | 9427 | /* |
9428 | * See if the job is owned by the requesting user... | |
9429 | */ | |
9430 | ||
9431 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
9432 | { | |
2fb76298 | 9433 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
ef416fc2 | 9434 | return; |
9435 | } | |
9436 | ||
9437 | /* | |
9438 | * OK, see if the client is sending the document compressed - CUPS | |
9439 | * only supports "none" and "gzip". | |
9440 | */ | |
9441 | ||
9442 | compression = CUPS_FILE_NONE; | |
9443 | ||
fa73b229 | 9444 | if ((attr = ippFindAttribute(con->request, "compression", |
9445 | IPP_TAG_KEYWORD)) != NULL) | |
ef416fc2 | 9446 | { |
9447 | if (strcmp(attr->values[0].string.text, "none") | |
9448 | #ifdef HAVE_LIBZ | |
9449 | && strcmp(attr->values[0].string.text, "gzip") | |
9450 | #endif /* HAVE_LIBZ */ | |
9451 | ) | |
9452 | { | |
9453 | send_ipp_status(con, IPP_ATTRIBUTES, _("Unsupported compression \"%s\"!"), | |
9454 | attr->values[0].string.text); | |
9455 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD, | |
9456 | "compression", NULL, attr->values[0].string.text); | |
9457 | return; | |
9458 | } | |
9459 | ||
9460 | #ifdef HAVE_LIBZ | |
9461 | if (!strcmp(attr->values[0].string.text, "gzip")) | |
9462 | compression = CUPS_FILE_GZIP; | |
9463 | #endif /* HAVE_LIBZ */ | |
9464 | } | |
9465 | ||
9466 | /* | |
9467 | * Do we have a file to print? | |
9468 | */ | |
9469 | ||
9470 | if (!con->filename) | |
9471 | { | |
9472 | send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!")); | |
9473 | return; | |
9474 | } | |
9475 | ||
9476 | /* | |
9477 | * Is it a format we support? | |
9478 | */ | |
9479 | ||
9480 | if ((format = ippFindAttribute(con->request, "document-format", | |
9481 | IPP_TAG_MIMETYPE)) != NULL) | |
9482 | { | |
9483 | /* | |
9484 | * Grab format from client... | |
9485 | */ | |
9486 | ||
bc44d920 | 9487 | if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", |
9488 | super, type) != 2) | |
ef416fc2 | 9489 | { |
9490 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"), | |
9491 | format->values[0].string.text); | |
9492 | return; | |
9493 | } | |
9494 | } | |
f7deaa1a | 9495 | else if ((default_format = cupsGetOption("document-format", |
9496 | printer->num_options, | |
9497 | printer->options)) != NULL) | |
9498 | { | |
9499 | /* | |
9500 | * Use default document format... | |
9501 | */ | |
9502 | ||
9503 | if (sscanf(default_format, "%15[^/]/%31[^;]", super, type) != 2) | |
9504 | { | |
9505 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9506 | _("Could not scan type \"%s\"!"), | |
9507 | default_format); | |
9508 | return; | |
9509 | } | |
9510 | } | |
ef416fc2 | 9511 | else |
9512 | { | |
9513 | /* | |
9514 | * No document format attribute? Auto-type it! | |
9515 | */ | |
9516 | ||
9517 | strcpy(super, "application"); | |
9518 | strcpy(type, "octet-stream"); | |
9519 | } | |
9520 | ||
fa73b229 | 9521 | if (!strcmp(super, "application") && !strcmp(type, "octet-stream")) |
ef416fc2 | 9522 | { |
9523 | /* | |
9524 | * Auto-type the file... | |
9525 | */ | |
9526 | ||
bd7854cb | 9527 | ipp_attribute_t *doc_name; /* document-name attribute */ |
9528 | ||
9529 | ||
a0f6818e | 9530 | cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] Auto-typing file...", job->id); |
ef416fc2 | 9531 | |
bd7854cb | 9532 | doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME); |
9533 | filetype = mimeFileType(MimeDatabase, con->filename, | |
9534 | doc_name ? doc_name->values[0].string.text : NULL, | |
9535 | &compression); | |
ef416fc2 | 9536 | |
f7deaa1a | 9537 | if (!filetype) |
f7faf1f5 | 9538 | filetype = mimeType(MimeDatabase, super, type); |
a0f6818e MS |
9539 | |
9540 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
9541 | "[Job %d] Request file type is %s/%s.", job->id, | |
9542 | filetype->super, filetype->type); | |
ed486911 | 9543 | } |
f7faf1f5 | 9544 | else |
9545 | filetype = mimeType(MimeDatabase, super, type); | |
9546 | ||
a0f6818e MS |
9547 | jformat = ippFindAttribute(job->attrs, "document-format", IPP_TAG_MIMETYPE); |
9548 | ||
f7deaa1a | 9549 | if (filetype && |
a0f6818e | 9550 | (!jformat || |
f7deaa1a | 9551 | (!strcmp(super, "application") && !strcmp(type, "octet-stream")))) |
9552 | { | |
9553 | /* | |
9554 | * Replace the document-format attribute value with the auto-typed or | |
9555 | * default one. | |
9556 | */ | |
9557 | ||
9558 | snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, | |
9559 | filetype->type); | |
9560 | ||
a0f6818e | 9561 | if (jformat) |
f7deaa1a | 9562 | { |
a0f6818e | 9563 | _cupsStrFree(jformat->values[0].string.text); |
f7deaa1a | 9564 | |
a0f6818e | 9565 | jformat->values[0].string.text = _cupsStrAlloc(mimetype); |
f7deaa1a | 9566 | } |
9567 | else | |
a0f6818e | 9568 | ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_MIMETYPE, |
f7deaa1a | 9569 | "document-format", NULL, mimetype); |
9570 | } | |
9571 | else if (!filetype) | |
ef416fc2 | 9572 | { |
9573 | send_ipp_status(con, IPP_DOCUMENT_FORMAT, | |
9574 | _("Unsupported format \'%s/%s\'!"), super, type); | |
9575 | cupsdLogMessage(CUPSD_LOG_INFO, | |
9576 | "Hint: Do you have the raw file printing rules enabled?"); | |
9577 | ||
9578 | if (format) | |
9579 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE, | |
9580 | "document-format", NULL, format->values[0].string.text); | |
9581 | ||
9582 | return; | |
9583 | } | |
9584 | ||
80ca4592 | 9585 | if (printer->filetypes && !cupsArrayFind(printer->filetypes, filetype)) |
9586 | { | |
9587 | snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, | |
9588 | filetype->type); | |
9589 | ||
9590 | send_ipp_status(con, IPP_DOCUMENT_FORMAT, | |
9591 | _("Unsupported format \'%s\'!"), mimetype); | |
9592 | ||
9593 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE, | |
9594 | "document-format", NULL, mimetype); | |
9595 | ||
9596 | return; | |
9597 | } | |
9598 | ||
ef416fc2 | 9599 | /* |
9600 | * Add the file to the job... | |
9601 | */ | |
9602 | ||
bd7854cb | 9603 | cupsdLoadJob(job); |
9604 | ||
ef416fc2 | 9605 | if (add_file(con, job, filetype, compression)) |
9606 | return; | |
9607 | ||
ef416fc2 | 9608 | if (stat(con->filename, &fileinfo)) |
9609 | kbytes = 0; | |
9610 | else | |
9611 | kbytes = (fileinfo.st_size + 1023) / 1024; | |
9612 | ||
9613 | cupsdUpdateQuota(printer, job->username, 0, kbytes); | |
9614 | ||
fa73b229 | 9615 | if ((attr = ippFindAttribute(job->attrs, "job-k-octets", |
9616 | IPP_TAG_INTEGER)) != NULL) | |
ef416fc2 | 9617 | attr->values[0].integer += kbytes; |
9618 | ||
9619 | snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id, | |
9620 | job->num_files); | |
9621 | rename(con->filename, filename); | |
9622 | ||
9623 | cupsdClearString(&con->filename); | |
9624 | ||
9625 | cupsdLogMessage(CUPSD_LOG_INFO, | |
a0f6818e MS |
9626 | "[Job %d] File of type %s/%s queued by \"%s\".", job->id, |
9627 | filetype->super, filetype->type, job->username); | |
ef416fc2 | 9628 | |
9629 | /* | |
9630 | * Start the job if this is the last document... | |
9631 | */ | |
9632 | ||
fa73b229 | 9633 | if ((attr = ippFindAttribute(con->request, "last-document", |
9634 | IPP_TAG_BOOLEAN)) != NULL && | |
ef416fc2 | 9635 | attr->values[0].boolean) |
9636 | { | |
9637 | /* | |
9638 | * See if we need to add the ending sheet... | |
9639 | */ | |
9640 | ||
91c84a35 MS |
9641 | if (cupsdTimeoutJob(job)) |
9642 | return; | |
ef416fc2 | 9643 | |
bd7854cb | 9644 | if (job->state_value == IPP_JOB_STOPPED) |
9645 | { | |
ef416fc2 | 9646 | job->state->values[0].integer = IPP_JOB_PENDING; |
bd7854cb | 9647 | job->state_value = IPP_JOB_PENDING; |
9648 | } | |
9649 | else if (job->state_value == IPP_JOB_HELD) | |
ef416fc2 | 9650 | { |
fa73b229 | 9651 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", |
9652 | IPP_TAG_KEYWORD)) == NULL) | |
ef416fc2 | 9653 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); |
9654 | ||
fa73b229 | 9655 | if (!attr || !strcmp(attr->values[0].string.text, "no-hold")) |
bd7854cb | 9656 | { |
ef416fc2 | 9657 | job->state->values[0].integer = IPP_JOB_PENDING; |
bd7854cb | 9658 | job->state_value = IPP_JOB_PENDING; |
9659 | } | |
ef416fc2 | 9660 | } |
9661 | ||
3dfe78b3 MS |
9662 | job->dirty = 1; |
9663 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); | |
ef416fc2 | 9664 | |
9665 | /* | |
9666 | * Start the job if possible... Since cupsdCheckJobs() can cancel a | |
9667 | * job if it doesn't print, we need to re-find the job afterwards... | |
9668 | */ | |
9669 | ||
9670 | jobid = job->id; | |
9671 | ||
9672 | cupsdCheckJobs(); | |
9673 | ||
9674 | job = cupsdFindJob(jobid); | |
9675 | } | |
9676 | else | |
9677 | { | |
fa73b229 | 9678 | if ((attr = ippFindAttribute(job->attrs, "job-hold-until", |
9679 | IPP_TAG_KEYWORD)) == NULL) | |
ef416fc2 | 9680 | attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME); |
9681 | ||
fa73b229 | 9682 | if (!attr || !strcmp(attr->values[0].string.text, "no-hold")) |
ef416fc2 | 9683 | { |
9684 | job->state->values[0].integer = IPP_JOB_HELD; | |
bd7854cb | 9685 | job->state_value = IPP_JOB_HELD; |
ef416fc2 | 9686 | job->hold_until = time(NULL) + 60; |
3dfe78b3 MS |
9687 | job->dirty = 1; |
9688 | ||
9689 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); | |
ef416fc2 | 9690 | } |
9691 | } | |
9692 | ||
9693 | /* | |
9694 | * Fill in the response info... | |
9695 | */ | |
9696 | ||
9697 | snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName, | |
9698 | LocalPort, jobid); | |
9699 | ||
9700 | ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, | |
9701 | job_uri); | |
9702 | ||
9703 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", jobid); | |
9704 | ||
9705 | ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", | |
d09495fa | 9706 | job ? job->state_value : IPP_JOB_CANCELED); |
ef416fc2 | 9707 | add_job_state_reasons(con, job); |
9708 | ||
9709 | con->response->request.status.status_code = IPP_OK; | |
9710 | } | |
9711 | ||
9712 | ||
9713 | /* | |
9714 | * 'send_http_error()' - Send a HTTP error back to the IPP client. | |
9715 | */ | |
9716 | ||
9717 | static void | |
f899b121 | 9718 | send_http_error( |
9719 | cupsd_client_t *con, /* I - Client connection */ | |
9720 | http_status_t status, /* I - HTTP status code */ | |
9721 | cupsd_printer_t *printer) /* I - Printer, if any */ | |
ef416fc2 | 9722 | { |
9723 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: %s", | |
9724 | ippOpString(con->request->request.op.operation_id), | |
9725 | httpStatus(status)); | |
9726 | ||
f899b121 | 9727 | if (status == HTTP_UNAUTHORIZED && |
9728 | printer && printer->num_auth_info_required > 0 && | |
9729 | !strcmp(printer->auth_info_required[0], "negotiate")) | |
5bd77a73 | 9730 | cupsdSendError(con, status, CUPSD_AUTH_NEGOTIATE); |
2fb76298 MS |
9731 | else if (printer) |
9732 | { | |
9733 | char resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
9734 | cupsd_location_t *auth; /* Pointer to authentication element */ | |
db0bd74a | 9735 | int auth_type; /* Type of authentication required */ |
2fb76298 MS |
9736 | |
9737 | ||
9738 | if (printer->type & CUPS_PRINTER_CLASS) | |
9739 | snprintf(resource, sizeof(resource), "/classes/%s", printer->name); | |
9740 | else | |
9741 | snprintf(resource, sizeof(resource), "/printers/%s", printer->name); | |
9742 | ||
9743 | if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL || | |
5bd77a73 | 9744 | auth->type == CUPSD_AUTH_NONE) |
db0bd74a MS |
9745 | auth = cupsdFindPolicyOp(printer->op_policy_ptr, |
9746 | con->request ? | |
9747 | con->request->request.op.operation_id : | |
9748 | IPP_PRINT_JOB); | |
9749 | ||
9750 | if (!auth) | |
9751 | auth_type = CUPSD_AUTH_NONE; | |
9752 | else if (auth->type == CUPSD_AUTH_DEFAULT) | |
9753 | auth_type = DefaultAuthType; | |
9754 | else | |
9755 | auth_type = auth->type; | |
2fb76298 | 9756 | |
db0bd74a | 9757 | cupsdSendError(con, status, auth_type); |
2fb76298 | 9758 | } |
f899b121 | 9759 | else |
5bd77a73 | 9760 | cupsdSendError(con, status, CUPSD_AUTH_NONE); |
ef416fc2 | 9761 | |
9762 | ippDelete(con->response); | |
9763 | con->response = NULL; | |
9764 | ||
9765 | return; | |
9766 | } | |
9767 | ||
9768 | ||
9769 | /* | |
9770 | * 'send_ipp_status()' - Send a status back to the IPP client. | |
9771 | */ | |
9772 | ||
9773 | static void | |
9774 | send_ipp_status(cupsd_client_t *con, /* I - Client connection */ | |
9775 | ipp_status_t status, /* I - IPP status code */ | |
9776 | const char *message, /* I - Status message */ | |
9777 | ...) /* I - Additional args as needed */ | |
9778 | { | |
9779 | va_list ap; /* Pointer to additional args */ | |
9780 | char formatted[1024]; /* Formatted errror message */ | |
9781 | ||
9782 | ||
3d8365b8 | 9783 | va_start(ap, message); |
9784 | vsnprintf(formatted, sizeof(formatted), | |
9785 | _cupsLangString(con->language, message), ap); | |
9786 | va_end(ap); | |
ef416fc2 | 9787 | |
3d8365b8 | 9788 | cupsdLogMessage(CUPSD_LOG_DEBUG, "%s %s: %s", |
9789 | ippOpString(con->request->request.op.operation_id), | |
9790 | ippErrorString(status), formatted); | |
ef416fc2 | 9791 | |
9792 | con->response->request.status.status_code = status; | |
9793 | ||
fa73b229 | 9794 | if (ippFindAttribute(con->response, "attributes-charset", |
9795 | IPP_TAG_ZERO) == NULL) | |
ef416fc2 | 9796 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
9797 | "attributes-charset", NULL, DefaultCharset); | |
9798 | ||
9799 | if (ippFindAttribute(con->response, "attributes-natural-language", | |
9800 | IPP_TAG_ZERO) == NULL) | |
9801 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, | |
9802 | "attributes-natural-language", NULL, DefaultLanguage); | |
9803 | ||
3d8365b8 | 9804 | ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_TEXT, |
9805 | "status-message", NULL, formatted); | |
ef416fc2 | 9806 | } |
9807 | ||
9808 | ||
9809 | /* | |
9810 | * 'set_default()' - Set the default destination... | |
9811 | */ | |
9812 | ||
9813 | static void | |
9814 | set_default(cupsd_client_t *con, /* I - Client connection */ | |
9815 | ipp_attribute_t *uri) /* I - Printer URI */ | |
9816 | { | |
9817 | http_status_t status; /* Policy status */ | |
bc44d920 | 9818 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 9819 | cupsd_printer_t *printer; /* Printer */ |
9820 | ||
9821 | ||
9822 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_default(%p[%d], %s)", con, | |
9823 | con->http.fd, uri->values[0].string.text); | |
9824 | ||
9825 | /* | |
9826 | * Is the destination valid? | |
9827 | */ | |
9828 | ||
f7deaa1a | 9829 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 9830 | { |
9831 | /* | |
9832 | * Bad URI... | |
9833 | */ | |
9834 | ||
9835 | send_ipp_status(con, IPP_NOT_FOUND, | |
9836 | _("The printer or class was not found.")); | |
9837 | return; | |
9838 | } | |
9839 | ||
9840 | /* | |
9841 | * Check policy... | |
9842 | */ | |
9843 | ||
9844 | if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK) | |
9845 | { | |
f899b121 | 9846 | send_http_error(con, status, NULL); |
ef416fc2 | 9847 | return; |
9848 | } | |
9849 | ||
9850 | /* | |
9851 | * Set it as the default... | |
9852 | */ | |
9853 | ||
9854 | DefaultPrinter = printer; | |
9855 | ||
3dfe78b3 MS |
9856 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS | CUPSD_DIRTY_CLASSES | |
9857 | CUPSD_DIRTY_REMOTE | CUPSD_DIRTY_PRINTCAP); | |
ef416fc2 | 9858 | |
9859 | cupsdLogMessage(CUPSD_LOG_INFO, | |
f7deaa1a | 9860 | "Default destination set to \"%s\" by \"%s\".", |
9861 | printer->name, get_username(con)); | |
ef416fc2 | 9862 | |
9863 | /* | |
9864 | * Everything was ok, so return OK status... | |
9865 | */ | |
9866 | ||
9867 | con->response->request.status.status_code = IPP_OK; | |
9868 | } | |
9869 | ||
9870 | ||
9871 | /* | |
9872 | * 'set_job_attrs()' - Set job attributes. | |
9873 | */ | |
9874 | ||
9875 | static void | |
9876 | set_job_attrs(cupsd_client_t *con, /* I - Client connection */ | |
9877 | ipp_attribute_t *uri) /* I - Job URI */ | |
9878 | { | |
9879 | ipp_attribute_t *attr, /* Current attribute */ | |
9880 | *attr2; /* Job attribute */ | |
9881 | int jobid; /* Job ID */ | |
9882 | cupsd_job_t *job; /* Current job */ | |
9883 | char method[HTTP_MAX_URI], | |
9884 | /* Method portion of URI */ | |
9885 | username[HTTP_MAX_URI], | |
9886 | /* Username portion of URI */ | |
9887 | host[HTTP_MAX_URI], | |
9888 | /* Host portion of URI */ | |
9889 | resource[HTTP_MAX_URI]; | |
9890 | /* Resource portion of URI */ | |
9891 | int port; /* Port portion of URI */ | |
d09495fa | 9892 | int event; /* Events? */ |
ef416fc2 | 9893 | |
9894 | ||
9895 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_job_attrs(%p[%d], %s)", con, | |
9896 | con->http.fd, uri->values[0].string.text); | |
9897 | ||
9898 | /* | |
9899 | * Start with "everything is OK" status... | |
9900 | */ | |
9901 | ||
9902 | con->response->request.status.status_code = IPP_OK; | |
9903 | ||
9904 | /* | |
9905 | * See if we have a job URI or a printer URI... | |
9906 | */ | |
9907 | ||
fa73b229 | 9908 | if (!strcmp(uri->name, "printer-uri")) |
ef416fc2 | 9909 | { |
9910 | /* | |
9911 | * Got a printer URI; see if we also have a job-id attribute... | |
9912 | */ | |
9913 | ||
fa73b229 | 9914 | if ((attr = ippFindAttribute(con->request, "job-id", |
9915 | IPP_TAG_INTEGER)) == NULL) | |
ef416fc2 | 9916 | { |
9917 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9918 | _("Got a printer-uri attribute but no job-id!")); | |
9919 | return; | |
9920 | } | |
9921 | ||
9922 | jobid = attr->values[0].integer; | |
9923 | } | |
9924 | else | |
9925 | { | |
9926 | /* | |
9927 | * Got a job URI; parse it to get the job ID... | |
9928 | */ | |
9929 | ||
a4d04587 | 9930 | httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method, |
9931 | sizeof(method), username, sizeof(username), host, | |
9932 | sizeof(host), &port, resource, sizeof(resource)); | |
ef416fc2 | 9933 | |
fa73b229 | 9934 | if (strncmp(resource, "/jobs/", 6)) |
ef416fc2 | 9935 | { |
9936 | /* | |
9937 | * Not a valid URI! | |
9938 | */ | |
9939 | ||
9940 | send_ipp_status(con, IPP_BAD_REQUEST, | |
9941 | _("Bad job-uri attribute \"%s\"!"), | |
9942 | uri->values[0].string.text); | |
9943 | return; | |
9944 | } | |
9945 | ||
9946 | jobid = atoi(resource + 6); | |
9947 | } | |
9948 | ||
9949 | /* | |
9950 | * See if the job exists... | |
9951 | */ | |
9952 | ||
9953 | if ((job = cupsdFindJob(jobid)) == NULL) | |
9954 | { | |
9955 | /* | |
9956 | * Nope - return a "not found" error... | |
9957 | */ | |
9958 | ||
9959 | send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid); | |
9960 | return; | |
9961 | } | |
9962 | ||
9963 | /* | |
9964 | * See if the job has been completed... | |
9965 | */ | |
9966 | ||
bd7854cb | 9967 | if (job->state_value > IPP_JOB_STOPPED) |
ef416fc2 | 9968 | { |
9969 | /* | |
9970 | * Return a "not-possible" error... | |
9971 | */ | |
9972 | ||
9973 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
9974 | _("Job #%d is finished and cannot be altered!"), jobid); | |
9975 | return; | |
9976 | } | |
9977 | ||
9978 | /* | |
9979 | * See if the job is owned by the requesting user... | |
9980 | */ | |
9981 | ||
9982 | if (!validate_user(job, con, job->username, username, sizeof(username))) | |
9983 | { | |
2fb76298 | 9984 | send_http_error(con, HTTP_UNAUTHORIZED, cupsdFindDest(job->dest)); |
ef416fc2 | 9985 | return; |
9986 | } | |
9987 | ||
9988 | /* | |
9989 | * See what the user wants to change. | |
9990 | */ | |
9991 | ||
bd7854cb | 9992 | cupsdLoadJob(job); |
9993 | ||
d09495fa | 9994 | event = 0; |
9995 | ||
fa73b229 | 9996 | for (attr = con->request->attrs; attr; attr = attr->next) |
ef416fc2 | 9997 | { |
9998 | if (attr->group_tag != IPP_TAG_JOB || !attr->name) | |
9999 | continue; | |
10000 | ||
10001 | if (!strcmp(attr->name, "attributes-charset") || | |
10002 | !strcmp(attr->name, "attributes-natural-language") || | |
10003 | !strcmp(attr->name, "document-compression") || | |
10004 | !strcmp(attr->name, "document-format") || | |
10005 | !strcmp(attr->name, "job-detailed-status-messages") || | |
10006 | !strcmp(attr->name, "job-document-access-errors") || | |
10007 | !strcmp(attr->name, "job-id") || | |
10008 | !strcmp(attr->name, "job-k-octets") || | |
10009 | !strcmp(attr->name, "job-originating-host-name") || | |
10010 | !strcmp(attr->name, "job-originating-user-name") || | |
10011 | !strcmp(attr->name, "job-printer-up-time") || | |
10012 | !strcmp(attr->name, "job-printer-uri") || | |
10013 | !strcmp(attr->name, "job-sheets") || | |
10014 | !strcmp(attr->name, "job-state-message") || | |
10015 | !strcmp(attr->name, "job-state-reasons") || | |
10016 | !strcmp(attr->name, "job-uri") || | |
10017 | !strcmp(attr->name, "number-of-documents") || | |
10018 | !strcmp(attr->name, "number-of-intervening-jobs") || | |
10019 | !strcmp(attr->name, "output-device-assigned") || | |
10020 | !strncmp(attr->name, "date-time-at-", 13) || | |
10021 | !strncmp(attr->name, "job-impressions", 15) || | |
10022 | !strncmp(attr->name, "job-k-octets", 12) || | |
10023 | !strncmp(attr->name, "job-media-sheets", 16) || | |
10024 | !strncmp(attr->name, "time-at-", 8)) | |
10025 | { | |
10026 | /* | |
10027 | * Read-only attrs! | |
10028 | */ | |
10029 | ||
10030 | send_ipp_status(con, IPP_ATTRIBUTES_NOT_SETTABLE, | |
10031 | _("%s cannot be changed."), attr->name); | |
10032 | ||
10033 | if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL) | |
10034 | attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP; | |
10035 | ||
10036 | continue; | |
10037 | } | |
10038 | ||
10039 | if (!strcmp(attr->name, "job-priority")) | |
10040 | { | |
10041 | /* | |
10042 | * Change the job priority... | |
10043 | */ | |
10044 | ||
10045 | if (attr->value_tag != IPP_TAG_INTEGER) | |
10046 | { | |
10047 | send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-priority value!")); | |
10048 | ||
10049 | if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL) | |
10050 | attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP; | |
10051 | } | |
bd7854cb | 10052 | else if (job->state_value >= IPP_JOB_PROCESSING) |
ef416fc2 | 10053 | { |
10054 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10055 | _("Job is completed and cannot be changed.")); | |
10056 | return; | |
10057 | } | |
10058 | else if (con->response->request.status.status_code == IPP_OK) | |
d09495fa | 10059 | { |
ef416fc2 | 10060 | cupsdSetJobPriority(job, attr->values[0].integer); |
d9bca400 MS |
10061 | event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | |
10062 | CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED; | |
d09495fa | 10063 | } |
ef416fc2 | 10064 | } |
10065 | else if (!strcmp(attr->name, "job-state")) | |
10066 | { | |
10067 | /* | |
10068 | * Change the job state... | |
10069 | */ | |
10070 | ||
10071 | if (attr->value_tag != IPP_TAG_ENUM) | |
10072 | { | |
10073 | send_ipp_status(con, IPP_REQUEST_VALUE, _("Bad job-state value!")); | |
10074 | ||
10075 | if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL) | |
10076 | attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP; | |
10077 | } | |
10078 | else | |
10079 | { | |
10080 | switch (attr->values[0].integer) | |
10081 | { | |
10082 | case IPP_JOB_PENDING : | |
10083 | case IPP_JOB_HELD : | |
bd7854cb | 10084 | if (job->state_value > IPP_JOB_HELD) |
ef416fc2 | 10085 | { |
10086 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10087 | _("Job state cannot be changed.")); | |
10088 | return; | |
10089 | } | |
10090 | else if (con->response->request.status.status_code == IPP_OK) | |
bd7854cb | 10091 | { |
ef416fc2 | 10092 | job->state->values[0].integer = attr->values[0].integer; |
bc44d920 | 10093 | job->state_value = (ipp_jstate_t)attr->values[0].integer; |
d09495fa | 10094 | |
10095 | event |= CUPSD_EVENT_JOB_STATE; | |
bd7854cb | 10096 | } |
ef416fc2 | 10097 | break; |
10098 | ||
10099 | case IPP_JOB_PROCESSING : | |
10100 | case IPP_JOB_STOPPED : | |
bd7854cb | 10101 | if (job->state_value != attr->values[0].integer) |
ef416fc2 | 10102 | { |
10103 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10104 | _("Job state cannot be changed.")); | |
10105 | return; | |
10106 | } | |
10107 | break; | |
10108 | ||
d09495fa | 10109 | case IPP_JOB_CANCELED : |
ef416fc2 | 10110 | case IPP_JOB_ABORTED : |
10111 | case IPP_JOB_COMPLETED : | |
bd7854cb | 10112 | if (job->state_value > IPP_JOB_PROCESSING) |
ef416fc2 | 10113 | { |
10114 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10115 | _("Job state cannot be changed.")); | |
10116 | return; | |
10117 | } | |
10118 | else if (con->response->request.status.status_code == IPP_OK) | |
07725fee | 10119 | cupsdCancelJob(job, 0, (ipp_jstate_t)attr->values[0].integer); |
ef416fc2 | 10120 | break; |
10121 | } | |
10122 | } | |
10123 | } | |
10124 | else if (con->response->request.status.status_code != IPP_OK) | |
10125 | continue; | |
fa73b229 | 10126 | else if ((attr2 = ippFindAttribute(job->attrs, attr->name, |
10127 | IPP_TAG_ZERO)) != NULL) | |
ef416fc2 | 10128 | { |
10129 | /* | |
10130 | * Some other value; first free the old value... | |
10131 | */ | |
10132 | ||
10133 | if (job->attrs->prev) | |
10134 | job->attrs->prev->next = attr2->next; | |
10135 | else | |
10136 | job->attrs->attrs = attr2->next; | |
10137 | ||
10138 | if (job->attrs->last == attr2) | |
10139 | job->attrs->last = job->attrs->prev; | |
10140 | ||
757d2cad | 10141 | _ippFreeAttr(attr2); |
ef416fc2 | 10142 | |
10143 | /* | |
10144 | * Then copy the attribute... | |
10145 | */ | |
10146 | ||
10147 | copy_attribute(job->attrs, attr, 0); | |
10148 | ||
10149 | /* | |
10150 | * See if the job-name or job-hold-until is being changed. | |
10151 | */ | |
10152 | ||
10153 | if (!strcmp(attr->name, "job-hold-until")) | |
10154 | { | |
10155 | cupsdSetJobHoldUntil(job, attr->values[0].string.text); | |
10156 | ||
10157 | if (!strcmp(attr->values[0].string.text, "no-hold")) | |
10158 | cupsdReleaseJob(job); | |
10159 | else | |
10160 | cupsdHoldJob(job); | |
d09495fa | 10161 | |
10162 | event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE; | |
ef416fc2 | 10163 | } |
10164 | } | |
10165 | else if (attr->value_tag == IPP_TAG_DELETEATTR) | |
10166 | { | |
10167 | /* | |
10168 | * Delete the attribute... | |
10169 | */ | |
10170 | ||
10171 | if ((attr2 = ippFindAttribute(job->attrs, attr->name, | |
10172 | IPP_TAG_ZERO)) != NULL) | |
10173 | { | |
10174 | if (job->attrs->prev) | |
10175 | job->attrs->prev->next = attr2->next; | |
10176 | else | |
10177 | job->attrs->attrs = attr2->next; | |
10178 | ||
10179 | if (attr2 == job->attrs->last) | |
10180 | job->attrs->last = job->attrs->prev; | |
10181 | ||
757d2cad | 10182 | _ippFreeAttr(attr2); |
d09495fa | 10183 | |
10184 | event |= CUPSD_EVENT_JOB_CONFIG_CHANGED; | |
ef416fc2 | 10185 | } |
10186 | } | |
10187 | else | |
10188 | { | |
10189 | /* | |
10190 | * Add new option by copying it... | |
10191 | */ | |
10192 | ||
10193 | copy_attribute(job->attrs, attr, 0); | |
d09495fa | 10194 | |
10195 | event |= CUPSD_EVENT_JOB_CONFIG_CHANGED; | |
ef416fc2 | 10196 | } |
10197 | } | |
10198 | ||
10199 | /* | |
10200 | * Save the job... | |
10201 | */ | |
10202 | ||
3dfe78b3 MS |
10203 | job->dirty = 1; |
10204 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); | |
ef416fc2 | 10205 | |
d09495fa | 10206 | /* |
10207 | * Send events as needed... | |
10208 | */ | |
10209 | ||
d9bca400 MS |
10210 | if (event & CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED) |
10211 | cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED, job->printer, job, | |
10212 | "Job priority changed by user."); | |
10213 | ||
d09495fa | 10214 | if (event & CUPSD_EVENT_JOB_STATE) |
10215 | cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, | |
10216 | job->state_value == IPP_JOB_HELD ? | |
10217 | "Job held by user." : "Job restarted by user."); | |
10218 | ||
10219 | if (event & CUPSD_EVENT_JOB_CONFIG_CHANGED) | |
10220 | cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, job->printer, job, | |
10221 | "Job options changed by user."); | |
10222 | ||
ef416fc2 | 10223 | /* |
10224 | * Start jobs if possible... | |
10225 | */ | |
10226 | ||
10227 | cupsdCheckJobs(); | |
10228 | } | |
10229 | ||
10230 | ||
b423cd4c | 10231 | /* |
10232 | * 'set_printer_defaults()' - Set printer default options from a request. | |
10233 | */ | |
10234 | ||
10235 | static void | |
10236 | set_printer_defaults( | |
10237 | cupsd_client_t *con, /* I - Client connection */ | |
10238 | cupsd_printer_t *printer) /* I - Printer */ | |
10239 | { | |
10240 | int i; /* Looping var */ | |
10241 | ipp_attribute_t *attr; /* Current attribute */ | |
10242 | int namelen; /* Length of attribute name */ | |
10243 | char name[256], /* New attribute name */ | |
10244 | value[256]; /* String version of integer attrs */ | |
10245 | ||
10246 | ||
10247 | for (attr = con->request->attrs; attr; attr = attr->next) | |
10248 | { | |
10249 | /* | |
10250 | * Skip non-printer attributes... | |
10251 | */ | |
10252 | ||
10253 | if (attr->group_tag != IPP_TAG_PRINTER || !attr->name) | |
10254 | continue; | |
10255 | ||
10256 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_printer_defaults: %s", attr->name); | |
10257 | ||
10258 | if (!strcmp(attr->name, "job-sheets-default")) | |
10259 | { | |
10260 | /* | |
10261 | * Only allow keywords and names... | |
10262 | */ | |
10263 | ||
10264 | if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD) | |
10265 | continue; | |
10266 | ||
10267 | /* | |
10268 | * Only allow job-sheets-default to be set when running without a | |
10269 | * system high classification level... | |
10270 | */ | |
10271 | ||
10272 | if (Classification) | |
10273 | continue; | |
10274 | ||
10275 | cupsdSetString(&printer->job_sheets[0], attr->values[0].string.text); | |
10276 | ||
10277 | if (attr->num_values > 1) | |
10278 | cupsdSetString(&printer->job_sheets[1], attr->values[1].string.text); | |
10279 | else | |
10280 | cupsdSetString(&printer->job_sheets[1], "none"); | |
10281 | } | |
10282 | else if (!strcmp(attr->name, "requesting-user-name-allowed")) | |
10283 | { | |
10284 | cupsdFreePrinterUsers(printer); | |
10285 | ||
10286 | printer->deny_users = 0; | |
10287 | ||
10288 | if (attr->value_tag == IPP_TAG_NAME && | |
10289 | (attr->num_values > 1 || | |
10290 | strcmp(attr->values[0].string.text, "all"))) | |
10291 | { | |
10292 | for (i = 0; i < attr->num_values; i ++) | |
10293 | cupsdAddPrinterUser(printer, attr->values[i].string.text); | |
10294 | } | |
10295 | } | |
10296 | else if (!strcmp(attr->name, "requesting-user-name-denied")) | |
10297 | { | |
10298 | cupsdFreePrinterUsers(printer); | |
10299 | ||
10300 | printer->deny_users = 1; | |
10301 | ||
10302 | if (attr->value_tag == IPP_TAG_NAME && | |
10303 | (attr->num_values > 1 || | |
10304 | strcmp(attr->values[0].string.text, "none"))) | |
10305 | { | |
10306 | for (i = 0; i < attr->num_values; i ++) | |
10307 | cupsdAddPrinterUser(printer, attr->values[i].string.text); | |
10308 | } | |
10309 | } | |
10310 | else if (!strcmp(attr->name, "job-quota-period")) | |
10311 | { | |
10312 | if (attr->value_tag != IPP_TAG_INTEGER) | |
10313 | continue; | |
10314 | ||
10315 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-quota-period to %d...", | |
10316 | attr->values[0].integer); | |
10317 | cupsdFreeQuotas(printer); | |
10318 | ||
10319 | printer->quota_period = attr->values[0].integer; | |
10320 | } | |
10321 | else if (!strcmp(attr->name, "job-k-limit")) | |
10322 | { | |
10323 | if (attr->value_tag != IPP_TAG_INTEGER) | |
10324 | continue; | |
10325 | ||
10326 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-k-limit to %d...", | |
10327 | attr->values[0].integer); | |
10328 | cupsdFreeQuotas(printer); | |
10329 | ||
10330 | printer->k_limit = attr->values[0].integer; | |
10331 | } | |
10332 | else if (!strcmp(attr->name, "job-page-limit")) | |
10333 | { | |
10334 | if (attr->value_tag != IPP_TAG_INTEGER) | |
10335 | continue; | |
10336 | ||
10337 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-page-limit to %d...", | |
10338 | attr->values[0].integer); | |
10339 | cupsdFreeQuotas(printer); | |
10340 | ||
10341 | printer->page_limit = attr->values[0].integer; | |
10342 | } | |
10343 | else if (!strcmp(attr->name, "printer-op-policy")) | |
10344 | { | |
10345 | cupsd_policy_t *p; /* Policy */ | |
10346 | ||
10347 | ||
10348 | if (attr->value_tag != IPP_TAG_NAME) | |
10349 | continue; | |
10350 | ||
10351 | if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL) | |
10352 | { | |
10353 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10354 | "Setting printer-op-policy to \"%s\"...", | |
10355 | attr->values[0].string.text); | |
10356 | cupsdSetString(&printer->op_policy, attr->values[0].string.text); | |
10357 | printer->op_policy_ptr = p; | |
10358 | } | |
10359 | else | |
10360 | { | |
10361 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10362 | _("Unknown printer-op-policy \"%s\"."), | |
10363 | attr->values[0].string.text); | |
10364 | return; | |
10365 | } | |
10366 | } | |
10367 | else if (!strcmp(attr->name, "printer-error-policy")) | |
10368 | { | |
10369 | if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD) | |
10370 | continue; | |
10371 | ||
10372 | if (strcmp(attr->values[0].string.text, "abort-job") && | |
10373 | strcmp(attr->values[0].string.text, "retry-job") && | |
10374 | strcmp(attr->values[0].string.text, "stop-printer")) | |
10375 | { | |
10376 | send_ipp_status(con, IPP_NOT_POSSIBLE, | |
10377 | _("Unknown printer-error-policy \"%s\"."), | |
10378 | attr->values[0].string.text); | |
10379 | return; | |
10380 | } | |
10381 | ||
10382 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10383 | "Setting printer-error-policy to \"%s\"...", | |
10384 | attr->values[0].string.text); | |
10385 | cupsdSetString(&printer->error_policy, attr->values[0].string.text); | |
10386 | } | |
b423cd4c | 10387 | |
10388 | /* | |
10389 | * Skip any other non-default attributes... | |
10390 | */ | |
10391 | ||
10392 | namelen = strlen(attr->name); | |
10393 | if (namelen < 9 || strcmp(attr->name + namelen - 8, "-default") || | |
10394 | namelen > (sizeof(name) - 1) || attr->num_values != 1) | |
10395 | continue; | |
10396 | ||
10397 | /* | |
10398 | * OK, anything else must be a user-defined default... | |
10399 | */ | |
10400 | ||
10401 | strlcpy(name, attr->name, sizeof(name)); | |
10402 | name[namelen - 8] = '\0'; /* Strip "-default" */ | |
10403 | ||
10404 | switch (attr->value_tag) | |
10405 | { | |
10406 | case IPP_TAG_DELETEATTR : | |
10407 | printer->num_options = cupsRemoveOption(name, | |
10408 | printer->num_options, | |
10409 | &(printer->options)); | |
10410 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10411 | "Deleting %s", attr->name); | |
10412 | break; | |
10413 | ||
10414 | case IPP_TAG_NAME : | |
10415 | case IPP_TAG_KEYWORD : | |
10416 | case IPP_TAG_URI : | |
10417 | printer->num_options = cupsAddOption(name, | |
10418 | attr->values[0].string.text, | |
10419 | printer->num_options, | |
10420 | &(printer->options)); | |
10421 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10422 | "Setting %s to \"%s\"...", attr->name, | |
10423 | attr->values[0].string.text); | |
10424 | break; | |
10425 | ||
10426 | case IPP_TAG_BOOLEAN : | |
10427 | printer->num_options = cupsAddOption(name, | |
10428 | attr->values[0].boolean ? | |
10429 | "true" : "false", | |
10430 | printer->num_options, | |
10431 | &(printer->options)); | |
10432 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10433 | "Setting %s to %s...", attr->name, | |
10434 | attr->values[0].boolean ? "true" : "false"); | |
10435 | break; | |
10436 | ||
10437 | case IPP_TAG_INTEGER : | |
10438 | case IPP_TAG_ENUM : | |
10439 | sprintf(value, "%d", attr->values[0].integer); | |
10440 | printer->num_options = cupsAddOption(name, value, | |
10441 | printer->num_options, | |
10442 | &(printer->options)); | |
10443 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10444 | "Setting %s to %s...", attr->name, value); | |
10445 | break; | |
10446 | ||
10447 | case IPP_TAG_RANGE : | |
10448 | sprintf(value, "%d-%d", attr->values[0].range.lower, | |
10449 | attr->values[0].range.upper); | |
10450 | printer->num_options = cupsAddOption(name, value, | |
10451 | printer->num_options, | |
10452 | &(printer->options)); | |
10453 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10454 | "Setting %s to %s...", attr->name, value); | |
10455 | break; | |
10456 | ||
10457 | case IPP_TAG_RESOLUTION : | |
10458 | sprintf(value, "%dx%d%s", attr->values[0].resolution.xres, | |
10459 | attr->values[0].resolution.yres, | |
10460 | attr->values[0].resolution.units == IPP_RES_PER_INCH ? | |
10461 | "dpi" : "dpc"); | |
10462 | printer->num_options = cupsAddOption(name, value, | |
10463 | printer->num_options, | |
10464 | &(printer->options)); | |
10465 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
10466 | "Setting %s to %s...", attr->name, value); | |
10467 | break; | |
10468 | ||
10469 | default : | |
10470 | /* Do nothing for other values */ | |
10471 | break; | |
10472 | } | |
10473 | } | |
10474 | } | |
10475 | ||
10476 | ||
ef416fc2 | 10477 | /* |
10478 | * 'start_printer()' - Start a printer. | |
10479 | */ | |
10480 | ||
10481 | static void | |
10482 | start_printer(cupsd_client_t *con, /* I - Client connection */ | |
10483 | ipp_attribute_t *uri) /* I - Printer URI */ | |
10484 | { | |
10485 | http_status_t status; /* Policy status */ | |
bc44d920 | 10486 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 10487 | cupsd_printer_t *printer; /* Printer data */ |
10488 | ||
10489 | ||
10490 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_printer(%p[%d], %s)", con, | |
10491 | con->http.fd, uri->values[0].string.text); | |
10492 | ||
10493 | /* | |
10494 | * Is the destination valid? | |
10495 | */ | |
10496 | ||
f7deaa1a | 10497 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 10498 | { |
10499 | /* | |
10500 | * Bad URI... | |
10501 | */ | |
10502 | ||
10503 | send_ipp_status(con, IPP_NOT_FOUND, | |
10504 | _("The printer or class was not found.")); | |
10505 | return; | |
10506 | } | |
10507 | ||
10508 | /* | |
10509 | * Check policy... | |
10510 | */ | |
10511 | ||
10512 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) | |
10513 | { | |
f899b121 | 10514 | send_http_error(con, status, printer); |
ef416fc2 | 10515 | return; |
10516 | } | |
10517 | ||
10518 | /* | |
10519 | * Start the printer... | |
10520 | */ | |
10521 | ||
10522 | printer->state_message[0] = '\0'; | |
10523 | ||
10524 | cupsdStartPrinter(printer, 1); | |
10525 | ||
10526 | if (dtype & CUPS_PRINTER_CLASS) | |
f7deaa1a | 10527 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".", |
10528 | printer->name, get_username(con)); | |
e00b005a | 10529 | else |
f7deaa1a | 10530 | cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".", |
10531 | printer->name, get_username(con)); | |
ef416fc2 | 10532 | |
10533 | cupsdCheckJobs(); | |
10534 | ||
10535 | /* | |
10536 | * Everything was ok, so return OK status... | |
10537 | */ | |
10538 | ||
10539 | con->response->request.status.status_code = IPP_OK; | |
10540 | } | |
10541 | ||
10542 | ||
10543 | /* | |
10544 | * 'stop_printer()' - Stop a printer. | |
10545 | */ | |
10546 | ||
10547 | static void | |
10548 | stop_printer(cupsd_client_t *con, /* I - Client connection */ | |
10549 | ipp_attribute_t *uri) /* I - Printer URI */ | |
10550 | { | |
10551 | http_status_t status; /* Policy status */ | |
bc44d920 | 10552 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 10553 | cupsd_printer_t *printer; /* Printer data */ |
10554 | ipp_attribute_t *attr; /* printer-state-message attribute */ | |
10555 | ||
10556 | ||
10557 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "stop_printer(%p[%d], %s)", con, | |
10558 | con->http.fd, uri->values[0].string.text); | |
10559 | ||
10560 | /* | |
10561 | * Is the destination valid? | |
10562 | */ | |
10563 | ||
f7deaa1a | 10564 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 10565 | { |
10566 | /* | |
10567 | * Bad URI... | |
10568 | */ | |
10569 | ||
10570 | send_ipp_status(con, IPP_NOT_FOUND, | |
10571 | _("The printer or class was not found.")); | |
10572 | return; | |
10573 | } | |
10574 | ||
10575 | /* | |
10576 | * Check policy... | |
10577 | */ | |
10578 | ||
10579 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) | |
10580 | { | |
f899b121 | 10581 | send_http_error(con, status, printer); |
ef416fc2 | 10582 | return; |
10583 | } | |
10584 | ||
10585 | /* | |
10586 | * Stop the printer... | |
10587 | */ | |
10588 | ||
10589 | if ((attr = ippFindAttribute(con->request, "printer-state-message", | |
10590 | IPP_TAG_TEXT)) == NULL) | |
10591 | strcpy(printer->state_message, "Paused"); | |
10592 | else | |
10593 | { | |
10594 | strlcpy(printer->state_message, attr->values[0].string.text, | |
10595 | sizeof(printer->state_message)); | |
10596 | } | |
10597 | ||
10598 | cupsdStopPrinter(printer, 1); | |
10599 | ||
10600 | if (dtype & CUPS_PRINTER_CLASS) | |
f7deaa1a | 10601 | cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".", |
10602 | printer->name, get_username(con)); | |
ef416fc2 | 10603 | else |
f7deaa1a | 10604 | cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".", |
10605 | printer->name, get_username(con)); | |
ef416fc2 | 10606 | |
10607 | /* | |
10608 | * Everything was ok, so return OK status... | |
10609 | */ | |
10610 | ||
10611 | con->response->request.status.status_code = IPP_OK; | |
10612 | } | |
10613 | ||
10614 | ||
89d46774 | 10615 | /* |
10616 | * 'url_encode_attr()' - URL-encode a string attribute. | |
10617 | */ | |
10618 | ||
10619 | static void | |
10620 | url_encode_attr(ipp_attribute_t *attr, /* I - Attribute */ | |
10621 | char *buffer,/* I - String buffer */ | |
10622 | int bufsize)/* I - Size of buffer */ | |
10623 | { | |
10624 | int i; /* Looping var */ | |
10625 | char *bufptr, /* Pointer into buffer */ | |
b94498cf | 10626 | *bufend; /* End of buffer */ |
89d46774 | 10627 | |
10628 | ||
10629 | strlcpy(buffer, attr->name, bufsize); | |
10630 | bufptr = buffer + strlen(buffer); | |
10631 | bufend = buffer + bufsize - 1; | |
10632 | ||
10633 | for (i = 0; i < attr->num_values; i ++) | |
10634 | { | |
10635 | if (bufptr >= bufend) | |
10636 | break; | |
10637 | ||
10638 | if (i) | |
10639 | *bufptr++ = ','; | |
10640 | else | |
10641 | *bufptr++ = '='; | |
10642 | ||
10643 | if (bufptr >= bufend) | |
10644 | break; | |
10645 | ||
10646 | *bufptr++ = '\''; | |
10647 | ||
b94498cf | 10648 | bufptr = url_encode_string(attr->values[i].string.text, |
10649 | bufptr, bufend - bufptr + 1); | |
89d46774 | 10650 | |
10651 | if (bufptr >= bufend) | |
10652 | break; | |
10653 | ||
10654 | *bufptr++ = '\''; | |
10655 | } | |
10656 | ||
10657 | *bufptr = '\0'; | |
10658 | } | |
10659 | ||
10660 | ||
b94498cf | 10661 | /* |
10662 | * 'url_encode_string()' - URL-encode a string. | |
10663 | */ | |
10664 | ||
10665 | static char * /* O - End of string */ | |
10666 | url_encode_string(const char *s, /* I - String */ | |
10667 | char *buffer, /* I - String buffer */ | |
10668 | int bufsize) /* I - Size of buffer */ | |
10669 | { | |
10670 | char *bufptr, /* Pointer into buffer */ | |
10671 | *bufend; /* End of buffer */ | |
10672 | static const char *hex = "0123456789ABCDEF"; | |
10673 | /* Hex digits */ | |
10674 | ||
10675 | ||
10676 | bufptr = buffer; | |
10677 | bufend = buffer + bufsize - 1; | |
10678 | ||
10679 | while (*s && bufptr < bufend) | |
10680 | { | |
10681 | if (*s == ' ' || *s == '%') | |
10682 | { | |
10683 | if (bufptr >= (bufend - 2)) | |
10684 | break; | |
10685 | ||
10686 | *bufptr++ = '%'; | |
10687 | *bufptr++ = hex[(*s >> 4) & 15]; | |
10688 | *bufptr++ = hex[*s & 15]; | |
10689 | ||
10690 | s ++; | |
10691 | } | |
10692 | else if (*s == '\'' || *s == '\\') | |
10693 | { | |
10694 | if (bufptr >= (bufend - 1)) | |
10695 | break; | |
10696 | ||
10697 | *bufptr++ = '\\'; | |
10698 | *bufptr++ = *s++; | |
10699 | } | |
10700 | else | |
10701 | *bufptr++ = *s++; | |
10702 | } | |
10703 | ||
10704 | *bufptr = '\0'; | |
10705 | ||
10706 | return (bufptr); | |
10707 | } | |
10708 | ||
10709 | ||
ef416fc2 | 10710 | /* |
10711 | * 'user_allowed()' - See if a user is allowed to print to a queue. | |
10712 | */ | |
10713 | ||
10714 | static int /* O - 0 if not allowed, 1 if allowed */ | |
10715 | user_allowed(cupsd_printer_t *p, /* I - Printer or class */ | |
10716 | const char *username) /* I - Username */ | |
10717 | { | |
10718 | int i; /* Looping var */ | |
10719 | struct passwd *pw; /* User password data */ | |
5bd77a73 MS |
10720 | char baseuser[256], /* Base username */ |
10721 | *baseptr; /* Pointer to "@" in base username */ | |
ef416fc2 | 10722 | |
10723 | ||
10724 | if (p->num_users == 0) | |
10725 | return (1); | |
10726 | ||
10727 | if (!strcmp(username, "root")) | |
10728 | return (1); | |
10729 | ||
5bd77a73 MS |
10730 | if (strchr(username, '@')) |
10731 | { | |
10732 | /* | |
10733 | * Strip @REALM for username check... | |
10734 | */ | |
10735 | ||
10736 | strlcpy(baseuser, username, sizeof(baseuser)); | |
10737 | ||
10738 | if ((baseptr = strchr(baseuser, '@')) != NULL) | |
10739 | *baseptr = '\0'; | |
10740 | ||
10741 | username = baseuser; | |
10742 | } | |
10743 | ||
ef416fc2 | 10744 | pw = getpwnam(username); |
10745 | endpwent(); | |
10746 | ||
10747 | for (i = 0; i < p->num_users; i ++) | |
10748 | { | |
10749 | if (p->users[i][0] == '@') | |
10750 | { | |
10751 | /* | |
10752 | * Check group membership... | |
10753 | */ | |
10754 | ||
10755 | if (cupsdCheckGroup(username, pw, p->users[i] + 1)) | |
10756 | break; | |
10757 | } | |
10758 | else if (!strcasecmp(username, p->users[i])) | |
10759 | break; | |
10760 | } | |
10761 | ||
10762 | return ((i < p->num_users) != p->deny_users); | |
10763 | } | |
10764 | ||
10765 | ||
10766 | /* | |
10767 | * 'validate_job()' - Validate printer options and destination. | |
10768 | */ | |
10769 | ||
10770 | static void | |
10771 | validate_job(cupsd_client_t *con, /* I - Client connection */ | |
10772 | ipp_attribute_t *uri) /* I - Printer URI */ | |
10773 | { | |
10774 | http_status_t status; /* Policy status */ | |
10775 | ipp_attribute_t *attr; /* Current attribute */ | |
10776 | ipp_attribute_t *format; /* Document-format attribute */ | |
bc44d920 | 10777 | cups_ptype_t dtype; /* Destination type (printer/class) */ |
ef416fc2 | 10778 | char super[MIME_MAX_SUPER], |
10779 | /* Supertype of file */ | |
10780 | type[MIME_MAX_TYPE]; | |
10781 | /* Subtype of file */ | |
10782 | cupsd_printer_t *printer; /* Printer */ | |
10783 | ||
10784 | ||
10785 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "validate_job(%p[%d], %s)", con, | |
10786 | con->http.fd, uri->values[0].string.text); | |
10787 | ||
10788 | /* | |
10789 | * OK, see if the client is sending the document compressed - CUPS | |
10790 | * doesn't support compression yet... | |
10791 | */ | |
10792 | ||
fa73b229 | 10793 | if ((attr = ippFindAttribute(con->request, "compression", |
10794 | IPP_TAG_KEYWORD)) != NULL && | |
10795 | !strcmp(attr->values[0].string.text, "none")) | |
ef416fc2 | 10796 | { |
10797 | send_ipp_status(con, IPP_ATTRIBUTES, | |
10798 | _("Unsupported compression attribute %s!"), | |
10799 | attr->values[0].string.text); | |
10800 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_KEYWORD, | |
10801 | "compression", NULL, attr->values[0].string.text); | |
10802 | return; | |
10803 | } | |
10804 | ||
10805 | /* | |
10806 | * Is it a format we support? | |
10807 | */ | |
10808 | ||
10809 | if ((format = ippFindAttribute(con->request, "document-format", | |
10810 | IPP_TAG_MIMETYPE)) != NULL) | |
10811 | { | |
bc44d920 | 10812 | if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", |
10813 | super, type) != 2) | |
ef416fc2 | 10814 | { |
10815 | send_ipp_status(con, IPP_BAD_REQUEST, _("Bad document-format \"%s\"!"), | |
10816 | format->values[0].string.text); | |
10817 | return; | |
10818 | } | |
10819 | ||
fa73b229 | 10820 | if ((strcmp(super, "application") || strcmp(type, "octet-stream")) && |
10821 | !mimeType(MimeDatabase, super, type)) | |
ef416fc2 | 10822 | { |
10823 | cupsdLogMessage(CUPSD_LOG_INFO, | |
10824 | "Hint: Do you have the raw file printing rules enabled?"); | |
10825 | send_ipp_status(con, IPP_DOCUMENT_FORMAT, | |
10826 | _("Unsupported format \"%s\"!"), | |
10827 | format->values[0].string.text); | |
10828 | ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE, | |
10829 | "document-format", NULL, format->values[0].string.text); | |
10830 | return; | |
10831 | } | |
10832 | } | |
10833 | ||
10834 | /* | |
10835 | * Is the destination valid? | |
10836 | */ | |
10837 | ||
f7deaa1a | 10838 | if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer)) |
ef416fc2 | 10839 | { |
10840 | /* | |
10841 | * Bad URI... | |
10842 | */ | |
10843 | ||
10844 | send_ipp_status(con, IPP_NOT_FOUND, | |
10845 | _("The printer or class was not found.")); | |
10846 | return; | |
10847 | } | |
10848 | ||
10849 | /* | |
10850 | * Check policy... | |
10851 | */ | |
10852 | ||
10853 | if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK) | |
10854 | { | |
f899b121 | 10855 | send_http_error(con, status, printer); |
ef416fc2 | 10856 | return; |
10857 | } | |
10858 | ||
10859 | /* | |
10860 | * Everything was ok, so return OK status... | |
10861 | */ | |
10862 | ||
10863 | con->response->request.status.status_code = IPP_OK; | |
10864 | } | |
10865 | ||
10866 | ||
10867 | /* | |
10868 | * 'validate_name()' - Make sure the printer name only contains valid chars. | |
10869 | */ | |
10870 | ||
bc44d920 | 10871 | static int /* O - 0 if name is no good, 1 if good */ |
ef416fc2 | 10872 | validate_name(const char *name) /* I - Name to check */ |
10873 | { | |
10874 | const char *ptr; /* Pointer into name */ | |
10875 | ||
10876 | ||
10877 | /* | |
10878 | * Scan the whole name... | |
10879 | */ | |
10880 | ||
10881 | for (ptr = name; *ptr; ptr ++) | |
f7deaa1a | 10882 | if ((*ptr > 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/' || *ptr == '#') |
ef416fc2 | 10883 | return (0); |
10884 | ||
10885 | /* | |
10886 | * All the characters are good; validate the length, too... | |
10887 | */ | |
10888 | ||
10889 | return ((ptr - name) < 128); | |
10890 | } | |
10891 | ||
10892 | ||
10893 | /* | |
10894 | * 'validate_user()' - Validate the user for the request. | |
10895 | */ | |
10896 | ||
10897 | static int /* O - 1 if permitted, 0 otherwise */ | |
10898 | validate_user(cupsd_job_t *job, /* I - Job */ | |
10899 | cupsd_client_t *con, /* I - Client connection */ | |
10900 | const char *owner, /* I - Owner of job/resource */ | |
10901 | char *username, /* O - Authenticated username */ | |
10902 | int userlen) /* I - Length of username */ | |
10903 | { | |
ef416fc2 | 10904 | cupsd_printer_t *printer; /* Printer for job */ |
10905 | ||
10906 | ||
10907 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
10908 | "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, " | |
10909 | "userlen=%d)", | |
91c84a35 MS |
10910 | job->id, con ? con->http.fd : 0, |
10911 | owner ? owner : "(null)", username, userlen); | |
ef416fc2 | 10912 | |
10913 | /* | |
10914 | * Validate input... | |
10915 | */ | |
10916 | ||
10917 | if (!con || !owner || !username || userlen <= 0) | |
10918 | return (0); | |
10919 | ||
10920 | /* | |
10921 | * Get the best authenticated username that is available. | |
10922 | */ | |
10923 | ||
e00b005a | 10924 | strlcpy(username, get_username(con), userlen); |
ef416fc2 | 10925 | |
10926 | /* | |
10927 | * Check the username against the owner... | |
10928 | */ | |
10929 | ||
80ca4592 | 10930 | printer = cupsdFindDest(job->dest); |
ef416fc2 | 10931 | |
10932 | return (cupsdCheckPolicy(printer ? printer->op_policy_ptr : DefaultPolicyPtr, | |
10933 | con, owner) == HTTP_OK); | |
10934 | } | |
10935 | ||
10936 | ||
10937 | /* | |
2e4ff8af | 10938 | * End of "$Id: ipp.c 7014 2007-10-10 21:57:43Z mike $". |
ef416fc2 | 10939 | */ |